Skip to content

Slicing to downsample image does not work #16

@sfe-SparkFro

Description

@sfe-SparkFro

Using a 640x480 image (source: Wikipedia), I attempted to downsample it for display with cv2.imshow(display, img[::2, ::2]). In standard Python, the following was displayed:

Image

In MicroPython, the following was displayed:

Image

Poking around with a debugger right here:

Mat mat = Mat(ndims, size, type, (void*) ndarray->array, step);

The constructed Mat object's step array does not match the provided step array:

(gdb) p step
$8 = {3840, 6, 0 <repeats 31 times>}
(gdb) p mat.step.buf
$9 = {3840, 3}

I suspect the problem is here:

@param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always set to the element size)...

Not sure why there's a discrepancy between standard Python and MicroPython, because ndarray_to_mat() is basically the same as pyopencv_to() (at least, as far as how step is constructed). I suspect when standard NumPy does the array slicing, it makes a copy instead of reusing the same array like ulab NumPy does, so forcing the last element of steps to be the element size isn't a problem. Maybe. Regardless, might just be able to force the Mat object's step array to match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions