OpenCV trying to integrate ARtoolkit with OpenCV - c++

I am new to C++, openCV and Artoolkit
I am trying to build a motion tracker devices
right now, I am following the tutorial
https://artoolkit.org/blog/2016/05/opencv-with-artoolkit
However I meet some problem when I trying to implement this on SimpleTest on the Linux machine.
The error I get is like this:
"clang++ -c -O3 -fPIC -march=core2 -DHAVE_NFT=1 -I/usr/include/x86_64-linux-gnu -pthread -I/usr/include/gstreamer-0.10 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libxml2 -I../../include simpleTest.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated In file included from simpleTest.c:79: In file included from ../../include/linux-x86_64/opencv2/opencv.hpp:59:/usr/include/opencv2/contrib/contrib.hpp:273:23: error: no template named
'vector'; did you mean 'std::vector'?"
simpleTest code
I added line like this
#include <linux-x86_64/opencv2/opencv.hpp>
#include <linux-x86_64/opencv2/opencv_modules.hpp>
using namespace std;
using namespace cv;
in the make file:
I add some this:
LIBS= -lARgsub -lARvideo -lAR -lARICP -lAR -lglut -lGLU -lGL -lX11 -lm -lpthread -ljpeg -pthread -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lxml2 -lglib-2.0 -ldc1394 -lraw1394 -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_viz -lippicv -lopencv_core
and
CC = clang++

There are some similar issues found on SO here.....
Linking C from C++ in OS X Mavericks
Warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated
There's a mismatch between C++ and C.
To get around this, it would be best if you used ARWrapper for ARToolkit within a C++ framework.

Related

Why does my g++ compiler not find the right OpenCV version?

I am trying to compile a program using this command:
g++ -std=c++11 -I"/usr/local/Cellar/opencv/4.5.0_5/include/opencv4/opencv2/" -I"/usr/include/python2.7" stl.cpp -o stl -ldl -lpthread -lrt -lopencv_core -lpython2.7
However, I keep getting this error:
fatal error: 'opencv2/core.hpp' file not found
I changed my -I include path to point to my version of OpenCV that has opencv2/core.hpp properly installed. Am I missing something? This approach has worked for other compilations...
EDIT
After trying the suggestions below, I'm still having no luck.
I added the pkg-config suggestion like below:
g++ -std=c++11 -I"/usr/include/python2.7" stl.cpp -o stl -ldl -lpthread -lrt -lopencv_core -lpython2.7 `pkg-config --cflags --libs opencv4`
but I still get "opencv2/core.hpp" not found. This is weird because when I run:
pkg-config --cflags --libs opencv4
I get:
-I/usr/local/Cellar/opencv/4.5.0_5/include/opencv4 -L/usr/local/Cellar/opencv/4.5.0_5/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_viz -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core
which makes me think it should work.
I also tried changing #include opencv2/core.hpp to #include core.hpp. This gets me closer, but then I get an error in my actual opencv2/core.hpp file saying it can't find the includes anymore. I don't think I want to start editing include paths in the original opencv library.
It looks like your include path is a bit wrong.
With your -I path you are looking at ...opencv4/opencv2/. And when you include core.hpp you are including it with (presumably):
#include "opencv2/core.hpp"
So the compiler is basically looking for core.hpp at: ...opencv4/opencv2/opencv2/core.hpp.
Try using ...include/opencv4/ instead. Or include like so:
#include "core.hpp"

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.

Adding opencv lib to custom lib, errors with ipp?

I'm bundling openCV into an SDK for people developing in C++ in linux. I'm linking a test executable with my built library and its giving me a huge dump of errors, one of which is:
/path/to/build/libopencv_core.a(copy.cpp.o): In function `cv::Mat::setTo(cv::_InputArray const&, cv::_InputArray const&)':
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x15c1): undefined reference to `ippicviSet_32f_C1MR'
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x1700): undefined reference to `ippicviSet_32f_C4MR'
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x1743): undefined reference to `ippicviSet_32s_C4MR'
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x17a4): undefined reference to `ippicviSet_16s_C4MR'
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x1805): undefined reference to `ippicviSet_16u_C4MR'
What is this error referencing? Should I be building without ipp? I compiled the opencv libs -fPIC and standalone. I'm actually getting thousands of errors which have some mention of ippicvi and this is just an example.
I had the same error. You need to link the executable to the library libippicv.
This is a 3rd party library used by OpenCV an you can find it in /usr/local/share/OpenCV/3rdparty/lib/libippicv.a.
You can also find in opencv.pc all the dependencies used by OpenCV. E.g.:
/usr/local/lib/pkgconfig/opencv.pc
# Package Information for pkg-config
prefix=/usr/local exec_prefix=${prefix} libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 3.2.0
Libs: -L${exec_prefix}/lib -lopencv_shape -lopencv_stitching
-lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
Libs.private: -L${exec_prefix}/share/OpenCV/3rdparty/lib -llibwebp
-lippicv -L/usr/lib/x86_64-linux-gnu -lpng -lz -ltiff -ljasper -ljpeg -lImath -lIlmImf -lIex -lHalf -lIlmThread -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lgthread-2.0 -ldc1394 -lavcodec-ffmpeg -lavformat-ffmpeg -lavutil-ffmpeg -lswscale-ffmpeg -lstdc++ -ldl -lm -lpthread -lrt Cflags: -I${includedir_old} -I${includedir_new}

Error compiling with Opencv

I'm trying to compile a program in C++ which uses OpenCV 2.4.10
But during compilation time it can't find the Imf symbol, and gives out a list of errors like
/usr/lib//libopencv_highgui.a(grfmt_exr.o): In function cv::ExrDecoder::readHeader()':
(.text._ZN2cv10ExrDecoder10readHeaderEv+0x12): undefined reference toImf::globalThreadCount()'
I'm compiling with
g++ -L/usr/local/lib/ -L/usr/lib/ -L/usr/lib/x86_64-linux-gnu/ -static -o "find_box_layout" ./src/find_box_layout.o -lopencv_imgproc -lopencv_highgui -lopencv_core -lm -ljasper -ljpeg -ltiff -lpng -lz -lpthread -lrt
Any help with this?

Eclipse CDT not working with OpenCV 2.0 integrated with Cygwin compiler

I have done all the necessary job like adding "c:/cygwin/bin" to system path, I have also set the include path under project->properties->c/c++ build->setting and also set the linker library search path.
Now when I include file like #include"cv.h", it gives no error, but when I run the program error comes like
undefined reference to '_cvGetSize'
I have included the necessary files, and read lots of tutorials that are available but still I couldn't able to run my code, please help me
I always recommend that before jumping to an IDE you make sure your system is installed and configured correctly by attempting to compile an application on the cmd-line:
g++ flann.cpp -o flann `pkg-config --cflags --libs opencv`
or:
g++ flann.cpp -o flann -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
Apparently you didn't link your project with the opencv libraries, which is being achieved in the cmd above with: -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann.
That missing symbol is defined in one of these libraries.