mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
tools/pyopenmv_fb: Fix pygame FB test script.
This commit is contained in:
parent
28f2976898
commit
8b2ba4bfc8
@ -39,8 +39,9 @@ if len(sys.argv)!= 2:
|
|||||||
print ('usage: pyopenmv_fb.py <serial port>')
|
print ('usage: pyopenmv_fb.py <serial port>')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
portname = sys.argv[1]
|
|
||||||
connected = False
|
connected = False
|
||||||
|
portname = sys.argv[1]
|
||||||
|
|
||||||
pyopenmv.disconnect()
|
pyopenmv.disconnect()
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
try:
|
try:
|
||||||
@ -68,6 +69,9 @@ pyopenmv.exec_script(script)
|
|||||||
|
|
||||||
# init screen
|
# init screen
|
||||||
running = True
|
running = True
|
||||||
|
screen = None
|
||||||
|
IMAGE_SCALE = 4
|
||||||
|
|
||||||
Clock = pygame.time.Clock()
|
Clock = pygame.time.Clock()
|
||||||
font = pygame.font.SysFont("monospace", 15)
|
font = pygame.font.SysFont("monospace", 15)
|
||||||
|
|
||||||
@ -76,13 +80,17 @@ while running:
|
|||||||
|
|
||||||
# read framebuffer
|
# read framebuffer
|
||||||
fb = pyopenmv.fb_dump()
|
fb = pyopenmv.fb_dump()
|
||||||
if fb != None:
|
if fb is not None:
|
||||||
# create image from RGB888
|
|
||||||
image = pygame.image.frombuffer(fb[2].flat[0:], (fb[0], fb[1]), 'RGB')
|
|
||||||
# TODO check if res changed
|
|
||||||
screen = pygame.display.set_mode((fb[0], fb[1]), pygame.DOUBLEBUF, 32)
|
|
||||||
|
|
||||||
fps = Clock.get_fps()
|
fps = Clock.get_fps()
|
||||||
|
w, h, data = fb[0], fb[1], fb[2]
|
||||||
|
|
||||||
|
# create image from RGB888
|
||||||
|
image = pygame.image.frombuffer(data.flat[0:], (w, h), 'RGB')
|
||||||
|
image = pygame.transform.scale(image, (w * IMAGE_SCALE, h * IMAGE_SCALE))
|
||||||
|
|
||||||
|
if screen is None:
|
||||||
|
screen = pygame.display.set_mode((w * IMAGE_SCALE, h * IMAGE_SCALE), pygame.DOUBLEBUF, 32)
|
||||||
|
|
||||||
# blit stuff
|
# blit stuff
|
||||||
screen.blit(image, (0, 0))
|
screen.blit(image, (0, 0))
|
||||||
screen.blit(font.render("FPS %.2f"%(fps), 1, (255, 0, 0)), (0, 0))
|
screen.blit(font.render("FPS %.2f"%(fps), 1, (255, 0, 0)), (0, 0))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user