Browse Source

made code more clean and added getting thickness from client

video-streaming
s_kiani 2 months ago
parent
commit
b79d689fc4
  1. 19
      core.py

19
core.py

@ -100,27 +100,23 @@ class Core(QThread):
if frame_1 is not None: if frame_1 is not None:
self.__rtspserver_1.update_frame(frame_1) self.__rtspserver_1.update_frame(frame_1)
sleep(0.03)
sleep(1/25)
except Exception as e: except Exception as e:
print(e) print(e)
sleep(0.1) sleep(0.1)
except Exception as e:
print(e)
sleep(0.1)
def __detection(self): def __detection(self):
while self.__is_detecting: while self.__is_detecting:
try: try:
torch.cuda.empty_cache()
torch.cuda.set_per_process_memory_fraction()
source = self.__processing_source source = self.__processing_source
roi = self.__detection_roi roi = self.__detection_roi
frame = source.get_frame() frame = source.get_frame()
cropped_frame = frame[roi[1]:roi[3], roi[0]:roi[2]] cropped_frame = frame[roi[1]:roi[3], roi[0]:roi[2]]
results = self.__detector.predict(cropped_frame)
with torch.no_grad():
results = self.__detector.predict(cropped_frame)
global_bboxes = list() global_bboxes = list()
for result in results: for result in results:
cls = result[0] cls = result[0]
@ -136,8 +132,11 @@ class Core(QThread):
print(e) print(e)
sleep(0.1) sleep(0.1)
def __tracking(self): def __tracking(self):
source = self.__processing_source source = self.__processing_source
track_color = (0, 255, 0) #green
lost_color = (255, 0, 0) #blue
if showTrack: if showTrack:
pygame.init() pygame.init()
@ -167,8 +166,8 @@ class Core(QThread):
if frame is not None: if frame is not None:
if self.__is_tracking and self.__tracker is not None and self.__tracker_roi is not None : if self.__is_tracking and self.__tracker is not None and self.__tracker_roi is not None :
x, y, w, h = map(int, self.__tracker_roi) x, y, w, h = map(int, self.__tracker_roi)
box_color = (0, 255, 255) if self.__tracker__succ else (255, 0, 0)
cv2.rectangle(frame, (x, y), (x + w, y + h), box_color, 2)
box_color = track_color if self.__tracker__succ else lost_color
cv2.rectangle(frame, (x, y), (x + w, y + h), box_color, self.__thickness)
if self.__processing_id == 1: if self.__processing_id == 1:
self.__rtspserver_1.update_frame(frame) self.__rtspserver_1.update_frame(frame)

Loading…
Cancel
Save