cvBlob示例不能正常工作cvLabel

时间:2013-02-02 12:19:07

标签: ubuntu opencv compiler-errors blob

我尝试使用teh cvBlob lib进行blob检测,在 Ubuntu 下的opencv中,但我在开始时被阻止了。当我尝试在那里编译示例表单时:

#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);
    }

}

我为此原始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

我不知道应该是什么问题!

在第一个回答中提到的更改后,我收到了一个链接器错误:(

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

我应该在什么地方和哪里认识到上面提到的功能?(CMakeList或Makefile)?

1 个答案:

答案 0 :(得分:1)

您的代码中有两个拼写错误,会产生以下错误: - IplImage src_g; - &GT;应该声明为指针 - unsigned int result = cvb :: CvLabel (src_g,labelImg,blobs); - &GT;使用cvLabel()而不是CvLabel()

希望这有帮助, TL