import numpy as np
import cv2
capture = cv2.VideoCapture(0)
while capture.isOpened():
retval, image = capture.read()
cv2.imshow("Video", image)
key = cv2.waitKey(1)
if key == 32:
break
img = image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# blurred = cv2.GaussianBlur(gray, (5, 5), 0)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 70, param1=100, param2=50, minRadius=150, maxRadius=500)
circles = np.uint(circles)
for c in circles[0]:
x, y, radius = c;
# edged = cv2.Canny(blurred, 75, 200)
# contours, hierarchy = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# center, radius = cv2.minEnclosingCircle(contours[-1])
# x = int(np.around(center[0]))
# y = int(np.around(center[1]))
cv2.circle(img, (x, y), int(radius), (0, 0, 255), 2)
# sp = img.shape
# img_x = int(np.around(sp[0] / 2))
# img_y = int(np.around(sp[1] / 2))
# k = 10 / (2 * int(radius))
# d_x = (x - img_x) * k
# d_y = (y - img_y) * k
cv2.imshow("img", img)
capture.release()
cv2.destroyAllWindows()
opcv圆环识别
最新推荐文章于 2024-09-11 20:22:41 发布