Skip to content

Instantly share code, notes, and snippets.

#%% Read and resize images
import numpy as np
import cv2 as cv
# Read images
train_img = cv.imread('train.png')
query_img = cv.imread('query.png')
# Resize images
train_img = cv.resize(train_img, dsize=(600, 950))
@emnak
emnak / warping.py
Last active October 27, 2020 15:53
# Select good matched keypoints
ref_matched_kpts = np.float32([kp1[m[0].queryIdx].pt for m in good_matches])
sensed_matched_kpts = np.float32([kp2[m[0].trainIdx].pt for m in good_matches])
# Compute homography
H, status = cv.findHomography(sensed_matched_kpts, ref_matched_kpts, cv.RANSAC,5.0)
# Warp image
warped_image = cv.warpPerspective(img2, H, (img2.shape[1], img2.shape[0]))
@emnak
emnak / matching.py
Last active October 27, 2020 15:53
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
import numpy as np
import cv2 as cv
img = cv.imread('image.jpg')
gray= cv.cvtColor(img, cv.COLOR_BGR2GRAY)
akaze = cv.AKAZE_create()
kp, descriptor = akaze.detectAndCompute(gray, None)
img=cv.drawKeypoints(gray, kp, img)