Problem with sensor_msgs::Image::ConstPtr conversion to IplImage
Hello Ros-Users,
i have a strange problem using the CvBridge and OpenCV. I subscribed to a topic delivering images. The Problem is that cvSaveImage() fails sometimes with :
OpenCV Error: Bad argument (Unknown array type) in cvarrToMat, file /tmp/buildd/ros-diamondback-vision-opencv-1.4.1/debian/ros-diamondback-vision-opencv/opt/ros/diamondback/stacks/vision_opencv/opencv2/build/opencv-svn/modules/core/src/matrix.cpp, line 641
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/ros-diamondback-vision-opencv-1.4.1/debian/ros-diamondback-vision-opencv/opt/ros/diamondback/stacks/vision_opencv/opencv2/build/opencv-svn/modules/core/src/matrix.cpp:641: error: (-5) Unknown array type in function cvarrToMat
The strangeness is that if i do cvSaveImage() directly in my callbackFunction it does not fail at all. Ist just fails (after some time) if i push the images back into a vector. I want to buffer the images for later processing and then store them to HDD, so that's why i am doing the vector-stuff.
My callback function is:
void RosClass::imageCallback(const sensor_msgs::Image::ConstPtr& msg){
//image_queue is a std::vector<sensor_msgs::Image::ConstPtr>
//cvSaveImage("test.jpg", getIplImage(msg)) works perfectly
image_queue.push_back(temp);
}
My Function to convert the Ros-Image to an IplImage is:
IplImage* RosClass::getIplImage(sensor_msgs::Image::ConstPtr msg){
IplImage *img = 0;
std::string cv_encoding="passthrough";
sensor_msgs::CvBridge bridge;
try{
img = bridge.imgMsgToCv(msg, cv_encoding);
}catch(sensor_msgs::CvBridgeException error) { //TODO: Compiler meldet ein Warning
ROS_ERROR("Failed to convert sensor_msgs::Image to img_t with error [%d]", error);
return 0;
}
return img;
}
This is the function where i retrieve the images from the vector and try to save them to HDD. But this fails. Not instantly but after some time. My workflow is only: Push images to the vector - if vector.size() > Threash - store them to HDD - clear the vector. Thats all. It seems like the cvSaveImage() fails after the vector was 1 time cleared. I have no idea whats the problem. Any suggestions? :)
void RosClass::processBufferedImages(){
for(int i = 0; i < image_queue.size();i++){
//Convert to IplImage -> works without any problems
IplImage *img = getIplImage(image_queue.at(i));
//Save Images to HDD -> fails after some time ... :/
cvSaveImage("test.jpg",img);
}
image_queue.clear()
}
Thx for reading.