Revision 6 as of 2016-03-17 22:23:02

Clear message

Only released in EOL distros:  

Package Summary

OpenCV 3.0: NOT FINAL

  • Maintainer: Edgar Riba <edgar.riba AT gmail DOT com>
  • Author: The OpenCV team
  • License: BSD
  • External website: http://opencvg.org

Package Summary

OpenCV 3.0

  • Maintainer status: maintained
  • Maintainer: Vincent Rabaud <vincent.rabaud AT gmail DOT com>
  • Author: The OpenCV team
  • License: BSD
  • External website: http://opencvg.org

Package Summary

OpenCV 3.x

  • Maintainer status: maintained
  • Maintainer: Vincent Rabaud <vincent.rabaud AT gmail DOT com>
  • Author: The OpenCV team
  • License: BSD
  • External website: http://opencv.org

Package Summary

OpenCV 3.x

  • Maintainer status: maintained
  • Maintainer: Vincent Rabaud <vincent.rabaud AT gmail DOT com>
  • Author: The OpenCV team
  • License: BSD
  • External website: http://opencv.org

Package Summary

OpenCV 3.x

  • Maintainer status: maintained
  • Maintainer: Vincent Rabaud <vincent.rabaud AT gmail DOT com>
  • Author: The OpenCV team
  • License: BSD
  • External website: http://opencv.org

Status

Since Indigo, there is a package for OpenCV3. It contains the opencv and opencv_contrib repos from https://github.com/Itseez. Some modules might not get included because the dependencies are hard to package for all platforms (e.g. the optical character recognition module that needs tesseract).

OpenCV3 will most likely be the default for Kinetic. Discussion is happening at https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/ros-sig-perception/K5__71SX7eU/mxWwn3AeAwAJ

Usage

You would use OpenCV3 as you would usually outside of ROS but let's explain a few corner cases:

  • if you have OpenCV2 and OpenCV3 installed, find_package(OpenCV) in CMake will first fine OpenCV3. If you want to explicitly link to OpenCV2, use find_package(OpenCV 2)

  • if you have OpenCV2 and OpenCV3 installed, OpenCV3 is not on your path: libraries and headers are renamed to only be visible through CMake. Python is the only exception but you can use the guide below to get your code to work with both.
  • just like with any library, you have to be careful that your binary does not link directly or indirectly (through a dependency) to both OpenCV2 and OpenCV3.

Migration

Switching code to OpenCV3 can be done following the official guide at http://docs.opencv.org/master/db/dfa/tutorial_transition_guide.html.

The rosdep key is opencv3.

Dual Compatibility

Now, as a maintainer, you might want to not duplicate branches and keep you code compatibility with OpenCV2. It is actually easy to write code compatible with OpenCV 2.4.9+ and 3+.

Python

Toggle line numbers
   1 import cv2
   2 from distutils.version import LooseVersion
   3 if LooseVersion(cv2.__version__).version[0] == 2:
   4     # Whatever OpenCV2 code
   5 else:
   6     # Whatever OpenCV3 code

C++

#include "opencv2/core/version.hpp"
#if CV_MAJOR_VERSION == 2
// do opencv 2 code
#elif CV_MAJOR_VERSION == 3
// do opencv 3 code
#endif

Also, if you write OpenCV3 code, chances are high that it will also compile with OpenCV 2.4.9+. E.g., in color conversion, when replacing CV_BGR2GRAY by cv::COLOR_RGB2GRAY, your code will also compile in OpenCV2 as this API has been backported (and not documented ...).

CMake

if(OpenCV_VERSION VERSION_LESS "3.0")
# use 2.4 modules
else()
# use 3.x modules
endif()

package.xml

Instead of depending on opencv3, you should depend on cv_bridge or image_geometry. Depending on one of those two keys transitively makes you depend on libopencv-dev on Jade and below, or opencv3 on Kinetic and above.

image_pipeline will only pull in sensor_msgs as an extra dependency while cv_bridge will also pull in boost, python and rosconsole so it depends on whether you go for something small or something you need.

Building the Package

The package is slightly patched from upstream to not build certain things like tests and examples. It is released through bloom using a tar file as source. This tar file is obtained with the following:

Toggle line numbers
   1 #!/bin/bash
   2 mkdir tmp
   3 cd tmp
   4 # the two lines below will fail in case it's not the first time we clone
   5 git clone --depth 1 https://github.com/Itseez/opencv.git
   6 git clone --depth 1 https://github.com/Itseez/opencv_contrib.git
   7 
   8 # revert the main CMakeLists.txt file in case it's not the first time
   9 cd opencv
  10 git clean -dxf
  11 git reset --hard HEAD
  12 git pull --rebase
  13 cp ../../package.xml ./
  14 
  15 cd ../opencv_contrib
  16 git pull --rebase
  17 cd ../
  18 
  19 cp -fr ./opencv_contrib/modules ./opencv/opencv_contrib
  20 
  21 cd opencv
  22 # revert the main CMakeLists.txt file in case it's not the first time
  23 cd opencv && git checkout CMakeLists.txt && cd ../
  24 sed -i 's/set(OPENCV_EXTRA_MODULES_PATH "" CACHE PATH "Where to look for additional OpenCV modules")/set(OPENCV_EXTRA_MODULES_PATH "${CMAKE_CURRENT_SOURCE_DIR}\/opencv_contrib\/" CACHE PATH "Where to look for additional OpenCV modules")/' ./CMakeLists.txt
  25 sed -i 's/OCV_OPTION(BUILD_TESTS              "Build accuracy \& regression tests"           ON  IF (NOT APPLE_FRAMEWORK) )/OCV_OPTION(BUILD_TESTS              "Build accuracy \& regression tests"           OFF)/' ./CMakeLists.txt
  26 sed -i 's/OCV_OPTION(BUILD_PERF_TESTS         "Build performance tests"                     ON  IF (NOT APPLE_FRAMEWORK) )/OCV_OPTION(BUILD_PERF_TESTS         "Build performance tests"                     OFF)/' ./CMakeLists.txt
  27 sed -i 's/OCV_OPTION(WITH_QT             "Build with Qt Backend support"               OFF  IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )/OCV_OPTION(WITH_QT             "Build with Qt Backend support"               ON  IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )/' ./CMakeLists.txt
  28 sed -i 's/OCV_OPTION(INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help with side by side installs." OFF IF (UNIX AND NOT ANDROID AND NOT APPLE_FRAMEWORK AND BUILD_SHARED_LIBS) )/OCV_OPTION(INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help with side by side installs." ON)/' ./CMakeLists.txt
  29 #sed -i 's/OCV_OPTION(WITH_IPP            "Include Intel IPP support"                   NOT MINGW IF (X86_64 OR X86) AND NOT WINRT )/OCV_OPTION(WITH_IPP            "Include Intel IPP support"                   OFF)/' ./CMakeLists.txt
  30 sed -i 's/set(OPENCV_DLLVERSION "")/set(OPENCV_DLLVERSION "3")/' ./CMakeLists.txt
  31 echo "install(FILES package.xml DESTINATION share/opencv3)" >> ./CMakeLists.txt
  32 
  33 cd ../
  34 
  35 # when configuring bloom the first time, use the tar file created above
  36 rm ./opencv.tar.gz
  37 tar --exclude-vcs -zcvf ./opencv.tar.gz ./opencv/*

Future

OpenCV3 still evolves a lot, though the API is stable. You can expect more GSOC projects to be integrated and more CMake modularity.