How to manage Tegra4OpenCV and OpenCV3.1 together on Jetson TX1

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.

cmake_minimum_required (VERSION 2.8)
set(OpenCV_DIR "/usr/share/OpenCV")
set(OpenCV_INCLUDE_DIRS "/usr/include/opencv" "/usr/include")


# To find OpenCV package
find_package(OpenCV REQUIRED)

    message("-- OpenCV version: ${OpenCV_VERSION}")
    message("-- OpenCV include directories: ${OpenCV_INCLUDE_DIRS}")
    message("-- OpenCV libraries: ${OpenCV_LIBS}")
    message("-- OpenCV directory: ${OpenCV_DIR}")
    add_executable(cv_hello cv_hello.cpp)
    target_link_libraries(cv_hello ${OpenCV_LIBS})

The output of cmake is as below:

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'
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:

CPPFLAGS+=`pkg-config --cflags opencv`
LDFLAGS+=`pkg-config --libs opencv`

and these lines for private-compiled opencv-3.x

CPPFLAGS+=-I/home/ubuntu/Work/tx1/opencv/opencv-3.1.0/build/include -D_GLIBCXX_USE_CXX11_ABI=0
LDFLAGS+=-L/home/ubuntu/Work/tx1/opencv/opencv-3.1.0/build/lib -L/usr/local/cuda/lib64 -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lopencv_detection_based_tracker -lopencv_esm_panorama -lopencv_facedetect -lopencv_imuvstab -lopencv_tegra -lopencv_vstab -lcufft -lnpps -lnppi -lnppc -lcudart -ltbb -lrt -lpthread -lm -ldl -lopencv_imgcodecs -lopencv_videoio


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.

This is my Makefile:

CFLAGS+=`pkg-config --cflags opencv`
LDFLAGS+=`pkg-config --libs opencv`


.PHONY: all clean
$(PROG): $(OBJS)
	$(CC) -o $(PROG) $(OBJS) $(LDFLAGS)

%.o: %.cpp
	$(CC) -c $(CFLAGS) $<

all: $(PROG)

	rm -f $(OBJS) $(PROG)

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'
Makefile:13: recipe for target 'cv_hello.o' failed
make: *** [cv_hello.o] Error 1

And the output of pkg-config --cflags opencv

-I/usr/local/include/opencv -I/usr/local/include

also the output of pkg-config --libs opencv

-L/usr/local/lib -lopencv_cudabgsegm -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_shape -lopencv_stitching -lopencv_cudafeatures2d -lopencv_superres -lopencv_cudacodec -lopencv_videostab -lopencv_cudaoptflow -lopencv_cudalegacy -lopencv_calib3d -lopencv_features2d -lopencv_objdetect -lopencv_highgui -lopencv_videoio -lopencv_photo -lopencv_imgcodecs -lopencv_cudawarping -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_video -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_cudaarithm -lopencv_core -lopencv_cudev

Any idea where goes wrong? Thanks.

Best Regards,

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]