OpenCV Installing and Cross-Compiling for DrivePX2

Hello,

I want to run a simple OpenCV based program on DrivePX2 Autochauffeur. I have been searching and trying suggestions from the forum for a few days and it seems that I am doing something wrong. Does a complete guide on how to install OpenCV libraries and then cross-compile my source code exist?

My Host PC and Drive PX2 have the latest versions of DriveWorks and all the libraries.

I have tried the steps described in OpenCV. Based on the “git checkout” commands, it seems to install the OpenCV version 3.1, could this cause any problem with the dw or cuda versions?
Does changing -DCMAKE_INSTALL_PREFIX from “/usr” to “~/opencv/build/install” make any difference?

Assuming a successful setup using these instructions on the Host PC, do I have to run a similar procedure on the Drive platform?

And finally, in order to cross-compile the source code, are the following lines on CMakeLists.txt sufficient?
find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries(${PROJECT_NAME} ${OPENCV_LIBS})

Thank you

Dear @hroniss,
Did you check the discussion on Opencv Unable to stop the stream: Inappropriate ioctl for device?

Thanks for your reply,

I have tried it and got the error

Can't open
  /home/kyriaz/nvidia/nvidia_sdk/DRIVE/Linux/5.0.10.3/OSPDK/DrivePDK/drive-t186ref-linux//lib-target/version-nv-(pdk/sdk).txt
  for PDK branch detection

due to the -DVIBRANTE_PDK option. Is this PDK path correct? Because in my ~nvidia/nvidia_sdk directory, I only have these two folders:

  • DRIVE_OS_5.0.10.3_SDK_with_DriveWorks_Linux_OS

  • DRIVE_OS_5.0.10.3_SDK_with_DriveWorks_Linux_OS_PX2_AUTOCHAUFFEUR

and for cross-compilation I am using -DVIBRANTE_PDK:STRING=$PATH_TO_DRIVE,
(PATH_TO_DRIVE=~/nvidia/nvidia_sdk/DRIVE_OS_5.0.10.3_SDK_with_DriveWorks_Linux_OS_
PX2_AUTOCHAUFFEUR/DriveSDK/drive-t186ref-linux)

Thanks in advance

Update,

I have tried the guide above on a fresh install of ubuntu 16.04, with a few changes, such as:

  • DVIBRANTE_PDK:STRING=PATH_TO_DRIVE=~/nvidia/nvidia_sdk/DRIVE_OS_5.0.10.3_SDK_with_DriveWorks_Linux_OS_PX2_AUTOCHAUFFEUR/DriveSDK/drive-t186ref-linux

  • -DBUILD_opencv_highgui=ON

  • -DWITH_GTK=ON

The build and install was successful. Then I added openCV libraries in the CMakeLists.txt file.

project(${PROJECT_NAME} C CXX)

#------------------------------------------------------------------------------
# OpenCV
#------------------------------------------------------------------------------
set(CMAKE_PREFIX_PATH "/home/kyriaz/opencv/build/install")

find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )

#-------------------------------------------------------------------------------
# Project files
#-------------------------------------------------------------------------------
set(SOURCES
    main.cpp
)

set(LIBRARIES
    ${OPENCV_LIBS}
    ${Driveworks_LIBRARIES}
    dw_samples_framework    
)

#-------------------------------------------------------------------------------
# Final target
#-------------------------------------------------------------------------------
cuda_add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBRARIES})
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Samples")

# ------------------------------------------------------------------------------
# Install target
# ------------------------------------------------------------------------------
sdk_add_sample(${PROJECT_NAME})

Cmake runs without errors, but running ‘make -j’ yields indefined references to cv:: as seen below:

kyriaz@kyriaz-Linux:~/build$ make -j
Scanning dependencies of target update_cuda_deps
Scanning dependencies of target lodepng-src
Scanning dependencies of target glfw
[  0%] Built target update_cuda_deps
[  4%] Building CXX object 3rdparty/src/lodepng/CMakeFiles/lodepng-src.dir/src/lodepng.cpp.o
[  9%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/window.c.o
[ 14%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/input.c.o
[ 23%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/context.c.o
[ 23%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/vulkan.c.o
[ 28%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/init.c.o
[ 33%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/monitor.c.o
[ 38%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/posix_time.c.o
[ 42%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/x11_window.c.o
[ 47%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/x11_init.c.o
[ 52%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/x11_monitor.c.o
[ 57%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/posix_tls.c.o
[ 61%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/egl_context.c.o
[ 66%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/xkb_unicode.c.o
[ 71%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/linux_joystick.c.o
[ 76%] Building C object 3rdparty/src/glfw/3.2-screen/src/CMakeFiles/glfw.dir/glx_context.c.o
[ 80%] Linking C static library libglfw3.a
[ 80%] Built target glfw
[ 85%] Linking CXX static library liblodepng-src.a
[ 85%] Built target lodepng-src
Scanning dependencies of target dw_samples_framework
[ 90%] Linking CXX static library libdw_samples_framework.a
[ 90%] Built target dw_samples_framework
Scanning dependencies of target kkyriaz
[ 95%] Building CXX object src/drivenet/CMakeFiles/kkyriaz.dir/main.cpp.o
[100%] Linking CXX executable kkyriaz
CMakeFiles/kkyriaz.dir/main.cpp.o: In function `cvflann::anyimpl::big_any_policy<cv::String>::move(void* const*, void**)':
main.cpp:(.text._ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE4moveEPKPvPS5_[_ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE4moveEPKPvPS5_]+0x18): undefined reference to `cv::String::deallocate()'
main.cpp:(.text._ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE4moveEPKPvPS5_[_ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE4moveEPKPvPS5_]+0x30): undefined reference to `cv::String::deallocate()'
CMakeFiles/kkyriaz.dir/main.cpp.o: In function `cvflann::anyimpl::big_any_policy<cv::String>::static_delete(void**)':
main.cpp:(.text._ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE13static_deleteEPPv[_ZN7cvflann7anyimpl14big_any_policyIN2cv6StringEE13static_deleteEPPv]+0x1c): undefined reference to `cv::String::deallocate()'
CMakeFiles/kkyriaz.dir/main.cpp.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4c): undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/kkyriaz.dir/main.cpp.o: In function `cv::Mat::~Mat()':
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x8c): undefined reference to `cv::fastFree(void*)'
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x9c): undefined reference to `cv::Mat::deallocate()'
CMakeFiles/kkyriaz.dir/main.cpp.o: In function `main':
main.cpp:(.text.startup+0x34): undefined reference to `cv::imread(cv::String const&, int)'
main.cpp:(.text.startup+0x40): undefined reference to `cv::String::deallocate()'
main.cpp:(.text.startup+0x70): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
main.cpp:(.text.startup+0x78): undefined reference to `cv::String::deallocate()'
main.cpp:(.text.startup+0x80): undefined reference to `cv::waitKey(int)'
main.cpp:(.text.startup+0x84): undefined reference to `cv::destroyAllWindows()'
main.cpp:(.text.startup+0xac): undefined reference to `cv::String::deallocate()'
main.cpp:(.text.startup+0xc0): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
src/drivenet/CMakeFiles/kkyriaz.dir/build.make:113: recipe for target 'src/drivenet/kkyriaz' failed
make[2]: *** [src/drivenet/kkyriaz] Error 1
CMakeFiles/Makefile2:326: recipe for target 'src/drivenet/CMakeFiles/kkyriaz.dir/all' failed
make[1]: *** [src/drivenet/CMakeFiles/kkyriaz.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

I am trying to cross compile the following simple program:

#include<opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;


int main()
{	
	Mat image = imread("./roadsign.png");
	imshow("test", image);    
    waitKey(0);
    destroyAllWindows();

    return 0;
}

Any Ideas on what is the problem ?

Dear @hroniss,
My apologies for missing the update. Do you still have issue with opencv? Could you please update the latest status for further guidance.