GithubHelp home page GithubHelp logo

vision_opencv's Introduction

vision_opencv

ros2 vision_opencv contains packages to interface ROS 2 with OpenCV which is a library designed for computational efficiency and strong focus for real time computer vision applications. This repository contains:

  • cv_bridge: Bridge between ROS 2 image messages and OpenCV image representation
  • image_geometry: Collection of methods for dealing with image and pixel geometry
  • opencv_tests: Integration tests to use the capability of the packages with opencv
  • vision_opencv: Meta-package to install both cv_bridge and image_geometry

In order to use ROS 2 with OpenCV, please see the details within cv_bridge package.

vision_opencv's People

Contributors

bulwahn avatar carlosmccosta avatar christian-rauch avatar clalancette avatar de-vri-es avatar dimatura avatar dirk-thomas avatar eric-wieser avatar gaoethan avatar garaemon avatar ijnek avatar jensenb avatar k-okada avatar karsten1987 avatar liborw avatar lucasw avatar mattalvarado avatar mikaelarguedas avatar mintar avatar mjcarroll avatar pmusau17 avatar scottmonaghan avatar seanyen avatar sloretz avatar talregev avatar vrabaud avatar wjwwood avatar wkentaro avatar yadunund avatar yuohara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vision_opencv's Issues

cv_bridge broken in Groovy

When I run the first cv_bridge Python example on the ROS Wiki, I get the following error repeated over and over:

[ERROR] [WallTime: 1357692371.463472] bad callback: <bound method image_converter.callback of <__main__.image_converter instance at 0xac1378c>>
Traceback (most recent call last):
  File "/opt/ros/groovy/lib/python2.7/dist-packages/rospy/topics.py", line 678, in _invoke_callback
    cb(msg)
  File "/home/patrick/Dropbox/Robotics/ros/experimental-pi-robot-ros-pkg/pi_robot/pi_vision_test/nodes/cv_bridge_test.py", line 22, in callback
    cv_image = self.bridge.imgmsg_to_cv(data, "bgr8")
  File "/opt/ros/groovy/lib/python2.7/dist-packages/cv_bridge/cv_bridge.py", line 105, in imgmsg_to_cv
    source_type = self.encoding_as_cvtype(img_msg.encoding)
  File "/opt/ros/groovy/lib/python2.7/dist-packages/cv_bridge/cv_bridge.py", line 53, in encoding_as_cvtype
    return eval("cv.CV_%s" % encoding)
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'CV_yuv422'

I get the same error when trying to use cv_bridge in any of my own existing code--code that runs fine under both Electric and Fuerte.

proposal for adding visoin_examples repository

I'd like to propose new repository, that contains ros node for opencv examples, such as face detection, edge detection, template matching, optical flows....(https://github.com/Itseez/opencv/tree/master/samples/cpp)

The motivation is

  1. every one who learn vision based robotic behavior, they start from red-ball tracking or face recognition, but currently there are no collection of such simple vision processing example so that every one have to write their own code
  2. when I explain (advertise, push) ROS to other people, I'll explain "there are great collection of useful software modules and it is super easy to use them". and if we can run face detection example with just few seconds and the same software can run on different camera (usb cam vs kinect), then that will support my opinion.

here is the some list of existing vision node:

Wrong conversion from MONO16 to BGR8

Noticed that when I was trying to visualize some MONO16 images with rqt_image_view.
After some digging I found that rqt_image_view first tries to convert the input image to BGR8 using the cv_bridge functions.

There is a bug in the ordering when trying to perform color conversion with images of different depths. I've prepared a patch. Will send a PR.

toCvCopy Problems in Jade

I am following the C++ cv_bridge tutorial found here:

http://wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages

The provided code works fine in Ubuntu 14.04 with ROS Indigo. I am having problems with the same code in Ubuntu 15.04 with ROS Jade. If I attempt to run the tutorial node, I receive the following error when calling cv::namedWindow.

OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /tmp/buildd/ros-jade-opencv3-3.0.0-1vivid-20150620-1427/modules/highgui/src/window.cpp, line 517
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/ros-jade-opencv3-3.0.0-1vivid-20150620-1427/modules/highgui/src/window.cpp:517: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow

Using the instructions I found here, rebuilt OpenCV with gtk support:
http://stackoverflow.com/questions/30450602/opencv-3-0-python-imshow-error

Now when I run the tutorial node, the call to namedWindow() succeeds, I get an error when calling toCvCopy, that I am using an unknown/unsupported array type.

cv_bridge fails to link sensor_msgs on OSX

==> Processing catkin package: 'cv_bridge'
==> Building with env: '/opt/ros/groovy/env.sh'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/Users/me/Documents/Research/ros/catkin_ws/build_isolated/cv_bridge'
-- Boost version: 1.53.0
-- Found the following Boost libraries:
--   python
-- Using CATKIN_DEVEL_PREFIX: /Users/me/Documents/Research/ros/catkin_ws/devel_isolated/cv_bridge
-- Using CMAKE_PREFIX_PATH: /opt/ros/groovy
-- This workspace overlays: /opt/ros/groovy
-- Found gtest: gtests will be built
-- Using CATKIN_TEST_RESULTS_DIR: /Users/me/Documents/Research/ros/catkin_ws/build_isolated/cv_bridge/test_results
-- catkin 0.5.65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/me/Documents/Research/ros/catkin_ws/build_isolated/cv_bridge
==> make -j1 -l1 in '/Users/me/Documents/Research/ros/catkin_ws/build_isolated/cv_bridge'
Linking CXX shared library /Users/me/Documents/Research/ros/catkin_ws/devel_isolated/cv_bridge/lib/libcv_bridge.dylib
ld: warning: directory not found for option '-L/opt/ros/groovy/share/OpenCV/3rdparty/lib'
Undefined symbols for architecture x86_64:
  "sensor_msgs::image_encodings::TYPE_16SC1", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_16SC2", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_16SC3", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_16SC4", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_16UC1", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_16UC2", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_16UC3", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_16UC4", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_32FC1", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_32FC2", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_32FC3", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_32FC4", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_32SC1", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_32SC2", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_32SC3", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_32SC4", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_64FC1", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_64FC2", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_64FC3", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_64FC4", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BAYER_BGGR8", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BAYER_GBRG8", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BAYER_GRBG8", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BAYER_RGGB8", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::numChannels(std::string const&)", referenced from:
      cv_bridge::getConversionCode(std::string, std::string) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BAYER_BGGR16", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BAYER_GBRG16", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BAYER_GRBG16", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BAYER_RGGB16", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BGR8", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::RGB8", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BGR16", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BGRA8", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::MONO8", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::RGB16", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::RGBA8", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::BGRA16", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::MONO16", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::RGBA16", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::YUV422", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getFormat(std::string const&) in cv_bridge.cpp.o
      cv_bridge::getConversionCode(std::string, std::string) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::isMono(std::string const&)", referenced from:
      cv_bridge::getConversionCode(std::string, std::string) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::isBayer(std::string const&)", referenced from:
      cv_bridge::getConversionCode(std::string, std::string) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::isColor(std::string const&)", referenced from:
      cv_bridge::getConversionCode(std::string, std::string) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::bitDepth(std::string const&)", referenced from:
      cv_bridge::getConversionCode(std::string, std::string) in cv_bridge.cpp.o
      cv_bridge::toCvCopyImpl(cv::Mat const&, std_msgs::Header_<std::allocator<void> > const&, std::string const&, std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_8SC1", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_8SC2", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_8SC3", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_8SC4", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_8UC1", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_8UC2", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_8UC3", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
  "sensor_msgs::image_encodings::TYPE_8UC4", referenced from:
      cv_bridge::getCvType(std::string const&) in cv_bridge.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/me/Documents/Research/ros/catkin_ws/devel_isolated/cv_bridge/lib/libcv_bridge.dylib] Error 1
make[1]: *** [src/CMakeFiles/cv_bridge.dir/all] Error 2
make: *** [all] Error 2
Traceback (most recent call last):
  File "./src/catkin/bin/../python/catkin/builder.py", line 658, in build_workspace_isolated
    number=index + 1, of=len(ordered_packages)
  File "./src/catkin/bin/../python/catkin/builder.py", line 443, in build_package
    install, jobs, force_cmake, quiet, last_env, cmake_args, make_args
  File "./src/catkin/bin/../python/catkin/builder.py", line 297, in build_catkin_package
    run_command(make_cmd, build_dir, quiet)
  File "./src/catkin/bin/../python/catkin/builder.py", line 186, in run_command
    raise subprocess.CalledProcessError(proc.returncode, ' '.join(cmd))
CalledProcessError: Command '/opt/ros/groovy/env.sh make -j1 -l1' returned non-zero exit status 2
<== Failed to process package 'cv_bridge': 
  Command '/opt/ros/groovy/env.sh make -j1 -l1' returned non-zero exit status 2

groovy libopencv_calib3d link error

ROS Groovy
Ubuntu 12.04
Catkin

There is a bug in /opt/ros/groovy/share/OpenCV/OpenCVConfig.cmake when trying to link libopencv_calib3d.so.

Pre-fix, this error message is generated:

/usr/bin/ld: CMakeFiles/show_image.dir/src/show_image.cpp.o: undefined reference to symbol '_ZN2cv8solvePnPERKNS_11_InputArrayES2_S2_S2_RKNS_12_OutputArrayES5_bi'
/usr/bin/ld: note: '_ZN2cv8solvePnPERKNS_11_InputArrayES2_S2_S2_RKNS_12_OutputArrayES5_bi' is defined in DSO /opt/ros/groovy/lib/libopencv_calib3d.so.2.4 so try adding it to the linker command line
/opt/ros/groovy/lib/libopencv_calib3d.so.2.4: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make[2]: *** [/home/jay/research/s2p/catkin_ws/devel/lib/opencv_test/show_image] Error 1
make[1]: *** [opencv_test/CMakeFiles/show_image.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed

To fix it, edit OpenCVConfig.cmake and move opencv_calib3d before opencv_core on line 109 ( SET(OpenCV_LIB_COMPONENTS...)

diff:

109c109

< SET(OpenCV_LIB_COMPONENTS opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_objdetect;opencv_nonfree;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_calib3d;opencv_core;opencv_contrib)

SET(OpenCV_LIB_COMPONENTS opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_objdetect;opencv_nonfree;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d)

PinholeCameraModel::fromCameraInfo() may fail to initialize the projection matrix

If info.P contains only zeroes, then

image_geometry::PinholeCameraModel camera;
camera.fromCameraInfo(info);

results in camera having inconsistent internal state. In particular, camera.initialzed() returns true, but camera.projectionMatrix() returns a 0 x 0 matrix. The projection matrix should be 3 x 4 for an initialized camera model.

Full program illustrating the problem:

#include <ros/ros.h>
#include <image_geometry/pinhole_camera_model.h>
#include <sensor_msgs/CameraInfo.h>

int main() {

    sensor_msgs::CameraInfo info;
    image_geometry::PinholeCameraModel camera;

    // Uncommenting this line causes the unexpected behavior to disappear.
    // info.P[0] = 1;

    camera.fromCameraInfo(info);

    // prints "initialized: true"
    ROS_INFO("initialized: %s", camera.initialized() ? "true" : "false");

    // Expectation: at this point, `camera` should to be fully
    // initialized. This would imply that its projection matrix is of
    // size 3 x 4. On the contrary, it is still of size 0 x 0.

    // prints "rows: 0, cols: 0"
    ROS_INFO("rows: %d, cols: %d",
             camera.projectionMatrix().rows, camera.projectionMatrix().cols);


    // Either of these lines would cause a segfault:
    // ROS_INFO("fx: %f", camera.projectionMatrix()(0,0));
    // ROS_INFO("fx: %f", camera.fx());
}

Missing dependency upon nodelet

Shouldn't the package.xml specify a dependency upon nodelet? It's required by the opencv_apps package

I created a rosinstall file using rosinstall_generator which include vision_opencv, but catkin_make fails with:

-- +++ processing catkin package: 'opencv_apps'
-- ==> add_subdirectory(vision_opencv/opencv_apps)
-- Using these message generators: gencpp;geneus;genlisp;genpy
CMake Error at /home/marv/ros_base_ws/devel/share/catkin/cmake/catkinConfig.cmake:75 (find_package):
Could not find a package configuration file provided by "nodelet" with any
of the following names:

nodeletConfig.cmake
nodelet-config.cmake

Add the installation prefix of "nodelet" to CMAKE_PREFIX_PATH or set
"nodelet_DIR" to a directory containing one of the above files. If
"nodelet" provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
vision_opencv/opencv_apps/CMakeLists.txt:4 (find_package)

-- Configuring incomplete, errors occurred!

//include/opencv not found

I came across this issue when doing a full build of ROS from source in Fedora 21. I will first describe the error and then how I resolved it and then some details about my system.

The error:

at /usr/local/ros/jade/share/image_proc/cmake/image_procConfig.cmake:106 (message):
Project 'image_proc' specifies '//include/opencv' as an include dir, which
is not found.  It does neither exist as an absolute directory nor in
'/usr/local/ros/jade///include/opencv'.  Ask the maintainer 'Vincent Rabaud
<[email protected]>' to fix it.
Call Stack (most recent call first):
/usr/local/ros/jade/share/catkin/cmake/catkinConfig.cmake:75 (find_package)
CMakeLists.txt:4 (find_package)

Somehow my opencv location "/usr/include/opencv" is being stored as "//include/opencv"

I'm not much of a cmake wizard, but what I decided to do is comment out "DEPENDS
OpenCV" in the catkin_package macro in the files listed below.

src/image_pipeline/image_proc/CMakeLists.txt:21:  #DEPENDS OpenCV
src/image_transport_plugins/compressed_image_transport/CMakeLists.txt:15:  #DEPENDS OpenCV
src/image_transport_plugins/compressed_depth_image_transport/CMakeLists.txt:15:  #DEPENDS OpenCV
src/vision_opencv/image_geometry/CMakeLists.txt:11:               #DEPENDS OpenCV
src/vision_opencv/cv_bridge/CMakeLists.txt:18:  #DEPENDS OpenCV

With the above changes, I can successfully build jade on my machine. I'm new to
ROS, but fairly handy with Linux, so I can try to provide additional info if
needed.

Some details about my system:
Fedora 21 amd64
OpenCV installed via yum (/usr/include/opencv)
ROS installed to /usr/local/ros/jade/

Thanks for your work.

Broken opencv2 cmake config in hydro

With the recent update of the opencv2 package from 2.4.6 to 2.4.9 in ros/rosdistro@0ee098e image_geometry (and probably other packages) do not export the opencv2 libraries correctly in its catkin-generated config files. That's why several packages that depend on opencv2 indirectly via another package currently have linker errors in Jenkins, for example:

The cmake config of OpenCV is different for 2.4.6 and 2.4.9 and this results in a different pkg-config/cmake config of package image_geometry:

  • With ros-hydro-opencv2-2.4.6-3precise-20140303-2244-+0000 and ros-hydro-image-geometry-1.10.17-1precise-20140521-1853-+0000 from the public repo:

    $ cmake --find-package -DNAME=OpenCV -DCOMPILER_ID=GNU -DLANGUAGE=CXX -DMODE=LINK
    -rdynamic -ldebug /opt/ros/hydro/lib/libopencv_calib3d.so -ldebug /opt/ros/hydro/lib/libopencv_contrib.so -ldebug /opt/ros/hydro/lib/libopencv_core.so -ldebug /opt/ros/hydro/lib/libopencv_features2d.so -ldebug /opt/ros/hydro/lib/libopencv_flann.so -ldebug /opt/ros/hydro/lib/libopencv_gpu.so -ldebug /opt/ros/hydro/lib/libopencv_highgui.so -ldebug /opt/ros/hydro/lib/libopencv_imgproc.so -ldebug /opt/ros/hydro/lib/libopencv_legacy.so -ldebug /opt/ros/hydro/lib/libopencv_ml.so -ldebug /opt/ros/hydro/lib/libopencv_nonfree.so -ldebug /opt/ros/hydro/lib/libopencv_objdetect.so -ldebug /opt/ros/hydro/lib/libopencv_photo.so -ldebug /opt/ros/hydro/lib/libopencv_stitching.so -ldebug /opt/ros/hydro/lib/libopencv_superres.so -ldebug /opt/ros/hydro/lib/libopencv_ts.so -ldebug /opt/ros/hydro/lib/libopencv_video.so -ldebug /opt/ros/hydro/lib/libopencv_videostab.so -loptimized /opt/ros/hydro/lib/libopencv_calib3d.so -loptimized /opt/ros/hydro/lib/libopencv_contrib.so -loptimized /opt/ros/hydro/lib/libopencv_core.so -loptimized /opt/ros/hydro/lib/libopencv_features2d.so -loptimized /opt/ros/hydro/lib/libopencv_flann.so -loptimized /opt/ros/hydro/lib/libopencv_gpu.so -loptimized /opt/ros/hydro/lib/libopencv_highgui.so -loptimized /opt/ros/hydro/lib/libopencv_imgproc.so -loptimized /opt/ros/hydro/lib/libopencv_legacy.so -loptimized /opt/ros/hydro/lib/libopencv_ml.so -loptimized /opt/ros/hydro/lib/libopencv_nonfree.so -loptimized /opt/ros/hydro/lib/libopencv_objdetect.so -loptimized /opt/ros/hydro/lib/libopencv_photo.so -loptimized /opt/ros/hydro/lib/libopencv_stitching.so -loptimized /opt/ros/hydro/lib/libopencv_superres.so -loptimized /opt/ros/hydro/lib/libopencv_ts.so -loptimized /opt/ros/hydro/lib/libopencv_video.so -loptimized /opt/ros/hydro/lib/libopencv_videostab.so -ldebug -Wl,-rpath,/opt/ros/hydro/lib 
    
    $ cat /opt/ros/hydro/lib/pkgconfig/image_geometry.pc
    prefix=/opt/ros/hydro
    
    Name: image_geometry
    Description: Description of image_geometry
    Version: 1.10.17
    Cflags: -I/opt/ros/hydro/include -I/opt/ros/hydro/include/opencv
    Libs: -L/opt/ros/hydro/lib -limage_geometry -l:/opt/ros/hydro/lib/libopencv_calib3d.so -l:/opt/ros/hydro/lib/libopencv_contrib.so -l:/opt/ros/hydro/lib/libopencv_core.so -l:/opt/ros/hydro/lib/libopencv_features2d.so -l:/opt/ros/hydro/lib/libopencv_flann.so -l:/opt/ros/hydro/lib/libopencv_gpu.so -l:/opt/ros/hydro/lib/libopencv_highgui.so -l:/opt/ros/hydro/lib/libopencv_imgproc.so -l:/opt/ros/hydro/lib/libopencv_legacy.so -l:/opt/ros/hydro/lib/libopencv_ml.so -l:/opt/ros/hydro/lib/libopencv_nonfree.so -l:/opt/ros/hydro/lib/libopencv_objdetect.so -l:/opt/ros/hydro/lib/libopencv_photo.so -l:/opt/ros/hydro/lib/libopencv_stitching.so -l:/opt/ros/hydro/lib/libopencv_superres.so -l:/opt/ros/hydro/lib/libopencv_video.so -l:/opt/ros/hydro/lib/libopencv_videostab.so
    Requires: sensor_msgs
    
  • With ros-hydro-opencv2-2.4.9-1precise-20140613-1754-+0000 and ros-hydro-image-geometry_1.10.18-0precise-20140613-1913-+0000_amd64 from ros-shadow-fixed:

    $ cmake --find-package -DNAME=OpenCV -DCOMPILER_ID=GNU -DLANGUAGE=CXX -DMODE=LINK
    -rdynamic /opt/ros/hydro/lib/libopencv_videostab.so.2.4.9 /opt/ros/hydro/lib/libopencv_video.so.2.4.9 /opt/ros/hydro/lib/libopencv_ts.a /opt/ros/hydro/lib/libopencv_superres.so.2.4.9 /opt/ros/hydro/lib/libopencv_stitching.so.2.4.9 /opt/ros/hydro/lib/libopencv_photo.so.2.4.9 /opt/ros/hydro/lib/libopencv_ocl.so.2.4.9 /opt/ros/hydro/lib/libopencv_objdetect.so.2.4.9 /opt/ros/hydro/lib/libopencv_nonfree.so.2.4.9 /opt/ros/hydro/lib/libopencv_ml.so.2.4.9 /opt/ros/hydro/lib/libopencv_legacy.so.2.4.9 /opt/ros/hydro/lib/libopencv_imgproc.so.2.4.9 /opt/ros/hydro/lib/libopencv_highgui.so.2.4.9 /opt/ros/hydro/lib/libopencv_gpu.so.2.4.9 /opt/ros/hydro/lib/libopencv_flann.so.2.4.9 /opt/ros/hydro/lib/libopencv_features2d.so.2.4.9 /opt/ros/hydro/lib/libopencv_core.so.2.4.9 /opt/ros/hydro/lib/libopencv_contrib.so.2.4.9 /opt/ros/hydro/lib/libopencv_calib3d.so.2.4.9 -ldl -lm -lpthread -lrt /opt/ros/hydro/lib/libopencv_nonfree.so.2.4.9 /opt/ros/hydro/lib/libopencv_ocl.so.2.4.9 /opt/ros/hydro/lib/libopencv_gpu.so.2.4.9 /opt/ros/hydro/lib/libopencv_photo.so.2.4.9 /opt/ros/hydro/lib/libopencv_objdetect.so.2.4.9 /opt/ros/hydro/lib/libopencv_legacy.so.2.4.9 /opt/ros/hydro/lib/libopencv_video.so.2.4.9 /opt/ros/hydro/lib/libopencv_ml.so.2.4.9 /opt/ros/hydro/lib/libopencv_calib3d.so.2.4.9 /opt/ros/hydro/lib/libopencv_features2d.so.2.4.9 /opt/ros/hydro/lib/libopencv_highgui.so.2.4.9 /opt/ros/hydro/lib/libopencv_imgproc.so.2.4.9 /opt/ros/hydro/lib/libopencv_flann.so.2.4.9 /opt/ros/hydro/lib/libopencv_core.so.2.4.9 -Wl,-rpath,/opt/ros/hydro/lib 
    
    $ cat /opt/ros/hydro/lib/pkgconfig/image_geometry.pc
    prefix=/opt/ros/hydro
    
    Name: image_geometry
    Description: Description of image_geometry
    Version: 1.10.18
    Cflags: -I/opt/ros/hydro/include -I/opt/ros/hydro/include/opencv
    Libs: -L/opt/ros/hydro/lib -limage_geometry
    Requires: sensor_msgs
    

No change in image_geometry between 1.10.17 and 1.10.18 could explain the missing opencv export, so it must be the versioned library names in the exported OpenCV_LIBRARIES cmake variable that catkin_package(DEPENDS OpenCV2 ...) in image_geometry's CMakeLists.txt cannot handle.

bad build in ros-hydro-opencv2?

hello

Some of the code I'm maintaining that uses cv::HOGDescriptor started to crash after the recent release of ros-hydro-opencv2 (Jun 17). I checked on https://github.com/ros-gbp/opencv2-release.git and apparently it's still the same version 2.4.9, since last fall. So is there an explanation for this problem?

I'm 99.9% sure it's not on my side, as I tested with old version of my code that I know was working some weeks ago.

Brice

missing numpy dependency in package.xml

It seems cv_bridge/src/CmakeLists.txt needs numpy, but it is not declared in package.xml.
The package missing in ubuntu was python-numpy-dev, if that helps.

Groovy debs missing vision_opencv CvBridge.h

Under Fuerte, I can rosmake Eric Perko's uvc_cam package (https://github.com/ericperko/uvc_cam.git). However, under Groovy, rosmake now fails with the error:

uvc_cam_node.cpp:50:32: fatal error: cv_bridge/CvBridge.h: No such file or directory

In Fuerte, the CvBridge.h file is found at:

/opt/ros/fuerte/stacks/vision_opencv/cv_bridge/include/cv_bridge/CvBridge.h

but it does not appear to exist in the vision_opencv debian package for Groovy.

Is it possible to bring these include files back into Groovy?

ImportError: No module named cv_bridge_boost on Mac OS X

This seems to be related to ros-perception/image_pipeline#34

We (myself and @kyonifer) built groovy-dekstop using MacPorts on OS X 10.7.5 , and on using opencv_bridge (version 1.10.7) in python get the message:

ImportError: No module named cv_bridge_boost

More guessing that it has to do with something not detecting that cv_bridge_boost.dylib is created when compiling on the Mac vs cv_bridge_boost.so.

The library is compiled, and exists under $PYTHON_PATH at /opt/local/lib/python2.7/site-packages/cv_bridge/boost

edward:cv_bridge venabled$ ls -l /opt/local/lib/python2.7/site-packages/cv_bridge/boost
total 320
-rw-r--r--  1 root  admin       0 Aug  7 17:54 __init__.py
-rwxr-xr-x  1 root  admin  160988 Aug  7 17:55 cv_bridge_boost.dylib

Full code traceback:

Traceback (most recent call last):
  File "./evaluate_pnp.py", line 221, in <module>
    aspn_meas = np.array(bridge.imgmsg_to_cv(msg))
  File "/opt/local/lib/python2.7/site-packages/cv_bridge/core.py", line 101, in imgmsg_to_cv
    source_type = self.encoding_as_cvtype(img_msg.encoding)
  File "/opt/local/lib/python2.7/site-packages/cv_bridge/core.py", line 73, in encoding_as_cvtype
    from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: No module named cv_bridge_boost

cv_bridge::toCvCopy() segfaults on some inputs

The following program crashes with a segmentation fault.

#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/Image.h>

#include <iostream>

int main() {

    sensor_msgs::Image image;
    cv_bridge::CvImagePtr cv_ptr;

    image.encoding = "bgr8";
    image.height = 200;
    image.width = 200;

    try {
        cv_ptr = cv_bridge::toCvCopy(image, "mono8");
    } catch (cv_bridge::Exception& e) {
        ROS_ERROR("cv_bridge exception: %s", e.what());
    }
}

Note that line 339 of cv_bridge.cpp constructs a matrix like this:

  const cv::Mat tmp((int)source.height, (int)source.width, source_type,
                    const_cast<uint8_t*>(&source.data[0]), (size_t)source.step);

This call is unsafe if source.data is empty, or if source.height, source.width, and source.step do not accurately describe source.data.

Therefore, either:

  1. toCvCopy() should validate that source is well-formed before calling this constructor, or
  2. the cv_bridge documentation / tutorials should indicate that it is unsafe to call toCvCopy() on an inconsistent sensor_msgs/Image message.

Note, furthermore, that toCvShare() appears to suffer from a similar problem.

Bloom Release of vision_opencv for OpenCV3?

I realize it is possible to compile cv_bridge and the image_pipeline for OpenCV3 as mentioned in the ROS Answers post, but is it possible to do a Debian release built against OpenCV3? This may require specifying a separate install ros-indigo-cv3-bridge package from vision_opencv, but there is a precedent for this sort of thing with gazebo_ros_packages making releases depending on different versions of Gazebo (2.2, 5.0, etc.). Any thoughts on this level of Debian cross OpenCV(2<->3) support?

cv_bridge STILL exposes internal GTest symbols from OpenCV and/or links incorrectly

We closed issue #22 slightly preemptively. I still have this issue with just the cv_bridge package.

If we create a package as follows:

$ roscreate-pkg opencv_tests roscpp cv_bridge
$ cd opencv_tests
$ mkdir test
$ echo "rosbuild_add_gtest(test_opencv test/test_opencv.cpp)" >> CMakeLists.txt

and test_opencv.cpp contains

#include <gtest/gtest.h>

int main(int argc, char **argv)
{
  testing::InitGoogleTest(&argc, argv);

  ::testing::FLAGS_gtest_death_test_style = "threadsafe";

  return RUN_ALL_TESTS();
}

then we run make test, the test compiles, but crashes on destruction. This is because the library opencv_ts is linked incorrectly. I thought this was an opencv issue, but it seems like just a cv_bridge issue.

If we change the package by editing the manifest.xml and instead depend on image_geometry, which still depends on opencv2 the problem is not there.

Here is the comparison. With this manifest

<package>
  <description brief="opencv_tests">

     opencv_tests

  </description>
  <author>Chris Mansley</author>
  <license>BSD</license>
  <review status="unreviewed" notes=""/>
  <url>http://ros.org/wiki/opencv_tests</url>
  <depend package="roscpp"/>
  <depend package="cv_bridge"/>
</package>

and this command VERBOSE=1 make tests | grep opencv_ts. I get this line:

/usr/bin/c++   -O2 -g    -L/home/mac1pal/rdr/stacks/perception/opencv_tests/lib CMakeFiles/test_opencv.dir/test/test_opencv.cpp.o  -o ../bin/test_opencv -rdynamic -L/opt/ros/groovy/lib -L/home/mac1pal/rdr/stacks/perception/opencv_tests/lib -lroscpp -l:/usr/lib/libboost_signals-mt.so -l:/usr/lib/libboost_filesystem-mt.so -lxmlrpcpp -lcv_bridge -l:/opt/ros/groovy/lib/libopencv_calib3d.so -l:/opt/ros/groovy/lib/libopencv_contrib.so -l:/opt/ros/groovy/lib/libopencv_core.so -l:/opt/ros/groovy/lib/libopencv_features2d.so -l:/opt/ros/groovy/lib/libopencv_flann.so -l:/opt/ros/groovy/lib/libopencv_gpu.so -l:/opt/ros/groovy/lib/libopencv_highgui.so -l:/opt/ros/groovy/lib/libopencv_imgproc.so -l:/opt/ros/groovy/lib/libopencv_legacy.so -l:/opt/ros/groovy/lib/libopencv_ml.so -l:/opt/ros/groovy/lib/libopencv_nonfree.so -l:/opt/ros/groovy/lib/libopencv_objdetect.so -l:/opt/ros/groovy/lib/libopencv_photo.so -l:/opt/ros/groovy/lib/libopencv_stitching.so -l:/opt/ros/groovy/lib/libopencv_superres.so -l:/opt/ros/groovy/lib/libopencv_ts.so -l:/opt/ros/groovy/lib/libopencv_video.so -l:/opt/ros/groovy/lib/libopencv_videostab.so -lrosconsole -l:/usr/lib/libboost_regex-mt.so -l:/usr/lib/liblog4cxx.so -lroscpp_serialization -lrostime -l:/usr/lib/libboost_date_time-mt.so -l:/usr/lib/libboost_system-mt.so -l:/usr/lib/libboost_thread-mt.so -lpthread -lcpp_common ../lib/libgtest.so -lpthread -Wl,-rpath,/opt/ros/groovy/lib:/home/mac1pal/rdr/stacks/perception/opencv_tests/lib 

However, with this manifest (only changing cv_bridge to image_geometry):

<package>
  <description brief="opencv_tests">

     opencv_tests

  </description>
  <author>Chris Mansley</author>
  <license>BSD</license>
  <review status="unreviewed" notes=""/>
  <url>http://ros.org/wiki/opencv_tests</url>
  <depend package="roscpp"/>
  <depend package="image_geometry"/>
</package>

and this command VERBOSE=1 make tests | grep opencv_ts, grep fails to find opencv_ts in the link lines. But, other opencv libraries are correctly linked.

So, the story here is that it must be something in the cv_bridge package that is specifically adding the opencv_ts library. I don't know why this is happening.

optical flow in opencv_apps

Hi! First of all I'm quite new to ROS so I'm not sure whether this is a silly question.

What role do the opencv_apps play in this repository? Are those meant just as code examples and not meant to be used within 'proper' applications?

In short: is it advisable to use opencv_apps/Flow.msg and fback_flow_nodelet in my application or should I roll my own? The fact that fback_flow_nodelet unconditionally draws the flow visualization suggests that it's really meant more as an example application, rather than a general nodelet for optical flow.


If opencv_apps are meant to be useful apart from serving as a code example I would suggest a few changes (and gladly provide pull requests) to the optical flow part.

In particular I think that the definition of the flow messages should be different. In Flow.msg the flow vector is called velocity, but what fback_flow_nodelet and lk_flow_nodelet really compute are the motions between two frames in pixels irrespective of the time passed between the two frames. So either the nodelets need to scale the movement by the time between the frames, so that the velocity field in Flow.msg get a proper unit (px/s e.g.), or velocity needs to be renamed to displacement and a time field needs to be added to Flow.msg.

PS: great repo! ๐Ÿ‘ ๐Ÿ˜„

AttributeError: 'cv2.cv.cvmat' object has no attribute 'shape'

I'm not sure if this is an OpenCV issue or a cv_bridge issue but it started with cv_bridge so I'll post here first.

I have a Python ROS node that runs fine under Hydro. When switching to Indigo, the script first threw the error:

AttributeError: CvBridge instance has no attribute 'cv_to_imgmsg'

Somehow I figured out that this has been changed to cv2_to_imgsmsg so I did the substitution. Now I get the error in the subject line:

Traceback (most recent call last):
  File "/home/patrick/catkin_ws/src/rbx1/rbx1_vision/nodes/video2ros.py", line 199, in <module>
    main(sys.argv)
  File "/home/patrick/catkin_ws/src/rbx1/rbx1_vision/nodes/video2ros.py", line 193, in main
    v2r = Video2ROS()
  File "/home/patrick/catkin_ws/src/rbx1/rbx1_vision/nodes/video2ros.py", line 109, in __init__
    image_pub.publish(bridge.cv2_to_imgmsg(cv.fromarray(frame), "bgr8"))
  File "/opt/ros/indigo/lib/python2.7/dist-packages/cv_bridge/core.py", line 161, in cv2_to_imgmsg
    img_msg.height = cvim.shape[0]
AttributeError: 'cv2.cv.cvmat' object has no attribute 'shape'
Shutting down video2ros node.

The script I am trying to run is listed below:

#!/usr/bin/env python

""" video2ros.py - Version 1.1 2013-12-20

    Read in a recorded video file and republish as a ROS Image topic.

    Created for the Pi Robot Project: http://www.pirobot.org
    Copyright (c) 2012 Patrick Goebel.  All rights reserved.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details at:

    http://www.gnu.org/licenses/gpl.html

"""

import rospy
import sys
from cv2 import cv as cv
import cv2
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError

class Video2ROS:
    def __init__(self):
        rospy.init_node('video2ros', anonymous=False)

        rospy.on_shutdown(self.cleanup)

        """ Define the input (path to video file) as a ROS parameter so it
            can be defined in a launch file or on the command line """
        self.input = rospy.get_param("~input", "")

        """ Define the image publisher with generic topic name "output" so that it can
            be remapped in the launch file. """
        image_pub = rospy.Publisher("output", Image, queue_size=30)

        # The target frames per second for the video
        self.fps = rospy.get_param("~fps", 25)

        # Do we restart the video when the end is reached?
        self.loop = rospy.get_param("~loop", False)

        # Start the video paused?
        self.start_paused = rospy.get_param("~start_paused", False)

        # Show text feedback by default?
        self.show_text = rospy.get_param("~show_text", True)

        # Resize the original video?
        self.resize_video = rospy.get_param("~resize_video", False)

        # If self.resize_video is True, set the desired width and height here
        self.resize_width = rospy.get_param("~resize_width", 0)
        self.resize_height = rospy.get_param("~resize_height", 0)

        # Initialize a few variables
        self.paused = self.start_paused
        self.loop_video = True
        self.keystroke = None
        self.restart = False
        self.last_frame = None

        # Initialize the text font
        font_face = cv2.FONT_HERSHEY_SIMPLEX
        font_scale = 0.5

        # Define the capture object as pointing to the input file
        self.capture = cv2.VideoCapture(self.input)

        # Get the original frames per second
        fps = self.capture.get(cv.CV_CAP_PROP_FPS)

        # Get the original frame size
        self.frame_size = (self.capture.get(cv.CV_CAP_PROP_FRAME_HEIGHT), self.capture.get(cv.CV_CAP_PROP_FRAME_WIDTH))

        # Check that we actually have a valid video source
        if fps == 0.0:
            print "Video source", self.input, "not found!"
            return None        

        # Bring the fps up to the specified rate
        try:
            fps = int(fps * self.fps / fps)
        except:
            fps = self.fps

        # Create the display window
        cv.NamedWindow("Video Playback", True) # autosize the display
        cv.MoveWindow("Video Playback", 375, 25)

        # Create the CvBridge object
        bridge = CvBridge()

        # Enter the main processing loop
        while not rospy.is_shutdown():
            # Get the next frame from the video
            frame = self.get_frame()

            # Convert the frame to ROS format
            try:
                image_pub.publish(bridge.cv2_to_imgmsg(cv.fromarray(frame), "bgr8"))
            except CvBridgeError, e:
                print e

            # Create a copy of the frame for displaying the text
            display_image = frame.copy()

            if self.show_text:
                cv2.putText(display_image, "FPS: " + str(self.fps), (10, 20), font_face, font_scale, cv.RGB(255, 255, 0))
                cv2.putText(display_image, "Keyboard commands:", (20, int(self.frame_size[0] * 0.6)), font_face, font_scale, cv.RGB(255, 255, 0))
                cv2.putText(display_image, " ", (20, int(self.frame_size[0] * 0.65)), font_face, font_scale, cv.RGB(255, 255, 0))
                cv2.putText(display_image, "space - toggle pause/play", (20, int(self.frame_size[0] * 0.72)), font_face, font_scale, cv.RGB(255, 255, 0))
                cv2.putText(display_image, "     r - restart video from beginning", (20, int(self.frame_size[0] * 0.79)), font_face, font_scale, cv.RGB(255, 255, 0))
                cv2.putText(display_image, "     t - hide/show this text", (20, int(self.frame_size[0] * 0.86)), font_face, font_scale, cv.RGB(255, 255, 0))
                cv2.putText(display_image, "     q - quit the program", (20, int(self.frame_size[0] * 0.93)), font_face, font_scale, cv.RGB(255, 255, 0))

            # Merge the original image and the display image (text overlay)
            display_image = cv2.bitwise_or(frame, display_image)

            # Now display the image.
            cv2.imshow("Video Playback", display_image)

            """ Handle keyboard events """
            self.keystroke = cv.WaitKey(1000 / fps)

            """ Process any keyboard commands """
            if 32 <= self.keystroke and self.keystroke < 128:
                cc = chr(self.keystroke).lower()
                if cc == 'q':
                    """ user has press the q key, so exit """
                    rospy.signal_shutdown("User hit q key to quit.")
                elif cc == ' ':
                    """ Pause or continue the video """
                    self.paused = not self.paused
                elif cc == 'r':
                    """ Restart the video from the beginning """
                    self.restart = True
                elif cc == 't':
                    """ Toggle display of text help message """
                    self.show_text = not self.show_text        


    def get_frame(self):
        # If the video is paused, return the last frame
        if self.paused and not self.last_frame is None:
            frame = self.last_frame
        else:
            # Get the next frame
            ret, frame = self.capture.read()

        if frame is None:
            # If we've run out of frames, loop if set True
            if self.loop_video:
                self.restart = True     

        # Did we receive the restart command?
        if self.restart:
            # To restart, simply reinitialize the capture object
            self.capture = cv2.VideoCapture(self.input)
            self.restart = False
            ret, frame = self.capture.read()

        # Were we asked to resize the video?
        if self.resize_video:
            frame = cv2.resize(frame, (self.resize_width, self.resize_height))

        # Store the last frame for when we pause
        self.last_frame = frame

        return frame

    def cleanup(self):
            print "Shutting down video2ros node."
            cv2.destroyAllWindows()

def main(args):
    help_message =  "Hot keys: \n" \
          "\tq     - quit the program\n" \
          "\tr     - restart video from beginning\n" \
          "\tspace - toggle pause/play\n"

    print help_message

    try:
        v2r = Video2ROS()
    except KeyboardInterrupt:
        print "Shutting down video2ros..."
        cv2.destroyAllWindows()

if __name__ == '__main__':
    main(sys.argv)

Missing opencv_test dependency?

Hi there!

Once of my Turtlebot apps, which I am trying to get running crashes due to a missing dependency in cv_bridge. It is pulling in opencv_tests(*), which are not listed in the package.xml.

(*) in cv_bridge/src/cv_bridge/cv_bridge.py

import roslib
roslib.load_manifest('opencv_tests')
import rostest
import rospy
import unittest

import sensor_msgs.msg
import cv

Is that a bug or am I missing something?

PS: Here is the original bug: turtlebot/turtlebot_apps#23
PPS: In case opencv_tests is really needed, will you release it as well?

CvBridge not supporting no channel information (OpenCV at fault)

I don't know how much the error is because of CvBridge, but I have some problem with sending gray images over ROS, see:
https://stackoverflow.com/questions/26610235/ros-cvbridge-not-working-because-of-channel-information

The problem lays in that using functions like cv2.resize() when used on a gray image (x, y, channel=1) loses the channel information. Color images work perfectly fine because the channel information (3 channels) is not lost. Would it be possible to send gray images without channel information with CvBridge, do you know a way to not lose channel information or how to transform the number of channels to 3?

OpenCV linker errors in ROS Fuerte (reopened #5437 from code.ros.org)

This bug was already reported as #5437 on code.ros.org 9 months ago or at least the symptoms are the same. Although the bug was fixed by an update of the opencv.pc pkgconfig file, we again observe linker errors in jenkins for the fuerte version of our hector_worldmodel stack:

Linking CXX executable ../../bin/object_tracker
/usr/bin/ld: CMakeFiles/object_tracker.dir/object_tracker.o: undefined reference to symbol 'cv::fastFree(void*)'
/usr/bin/ld: note: 'cv::fastFree(void*)' is defined in DSO /opt/ros/fuerte/lib/libopencv_core.so so try adding it to the linker command line
/opt/ros/fuerte/lib/libopencv_core.so: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make[5]: *** [../bin/object_tracker] Error 1

(from http://jenkins.willowgarage.com:8080/view/FbinP64/job/ros-fuerte-hector-worldmodel_binarydeb_precise_amd64/60/console)

Note that we did not change the stack since the initial release more than two months ago and the object_tracker does not use opencv directly, but only indirectly via the image_geometry package. image_geometry exports the opencv pkgconfig flags via its manifest.xml file, but this seems to be insufficient due to the wrong ordering of linked libraries in rosbuild for dependent packages.

In groovy, the export section in image_geometry/package.xml is totally missing and I am not sure why the package compiles without errors here, although cv data types are referenced in the image_geometry's pinhole_camera_model.h header file (http://jenkins.willowgarage.com:8080/view/GbinP64/job/ros-groovy-hector-worldmodel_binarydeb_precise_amd64/36/console).

On my own machine the stack compiles without errors in fuerte and groovy with the current versions of ros-groovy-opencv2 (2.4.3-6precise-20130125-0338) / ros-fuerte-opencv2 (2.4.2-0precise-20120908-1624) and ros-groovy-image-transport (1.10.0-0precise-20130129-0755) / ros-fuerte-vision-opencv (1.8.8-s1349900876~precise) from ros-shadow-fixed, but jenkins is using newer versions:

Selecting previously unselected package ros-fuerte-opencv2.
Unpacking ros-fuerte-opencv2 (from .../ros-fuerte-opencv2_2.4.2-0precise-20130202-0927-+0000_amd64.deb) ...
Selecting previously unselected package ros-fuerte-vision-opencv.
Unpacking ros-fuerte-vision-opencv (from .../ros-fuerte-vision-opencv_1.8.8-s1359887542~precise_amd64.deb) ...

Was there an update that could have caused the above linker error?

package conflict

I am using Ubuntu 12.10 and ROS Groovy. 'ros-groovy-cv-bridge' depends on libavcodec53 and libavutil51, which conflicts with some other packages in Ubuntu.

For example, 'webots' depends on libavcode-extra-53 and libavutil-extra-51. However, libavcodec53 conflicts with libavcodec-extra-53, and libavutil51 conflicts with libavutil-extra-51. I cannot install both ros-groovy-cv-bridge and webots.

gtest dependency

This packages needs libgtest-dev to be built. Please add it to package.xml

duplicate empty opencv2.pc pkgconfig file installed in groovy

I am not sure if this is related to the vision_opencv stack, but as I did not find a separate bug tracker for the ROS packaged version of opencv2, I report it here:

The current Ubuntu package ros-groovy-opencv2 (version 2.4.3-6precise-20130125-0338-+0000) installs to pkgconfig files in /opt/ros/groovy/lib/pkgconfig, namely opencv.pc and opencv2.pc. The second file seems to be malformed, as it does not contain any includes or library definitions.

opencv.pc:

# Package Information for pkg-config

prefix=/opt/ros/groovy
exec_prefix=${prefix}
libdir=
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.4.3.2
Libs: -L${exec_prefix}/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_ts -lopencv_video -lopencv_videostab
Cflags: -I${includedir_old} -I${includedir_new}

opencv2.pc:

Name: opencv2
Description: Description of opencv2
Version: 2.4.3
Cflags: -I
Libs: -L/opt/ros/groovy/lib
Requires:

cv_bridge exposes internal GTest symbols from OpenCV and/or links incorrectly

If we create a package as follows:

$ roscreate-pkg opencv_tests roscpp cv_bridge
$ cd opencv_tests
$ mkdir test
$ echo "rosbuild_add_gtest(test_opencv test/test_opencv.cpp)" >> CMakeLists.txt

and test_opencv.cpp contains

#include <gtest/gtest.h>

int main(int argc, char **argv)
{
  testing::InitGoogleTest(&argc, argv);

  ::testing::FLAGS_gtest_death_test_style = "threadsafe";

  return RUN_ALL_TESTS();
}

then we run rosmake test, the test compiles, but crashes on destruction.

Here is the gdb output:

(gdb) bt
#0  0x00007ffff7285425 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff7288b8b in __GI_abort () at abort.c:91
#2  0x00007ffff72c339e in __libc_message (do_abort=2, fmt=0x7ffff73cd008 "*** glibc detected *** %s: %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:201
#3  0x00007ffff72cdb96 in malloc_printerr (action=3, str=0x7ffff73c9913 "free(): invalid pointer", ptr=<optimized out>) at malloc.c:5018
#4  0x0000000000400b67 in operator= (rhs=..., this=<optimized out>) at /usr/include/gtest/internal/gtest-string.h:285
#5  operator= (a_c_str=0x400e4c "threadsafe", this=<optimized out>) at /usr/include/gtest/internal/gtest-string.h:279
#6  main (argc=1, argv=<optimized out>) at /home/user/opencv_tests/test/test_opencv.cpp:7
(gdb) 

When I get this error, it typically is because GTest and OpenCV are fighting about symbols. In other words, OpenCV includes a version of GTest and we are linking against the wrong one.

Image Message step handling broken

The cv_bridge handling of the image step size field of an image message is broken. Introduced in ee10a9d there is now an invariant when converting ROS Image Messages to cv::Mat instances where the step size has to be equal to the image element size * the number of channels * the image width. If this invariant is not fulfilled an exception is thrown, crashing rqt_image_view for example. This is requirement is not listed on the wiki page, and is not listed in the Image Message documentation: http://docs.ros.org/api/sensor_msgs/html/msg/Image.html. Aligned Image Messages are thus no longer supported.

I see no reason why the cv_bridge step handling has to forbid aligned images, when the underlying OpenCV API has no problem with this.

Python imgmsg_to_cv2 memory leak

When using the imgmsg_to_cv2 function from Python cv_bridge.CvBridge class, memory is leaked if colour conversion is performed. I am using the latest Hydro release, code like this:

    def image_cb(self, image):
            try:
                ## This leaks, using colour conversion:
                #self._image = self.bridge.imgmsg_to_cv2(image, "bgr8")
                ## This works, no conversions:
                self._image = self.bridge.imgmsg_to_cv2(image)
            except CvBridgeError, e:
                print e

Looking at the refcounts for self._image.block, they are screwed up when using colour conversion and fine otherwise. Am I just missing something?

Grayscale images

Hej there,

thank you for this nice little package, it currently helps me playing around with some opencv-algorithms on rosbag recordings.

However, support for grayscale images would be great. I had to change the code at some points so it didn't crash on cv::cvtColor. The code (or diff) I used is

  /// Convert image to gray and blur it
  + if ( frame.channels() > 1 ) {
     cv::cvtColor( frame, src_gray, cv::COLOR_RGB2GRAY );
  + } else {
  +   src_gray = frame;
  + }
  cv::blur( src_gray, src_gray, cv::Size(3,3) );

I fixed it in findContours, generalContours and HoughCircles, but I guess this could be useful in other nodelets as well. What's your opinion about this?

[Python] rectifyPoint is broken since OpenCV 2 Python API change

Just realized the Python rectifyPoint() method (in PinholeCameraModel inside image_geometry package) is broken, probably since the OpenCV 2 Python API change in this commit.

It seems the cv2.undistortPoints() function in Python (OpenCV 2 API) behaves differently than in OpenCV 1 (they don't document it apparently). Possible solution: the input argument src has to be a 3d array (?).

Just uncomment this line in the test and run it, and you will see it crash and give this error:

OpenCV Error: Assertion failed (src.isContinuous() && (src.depth() == CV_32F || src.depth() == CV_64F) && ((src.rows == 1 && src.channels() == 2) || src.cols*src.channels() == 2)) in undistortPoints, file /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/undistort.cpp, line 394
test_monocular ... ERROR!
ERROR: /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/undistort.cpp:394: error: (-215) src.isContinuous() &amp;&amp; (src.depth() == CV_32F || src.depth() == CV_64F) &amp;&amp; ((src.rows == 1 &amp;&amp; src.channels() == 2) || src.cols*src.channels() == 2) in function undistortPoints

broken dependencies?

My colleague messed up his system, and so we had to reinstall ROS, and rebuild the workspace. We ran into an interesting issue that I believe is worth reporting.

Although he had installed image_proc, and vision_opencv, etc. (we tried a lot of stuffs to get it to work), it had not installed ros-hydro-opencv2... It was instead compiling against the libopencv deb. As a result it was complaining that there was no rule for target /opt/ros/hydro/lib/opencv_videostab.so.2.4.9 (from memory).

Installing ros-hydro-opencv2 fixed the problem, but I was surprised that it was not installed directly from installing image_proc and friends.

cv_bridge does not support endianness

Original bug report by @jack-oquin

I am trying to add the mono16 IIDC 1394 modes back in for Diamondback. They did not work in Cturtle, https://code.ros.org/trac/ros-pkg/ticket/4142 fixed a crash, but did not make those modes work.

The image_view node still does not display the images correctly. The IIDC specification requires hardware images to provide multi-byte pixels in big endian format. I do not think swapping the bytes in the driver is a good solution.

If we are not going to support the is_bigendian field in the Image message, we should remove it and document the fact that all multi-byte data must be little-endian (or is that "whatever byte orientation is supported by the system the driver runs on").

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.