我尝试在Ubuntu下的opencv中使用teh cvBlob lib进行blob检测,但我一开始就被阻止了。当我尝试在那里编译示例表单时:
#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)?