bahakizil commited on
Commit
8811b18
·
verified ·
1 Parent(s): c59d3ed

Upload 6 files

Browse files
Files changed (6) hide show
  1. Dockerfile +11 -0
  2. __init__.py +1 -0
  3. app.py +5 -0
  4. main.py +53 -0
  5. requirements.txt +7 -0
  6. video_utils.py +17 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["python", "app.py"]
__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ # This file is intentionally left blank.
app.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # filepath: /Users/bahakizil/Desktop/rstm/yolo-rtmp-detection/app.py
2
+ from app.main import iface
3
+
4
+ if __name__ == "__main__":
5
+ iface.queue().launch()
main.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import gradio as gr
3
+ import PIL.Image
4
+ import time
5
+ from ultralytics import YOLO
6
+
7
+ # Initialize model with lower confidence threshold (0.2)
8
+ model = YOLO("models/yolo11n.pt")
9
+ model.conf = 0.2 # Set confidence threshold to 0.2
10
+
11
+ # Default RTMP URL
12
+ default_rtmp_url = "rtmp://flvcloudhkwa.ezvizlife.com:1935/v3/openlive/E56405322_1_1?expire=1803836768&id=819385674427736064&c=1cd321224b&t=c1eea0c9fe19262cbc4cb8d9523389e0eef1e51981a6ce8ddf8275e6ec4067b9&ev=100"
13
+
14
+ def stream_yolo(rtmp_url):
15
+ if not rtmp_url:
16
+ rtmp_url = default_rtmp_url
17
+
18
+ cap = cv2.VideoCapture(rtmp_url)
19
+ if not cap.isOpened():
20
+ print("Video stream açılırken hata oluştu.")
21
+ yield PIL.Image.new('RGB', (640, 480), color='red')
22
+ return
23
+
24
+ while True:
25
+ ret, frame = cap.read()
26
+ if not ret:
27
+ print("Frame alınamadı, akış sona erdi.")
28
+ break
29
+
30
+ results = model(frame)
31
+ # Access the first result from the results list
32
+ # Then render it or just use plotted directly
33
+ annotated_frame = results[0].plot()
34
+ annotated_frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
35
+ image = PIL.Image.fromarray(annotated_frame)
36
+ yield image
37
+ time.sleep(0.03)
38
+
39
+ iface = gr.Interface(
40
+ fn=stream_yolo,
41
+ inputs=gr.Textbox(
42
+ label="RTMP URL",
43
+ placeholder="Enter your RTMP URL here...",
44
+ value=default_rtmp_url
45
+ ),
46
+ outputs=gr.Image(type="pil", label="Canlı YOLO Tespiti"),
47
+ live=True,
48
+ title="RTMP Akışından Canlı YOLO Tespiti",
49
+ description="Kendi CCTV akışınızı izlemek için RTMP URL'sini girin. YOLOv11n, 0.2 güven eşiği ile çalışır."
50
+ )
51
+
52
+ if __name__ == "__main__":
53
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import gradio
2
+ import opencv-python
3
+ import ultralytics
4
+ import numpy
5
+ import pillow
6
+ import python-dotenv
7
+ import requests
video_utils.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def extract_frames_from_stream(rtmp_url):
2
+ cap = cv2.VideoCapture(rtmp_url)
3
+ if not cap.isOpened():
4
+ raise ValueError("Unable to open video stream.")
5
+
6
+ while True:
7
+ ret, frame = cap.read()
8
+ if not ret:
9
+ break
10
+ yield frame
11
+
12
+ cap.release()
13
+
14
+ def process_frame(frame, model):
15
+ results = model(frame)
16
+ annotated_frame = results.render()[0]
17
+ return annotated_frame