Python Forum
Checking for a recognized text in a Dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking for a recognized text in a Dataframe
#1
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: [] >
Yoriz write Aug-31-2021, 05:35 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Checking if an element belongs in a dataframe row palladium 0 1,480 Jul-12-2020, 02:06 PM
Last Post: palladium
  loading a csv file into python from pandas. Variable is not recognized vijjumodi 2 2,877 Apr-19-2019, 04:09 AM
Last Post: kus
  Python QtableWidget get text of all cells and headers to dataframe Mady 3 23,032 Dec-15-2018, 06:46 PM
Last Post: Axel_Erfurt
  sklearn imported but not recognized kerberg 6 16,364 Jun-18-2017, 12:32 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020