Search code examples
opencvubuntu-18.04header-filesjetson-xavier

Linking opencv 3.2 for cv_bridge in Ubuntu 18.04 Jetson


I need to use cv_bridge and transfer the images to vison wx. I am using makefile to link / compile. The problem I have is I don't know where the header files are for the opencv 3.2 libraries. This is on a Jetson Xavier, opencv 3.2 may have been installed by the SDK Manager, or I may have installed it later. Anyway, I just reinstalled it now using the command

sudo apt-get install --reinstall libopencv-core3.2

To identify the compiler and linker flags, I run the the two pkg-config commands

pkg-config --cflags cv_bridge

-I/opt/ros/melodic/include -I/usr/include/opencv -I/opt/ros/melodic/include

pkg-config --libs cv_bridge 

-L/opt/ros/melodic/lib -lcv_bridge /usr/lib/aarch64-linux-gnu/libopencv_core.so.3.2.0 /usr/lib/aarch64-linux-gnu/libopencv_imgproc.so.3.2.0 /usr/lib/aarch64-linux-gnu/libopencv_imgcodecs.so.3.2.0 -lrosconsole -lrosconsole_log4cxx -lrosconsole_backend_interface /usr/lib/aarch64-linux-gnu/liblog4cxx.so /usr/lib/aarch64-linux-gnu/libboost_regex.so /usr/lib/aarch64-linux-gnu/libboost_system.so /usr/lib/aarch64-linux-gnu/libboost_thread.so /usr/lib/aarch64-linux-gnu/libboost_chrono.so /usr/lib/aarch64-linux-gnu/libboost_date_time.so /usr/lib/aarch64-linux-gnu/libboost_atomic.so /usr/lib/aarch64-linux-gnu/libpthread.so -lroscpp_serialization -lrostime /usr/lib/aarch64-linux-gnu/libboost_date_time.so /usr/lib/aarch64-linux-gnu/libboost_system.so /usr/lib/aarch64-linux-gnu/libboost_thread.so /usr/lib/aarch64-linux-gnu/libboost_chrono.so /usr/lib/aarch64-linux-gnu/libboost_atomic.so /usr/lib/aarch64-linux-gnu/libpthread.so -lcpp_common /usr/lib/aarch64-linux-gnu/libboost_system.so /usr/lib/aarch64-linux-gnu/libboost_thread.so /usr/lib/aarch64-linux-gnu/libboost_chrono.so /usr/lib/aarch64-linux-gnu/libboost_date_time.so /usr/lib/aarch64-linux-gnu/libboost_atomic.so /usr/lib/aarch64-linux-gnu/libpthread.so /usr/lib/aarch64-linux-gnu/libconsole_bridge.so.0.4

From the above output, there is a opencv core library at

ls /usr/lib/aarch64-linux-gnu/libopencv_core.so.3.2.0

/usr/lib/aarch64-linux-gnu/libopencv_core.so.3.2.0

The problem is I can't find the header files for opencv 3.2. From the output above, the header files should be in directory

-I/usr/include/opencv

In directory /usr/include/opencv, there is a subdirectory

/usr/include/opencv4/opencv2_orig/core/version.hpp

And that contains the version.hpp file which contains these lines showing the version is version is 4.1.1.

file: /usr/include/opencv4/opencv2_orig/core/version.hpp

#define CV_VERSION_MAJOR    4
#define CV_VERSION_MINOR    1
#define CV_VERSION_REVISION 1

So, how can I install the header files for opencv version 3.2, that go with cv_bridge? Also, there may be a ROS package solution to this question, that may be more appropriate since cv_bridge library is in /opt/ros/melodic/lib.

Hmmm I see there's no tag for cv-bridge. I think that means I'm in the wrong blog. Any suggestion where I should post this question?


Solution

  • Opencv 3.2 can be installed using the command below, and the header files are placed in /usr/include/opencv2. I believe what has occurred is opencv4 was installed, and at that time the header files for opencv 3.2 were removed.

    sudo apt install libopencv-dev=3.2.0+dfsg-4ubuntu0.1
    

    Here is an example of linking cpp code step_2 with rosbag, cv_bridge, and opencv (3.2). The include -I/opt/ros/melodic/include is not required, it is generated by the rosbag pkg-config command, but is included for clarity, to identify location of cv_bridge header.

    g++ step_2.cpp -o step_2  `pkg-config --cflags --libs rosbag` \
        -I/opt/ros/melodic/include \
        -L/usr/lib/aarch64-linux-gnu/ -lopencv_core -lopencv_highgui \
        -L/opt/ros/melodic/lib -lcv_bridge
    

    ref ros perception