Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python - Pytesseract does not detect me numbers

I am making a simple program to detect numbers in an image with python and pytesseract, but the case is that it always returns me ♀, I am analyzing an image like this:

my image

and my code to read the numbers is the following:

import pytesseract
from pytesseract import (
    Output,
    TesseractError,
    TesseractNotFoundError,
    TSVNotSupported,
    get_tesseract_version,
    image_to_boxes,
    image_to_data,
    image_to_osd,
    image_to_pdf_or_hocr,
    image_to_string,
    run_and_get_output
)

def analizar_resultado(path): 
    image = cv2.imread(path, 1)
    
    text = pytesseract.image_to_string(image, config = 'digits')
    print('texto detectado:', text)

but I can't make it work for me, I have tried more images of this type with better quality and others, but I can't get any number back, how could I solve this? Thanks a lot

question from:https://stackoverflow.com/questions/65877125/pytesseract-does-not-detect-me-numbers

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

1 Answer

0 votes
by (71.8m points)

I have a three-step solution


    1. Get each digit separately
    1. Apply threshold
    1. Read the output

Part-1: Get each digit separately

  • You can get each digit by using index variables. For instance:

    • s_idx = 0  # start index
      e_idx = int(w/5) - 10  # end index
      
  • First get height and width of the image then for each digit, increase the indexes

    • for _ in range(0, 6):
          gry_crp = gry[0:h, s_idx:e_idx]
          s_idx = e_idx
          e_idx = s_idx + int(w/5) - 20
      
  • Result

    • 0 0 9 9 7 6
      enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...