1 | initial version |
Find contours is find blobs for you, or more precisely, connected components. This code is extracted from the documentation here.
findContours( fg, contours, hierarchy,
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
/ iterate through all the top-level contours,
// draw each connected component with its own random color
int idx = 0;
for( ; idx >= 0; idx = hierarchy[idx][0] )
{
Scalar color( rand()&255, rand()&255, rand()&255 );
drawContours( frame, contours, idx, color, CV_FILLED, 8, hierarchy );
}
Otherwise, you can use the blob detector (doc) that can do it for you. Read the algorithm explain below the function. See a sample here or any other on Google...
2 | Suppress comments to make the code more readable. |
Find contours is find blobs for you, or more precisely, connected components. This code is extracted from the documentation here.
findContours( fg, contours, hierarchy,
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
/ iterate through all the top-level contours,
// draw each connected component with its own random color
int idx = 0;
for( ; idx >= 0; idx = hierarchy[idx][0] )
{
Scalar color( rand()&255, rand()&255, rand()&255 );
drawContours( frame, contours, idx, color, CV_FILLED, 8, hierarchy );
}
Otherwise, you can use the blob detector (doc) that can do it for you. Read the algorithm explain below the function. See a sample here or any other on Google...