Spaces:
Build error
Build error
import cv2 | |
import gradio as gr | |
import PIL.Image | |
import time | |
from ultralytics import YOLO | |
# Initialize model with lower confidence threshold (0.2) | |
model = YOLO("models/yolo11n.pt") | |
model.conf = 0.2 # Set confidence threshold to 0.2 | |
# Default RTMP URL | |
default_rtmp_url = "rtmp://flvcloudhkwa.ezvizlife.com:1935/v3/openlive/E56405322_1_1?expire=1803836768&id=819385674427736064&c=1cd321224b&t=c1eea0c9fe19262cbc4cb8d9523389e0eef1e51981a6ce8ddf8275e6ec4067b9&ev=100" | |
def stream_yolo(rtmp_url): | |
if not rtmp_url: | |
rtmp_url = default_rtmp_url | |
cap = cv2.VideoCapture(rtmp_url) | |
if not cap.isOpened(): | |
print("Video stream açılırken hata oluştu.") | |
yield PIL.Image.new('RGB', (640, 480), color='red') | |
return | |
while True: | |
ret, frame = cap.read() | |
if not ret: | |
print("Frame alınamadı, akış sona erdi.") | |
break | |
results = model(frame) | |
# Access the first result from the results list | |
# Then render it or just use plotted directly | |
annotated_frame = results[0].plot() | |
annotated_frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB) | |
image = PIL.Image.fromarray(annotated_frame) | |
yield image | |
time.sleep(0.03) | |
iface = gr.Interface( | |
fn=stream_yolo, | |
inputs=gr.Textbox( | |
label="RTMP URL", | |
placeholder="Enter your RTMP URL here...", | |
value=default_rtmp_url | |
), | |
outputs=gr.Image(type="pil", label="Canlı YOLO Tespiti"), | |
live=True, | |
title="RTMP Akışından Canlı YOLO Tespiti", | |
description="Kendi CCTV akışınızı izlemek için RTMP URL'sini girin. YOLOv11n, 0.2 güven eşiği ile çalışır." | |
) | |
if __name__ == "__main__": | |
iface.launch() |