由於它不是一個簡單的問題,因此需要進行大量的調整才能使其健壯。但我想建議你一個好的起點。你可以玩它,並嘗試使其工作。
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的屬性檢查'查找輪廓',這會給我一些區域的輪廓陣列,從中我可以得到最大的輪廓或檢查它內部的填充像素的數量,但我仍然需要對像素數量進行一些固定的閾值來說明是否填充。這是你的觀點嗎? –