segmentation fault on cv::imshow("windowName", cvImagePtr->image)
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
void callback(const sensor_msgs::ImageConstPtr& msg) {
cv_bridge::CvImagePtr cvImagePtr; try {
cvImagePtr = cv_bridge::toCvCopy(msg);
//cv::Mat &mat = cvImagePtr->image;
cv::imshow("windowName", cvImagePtr->image);
cv::destroyWindow("windowName");
}
catch (cv_bridge::Exception &e) {
ROS_ERROR("cv_bridge exception: %s", e.what());
}
}
int main(int argc, char **argv) {
ros::init(argc, argv, "nodeName");
cv::namedWindow("windowName");
ros::NodeHandle nh;
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub = it.subscribe("/ardrone/image_raw", 1, callback);
ros::spin();
}
can you do a check for
cvImagePtr->image.empty()
, before throwing it at imshow() ?also, try a debug build, so at least it throws a proper exception
it gives me the rows and columns when i printed out mat.rows and mat.columns.
any news on this issue?