犯罪嫌疑人X
我知道它有点晚了,但我使用了更简单的方法。从cv2.HoughCircles(...)你得到圆的中心和直径(x,y,r)。因此,我只需浏览圆圈的所有中心点,然后检查它们是否远离图像边缘而不是直径。这是我的代码: height, width = img.shape[:2]
#test top edge
up = (circles[0, :, 0] - circles[0, :, 2]) >= 0
#test left edge
left = (circles[0, :, 1] - circles[0, :, 2]) >= 0
#test right edge
right = (circles[0, :, 0] + circles[0, :, 2]) <= width
#test bottom edge
down = (circles[0, :, 1] + circles[0, :, 2]) <= height
circles = circles[:, (up & down & right & left), :]