c++ - Delete matches in OpenCV (Keypoints and descriptors) -
i want check scene image against 2 train images. that, detect features , compute descriptors of both training images. before detecting, computing , matching scene image, delete matches of train1 , train2. because these matches won't facilitate matching of scene image train1 , train2.
so, match train1 train2 , vector of matches trainidx , queryidx. how can delete these matches in keypoints-vector , descriptor matrix of train1 , train2?
best regards, dwi
i have done below:
std::vector<cv::keypoint> keypoints[2]; cv::mat descriptor[2]; std::vector< cv::dmatch > matches; /* write code generate keypoints, descriptors , matches here... keypoint[0] -> train image 1 keypoints keypoint[1] -> train image 2 keypoints descriptor[0] -> train image 1 descriptors descriptor[1] -> train image 2 descriptors matches -> matched between train image 1 , 2 */ // logic keep unmatched keypoints , corresponding descriptors (int idx = 0; idx < 2; idx++) { std::vector<bool> ismatched(keypoints[idx].size(), false); // mark matched keypoint true (int = 0; < matches.size(); i++) { if (idx == 0) { ismatched[matches[i].queryidx] = true; } else { ismatched[matches[i].trainidx] = true; } } std::vector<cv::keypoint>::const_iterator itr = keypoints[idx].begin(); // new descriptor length old descriptor length minus matched keypoints size int descriptor_length = keypoints[idx].size() - matches.size(); // create temporary descriptor of new descriptor length cv::mat tempdescriptor(descriptor_length, descriptor[idx].cols, descriptor[idx].depth()); int count = 0; (int = 0; < ismatched.size(); i++) { // remove matched keypoints if (ismatched[i] == true) { itr = keypoints[idx].erase(itr); } else { descriptor[idx].row(i).copyto(tempdescriptor.row(count)); itr++; count++; } } descriptor[idx].release(); descriptor[idx] = tempdescriptor.clone(); }
i hope help.
Comments
Post a Comment