I am currently having Tegra4OpenCV and OpenCV3.1 together installed on my Jetson TX1 and following OpenCV 101 tutorial.
When both Tegra4OpenCV and OpenCV 3.1 (installed from source) installed, i am not able to complied the simplest “Hello OpenCV!” sample code. It threw compilation error as “‘putText’ is not a member of ‘cv’”.
When I uninstalled OpenCV 3.1 manually, everything goes back fine.
I have googled the issue, and even tried to have a customized CMakeLists.txt, it still failed as not a member of ‘cv’ issue.
ubuntu@tegra-ubuntu:~/Documents/OpenCV/Hello/build$ cmake -DCUDA_USE_STATIC_CUDA_RUNTIME=OFF ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found CUDA: /usr/local/cuda-8.0 (found suitable exact version "8.0")
-- OpenCV version: 2.4.13
-- OpenCV include directories: /usr/include/opencv;/usr/include
-- OpenCV libraries: opencv_vstab;opencv_tegra;opencv_imuvstab;opencv_facedetect;opencv_esm_panorama;opencv_detection_based_tracker;opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_objdetect;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d
-- OpenCV directory: /usr/share/OpenCV
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/Documents/OpenCV/Hello/build
and the output from make:
ubuntu@tegra-ubuntu:~/Documents/OpenCV/Hello/build$ make
Scanning dependencies of target cv_hello
[ 50%] Building CXX object CMakeFiles/cv_hello.dir/cv_hello.cpp.o
/home/ubuntu/Documents/OpenCV/Hello/cv_hello.cpp: In function 'int main()':
/home/ubuntu/Documents/OpenCV/Hello/cv_hello.cpp:7:5: error: 'putText' is not a member of 'cv'
cv::putText(img,
^
CMakeFiles/cv_hello.dir/build.make:62: recipe for target 'CMakeFiles/cv_hello.dir/cv_hello.cpp.o' failed
make[2]: *** [CMakeFiles/cv_hello.dir/cv_hello.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/cv_hello.dir/all' failed
make[1]: *** [CMakeFiles/cv_hello.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
My question is: is there any solution to make it work even OpenCV3.1 is kept installed? and I want to still use OpenCV 2.4.13 for some application. I’ve no idea what’s going on here. Any help? Thanks in advance!
Hello, ruih:
I just used make (no exp on cmake.) and maybe it can be a little helpful.
Generally, I will install NV official opencv4tegra through jetpack or apt-get install, and compile opencv-3.x source by myself, with specified installed directory.
In my open-CV application make file, with following lines, it will compile/link against default installed opencv, i.e. opencv4tegra:
Hello Chenjian,
Thanks for your response.
I am having opencv4tegra and opencv 3.1 installed on my TX1. I want to use opencv4tegra to compile the tutorial sample.
Still I can’t compile the simple code successfully.
g++ -c `pkg-config --cflags opencv` cv_hello.cpp
cv_hello.cpp: In function 'int main()':
cv_hello.cpp:5:5: error: 'putText' is not a member of 'cv'
cv::putText(img,
^
Makefile:13: recipe for target 'cv_hello.o' failed
make: *** [cv_hello.o] Error 1
Basically, your problem is that opencv4tegra is installed in /usr, and /usr/include is a standard include path (as /usr/lib is a standard path for link). When you try to compile for opencv3.1, gcc finds opencv4tegra before opencv3 headers.
You can try to use -nostdinc in cflags so that gcc doesn’t find opencv4tegra headers in /usr/include.
But if you have dependencies to others headers there it won’t work. Maybe giving -I<path_to_opencv3.1_include> before -I/usr/include could help but you may have to manage link as well with -L<path-to_opencv3.1_libs>.
If it doesn’t work, you can try to move opencv4tegra into a specific directory (I would suggest /usr/local/opencv4tegra-2.4.12), while installing opencv3.1.0 in /usr/local/opencv-3.1.0.
If you are familiar with package options, maybe you can reinstall properly in your new folder.
I had made that a dirty way, just moving folders opencv and opencv2 from usr/include to /usr/local/opencv4tegra-2.4.12/include, moving /usr/lib/libopencv* to /usr/local/opencv4tegra-2.4.12/lib.
(you should also move examples opencv* from /usr/bin folder and doc in /usr/share/doc). It was ok.
Then you can tell to gcc which one to choose for compiling and linking.
For linking or executing, you may have to set environement LD_LIBRARY_PATH to the libs you want to use. For example:
export LD_LIBRARY_PATH=/usr/cuda/lib:/usr/local/opencv-3.1.0/lib
[EDIT: Be aware that using pkg-config --cflags opencv will report false paths and should not be used any longer if you’ve moved opencv4tegra folder.]
[EDIT2: Seems now it is ok to let opencv4tergra in /usr and just say to gcc
gcc -I/usr/local/opencv-3.1.0/include mycode.cpp -L/usr/local/opencv-3.1.0/lib -lopencv_core ...and other libs... -o myapp
and set LD_LIBRARY_PATH accordingly for execution]