当我尝试使用opencv编译我的程序来检测blob时,我收到以下错误:
11:47:34 **** Incremental Build of configuration Debug for project testOpencv
Info: Internal Builder is used for build
g++ "-IC:\\Development\\opencv\\build\\include" -O0 -g3 -Wall -c -fmessage- length=0 -o "src\\testOpencv.o" "..\\src\\testOpencv.cpp"
g++ "-LC:\\Development\\opencv\\MINGW\\x86\\bin" -o testOpencv.exe "src\\testOpencv.o" -llibopencv_calib3d2410 -llibopencv_contrib2410 - llibopencv_core2410 -llibopencv_flann2410 -llibopencv_gpu2410 - llibopencv_highgui2410 -llibopencv_imgproc2410 -llibopencv_ml2410 - llibopencv_legacy2410 -llibopencv_nonfree2410 -llibopencv_objdetect2410 - llibopencv_ocl2410 -llibopencv_photo2410 -llibopencv_stitching2410 - llibopencv_superres2410 -llibopencv_video2410 -llibopencv_videostab2410 - lopencv_ffmpeg2410 -llibopencv_ml2410
src\testOpencv.o: In function `main':
C:\Development\Workspace\testOpencv\Debug/../src/testOpencv.cpp:98: undefined reference to `cv::SimpleBlobDetector::Params::Params()'
C:\Development\Workspace\testOpencv\Debug/../src/testOpencv.cpp:110: undefined reference to `cv::SimpleBlobDetector::SimpleBlobDetector(cv::SimpleBlobDetector::Params const&)'
C:\Development\Workspace\testOpencv\Debug/../src/testOpencv.cpp:113: undefined reference to `cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const'
C:\Development\Workspace\testOpencv\Debug/../src/testOpencv.cpp:117: undefined reference to `cv::drawKeypoints(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::Mat&, cv::Scalar_<double> const&, int)'
src\testOpencv.o: In function `ZN2cv18SimpleBlobDetectorD1Ev':
C:/Development/opencv/build/include/opencv2/features2d/features2d.hpp:615: undefined reference to `vtable for cv::SimpleBlobDetector'
C:/Development/opencv/build/include/opencv2/features2d/features2d.hpp:615:undefined reference to `vtable for cv::SimpleBlobDetector'
C:/Development/opencv/build/include/opencv2/features2d/features2d.hpp:615:undefined reference to `VTT for cv::SimpleBlobDetector'
C:/Development/opencv/build/include/opencv2/features2d/features2d.hpp:615: undefined reference to `cv::FeatureDetector::~FeatureDetector()'collect2.exe: error: ld returned 1 exit status
11:47:38 Build Finished (took 4s.111ms) >
我正在Eclipse中编译,Windows 7 - 64位,我尝试按照相反的顺序包含库,如此链接 - OpenCV undefined references。 以下是我的包含文件 -
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <iostream>
string imageName("image/Picture7.jpg");
if( argc > 1)
{
imageName = argv[1];
}
Mat image,grey_image, src;
src = imread("image/lena512color.jpg");
image = imread(imageName.c_str(), IMREAD_COLOR);
//resizing to make it a normal size
resize(image, image, src.size());
namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", image );
// to display the image in greyscale
cvtColor(image, grey_image, CV_RGB2GRAY);//CV_BGR2GRAY);
imwrite( "savedImage/Gray_image.jpg", grey_image );
namedWindow("Gray window", WINDOW_AUTOSIZE);
imshow("Gray window", grey_image);
// Reduce the noise so we avoid false circle detection
GaussianBlur( grey_image, grey_image, Size(9, 9), 2, 2 );
SimpleBlobDetector::Params params;
params.maxThreshold= 200;
params.minThreshold = 10;
params.filterByArea= true;
params.minArea = 1500;
params.filterByCircularity= true;
params.minCircularity = 0.1;
params.filterByConvexity= true;
params.minConvexity = 0.87;
params.filterByInertia= true;
params.minInertiaRatio= 0.01;
SimpleBlobDetector detector(params);
vector<KeyPoint> keypoints;
detector.detect(grey_image, keypoints);
//Draw detected blobs as red circles
Mat blob_circles;
drawKeypoints(grey_image, keypoints, blob_circles,Scalar(0,0,255), DrawMatchesFlags:: DRAW_RICH_KEYPOINTS);
imshow("Keypoints", blob_circles);
waitKey(0);
return 0;
}
如何避免这些错误?
答案 0 :(得分:0)
在您的链接器选项中:根据#include <windows.h>
class Foo
{
public :
Foo()
{
Connect();
}
virtual ~Foo()
{
Disconnect();
}
protected:
static Foo* current_foo;
static BOOL CtrlHandler(DWORD fdwCtrlType)
{
switch (fdwCtrlType)
{
// Handle the CTRL-C signal.
case CTRL_C_EVENT:
current_foo->Disconnect();
return(TRUE);
default:
return FALSE;
}
}
Run() {
Foo::current_foo = this;
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE );
// Other things
}
Connect();
Disconnect();
};
Foo* Foo::current_foo = nullptr;
int main(int argc, char* argv[])
{
Foo myFoo;
myFoo.Run();
}
版本的名称添加-llibopencv_feature2d2410.lib
,-llibopencv_objdetect2410.lib
。
lib的路径似乎还不行:
opencv
应为"-LC:\\Development\\opencv\\MINGW\\x86\\bin"