Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find contours only in black colour?

I try to remove noises from an image. I have some black group of pixels in the image. I use cv::findContours and cv::boundingRect. And I fill small rectangles (small rectangles are noises in the image) with white colour. But this method also find me white contours (for example middle of black circle). How to find countours for black pixels? Is there any easy solution?

like image 979
peter55555 Avatar asked Feb 17 '15 23:02

peter55555


People also ask

How do you find the number of contours?

To find the number of contours, we use the len() function. This gives us the number of contours (or objects) in the image. We then print out the number of objects in this image. So this how we can count the number of objects in an image in Python using OpenCV.

How do you find contours in C++?

Use the findContours() function to detect the contours in the image.

What is the contour of an image?

A contour is a path in an image along which the image intensity values are equal to a constant.


1 Answers

Contour of black object will have an opposite orientation from a contour of white object (clockwise vs counter clockwise). You can check it by calling a function that calculates signed area:

if (contourArea(someContour,true) > 0)
    cout << "black" << endl;
else
    cout << "white" << endl;
like image 198
Michael Burdinov Avatar answered Oct 23 '22 12:10

Michael Burdinov