segmentation fault on cv::imshow("windowName", cvImagePtr->image)

asked 2015-04-15 18:33:28 -0600

updated 2015-04-16 03:40:41 -0600

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

}
edit retag flag offensive close merge delete

Comments

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

berak gravatar imageberak ( 2015-04-16 03:45:04 -0600 )edit

it gives me the rows and columns when i printed out mat.rows and mat.columns.

chetan3061 gravatar imagechetan3061 ( 2015-04-16 16:06:21 -0600 )edit

any news on this issue?

acajic gravatar imageacajic ( 2016-05-20 10:06:30 -0600 )edit