pr2 camera subscriber [closed]
Hello everyone!
First I am using the groovy version of ROS under ubuntu 12.04.
I have some issues with the ImageTransporter Subscriber. I am trying to save pictures from different points of the environment using a pr2 robot.
I use a lookAt function described here to point to a coordinate in the environment and then subscribe to the "wide_stereo/left/image_mono" topic.
Here is the code I use for saving the picture:
void savePicture(const sensor_msgs::ImageConstPtr& msg){
std::stringstream s;
s<<"image"<<numImage<<".png";
try
{
cv::imwrite(s.str().c_str(), cv_bridge::toCvShare(msg, "bgr8")->image);
}
catch(std::runtime_error& ex)
{
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
}
And here is my "main" function:
int main(int argc, char** argv)
{
//init the ROS node
ros::init(argc, argv, "image_listener");
ros::NodeHandle nh;
RobotHead head(nh);
image_transport::ImageTransport it(nh);
float angle = -M_PI;
numImage = 0; //Global variable to increment each time a picture is taken
while(angle<M_PI)
{
head.lookAt("base_link",cos(angle),sin(angle),1.2);
image_transport::Subscriber sub = it.subscribe("wide_stereo/left/image_mono", 1, savePicture);
numImage++;
angle = angle + (M_PI/4.0);
}
ros::spin();
}
The thing is that this code is correctly compiled but doesn't save any image. When I put the ros::spin()
in the while
loop it only saves the first point given to the lookAt()
function so it seems that the saving works.
Any help or advice is welcome and thank you for reading.