forked from samwestby/OpenCV-Python-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_corner_detection.py
32 lines (25 loc) · 926 Bytes
/
5_corner_detection.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
import cv2
import numpy as np
img = cv2.imread("assets/shapes.png")
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# SHI-TOMASI METHOD
corners = cv2.goodFeaturesToTrack(gray_img, maxCorners=50,
qualityLevel=0.15, minDistance=50)
corners = np.int0(corners)
for c in corners:
x, y = c.ravel()
img = cv2.circle(img, center=(x, y), radius=20,
color=(0, 0, 255), thickness=-1)
# HARRIS CORNER DETECTION
corners = cv2.goodFeaturesToTrack(gray_img, maxCorners=50,
qualityLevel=0.01, minDistance=50,
useHarrisDetector=True, k=0.1)
corners = np.int0(corners)
for c in corners:
x, y = c.ravel()
img = cv2.circle(img, center=(x, y), radius=10,
color=(0, 254, 0), thickness=-1)
cv2.imshow("Shape", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("assets/5_shape_w_corners.png", img)