mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
tools/pyopenmv: Misc fixes.
* Add scale arg. * Fix RGB565 byte order.
This commit is contained in:
parent
23447870b5
commit
48d2f8ddf5
@ -97,7 +97,7 @@ def read_state():
|
|||||||
buff = np.column_stack((y, y, y))
|
buff = np.column_stack((y, y, y))
|
||||||
size = w * h
|
size = w * h
|
||||||
elif size == 2: # RGB565
|
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)
|
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)
|
||||||
@ -135,7 +135,7 @@ def fb_dump():
|
|||||||
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))
|
||||||
elif size[2] == 2: # RGB565
|
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)
|
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)
|
||||||
|
|||||||
@ -26,7 +26,6 @@ clock = time.clock()
|
|||||||
while(True):
|
while(True):
|
||||||
clock.tick()
|
clock.tick()
|
||||||
img = sensor.snapshot()
|
img = sensor.snapshot()
|
||||||
sensor.flush()
|
|
||||||
print(clock.fps(), " FPS")
|
print(clock.fps(), " FPS")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ while(True):
|
|||||||
img.flush()
|
img.flush()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def pygame_test(port, poll_rate, benchmark):
|
def pygame_test(port, poll_rate, scale, benchmark):
|
||||||
# init pygame
|
# init pygame
|
||||||
pygame.init()
|
pygame.init()
|
||||||
pyopenmv.disconnect()
|
pyopenmv.disconnect()
|
||||||
@ -73,7 +72,6 @@ def pygame_test(port, poll_rate, benchmark):
|
|||||||
# init screen
|
# init screen
|
||||||
running = True
|
running = True
|
||||||
screen = None
|
screen = None
|
||||||
IMAGE_SCALE = 4
|
|
||||||
|
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
fps_clock = pygame.time.Clock()
|
fps_clock = pygame.time.Clock()
|
||||||
@ -96,10 +94,10 @@ def pygame_test(port, poll_rate, benchmark):
|
|||||||
# Create image from RGB888
|
# Create image from RGB888
|
||||||
if not benchmark:
|
if not benchmark:
|
||||||
image = pygame.image.frombuffer(data.flat[0:], (w, h), 'RGB')
|
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:
|
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
|
# blit stuff
|
||||||
if benchmark:
|
if benchmark:
|
||||||
@ -131,7 +129,8 @@ def pygame_test(port, poll_rate, benchmark):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(description='pyopenmv module')
|
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('--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('--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()
|
args = parser.parse_args()
|
||||||
pygame_test(args.port, int(args.poll), args.bench)
|
pygame_test(args.port, args.poll, args.scale, args.bench)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user