mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #2359 from openmv/pyopenmv_updates
tools/pyopenmv: Display image size and format.
This commit is contained in:
commit
c57ffdc61e
@ -84,7 +84,7 @@ def read_state():
|
|||||||
text = text_buf.split(b'\0', 1)[0].decode()
|
text = text_buf.split(b'\0', 1)[0].decode()
|
||||||
|
|
||||||
if flags & __USBDBG_STATE_FLAGS_FRAME == 0:
|
if flags & __USBDBG_STATE_FLAGS_FRAME == 0:
|
||||||
return 0, 0, None, 0, text
|
return 0, 0, None, 0, text, ""
|
||||||
|
|
||||||
num_bytes = size if size > 2 else (w * h * size)
|
num_bytes = size if size > 2 else (w * h * size)
|
||||||
|
|
||||||
@ -93,17 +93,18 @@ def read_state():
|
|||||||
buff = __serial.read(num_bytes)
|
buff = __serial.read(num_bytes)
|
||||||
|
|
||||||
if size == 1: # Grayscale
|
if size == 1: # Grayscale
|
||||||
|
fmt = "GRAY"
|
||||||
y = np.fromstring(buff, dtype=np.uint8)
|
y = np.fromstring(buff, dtype=np.uint8)
|
||||||
buff = np.column_stack((y, y, y))
|
buff = np.column_stack((y, y, y))
|
||||||
size = w * h
|
|
||||||
elif size == 2: # RGB565
|
elif size == 2: # RGB565
|
||||||
|
fmt = "RGB"
|
||||||
arr = np.fromstring(buff, dtype=np.uint16)
|
arr = np.fromstring(buff, dtype=np.uint16)
|
||||||
r = (((arr & 0xF800) >>11)*255.0/31.0).astype(np.uint8)
|
r = (((arr & 0xF800) >>11)*255.0/31.0).astype(np.uint8)
|
||||||
g = (((arr & 0x07E0) >>5) *255.0/63.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)
|
b = (((arr & 0x001F) >>0) *255.0/31.0).astype(np.uint8)
|
||||||
buff = np.column_stack((r,g,b))
|
buff = np.column_stack((r,g,b))
|
||||||
size = w * h * 2
|
|
||||||
else: # JPEG
|
else: # JPEG
|
||||||
|
fmt = "JPEG"
|
||||||
try:
|
try:
|
||||||
buff = np.asarray(Image.frombuffer("RGB", (w, h), buff, "jpeg", "RGB", ""))
|
buff = np.asarray(Image.frombuffer("RGB", (w, h), buff, "jpeg", "RGB", ""))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -112,7 +113,7 @@ def read_state():
|
|||||||
if (buff.size != (w*h*3)):
|
if (buff.size != (w*h*3)):
|
||||||
raise ValueError(f"Unexpected frame size. Expected: {w*h*3} received: {buff.size}")
|
raise ValueError(f"Unexpected frame size. Expected: {w*h*3} received: {buff.size}")
|
||||||
|
|
||||||
return w, h, buff.reshape((h, w, 3)), size, text
|
return w, h, buff.reshape((h, w, 3)), num_bytes, text, fmt
|
||||||
|
|
||||||
|
|
||||||
def fb_dump():
|
def fb_dump():
|
||||||
|
|||||||
@ -75,7 +75,7 @@ def pygame_test(port, poll_rate, scale, benchmark):
|
|||||||
|
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
fps_clock = pygame.time.Clock()
|
fps_clock = pygame.time.Clock()
|
||||||
font = pygame.font.SysFont("monospace", 50)
|
font = pygame.font.SysFont("monospace", 30)
|
||||||
|
|
||||||
if benchmark:
|
if benchmark:
|
||||||
screen = pygame.display.set_mode((640, 120), pygame.DOUBLEBUF, 32)
|
screen = pygame.display.set_mode((640, 120), pygame.DOUBLEBUF, 32)
|
||||||
@ -83,7 +83,7 @@ def pygame_test(port, poll_rate, scale, benchmark):
|
|||||||
try:
|
try:
|
||||||
while running:
|
while running:
|
||||||
# Read state
|
# Read state
|
||||||
w, h, data, size, text = pyopenmv.read_state()
|
w, h, data, size, text, fmt = pyopenmv.read_state()
|
||||||
|
|
||||||
if text is not None:
|
if text is not None:
|
||||||
print(text, end="")
|
print(text, end="")
|
||||||
@ -104,7 +104,7 @@ def pygame_test(port, poll_rate, scale, benchmark):
|
|||||||
screen.fill((0, 0, 0))
|
screen.fill((0, 0, 0))
|
||||||
else:
|
else:
|
||||||
screen.blit(image, (0, 0))
|
screen.blit(image, (0, 0))
|
||||||
screen.blit(font.render("%.2f FPS %.2f MB/s"%(fps, fps * size / 1024**2), 5, (255, 0, 0)), (0, 0))
|
screen.blit(font.render(f"{fps:.2f} FPS {fps * size / 1024**2:.2f} MB/s {w}x{h} {fmt}", 5, (255, 0, 0)), (0, 0))
|
||||||
|
|
||||||
# update display
|
# update display
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user