Skip to content

Commit 37756bb

Browse files
committed
Don't set NumPy allocator as default
Caused issues with Canny, which internally creates 64-bit float Mat, which ulab does not support Replaced with call to ensure StdMatAllocator is allocated on the C heap
1 parent 01931af commit 37756bb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/core.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,16 @@ bool upyOpenCVBoot() {
4242
// https://github.com/sparkfun/micropython-opencv/issues/17
4343
haveImageWriter(".bmp");
4444

45-
// Sets the NumpyAllocator as the default Mat object allocator, see
45+
// Initializes `StdMatAllocator` on the C heap, see:
4646
// https://github.com/sparkfun/micropython-opencv/issues/17
47-
Mat::setDefaultAllocator(&GetNumpyAllocator());
47+
// Alternatively, we could set the NumpyAllocator as the default Mat
48+
// allocator with Mat::setDefaultAllocator(&GetNumpyAllocator()),
49+
// however that actually causes some issues. For example, Canny()
50+
// creates an temporary 64-bit float Mat, which is not supported by
51+
// ulab NumPy and therefore fails if we use the NumpyAllocator. The
52+
// StdMatAllocator is fine, because it calls `malloc()`, which we catch
53+
// with `__wrap_malloc()` to ensure the data is allocated on the GC heap
54+
Mat::getDefaultAllocator();
4855

4956
return true;
5057
} catch (const Exception& e) {

0 commit comments

Comments
 (0)