mask in FlannBasedMatcher::match doesn't work normally
Cross post here
I note the FlannBasedMatcher::match
have a parameter mask
, so I give a try with following code:
#include<opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
using namespace std;
int main() {
Mat rightImg = imread("right.jpg", 0);
Mat leanImg = imread("lean.jpg", 0);
if (!rightImg.data || !leanImg.data) {
cout << "Fail to read your image. Please check your path.\n";
return -1;
}
resize(leanImg, leanImg, rightImg.size());
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
vector<KeyPoint> keypoints_right, keypoints_lean;
detector.detect(rightImg, keypoints_right);
detector.detect(leanImg, keypoints_lean);
Mat med_right, med_lean;
drawKeypoints(rightImg, keypoints_right, med_right);
drawKeypoints(leanImg, keypoints_lean, med_lean);
SurfDescriptorExtractor extractor;
Mat descriptors_right, descriptors_lean;
extractor.compute(rightImg, keypoints_right, descriptors_right);
extractor.compute(leanImg, keypoints_lean, descriptors_lean);
FlannBasedMatcher matcher;
vector< DMatch > matches;
Mat mask(rightImg.size(), CV_8UC1, Scalar(255));
ellipse(mask, Point(rightImg.cols / 2, rightImg.rows / 2), Size(rightImg.cols / 2.5, rightImg.rows / 2.5), 0, 0, 360, Scalar(0), CV_FILLED);
matcher.match(descriptors_right, descriptors_lean, matches/*, mask*/);// You can use the mask or not to test
Mat img_matches;
drawMatches(rightImg, keypoints_right, leanImg, keypoints_lean,
matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
return 0;
}
And this is my right.jpg and lean.jpg. But I note I will get a same result totally whether I use the mask
in the function FlannBasedMatcher::match
. You can use the mask or not to reproduce it. Do I have missed something or the OpenCV have a bug in my 2.4.13
? Can anyone tell me how to use the mask
in the FlannBasedMatcher::match
? I even don't know its size should same with the query image or train image. But I think it is a usefull parameter..
why do you want to use a mask, and where would you get the information, how to fill it ?
https://docs.opencv.org/master/db/d39...
see, that is not an "image", the shape of your mask is entirely wrong, if at all, it should be:
but what to mask out there ? we're back at the why ...
@berak I'm sorry, actually no why. I'm just studing OpenCV, and I want to know how to use the parameter of
mask
..I don't care those points in the center ofright.jpg
. So I create those mask.".I don't care those points in the center of right.jpg"
i never used this, but i guess, what you have to do then is: find the keypoints in the right image, which you want to ignore, and set the resp. column in the mask to 0
again it's not the image size, you have to use the keypoint indices, not their coords
@berak As you first comment and your link, I make a new comment. But seen don't work still..