Skip to main content

OpenMV Camera Protocol V2 - Python library and CLI

Project description

OpenMV Python

Python library and CLI for communicating with OpenMV cameras using Protocol V2.

Installation

pip install openmv

CLI Usage

Examples

# Basic usage - stream video from camera
openmv --port /dev/ttyACM0

# Run a custom script
openmv --port /dev/ttyACM0 --script my_script.py

# Adjust display scale (default is 4x)
openmv --port /dev/ttyACM0 --scale 2

# Run throughput benchmark
openmv --port /dev/ttyACM0 --bench

# Load firmware symbols for profiler function names
openmv --port /dev/ttyACM0 --firmware build/firmware.elf

# Quiet mode (suppress script output)
openmv --port /dev/ttyACM0 --quiet

# Debug mode (verbose logging)
openmv --port /dev/ttyACM0 --debug

Options

Option Default Description
--port PORT /dev/ttyACM0 Serial port
--script FILE None MicroPython script file to execute
--scale N 4 Display scaling factor
--poll MS 4 Poll rate in milliseconds
--bench False Run throughput benchmark mode
--timeout SEC 1.0 Protocol timeout in seconds
--baudrate N 921600 Serial baudrate
--firmware FILE None Firmware ELF file for profiler symbol resolution
--quiet False Suppress script output text
--debug False Enable debug logging

Protocol Options

Option Default Description
--crc BOOL true Enable CRC validation
--seq BOOL true Enable sequence number validation
--ack BOOL true Enable packet acknowledgment
--events BOOL true Enable event notifications
--max-retry N 3 Maximum number of retries
--max-payload N 4096 Maximum payload size in bytes
--drop-rate N 0.0 Packet drop simulation rate (0.0-1.0, for testing)

Keyboard Controls

Key Action
ESC Exit
P Cycle profiler overlay (Off → Performance → Events)
M Toggle profiler mode (Inclusive ↔ Exclusive)
R Reset profiler counters

Library Usage

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='')

API Reference

Full API documentation: docs/api.md

Camera

from openmv import Camera

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)
)

Methods

Method Description
connect() / disconnect() Manage connection
is_connected() Check connection status
exec(script) Execute a MicroPython script
stop() Stop the running script
streaming(enable, raw=False, res=None) Enable/disable video streaming
read_frame() Read video frame → {width, height, format, depth, data, raw_size}
read_stdout() Read script output text
read_status() Poll channel status → {channel_name: bool, ...}
has_channel(name) Check if channel exists
channel_read(name, size=None) Read from custom channel
channel_write(name, data) Write to custom channel
channel_size(name) Get available data size
system_info() Get camera system information
host_stats() / device_stats() Get protocol statistics

Profiler Methods (if available)

Method Description
read_profile() Read profiler data
profiler_mode(exclusive) Set inclusive/exclusive mode
profiler_reset(config=None) Reset profiler counters
profiler_event(counter_num, event_id) Configure event counter

Exceptions

Exception Description
OMVException Base protocol exception
TimeoutException Timeout during communication
ChecksumException CRC validation failure
SequenceException Sequence number mismatch

Requirements

  • Python 3.8+
  • pyserial >= 3.5
  • numpy >= 1.20.0
  • pygame >= 2.0.0
  • pyelftools

License

MIT License - Copyright (c) 2025 OpenMV, LLC.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openmv-1.0.3.tar.gz (34.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openmv-1.0.3-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

Details for the file openmv-1.0.3.tar.gz.

File metadata

  • Download URL: openmv-1.0.3.tar.gz
  • Upload date:
  • Size: 34.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openmv-1.0.3.tar.gz
Algorithm Hash digest
SHA256 19c055a83e83054ed765db53366a5d94ff42a09651a9bffddf8573beea306779
MD5 01710f6c32edc224fb8cece4067b5d2a
BLAKE2b-256 b2851db2fdc1cff60fe0478b5cc584c96d8fe3ab5e9d9c0dc520ece1e385e28e

See more details on using hashes here.

Provenance

The following attestation bundles were made for openmv-1.0.3.tar.gz:

Publisher: package.yml on openmv/openmv-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openmv-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: openmv-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 30.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openmv-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d2f17aca45a45206028a82be0682c19ecf08af958158510561b7f3c621f2054c
MD5 c29d33d8463cd3ed3ba34fd82c9b7473
BLAKE2b-256 f7a7bee59f279ba7209fb63810a77d6691a84749bc13121c0a6afd546380bd55

See more details on using hashes here.

Provenance

The following attestation bundles were made for openmv-1.0.3-py3-none-any.whl:

Publisher: package.yml on openmv/openmv-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page