Robotics StackExchange | Archived questions

Questions about openCV installation and tutorial

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/workspaceros/src/camexperiment/src/main.cpp: In function ‘void imageCallback(const ImageConstPtr&)’: /home/wilhem/workspaceros/src/camexperiment/src/main.cpp:43:3: error: ‘CvBridge’ is not a member of ‘sensormsgs’ sensormsgs::CvBridge bridge; ^ /home/wilhem/workspaceros/src/camexperiment/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)
project(cam_experiment)

find_package(catkin REQUIRED COMPONENTS
  #cv_brigde        #  I HAVE TO KEEP cv_bridge UNCOMMENTED OTHERWISE ERRORS APPEAR. MORE LATER
  image_transport
  roscpp
  sensor_msgs
  std_msgs
)

catkin_package(
CATKIN_DEPENDS cv_brigde image_transport roscpp sensor_msgs std_msgs
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

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:

cvbrigdeConfig.cmake cvbrigde-config.cmake

Add the installation prefix of "cvbrigde" to CMAKEPREFIXPATH or set "cvbrigdeDIR" to a directory containing one of the above files. If "cvbrigde" 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 cv2.so | grep python

I get the following output:

/usr/lib/python2.7/dist-packages/cv2.so

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

Asked by Andromeda on 2014-08-24 04:25:54 UTC

Comments

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

Asked by jarvisschultz on 2014-08-25 07:13:19 UTC

Answers

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.

Asked by Murilo F. M. on 2014-08-24 15:08:22 UTC

Comments

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)
{
  try
  {
    cv::Mat lo_mat = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8)->image;
    cv::imshow( "view", lo_mat );
    cv::waitKey(10);
  }
  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;
  cv::namedWindow("view");
  cv::startWindowThread();
  image_transport::ImageTransport it(nh);
  image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback);
  ros::spin();
  cv::destroyWindow("view");
}

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 http://wiki.ros.org/vision_opencv into your workspace.

About #3:

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

http://answers.ros.org/question/123241/could-not-find-a-configuration-file-for-package-opencv/#123286

Asked by Wolf on 2014-08-25 01:10:56 UTC

Comments