I'm going step by step like this guide and my code does not compile. It has gotten some linker errors which I don't know how to fix. this is my terminal's answer to : pkg-config --libs opencv
/usr/lib/x86_64-linux-gnu$ pkg-config --libs opencv
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d
/usr/lib/x86_64-linux-gnu/libopencv_contrib.so -lopencv_contrib
/usr/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core
/usr/lib/x86_64-linux-gnu/libopencv_features2d.so -lopencv_features2d
/usr/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann
/usr/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so -lopencv_highgui
/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so -lopencv_imgproc
/usr/lib/x86_64-linux-gnu/libopencv_legacy.so -lopencv_legacy
/usr/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml
/usr/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect
/usr/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl
/usr/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo
/usr/lib/x86_64-linux-gnu/libopencv_stitching.so -lopencv_stitching
/usr/lib/x86_64-linux-gnu/libopencv_superres.so -lopencv_superres
/usr/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts
/usr/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video
/usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_videostab
sorry if it's a mess to read but this is exactly how I received the answer.
This is how I've organized my linker
this is the error I get:
Building target: Ball_Plate Invoking: GCC C++ Linker g++ -L/usr/lib/x86_64-linux-gnu -o"Ball_Plate" ./Src/src.o -lopencv_core\ opencv_imgproc\ opencv_highgui\ opencv_ml\ opencv_video\ opencv_features2d\ opencv_calib3d\ opencv_objdetect\
opencv_contrib\ opencv_legacy\ opencv_flann /usr/bin/ld: cannot find
-lopencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_objdetect opencv_contrib
opencv_legacy opencv_flann collect2: error: ld returned 1 exit status
makefile:45: recipe for target 'Ball_Plate' failed make: ***
[Ball_Plate] Error 1
I don't know how to fix this, I don't know much about how linker works around .so files and I would appreciate that if you could help me.
So I read this post and found out what the problem was, tried to compile the OpenCV library with -DBUILD_TIFF=ON, Now Eclipse can find the header files but I get linker errors again, Eclipse cannot link the libraries.
Related
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.
Apple Mach-O Linker (ld) Error Group , found many existing question with same tag, however none did fix my issue.
I am trying to include OpenCV with my project in order to track hand position. And so far everything works fine, however when I build the project. It gives the error : Apple Mach-O Linker (ld) Error Group .
From the log here is what I obtained :
Ld /Users/shaheenakader/Library/Developer/Xcode/DerivedData/handSeg-fiojpqxgqvrsbxadwvnbdsljpycy/Build/Products/Debug/handSeg normal x86_64
cd /Users/shaheenakader/Documents/tracking
export MACOSX_DEPLOYMENT_TARGET=10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -L/Users/shaheenakader/Library/Developer/Xcode/DerivedData/handSeg-fiojpqxgqvrsbxadwvnbdsljpycy/Build/Products/Debug -L/usr/local/lib -F/Users/shaheenakader/Library/Developer/Xcode/DerivedData/handSeg-fiojpqxgqvrsbxadwvnbdsljpycy/Build/Products/Debug -filelist /Users/shaheenakader/Library/Developer/Xcode/DerivedData/handSeg-fiojpqxgqvrsbxadwvnbdsljpycy/Build/Intermediates/handSeg.build/Debug/handSeg.build/Objects-normal/x86_64/handSeg.LinkFileList -mmacosx-version-min=10.9 -Xlinker -object_path_lto -Xlinker /Users/shaheenakader/Library/Developer/Xcode/DerivedData/handSeg-fiojpqxgqvrsbxadwvnbdsljpycy/Build/Intermediates/handSeg.build/Debug/handSeg.build/Objects-normal/x86_64/handSeg_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab -lopencv_core.2.4.10 -lopencv_objdetect.2.4.10 -lopencv_highgui.2.4.10 -lopencv_imgproc.2.4.10 -Xlinker -dependency_info -Xlinker /Users/shaheenakader/Library/Developer/Xcode/DerivedData/handSeg-fiojpqxgqvrsbxadwvnbdsljpycy/Build/Intermediates/handSeg.build/Debug/handSeg.build/Objects-normal/x86_64/handSeg_dependency_info.dat -o /Users/shaheenakader/Library/Developer/Xcode/DerivedData/handSeg-fiojpqxgqvrsbxadwvnbdsljpycy/Build/Products/Debug/handSeg
Also,
ld: library not found for -lopencv_imgcodecs
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Previously
I manually built the OpenCV library using Cmake .
And inside my Xcode project, I set header search path to : /usr/local/include
and library search path to : /usr/local/lib .
Also, set other linker flags to : -lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab
What could possibly be causing this issue, and how to resolve this issue? Any help would be much appreciated.
It’s not enough just to link libraries in Xcode. You need to add the libraries into the projects. To do so, go to /usr/local/libs and drags them to the project explorer (the left panel of Xcode) and choose to create references on the pop up window. You can uncheck the option copy if needed on that window to avoid unnecessary clones of the libraries.
I installed OpenCV 3.2.0-dev on my mac(10.12) using Homebrew following this instruction http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/.
I solved the QTKit.h problem by skipping the checkout step.
Then I tried to build a small c++ program in Xcode 8 because I'm more familiar with c++ than python, it gave me an Apple mach-O linker (id) error which is shown here:
error message screenshot
The search paths for header and library are /usr/local/include and /usr/local/lib respectively. And the linker flags are
-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab
And I know when I use OpenCV version later than 3.1(I think), the linker flags can be replaced by something like opencv_world310.lib. Is there a similar way in Xcode?
Anyone can help me with that?
Homebrew install opencv in /usr/local/Cellar/, not in /usr/local/. So you need to modify header and library search paths correspondingly.
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
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.