Skip to content

Commit 8637030

Browse files
committed
Update README.md
Add splash image Update Quick Start section now that examples are frozen into the firmware Condense example code snippets Re-organize supported hardware list as tables with emojis
1 parent d327ecd commit 8637030

File tree

1 file changed

+63
-93
lines changed

1 file changed

+63
-93
lines changed

README.md

Lines changed: 63 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<p align="center">
2+
<img src="opencv-examples/images/splash.png" />
3+
</p>
4+
15
# MicroPython-OpenCV
26

37
Welcome to SparkFun's MicroPython port of OpenCV! This is the first known MicroPython port of OpenCV, and as such, there may be some rough edges. Hardware support is limited to SparkFun products.
@@ -6,127 +10,93 @@ Welcome to SparkFun's MicroPython port of OpenCV! This is the first known MicroP
610

711
1. Flash MicroPython-OpenCV firmware
812
* Back up any files you want to keep, they *will* be overwritten!
9-
* Download the latest firmware from the [Releases tab](https://github.com/sparkfun/micropython-opencv/releases).
13+
* Download the latest firmware for your board from the [Releases tab](https://github.com/sparkfun/micropython-opencv/releases).
1014
* If you don't know how to flash firmware to your board, find your board [here](https://micropython.org/download/) and follow the instructions using the OpenCV firmware.
11-
2. Copy examples (optional)
12-
* It is suggested to copy the entire examples folder to your MicroPython board to get started. This can be done simply with [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html):
13-
* `cd micropython-opencv/examples`
14-
* `mpremote cp -r . :`
15-
3. Configure hardware drivers
15+
* After first boot, the [opencv-examples](opencv-examples) directory will be automatically extraced to the MicroPython filesystem for easy access to all the examples.
16+
2. Configure hardware driver initialization
1617
* The MicroPython port of OpenCV depends on hardware drivers to interface with cameras and displays. Drivers are built into the firmware, so there is no need to install them manually.
17-
* An example module called [cv2_hardware_init](examples/cv2_hardware_init/) is imported by all examples to initialize the drivers. You will likely need to edit the files for your specific hardware and board configuration.
18-
4. Write OpenCV code!
18+
* An example module called [cv2_hardware_init](opencv-examples/cv2_hardware_init/) is imported by all examples to initialize the drivers. You will likely need to edit the files for your specific hardware and board configuration.
19+
3. Write and run OpenCV code
1920
* Any IDE should work, so use your favorite!
20-
* The code block below contains snippets from various examples to highlight major features.
21+
* Start with the examples! Go through them in order, which will verify your hardware is working and demonstrate some basics of OpenCV. Read the comments to understand the differences with the MicroPython port.
22+
* The code block below contains snippets to highlight major features.
2123

2224
```python
23-
# Import OpenCV, just as you would in any other Python environment!
25+
# Import OpenCV, just like any other Python environment!
2426
import cv2 as cv
2527

26-
# Standard OpenCV leverages the host operating system to access hardware, but we
27-
# don't have that luxury in MicroPython. Instead, drivers are provided for
28-
# various hardware components, which need to be initialized before using them.
29-
# The exmples import a module called `cv2_hardware_init`, which initializes the
30-
# drivers. You may need to edit the contents of the `cv2_hardware_init` module
31-
# based on your specific board and hardware configuration
28+
# Initialize hardware drivers by importing the example module (you'll likely
29+
# need to modify it for your specific hardware configuration).
3230
from cv2_hardware_init import *
3331

34-
# Import NumPy, almost like any other Python environment! The only difference is
35-
# the addition of `from ulab` since MicroPython does not have a full NumPy
36-
# implementation; ulab NumPy is a lightweight version of standard NumPy
32+
# Import ulab NumPy and initialize an image, almost like any other Python
33+
# environment!
3734
from ulab import numpy as np
38-
39-
# Initialize an image (NumPy array) to be displayed, just like in any other
40-
# Python environment! Here we create a 240x320 pixel image with 3 color channels
41-
# (BGR order, like standard OpenCV) and a data type of `uint8` (you should
42-
# always specify the data type, because NumPy defaults to `float`)
4335
img = np.zeros((240, 320, 3), dtype=np.uint8)
4436

45-
# OpenCV's drawing functions can be used to modify the image. Here is the
46-
# obligatory "Hello OpenCV!" text in red
47-
img = cv2.putText(img, "Hello OpenCV!", (50, 200), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
37+
# Call OpenCV functions just like any other Python environment!
38+
img = cv.putText(img, "Hello OpenCV!", (50, 200), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
39+
img = cv.Canny(img, 100, 200)
4840

49-
# Once we have an image ready to show, just call `cv.imshow()`, almost like any
50-
# other Python environment! However, there is one important difference:
51-
#
52-
# Standard OpenCV takes a window name string in `cv.imshow()`, which is used
53-
# to display the image in a window. We don't have windows in MicroPython, so
54-
# there is an API change where the first argument must be a display driver. Any
55-
# display driver can be used, as long as it implements an `imshow()` method that
56-
# takes a NumPy array as input
57-
cv.imshow(display, img) # Can alternatively call `display.imshow(img)`
58-
59-
# Standard OpenCV requires a call to `cv.waitKey()` to process events and
60-
# actually display the image. However the display driver shows the image
61-
# immediately, so it's not necessary to call `cv.waitKey()` in MicroPython.
62-
# But it is available, and behaves almost like any other Python environment! The
63-
# only difference is that it requires a key to be pressed in the REPL instead of
64-
# a window. It will wait for up to the specified number of milliseconds (0 for
65-
# indefinite), and return the ASCII code of the key pressed (-1 if no key press)
66-
#
67-
# Note - Some MicroPython IDEs (like Thonny) don't actually send any key presses
68-
# until you hit Enter on your keyboard
69-
key = cv.waitKey(0) # Not necessary to display image, can remove if desired
70-
71-
# Open a camera, similar to any other Python environment! In standard OpenCV,
72-
# you would use `cv.VideoCapture(0)` or similar, and OpenCV would leverage the
73-
# host operating system to open a camera object and return it as a
74-
# `cv.VideoCapture` object. However, we don't have that luxury in MicroPython,
75-
# so a camera driver is required instead. Any camera driver can be used, as long
76-
# as it implements the same methods as the standard OpenCV `cv.VideoCapture`
77-
# class, such as `open()`, `read()`, and `release()`
78-
camera.open()
41+
# Call `cv.imshow()`, almost like any other Python environment! Instead of a
42+
# window name string, you pass a display driver that implements an `imshow()`
43+
# method that takes a NumPy array as input
44+
cv.imshow(display, img)
7945

80-
# Read a frame from the camera, just like any other Python environment! It
81-
# returns a tuple, where the first element is a boolean indicating success,
82-
# and the second element is the frame (NumPy array) read from the camera
83-
success, frame = camera.read()
46+
# Call `cv.waitKey()`, just like any other Python environment! This waits for a
47+
# key press on the REPL. Standard OpenCV requires this to update windows, but
48+
# MicroPython OpenCV does not.
49+
key = cv.waitKey(0)
8450

85-
# Release the camera, just like in any other Python environment!
51+
# Use a camera, similar to any other Python environment! `cv.VideoCapture(0)`
52+
# is not used in MicroPython OpenCV, the driver is initialized separately.
53+
camera.open()
54+
success, frame = camera.read()
8655
camera.release()
8756

88-
# Call `cv.imread()` to read an image from the MicroPython filesystem, just
89-
# like in any other Python environment! Make sure to copy the image to the
90-
# MicroPython filesystem first, and set the path to the image file as needed
91-
#
92-
# If your board can mount an SD card, you can instead load the image to the SD
93-
# card and change the path to point to the SD card
94-
#
95-
# Note - only BMP and PNG formats are currently supported in MicroPython OpenCV
96-
img = cv.imread("test_images/sparkfun_logo.png")
97-
98-
# Let's modify the image! Here we use `cv2.Canny()` to perform edge detection
99-
# on the image, which is a common operation in computer vision
100-
edges = cv2.Canny(img, 100, 200)
101-
102-
# Now we'll save the modified image to the MicroPython filesystem using
103-
# `cv.imwrite()`, just like in any other Python environment!
104-
#
105-
# Again, SD cards are supported, just change the path to point to the SD card
57+
# Call `cv.imread()` and `cv.imwrite()` to read and write images to and from
58+
# the MicroPython filesystem, just like in any other Python environment! Can
59+
# also point to an SD card.
10660
#
10761
# Note - only BMP and PNG formats are currently supported in MicroPython OpenCV
108-
success = cv.imwrite("test_images/sparkfun_logo_edges.png", edges)
62+
img = cv.imread("path/to/image.png")
63+
success = cv.imwrite("path/to/image.png", img)
10964
```
11065

11166
# Hardware Support and Requirements
11267

11368
Hardware support in this repository is mostly limited to SparkFun products. The current list of supported proudcts is very small, but may be expanded in the future. Users are welcome to fork this repository to add support for other products, following our licence requirements. Assistance in adding support for other hardware will not be provided by SparkFun. We may consider pull requests that add support for additional hardware, see [#Contributing](#Contributing).
11469

115-
The OpenCV firmware adds ~3MiB on top of the standard MicroPython firmware, which itself be up to 1MiB in size (depending on platform and board). So a board with at least 8MB of flash is recommended, to also have space available for file storage.
70+
The OpenCV firmware adds over 3MiB on top of the standard MicroPython firmware, which itself be up to 1MiB in size (depending on platform and board). You'll also want some storage space, so a board with at least 8MB of flash is recommended.
11671

11772
PSRAM is a requirement to do anything useful with OpenCV. A single 320x240 RGB888 frame buffer requires 225KiB of RAM; most processors only have a few hundred KiB of SRAM. Several frame buffers can be needed for even simple vision pipelines, so you really need at least a few MiB of RAM available. The more the merrier!
11873

119-
Below is the list of supported hardware devices:
120-
121-
* MicroPython Devices
122-
* [XRP Controller](https://www.sparkfun.com/sparkfun-experiential-robotics-platform-xrp-controller.html)
123-
* Camera Drivers
124-
* HM01B0
125-
* [OV5640](https://www.sparkfun.com/ov5640-camera-board-5-megapixel-2592x1944-fisheye-lens.html) (not fully working yet)
126-
* Display Drivers
127-
* ST7789
128-
* Touch Screen Drivers
129-
* CST816
74+
Below is the list of currently supported hardware:
75+
76+
## MicroPython Devices
77+
78+
| Status | Device | Notes |
79+
| --- | --- | --- |
80+
| ✔️ | [XRP Controller](https://www.sparkfun.com/sparkfun-experiential-robotics-platform-xrp-controller.html) | |
81+
82+
## Camera Drivers
83+
84+
| Status | Device | Notes |
85+
| --- | --- | --- |
86+
| ✔️ | HM01B0 | |
87+
| ⚠️ | [OV5640](https://www.sparkfun.com/ov5640-camera-board-5-megapixel-2592x1944-fisheye-lens.html) | See [#22](https://github.com/sparkfun/micropython-opencv/issues/22) |
88+
89+
## Display Drivers
90+
91+
| Status | Device | Notes |
92+
| --- | --- | --- |
93+
| ✔️ | ST7789 | |
94+
95+
## Touch Screen Drivers
96+
97+
| Status | Device | Notes |
98+
| --- | --- | --- |
99+
| ✔️ | CST816 | |
130100

131101
# Performance
132102

0 commit comments

Comments
 (0)