基于pytesseract-python的图像识别
我有一个图像,但它无法得到的价格,这是我所拥有的基于pytesseract-python的图像识别,python,image-processing,python-tesseract,Python,Image Processing,Python Tesseract,我有一个图像,但它无法得到的价格,这是我所拥有的 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
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
这就是我要分析的图像
-我需要的是相应名称的图像的价格
-我可以提取产品名称,但无法获取价格
-我怎样才能做到这一点?如有任何帮助,将不胜感激
请注意,我对图像处理非常陌生尝试了两个选项:
easyocr在这些图像上工作得更好
您需要探索您希望使用哪种选项。您也可以尝试@Nathance 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))
哇,这是个棘手的问题!我的第一个建议是不要将完整图像放入tesseract,而是将其划分为更小的子图像。例如,您可以尝试查找红色圆圈,剪切圆圈大小的子图像,并将其传递到tesseract以提取价格文本。通过这一点,您可以更轻松地调整字符大小等参数。问题是,我无法剪切图像。我正在从一个在线网站获取图像,该网站每周都在使用OpenCV(请参阅:)更新图像中的圆,然后您可能能够获取所有圆的坐标,然后将它们提供给具有白名单字符的tesseract(数字和货币符号)
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
'''
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))