简体   繁体   中英

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. 在此处输入图像描述

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

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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