|
44 | 44 | class ObjectDetectorLite(): |
45 | 45 | def __init__(self, model_path='detect.tflite', threads_num=4): |
46 | 46 | try: |
47 | | - self.interpreter = Interpreter(model_path=model_path, num_threads=num_threads) |
| 47 | + self.interpreter = Interpreter(model_path=model_path, num_threads=threads_num) |
48 | 48 | except: |
49 | | - self.interpreter = tf.lite.Interpreter(model_path=model_path, num_threads=num_threads) |
| 49 | + self.interpreter = tf.lite.Interpreter(model_path=model_path, num_threads=threads_num) |
50 | 50 | try: |
51 | 51 | self.interpreter.allocate_tensors() |
52 | 52 | except: |
53 | 53 | pass |
54 | 54 | self.input_details = self.interpreter.get_input_details() |
55 | 55 | self.output_details = self.interpreter.get_output_details() |
56 | 56 |
|
57 | | - def _boxes_coordinates(self, |
58 | | - image, |
59 | | - boxes, |
60 | | - classes, |
61 | | - scores, |
62 | | - max_boxes_to_draw=20, |
63 | | - min_score_thresh=.5): |
| 57 | + def _boxes_coordinates( |
| 58 | + self, |
| 59 | + image, |
| 60 | + boxes, |
| 61 | + classes, |
| 62 | + scores, |
| 63 | + max_boxes_to_draw=20, |
| 64 | + min_score_thresh=.5 |
| 65 | + ): |
64 | 66 |
|
65 | 67 | if not max_boxes_to_draw: |
66 | 68 | max_boxes_to_draw = boxes.shape[0] |
@@ -96,11 +98,13 @@ def detect(self, image, threshold=0.1): |
96 | 98 | num = self.interpreter.get_tensor(self.output_details[3]['index']) |
97 | 99 |
|
98 | 100 | # Find detected boxes coordinates |
99 | | - return self._boxes_coordinates(image, |
100 | | - np.squeeze(boxes[0]), |
101 | | - np.squeeze(classes[0]+1).astype(np.int32), |
102 | | - np.squeeze(scores[0]), |
103 | | - min_score_thresh=threshold) |
| 101 | + return self._boxes_coordinates( |
| 102 | + image, |
| 103 | + np.squeeze(boxes[0]), |
| 104 | + np.squeeze(classes[0]+1).astype(np.int32), |
| 105 | + np.squeeze(scores[0]), |
| 106 | + min_score_thresh=threshold, |
| 107 | + ) |
104 | 108 |
|
105 | 109 |
|
106 | 110 | def camThread(results, frameBuffer, camera_width, camera_height, vidfps, usbcamno): |
@@ -197,7 +201,7 @@ def overlay_on_image(frames, object_infos, camera_width, camera_height): |
197 | 201 | cv2.rectangle(img_cp, (box_left, box_top), (box_right, box_bottom), box_color, box_thickness) |
198 | 202 |
|
199 | 203 | percentage = int(obj[2] * 100) |
200 | | - label_text = obj[3] + " (" + str(percentage) + "%)" |
| 204 | + label_text = obj[3] + " (" + str(percentage) + "%)" |
201 | 205 |
|
202 | 206 | label_size = cv2.getTextSize(label_text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1)[0] |
203 | 207 | label_left = box_left |
@@ -238,17 +242,21 @@ def overlay_on_image(frames, object_infos, camera_width, camera_height): |
238 | 242 | results = mp.Queue() |
239 | 243 |
|
240 | 244 | # Start streaming |
241 | | - p = mp.Process(target=camThread, |
242 | | - args=(results, frameBuffer, camera_width, camera_height, vidfps, usbcamno), |
243 | | - daemon=True) |
| 245 | + p = mp.Process( |
| 246 | + target=camThread, |
| 247 | + args=(results, frameBuffer, camera_width, camera_height, vidfps, usbcamno), |
| 248 | + daemon=True, |
| 249 | + ) |
244 | 250 | p.start() |
245 | 251 | processes.append(p) |
246 | 252 |
|
247 | 253 | # Activation of inferencer |
248 | 254 | for process_num in range(core_num): |
249 | | - p = mp.Process(target=inferencer, |
250 | | - args=(results, frameBuffer, model, camera_width, camera_height, process_num, threads_num), |
251 | | - daemon=True) |
| 255 | + p = mp.Process( |
| 256 | + target=inferencer, |
| 257 | + args=(results, frameBuffer, model, camera_width, camera_height, process_num, threads_num), |
| 258 | + daemon=True, |
| 259 | + ) |
252 | 260 | p.start() |
253 | 261 | processes.append(p) |
254 | 262 |
|
|
0 commit comments