FlannBasedMatcher matcher building - c++

as soon as i add to my code
FlannBasedMatcher matcher;
i get the following error when building
g++ -o "track" ./track.o -lopencv_imgproc -lopencv_features2d
-lopencv_nonfree -lopencv_core -lopencv_highgui -lopencv_video /usr/bin/ld: ./track.o: undefined reference to symbol
'_ZN2cv5flann12SearchParamsC1Eifb'
//usr/lib/x86_64-linux-gnu/libopencv_flann.so.2.4: error adding
symbols: DSO missing from command line collect2: error: ld returned 1
exit status
any idea? I am running Ubuntu
Thanks

Answer from an earlier question (Strange linking error: DSO missing from command line)
You should mention the library on the command line after the object
files being compiled
So, in your case:
Find out where _ZN2cv5flann12SearchParamsC1Eifb (actually "cv::flann::SearchParams::SearchParams(int, float, bool)") is defined:
nm -AD --defined-only /usr/lib64/libopencv_so. | grep
_ZN2cv5flann12SearchParamsC1Eifb /usr/lib64/libopencv_flann.so.2.4:0000000000029650 T
_ZN2cv5flann12SearchParamsC1Eifb /usr/lib64/libopencv_flann.so.2.4.9:0000000000029650 T
_ZN2cv5flann12SearchParamsC1Eifb
add -lopencv_flann to the link command immediately after it was referenced:
g++ fbm.cc -o fbm -lopencv_flann -lopencv_imgproc -lopencv_features2d -lopencv_nonfree -lopencv_core -lopencv_highgui -lopencv_video
Code sample for testing:
#include <opencv2/features2d/features2d.hpp>
using namespace cv;
FlannBasedMatcher matcher;
int main()
{}

Related

Running OpenCV in Mac OS terminal with opencv_contrib

I'm trying to compile and run OpenCV through the command line. I can get the main Open CV libraries to work however I think my problem is with using the opencv_contrib libraries.
I have installed Open CV with home brew.
I can compile and run the below code fine from another SO question:
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
Mat src = Mat(Size(320,240),CV_64F);;
namedWindow("test");
cout << "press any key to close" << endl;
while(true){
randn(src,0,1.0);
imshow("test",src);
if(waitKey() > 0) break;
}
}
This is compiled like this:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" -lopencv_core -lopencv_highgui -o cv
Then ran ./main
However when I try and run anything with the opencv_contrib libraries I get this error when compiled like this:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core -o cv
error:
Undefined symbols for architecture x86_64:
"cv::xfeatures2d::SURF::create(double, int, int, bool, bool)", referenced from:
_main in cv-f48298.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I believe this is likely due to not specifying the opencv_contrib libraries. I understand they come installed with homebrew. In my Cellar directory I have a directory for opencv and opencv_contrib. I'm not sure if the opencv_contrib directory needs to be located within the opencv directory.
But I believe everything is there as with this:
pkg-config --libs --cflags opencv
It outputs:
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
But then if I add that to my command like:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" pkg-config --libs --cflags opencv -o cv
I get this:
clang: error: unsupported option '--libs'
clang: error: unsupported option '--cflags'
clang: error: no such file or directory: 'pkg-config'
clang: error: no such file or directory: 'opencv'
I'm able to compile the same code in Xcode and I only needed to add the search paths for the openCV directory and add the libs within there. I can run the code by opening the products folder in finder and running ./cv with images passed in. But I'm struggling with doing this all through the command line.
Any help would be great!
You want to add the output of the pkgconfig tool (you listed it above: -I/usr/local/include/opencv ...) to your compilation command line to compile correctly.
You could just manually copy this output text into your compiler invocation command:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core -o cv
This is usually automated by calling pkgconfig inline:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" `pkg-config --libs --cflags opencv` -o cv
Notice the backticks in this though - they are missing in your command line. With the backticks pkgconfig will be executed and the output (which you know what it looks like) will be inserted into the command line.

opencv: undefined reference to `cv::cuda::DescriptorMatcher::createBFMatcher(int)'

I'm trying to complie opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp through:
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary surf_keypoint_matcher.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_stitching -lopencv_imgcodecs -lopencv_xfeatures2d
But I'm getting this error:
/tmp/ccQW7t3Z.o: In function `main':
/home/luca/Downloads/opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp:65: undefined reference to `cv::cuda::DescriptorMatcher::createBFMatcher(int)'
collect2: error: ld returned 1 exit status
Why?
Your error message:
/home/luca/Downloads/opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp:65: undefined reference to `cv::cuda::DescriptorMatcher::createBFMatcher(int)'
collect2: error: ld returned 1 exit status
shows that you have an undefined reference to cv::cuda::DescriptorMatcher::createBFMatcher
this resides in the cuda libs so you need to include the appropriate headers and link into the following libs as opencv_cudafeatures2d depends on them:
opencv_cudafilters
opencv_cudawarping
opencv_features2d
opencv_cudaarithmn
opencv_flann
opencv_core
certainly this is true for opencv version 3.1.0 which is what I'm using
DescriptorMatcher is in cudafeatures2d.hpp. So, you have to include the header cudafeatures2d.hpp in the .cpp program and link the library in the compile process.
The program runs if you use this -lopencv_cudafeatures2d:
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary surf_gpu_probe1.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_stitching -lopencv_imgcodecs -lopencv_xfeatures2d -lopencv_cudafeatures2d

undefined reference to some of the opencv functions

I'm trying to compile the 'motemple.c' that comes with the opencv samples in Ubuntu 14.04 environment. I think that opencv has been properly installed; most of the programs are running as expected. However, when compiling the above mentioned file, an error "undefined reference" is raised for several functions. Below is the output of the compilation:
Building target: ACTION_detection1
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "ACTION_detection1" ./opencvexample/MotionSegmentation.o -lopencv_core -lopencv_photo -lopencv_videoio -lopencv_videostab -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
./opencvexample/MotionSegmentation.o: In function `update_mhi':
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:103: undefined reference to `cvUpdateMotionHistory'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:105: undefined reference to `cvUpdateMotionHistory'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:114: undefined reference to `cvCalcMotionGradient'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:123: undefined reference to `cvSegmentMotion'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:149: undefined reference to `cvCalcGlobalOrientation'
collect2: error: ld returned 1 exit status
make: *** [ACTION_detection1] Error 1
As it can be seen, I have linked all the opencv libraries to mu Eclipse project. I also tried the command line solution provided here, but still get the same error.
they have been replaced to the opencv_contrib from the main repository. You can find them in the optflow module.
Notice: cvUpdateMotionHistory, cvCalcMotionGradient, etc. is the name of OpenCV 1.x API functions, they are now obsoleted/outdated so try to avoid them by replacing to cv::updateMotionHistory, cv::calcMotionGradient, etc.

Homography Error

first I would like to state that I'm a very noob at c++. I am using to compile and run code from Features2D + Homography to find a known object tutorial, but I think I'm having trouble in linking correctly the libraries needed. I am getting this:
Invoking: GCC C++ Linker g++ -L/usr/local/lib -o "Homografia2"
./src/Homografia2.o -lopencv_core -lopencv_nonfree -lopencv_imgproc
-lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In
function _start': (.text+0x18): undefined reference tomain'
collect2: ld returned 1 exit status make: * [Homografia2] Error 1
**** Build Finished ****
I'm working on eclipse. Please, I really need help.
The error is clear main function was not found. Are you missing it?
int main(int argc, char *argv[]){
//start application.
}
Regards

Opencv Static Linking Gives Error

Recently I build opencv as static library(by using BUILD_SHARED_LIBS=OFF) while dynamic libraries are already there, but at different location. And when I build may program I am getting many error. I am using command line for compiling the code, and look like below.
g++ -static -I$(OpenCV_Static_Build)/include/opencv -L$(OpenCV_Static_Build)/lib/ -g -o binary main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy
The error look like,
grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder12writeLibTiffERKNS_3MatERKSt6vectorIiSaIiEE+0x167): undefined reference to `TIFFSetField'
window_gtk.cpp:(.text.cvNamedWindow+0x29d): undefined reference to `g_type_check_instance_cast'
/usr/lib/gcc/i486-linux-gnu/4.4.3/libgcc_eh.a(unwind-dw2.o): In function `uw_init_context_1':
(.text+0x22f8): undefined reference to `pthread_once'
Those errors don't come from OpenCV (as one can tell from the function names) but from GLib and libpthread. Use the -lglib-2.0 -lpthread linker flags.