Python Computer Vision: Harris Corner
Harris Corner 偵測:
看了 CV 的書實做了一下 Harris Corner Detector,原理等之後有空再補吧(Latex 好麻煩XDD)
def compute_harris_responce(im, sigma=3): """ Compute the Harris response of each pixel in the gray-scale image. """ from scipy.ndimage import filters import numpy as np imx = np.zeros(im.shape) filters.gaussian_filter(im, (sigma,sigma), (0,1), imx) imy = np.zeros(im.shape) filters.gaussian_filter(im, (sigma,sigma), (1,0), imy) # compute Harris corner Wxx = filters.gaussian_filter(imx*imx, sigma) Wxy = filters.gaussian_filter(imx*imy, sigma) Wyy = filters.gaussian_filter(imy*imy, sigma) Wdet = Wxx * Wyy - Wxy ** 2 Wtr = Wxx + Wyy return Wdet/Wtr if __name__ == "__main__": import numpy as np from matplotlib import pyplot as plt from PIL import Image from scipy.ndimage import filters pli_img = Image.open("TT.jpg").convert("L") img = np.array(pli_img) plt.subplot(121) plt.axis("off") plt.imshow(img, cmap="gray") # compute and display Harris corner harris_response = compute_harris_responce(img) plt.subplot(122) plt.axis("off") plt.imshow(harris_response, cmap="gray") plt.show()
結果如下:
留言
張貼留言