简体   繁体   English

如何从 Easyocr 结果创建自动打折价目表?

[英]How to create a automatic discounted price list from Easyocr result?

So we are tasked to create a code where the result of the Easyocr into a table (specifically food menus).因此,我们的任务是创建一个代码,将 Easyocr 的结果放入表格(特别是食物菜单)中。 The brick wall starts right after obtaining the result from easyocr since it I tried sorting the result but it sorts per character and number instead of words and price.砖墙在从 easyocr 获得结果后立即开始,因为我尝试对结果进行排序,但它按字符和数字而不是单词和价格排序。 I know that creating a list manually will solve it but it beats the purpose of automating the code of applying discount on a ocr.我知道手动创建一个列表可以解决这个问题,但它超过了自动化在 ocr 上应用折扣的代码的目的。

We read the text:我们读课文:

result2 = reader.readtext(IMAGE_PATH, detail=0, slope_ths= 0.2)

result2 contains the following:结果 2 包含以下内容:

['SIZZLING SPECIALS',
 'Spareribs',
 '195.00',
 'Pork Katsudon',
 '175.00',
 'Sizzling Sisig',
 '180.00',
 'Sisig Pulutan',
 '160.00',
 'Pork',
 'Barbeque',
 '160.00',
 'Pork Teriyaki',
 '160.00',
 'Peruvian Chicken',
 '160.,00',
 'Stuffed Squid',
 '345.00',
 'Boneless Bangus',
 '150.00',
 "Tokwa't Baboy",
 '150.00',
 'Sizzling Lomi',
 '110.00']

I wanted to have a result where in the food name and the price are in separate columns.我想得到一个结果,其中食物名称和价格在不同的列中。 As well as to apply discount to the price.以及对价格应用折扣。

Column 1第 1 列 Column 2第 2 栏
Spareribs排骨 195.00-20% 195.00-20%
Pork Katsudon猪排盖饭 175.00-20% 175.00-20%
... ... ... ...
... ... ... ...
... ... ... ...
Sizzling lomi铁板lomi 115.00-20% 115.00-20%

You would need to do some data cleaning, but try the following:您需要进行一些数据清理,但请尝试以下操作:

import pandas as pd

result2 = ['SIZZLING SPECIALS',
           'Spareribs',
           '195.00',
           'Pork Katsudon',
           '175.00',
           'Sizzling Sisig',
           '180.00',
           'Sisig Pulutan',
           '160.00',
           'Pork',
           'Barbeque',
           '160.00',
           'Pork Teriyaki',
           '160.00',
           'Peruvian Chicken',
           '160.,00',
           'Stuffed Squid',
           '345.00',
           'Boneless Bangus',
           '150.00',
           "Tokwa't Baboy",
           '150.00',
           'Sizzling Lomi',
           '110.00']

# Remove SIZZING SPECIALS and Pork
result2 = result2[1::]
del result2[result2.index("Pork")]

result_final = pd.DataFrame([
    {"Column 1": result2[2*i],
     "Column 2": result2[2*i+1]} for i in range(len(result2) // 2)])

result_final
Column 1第 1 列 Column 2第 2 栏
Spareribs排骨 195.00 195.00
Pork Katsudon猪排盖饭 175.00 175.00
Sizzling Sisig铁板西格 180.00 180.00
Sisig Pulutan西格普卢坦 160.00 160.00
Barbeque烧烤 160.00 160.00
Pork Teriyaki照烧猪肉 160.00 160.00
Peruvian Chicken秘鲁鸡 160.,00 160.,00
Stuffed Squid酿鱿鱼 345.00 345.00
Boneless Bangus去骨班格斯 150.00 150.00
Tokwa't Baboy Tokwa't Baboy 150.00 150.00
Sizzling Lomi铁板罗米 110.00 110.00

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM