Two things about the mask.
- the mask should be a 1-channel matrix of 8-bit unsigned chars, which translates to opencv type
CV_8U
. In your case the mask is of type srcImage.type(), which is a 3-channel matrix - you are passing
roi
to the detector but you should be passingmask
. When you are making changes toroi
, you are also changingmask
.
the following should work
Mat srcImage; //RGB source image
Mat mask = Mat::zeros(srcImage.size(), CV_8U); // type of mask is CV_8U
// roi is a sub-image of mask specified by cv::Rect object
Mat roi(mask, cv::Rect(10,10,100,100));
// we set elements in roi region of the mask to 255
roi = Scalar(255);
SurfFeatureDetector detector();
std::vector<KeyPoint> keypoints;
detector.detect(srcImage, keypoints, mask); // passing `mask` as a parameter