簡體   English   中英

使用 pytesseract python 進行圖像識別

[英]image recognition using pytesseract python

我有一張圖片,但它無法得到價格這就是我所擁有的

import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract'
print(pytesseract.image_to_string("local-filename.jpg"))

output


Nestle Bakers’
Choice Melts
290g/

Choc Bits
200g


Altimate
Salted Caramel
Waffle Cones
12's


~ Seitarium ss, :
et-E Ly y ”.
oss a
=| x
) " 4
oat

.

FruitCo Juice 2 Litres
‘Apple/ Apricot/ Apple, Mange,
‘Banana/ Apple Pea

Cottee’s Jams

Betty Crocker Triple
500g

Sanitarium Weet-bix
750g Chocolate Muffin Mix 500g

 

Ss
>

s

Authentic Thai

; Sweet Chili Sauce
Vanilla em, ‘ 725ml

Dell

cours ® ‘OCOMUT HE


Sandhurst Coconut Milk

Chelsea Berry/ Vanilla
400m!

Icing Sugar 3759

  


Process finished with exit code 0

這就是我要分析的圖像

在此處輸入圖像描述

- 我需要的是具有相應名稱的圖像的價格 - 我能夠提取產品名稱但無法獲得價格 - 我該如何實現這一點 任何幫助將不勝感激 請注意我對圖像非常陌生加工

嘗試了兩種選擇:

  1. easyocr 通過 !pip install easyocr 安裝
  2. tesseract 通過(在 Mac 上)安裝 brew install tesseract

結果如下:

  1. 全圖,easyocr 和 tesseract 都沒有給出價格。
  2. 只拿了價格圈
    在此處輸入圖像描述
image = cv2.imread('795.png')
print(pytesseract.image_to_string(sk1)) # printed spaces i.e no result

import easyocr
reader = easyocr.Reader(['en'],gpu = False) #  load model into memory once
result = reader.readtext(image,detail=0) # resul ['s7.95', 'cach']

easyocr 工作得更好!!

帶有產品描述的圖像上的下一個
在此處輸入圖像描述

image = cv2.imread('795 Product.png')
reader.readtext(image,detail=0)
'''
['Nestle',
 'eaa',
 'Nestle',
 'RuS',
 'aa',
 'melts',
 'PARKCHOC',
 'chocbts',
 'Nestle Bakers',
 'S',
 'Choice Melts',
 '290g/',
 'cach',
 'Choc Bits',
 '200g',
 'Nestle',
 '"8628',
 'nelts',
 '(Neste)',
 'JTE CHOC',
 '7.95']
'''
print(pytesseract.image_to_string(image))
'''
Nestle Bakers’
Choice Melts
290g/

Choc Bits
200g
'''

easyocr 在這些圖像上效果更好。

您需要探索要轉發的選項。 你也可以試試@nathancy 提供的推薦How to process and extract text from image by

Google Vision API 給出了最好的結果。 谷歌雲為每位用戶提供 300 美元的免費積分。

下面是相同的代碼片段。

def detect_text(path):
    """Detects text in the file."""
    from google.cloud import vision
    import io
    client = vision.ImageAnnotatorClient()

    with io.open(path, 'rb') as image_file:
        content = image_file.read()

    image = vision.Image(content=content)

    response = client.text_detection(image=image)
    texts = response.text_annotations
    print('Texts:')

    for text in texts:
        print('\n"{}"'.format(text.description))

        vertices = (['({},{})'.format(vertex.x, vertex.y)
                    for vertex in text.bounding_poly.vertices])

        print('bounds: {}'.format(','.join(vertices)))

    if response.error.message:
        raise Exception(
            '{}\nFor more info on error messages, check: '
            'https://cloud.google.com/apis/design/errors'.format(
                response.error.message))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM