Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Segmentation fault with ORB feature extractor

Hi, I've written a bit of code which takes an image, detects keypoints with using FAST (as shown below) and the resulting keypoints are passed over to an ORB feature detector. However, despite checking the image to be not empty and having a lot of keypoints, I get a weird segmentation fault whenever I try and run it.

class Code{
  //ROS node init removed for brevity
  Ptr<cv::FastFeatureDetector> detector = cv::FastFeatureDetector::create(detector_set_input);
  DescriptorExtractor* extractor = cv::ORB::create();
  std::vector<KeyPoint> keypoints_last;
  Mat descriptors_last;

public:
  void callback(const sensor_msgs::ImageConstPtr& msg)
  {
    cv_bridge::CvImagePtr cv_ptr;
    cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);   //try/excepts cut down for brevity
    Mat img = cv_ptr->image;
    detector->detect(image, keypoints_last);   //This line never throws bugs
    extractor->compute(gray_lastimage, keypoints_last, descriptors_last);    //Segmentation fault here
  }
};

Details: callback is a ROS node callback function, and the image is converted from a sensor_msg to a cv::Mat using cv_bridge, but I don't think that's where the error is coming from or it probably wouldn't have detected any keypoints.

descriptors_last and keypoints_last are empty here- the issue comes from when the node is trying to initialize.

I'm using openCV3.3 on Ubuntu 16.04 with ROS Kinetic.

Many thanks!