Posts

Showing posts with the label ocr

Pytesseract loop error

Pytesseract loop error I'm trying to loop pytesseract code to convert multiple images(18) into strings and name the output in sequece. tried to rearrange and replace the loop position more errors accur. import cv2 import numpy as np import pytesseract from PIL import Image src_path = "/home/pi/Desktop/" def get_string(img_path): for n in range(0,18): n=n+1 img = cv2.imread(img_path) img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) kernel = np.ones((1, 1), np.uint8) img = cv2.dilate(img, kernel, iterations=1) img = cv2.erode(img, kernel, iterations=1) cv2.imwrite(src_path + "removed_noise"+ n +".png",img) cv2.imwrite(src_path +"thres"+ n +".png", img) result = pytesseract.image_to_string(Image.open(src_path + "thres"+ n +".png")) return result print (get_string(src_path +"sample"+ str(n) +".jpeg")) print ("------ D...