Skip to content

Commit 9eee6f9

Browse files
committed
corner detection
1 parent 96aedbd commit 9eee6f9

14 files changed

+141
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,6 @@ code_077 | [Video Read, Write and Process](python/code_077/opencv_077.py) |
119119
code_078 | [Identify and Track Specific Color Objects in Video](python/code_078) | ✔️
120120
code_079 | [Video Analysis-Background/Foreground Extraction](python/code_079/opencv_079.py) | ✔️
121121
code_080 | [Video Analysis–Background Subtraction and ROI Extraction of the Foreground](python/code_080) | ✔️
122+
code_081 | [Corner Detection-Harris](python/code_081) | ✔️
123+
code_082 | [Corner Detection-Shi-Tomas](python/code_082) | ✏️
124+
code_083 | [Corner Detection-Sub-Pixel ](python/code_083) | ✔️

README_CN.md

+3
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@ code_077 | [视频读写和处理](python/code_077/opencv_077.py) | ✏️
118118
code_078 | [识别与跟踪视频中的特定颜色对象](python/code_078) | ✔️
119119
code_079 | [视频分析-背景/前景 提取](python/code_079/opencv_079.py) | ✔️
120120
code_080 | [视频分析–背景消除与前景ROI提取](python/code_080) | ✔️
121+
code_081 | [角点检测-Harris角点检测](python/code_081) | ✔️
122+
code_082 | [角点检测-Shi-Tomas角点检测](python/code_082) | ✏️
123+
code_083 | [角点检测-亚像素角点检测](python/code_083) | ✔️

python/code_081/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#### More Detail, please check the blog of zhihu as below
2+
✈️ ✈️ ✈️ [OpenCV图像处理- 角点检测](https://zhuanlan.zhihu.com/p/68571164)

python/code_081/chessboard.jpg

8.67 KB
Loading

python/code_081/opencv_081.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import numpy as np
2+
import cv2 as cv
3+
4+
5+
def harris(image, opt=1):
6+
# Detector parameters
7+
blockSize = 2
8+
apertureSize = 3
9+
k = 0.04
10+
# Detecting corners
11+
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
12+
dst = cv.cornerHarris(gray, blockSize, apertureSize, k)
13+
# Normalizing
14+
dst_norm = np.empty(dst.shape, dtype=np.float32)
15+
cv.normalize(dst, dst_norm, alpha=0, beta=255, norm_type=cv.NORM_MINMAX)
16+
17+
# Drawing a circle around corners
18+
for i in range(dst_norm.shape[0]):
19+
for j in range(dst_norm.shape[1]):
20+
if int(dst_norm[i, j]) > 120:
21+
cv.circle(image, (j, i), 2, (0, 255, 0), 2)
22+
# output
23+
return image
24+
25+
26+
src = cv.imread("chessboard.jpg")
27+
cv.imshow("input", src)
28+
result = harris(src)
29+
cv.imshow('result', result)
30+
cv.imwrite('result.jpg', result)
31+
cv.waitKey(0)
32+
cv.destroyAllWindows()
33+
"""
34+
# For video:
35+
cap = cv.VideoCapture(0)
36+
while True:
37+
ret, frame = cap.read()
38+
cv.imwrite("input.png", frame)
39+
cv.imshow('input', frame)
40+
result = harris(frame)
41+
cv.imshow('result', result)
42+
k = cv.waitKey(5)&0xff
43+
if k == 27:
44+
break
45+
cap.release()
46+
cv.destroyAllWindows()
47+
"""

python/code_081/result.jpg

30.5 KB
Loading

python/code_082/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#### More Detail, please check the blog of zhihu as below
2+
✈️ ✈️ ✈️ [OpenCV图像处理- 角点检测](https://zhuanlan.zhihu.com/p/68571164)

python/code_082/blox.jpg

7.52 KB
Loading

python/code_082/opencv_082.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import numpy as np
2+
import cv2
3+
4+
5+
def process(image, opt=1):
6+
# Detecting corners
7+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
8+
corners = cv2.goodFeaturesToTrack(gray, 35, 0.05, 10)
9+
print(len(corners))
10+
for pt in corners:
11+
print(pt)
12+
b = np.random.random_integers(0, 256)
13+
g = np.random.random_integers(0, 256)
14+
r = np.random.random_integers(0, 256)
15+
x = np.int32(pt[0][0])
16+
y = np.int32(pt[0][1])
17+
cv2.circle(image, (x, y), 5, (int(b), int(g), int(r)), 2)
18+
# output
19+
return image
20+
21+
22+
src = cv2.imread("blox.jpg")
23+
cv2.imshow("input", src)
24+
result = process(src)
25+
cv2.imshow('result', result)
26+
cv2.imwrite('result.jpg',result)
27+
cv2.waitKey(0)
28+
cv2.destroyAllWindows()

python/code_082/result.jpg

20.1 KB
Loading

python/code_083/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#### More Detail, please check the blog of zhihu as below
2+
✈️ ✈️ ✈️ [OpenCV图像处理- 角点检测](https://zhuanlan.zhihu.com/p/68571164)

python/code_083/opencv_083.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import numpy as np
2+
import cv2 as cv
3+
4+
5+
def process(image, opt=1):
6+
# Detecting corners
7+
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
8+
corners = cv.goodFeaturesToTrack(gray, 100, 0.05, 10)
9+
print(len(corners))
10+
for pt in corners:
11+
print(pt)
12+
b = np.random.random_integers(0, 256)
13+
g = np.random.random_integers(0, 256)
14+
r = np.random.random_integers(0, 256)
15+
x = np.int32(pt[0][0])
16+
y = np.int32(pt[0][1])
17+
cv.circle(image, (x, y), 5, (int(b), int(g), int(r)), 2)
18+
19+
# detect sub-pixel
20+
winSize = (3, 3)
21+
zeroZone = (-1, -1)
22+
23+
# Stop condition
24+
criteria = (cv.TERM_CRITERIA_EPS + cv.TermCriteria_COUNT, 40, 0.001)
25+
# Calculate the refined corner locations
26+
corners = cv.cornerSubPix(gray, corners, winSize, zeroZone, criteria)
27+
# display
28+
for i in range(corners.shape[0]):
29+
print(" -- Refined Corner [", i, "] (", corners[i, 0, 0], ",", corners[i, 0, 1], ")")
30+
return image
31+
32+
src = cv.imread("tyt.png")
33+
cv.imshow("input", src)
34+
result = process(src)
35+
cv.imshow('result', result)
36+
cv.imwrite('result.jpg',result)
37+
cv.waitKey(0)
38+
cv.destroyAllWindows()
39+
40+
'''
41+
cap = cv.VideoCapture(0)
42+
while True:
43+
ret, frame = cap.read()
44+
frame = cv.flip(frame, 1)
45+
cv.imwrite("input.png", frame)
46+
cv.imshow('input', frame)
47+
result = process(frame)
48+
cv.imwrite('result.png', result)
49+
k = cv.waitKey(5)&0xff
50+
if k == 27:
51+
break
52+
cap.release()
53+
cv.destroyAllWindows()
54+
'''

python/code_083/result.jpg

57.8 KB
Loading

python/code_083/tyt.png

208 KB
Loading

0 commit comments

Comments
 (0)