I am a newbie with python, but I am trying to make a receipt scanner project. I have watched several tutorials and combined the techniques from them and managed to make the preprocessing part to work quite good (for what I need). Now, I want to extract text from the final processed image using tesseract, but I only want to extract some specific data. This is my code for text extraction:
pricePattern = r'([0-9]+\.[0-9]+)'
datePattern = r'\d{2}-\d{2}-\d{4}'
#idPattern = r'(iD)+(BF), iD BF'
#totalPattern = r'[A-Z]{4}, [A-Z]{3}, .[0-9]'
for row in img2char.split("\n"):
if re.search(pricePattern, row) is not None:
print(row)
if re.search(datePattern, row) is not None:
print(row)
#if re.search(idPattern, row) is not None:
#print(row)
#if re.search(totalPattern, row) is not None:
#print(row)
This is a part of the output from the bill using tesseract:
TOTAL LEI 90.00 | CARD 50.00 REST 0.00 TOTAL TUA A - 19% 1.92 TOTAL TAC - 5% al TOTAL TUA BON 3.73 2:0764 BF +0049 AR. ANEF 0001, iD BF: 3000856168202 1 129015100807640049 DATA: 30-12-2021 ORA: 15:10:08
My code above extracts the date correctly, but besides the date I only want to extract the lines with "TOTAL LEI" (and the the value that follows) and "iD BF" (with the value as well).
Does anyone have any tips how modify my code to extract those 2 lines?
@will First of all, thank you very much for taking time to answer. My application scans bills. From those scanned bills, I need to output with tesseract specific data (see bill.jpg)enter image description here
I need to output only the data in the red rectangles. After the preprocessing of the image, using tesseract, I get pretty decent text information from the image, but I don't really know how to use regex to only filter that data from the red rectangles (both the text and the value). This is an output example from a bill:
B ART CASTRONONIE SRL
STR. MICHAEL WEISS HR.2?
EXTINOERE STR.REPUBLICI) HR.1?
PARTER, AP.6, ET-PARTER. AP. 1
BRASOV, JUD. BRASOU
CIF: ROIBRO4E81
VIN FIERT 1 BUC X 12.005 12,00 A
CIORBA DE FASOLE CU CIOLAH
1 BLC X 17.00= 17.00 C
STRUDEL CU HERE 1 BUC xX 21.00= 21.00 C
TOTAL LEI 90.00 <--- output
| CARD 50.00
REST 0.00
TOTAL TUA A - 19% 1.92
TOTAL TAC - 5% al
TOTAL TUA BON 3.73
2:0764 BF +0049 AR. ANEF 0001,
iD BF: 3000856168202 1 129015100807640049 <--- output
DATA: 30-12-2021 ORA: 15:10:08 <--- output
S/N:0B4700019053 Tb:00083731
CASIER 30: CASLER 30
7 GON FISCAL
AZ 3000556168
ā UA MULTUNIN
I hope this is clear enough. Thanks a lot again!