ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Questions about openCV installation and tutorial

asked 2014-08-24 04:25:54 -0500

Andromeda gravatar image

Hi everybody,

Question #1: I installed opencv opencv2 and cv_bridge as explained it the realtive sections. So I wrote a simple program to use opencv and I got lot of problems. Then I tried to simply copy and paste the script in the tutorial and I get now:

/home/wilhem/workspace_ros/src/cam_experiment/src/main.cpp: In function ‘void imageCallback(const ImageConstPtr&)’: /home/wilhem/workspace_ros/src/cam_experiment/src/main.cpp:43:3: error: ‘CvBridge’ is not a member of ‘sensor_msgs’ sensor_msgs::CvBridge bridge; ^ /home/wilhem/workspace_ros/src/cam_experiment/src/main.cpp:43:25: error: expected ‘;’ before ‘bridge’
sensor_msgs::CvBridge bridge; ^

here is my CMakeList.txt:

cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS

CATKIN_DEPENDS cv_brigde image_transport roscpp sensor_msgs std_msgs


add_executable( cam_experiment src/main.cpp )
target_link_libraries( cam_experiment ${catkin_LIBRARIES} )

Question #2: if I try to specify in my CMakeLists.txt that I want to use cv_bridge I get the following problem and it didn t get compiled:

Could not find a package configuration file provided by "cv_brigde" with
any of the following names:

cv_brigdeConfig.cmake cv_brigde-config.cmake

Add the installation prefix of "cv_brigde" to CMAKE_PREFIX_PATH or set "cv_brigde_DIR" to a directory containing one of the above files. If "cv_brigde" provides a separate development package or SDK, be sure it has been installed.

Question #3: After reading in the Q&A I found that running:

$ locate | grep python

I get the following output:


which is definitely NOT in a ROS' folder. Maybe it is the problem, but since opencv is not more a package of ROS it must been installed from source. How to get the library linked and with a program compiled? Ah! I m running indigo and he webcam drivers are working in ROS.

Regards and nice sunday

edit retag flag offensive close merge delete


Beyond the answers below, you might want to check that you are spelling bridge correctly. It shows up incorrectly in a few places in your question

jarvisschultz gravatar image jarvisschultz  ( 2014-08-25 07:13:19 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2014-08-24 15:08:22 -0500

Murilo F. M. gravatar image

Regarding your question #1, you are mixing up things. There is no sensor_msgs/CvBridge, it should rather be sensor_msgs/Image. See details here.

In relation to question #2, make sure cv_bridge package is installed. Also make sure your package.xml is configured accordingly to have the package as dependency. You need to add cv_bridge if you want to use it in your code.

Lastly, question #3: if your package depends on OpenCV (which obviously does), you must configure the CMakeLists.txt. The right way of doing so is documented here.

edit flag offensive delete link more

answered 2014-08-25 01:10:56 -0500

Wolf gravatar image

Expanding a bit on @Murilo F. M. 's answer:

About #1:

The tutorial you cited is quite outdated. It uses old cv_bridge version and the old C API of opencv (not opencv2 C++ API).

A quick rewrite (not yet compiled/tested) could look like:

#include <ros/ros.h>
#include <sensor_msgs/image.h>
#include <image_transport/image_transport.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>

void imageCallback(const sensor_msgs::ImageConstPtr& msg)
    cv::Mat lo_mat = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8)->image;
    cv::imshow( "view", lo_mat );
  catch ( cv_bridge::CvBridgeException& e)
    ROS_ERROR_STREAM("Could not convert from '" << msg->encoding << "' to 'bgr8'." );

int main(int argc, char **argv)
  ros::init(argc, argv, "image_listener");
  ros::NodeHandle nh;
  image_transport::ImageTransport it(nh);
  image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback);

About #2: As mentioned make sure to have cv_bridge (in vision_opencv metapackage )installed. Run

sudo apt-get install ros-hydro-vision-opencv

or check out the src code mentioned at into your workspace.

About #3:

Make sure opencv is correctly configured in your CMakeLists.txt as described in the tutorial given or here :

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-08-24 04:25:54 -0500

Seen: 1,792 times

Last updated: Aug 25 '14