-
-
Save amankharwal/97942aa0ac00678b68ad60b55a8ad7c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
cap = cv2.VideoCapture(0) | |
while(True): | |
ret, frame = cap.read() | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
gray = cv2.medianBlur(gray, 5) | |
# Extract regions/pixels of interest | |
rows = gray.shape[0] | |
# Find circles: | |
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, rows / 8, | |
param1=100, param2=30, | |
minRadius=1, maxRadius=30) | |
# Found circles ? Draw on top of them | |
if circles is not None: | |
circles = np.uint16(np.around(circles)) | |
for i in circles[0, :]: | |
center = (i[0], i[1]) | |
# circle center | |
cv2.circle(frame, center, 1, (0, 100, 100), 3) | |
# circle outline | |
radius = i[2] | |
cv2.circle(frame, center, radius, (255, 0, 255), 3) | |
# Display orignal frame: | |
cv2.imshow('frame', frame) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
cap.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment