|
| 1 | +# OpenMV Python |
| 2 | + |
| 3 | +Python library and CLI for communicating with OpenMV cameras using Protocol V2. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +pip install openmv |
| 9 | +``` |
| 10 | + |
| 11 | +For video streaming support (requires pygame): |
| 12 | + |
| 13 | +```bash |
| 14 | +pip install openmv[gui] |
| 15 | +``` |
| 16 | + |
| 17 | +## CLI Usage |
| 18 | + |
| 19 | +### Stream Video |
| 20 | + |
| 21 | +```bash |
| 22 | +# Stream from default port (/dev/ttyACM0) |
| 23 | +openmv |
| 24 | + |
| 25 | +# Stream from specific port |
| 26 | +openmv --port /dev/ttyACM1 |
| 27 | + |
| 28 | +# Run a custom script |
| 29 | +openmv --script my_script.py |
| 30 | + |
| 31 | +# Adjust display scale |
| 32 | +openmv --scale 2 |
| 33 | +``` |
| 34 | + |
| 35 | +### Camera Info |
| 36 | + |
| 37 | +```bash |
| 38 | +openmv --info |
| 39 | +``` |
| 40 | + |
| 41 | +### Reset Camera |
| 42 | + |
| 43 | +```bash |
| 44 | +openmv --reset |
| 45 | +``` |
| 46 | + |
| 47 | +### Enter Bootloader |
| 48 | + |
| 49 | +```bash |
| 50 | +openmv --boot |
| 51 | +``` |
| 52 | + |
| 53 | +### Benchmark Mode |
| 54 | + |
| 55 | +```bash |
| 56 | +openmv --bench |
| 57 | +``` |
| 58 | + |
| 59 | +### Controls (Stream Mode) |
| 60 | + |
| 61 | +- `C` - Capture screenshot to `capture.png` |
| 62 | +- `ESC` - Exit |
| 63 | + |
| 64 | +## Library Usage |
| 65 | + |
| 66 | +```python |
| 67 | +from openmv import OMVCamera |
| 68 | + |
| 69 | +# Connect to camera |
| 70 | +with OMVCamera('/dev/ttyACM0') as camera: |
| 71 | + # Get system info |
| 72 | + info = camera.system_info() |
| 73 | + print(f"Firmware: {info['firmware_version']}") |
| 74 | + |
| 75 | + # Execute a script |
| 76 | + camera.exec(''' |
| 77 | +import csi |
| 78 | +csi0 = csi.CSI() |
| 79 | +csi0.reset() |
| 80 | +''') |
| 81 | + |
| 82 | + # Read frames |
| 83 | + camera.streaming(True) |
| 84 | + while True: |
| 85 | + if frame := camera.read_frame(): |
| 86 | + print(f"Frame: {frame['width']}x{frame['height']}") |
| 87 | +``` |
| 88 | + |
| 89 | +## API Reference |
| 90 | + |
| 91 | +### OMVCamera |
| 92 | + |
| 93 | +Main class for camera communication. |
| 94 | + |
| 95 | +```python |
| 96 | +OMVCamera( |
| 97 | + port, # Serial port (e.g., '/dev/ttyACM0') |
| 98 | + baudrate=921600, # Serial baudrate |
| 99 | + crc=True, # Enable CRC validation |
| 100 | + seq=True, # Enable sequence number validation |
| 101 | + ack=True, # Enable packet acknowledgment |
| 102 | + events=True, # Enable event notifications |
| 103 | + timeout=1.0, # Protocol timeout in seconds |
| 104 | + max_retry=3, # Maximum retries |
| 105 | + max_payload=4096, # Maximum payload size |
| 106 | +) |
| 107 | +``` |
| 108 | + |
| 109 | +#### Methods |
| 110 | + |
| 111 | +- `connect()` / `disconnect()` - Manage connection |
| 112 | +- `exec(script)` - Execute a MicroPython script |
| 113 | +- `stop()` - Stop the running script |
| 114 | +- `reset()` - Reset the camera |
| 115 | +- `boot()` - Enter bootloader mode |
| 116 | +- `streaming(enable, raw=False, res=None)` - Enable/disable video streaming |
| 117 | +- `read_frame()` - Read a video frame |
| 118 | +- `read_stdout()` - Read script output |
| 119 | +- `read_status()` - Poll channel status |
| 120 | +- `system_info()` - Get camera system information |
| 121 | +- `channel_read(name)` / `channel_write(name, data)` - Custom channel I/O |
| 122 | + |
| 123 | +### Exceptions |
| 124 | + |
| 125 | +- `OMVPException` - Base protocol exception |
| 126 | +- `OMVPTimeoutException` - Timeout during communication |
| 127 | +- `OMVPChecksumException` - CRC validation failure |
| 128 | +- `OMVPSequenceException` - Sequence number mismatch |
| 129 | + |
| 130 | +## Requirements |
| 131 | + |
| 132 | +- Python 3.8+ |
| 133 | +- pyserial |
| 134 | +- numpy |
| 135 | +- pygame (optional, for video streaming) |
| 136 | + |
| 137 | +## License |
| 138 | + |
| 139 | +MIT License - Copyright (c) 2025 OpenMV, LLC. |
0 commit comments