The problem was the order of the parameters in drawMatches .
The correct order is:
drawMatches(frame, keypoints_frame, object, keypoints_object, matches, output);
Explanation:
In step 5, I use the match method of the matcher object:
matcher.match(descriptors_frame, descriptors_object, matches);
Signature of this method
void match( const Mat& queryDescriptors, const Mat& trainDescriptors, CV_OUT vector<DMatch>& matches, const Mat& mask=Mat() ) const;
This means that matches contains matches from trainDescriptors to queryDescriptors .
In my case, the train descriptors have an object , and the request descriptors have a frame , so matches contains matches from object to frame .
Signature drawMatches is
void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1, const Mat& img2, const vector<KeyPoint>& keypoints2, const vector<DMatch>& matches1to2, ... );
When calling drawMatches with an invalid parameter:
drawMatches(object, keypoints_object, frame, keypoints_frame, matches, output);
the method looks for the coordinates of matches in the incorrect image, which may lead to an attempt to access pixels "outside the boundaries"; Therefore, segmentation error.