Ask Your Question

Revision history [back]

I cannot reproduce using this program : all keypoints in image in mask can be found inside image with mask.

Color for keypoints is choosen randomly may be keypoint missing are background color?

When I need N keypoints (in create), i get N keypoints (of course when it is possible).

Mat img = imread("c:/temp/1519118663237344.jpg", IMREAD_UNCHANGED);
Mat imgHSV;
cvtColor(img, imgHSV, COLOR_BGR2HSV);
Ptr<ORB> f1 = ORB::create(300, 2.0, 3, 31, 0, 2, 0, 31, 15);
Ptr<ORB> f2 = ORB::create(301, 2.0, 3, 31, 0, 2, 0, 31, 15);
vector<KeyPoint> key1, key2;
Mat desc1, desc2;
Mat mask1;
blur(imgHSV, imgHSV, Size(7, 7));
inRange(imgHSV, Scalar(15, 000, 00), Scalar(35, 255, 255), mask1);
vector<vector<Point>> ctr;
vector<cv::Vec4i> h;
findContours(mask1, ctr, h, RETR_EXTERNAL, CHAIN_APPROX_NONE);
Mat mask = Mat::zeros(mask1.size(), CV_8UC1);
drawContours(mask, ctr, ctr.size()-1, 255, -1);
imshow("mask", mask);


f1->detectAndCompute(img, noArray(), key1, desc1);
f2->detectAndCompute(img, mask, key2, desc2);
cout << "Image 1 keypoints : "<<key1.size() << "\n";
cout << "Image 2 keypoints : " << key2.size() << "\n";

BFMatcher bf(4,true);
vector<DMatch> dm,dme;
bf.match(desc1, desc2, dm);
Mat dst = img.clone();
drawKeypoints(img, key1, dst, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_OVER_OUTIMG);
drawKeypoints(img, key2, dst, Scalar(255, 0, 0), DrawMatchesFlags::DRAW_OVER_OUTIMG);
drawMatches(img, key1, img, key2, dme, dst);
imshow("Key 1 2", dst);

waitKey(0);

result is

Image 1 keypoints : 300
Image 2 keypoints : 301

and image is

image description