简体   繁体   English

我正在尝试使用 pytesseract 从图像中读取数据

[英]im trying to read the data from the image using pytesseract

i tried to open read the image using the pytesseract, however the code is not able to read it please check this photo im using for reading the text.我尝试使用 pytesseract 打开读取图像,但是代码无法读取它,请检查我用于读取文本的这张照片。 在此处输入图像描述

below is my code:-以下是我的代码:-

import cv2
import time
import pyscreenshot as ImageGrab
import pytesseract
pytesseract.pytesseract.tesseract_cmd=r'C:/Users/RTam/AppData/Local/Programs/Tesseract-OCR/tesseract.exe'

def takescreenshot():
    
    path= (r'C:\Users\RTam\Desktop\python basics\web scraping\Pyautogui\photos')
    im=ImageGrab.grab(bbox=(900,1000,1200,1100))
    
    im.save(path+'\\'+'ss.png')

img= cv2.imread(r'C:\Users\RTam\Desktop\python basics\web scraping\Pyautogui\photos\ss3.png')

cv2.imshow('sample',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

sample_text= pytesseract.image_to_string(img)
print(sample_text)

the only output im getting is and empty space please help我得到的唯一 output 是空白空间,请帮忙

Eventually, I found the answer to my question.最终,我找到了问题的答案。

However this code will not run properly in Spyder IDE, so we should make sure we have the latest tesseract version.但是这段代码在 Spyder IDE 中无法正常运行,所以我们应该确保我们拥有最新的 tesseract 版本。

import cv2
import time
import pyscreenshot as ImageGrab
import pytesseract
pytesseract.pytesseract.tesseract_cmd=r'C:/Users/RTam/AppData/Local/Programs/Tesseract-OCR/tesseract.exe'

def takescreenshot():
    
    path= (r'C:\Users\RTam\Desktop\python basics\web scraping\Pyautogui\photos')
    im=ImageGrab.grab(bbox=(900,1000,1200,1100))
    
    im.save(path+'\\'+'ss.png')

img= cv2.imread(r'C:\Users\RTam\Desktop\python basics\web scraping\Pyautogui\photos\ss3.png')

def clerify_pic():
    img2 = cv2.resize(img, (0, 0), fx=2, fy=2)
    gry = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
    thr = cv2.threshold(gry, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
    
    
    return pytesseract.image_to_string(thr)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM