我在 Python 3 中使用 OpenCV 来检测白场上的白/黑球并给出准确的(x,y,半径)和颜色。
我使用函数 cv2.Canny() 和 cv2.findContours() 来找到它,但问题是 cv2.Canny() 并不总是检测到圆的完整形状(大多数时候只有圆的 3/4)。因此,当我使用 cv2.findContours() 时,它不会将其检测为轮廓。
请参见 :
和
这是最重要的代码:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(blurred, 10, 40) # 10 and 40 to be more perceptive
contours_canny= cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)[-2]
之后我使用:
approx = cv2.approxPolyDP(contour,0.01*cv2.arcLength(contour,True),True)
所以,如果你能帮我找到一个很棒的解决方案!也许有一个功能可以完成圆形的形状,以便我可以检测到它?