@@ -87,25 +87,38 @@ def run_detection(self, cameras: list, single_frame_mode: bool = False, single_f
8787 yield False
8888
8989class ClothesDetection :
90- def __init__ (self , num_cameras : int ):
91- self .models = [Load_DeepFashion2_Yolov3 () for _ in range (num_cameras )]
92- self .cap_list = [cv2 .VideoCapture (i ) for i in range (num_cameras )]
90+ def __init__ (self , num_cameras : int , isframe = False , frame = None ):
91+ self .isframe = isframe
92+ if not self .isframe :
93+ self .models = [Load_DeepFashion2_Yolov3 () for _ in range (num_cameras )]
94+ self .cap_list = [cv2 .VideoCapture (i ) for i in range (num_cameras )]
95+ else :
96+ self .models = [Load_DeepFashion2_Yolov3 ()]
97+ self .frame = frame
9398 self .start_time = time .time ()
9499
95100 def run_detection (self , cameras : list ):
96101 gunman_is_wearing = ""
97102 avg_rgb_values = []
98103 while len (gunman_is_wearing )== 0 :
99- frames = [cap .read ()[1 ] for cap in self .cap_list ]
100- ret_list = [frame is not None for frame in frames ]
101- if not all (ret_list ):
102- break
103-
104- img_tensors = [tf .convert_to_tensor (frame [tf .newaxis , ...], dtype = tf .float32 ) / 255.0 for frame in frames ]
105- img_with_boxes_list = []
106- box_array_list = []
104+ if not self .isframe :
105+ frames = [cap .read ()[1 ] for cap in self .cap_list ]
106+ ret_list = [frame is not None for frame in frames ]
107+ if not all (ret_list ):
108+ break
107109
108- text = ""
110+ if not self .isframe :
111+ img_tensors = [tf .convert_to_tensor (frame [tf .newaxis , ...], dtype = tf .float32 ) / 255.0 for frame in frames ]
112+ img_with_boxes_list = []
113+ box_array_list = []
114+
115+ text = ""
116+ else :
117+ img_tensors = [tf .convert_to_tensor (self .frame [tf .newaxis , ...], dtype = tf .float32 ) / 255.0 ]
118+ img_with_boxes_list = []
119+ box_array_list = []
120+
121+ text = ""
109122
110123 for i , (img_tensor , model ) in enumerate (zip (img_tensors , self .models )):
111124 img_with_boxes , box_array , text = Draw_Bounding_Box (frames [i ], Detect_Clothes (img_tensor , model ))
@@ -120,24 +133,26 @@ def run_detection(self, cameras: list):
120133 # number=2142184754, provider="T-Mobile")
121134 avg_rgb_values = self .get_avg_rgb (box_array , frames [i ])
122135 print (avg_rgb_values )
136+
123137 #color_category = self.get_color_category(avg_rgb_values)
124138 #print(f"Color category for cam {i + 1}: {color_category}")
125139
126140 elapsed_time = time .time () - self .start_time
127141 fps = len (cameras ) / elapsed_time
128142
129143 for i , img_with_boxes in enumerate (img_with_boxes_list ):
130- cv2 .putText (img_with_boxes , f"FPS: { fps :.2f} " , (10 , 30 ), cv2 .FONT_HERSHEY_SIMPLEX , 1 , (0 , 255 , 0 ), 2 )
131- cv2 .putText (img_with_boxes , f"Gunman is wearing { gunman_is_wearing } " , (10 , 100 ), cv2 .FONT_HERSHEY_SIMPLEX , 1 , (0 , 255 , 0 ), 2 )
132- cv2 .putText (img_with_boxes , f"Color rgb { avg_rgb_values } " , (10 , 200 ), cv2 .FONT_HERSHEY_SIMPLEX , 1 , (0 , 255 , 0 ), 2 )
133- cv2 .imshow (f"Clothes detection cam { i + 1 } " , img_with_boxes )
144+ if not self .isframe :
145+ cv2 .putText (img_with_boxes , f"FPS: { fps :.2f} " , (10 , 30 ), cv2 .FONT_HERSHEY_SIMPLEX , 1 , (0 , 255 , 0 ), 2 )
146+ cv2 .putText (img_with_boxes , f"Gunman is wearing { gunman_is_wearing } " , (10 , 100 ), cv2 .FONT_HERSHEY_SIMPLEX , 1 , (0 , 255 , 0 ), 2 )
147+ cv2 .putText (img_with_boxes , f"Color rgb { avg_rgb_values } " , (10 , 200 ), cv2 .FONT_HERSHEY_SIMPLEX , 1 , (0 , 255 , 0 ), 2 )
148+ cv2 .imshow (f"Clothes detection cam { i + 1 } " , img_with_boxes )
134149
135150 if cv2 .waitKey (1 ) & 0xFF == ord ('q' ):
136151 break
137-
138- for cap in self .cap_list :
139- cap .release ()
140- cv2 .destroyAllWindows ()
152+ if not self . isframe :
153+ for cap in self .cap_list :
154+ cap .release ()
155+ cv2 .destroyAllWindows ()
141156 return (gunman_is_wearing ,avg_rgb_values )
142157 def get_avg_rgb (self , box_array : list , frame : np .ndarray ) -> list :
143158 avg_rgb_values = []
0 commit comments