Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit43dfad1

Browse files
committed
edited hough transform tutorial
1 parent8da22e8 commit43dfad1

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

‎machine-learning/shape-detection/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ To run this:
88
- To detect lines of live camera:
99
```
1010
python live_shape_detector.py
11+
```
12+
- To detect circles on `coins.jpg` image, consider:
13+
```
14+
python circle_detector.py coins.jpg
1115
```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
importcv2
2+
importnumpyasnp
3+
importmatplotlib.pyplotasplt
4+
importsys
5+
6+
# load the image
7+
img=cv2.imread(sys.argv[1])
8+
# convert BGR to RGB to be suitable for showing using matplotlib library
9+
img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
10+
# make a copy of the original image
11+
cimg=img.copy()
12+
# convert image to grayscale
13+
img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
14+
# apply a blur using the median filter
15+
img=cv2.medianBlur(img,5)
16+
# finds the circles in the grayscale image using the Hough transform
17+
circles=cv2.HoughCircles(image=img,method=cv2.HOUGH_GRADIENT,dp=0.9,
18+
minDist=80,param1=110,param2=39,maxRadius=70)
19+
20+
forco,iinenumerate(circles[0, :],start=1):
21+
# draw the outer circle in green
22+
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
23+
# draw the center of the circle in red
24+
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
25+
26+
# print the number of circles detected
27+
print("Number of circles detected:",co)
28+
# save the image, convert to BGR to save with proper colors
29+
# cv2.imwrite("coins_circles_detected.png", cimg)
30+
# show the image
31+
plt.imshow(cimg)
32+
plt.show()
104 KB
Loading

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp