Spaces:
Paused
Paused
| import cv2 | |
| import gradio as gr | |
| # Your RTSP stream URL | |
| RTSP_URL = "rtsp://Nani@471:Nani@471@192.168.1.13:554/stream1" | |
| # Load OpenCV's built-in face detection model | |
| face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") | |
| def get_rtsp_frame(): | |
| cap = cv2.VideoCapture(RTSP_URL) | |
| if not cap.isOpened(): | |
| return None | |
| ret, frame = cap.read() | |
| cap.release() | |
| if not ret: | |
| return None | |
| # Convert to grayscale for face detection | |
| gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
| faces = face_cascade.detectMultiScale(gray, 1.3, 5) | |
| # Draw rectangles around faces | |
| for (x, y, w, h) in faces: | |
| cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2) | |
| return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
| # Gradio app | |
| gr.Interface( | |
| fn=get_rtsp_frame, | |
| inputs=[], | |
| outputs=gr.Image(type="numpy", label="Live RTSP Feed with Face Detection"), | |
| live=True, | |
| title="RTSP CCTV Face Detection" | |
| ).launch() | |