我试图从下图中提取数字/数字:
首先,我尝试了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逻辑,我无法指出如何在图像中找到所需数字的位置。在
我真的很困惑,我怎么从图像中提取数字呢。在
我正在寻找一些提示或指南,甚至代码来完成我的任务
提前谢谢