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

cvLoadImage under roslaunch

asked 2012-10-15 05:47:16 -0500

pmarinplaza gravatar image

updated 2014-04-20 14:09:45 -0500

ngrennan gravatar image

Hi, reading this post:

http://answers.ros.org/question/31491/cvloadimage-fail-in-ros/?comment=45908#comment-45908

I have the same problem. This is my code:

  IplImage *img = NULL;

  img = cvLoadImage("$(find lsi_node)/images/herramientas.jpg", CV_LOAD_IMAGE_COLOR);
  cvNamedWindow("result",CV_WINDOW_AUTOSIZE );
  cvShowImage("result", img);
  cvWaitKey(0);

where lsi_node is the real package, images is the folder inside this package which contains the images and herramientas.jpg is the picture which I want to load.

This image doesn't load. The includes are:

#include <ros/ros.h>
#include "sensor_msgs/Image.h"
#include "image_transport/image_transport.h"
#include "cv_bridge/CvBridge.h"
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>

I miss some command or something like ' or ` or " or in the path of my image? or any include?

In the roslaunch:

<launch>
  <node pkg="lsi_node" type="lsi_node" name="lsi_node" output="screen"/>
</launch>

SOLVED

Finally I find the solution of this topic.

This is the final code:

#include <ros/ros.h>
#include "sensor_msgs/Image.h"
#include "image_transport/image_transport.h"
#include "cv_bridge/CvBridge.h"
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>

#include <ros/package.h>

using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
  ros::init(argc, argv, "lsi_node");
  ros::NodeHandle n;

  std::string path = ros::package::getPath("lsi_node");

  IplImage *img = NULL;

  path.append("/images/herramientas.jpg");

  img = cvLoadImage(path.c_str(), CV_LOAD_IMAGE_COLOR);
  cvNamedWindow("result",CV_WINDOW_AUTOSIZE );
  cvShowImage("result", img);
  cvWaitKey(0);
  cvDestroyWindow("result");
}

And actually the picture appear in the screen.

Hope this will be useful.

Best regards.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-10-15 05:52:50 -0500

kszonek gravatar image

Does image load if you dont use $(find lsi_node) ?

Try loading:

img = cvLoadImage("herramientas.jpg", CV_LOAD_IMAGE_COLOR);

and put herramientas.jpg into ~/.ros directory. If it works you can change working directory to $(find lsi_node) for this node with your launch file.

$(find lsi_node) in code code may not work as wanted, bacause it is not a launch file. You could try to work with:

 `rospack find lsi_node`
edit flag offensive delete link more

Comments

If you want to use package relative filenames in ros nodes, the best way is to use resource_retriver.

Lorenz gravatar image Lorenz  ( 2012-10-15 06:06:46 -0500 )edit

Question Tools

Stats

Asked: 2012-10-15 05:47:16 -0500

Seen: 698 times

Last updated: Oct 16 '12