Python library and CLI for communicating with OpenMV cameras using Protocol V2.
pip install openmv# Stream from specific port
openmv --port /dev/ttyACM0
# Run a custom script
openmv --script my_script.py
# Adjust display scale
openmv --scale 2
# Enable firmware symbols
openmv --firmware path/to/firmware.elfopenmv --benchESC- ExitP- Cycle profiler overlay (Off → Performance → Events)M- Toggle profiler mode (Inclusive ↔ Exclusive)R- Reset profiler counters
from openmv import Camera
script = """
import csi, time
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
clock = time.clock()
while True:
clock.tick()
img = csi0.snapshot()
print(clock.fps(), "FPS")
"""
# Connect to camera
with Camera('/dev/ttyACM0') as camera:
# Stop running script (if any)
camera.stop()
# Execute script and enable streaming
camera.exec(script)
camera.streaming(True, raw=False, res=(512, 512))
# Read frames and output
while True:
if frame := camera.read_frame():
print(f"Frame: {frame['width']}x{frame['height']}")
if text := camera.read_stdout():
print(text, end='')Main class for camera communication.
Camera(
port, # Serial port (e.g., '/dev/ttyACM0')
baudrate=921600, # Serial baudrate
crc=True, # Enable CRC validation
seq=True, # Enable sequence number validation
ack=True, # Enable packet acknowledgment
events=True, # Enable event notifications
timeout=1.0, # Protocol timeout in seconds
max_retry=3, # Maximum retries
max_payload=4096, # Maximum payload size
drop_rate=0.0, # Packet drop simulation (testing only)
)Connection Management:
connect()/disconnect()- Manage connectionis_connected()- Check connection status
Script Execution:
exec(script)- Execute a MicroPython scriptstop()- Stop the running script
Video Streaming:
streaming(enable, raw=False, res=None)- Enable/disable video streamingread_frame()- Read a video frame (returns dict with width, height, format, depth, data, raw_size)
Output and Status:
read_stdout()- Read script output textread_status()- Poll channel status (returns dict of channel readiness)
Channel Operations:
has_channel(name)- Check if a channel existschannel_read(name, size=None)- Read data from a custom channelchannel_write(name, data)- Write data to a custom channelchannel_size(name)- Get size of available data in a channel
Profiler (if available):
read_profile()- Read profiler dataprofiler_mode(exclusive)- Set profiler mode (inclusive/exclusive)profiler_reset(config=None)- Reset profiler countersprofiler_event(counter_num, event_id)- Configure event counter
System Information:
system_info()- Get camera system informationhost_stats()/device_stats()- Get protocol statistics
OMVException- Base protocol exceptionTimeoutException- Timeout during communicationChecksumException- CRC validation failureSequenceException- Sequence number mismatch
- Python 3.8+
- pyserial >= 3.5
- numpy >= 1.20.0
- pygame >= 2.0.0
- pyelftools
MIT License - Copyright (c) 2025 OpenMV, LLC.