-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (23 loc) · 867 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Sends images acquired from the OpenMV Cam via the serial port.
Important:
This script should be copied to the OpenMV Cam as `main.py`.
Source:
https://github.com/openmv/openmv/blob/master/scripts/examples/02-Board-Control/usb_vcp.py
"""
import sensor
import ustruct
import pyb
usb_vcp = pyb.USB_VCP()
# Disable USB interrupt (CTRL-C by default) when sending raw data (i.e. images)
# See: https://docs.openmv.io/library/pyb.USB_VCP.html#pyb.USB_VCP.setinterrupt
usb_vcp.setinterrupt(-1)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.VGA)
sensor.skip_frames(time=2000) # wait for settings to take effect!
while True:
command = usb_vcp.recv(4, timeout=5000)
if command == b'snap':
image = sensor.snapshot().compress()
usb_vcp.send(ustruct.pack('<L', image.size()))
usb_vcp.send(image)