Beispiel #1
0
def extract_text(img_path, model_path):
    ocr = pyclstm.ClstmOcr()
    ocr.load(model_path)
    imgFile = Image.open(img_path)
    text = ocr.recognize(imgFile)
    text.encode('utf-8')
    chars = ocr.recognize_chars(imgFile)
    prob = 1
    index = 0
    x = 0
    #print text
    if (text.find(u':') != -1 and text.index(u':') < 5):
        index = text.index(u':') + 1
    if (text.find(u' ') != -1 and (text.index(u' ') <= 3)):
        if (len(text) > text.index(u' ') + 1):
            index = text.index(u' ') + 1
    for ind, j in enumerate(chars):
        #print j
        if ind >= index:
            prob *= j.confidence
        if j.char == u':':
            if j.x_position > x:
                x = j.x_position

    #return text[index:], prob, index
    return text, prob, index, x
Beispiel #2
0
def extract_text(img_path, model_path):
    ocr = pyclstm.ClstmOcr()
    ocr.load(model_path)
    imgFile = Image.open(img_path)
    text = ocr.recognize(imgFile)
    text.encode('utf-8')
    chars = ocr.recognize_chars(imgFile)
    prob = 1
    index = 0
    # print text
    if text.find(u':') != -1 and text.index(u':') < 3:
        index = text.index(u':') + 1
    if text.find(u' ') != -1 and (text.index(u' ') <= 3):
        if (len(text) > text.index(u' ') + 1):
            index = text.index(u' ') + 1
    for ind, j in enumerate(chars):
        if ind >= index:
            prob *= j.confidence
    return text, prob
Beispiel #3
0
def extract_text(img_path, model_path):
    ocr = pyclstm.ClstmOcr()
    ocr.load(model_path)
    imgFile = Image.open(img_path)
    text = ocr.recognize(imgFile)
    #print text
    text.encode('utf-8')

    chars = ocr.recognize_chars(imgFile)
    prob = 1
    index = 0
    #print text
    # if(text.find(u':') != -1 and text.index(u':') < 5):
    # 	index = text.index(u':')+1
    # if(text.find(u' ') != -1 and (text.index(u' ') <= 3)):
    # 	if(len(text)>text.index(u' ')+1):
    # 		index = text.index(u' ')+1
    for ind, j in enumerate(chars):
        #print j
        #print j
        if ind >= 0:
            prob *= j.confidence
    #print index
    return text[0:], prob, 0