如何在Python中提取OMR数据? 我目前正在从事一个OMR数据提取项目,我必须检查学生OMR表。这是我的代码片段: 导入CV2 导入numpy作为NP #阅读图像 路径='./data/images/5.jpg' ...

问题描述 投票:0回答:1
这是我目前卡在的地方 我有一个想法将它们转换为网格,并以某种方式将每个块定义为二进制。 0->白色,1->黑色。但是我不知道该怎么做,因为我目前正在学习所有这些东西。

[

后轮廓图](
https://i.sstatic.net/v82nadjo.png

) 我试图通过识别轮廓来解决它,但是在识别轮廓之后,我没有成功,我不知道如何提取圆形且在气泡内部完全具有黑色的轮廓。如果我设法以某种方式这样做,我认为我可以做其余部分。

获得Mark Locaitons:

首先预处理图像检测图像 以(x,y)获取轮廓及其中心位置

用坐标决定选择为a,b,c或d

我可以解释如何正确过滤图像以及如何获取轮廓。您首先需要采用开放操作
python numpy opencv ocr omr
1个回答
0
投票
这是您的原始图像:

  • 这是打开的图像:

最终是检测到的轮廓(绿色)及其中心(蓝色):

original image

这是完整的代码,我相信您可以使用theese坐标来确定每个标记的选定选项。

import cv2 import numpy #Read the image and convert it to black-white the binary image test_image = cv2.imread('test_result.png') h,w,c = test_image.shape gray_image = cv2.cvtColor(test_image,cv2.COLOR_BGR2GRAY) lvl, thresholded_image = cv2.threshold(gray_image,150,255,cv2.THRESH_BINARY) #Make opening on the image to remove the samaller white blobs opened = cv2.morphologyEx(thresholded_image,cv2.MORPH_OPEN,cv2.getStructuringElement(cv2.MORPH_RECT,(11,11))) #Make the contour detection on the image and get their coordinates contours,hierarchy = cv2.findContours(opened,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) for cnt in contours: cv2.drawContours(test_image,[cnt],-1,(0,255,0),2) # compute the center of the contour M = cv2.moments(cnt) cx = int(M["m10"] / M["m00"]) cy = int(M["m01"] / M["m00"]) cv2.circle(test_image,(cx,cy),7,(255,0,0),-1) #Show the results cv2.imshow('Thresh',cv2.resize(thresholded_image,(int(w*720/h),720))) cv2.imshow('Original',cv2.resize(test_image,(int(w*720/h),720))) cv2.imshow('Opened',cv2.resize(opened,(int(w*720/h),720))) cv2.waitKey()`

opened image

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.