I wrote a program that scans text from images
The most of part is good but a small part has error
The error is about It scans non-text parts into symbols
the program I used Pytesseract and image processed
from PIL import Image
import pytesseract
from pathlib import Path as p
import cv2
import numpy as np
def image_processing(pic):
pic_np = np.array(pic)
adjusted = cv2.convertScaleAbs(pic_np,alpha=1.7,beta=0)
blurred = cv2.GaussianBlur(adjusted, (5, 5), 0)
pic2=cv2.cvtColor(blurred,cv2.COLOR_BGR2GRAY)
pic3 = cv2.adaptiveThreshold(pic2, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 85, 11)
#cv2.imshow('Adjusted Image',pic3)
#cv2.waitKey(0)
return pic3
path=p("D:\visual studio\image recognition\image_english")
num=0
for file in path.iterdir():
num+=1
print(num)
word=[]
c= "" ""
for a in range(num):
picture=str(a)+"."+"png"
img = Image.open(path/ picture )
img2 = image_processing(img)
text = pytesseract.image_to_string(img2,lang="eng+chi_tra",config='--psm 6')
word.append(text + "n""n""n")
f = open("file.txt",mode="w",encoding="utf-8")
f.writelines(word)
f.close()
[[enter image description here]
(https://i.sstatic.net/wAzPDPY8.png)]
(https://i.sstatic.net/cWpskYog.png)
I hope the program can scan text output like image
Do not scan into non-text parts become symbol
I tried config = “psm-1” , “psm-6”
New contributor
user24768854 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.