void compute_sift_matches( keypointslist& keys1, keypointslist& keys2, matchingslist& matchings,siftPar &par) { int imatch=0; float sqminratio = par.MatchRatio * par.MatchRatio, sqratio; // write the keypoint descriptors in char keypointslist_short keys1_short(keys1.size()); for (int i=0; i< (int) keys1.size(); i++) { keys1_short[i].x = keys1[i].x; keys1_short[i].y = keys1[i].y; keys1_short[i].scale = keys1[i].scale; keys1_short[i].angle = keys1[i].angle; for (int k=0; k < VecLength; k++) { keys1_short[i].vec[k] = (unsigned short) (keys1[i].vec[k]); } } keypointslist_short keys2_short(keys2.size()); for (int i=0; i< (int) keys2.size(); i++) { keys2_short[i].x = keys2[i].x; keys2_short[i].y = keys2[i].y; keys2_short[i].scale = keys2[i].scale; keys2_short[i].angle = keys2[i].angle; for (int k=0; k < VecLength; k++) { keys2_short[i].vec[k] = (unsigned short) (keys2[i].vec[k]); } } for (int i=0; i< (int) keys1.size(); i++) { // sqratio = CheckForMatch(keys1[i], keys2, imatch,par); sqratio = CheckForMatch_short(keys1_short[i], keys2_short, imatch,par); if (sqratio< sqminratio){ //std::cout << "ok:" << sqratio << " , " << std::endl; matchings.push_back( matching(keys1[i],keys2[imatch] )); }else{ //std::cout << "ng:" << sqratio << " , " << std::endl; } // matchings.push_back( matching_char(keys1_char[i],keys2_char[imatch] )); } }
void compute_cv_surf_keypoints(float *input, keypointslist& keypoints, int width, int height, siftPar &par){ pro::Image img(width,height,pro::Image::_8UC1); img.setU8Data(vector<uchar>(input,input+width*height),width,height,1); cv::normalize((cv::Mat&)img, (cv::Mat&)img, 0, 255, cv::NORM_MINMAX); std::vector<cv::KeyPoint> keys; std::vector<cv::KeyPoint>::iterator itk; cv::Mat descriptors; cv::SurfFeatureDetector detector(4000,3,4,false,false); detector.detect((const cv::Mat&)img, keys); cv::SurfDescriptorExtractor extractor(4000,3,4,false,false); cv::Scalar color(100,255,50); extractor.compute((const cv::Mat&)img, keys, descriptors); for(int i=0; i<descriptors.rows; ++i) { keypoint key; key.angle = keys[i].angle; key.scale = keys[i].octave; key.x = keys[i].pt.x; key.y = keys[i].pt.y; cv::Mat d(descriptors, cv::Rect(0,i,descriptors.cols,1)); for(int j=0;j<d.cols;j++){ key.vec[j] = d.data[j]; } keypoints.push_back(key); } }
/* Joan Pau: Add a new keypoint to a vector of keypoints Create a new keypoint and return list of keypoints with new one added. */ void MakeKeypoint( const flimage& grad, float octSize, float octScale, float octRow, float octCol, float angle, keypointslist& keys,siftPar &par) { keypoint newkeypoint; newkeypoint.x = octSize * octCol; /*x coordinate */ newkeypoint.y = octSize * octRow; /*y coordinate */ newkeypoint.scale = octSize * octScale; /* scale */ newkeypoint.angle = angle; /* orientation */ MakeKeypointSample(newkeypoint,grad,octScale,octRow,octCol,par); keys.push_back(newkeypoint); }
void compute_sift_matches( keypointslist& keys1, keypointslist& keys2, matchingslist& matchings,siftPar &par) { float sqminratio = par.MatchRatio * par.MatchRatio; for (keypointslist::size_type i=0; i< keys1.size(); i++) { keypointslist::size_type imatch=0; float sqratio = CheckForMatch(keys1[i], keys2, imatch,par); if(sqratio < sqminratio) matchings.push_back( Match(keys1[i].x,keys1[i].y, keys2[imatch].x, keys2[imatch].y) ); } }
/* This searches through the keypoints in klist for the two closest matches to key. It returns the ratio of the distance to key of the closest and next to closest keypoints in klist, while bestindex is the index of the closest keypoint. */ float CheckForMatch( keypoint& key, keypointslist& klist, keypointslist::size_type& min,siftPar &par) { float dsq, distsq1, distsq2; distsq1 = distsq2 = 1000000000000.0f; for (keypointslist::size_type j=0; j< klist.size(); j++){ dsq = DistSquared(key, klist[j], distsq2,par); if (dsq < distsq1) { distsq2 = distsq1; distsq1 = dsq; min = j; } else if (dsq < distsq2) distsq2 = dsq; } return distsq1/distsq2 ; }
/* This searches through the keypoints in klist for the two closest matches to key. It returns the ratio of the distance to key of the closest and next to closest keypoints in klist, while bestindex is the index of the closest keypoint. */ float CheckForMatch( keypoint& key, keypointslist& klist, int& min,siftPar &par) { int nexttomin = -1; float dsq, distsq1, distsq2; distsq1 = distsq2 = 1000000000000.0f; for (int j=0; j< (int) klist.size(); j++){ dsq = DistSquared(key, klist[j], distsq2,par); if (dsq < distsq1) { distsq2 = distsq1; distsq1 = dsq; nexttomin = min; min = j; } else if (dsq < distsq2) { distsq2 = dsq; nexttomin = j; } } return distsq1/distsq2 ; }