I’m using opencv-python
, and I am trying to visualize results from AKAZE keypoint matching for multiple images. While playing around with drawMatches
, several questions arose. Below is the code, and my questions:
import cv2
template_image cv2.imread("img1.tif")
target_image cv2.imread("img2.tif")
akaze = cv2.AKAZE_create()
kp1, des1 = akaze.detectAndCompute(template_image, None)
kp2, des2 = akaze.detectAndCompute(target_image, None)
matcher = cv2.DescriptorMatcher_create(cv2.DescriptorMatcher_BRUTEFORCE_HAMMING)
matches = matcher.knnMatch(des1, des2, 2)
good = []
for m, n in matches:
if m.distance < 0.8 * n.distance:
good.append(m)
results = cv2.drawMatches(template_image,kp1,
target_image,kp2,
good,None,
(0,255,0),
flags=1)
-
What is the correct use of the
DRAW_OVER_OUTIMG
flag (flag “1”)? I tried the following, but I get an error:
results = cv2.drawMatches(template_image, kp1, target_image, kp2, good, target_image, flags=1)
error: OpenCV(3.4.9) C:\projects\opencv-python\opencv\modules\features2d\src\draw.cpp:156: error: (-201:Incorrect size of input array) outImg has size less than need to draw img1 and img2 together in function 'cv::_prepareImgAndDrawKeypoints'
-
drawMatches takes
takes only two images, but I would like to visualize keypoint matches between the template and multiple target images - is there any way to do this? -
Can I change the image-matrix layout in
drawMatches
?