import cv2
import numpy as np
from PIL import Image
import pytesseract
def detect_demo_watermark(frame):
# Common demo mode indicators
demo_templates = {
'demo_text': cv2.imread('demo_template.png'),
'practice_text': cv2.imread('practice_template.png'),
'fun_play': cv2.imread('fun_play_template.png')
}
# Convert frame to grayscale for better matching
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Areas where demo watermarks typically appear
roi_zones = [
(0, 0, frame.shape[1]//3, frame.shape[0]//4), # Top left
(frame.shape[1]*2//3, 0, frame.shape[1], frame.shape[0]//4), # Top right
(0, frame.shape[0]*3//4, frame.shape[1], frame.shape[0]) # Bottom
]
# Check each ROI for demo indicators
for x1, y1, x2, y2 in roi_zones:
roi = gray[y1:y2, x1:x2]
# Template matching
for template in demo_templates.values():
result = cv2.matchTemplate(roi, template, cv2.TM_CCOEFF_NORMED)
if np.max(result) > 0.8: # Threshold for match confidence
return True
# OCR check for demo text
text = pytesseract.image_to_string(roi)
if any(keyword in text.lower() for keyword in ['demo', 'practice', 'fun play']):
return True
return False
def analyze_stream(video_path):
cap = cv2.VideoCapture(video_path)
frame_count = 0
demo_frames = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
if frame_count % 30 == 0: # Check every 30 frames
if detect_demo_watermark(frame):
demo_frames += 1
frame_count += 1
cap.release()
return demo_frames / frame_count # Return percentage of frames with demo indicators