카테고리 없음
[openCV]영상처리 - image matching
Eunn
2022. 7. 6. 20:55
반응형
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
queryImage= 'cv_cover.jpg'
trainImage='cv_desk.png'
plt.figure(figsize=(15,8))
plt.subplot(1,2,1)
plt.imshow(cv.cvtColor(cv.imread(queryImage), cv.COLOR_BGR2RGB))
plt.title('Query image')
plt.subplot(1,2,2)
plt.imshow(cv.cvtColor(cv.imread(trainImage), cv.COLOR_BGR2RGB))
plt.title('Desk image')
plt.show()
img1 = cv.imread(queryImage,cv.IMREAD_GRAYSCALE)
img2 = cv.imread(trainImage,cv.IMREAD_GRAYSCALE)
## ORB : 여러 피처매칭 알고리즘 중 가장 빠르고 잘되는 것으로 익히 알려져 있음.
# Initiate ORB detector ( ORB디텍터를 생성 )
orb = cv.ORB_create()
# find the keypoints and descriptors with ORB (# ORB로 키포인트 및 설명자 찾기)
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
# descriptor 매치
matches = bf.match(des1,des2)
# Sort them in the order of their distance (거리순으로 정렬)
matches = sorted(matches, key = lambda x:x.distance)
# Draw first 10 matches(거리 순 상위10개 매치)
img3 = cv.drawMatches(img1,kp1,img2,kp2,matches[:10],None,flags=cv.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
plt.figure(figsize=(15,8))
plt.imshow(img3)
plt.show()
다음 파트에서는 호모그래피를 통한 warping에 대해서 다룰 예정입니다.
반응형