cvLoadImage under roslaunch
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.