bool FaceRecognition::matchImages(cv::Mat p_ImagePrimary, cv::Mat p_ImageScondary) { std::vector<cv::KeyPoint> primaryKeyPoints = getKeyPoints(p_ImagePrimary); std::vector<cv::KeyPoint> secondaryKeyPoints = getKeyPoints(p_ImageScondary); std::vector<cv::Point2f> primaryPoints; std::vector<cv::Point2f> secondaryPoints; std::vector<cv::DMatch> goodMatches = getMatches(p_ImagePrimary, p_ImageScondary); if(!goodMatches.size() || goodMatches.size() < 4) return false; for( int i = 0; i < goodMatches.size(); i++ ) { primaryPoints.push_back( primaryKeyPoints[ goodMatches[i].queryIdx ].pt ); secondaryPoints.push_back( secondaryKeyPoints[ goodMatches[i].trainIdx ].pt ); } cv::Mat homography; try { homography = cv::findHomography(primaryPoints, secondaryPoints, CV_RANSAC); } catch(std::exception) { return false; } return true; }
std::vector<cv::DMatch> FaceRecognition::getMatches(cv::Mat p_ImagePrimary, cv::Mat p_ImageSecondary, int p_MinDist, int p_MaxDist) { cv::SurfDescriptorExtractor extractor; cv::Mat primaryDescriptor, secondaryDescriptor; std::vector<cv::KeyPoint> primaryKeyPoints = getKeyPoints(p_ImagePrimary), secondaryKeyPoints = getKeyPoints(p_ImageSecondary); extractor.compute(p_ImagePrimary, primaryKeyPoints, primaryDescriptor); extractor.compute(p_ImageSecondary, secondaryKeyPoints, secondaryDescriptor); cv::FlannBasedMatcher matcher; std::vector<cv::DMatch> matches; if(primaryDescriptor.data && secondaryDescriptor.data) matcher.match(primaryDescriptor, secondaryDescriptor, matches); else return matches; for( int i = 0; i < primaryDescriptor.rows; i++ ) { double dist = matches[i].distance; if( dist < p_MinDist ) p_MinDist = dist; if( dist > p_MaxDist ) p_MaxDist = dist; } std::vector<cv::DMatch> goodMatches; for( int i = 0; i < primaryDescriptor.rows; i++ ) { if(matches[i].distance <= 3 * p_MinDist) goodMatches.push_back(matches[i]); } return goodMatches; }
void phdGimbal2d::draw(ofMatrix4x4 & _mat) { ofPolyline _keys; getKeyPoints(_keys); getTransformedPolyline(_keys,_keys,_mat); if(_keys.size() > 1) { glBegin(GL_LINES); for(int i = 0; i < _keys.size()-1; i++) { glVertex2f(_keys[i].x, _keys[i].y); glVertex2f(_keys[i+1].x, _keys[i+1].y); } glEnd(); ofFill(); ofRect(_keys[0].x-3, _keys[0].y-3, 6, 6); // drag to scale width ofCircle(_keys[1].x, _keys[1].y, 4); // drag to rotate ofCircle(_keys[2].x, _keys[2].y, 5); // drag to translate ofRect(_keys[3].x-3, _keys[3].y-3, 6, 6); // drag to scale height } }
void CFast::operator ()(const cv::gpu::GpuMat& cvgmImg_, const cv::gpu::GpuMat& cvgmMask_, cv::gpu::GpuMat* pcvgmKeyPoints_) { calcKeyPointsLocation(cvgmImg_, cvgmMask_); //perform non-max suppression pcvgmKeyPoints_->cols = getKeyPoints(&*pcvgmKeyPoints_); }