【问题标题】:image recognition using pytesseract python使用 pytesseract python 进行图像识别
【发布时间】:2021-03-29 07:57:42
【问题描述】:

我有一张图片,但它无法得到价格这是我所拥有的

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

输出


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

这是我要分析的图像

-我需要的是对应名字的图片的价格 -我能够提取产品名称但无法获取价格 - 我怎样才能做到这一点任何帮助将不胜感激 请注意,我是图像处理的新手

【问题讨论】:

  • 哇,这是一个棘手的问题!我的第一个建议是不要将完整图像放入 tesseract,而是将其分成更小的子图像。例如,您可以尝试找到红色圆圈,剪切圆圈大小的子图像并将其传递给 tesseract 以提取价格文本。这样,您可以更轻松地调整字符大小等参数。
  • 问题是我无法剪切图像我从一个每周都会更新的在线网站获取图像
  • 尝试使用 OpenCV 在图像中查找圆圈(参考:geeksforgeeks.org/circle-detection-using-opencv-python),然后您可能能够获取所有圆圈的坐标,然后将它们与白名单字符(数字和货币符号)一起提供给 tesseract

标签: python image-processing python-tesseract


【解决方案1】:

尝试了两种选择:

  1. easyocr 通过 !pip install easyocr 安装
  2. 通过(在 Mac 上)brew install tesseract 安装 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

提供的推荐

【讨论】:

    【解决方案2】:

    Google Vision API 可提供最佳结果。谷歌云为每位用户提供 300 美元的免费积分。

    下面是相同的代码sn-p。

    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))
    

    【讨论】:

      猜你喜欢
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      • 2011-12-30
      • 2016-10-11
      • 2017-09-10
      • 2019-12-04
      • 1970-01-01
      相关资源
      最近更新 更多