From 0cb43251199ff6642ecca38ab4f9fd9d933c2107 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 3 Aug 2024 15:49:01 +0300 Subject: [PATCH] tools/pyopenmv: Return raw frame size for throughput calculations. --- tools/pyopenmv.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/pyopenmv.py b/tools/pyopenmv.py index 8bf1034b3..c43d38bfa 100755 --- a/tools/pyopenmv.py +++ b/tools/pyopenmv.py @@ -84,7 +84,7 @@ def read_state(): text = text_buf.split(b'\0', 1)[0].decode() if flags & __USBDBG_STATE_FLAGS_FRAME == 0: - return 0, 0, None, text + return 0, 0, None, 0, text num_bytes = size if size > 2 else (w * h * size) @@ -95,12 +95,14 @@ def read_state(): if size == 1: # Grayscale y = np.fromstring(buff, dtype=np.uint8) buff = np.column_stack((y, y, y)) + size = w * h elif size == 2: # RGB565 arr = np.fromstring(buff, dtype=np.uint16).newbyteorder('S') 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) buff = np.column_stack((r,g,b)) + size = w * h * 2 else: # JPEG try: buff = np.asarray(Image.frombuffer("RGB", (w, h), buff, "jpeg", "RGB", "")) @@ -110,7 +112,7 @@ def read_state(): if (buff.size != (w*h*3)): raise ValueError(f"Unexpected frame size. Expected: {w*h*3} received: {buff.size}") - return w, h, buff.reshape((h, w, 3)), text + return w, h, buff.reshape((h, w, 3)), size, text def fb_dump():