我尝试在 Ubuntu 下的 opencv 中使用 cvBlob 库进行 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 or Makefile)?
代码中有两个拼写错误,这会生成以下错误:- src_g图像;--> 应声明为指针- unsigned int result=cvb::CvLabel(src_g, labelImg, blobs);-->使用 cvLabel() 而不是 CvLabel()
希望这有帮助,TL