특징점 매칭

BERT·2023년 5월 1일
0

Computer Vision

목록 보기
47/56

특징점 매칭

feature point matching, keypoint matching
두 영상에서 추출한 특징점 기술자를 비교하여 유사한 기술자끼리 선택하는 작업

특징 벡터 유사도 측정 방법

실수 특징 벡터 : L2 norm 사용
이진 특징 벡터 : Hamming distance 사용

OpenCV 특징점 매칭 클래스

cv::DescriptorMatcher
  match()
  knnMatch()
  radiusMatch()

BF : Brute-force (전수 조사)
Flann : Fast Library for Approximate Nearest Neighbor (K-D Tree 사용)

cv::BFMatcher
cv::FlannBasedMatcher
cv::DMatch
  queryIdx
  trainIdx
  imgIdx
  distance

최선의 매칭 반환

queryDescriptors : 질의 기술자 집합
trainDescriptors : 훈련 기술자 집합
matches : 매칭 결과
mask : 서로 매칭 가능한 질의 기술자와 훈련 기술자를 지정할 때 사용

void DescriptorMatcher::match(InputArray queryDescriptors, InputArray trainDescriptors,
							  std::vector<DMatch>& matches,
                              InputArray mask = noArray()) const

상위 k개 매칭 반환

queryDescriptors : 질의 기술자 집합
trainDescriptors : 훈련 기술자 집합
matches : 매칭 결과
k : 찾고자 하는 최선의 매칭 결과 개수
mask : 서로 매칭 가능한 질의 기술자와 훈련 기술자를 지정할 때 사용
compactResult : mask 행렬이 비어있지 않을 때 사용되는 파라미터

void DescriptorMatcher::knnMatch(InputArray queryDescriptors,
								 InputArray trainDescriptors,
								 std::vector<std::vector<DMatch>>& matches,
                                 int k,
                                 InputArray mask = noArray(),
                                 bool compactResult = false) const

특징점 매칭 결과 영상 생성 함수

img1 영상에서 추출한 키포인트 keypoint1
img2 영상에서 추출한 키포인트 keypoint2
두 키포인트 사이의 매칭 결과 matches1to2 정보를 이용하여 outImg 영상을 생성
matchesMask는 매칭 정보를 선택하여 그릴 때 사용할 마스크로서 std::vector<char>()를 지정하면 모든 매칭 결과를 그림
flagsDrawMatchesFlags::NOT_DRAW_SINGLE_POINTS를 지정하면 매칭되지 않은 특징점은 그리지 않음

void drawMatches(InputArray img1, const std::vector<KeyPoint>& keypoint1,
				 InputArray img2, const std::vector<KeyPoint>& keypoint2,
                 const std::vector<DMatch>& matches1to2,
                 InputOutputArray outImg,
                 const Scalar& matchColor = Scalar::all(-1),
                 const Scalar& singlePointColor = Scalar::all(-1),
                 const std::vector<char>& matchesMask = std::vector<char>(),
                 int flags = DrawMatchesFlags::DEFAULT);

matching

좋은 매칭 선별 방법

#1

가장 좋은 매칭 결과에서 distance값이 작은 것 N개를 사용
DMatch::distance 값을 기준으로 정렬 후 상위 N개 선택
DMatch 클래스에 크기 비교 연산자(<) 오버로딩이 distance 멤버 변수를 사용하도록 되어 있음

#2

knnMatch()함수를 사용하여 두 개의 매칭 결과 반환
가장 좋은 매칭 결과의 distance 값과 두 번째로 좋은 매칭 결과의 distance 값의 비율을 계산
이 비율이 임계값보다 작으면 선택

matching

0개의 댓글