|  |  | @ -18,8 +18,7 @@ import time | 
			
		
	
		
			
				
					|  |  |  | from PyQt5.QtCore import QObject, pyqtSignal | 
			
		
	
		
			
				
					|  |  |  | import ctypes | 
			
		
	
		
			
				
					|  |  |  | from ctypes import c_int64 | 
			
		
	
		
			
				
					|  |  |  | from server import rtsp_server, run_server, RTSPServer | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | from server import run_server, RTSPServer, get_local_ip | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | showTrack = False | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -32,9 +31,14 @@ class Core(QThread): | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         self.__detector = detector | 
			
		
	
		
			
				
					|  |  |  |         self.__tracker = tracker | 
			
		
	
		
			
				
					|  |  |  |         self.__tracker_rio = None | 
			
		
	
		
			
				
					|  |  |  |         self.__tracker__secc = False | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         self.__rtspserver_0 = RTSPServer(get_local_ip(), 41231,"/stream0") | 
			
		
	
		
			
				
					|  |  |  |         threading.Thread(target=run_server,args=[self.__rtspserver_0], daemon=True).start() | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         self.__rtspserver = rtsp_server | 
			
		
	
		
			
				
					|  |  |  |         threading.Thread(target=run_server, daemon=True).start() | 
			
		
	
		
			
				
					|  |  |  |         self.__rtspserver_1 = RTSPServer(get_local_ip(), 41232,"/stream1") | 
			
		
	
		
			
				
					|  |  |  |         threading.Thread(target=run_server,args=[self.__rtspserver_1], daemon=True).start() | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         self.__video_sources = video_sources | 
			
		
	
		
			
				
					|  |  |  |         self.__processing_source = video_sources[0] | 
			
		
	
	
		
			
				
					|  |  | @ -53,6 +57,11 @@ class Core(QThread): | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         self.__frame = None  # Frame property for Pygame | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         # Start the continuous streaming thread | 
			
		
	
		
			
				
					|  |  |  |         self.__is_streaming = True | 
			
		
	
		
			
				
					|  |  |  |         self.__streaming_thread = Thread(target=self.__stream) | 
			
		
	
		
			
				
					|  |  |  |         self.__streaming_thread.start() | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @pyqtProperty(np.ndarray) | 
			
		
	
		
			
				
					|  |  |  |     def frame(self): | 
			
		
	
		
			
				
					|  |  |  |         return self.__frame | 
			
		
	
	
		
			
				
					|  |  | @ -69,6 +78,40 @@ class Core(QThread): | 
			
		
	
		
			
				
					|  |  |  |             self.__video_sources = video_sources | 
			
		
	
		
			
				
					|  |  |  |             self.set_source(0) | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     def __stream(self): | 
			
		
	
		
			
				
					|  |  |  |         """Continuous streaming of the video source.""" | 
			
		
	
		
			
				
					|  |  |  |         while self.__is_streaming: | 
			
		
	
		
			
				
					|  |  |  |             try: | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 frame_0 = self.__video_sources[0].get_frame() | 
			
		
	
		
			
				
					|  |  |  |                 frame_1 = self.__video_sources[1].get_frame() | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 if frame_1 is not None: | 
			
		
	
		
			
				
					|  |  |  |                     if self.__is_tracking and self.__tracker is not None and self.__processing_id == 1: | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                         if self.__tracker_rio is not None: | 
			
		
	
		
			
				
					|  |  |  |                             x, y, w, h = map(int, self.__tracker_roi) | 
			
		
	
		
			
				
					|  |  |  |                             box_color = (0, 255, 0) if self.__tracker__secc else (255, 0, 0) | 
			
		
	
		
			
				
					|  |  |  |                             cv2.rectangle(frame_1, (x, y), (x + w, y + h), box_color, 2) | 
			
		
	
		
			
				
					|  |  |  |                     self.__rtspserver_1.update_frame(frame_1) | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 if frame_0 is not None: | 
			
		
	
		
			
				
					|  |  |  |                     if self.__is_tracking and self.__tracker is not None and self.__processing_id == 0: | 
			
		
	
		
			
				
					|  |  |  |                         if self.__tracker_rio is not None: | 
			
		
	
		
			
				
					|  |  |  |                             x, y, w, h = map(int, self.__tracker_roi) | 
			
		
	
		
			
				
					|  |  |  |                             box_color = (0, 255, 0) if self.__tracker__secc else (255, 0, 0) | 
			
		
	
		
			
				
					|  |  |  |                             cv2.rectangle(frame_0, (x, y), (x + w, y + h), box_color, 2) | 
			
		
	
		
			
				
					|  |  |  |                     self.__rtspserver_0.update_frame(frame_0) | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 sleep(0.03) | 
			
		
	
		
			
				
					|  |  |  |                 # self.__tracker_roi = None | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             except Exception as e: | 
			
		
	
		
			
				
					|  |  |  |                 print(e) | 
			
		
	
		
			
				
					|  |  |  |                 sleep(0.1) | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     def __detection(self): | 
			
		
	
		
			
				
					|  |  |  |         while self.__is_detecting: | 
			
		
	
		
			
				
					|  |  |  |             try: | 
			
		
	
	
		
			
				
					|  |  | @ -93,8 +136,6 @@ class Core(QThread): | 
			
		
	
		
			
				
					|  |  |  |                 print(e) | 
			
		
	
		
			
				
					|  |  |  |                 sleep(0.1) | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     def __tracking(self): | 
			
		
	
		
			
				
					|  |  |  |         source = self.__processing_source | 
			
		
	
		
			
				
					|  |  |  |         if showTrack: | 
			
		
	
	
		
			
				
					|  |  | @ -118,8 +159,10 @@ class Core(QThread): | 
			
		
	
		
			
				
					|  |  |  |             ctime = c_int64(int(time.time() * 1000))  # Convert to c_int64 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             frame = source.get_frame() | 
			
		
	
		
			
				
					|  |  |  |             print(f"intial frame size :{frame.shape}") | 
			
		
	
		
			
				
					|  |  |  |             bbox, success = self.__tracker.update(frame) | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             self.__tracker_roi = bbox | 
			
		
	
		
			
				
					|  |  |  |             self.__tracker__secc = success | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             if bbox is not None: | 
			
		
	
		
			
				
					|  |  |  |                 center = bbox[:2] + bbox[2:] // 2 | 
			
		
	
	
		
			
				
					|  |  | @ -130,7 +173,6 @@ class Core(QThread): | 
			
		
	
		
			
				
					|  |  |  |                 box_color = (0, 255, 0) if success else (255, 0, 0) | 
			
		
	
		
			
				
					|  |  |  |                 cv2.rectangle(frame, (x, y), (x + w, y + h), box_color, 2) | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 self.__rtspserver.update_frame(frame) | 
			
		
	
		
			
				
					|  |  |  |                 if showTrack: | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                     # Convert OpenCV frame (BGR) to RGB | 
			
		
	
	
		
			
				
					|  |  | @ -151,10 +193,6 @@ class Core(QThread): | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                     frame = cv2.flip(frame, 1)  # Flip horizontally | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                     # Resize frame while maintaining aspect ratio | 
			
		
	
		
			
				
					|  |  |  |                     frame_height, frame_width, _ = frame.shape | 
			
		
	
		
			
				
					|  |  |  |                     aspect_ratio = frame_width / frame_height | 
			
		
	
	
		
			
				
					|  |  | 
 |