Skip to content

Commit

Permalink
Merge branch 'new-stream-integration' of https://github.com/unicam-co…
Browse files Browse the repository at this point in the history
  • Loading branch information
Glydric committed Jan 19, 2024
2 parents 77ad768 + a48ef3a commit b7de9c3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 153 deletions.
30 changes: 0 additions & 30 deletions ImageRecognition/main.py

This file was deleted.

60 changes: 60 additions & 0 deletions ImageRecognition/send_frame.py
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()

4 changes: 2 additions & 2 deletions ImageRecognition/src/ObjectDetectionYOLO.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import math
import threading
import requests
import numpy as np
from skimage.metrics import structural_similarity as ssim
from sklearn.metrics import mean_squared_error

#model
Expand Down Expand Up @@ -32,6 +30,8 @@
cam8 = 'rtsp://192.168.1.41:80/ch7_0.264'


TOKEN = '6929905186:AAEouI3G2sbfS-y6ZzkXrpNgPQRAPs5_v-g'
channel_id = '792557360'
last_sent_image = None

def post_request(image):
Expand Down
74 changes: 0 additions & 74 deletions ImageRecognition/src/convertStream.py

This file was deleted.

47 changes: 0 additions & 47 deletions ImageRecognition/src/handleSystemStream.py

This file was deleted.

0 comments on commit b7de9c3

Please sign in to comment.