이미지의 SURF 포인트를 비디오 피드와 일치시킵니다. 다양한 해상도로 테스트하고 싶지만 일치하는 키포인트를 작은 해상도로 그릴 때 색상이있는 키포인트로 인해 비디오 피드에서 어떤 현상이 발생하는지 더 이상 볼 수 없다는 성가신 문제가 있습니다. OpenCV에서 동영상을 그리는 것을 중지하고 동성어 만 표시하는 방법이 있습니까?OpenCV DrawMatchesFlags - 키포인트 옵션이 없습니까?
나는 DrawMatchesFlags
에 대한 옵션을 살펴 보았지만, 그 옵션을 제거하는 대신 그려지는 키포인트의 유형을 변경하는 것만 보였다. I는 drawMatches
사용하여 그려진 키포인트 데있다 Mat img_matches
만드는거야 : 사용
drawMatches(img_object, keypoints_object, frame, keypoints_scene, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
난 후 OpenCV의 findHomography
함수를 사용하여 호모 그래피를 검출하고 그 결과를 묘화하고 :
imshow("Good Matches & Object detection", img_matches);
비디오 피드에서 일치하는 특징점을 제거하고 동성애 만 표시하려면 어떻게합니까?
편집 :
감지 및 그리기 기능 :
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
std::vector<cv::KeyPoint> keypoints_object, keypoints_scene;
detector.detect(img_object, keypoints_object);
detector.detect(frame, keypoints_scene);
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute(img_object, keypoints_object, descriptors_object);
extractor.compute(frame, keypoints_scene, descriptors_scene);
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector<DMatch> matches;
matcher.match(descriptors_object, descriptors_scene, matches);
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for(int i = 0; i < descriptors_object.rows; i++)
{ double dist = matches[i].distance;
if(dist < min_dist) min_dist = dist;
if(dist > max_dist) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist);
printf("-- Min dist : %f \n", min_dist);
//-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist)
std::vector<DMatch> good_matches;
for(int i = 0; i < descriptors_object.rows; i++)
{ if(matches[i].distance < 3*min_dist)
{ good_matches.push_back(matches[i]); }
}
Mat img_matches;
drawMatches(img_object, keypoints_object, frame, keypoints_scene,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
//-- Localize the object
std::vector<Point2f> obj;
std::vector<Point2f> scene;
for(int i = 0; i < good_matches.size(); i++)
{
//-- Get the keypoints from the good matches
obj.push_back(keypoints_object[ good_matches[i].queryIdx ].pt);
scene.push_back(keypoints_scene[ good_matches[i].trainIdx ].pt);
}
Mat H = findHomography(obj, scene, CV_RANSAC);
//-- Get the corners from the image_1 (the object to be "detected")
std::vector<Point2f> obj_corners(4);
obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint(img_object.cols, 0);
obj_corners[2] = cvPoint(img_object.cols, img_object.rows); obj_corners[3] = cvPoint(0, img_object.rows);
std::vector<Point2f> scene_corners(4);
perspectiveTransform(obj_corners, scene_corners, H);
//-- Draw lines between the corners (the mapped object in the scene - image_2)
line(img_matches, scene_corners[0] + Point2f(img_object.cols, 0), scene_corners[1] + Point2f(img_object.cols, 0), Scalar(0, 255, 0), 4);
line(img_matches, scene_corners[1] + Point2f(img_object.cols, 0), scene_corners[2] + Point2f(img_object.cols, 0), Scalar(0, 255, 0), 4);
line(img_matches, scene_corners[2] + Point2f(img_object.cols, 0), scene_corners[3] + Point2f(img_object.cols, 0), Scalar(0, 255, 0), 4);
line(img_matches, scene_corners[3] + Point2f(img_object.cols, 0), scene_corners[0] + Point2f(img_object.cols, 0), Scalar(0, 255, 0), 4);
당신이 당신의 검출 및 도면 기능을 보여줄 수 있을까? 아마 당신은 당신의 코드에서이 "drawMatches()"를 제거해야 할 것입니다. 그것은 동형의 계산 및 그리기와 관련이 없습니다. – pwwpche
추가 된 코드가 추가되었습니다.이 함수를 제거 할 때 유일한 문제는 일치 된 점을'imshow' 함수에서 사용되는'img_matches'에 할당한다는 것입니다. – Colin747