Professional Documents
Culture Documents
Lab03_Feature Detection
Lab03_Feature Detection
image = gravel()
wimage = image * window('hann', image.shape) # window image to improve FFT
filtered_image = difference_of_gaussians(image, 1, 12)
filtered_wimage = filtered_image * window('hann', image.shape)
im_f_mag = fftshift(np.abs(fftn(wimage)))
fim_f_mag = fftshift(np.abs(fftn(filtered_wimage)))
import cv2
import numpy as np
from IPython.display import Image
def detect_corner(image_path, blockSize=2, ksize=3, k=0.04, threshold=0.01):
img = cv2.imread(image_path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray, blockSize, ksize, k)
#result is dilated for marking the corners, not important
dst = cv2.dilate(dst, None)
# Threshold for an optimal value, it may vary depending on the image.
img[dst>threshold*dst.max()]=[0, 0, 255]
cv2.imwrite('example.jpg',img)
return img
out_path = detect_corner('cat.jpg', blockSize=2, ksize=5, k=0.04, threshold=0.005)
Image(out_path)
Thử lại
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('example.jpg')
plt.imshow(img[:,:,::-1])
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0.04)
dst = cv2.dilate(dst,None)
img[dst>0.01*dst.max()] = [0,0,225]
plt.imshow(img[:,:,::-1])
https://www.youtube.com/watch?v=Kkkl0MCAD-
4&list=PL50pDT4Q2doQYwSJ7GglOQrlx0tgle-P0&index=6
image = gravel()
wimage = image * window('hann', image.shape) # window image to improve FFT
filtered_image = difference_of_gaussians(image, 1, 12)
filtered_wimage = filtered_image * window('hann', image.shape)
im_f_mag = fftshift(np.abs(fftn(wimage)))
fim_f_mag = fftshift(np.abs(fftn(filtered_wimage)))