import base64 import re import sys from datetime import datetime, timedelta from time import sleep from typing import List import os import utils from detector import Detector # Add the proto directory to the Python path proto_dir = os.path.join(os.path.dirname(__file__), 'message_queue', 'proto') if proto_dir not in sys.path: sys.path.append(proto_dir) # Debug: Print the updated Python path # print("Updated Python Path:", sys.path) from PyQt5.QtCore import QCoreApplication, Qt import conection from conection import ConnectionThread import shared_manager from utils import manager_callback, handle_camera_status, findUsbCams from configs import ConfigManager from core import Core from tracker import Tracker from message_queue.Bridge import Bridge from message_queue.Manager import Manager from message_queue.proto.ImageMessage_pb2 import ImageMessage, TrackMode from message_queue.proto.Message_pb2 import Message from message_queue.proto.enums_pb2 import MessageType from video_streamer.gst_video_streamer import GstVideoStreamer config_manager = ConfigManager('config.yaml') rtsp_links = config_manager.configs['rtsp_links'].get() debug = config_manager.configs['debug'].get() if __name__ == '__main__': QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QCoreApplication(sys.argv) videoStreamers = [] for idx, rtsp_link in enumerate(rtsp_links): videoStreamer = GstVideoStreamer(rtsp_link, [1920, 1080, 3], str(idx), fps=15) videoStreamer.cameraStatus.connect(handle_camera_status) print(f'{videoStreamer.id} connected') videoStreamers.append(videoStreamer) tracker = Tracker() detector = Detector(classes=[0, 2, 5, 7]) sources = findUsbCams() if len(sources) >= 2: core = Core(sources,tracker,detector) else: core = Core(videoStreamers, tracker, detector) utils.core = core cl_ip, _ = conection.start_discovery_service(12345) print(cl_ip) shared_manager.manager = Manager(f"tcp://{cl_ip}:5558", f"tcp://{cl_ip}:5557") shared_manager.manager.start(manager_callback) def gotNewFrame(bboxes, id_, isDetection, ctime): #print(f"Got new frame, bboxes : {bboxes} Id: {id} Is detection {isDetection}") m = Message() m.msgType = MessageType.MESSAGE_TYPE_IMAGE m.image.timestamp = int(ctime.value) for bbox in bboxes: # Skip if bbox is None, doesn't have exactly 4 elements, or contains None values if bbox is None or len(bbox) != 4 or not all(element is not None for element in bbox): continue # Add the bounding box to the image box = m.image.boxes.add() box.x, box.y, box.w, box.h = bbox m.image.camType = id_ if isDetection: m.image.trackMode = TrackMode.TRACK_MODE_DETECT else: m.image.trackMode = TrackMode.TRACK_MODE_TRACK shared_manager.manager.send_message(m.SerializeToString()) def gotCoords(id_, coord, successful): m = Message() m.msgType = MessageType.MESSAGE_TYPE_TRACK_COORD m.track_coords.camType = id_ m.track_coords.center.x = coord[0] m.track_coords.center.y = coord[1] m.track_coords.isLost = not successful shared_manager.manager.send_message(m.SerializeToString()) core.newFrame.connect(gotNewFrame) core.coordsUpdated.connect(gotCoords) # Start the connection thread connection_thread = ConnectionThread(debug,core) connection_thread.start() try: app.exec_() except KeyboardInterrupt: connection_thread.stop() connection_thread.join() sys.exit(0)