gpt4 book ai didi

python - 我正在尝试分析 Scantron 表单并为 OMR 项目创建 key

转载 作者:行者123 更新时间:2023-12-02 17:06:40 28 4
gpt4 key购买 nike

Scantron Key
因此,我尝试使用 OpenCV 扫描此表格,并从本质上为标记的问题制定一个 key 。现在,我尝试关闭一些我在网上找到的示例,并将其转换为二进制图像,但是在检测问题的标记时遇到了问题。我是通过我在网上找到的教程完成的,但他们使用了不同格式的表单,并且此表单上的 Material 比示例中显示的要多得多,我可以使用更熟悉 OpenCV 的人的一些输入。帮助不一定是对我的代码甚至工作代码的改进,它可能是对更有用的文档、 Material 或教程的链接和引用。
Binary of Key

def analyzeKey(self):
keypix = self.doc.getPagePixmap(0, alpha=False)
keyim = self.pixel2np(keypix)
cv2.imwrite("keyimage.jpg",keyim)
key = cv2.imread("keyimage.jpg")

grayscale = cv2.cvtColor(key, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(grayscale, (5, 5), 0)
edged = cv2.Canny(blurred, 75, 200)
cv2.imshow("Key", edged)


cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
docCnt = None

# ensure that at least one contour was found
if len(cnts) > 0:
# sort the contours according to their size in
# descending order
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)

# loop over the sorted contours
for c in cnts:
# approximate the contour
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
# if our approximated contour has four points,
if len(approx) == 4:
docCnt = approx
break

#originalkey = four_point_transform(key, docCnt.reshape(4, 2))
#newkey = four_point_transform(grayscale, docCnt.reshape(4, 2))
keyim[:,:,2] = 0
cv2.imshow("Split",keyim)
thresh = cv2.threshold(grayscale, 0,255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cv2.imshow("Otsu", thresh)
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
questionCnts = []

for cntrs in cnts:
(x, y, w, h) = cv2.boundingRect(c)
ar = w / float(h)

if w>= 20 and h>=20 and ar>=0.9 and ar<=1.1:
questionCnts.append(c)

cv2.imshow("cnts", questionCnts[0])

最佳答案

为了获得铅笔标记的轮廓,而不是阈值,您可以使用 cv2.inRange 区分灰色/黑色铅笔标记和橙色文本。 .您将为允许的颜色选择一个下限和上限。这里我简单地选择黑色作为下界,灰色(180,180,180)作为上界,并应用于你给的彩色图像。这些值之间的任何像素都在下面显示的输出掩码中指示。

img = cv2.imread('keyimage.jpg')
lower_bound = (0,0,0)
upper_bound = (180,180,180)
mask = cv2.inRange(img, lower_bound, upper_bound)
plt.imshow(mask, cmap='gray')
plt.show()

enter image description here

关于python - 我正在尝试分析 Scantron 表单并为 OMR 项目创建 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53180248/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com