Joyita Das Joyita Das - 1 month ago 27
C++ Question

Undefined reference error while using Opencv: BlobDetector

I am getting the below error when i try to compile my program using opencv to detect blobs:

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) >


I am compiling in Eclipse, windows 7 - 64bits and I have tried following the reverse order for including the libraries as in this link- OpenCV undefined references.
Below are my include files-

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


How do I avoid these errors?

Answer

In your linker option: add -llibopencv_feature2d2410.lib, -llibopencv_objdetect2410.lib according to the name of your opencv version.

Also path of lib seems not ok:

"-LC:\\Development\\opencv\\MINGW\\x86\\bin" should be "-LC:\\Development\\opencv\\MINGW\\x86\\lib"