Is there a version of the CvBlobs library that works with cv :: Mat?

I just discovered CvBlobsLib , which may be a blessing, but unfortunately uses IplImage.
Is there a chance that there is a new release of cv :: Mat-style that I just could not find?

EDIT:

It turned out that I managed to find two different libraries: CvBlobsLib and CvBlobs, yeehaa. :)
I saw that CvBlobsLib is used less than cvBlobs, that is, NOT on opencv willowgarage, but on google code. I welcome answers for both libraries, although I work with IplImage. :)

+4
source share
2 answers

EDIT: I'm talking about cvBlobs in this answer, sorry I messed it up with cvBlobsLib ...

I also searched for this, but did not come up with any library that uses the new image structure.

But in fact, you can always do this: IplImage iplImg = mat; and just use &iplimg wherever you need IplImage* .

I have used cvBlobs this way successfully in several projects:

 #include <cvblob.h> using namespace cvb; // load image cv::Mat mat = cv::imread("image.jpg"); // convert cv::Mat to IplImage IplImage img = mat; // convert to grayscale IplImage *gray = cvCreateImage( cvGetSize(&img), IPL_DEPTH_8U, 1 ); cvCvtColor( &img, gray, CV_BGR2GRAY ); // get binary image cvThreshold( gray, gray, 150, 255, CV_THRESH_BINARY ); // get blobs IplImage *labelImg = cvCreateImage( cvGetSize(gray), IPL_DEPTH_LABEL, 1 ); CvBlobs blobs; unsigned int result = cvLabel( gray, labelImg, blobs ); // render blobs in original image cvRenderBlobs( labelImg, blobs, &img, &img ); // *always* remember freeing unused IplImages cvReleaseImage( labelImg ); cvReleaseImage( gray ); // convert back to cv::Mat cv::Mat output( &img ); 
+5
source

Actually, the real version of @moosgummi's answer in C ++ looks something like this:

 #include <cvblobs.h> using namespace cvb; using namespace cv; // load image Mat mat = imread("image.jpg"); // convert to grayscale Mat gray; cvtColor(mat, gray, CV_BGR2GRAY); // get binary image threshold( gray, gray, 150, 255, CV_THRESH_BINARY ); // get blobs Mat labelImg; labelImg.create( gray.size(), IPL_DEPTH_LABEL ); // need to check if IPL_DEPTH_LABEL is the right type...not sure CvBlobs blobs; IplImage iplLabelImg = labelImg; // do not release this! unsigned int result = cvLabel( gray, &iplLabelImg, blobs ); // render blobs in original image IplImage iplMat = mat; // do not release this! cvRenderBlobs( &iplLabelImg, blobs, &iplMat, &iplMat); // for sake of compatibility with moosgummi: cv::Mat output = mat; 

And you need a wrapper class for CvBlobs tell class cvb::Blobs with lazy_copy_refcounted private CvBlobs data and some conversion operators to const CvBlobs and CvBlobs. We also need a wrapper function for cvLabel, cvb::label() , which makes castings for us C ++ programmers.

+3
source

Source: https://habr.com/ru/post/1447857/


All Articles