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?
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.
Use the findContours() function to detect the contours in the image.
A contour is a path in an image along which the image intensity values are equal to a constant.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With