mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update pyopenmv scripts
This commit is contained in:
parent
d282e92857
commit
9d6f753be7
@ -1,10 +1,8 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
import sys
|
import sys
|
||||||
# import usb.core
|
|
||||||
# import usb.util
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pygame
|
import pygame
|
||||||
import openmv
|
import pyopenmv
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
script = """
|
script = """
|
||||||
@ -35,12 +33,12 @@ else:
|
|||||||
portname = "/dev/openmvcam"
|
portname = "/dev/openmvcam"
|
||||||
|
|
||||||
connected = False
|
connected = False
|
||||||
openmv.disconnect()
|
pyopenmv.disconnect()
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
try:
|
try:
|
||||||
# opens CDC port.
|
# opens CDC port.
|
||||||
# Set small timeout when connecting
|
# Set small timeout when connecting
|
||||||
openmv.init(portname, baudrate=921600, timeout=0.050)
|
pyopenmv.init(portname, baudrate=921600, timeout=0.050)
|
||||||
connected = True
|
connected = True
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -55,10 +53,10 @@ if not connected:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Set higher timeout after connecting for lengthy transfers.
|
# Set higher timeout after connecting for lengthy transfers.
|
||||||
openmv.set_timeout(1*2) # SD Cards can cause big hicups.
|
pyopenmv.set_timeout(1*2) # SD Cards can cause big hicups.
|
||||||
openmv.stop_script()
|
pyopenmv.stop_script()
|
||||||
openmv.enable_fb(True)
|
pyopenmv.enable_fb(True)
|
||||||
openmv.exec_script(script)
|
pyopenmv.exec_script(script)
|
||||||
|
|
||||||
# init screen
|
# init screen
|
||||||
running = True
|
running = True
|
||||||
@ -69,7 +67,7 @@ while running:
|
|||||||
Clock.tick(100)
|
Clock.tick(100)
|
||||||
|
|
||||||
# read framebuffer
|
# read framebuffer
|
||||||
fb = openmv.fb_dump()
|
fb = pyopenmv.fb_dump()
|
||||||
|
|
||||||
if fb == None:
|
if fb == None:
|
||||||
continue
|
continue
|
||||||
@ -101,4 +99,4 @@ while running:
|
|||||||
|
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
openmv.stop_script()
|
pyopenmv.stop_script()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
import sys, os
|
import sys, os
|
||||||
import openmv
|
import pyopenmv
|
||||||
import argparse
|
import argparse
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from random import randint
|
from random import randint
|
||||||
@ -11,7 +11,8 @@ def main():
|
|||||||
parser.add_argument("-j", "--disable_fb", action = "store_true", help = "Disable FB JPEG compression")
|
parser.add_argument("-j", "--disable_fb", action = "store_true", help = "Disable FB JPEG compression")
|
||||||
parser.add_argument("-p", "--port", action = "store", help = "OpenMV serial port")
|
parser.add_argument("-p", "--port", action = "store", help = "OpenMV serial port")
|
||||||
parser.add_argument("-t", "--time", action = "store", default = 100, help = "Max time before stopping the script")
|
parser.add_argument("-t", "--time", action = "store", default = 100, help = "Max time before stopping the script")
|
||||||
parser.add_argument("-s", "--script", action = "store", default="examples/01-Basics/helloworld.py", help = "OpenMV script file")
|
parser.add_argument("-s", "--script", action = "store",\
|
||||||
|
default="../scripts/examples/01-Basics/helloworld.py", help = "OpenMV script file")
|
||||||
|
|
||||||
# Parse CMD args
|
# Parse CMD args
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@ -34,7 +35,7 @@ def main():
|
|||||||
try:
|
try:
|
||||||
# Open serial port.
|
# Open serial port.
|
||||||
# Set small timeout when connecting
|
# Set small timeout when connecting
|
||||||
openmv.init(portname, baudrate=921600, timeout=0.050)
|
pyopenmv.init(portname, baudrate=921600, timeout=0.050)
|
||||||
connected = True
|
connected = True
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -49,19 +50,19 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Set higher timeout after connecting.
|
# Set higher timeout after connecting.
|
||||||
openmv.set_timeout(0.500)
|
pyopenmv.set_timeout(0.500)
|
||||||
|
|
||||||
# Enable/Disable framebuffer compression.
|
# Enable/Disable framebuffer compression.
|
||||||
print(">>>Enable FB JPEG compression %s" %(str(not args.disable_fb)))
|
print(">>>Enable FB JPEG compression %s" %(str(not args.disable_fb)))
|
||||||
openmv.enable_fb(not args.disable_fb)
|
pyopenmv.enable_fb(not args.disable_fb)
|
||||||
|
|
||||||
# Interrupt running script.
|
# Interrupt running script.
|
||||||
openmv.stop_script()
|
pyopenmv.stop_script()
|
||||||
max_timeout = int(args.time)
|
max_timeout = int(args.time)
|
||||||
for i in xrange(1000):
|
for i in xrange(1000):
|
||||||
openmv.exec_script(script)
|
pyopenmv.exec_script(script)
|
||||||
sleep(randint(0, max_timeout)/1000)
|
sleep(randint(0, max_timeout)/1000)
|
||||||
openmv.stop_script()
|
pyopenmv.stop_script()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user