Skip to content

Commit 763f1bd

Browse files
committed
Tweaks for v1.0.0
1 parent adb5ef0 commit 763f1bd

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# Need to specify the platform to build for
12
ifndef PLATFORM
23
$(error PLATFORM not specified. Use 'make PLATFORM=rp2350' or similar.)
34
endif
45

6+
# Set the toolchain file
57
TOOLCHAIN_FILE = platforms/${PLATFORM}.toolchain.cmake
68

79
# TODO: For some reason, specifying this in the toolchain file doesn't work

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ img = cv.imread("path/to/image.png")
4545
success = cv.imwrite("path/to/image.png", img)
4646
```
4747

48-
For full example, see our [Red Vision repo](https://github.com/sparkfun/red_vision).
48+
For full examples, see our [Red Vision repo](https://github.com/sparkfun/red_vision).
4949

5050
# Performance
5151

@@ -248,9 +248,12 @@ Below are instructions to build the MicroPython-OpenCV firmware from scratch. In
248248
249249
# Adding New Boards
250250
251+
> [!NOTE]
252+
> This section assumes this board's platform is supported (eg. RP2350). If not, see [#Adding New Platforms](#Adding-New-Platforms).
253+
251254
Because OpenCV dramatically increases the firmware size, it may be necessary to define board variants that reduce the storage size to avoid it overlapping with the firmware. It is also beneficial to adjust the board name to include `OpenCV` or similar to help people identify that the MicroPython-OpenCV firmware is flashed to the board instead of standard MicroPython.
252255
253-
Below is the variant for the XRP Controller as an example. The variant is defined by creating a file called [`micropython/ports/rp2/boards/SPARKFUN_XRP_CONTROLLER/mpconfigvariant_RED_VISION.cmake`](https://github.com/sparkfun/micropython/blob/7e728e8c6aad74ca244183f3e0705db6f332abd9/ports/rp2/boards/SPARKFUN_XRP_CONTROLLER/mpconfigvariant_LARGE_BINARY.cmake) with contents:
256+
Below is the variant for the XRP Controller as an example. The variant is defined by creating a file called [`micropython/ports/rp2/boards/SPARKFUN_XRP_CONTROLLER/mpconfigvariant_RED_VISION.cmake`](https://github.com/sparkfun/micropython/blob/e23e46ad423352b3f2362a51889bda25cb17b6cb/ports/rp2/boards/SPARKFUN_XRP_CONTROLLER/mpconfigvariant_RED_VISION.cmake) with contents:
254257
255258
```
256259
list(APPEND MICROPY_DEF_BOARD
@@ -270,23 +273,29 @@ Then, the firmware can be built by adding `BOARD_VARIANT=<variant-name>` to the
270273
Only support for the Raspberry Pi RP2350 has been figured out, so the all requirements for adding new platforms is not fully known yet. However, it should be along the lines of:
271274
272275
1. Create a valid toolchain file for the platform
273-
* See [rp2350.toolchain.cmake](src/opencv/platforms/rp2350.toolchain.cmake) for reference
276+
* See [rp2350.toolchain.cmake](platforms/rp2350.toolchain.cmake) for reference
274277
* This loosely follow's [OpenCV's platform definitions](https://github.com/opencv/opencv/tree/4.x/platforms)
275-
2. Ensure OpenCV builds correctly
278+
2. Build OpenCV with the new platform
276279
* ```
277-
make -C micropython-opencv/src/opencv PLATFORM=<new-platform> --no-print-directory -j4
280+
make -C micropython-opencv/opencv PLATFORM=<new-platform> --no-print-directory -j4
278281
```
279-
3. Create new board(s) for that platform
282+
3. Create a new board for the new platform
280283
* See [#Adding New Boards](#Adding-New-Boards)
281-
4. Build MicroPython-OpenCV firmware for that board
284+
4. Build MicroPython-OpenCV firmware for the new board
282285
* ```
283-
make -C micropython/ports/rp2 BOARD=<board-name> USER_C_MODULES=micropython-opencv/src/micropython_opencv.cmake -j4
286+
make -C micropython/ports/rp2 BOARD=<board-name> USER_C_MODULES=micropython-opencv/micropython_opencv.cmake -j4
284287
```
285288
286289
# Contributing
287290
291+
> [!NOTE]
292+
> We at SparkFun are not OpenCV developers. For things related to OpenCV, please head to https://github.com/opencv/opencv
293+
288294
Found a bug? Is there a discrepancy between standard OpenCV and MicroPython-OpenCV? Have a feature request?
289295
290296
First, please see if there is an [existing issue](https://github.com/sparkfun/micropython-opencv/issues). If not, then please [open a new issue](https://github.com/sparkfun/micropython-opencv/issues/new) so we can discuss the topic!
291297
292298
Pull requests are welcome! Please keep the scope of your pull request focused (make separate ones if needed), and keep file changes limited to the scope of your pull request.
299+
300+
> [!NOTE]
301+
> Because of limitations of microcontrollers, MicroPython, and OpenCV, it may not be possible to add some features of OpenCV.

platforms/common.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Derived from:
1+
# Credit to Joachim Burket for getting OpenCV to build on the ESP32 and
2+
# documenting a functional CMake configuration for it! This file is based on
3+
# their work here:
24
# https://github.com/joachimBurket/esp32-opencv/blob/master/esp32/doc/detailed_build_procedure.md
35
set(CMAKE_BUILD_TYPE Release)
46
set(BUILD_SHARED_LIBS OFF)
Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1+
/*
2+
*------------------------------------------------------------------------------
3+
* SPDX-License-Identifier: MIT
4+
*
5+
* Copyright (c) 2025 SparkFun Electronics
6+
*------------------------------------------------------------------------------
7+
* rp2350_unsafe_cv_xadd.h
8+
*
9+
* Fix for https://github.com/raspberrypi/pico-sdk/issues/2505
10+
* TLDR; OpenCV uses atomic operations for incrementing reference counters by
11+
* default. However, the Pico SDK does not support atomic operations on data in
12+
* PSRAM; attempting to do so just causes an infinite loop where the value is
13+
* incremented forever. The workaround is to use a non-atomic operation by
14+
* re-defining the `CV_XADD` macro. This is "unsafe" because it's not atomic,
15+
* but it *should* be fine since we're only using one thread. Also see:
16+
* https://github.com/opencv/opencv/blob/52bed3cd7890192700b2451e2713c340209ffd79/modules/core/include/opencv2/core/cvdef.h#L697-L723
17+
*------------------------------------------------------------------------------
18+
*/
19+
120
#ifndef RP2350_UNSAFE_CV_XADD_H
221
#define RP2350_UNSAFE_CV_XADD_H
322

4-
// Fix for https://github.com/raspberrypi/pico-sdk/issues/2505
5-
// TLDR; OpenCV uses atomic operations for incrementing reference counters by
6-
// default. However, the Pico SDK does not support atomic operations on data in
7-
// PSRAM; attempting to do so just causes an infinite loop where the value is
8-
// incremented forever. The workaround is to use a non-atomic operation by
9-
// re-defining the `CV_XADD` macro. This is "unsafe" because it's not atomic,
10-
// but it *should* be fine since we're only using one thread. Also see:
11-
// https://github.com/opencv/opencv/blob/52bed3cd7890192700b2451e2713c340209ffd79/modules/core/include/opencv2/core/cvdef.h#L697-L723
23+
// This is the same as OpenCV's unsafe XADD implementation:
24+
// https://github.com/opencv/opencv/blob/52bed3cd7890192700b2451e2713c340209ffd79/modules/core/include/opencv2/core/cvdef.h#L719
1225
static inline int unsafe_cv_xadd(int* addr, int delta)
1326
{
1427
int tmp = *addr;
1528
*addr += delta;
1629
return tmp;
1730
}
31+
32+
// Define CV_XADD to use our version
1833
#define CV_XADD(addr, delta) unsafe_cv_xadd(addr, delta)
1934

2035
#endif

0 commit comments

Comments
 (0)