introlab / find-object

Find-Object project
http://introlab.github.io/find-object/
BSD 3-Clause "New" or "Revised" License
445 stars 188 forks source link

Gpu option is not working #45

Closed vmoysiadis closed 7 years ago

vmoysiadis commented 7 years ago

Hello, i am using find_object_3d with ros and kinect camera. How can i enable the gpu option for any detectors and descriptors?

matlabbe commented 7 years ago

OpenCV should be built with GPU/CUDA support to be enabled: screenshot from 2017-09-13 13-43-45 Note that only FAST, ORB and SURF have GPU option.

The default OpenCV installed with ROS would not have CUDA enabled. You should build OpenCV from source with CUDA enabled and then build from source find_object_2d package.

vmoysiadis commented 7 years ago

thank you for your quick response. I followed this tutorial https://gist.github.com/filitchp/5645d5eebfefe374218fa2cbf89189aa to build opencv with cuda enabled and your tutorial to build find_object_2d from source and i could not use gpu option note: I use find_object with ros

matlabbe commented 7 years ago

I tried OpenCV3.3 (opencv_contrib + cuda enabled) and gpu options are enabled in the standalone version. To make it with ROS, it is trickier as the package depends on opencv_bridge package, which links on OpenCV installed with ROS. If I tried this:

$ catkin_make -j2 VERBOSE=1 -DOpenCV_DIR=/usr/local/share/OpenCV --pkg find_object_2d

I get this linking:

~/catkin_ws/devel/lib/find_object_2d$ ldd find_object_2d | grep opencv
    libopencv_core3.so.3.2 => /opt/ros/kinetic/lib/libopencv_core3.so.3.2 (0x00007f755581b000)
    libopencv_xfeatures2d3.so.3.2 => /opt/ros/kinetic/lib/libopencv_xfeatures2d3.so.3.2 (0x00007f755537c000)
    libopencv_video.so.3.3 => /usr/local/lib/libopencv_video.so.3.3 (0x00007f75543c3000)
    libopencv_calib3d.so.3.3 => /usr/local/lib/libopencv_calib3d.so.3.3 (0x00007f755401c000)
    libopencv_videoio.so.3.3 => /usr/local/lib/libopencv_videoio.so.3.3 (0x00007f7553de6000)
    libopencv_xfeatures2d.so.3.3 => /usr/local/lib/libopencv_xfeatures2d.so.3.3 (0x00007f7552399000)
    libopencv_calib3d3.so.3.2 => /opt/ros/kinetic/lib/libopencv_calib3d3.so.3.2 (0x00007f7551e02000)
    libopencv_features2d3.so.3.2 => /opt/ros/kinetic/lib/libopencv_features2d3.so.3.2 (0x00007f7551b43000)
    libopencv_flann3.so.3.2 => /opt/ros/kinetic/lib/libopencv_flann3.so.3.2 (0x00007f75518f1000)
    libopencv_imgcodecs3.so.3.2 => /opt/ros/kinetic/lib/libopencv_imgcodecs3.so.3.2 (0x00007f75514cd000)
    libopencv_imgproc3.so.3.2 => /opt/ros/kinetic/lib/libopencv_imgproc3.so.3.2 (0x00007f754fd16000)
    libopencv_video3.so.3.2 => /opt/ros/kinetic/lib/libopencv_video3.so.3.2 (0x00007f754f992000)
    libopencv_videoio3.so.3.2 => /opt/ros/kinetic/lib/libopencv_videoio3.so.3.2 (0x00007f754f769000)
    libopencv_imgproc.so.3.3 => /usr/local/lib/libopencv_imgproc.so.3.3 (0x00007f7548ce4000)
    libopencv_core.so.3.3 => /usr/local/lib/libopencv_core.so.3.3 (0x00007f7547220000)
    libopencv_features2d.so.3.3 => /usr/local/lib/libopencv_features2d.so.3.3 (0x00007f7546f47000)
    libopencv_flann.so.3.3 => /usr/local/lib/libopencv_flann.so.3.3 (0x00007f7546ced000)
    libopencv_imgcodecs.so.3.3 => /usr/local/lib/libopencv_imgcodecs.so.3.3 (0x00007f754673b000)
    libopencv_cudaarithm.so.3.3 => /usr/local/lib/libopencv_cudaarithm.so.3.3 (0x00007f753a6ed000)

Note how some opencv 3.2 libraries are linked, so that it makes the GPU option disabled (as opencv installed by ros doesn't have gpu support). The cleanest solution would be to uninstall opencv3 of ROS, then remake by source all packages depending on opencv installed with ROS (like cv_bridge). That way, you will have only one OpenCV version to link on.

For info, here is my OpenCV log:

-- General configuration for OpenCV 3.3.0 =====================================
--   Version control:               unknown
-- 
--   Extra modules:
--     Location (extra):            /home/mathieu/workspace/opencv_contrib/modules
--     Version control (extra):     3.3.0
-- 
--   Platform:
--     Timestamp:                   2017-09-15T01:26:08Z
--     Host:                        Linux 4.4.0-93-generic x86_64
--     CMake:                       3.5.1
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
-- 
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2
--       SSE4_1 (2 files):          + SSSE3 SSE4_1
--       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (7 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 5.4.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):
--     Linker flags (Debug):
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          gtk-x11-2.0 gdk-x11-2.0 pangocairo-1.0 atk-1.0 cairo gdk_pixbuf-2.0 gio-2.0 pangoft2-1.0 pango-1.0 gobject-2.0 glib-2.0 fontconfig freetype gthread-2.0 /usr/lib/x86_64-linux-gnu/libwebp.so /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/libtiff.so /usr/lib/x86_64-linux-gnu/libjasper.so /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so dc1394 avcodec-ffmpeg avformat-ffmpeg avutil-ffmpeg swscale-ffmpeg dl m pthread rt cudart nppc nppi npps cufft -L/usr/local/cuda/lib64
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 cudev core cudaarithm flann imgproc ml objdetect video cudabgsegm cudafilters cudaimgproc cudawarping dnn imgcodecs photo shape videoio xobjdetect cudacodec highgui superres ts features2d calib3d ccalib cudafeatures2d cudalegacy cudaobjdetect cudastereo stereo videostab xfeatures2d ximgproc java optflow python2
--     Disabled:                    cudaoptflow stitching world aruco bgsegm bioinspired contrib_world datasets dnn_modern dpm face freetype fuzzy hdf img_hash line_descriptor phase_unwrapping plot reg rgbd saliency sfm structured_light surface_matching text xphoto
--     Disabled by dependency:      tracking
--     Unavailable:                 python3 viz cnn_3dobj cvv matlab
-- 
--   GUI: 
--     QT:                          NO
--     GTK+ 2.x:                    YES (ver 2.24.30)
--     GThread :                    YES (ver 2.48.2)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
--     WEBP:                        /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x0202)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.6)
--     JPEG 2000:                   /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
--     OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
--     GDAL:                        NO
--     GDCM:                        NO
-- 
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.4)
--     FFMPEG:                      YES
--       avcodec:                   YES (ver 56.60.100)
--       avformat:                  YES (ver 56.40.101)
--       avutil:                    YES (ver 54.31.100)
--       swscale:                   YES (ver 3.1.101)
--       avresample:                NO
--     GStreamer:                   NO
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     OpenNI2:                     NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     Aravis SDK:                  NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    NO/YES
--     XIMEA:                       NO
--     Xine:                        NO
--     Intel Media SDK:             NO
--     gPhoto2:                     NO
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Use Intel IPP:               2017.0.2 [2017.0.2]
--                at:               /home/mathieu/workspace/opencv-3.3.0/build/3rdparty/ippicv/ippicv_lnx
--     Use Intel IPP IW:            prebuilt binaries (2017.0.2)
--     Use Intel IPP Async:         NO
--     Use VA:                      NO
--     Use Intel VA-API/OpenCL:     NO
--     Use Lapack:                  NO
--     Use Eigen:                   YES (ver 3.2.92)
--     Use Cuda:                    YES (ver 8.0)
--     Use OpenCL:                  YES
--     Use OpenVX:                  NO
--     Use custom HAL:              NO
-- 
--   NVIDIA CUDA
--     Use CUFFT:                   YES
--     Use CUBLAS:                  NO
--     USE NVCUVID:                 NO
--     NVIDIA GPU arch:             20 30 35 37 50 52 60 61
--     NVIDIA PTX archs:
--     Use fast math:               NO
-- 
--   OpenCL:                        <Dynamic loading of OpenCL library>
--     Include path:                /home/mathieu/workspace/opencv-3.3.0/3rdparty/include/opencl/1.2
--     Use AMDFFT:                  NO
--     Use AMDBLAS:                 NO
-- 
--   Python 2:
--     Interpreter:                 /usr/bin/python2.7 (ver 2.7.12)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
--     packages path:               lib/python2.7/dist-packages
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.5.2)
-- 
--   Python (for build):            /usr/bin/python2.7
-- 
--   Java:
--     ant:                         /usr/bin/ant (ver 1.9.6)
--     JNI:                         /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
--     Java wrappers:               YES
--     Java tests:                  NO
-- 
--   Matlab:                        Matlab not found or implicitly disabled
-- 
--   Tests and samples:
--     Tests:                       NO
--     Performance tests:           NO
--     C/C++ Examples:              NO
-- 
--   Install path:                  /usr/local
-- 
--   cvconfig.h is in:              /home/mathieu/workspace/opencv-3.3.0/build
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done

cheers, Mathieu

vmoysiadis commented 7 years ago

Thank you so much. I was able to use gpu option both with and without ros, also the procedure to use ros with opencv3(from source) was a bit difficult