0
$\begingroup$

Rosanswers logo

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


Originally posted by Yongqiang Gao on ROS Answers with karma: 133 on 2011-03-09

Post score: 0


Original comments

Comment by KoenBuys on 2011-03-10:
You might want to choose your title a little bit more detailed

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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);

Originally posted by KoenBuys with karma: 2314 on 2011-03-10

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Yongqiang Gao on 2011-03-10:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.