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

Commit 8b19938

Browse files
Circle detection
1 parent 08b7bdd commit 8b19938

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# from turtle import circle
2+
import cv2
3+
import numpy as np
4+
from tkinter.filedialog import *
5+
import tkinter as tk
6+
7+
photo = askopenfilename()
8+
img = cv2.imread(photo,cv2.IMREAD_GRAYSCALE)
9+
blurred = cv2.medianBlur(img,5)
10+
edges = cv2.Canny(blurred,50,150,apertureSize=3)
11+
# the image read in grayscale format is blurred and edges are detected in it
12+
circles = cv2.HoughCircles(edges,cv2.HOUGH_GRADIENT,1,30,param1=50,param2=31,minRadius=0,maxRadius=0)
13+
# the parameters in the above function needs to be adjusted for each image accordingly.
14+
circles = np.uint16(np.around(circles))
15+
16+
colorImg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
17+
for i in circles[0,:]:
18+
cv2.circle(colorImg,(i[0],i[1]),i[2],(0,255,0),2)
19+
# drawing the circle
20+
cv2.circle(colorImg,(i[0],i[1]),2,(0,0,255),3)
21+
# drawing its center
22+
23+
cv2.imwrite('output.jpg',colorImg)
24+
cv2.imshow('output',colorImg)
25+
cv2.waitKey(2000)
26+
cv2.destroyAllWindows()

‎Circle_Detect_HoughCircle/ReadMe.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Circle detection
2+
This python script will allow us to identify circles in an image using Hough circle transform
3+
4+
## Setup Instructions
5+
### Install python3
6+
sudo apt-get install python3
7+
### Install pip (package installer for python)
8+
sudo apt-get install python3-pip
9+
### Install Numpy library with pip
10+
pip3 install numpy
11+
### Install OpenCV library with pip
12+
pip3 install opencv-python
13+
### Install tkinter library
14+
sudo apt-get install python3-tk
15+
16+
## Details/Output
17+
User is prompted to select an image and this script detects circles in it using the hough circle transform.
18+
19+
**Note** Each image needs its own set of parameters in cv2.HoughCircles() function. What worked for one might not work for another image.
20+
minDist(minimum distance between two centers), param1(parameter 1), param2(parameter 2) are to be adjusted until we get desired output.
21+
22+
The output image is written/stored in the current folder.
23+
24+
## Author
25+
Github: invigorzz313

‎Circle_Detect_HoughCircle/Sample.jpg‎

5.96 KB
Loading[フレーム]
17.8 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /