将轮廓与列表轮廓形状匹配

时间:2019-07-23 13:58:15

标签: python numpy opencv image-processing opencv-contour

我在下面创建了程序来更正答题纸。

https://gist.github.com/andreemidio/d2cdf3d301fd8df1677e9a315ff845f0

我能够绘制轮廓,识别填充,我需要匹配信息。

每行返回30个矩形轮廓,其中已填充的轮廓被标识。我现在需要知道这些填充的肺泡在该阵列中的位置。因此,我返回问题答案和所选选项。 我认为信息匹配的问题在代码的这一部分。

posicaoRespostas = np.empty(0,int)

for (q, i) in enumerate(np.arange(0, len(questionCnts), 30)):


cnts = contours.sort_contours(questionCnts[i:i+30])[0]

for (l ,k )in enumerate(cnts):
    (x, y, w, h) = cv2.boundingRect(k)
    if (w >= 20 and h >= 20) and (w <= 25  and h <= 25) and ar >= 0.7 and ar <= 1.3:
        box = [(x//5)*5, y]
    #print(x, y)

    posicaoRespostas = np.append(posicaoRespostas,(l))

    cv2.rectangle(bolhas, (x, y), (x+w, y+h), (0, 0, 255), 1) #desenho para visualização

我曾经用过Adrian Rosebrook的这篇文章

https://www.pyimagesearch.com/2016/10/03/bubble-sheet-multiple-choice-scanner-and-test-grader-using-omr-python-and-opencv/

原始

Imagem Original

尝试

Image processada

0 个答案:

没有答案