diff --git a/common/polystar/common/models/trt_model.py b/common/polystar/common/models/trt_model.py index 676e06af75a83aad7058d873874c848a73cc743f..b72fa2020009e6c03ba1fb964cdb62cdbdcd0489 100644 --- a/common/polystar/common/models/trt_model.py +++ b/common/polystar/common/models/trt_model.py @@ -46,7 +46,7 @@ class TRTModel: img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img = cv2.resize(img, self.input_size) img = img.transpose((2, 0, 1)).astype(np.float32) - img = (2.0/255.0) * img - 1.0 + img = (2.0 / 255.0) * img - 1.0 return img # Initialization diff --git a/common/polystar/common/view/bend_object_on_image.py b/common/polystar/common/view/bend_object_on_image.py index b91ce7206d7e4f2e6514bccf60ee66f23b9f2690..6e21ed0a081a0a36093cebf98c1d0f4ef769dcca 100644 --- a/common/polystar/common/view/bend_object_on_image.py +++ b/common/polystar/common/view/bend_object_on_image.py @@ -39,13 +39,21 @@ def bend_boxed_text_on_image(img: Image, text: str, topleft: Tuple[int, int], co # the patch is used to draw boxed text patch = np.zeros((h, w, 3), dtype=np.uint8) patch[...] = color - cv2.putText(patch, text, (margin+1, h-margin-2), FONT, TEXT_SCALE, - WHITE, thickness=TEXT_THICKNESS, lineType=cv2.LINE_8) - cv2.rectangle(patch, (0, 0), (w-1, h-1), BLACK, thickness=1) + cv2.putText( + patch, + text, + (margin + 1, h - margin - 2), + FONT, + TEXT_SCALE, + WHITE, + thickness=TEXT_THICKNESS, + lineType=cv2.LINE_8, + ) + cv2.rectangle(patch, (0, 0), (w - 1, h - 1), BLACK, thickness=1) w = min(w, img_w - topleft[0]) # clip overlay at image boundary h = min(h, img_h - topleft[1]) # Overlay the boxed text onto region of interest (roi) in img - roi = img[topleft[1]:topleft[1]+h, topleft[0]:topleft[0]+w, :] + roi = img[topleft[1] : topleft[1] + h, topleft[0] : topleft[0] + w, :] cv2.addWeighted(patch[0:h, 0:w, :], ALPHA, roi, 1 - ALPHA, 0, roi) return img diff --git a/robots-at-robots/research/demos/demo_pipeline_camera.py b/robots-at-robots/research/demos/demo_pipeline_camera.py index 94b8bc8417664e606080264e1ab2928241c9df76..d2b43ea6b27d29841dd9daaf9f0541711fc34445 100644 --- a/robots-at-robots/research/demos/demo_pipeline_camera.py +++ b/robots-at-robots/research/demos/demo_pipeline_camera.py @@ -77,8 +77,8 @@ if __name__ == "__main__": for f in filters: objects = f.filter(objects, image) - fps = .9 * fps + .1 / (time() - previous_time) - bend_boxed_text_on_image(image, f'FPS: {fps:.1f}', (10, 10), (0, 0, 0)) + fps = 0.9 * fps + 0.1 / (time() - previous_time) + bend_boxed_text_on_image(image, f"FPS: {fps:.1f}", (10, 10), (0, 0, 0)) for obj in objects: bend_object_on_image(image, obj)