Skip to content

Drawing into a numpy view with a negative step in the channel dimension doesn't work #15895

@tailsu

Description

@tailsu
System information (version)
  • OpenCV => opencv-contrib-python-headless==4.1.1.26
  • Operating System / Platform => OS X
Detailed description

I create three 3-channel images and draw a circle into them. In the second case I use the step trick A[:, :, ::-1] to flip the R and B channels in the image, emulating cv.cvtColor with COLOR_BGR2RGB. I then try to draw into that array. The result, as seen in the screenshot, is that nothing gets drawn. In the third case I explicitly make a copy of the channel-flipped array (which is actually a view) before drawing, and it works.

image

Expected is that cv.circle works in all three cases.

Steps to reproduce
import cv2 as cv

image1 = np.zeros((100, 100, 3), dtype='uint8')
cv.circle(image1, (50, 50), 10, (255, 255, 255), -1)

image2 = np.zeros((100, 100, 3), dtype='uint8')
image2 = image2[:, :, ::-1]
cv.circle(image2, (50, 50), 10, (255, 255, 255), -1)

image3 = np.zeros((100, 100, 3), dtype='uint8')
image3 = np.array(image3[:, :, ::-1])
cv.circle(image3, (50, 50), 10, (255, 255, 255), -1)

imshow(image1, image2, image3)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions