I'm capturing frames from video stream. In random moments, on constant place there is white text on the red gradient background. I want to get text from this frames (I use pytesseract) and save it to the database, so how can I detect that frames? When frames don't contains text, pytesseract returns senseless things and my code sends them to the database - this is unacceptable. Frames are cropped, so contains only white text on red background (only capital letters, one or two lines) or other random content. Sometimes can be possible situation when cropped is not good because the height of the red rectangle is reduced like this combination or unfortunately there is other text. In these cases pytesseract is weak.
import cv2
import pytesseract
import time
import mysql.connector
from difflib import SequenceMatcher
recent = ""
while True:
cap = cv2.VideoCapture(VIDEO_URL)
ret, frame = cap.read()
img = cv2.cvtColor(frame, cv2.IMREAD_COLOR)[815:970, 360:1920] #crop frame
text = pytesseract.image_to_string(img)
if SequenceMatcher(None, recent, text).ratio() < 0.5: #save only when text is new
sql = "INSERT INTO table(content, date) VALUES(%s ,%s)"
val = (text, time.localtime())
mycursor.execute(sql, val)
db.commit()
recent = text
How can I improve this solution and processing only croped frames with white text on red gradient background? Is something better then pytesseract for this solution?