Skip to content

Commit 3b6af98

Browse files
authored
Add files via upload
1 parent f954736 commit 3b6af98

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
import cv2
3+
import numpy as np
4+
from matplotlib import pyplot as plt
5+
6+
#读取图像
7+
img = cv2.imread('eyes.png')
8+
9+
#灰度转换
10+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
11+
12+
#显示原始图像
13+
plt.subplot(121), plt.imshow(gray, 'gray'), plt.title('Input Image')
14+
plt.axis('off')
15+
16+
#霍夫变换检测圆
17+
circles1 = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20,
18+
param1=100, param2=30,
19+
minRadius=160, maxRadius=200)
20+
print(circles1)
21+
22+
#提取为二维
23+
circles = circles1[0, :, :]
24+
25+
#四舍五入取整
26+
circles = np.uint16(np.around(circles))
27+
28+
#绘制圆
29+
for i in circles[:]:
30+
cv2.circle(img, (i[0],i[1]), i[2], (255,0,0), 5) #画圆
31+
cv2.circle(img, (i[0],i[1]), 2, (255,0,255), 8) #画圆心
32+
33+
#显示处理图像
34+
plt.subplot(122), plt.imshow(img), plt.title('Result Image')
35+
plt.axis('off')
36+
plt.show()
37+
38+
39+

0 commit comments

Comments
 (0)