tools/pyopenmv: Return raw frame size for throughput calculations.

This commit is contained in:
iabdalkader 2024-08-03 15:49:01 +03:00
parent 844329a886
commit 0cb4325119

View File

@ -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():