Python Forum
Problema with convert image to string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problema with convert image to string
#1
Hi everyone,

I am working on decoding a text of an image, for this I take a complicated case, captcha with lines ... I imagine that if it works well it will do it in fuzzy texts or in scratched documents ...

The problem is that when I decode, the result is very different from what I'm trying to read, why is this?

    ##############################
    import pytesseract
    from PIL import Image
    
    import cv2
    import numpy as np
    
    img = Image.open('C:/XYZ/AAAA/captcha2_Ejemplo.bmp').convert('RGB') 
    
    ##############################
    cv_img = np.asarray(img)[:,:,::].copy()
    
    gray = cv2.cvtColor(cv_img, cv2.COLOR_BGR2GRAY)
    
    edges = cv2.Canny(gray, 60, 200, apertureSize = 3)
    
    lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 1, None, 0, 0)
    
    for x1, y1, x2, y2 in lines[0]:
        cv2.line(cv_img, (x1, y1), (x2, y2), (255,255,255 ), 2)
        
    processed = cv2.cvtColor(cv_img, cv2.COLOR_BGR2GRAY)

    blur = cv2.GaussianBlur(processed, (3, 3), 0)

    threshold = cv2.threshold(blur, 128, 255, cv2.THRESH_BINARY)[1]

    ##############################

    pil_img = Image.fromarray(threshold)
    
    pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
    result = pytesseract.image_to_string(threshold)
    print(result)  
    ##############################    
Image for example:
https://drive.google.com/open?id=1oU4Qom...Uh-YXaLE4l

The result is "Ky é-Tel 3"... the correct result is "32YSQE"...

I will greatly appreciate your help


(Main source: https://gist.github.com/chroman/8485394)

Thanks
Karlo
Reply
#2
Any help?...please
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Sad ValueError: could not convert string to float badju 0 4,326 Jul-01-2021, 12:13 AM
Last Post: badju
  Indirectlty convert string to float in JSON file WBPYTHON 6 5,944 May-06-2020, 12:09 PM
Last Post: WBPYTHON
  ValueError: could not convert string to float RahulSingh 3 4,192 Apr-09-2020, 02:59 PM
Last Post: dinesh
  convert a list of string+bytes into a list of strings (python 3) pacscaloupsu 4 10,847 Mar-17-2020, 07:21 AM
Last Post: markfilan
  Convert dataframe string column to numeric in Python darpInd 1 2,301 Mar-14-2020, 10:07 AM
Last Post: ndc85430
  ValueError: could not convert string to float: '4 AVENUE' Kudzo 4 5,931 Jan-26-2020, 10:47 PM
Last Post: Kudzo
  Convert 'object' to 'string' AdWill97 1 62,456 May-06-2019, 08:22 AM
Last Post: Yoriz
  Convert Image API piedrucci 1 2,072 Apr-03-2019, 10:57 PM
Last Post: Larz60+
  ValueError: could not convert the string to float Grin 3 10,236 Jun-14-2018, 08:17 PM
Last Post: killerrex
  Error for convert image PIL to CV2 karlo123 2 4,795 May-07-2018, 03:14 AM
Last Post: karlo123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020