-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/unicam-complex-system/camer…
…a-security-system-monorepo into new-stream-integration
- Loading branch information
Showing
5 changed files
with
62 additions
and
153 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import cv2 | ||
import socketio | ||
import base64 | ||
import threading | ||
|
||
#cameras data | ||
cameras = { | ||
'1': 'rtsp://192.168.1.41:80/ch0_0.264', | ||
'2': 'rtsp://192.168.1.41:80/ch1_0.264', | ||
'3': 'rtsp://192.168.1.41:80/ch2_0.264', | ||
'4': 'rtsp://192.168.1.41:80/ch3_0.264', | ||
'5': 'rtsp://192.168.1.41:80/ch4_0.264', | ||
'6': 'rtsp://192.168.1.41:80/ch5_0.264', | ||
'7': 'rtsp://192.168.1.41:80/ch6_0.264', | ||
'8': 'rtsp://192.168.1.41:80/ch7_0.264', | ||
} | ||
|
||
# Server settings | ||
server_url = 'http://localhost:8080' | ||
|
||
sio = socketio.Client() | ||
|
||
def convert_frame(frame): | ||
jpeg_frame = cv2.imencode('.jpg', frame)[1].tobytes() | ||
return jpeg_frame | ||
|
||
|
||
def send_frames(camera_id, capture, interval=0.1): | ||
while True: | ||
ret, frame = capture.read() | ||
if ret: | ||
|
||
frame_conv = convert_frame(frame) | ||
|
||
sio.emit('message', {'id': camera_id, 'data': frame_conv}) | ||
sio.sleep(interval) | ||
|
||
|
||
|
||
for camera_id, camera_url in cameras.items(): | ||
capture = cv2.VideoCapture(camera_url) | ||
if not capture.isOpened(): | ||
print(f"Errore nell'apertura della telecamera {camera_id}") | ||
continue | ||
|
||
threading.Thread(target=send_frames, args=(camera_id, capture)).start() | ||
|
||
|
||
@sio.event | ||
def connect(): | ||
print("Server connected") | ||
|
||
@sio.event | ||
def disconnect(): | ||
print("Server disconnected") | ||
|
||
sio.connect(server_url, transports=['websocket']) | ||
|
||
sio.wait() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.