Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
Pipfile.lock

# PEP 582
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Project specific
capture.png
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 OpenMV, LLC.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
139 changes: 139 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# OpenMV Python

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

## Installation

```bash
pip install openmv
```

For video streaming support (requires pygame):

```bash
pip install openmv[gui]
```

## CLI Usage

### Stream Video

```bash
# Stream from default port (/dev/ttyACM0)
openmv

# Stream from specific port
openmv --port /dev/ttyACM1

# Run a custom script
openmv --script my_script.py

# Adjust display scale
openmv --scale 2
```

### Camera Info

```bash
openmv --info
```

### Reset Camera

```bash
openmv --reset
```

### Enter Bootloader

```bash
openmv --boot
```

### Benchmark Mode

```bash
openmv --bench
```

### Controls (Stream Mode)

- `C` - Capture screenshot to `capture.png`
- `ESC` - Exit

## Library Usage

```python
from openmv import OMVCamera

# Connect to camera
with OMVCamera('/dev/ttyACM0') as camera:
# Get system info
info = camera.system_info()
print(f"Firmware: {info['firmware_version']}")

# Execute a script
camera.exec('''
import csi
csi0 = csi.CSI()
csi0.reset()
''')

# Read frames
camera.streaming(True)
while True:
if frame := camera.read_frame():
print(f"Frame: {frame['width']}x{frame['height']}")
```

## API Reference

### OMVCamera

Main class for camera communication.

```python
OMVCamera(
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
)
```

#### Methods

- `connect()` / `disconnect()` - Manage connection
- `exec(script)` - Execute a MicroPython script
- `stop()` - Stop the running script
- `reset()` - Reset the camera
- `boot()` - Enter bootloader mode
- `streaming(enable, raw=False, res=None)` - Enable/disable video streaming
- `read_frame()` - Read a video frame
- `read_stdout()` - Read script output
- `read_status()` - Poll channel status
- `system_info()` - Get camera system information
- `channel_read(name)` / `channel_write(name, data)` - Custom channel I/O

### Exceptions

- `OMVPException` - Base protocol exception
- `OMVPTimeoutException` - Timeout during communication
- `OMVPChecksumException` - CRC validation failure
- `OMVPSequenceException` - Sequence number mismatch

## Requirements

- Python 3.8+
- pyserial
- numpy
- pygame (optional, for video streaming)

## License

MIT License - Copyright (c) 2025 OpenMV, LLC.
48 changes: 48 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "openmv"
version = "2.0.0"
description = "OpenMV Camera Protocol V2 - Python library and CLI"
readme = "README.md"
license = {text = "MIT"}
requires-python = ">=3.8"
authors = [
{name = "OpenMV, LLC", email = "info@openmv.io"}
]
keywords = ["openmv", "camera", "machine-vision", "embedded", "micropython"]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Image Processing",
"Topic :: Software Development :: Embedded Systems",
]
dependencies = [
"pyserial>=3.5",
"numpy>=1.20.0",
"pygame>=2.0.0",
"pyelftools"
]

[project.scripts]
openmv = "openmv.cli:main"

[project.urls]
Homepage = "https://openmv.io"
Documentation = "https://docs.openmv.io"
Repository = "https://github.com/openmv/openmv-python"
Issues = "https://github.com/openmv/openmv-python/issues"

[tool.setuptools.packages.find]
where = ["src"]
35 changes: 35 additions & 0 deletions src/openmv/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SPDX-License-Identifier: MIT
#
# Copyright (c) 2025 OpenMV, LLC.
#
# OpenMV Protocol Package
#
# This package provides a Python implementation of the OpenMV Protocol
# for communicating with OpenMV cameras.
#
# Main classes:
# Camera: High-level camera interface with channel operations
#
# Main exceptions:
# OMVException: Base exception for protocol errors
# TimeoutException: Timeout during protocol operations
# ChecksumException: CRC validation failures
# SequenceException: Sequence number validation failures

from .camera import Camera
from .exceptions import (
OMVException,
TimeoutException,
ChecksumException,
SequenceException
)

__version__ = "2.0.0"

__all__ = [
'Camera',
'OMVException',
'TimeoutException',
'ChecksumException',
'SequenceException'
]
Loading