Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behavior for Mat.from_array() #20

Open
huckw opened this issue Oct 23, 2019 · 1 comment
Open

Weird behavior for Mat.from_array() #20

huckw opened this issue Oct 23, 2019 · 1 comment
Labels

Comments

@huckw
Copy link

huckw commented Oct 23, 2019

Attached is an image that is acting very strange...

I=cv2.imread("path/to/hbl.png")[:,:,0]
I1 = np.array(mylib.Mat.from_array(I))
I2 = np.array(mylib.Mat.from_array(I.astype(np.uint8)))

I1 is all messed up but I2 works as expected. I's dtype is already np.uint8 so I don't know what the magic is with the asytpe() converting it to the same datatype.

Any idea what I might be doing incorrectly?

hbl

@renatoGarcia
Copy link
Owner

Good catch! Thanks!

When you do A = cv2.imread("path/to/hbl.png") A will be a (200, 200, 3) image.
when you do I=cv2.imread("path/to/hbl.png")[:,:,0] I will be a view of shape (200, 200) over the same underlaying memory as A. You can see that doing A.strides and I.strides, I1.strides, I2.strides.

What I3 = I.astype(np.uint8) is doing is creating a new (200, 200) buffer and copying the I data. Hence now the I3 memory is continuous and has the same strides as I2.

The bug lies at the function from_array doing the assumption that the array memory is continous.

Repository owner deleted a comment from 0vz-llu Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants