Read Price Text From Image using Python, spacy OpenCv and pytesseract (Part 2)
2 min readJun 5, 2024
To continue with the beginning please go through the part one.
In this part we will start with the Natural Language Processing work for getting the price text from the image. For the NLP related work we will use the spacy
import spacy
from spacy import displacy
# for the current work we can use the en_core_web_sm if you want you can download the en_core_web_md model
# for download the en_core_web_md model use the below command
# !python -m spacy download en_core_web_md
nlp = spacy.load('en_core_web_sm')
text = """P8040420
a NET QUANTITY:
MAP Re. 2 783.00 inc! fe.
PRODUCT beobESinks ©
ufactured: 11/2023
MII WARE Wer etn +
Lage -
TVS MOTOR COMPANY LTO TVS ~—
POST BOX NO. 4. HARITA, HOSUR - 635109.
TAMILNADU, INDIA. IN CASE OF CONSUMER
COMPLAINTS: CONTACT EXECUTIVE AI ABOVE
Q0DRESS OR CALL TOLL FREE NO 1800-258-7111 OR
WAIL: CUSTOMERCAREPARTS¢2 TVSMOTOR.COM
27/04/2024 12:26"""
doc2 = nlp(text)
for ent in doc2.ents:
print(ent.text, "-", ent.label_, "-", spacy.explain(ent.label_))
We will get the following output.
name = None
birth_date = None
price= None
for ent in doc2.ents:
if ent.label_ == "MONEY":
price = ent.text
print(f'price: {price}')
Now we will get this value as a final output: