Last active
October 27, 2020 15:53
-
-
Save emnak/39e29522731d66250fd1ade620aaba52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 as cv | |
import matplotlib.pyplot as plt | |
img1 = cv.imread('image1.jpg', cv.IMREAD_GRAYSCALE) # referenceImage | |
img2 = cv.imread('image2.jpg', cv.IMREAD_GRAYSCALE) # sensedImage | |
# Initiate AKAZE detector | |
akaze = cv.AKAZE_create() | |
# Find the keypoints and descriptors with SIFT | |
kp1, des1 = akaze.detectAndCompute(img1, None) | |
kp2, des2 = akaze.detectAndCompute(img2, None) | |
# BFMatcher with default params | |
bf = cv.BFMatcher() | |
matches = bf.knnMatch(des1, des2, k=2) | |
# Apply ratio test | |
good_matches = [] | |
for m,n in matches: | |
if m.distance < 0.75*n.distance: | |
good_matches.append([m]) | |
# Draw matches | |
img3 = cv.drawMatchesKnn(img1,kp1,img2,kp2,good_matches,None,flags=cv.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS) | |
cv.imwrite('matches.jpg', img3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment