由于它不是一个简单的问题,因此需要进行大量的调整才能使其健壮。但我想建议你一个好的起点。你可以玩它,并尝试使其工作。
import numpy as np
import cv2
image_ori = cv2.imread("circle_opt.png")
lower_bound = np.array([0, 0, 0])
upper_bound = np.array([255, 255, 195])
image = image_ori
mask = cv2.inRange(image_ori, lower_bound, upper_bound)
masked_red = cv2.bitwise_and(image, image, mask=mask)
kernel = np.ones((3,3),np.uint8)
closing = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
contours = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)[0]
contours.sort(key=lambda x:cv2.boundingRect(x)[0])
print len(contours)
for c in contours:
(x,y),r = cv2.minEnclosingCircle(c)
center = (int(x),int(y))
r = int(r)
if 10 <= r <= 15:
cv2.circle(image,center,r,(0,255,0),2)
# cv2.imwrite('omr_processed.png', image_ori)
cv2.imshow("original",image_ori)
cv2.waitKey(0)
我从我的代码有您共享图像上的结果是这个
您可以将阈值以这些绿色盘旋补丁再算上非零来得到,如果圆被标记或不标记。您可以使用lower和upper_bound来尝试使解决方案健壮。
希望这会有所帮助!祝你的问题解决:)
恐怕你的问题太广泛了。有许多方法和许多可能的解决方案,但给出一个好的建议将需要更多的图像和一些限制。到目前为止,我的答案是:是的,有人知道其他方法将圆圈归类为填充。 – Piglet
@vzhadeyev使用区域 –
@JeruLuke的属性检查'查找轮廓',这会给我一些区域的轮廓阵列,从中我可以得到最大的轮廓或检查它内部的填充像素的数量,但我仍然需要对像素数量进行一些固定的阈值来说明是否填充。这是你的观点吗? –