void FeatureMatchThread::run() { Mat resultImg; Mat grayImg; cvtColor(cropImg,grayImg,CV_BGR2GRAY); featureDetector.detect(grayImg,keyPoints); featureExtractor.compute(grayImg,keyPoints,descriptors); flannIndex.build(descriptors,flann::LshIndexParams(12,20,2),cvflann::FLANN_DIST_HAMMING); while(true) { Mat captureImage_gray; vector<KeyPoint> captureKeyPoints; Mat captureDescription; vector<DMatch> goodMatches; cap >> captureImage; if(captureImage.empty()) continue; cvtColor(captureImage,captureImage_gray,CV_BGR2GRAY); featureDetector.detect(captureImage_gray,captureKeyPoints); featureExtractor.compute(captureImage_gray,captureKeyPoints,captureDescription); Mat matchIndex(captureDescription.rows,2,CV_32SC1); Mat matchDistance(captureDescription.rows,2,CV_32FC1); flannIndex.knnSearch(captureDescription,matchIndex,matchDistance,2,flann::SearchParams()); for(int i=0;i<matchDistance.rows;i++) { if(matchDistance.at<float>(i,0) < 0.6 * matchDistance.at<float>(i,1)) { DMatch dmatches(i,matchIndex.at<int>(i,0),matchDistance.at<float>(i,0)); goodMatches.push_back(dmatches); } } drawMatches(captureImage,captureKeyPoints,cropImg,keyPoints,goodMatches,resultImg); emit NewFeatureMatch(&resultImg); imshow(WindowName,captureImage); cv::setMouseCallback(WindowName,mouse_callback); captureKeyPoints.clear(); goodMatches.clear(); waitKey(30); } return; }
void YawAngleEstimator::Indexmatch(Mat& CurrentDescriptors, float* CurrentVote) { //Lowe's Algorithm to caculate vote for each angletemplate for (int i = 4; i < AngleNum; i++) { //rows:numbers of keypoints Mat matchIndex(CurrentDescriptors.rows, 2, CV_32SC1), matchDistance(CurrentDescriptors.rows, 2, CV_32FC1); CurrentVote[i] = 0; //cout << CurrentDescriptors[0] << endl; YawIndex[i].knnSearch(CurrentDescriptors, matchIndex, matchDistance, 2, flann::SearchParams()); for (int j = 0; j < matchDistance.rows; j++) { if (matchDistance.at<float>(j, 0) < 0.6*matchDistance.at<float>(j, 1)) ++CurrentVote[i]; } } }