Python Forum
Checking for a recognized text in a Dataframe - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Checking for a recognized text in a Dataframe (/thread-34785.html)



Checking for a recognized text in a Dataframe - KDE - Aug-31-2021

I have a Recognition code to identify text written of trucks, i just have to add a dataframe in the same code in order to identify if it contains the recognized text, but it does not work.

<
import cv2
import pytesseract
import pandas as pd

pytesseract.pytesseract.tesseract_cmd = "C:/Program Files/Tesseract-OCR/tesseract.exe"

img = cv2.imread('image/tt.jpg')
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
(h, w) = gry.shape[:2]
gry = gry[int(h/4) + 40:int(h/2)-20, int(w/2):int((w*3)/4)]
blr = cv2.GaussianBlur(gry, (3, 3), 0)
thr = cv2.threshold(gry, 128, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
txt = pytesseract.image_to_string(thr)
print(txt)
########################
# Create dataframe
df = pd.DataFrame(columns=['IDs'])
df["IDs"] = ["CMA CGM", "7040", "431916", "KLG555"]
print(df.loc[df['IDs'].str.contains('txt', case=False)])
##########################
cv2.imshow("thr", thr)
cv2.waitKey(0)
>
The output
Output:
< C:\Users\KHAW\AppData\Local\Programs\Python\Python39\python.exe C:/Users/KHAW/PycharmProjects/pythonProject.py CMA CGM Empty DataFrame Columns: [IDs] Index: [] >