ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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