From 48d2f8ddf517030604503fd77cc84145410cd9a5 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 5 Aug 2024 13:34:15 +0300 Subject: [PATCH] tools/pyopenmv: Misc fixes. * Add scale arg. * Fix RGB565 byte order. --- tools/pyopenmv.py | 4 ++-- tools/pyopenmv_fb.py | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tools/pyopenmv.py b/tools/pyopenmv.py index c43d38bfa..5cc05c7d0 100755 --- a/tools/pyopenmv.py +++ b/tools/pyopenmv.py @@ -97,7 +97,7 @@ def read_state(): buff = np.column_stack((y, y, y)) size = w * h elif size == 2: # RGB565 - arr = np.fromstring(buff, dtype=np.uint16).newbyteorder('S') + arr = np.fromstring(buff, dtype=np.uint16) r = (((arr & 0xF800) >>11)*255.0/31.0).astype(np.uint8) g = (((arr & 0x07E0) >>5) *255.0/63.0).astype(np.uint8) b = (((arr & 0x001F) >>0) *255.0/31.0).astype(np.uint8) @@ -135,7 +135,7 @@ def fb_dump(): y = np.fromstring(buff, dtype=np.uint8) buff = np.column_stack((y, y, y)) elif size[2] == 2: # RGB565 - arr = np.fromstring(buff, dtype=np.uint16).newbyteorder('S') + arr = np.fromstring(buff, dtype=np.uint16) r = (((arr & 0xF800) >>11)*255.0/31.0).astype(np.uint8) g = (((arr & 0x07E0) >>5) *255.0/63.0).astype(np.uint8) b = (((arr & 0x001F) >>0) *255.0/31.0).astype(np.uint8) diff --git a/tools/pyopenmv_fb.py b/tools/pyopenmv_fb.py index eae69a10a..bad1d650c 100755 --- a/tools/pyopenmv_fb.py +++ b/tools/pyopenmv_fb.py @@ -26,7 +26,6 @@ clock = time.clock() while(True): clock.tick() img = sensor.snapshot() - sensor.flush() print(clock.fps(), " FPS") """ @@ -40,7 +39,7 @@ while(True): img.flush() """ -def pygame_test(port, poll_rate, benchmark): +def pygame_test(port, poll_rate, scale, benchmark): # init pygame pygame.init() pyopenmv.disconnect() @@ -73,7 +72,6 @@ def pygame_test(port, poll_rate, benchmark): # init screen running = True screen = None - IMAGE_SCALE = 4 clock = pygame.time.Clock() fps_clock = pygame.time.Clock() @@ -96,10 +94,10 @@ def pygame_test(port, poll_rate, benchmark): # Create image from RGB888 if not benchmark: image = pygame.image.frombuffer(data.flat[0:], (w, h), 'RGB') - image = pygame.transform.scale(image, (w * IMAGE_SCALE, h * IMAGE_SCALE)) + image = pygame.transform.smoothscale(image, (w * scale, h * scale)) if screen is None: - screen = pygame.display.set_mode((w * IMAGE_SCALE, h * IMAGE_SCALE), pygame.DOUBLEBUF, 32) + screen = pygame.display.set_mode((w * scale, h * scale), pygame.DOUBLEBUF, 32) # blit stuff if benchmark: @@ -131,7 +129,8 @@ def pygame_test(port, poll_rate, benchmark): if __name__ == '__main__': parser = argparse.ArgumentParser(description='pyopenmv module') parser.add_argument('--port', action = 'store', help='OpenMV camera port (default /dev/ttyACM0)', default='/dev/ttyACM0', ) - parser.add_argument('--poll', action = 'store', help='Poll rate in ms (default 4)', default=4) + parser.add_argument('--poll', action = 'store', help='Poll rate (default 4ms)', default=4, type=int) parser.add_argument('--bench', action = 'store_true', help='Run throughput benchmark.', default=False) + parser.add_argument('--scale', action = 'store', help='Set frame scaling factor (default 4x).', default=4, type=int) args = parser.parse_args() - pygame_test(args.port, int(args.poll), args.bench) + pygame_test(args.port, args.poll, args.scale, args.bench)