Skip to content

Commit afc0013

Browse files
committed
HoughCircles_chess
1 parent 70d67d2 commit afc0013

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2017/7/28 11:05
3+
# @Author : play4fun
4+
# @File : HoughCircles_chess.py
5+
# @Software: PyCharm
6+
7+
"""
8+
HoughCircles_chess.py:
9+
围棋
10+
"""
11+
12+
import cv2
13+
import numpy as np
14+
15+
img = cv2.imread('../data/weiqi.png')
16+
17+
img = cv2.medianBlur(img, 5)
18+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
19+
cv2.imshow('gray', gray)
20+
21+
# HoughCircles(image, method, dp, minDist, circles=None, param1=None, param2=None, minRadius=None, maxRadius=None)
22+
# circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=10, maxRadius=40)#有一些没有检测到
23+
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20, param1=100, param2=30, minRadius=10, maxRadius=50)
24+
25+
circles = np.uint16(np.around(circles))
26+
print(circles)
27+
28+
cv2.waitKey(0)
29+
for i in circles[0, :]:
30+
# draw the outer circle
31+
cv2.circle(img, (i[0], i[1]), i[2], (0, 255, 0), 2)
32+
# draw the center of the circle
33+
cv2.circle(img, (i[0], i[1]), 2, (0, 0, 255), 3)
34+
35+
cv2.imshow('detected chess', img)
36+
cv2.moveWindow('detected chess',y=0,x=img.shape[1])
37+
cv2.waitKey(100)
38+
39+
cv2.waitKey(0)
40+
cv2.destroyAllWindows()

data/weiqi.png

328 KB
Loading

0 commit comments

Comments
 (0)