如何使用python检测复选框

时间:2022-12-14 00:06:06

I have the below PNG image and I am trying to identify which box is checked using Python.

我有下面的PNG图像,我试图确定使用Python检查哪个框。

I installed the OMR (optical mark recognition) package https://pypi.python.org/pypi/omr/0.0.7 but it wasn't any help and there wasn't any documentation about OMR. So I need to know if there is any API or useful package I can use with Python.

我安装了OMR(光学标记识别)软件包https://pypi.python.org/pypi/omr/0.0.7,但它没有任何帮助,也没有任何关于OMR的文档。所以我需要知道我是否可以使用任何API或有用的包。

Here is my image:

这是我的形象:

如何使用python检测复选框

1 个解决方案

#1


3  

If you're not afraid of a little experimenting, the Python Imaging Library (PIL, download from http://www.pythonware.com/products/pil/ or your favorite repo. Manual: http://effbot.org/imagingbook/pil-index.htm) permits loading the PNG, and accessing it.

如果您不害怕进行一些实验,可以使用Python成像库(PIL,从http://www.pythonware.com/products/pil/下载或您最喜爱的回购手册:手册:http://effbot.org/imagingbook /pil-index.htm)允许加载PNG并访问它。

You can extract a section of the image (eg. the interior of a checkbox. See 'crop' in the library), and sum the pixels in that sub-image (see 'point'). Compare that with a threshold (say > 10 pixels = checked).

您可以提取图像的一部分(例如,复选框的内部。请参阅库中的“裁剪”),并对该子图像中的像素求和(请参阅“点”)。将其与阈值进行比较(例如> 10像素=检查)。

If the PNG comes from scanning forms, you may have to add some positional checking.

如果PNG来自扫描表单,您可能需要添加一些位置检查。

#1


3  

If you're not afraid of a little experimenting, the Python Imaging Library (PIL, download from http://www.pythonware.com/products/pil/ or your favorite repo. Manual: http://effbot.org/imagingbook/pil-index.htm) permits loading the PNG, and accessing it.

如果您不害怕进行一些实验,可以使用Python成像库(PIL,从http://www.pythonware.com/products/pil/下载或您最喜爱的回购手册:手册:http://effbot.org/imagingbook /pil-index.htm)允许加载PNG并访问它。

You can extract a section of the image (eg. the interior of a checkbox. See 'crop' in the library), and sum the pixels in that sub-image (see 'point'). Compare that with a threshold (say > 10 pixels = checked).

您可以提取图像的一部分(例如,复选框的内部。请参阅库中的“裁剪”),并对该子图像中的像素求和(请参阅“点”)。将其与阈值进行比较(例如> 10像素=检查)。

If the PNG comes from scanning forms, you may have to add some positional checking.

如果PNG来自扫描表单,您可能需要添加一些位置检查。