-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharris_demo.py
56 lines (41 loc) · 1.2 KB
/
harris_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
def myHarris(image):
"""Simple implementation of harris corner detector
Args:
image (np.array): gray image
"""
sobelx = np.array([[-1, 0, 1],
[-2, 0, 2],
[-1, 0, 1]])
sobely = np.array([[-1, -2, -1],
[0, 0, 0],
[1, 2, 1]])
Ixx = signal.convolve2d(signal.convolve2d(
image, sobelx, "same"), sobelx, "same")
Iyy = signal.convolve2d(signal.convolve2d(
image, sobely, "same"), sobely, "same")
Ixy = signal.convolve2d(signal.convolve2d(
image, sobelx, "same"), sobely, "same")
plt.figure("Original Image")
plt.set_cmap("gray")
plt.imshow(image)
plt.figure("Ixx")
plt.imshow(Ixx)
plt.figure("Iyy")
plt.imshow(Iyy)
plt.figure("Ixy")
plt.imshow(Ixy)
det = Ixx * Iyy - Ixy**2
trace = Ixx + Iyy
H = det - 0.2 * trace
plt.figure("Harris")
plt.imshow(np.abs(H))
plt.show()
if __name__ == '__main__':
# Create the image
image = np.zeros((200, 200))
image[50:150, 50:150] = 255
# Detect the corners
myHarris(image)