다음은 내 코드이며 SURF를 사용하여 피쳐를 추출하는 데 사용되며 flannBasedMatcher를 사용하여 점과 일치합니다. 나는 내가 일치하는 이미지의 두 기술자 및 벡터 2 가까운 충전 된 일치를 전달 아시다시피 바로이 방법SURF FlannBasedMatcher를 기반으로 한 피쳐 추출 및 키포인트 일치
matcher.knnMatch(des_object, des_image, matches, 2);
을 통해 어떻게 알고 싶어이 코드에서
Mat object = imread("S6E0.bmp", CV_LOAD_IMAGE_GRAYSCALE);
if(!object.data)
{
// std::cout<< "Error reading object " << std::endl;
return -2;
}
//Detect the keypoints using SURF Detector
int minHessian = 500;
SurfFeatureDetector detector(minHessian);
std::vector<KeyPoint> kp_object;
detector.detect(object, kp_object);
//Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat des_object;
extractor.compute(object, kp_object, des_object);
FlannBasedMatcher matcher;
char key = 'a';
//VideoCapture cap(0);
namedWindow("Good Matches");
std::vector<Point2f> obj_corners(4);
//Get the corners from the object
obj_corners[0] = cvPoint(0,0);
obj_corners[1] = cvPoint(object.cols, 0);
obj_corners[2] = cvPoint(object.cols, object.rows);
obj_corners[3] = cvPoint(0, object.rows);
Mat image = imread("S6E0.bmp", CV_LOAD_IMAGE_GRAYSCALE);
Mat des_image, img_matches;
std::vector<KeyPoint> kp_image;
std::vector<vector<DMatch >> matches;
std::vector<std::vector<cv::DMatch>> matches1;
std::vector<std::vector<cv::DMatch>> matches2;
std::vector<cv::DMatch> matches3;
std::vector<DMatch > good_matches;
std::vector<Point2f> obj;
std::vector<Point2f> scene;
std::vector<Point2f> scene_corners(4);
Mat H;
//cvtColor(frame, image, CV_RGB2GRAY);
detector.detect(image, kp_image);
extractor.compute(image, kp_image, des_image);
matcher.knnMatch(des_object, des_image, matches, 2);
for(int i = 0; i < min(des_image.rows-1,(int) matches.size()); i++) //THIS LOOP IS SENSITIVE TO SEGFAULTS
{
if((matches[i][0].distance < 0.6*(matches[i][1].distance)) && ((int) matches[i].size()<=2 && (int) matches[i].size()>0))
{
good_matches.push_back(matches[i][0]);
}
}
//Draw only "good" matches
drawMatches(object, kp_object, image, kp_image, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
if (good_matches.size() >= 4)
{
printf("Images matching %d , %d", good_matches.size(), kp_object.size());
//return 1;
for(int i = 0; i < good_matches.size(); i++)
{
//Get the keypoints from the good matches
obj.push_back(kp_object[ good_matches[i].queryIdx ].pt);
scene.push_back(kp_image[ good_matches[i].trainIdx ].pt);
}
//H = findHomography(obj, scene, CV_RANSAC);
//printf("Size : %d", H.size());
//perspectiveTransform(obj_corners, scene_corners, H);
//printf("Size : %d --- %d --- %d", H.size(), scene_corners.size());
}else{
printf("Images matching %d , %d", good_matches.size(), kp_object.size());
}
//Show detected matches
imshow("Good Matches", img_matches);
waitKey(0);
return 0;
이웃. 메소드에서 정확히 무슨 일이 일어나고 어떻게 matches 메소드가 채워지는지, 그리고 어떤 점이 채워지는지 알고 싶습니다. 0.6 근처 neibour 거리 비율 (nndr)를 사용
for(int i = 0; i < min(des_image.rows-1,(int) matches.size()); i++) //THIS LOOP IS SENSITIVE TO SEGFAULTS
{
if((matches[i][0].distance < 0.6*(matches[i][1].distance)) && ((int) matches[i].size()<=2 && (int) matches[i].size()>0))
{
good_matches.push_back(matches[i][0]);
}
}
IM 코드 세그먼트
, 난 good_matches 알아 및 nndr 값의 변화에 영향을 얼마나 얼마나 알고 싶어.이 코드를 해결할 수 있다면 큰 도움이 될 것입니다. 감사합니다. .
knnMatch (x, x, x) 방법을 설명해주십시오. 일치하는 점을 일치 벡터에 저장하고 있습니까? – posha
예. 일치 된 벡터에 일치하는 점을 저장합니다. @ scap3y는 알고리즘을 어디에서 가져 왔으며 여전히 메소드가 무엇을하는지 묻습니다. 그 종이를 읽고 무엇을 어떻게하는지 그 방법이 무엇인지 알아 내라. 게으르지 마라. 독서. – guneykayim