简体   繁体   English

我如何从左到右绘制轮廓答题卡

[英]how can i drawContours answer sheet from left to right

help how can i do about this code i want to answer check from answer sheet top-bottom then left-right but this code do left-right and top-bottom帮助我如何处理这个代码我想从答题卡上下然后左右回答检查,但是这个代码是左右和上下

for (q, i) in enumerate(np.arange(0, len(questionCnts), 5)):
    # sort the contours for the current question from
    # left to right, then initialize the index of the
    # bubbled answer
    cnts = contours.sort_contours(questionCnts[i:i + 5])[0]
    bubbled = None  


    # loop over the sorted contours
    for (j, c) in enumerate(cnts):
        # construct a mask that reveals only the current
        # "bubble" for the question
        mask = np.zeros(thresh.shape, dtype="uint8")
        cv2.drawContours(mask, [c], -1, 255, -1)

        # apply the mask to the thresholded image, then
        # count the number of non-zero pixels in the
        # bubble area
        mask = cv2.bitwise_and(thresh, thresh, mask=mask)
        total = cv2.countNonZero(mask)

        # if the current total has a larger number of total
        # non-zero pixels, then we are examining the currently
        # bubbled-in answer
        if bubbled is None or total > bubbled[0]:
            bubbled = (total, j)

    # initialize the contour color and the index of the
    # *correct* answer
    color = (0, 0, 255)
    k = ANSWER_KEY[q]

    # check to see if the bubbled answer is correct
    if k == bubbled[1]:
        color = (0, 255, 0)
        correct += 1

    # draw the outline of the correct answer on the test
    cv2.drawContours(paper, [cnts[k]], -1, color, -1)

img 1 answerSheet img 2 answer you will see the answer sheet in img1 but the real answer is img2 in img2 answer 1 is A answer 2 is 2 but now in the img1 answer 11 is 2 how can i do img 1 answerSheet img 2 answer你会在img1中看到答案表,但真正的答案是img2中的img2答案 1 是 A 答案 2 是 2 但现在在img1中答案 11 是 2 我该怎么办

Before you start iterating over all the contours, sort all of them based on y co-ordinate.在开始迭代所有轮廓之前,根据 y 坐标对所有轮廓进行排序。 Then start iterating in batches of 10(each row) and sort each batch based on x co-ordinate.然后开始以 10 个批次(每行)进行迭代,并根据 x 坐标对每个批次进行排序。 This way you will get every contour in the right sequence.这样,您将以正确的顺序获得每个轮廓。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM