1

I try to use teh cvBlob lib for blob detection, in opencv under Ubuntu but i got blocked right at the beginning. When i try to compile the example form there site:

#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include "cvblob.h"

using namespace cvb;
using namespace std;

int main( int argc,char** argv){
    if( argv[1] == NULL ){
        printf("\n Please Provide a valid Argument \n");
        return(0);
    }
    else{
        IplImage* src = cvLoadImage(argv[1],CV_LOAD_IMAGE_UNCHANGED);
        cvNamedWindow("Original",CV_WINDOW_AUTOSIZE);
        cvShowImage("Original",src);
    IplImage src_g;
    cvThreshold(src, src_g,35,255, CV_THRESH_BINARY);  
    IplImage *labelImg=cvCreateImage(cvGetSize(src_g), IPL_DEPTH_LABEL, 1);
    CvBlobs blobs;
    unsigned int result=cvb::CvLabel(src_g, labelImg, blobs);
    cvRenderBlobs(labelImg, blobs, src, src);
    for (CvBlobs::const_iterator it=blobs.begin(); it!=blobs.end(); ++it)
    {
      cout << "Blob #" << it->second->label << ": Area=" << it->second->area << ", Centroid=(" << it->second->centroid.x << ", " << it->second->centroid.y << ")" << endl;
    }
    cvNamedWindow( "Mod", CV_WINDOW_AUTOSIZE );
    cvShowImage( "Mod", src );  
    cvWaitKey(0);
        cvReleaseImage(&src);
        cvReleaseImage(&src_g);
        cvDestroyWindow("Image");
        return(0);
    }

}

I get this error for this raw unsigned int result=cvb::CvLabel(src_g, labelImg, blobs);:

home/rrg/OpenCV-2.4.3/release/bagDetect/main.cpp: In function ‘int main(int, char**)’:
/home/rrg/OpenCV-2.4.3/release/bagDetect/main.cpp:28: error: functional cast expression list treated as compound expression
/home/rrg/OpenCV-2.4.3/release/bagDetect/main.cpp:28: error: invalid cast from type ‘cvb::CvBlobs’ to type ‘cvb::CvLabel’
make[2]: *** [CMakeFiles/bag.dir/main.o] Error 1
make[1]: *** [CMakeFiles/bag.dir/all] Error 2
make: *** [all] Error 2

I have no idea what should be the problem!

After the changes mentioned in the first answer i got a linker error :(

Linking CXX executable bag
CMakeFiles/bag.dir/main.o: In function `main':
main.cpp:(.text+0x103): undefined reference to `cvLabel'
main.cpp:(.text+0x134): undefined reference to `cvRenderBlobs'
collect2: ld returned 1 exit status

What and where should I put to be recognized the functions mentioned above?(CMakeList or Makefile)?

1 Answer 1

1

There are two typos in your code, which generates you these errors: - IplImage src_g; --> should be declared as a pointer - unsigned int result=cvb::CvLabel(src_g, labelImg, blobs); --> use cvLabel() instead of CvLabel()

Hope this helps, TL

Sign up to request clarification or add additional context in comments.

2 Comments

Oh GOD, u were right, however now I have a similar problem as mentioned in one of my other post... i added to this one too.
Hi @Elod,about the linking: I managed to link with: ` gcc main.cpp pkg-config --cflags opencv -o test pkg-config cvblob opencv --libs `. It is a good practice to have the --libs at the end of the option list. Regards, TL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.