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

An error for connecting two different packages

asked 2011-03-09 17:35:40 -0500

Yongqiang Gao gravatar image

Hi, there some problems for connecting two packages. That, i learn learning_image_transport, and i create anther package named "subscriber" for subscribing the image which "learning_image_transport" published.

And the code of "subscriber" packages, /src/subscriber.cpp:

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cv_bridge/CvBridge.h>
IplImage* img_original=NULL;
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
sensor_msgs::CvBridge bridge;
img_original=bridge.imgMsgToCv(msg,"bgr8");
try
{
    cvShowImage("view",img_original);
}
catch(sensor_msgs::CvBridgeException& e)
{
    ROS_ERROR("Could not convert from '%s' to ''bgr8",msg->encoding.c_str());
}
}

int main(int argc,char**argv)
{
    ros::init(argc,argv,"image_subscriber",ros::init_options::AnonymousName);
ros::NodeHandle nh;
cvNamedWindow("Subscriber");
cvStartWindowThread();
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub=it.subscribe(argv[1],1,imageCallback);
ros::spin();
cvDestroyWindow("Subscriber");
}

for checking my rxgraph:image description

that "image_subscriver" node has already connected "image_publisher" node. But why it does not preform the image?

PS: my rostopic list as follow: /camera/image /camera/image/compressed /camera/image/compressed/parameter_descriptions /camera/image/compressed/parameter_updates /camera/image/theora /camera/image/theora/parameter_descriptions /camera/image/theora/parameter_updates /rosout /rosout_agg

edit retag flag offensive close merge delete

Comments

You might want to choose your title a little bit more detailed
KoenBuys gravatar image KoenBuys  ( 2011-03-10 06:08:35 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2011-03-10 06:15:46 -0500

KoenBuys gravatar image

How do you launch the files? Could you do a rostopic hz on /camera/image? You might want to have the

imgMsgToCv

in the try catch as this creates the exception. Further the

cvNamedWindow("Subscriber"); 
cvDestroyWindow("Subscriber");

must have the same windowname as

cvShowImage("view",img_original);
edit flag offensive delete link more

Comments

For my silly, I didn't have the same name between "cvNamedWindow" and "cvShowImage", and next, I try to subscribe camera stream. Thanks a lot for u.
Yongqiang Gao gravatar image Yongqiang Gao  ( 2011-03-10 11:18:20 -0500 )edit

Question Tools

Stats

Asked: 2011-03-09 17:35:40 -0500

Seen: 297 times

Last updated: Mar 10 '11