Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use "findContours" to find all blobs (binary large objects). BinaryImage needs to be an 8-bit single-channel image. It is helpful if you blur the image a bit before binarizing so that you don't get many 1 pixel objects.

vector<vector<Point>> contours;
vector<Vec4i> hierarchy;

findContours(BinaryImage, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE); //find all blobs
for (int i = 0; i < contours.size(); i++)
    vector<Point> contour_poly;
    approxPolyDP( Mat(contours[i]), contour_poly, 3, true );
    double Area=contourArea(contour_poly); //find area of each blob
    if (Area>25)
       //do whatever