600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > python抓取图片数字_从opencv python图像中提取数字

python抓取图片数字_从opencv python图像中提取数字

时间:2022-04-05 13:45:24

相关推荐

python抓取图片数字_从opencv python图像中提取数字

我试图从下图中提取数字/数字:

首先,我尝试了OCR,但是输出不相关,所以我计划使用opencv和{}

我写了以下代码:import numpy as np

import cv2

from matplotlib import pyplot as plt

#cv2.IMREAD_COLOR = 1 , Loads a color image. Any transparency of image will be neglected. It is the default flag.

#cv2.IMREAD_GRAYSCALE = 0 , Loads image in grayscale mode

#cv2.IMREAD_UNCHANGED = -1 , Loads image as such including alpha channel

image = cv2.imread( './in.png' , 1 )

gray = cv2.cvtColor( image, cv2.COLOR_BGR2GRAY )

ret1, thresh1 = cv2.threshold( gray, 127, 255, cv2.THRESH_BINARY )

image[ thresh1 == 0 ] = 255

kernal = cv2.getStructuringElement( cv2.MORPH_ELLIPSE, ( 5,5 ) )

erosion = cv2.erode( image, kernal, iterations = 1 )

cv2.imwrite( 'res.png', erosion )

我得到的结果是:

此时,我至少站在某个地方完成我的任务,但我无法决定进一步提取内容的步骤,我在google上找到了contours的内容,因此我尝试使用以下代码:

^{pr2}$

输出图像为:

同样,根据contours逻辑,我无法指出如何在图像中找到所需数字的位置。在

我真的很困惑,我怎么从图像中提取数字呢。在

我正在寻找一些提示或指南,甚至代码来完成我的任务

提前谢谢

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。