我试图在python中使用pytesseract但总是最终得到错误:
"TesseractNotFoundError:没有安装tesseract,或者它不在你的路径中"
pytesseract和tesseract安装在系统中.我是python的新手,所以如果有人可以帮助我,我将非常感激
我正在使用python-tesseract从图像中提取单词.这是tesseract的python包装器,它是一个OCR代码.
我使用以下代码来获取单词:
import tesseract
api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyz")
api.SetPageSegMode(tesseract.PSM_AUTO)
mImgFile = "test.jpg"
mBuffer=open(mImgFile,"rb").read()
result = tesseract.ProcessPagesBuffer(mBuffer,len(mBuffer),api)
print "result(ProcessPagesBuffer)=",result
Run Code Online (Sandbox Code Playgroud)
这仅返回图像中的单词而不是它们的位置/大小/方向(或者换句话说,包含它们的边界框).我想知道是否有任何方法可以实现这一点
我有一个图像,想要检测其中的文本区域.
我试过TiRG_RAW_20110219项目,但结果并不理想.如果输入图像是http://imgur.com/yCxOvQS,GD38rCa,则它将生成http://imgur.com/yCxOvQS,GD38rCa#1作为输出.
谁能提出一些替代方案.我想通过仅将文本区域作为输入发送来改善tesseract的输出.
我的代码很简单,如下:
import pytesseract
from PIL import Image
img = Image.open('C:/temp/foo.jpg')
img.load()
i = pytesseract.image_to_string(img)
Run Code Online (Sandbox Code Playgroud)
我得到的错误响应是:
Traceback (most recent call last):
File "img.py", line 6, in <module>
i = pytesseract.image_to_string(img)
File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 161, in image_to
_string
File "build\bdist.win32\egg\pytesseract\pytesseract.py", line 94, in run_tesse
ract
File "C:\Users\%USER%\AppData\Local\Continuum\Anaconda\lib\subprocess.py",
line 710, in __init__
errread, errwrite)
File "C:\Users\%USER%\AppData\Local\Continuum\Anaconda\lib\subprocess.py",
line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
任何指导都会很棒.
将tesseract添加到我的路径变量有助于:
C:\Program Files (x86)\Tesseract-OCR
但是在尝试运行pytesseract时,代码现在崩溃了.
我目前正在使用 python 2.7 进行最佳字符识别项目,在 Windows 中打开计算机视觉。为了完成这项任务,我知道它可以通过使用 tesseract (软件)来完成。但是,它不能安装在 Windows 上。我搜索了很多,但找不到解决方案。谁能告诉我有什么方法可以在 Windows 上安装它吗?或者可以不使用它来完成吗?
我正在尝试从图像中识别文本,然后输出文本;然而,这个错误吐出来了:
回溯(最近一次通话):文件“C:/Users/Benji's Beast/AppData/Local/Programs/Python/Python37-32/imageDet.py”,第 41 行,打印中(get_string(src_path + "cont.jpg") ) ) 文件“C:/Users/Benji's Beast/AppData/Local/Programs/Python/Python37-32/imageDet.py”,第 15 行,在 get_string img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cv:: cvt颜色'
图像分辨率为 1371x51。我曾尝试将 src_path 上的“/”更改为“\”,但这没有用。有任何想法吗?
这是我的代码:
import cv2
import numpy as np
import pytesseract
from PIL import Image
from pytesseract import image_to_string
# Path of working folder on Disk
src_path = "C:/Users/Benji's Beast/Desktop/image.PNG"
def get_string(img_path):
# Read image with opencv
img = cv2.imread(img_path)
# Convert to gray
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# …Run Code Online (Sandbox Code Playgroud) 我有此python代码,可用于将写在图片中的文本转换为字符串,它确实适用于某些字符较大的图像,但不适用于我现在尝试的仅包含数字的图像。
有我的代码:
from PIL import Image
img = Image.open('img.png')
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
result = pytesseract.image_to_string(img)
print (result)
Run Code Online (Sandbox Code Playgroud)
为什么无法识别此特定图像,我该如何解决此问题?谢谢。
有图片:
我tesseract通过pytesseract绑定用于 OCR 。不幸的是,我在尝试提取包含下标样式数字的文本时遇到了困难——下标数字被解释为一个字母。
例如,在基本图像中:
我想将文本提取为“CH3”,即我不担心知道数字3是图像中的下标。
我在此使用的尝试tesseract是:
import cv2
import pytesseract
img = cv2.imread('test.jpeg')
# Note that I have reduced the region of interest to the known
# text portion of the image
text = pytesseract.image_to_string(
img[200:300, 200:320], config='-l eng --oem 1 --psm 13'
)
print(text)
Run Code Online (Sandbox Code Playgroud)
不幸的是,这将错误地输出
'CHs'
Run Code Online (Sandbox Code Playgroud)
也有可能得到'CHa',具体取决于psm参数。
我怀疑这个问题与文本的“基线”在整个行中不一致有关,但我不确定。
如何从此类图像中准确提取文本?
更新 - 2020 年 5 月 19 日
在看到 Achintha Ihalage 的回答后tesseract,我没有为 提供任何配置选项,我探索了这些psm选项。
由于感兴趣的区域是已知的(在这种情况下,我使用 …
我正在尝试使用 python 创建实时 OCRmss和pytesseract。
到目前为止,我已经能够捕获整个屏幕,其 FPS 稳定为 30。如果我想捕获大约 500x500 的较小区域,我已经能够获得 100+ FPS。
然而,一旦我添加这行代码,text = pytesseract.image_to_string(img)FPS 就会飙升 0.8。有什么方法可以优化我的代码以获得更好的 FPS?该代码还能够检测文本,只是速度非常慢。
from mss import mss
import cv2
import numpy as np
from time import time
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\\Users\\Vamsi\\AppData\\Local\\Programs\\Tesseract-OCR\\tesseract.exe'
with mss() as sct:
# Part of the screen to capture
monitor = {"top": 200, "left": 200, "width": 500, "height": 500}
while "Screen capturing":
begin_time = time()
# Get raw pixels from the screen, save it to …Run Code Online (Sandbox Code Playgroud) 这是原始屏幕截图,我将图像裁剪成4个部分,并将图像的背景清除到我可以做的范围,但tesseract只检测到最后一列而忽略了其余部分.
显示tesseract的输出,因为在处理结果时我删除了空格
Femme—Fatale.
DaRkLoRdEIa
aChineseN1gg4
Noob_Diablo_
Run Code Online (Sandbox Code Playgroud)
显示tesseract的输出,因为在处理结果时我删除了空格
Kicked.
NosNoel
ChikiZD
Death_Eag|e_42
Chai—.
Run Code Online (Sandbox Code Playgroud)
3579 10 1 7 148
2962 3 O 7 101
2214 2 2 7 99
2205 1 3 6 78
Run Code Online (Sandbox Code Playgroud)
8212
7198
6307
5640
4884
15
40
40
6O
80
80
Run Code Online (Sandbox Code Playgroud)
我只是倾销输出
result = `pytesseract.image_to_string(Image.open("D:/newapproach/B&W"+str(i)+".jpg"),lang="New_Language")`
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何从这里开始获得一致的结果.无论如何,我可以强制tesseract识别文本区域并使其扫描.因为在培训师(SunnyPage)中,tesseract默认识别扫描它无法识别某些区域,但一旦我选择手动,一切都被检测到并正确翻译成文本
python-tesseract ×10
python ×9
tesseract ×7
ocr ×5
opencv ×4
python-3.x ×2
cv2 ×1
pytesser ×1
python-2.7 ×1