cvBlobsLib is an useful OpenCV 3rd party library to do blob analysis. However the blobs extracted are sorted based on their y coordinates and the author provided no interface to sort the blobs by other criteria such as area. To do so, you need to make some internal change. Add the following member function that sort the blobs based on their areas to the class CBlobResult.
// sort blobs
void SortBlobs()
{
struct myclass {
bool operator() (CBlob* b1,CBlob* b2)
{
return (b1->GetArea() < b2->GetArea());
}
} blobComp;
std::sort(m_blobs.begin(),m_blobs.end(),blobComp);
}
If you want to sort the blobs based on their x coordinates, change the 7th line of above code to
return (b1->GetBoundingBox().x < b2->GetBoundingBox().x);
.
Posted by chi3x10 
