Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pytesseract可以';识别号码1_Python_Image_Python Tesseract - Fatal编程技术网

Python pytesseract可以';识别号码1

Python pytesseract可以';识别号码1,python,image,python-tesseract,Python,Image,Python Tesseract,我正在运行一个脚本,它会在一个无序的Numpad中返回数字和数字的位置。但在识别1时,我会得到71或7 这是我正在运行的脚本 numero.save(r'C:\imagenes\numeros\numero.png') image = Image.open(r'C:\imagenes\numeros\numero.png') inverted_image = PIL.ImageOps.invert(image) inverted_image.save(r'C:\imagenes\numeros

我正在运行一个脚本,它会在一个无序的Numpad中返回数字和数字的位置。但在识别1时,我会得到71或7

这是我正在运行的脚本

numero.save(r'C:\imagenes\numeros\numero.png')
image = Image.open(r'C:\imagenes\numeros\numero.png')
inverted_image = PIL.ImageOps.invert(image)
inverted_image.save(r'C:\imagenes\numeros\numero.png')

image = cv2.imread(r'C:\imagenes\numeros\numero.png')

numero = int(pytesseract.image_to_string(image, lang='spa', config='--psm 6 digits'))
print("numero :", numero)

if numero == 7 or numero not in numeros:
     numero_1_eng = int(pytesseract.image_to_string(image, lang='eng', config='--psm 6 digits'))
if numero_eng != 7:
     numero = 1
else:
     numero = numero_eng
print("numero:", numero)

vector = 930, 425, numero
vector_de_vectores.append(vector)

解决方案


1-应用自适应阈值

2-将tesseract配置设置为
--psm 7
(因为您试图识别单个文本行。请参阅全部)


自适应阈值化的结果

当你读到:

txt=pytesseract.image_to_字符串(thr,config=“--psm 7”)
打印(txt)
结果:

1
代码:


导入cv2
导入pytesseract
img=cv2.imread(“tUh0U.png”)
gry=cv2.CVT颜色(img,cv2.COLOR\u BGR2GRAY)
thr=cv2.自适应阈值(gry,252,cv2.自适应阈值平均值,
cv2.THRESH_二进制_INV,31,61)
txt=pytesseract.image_to_字符串(thr,config=“--psm 7”)
打印(txt)