Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
634 views
in Technique[技术] by (71.8m points)

python - Tesseract ocr output with single characters in between the detected text

I am trying to use Tesseract to extract from the below image,

enter image description here

text = pytesseract.image_to_string(image, config='-c preserve_interword_spaces=1 --psm 1 --oem 1')

Here is the result from tesseract 4 ocr,

print(text)

Wrote Datastream application 
e Used Kafka to get the accounts

If you see the bullet point in the image is converted to e, I found several such points in document converted into single characters in ascii

If anyone is familiar with such issue and have a solution please let me know.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have a suggestion, maybe its better to remove the bullet-points.

  • One solution for removing the bullet-point is applying adaptive-threshold

  • If we apply adaptive-threshold to the current image:

    • enter image description here
  • Now if we read it:

    • Wrote Datastream application |
      Used Kafka to get the accounts
      
      

Code:


import cv2
import pytesseract

img = cv2.imread("4XMue.png")
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thr = cv2.adaptiveThreshold(gry, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
                            cv2.THRESH_BINARY, 11, 131)
txt = pytesseract.image_to_string(thr)
print(txt)

Please let me tell you that my example code, may not work for every image. Since an image may have different artifacts or require additional processing. You may need to change the block-size and C parameters of the adaptive-threshold. Therefore, please start with reading the adaptive-threshold


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...