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

np.rot90() and cv2.line() doesn't seem to work together #1057

Open
4 tasks done
FrickTobias opened this issue Dec 6, 2024 · 0 comments
Open
4 tasks done

np.rot90() and cv2.line() doesn't seem to work together #1057

FrickTobias opened this issue Dec 6, 2024 · 0 comments

Comments

@FrickTobias
Copy link

FrickTobias commented Dec 6, 2024

Expected behaviour

cv2.line() should work on what np.rot90() returns (np arrays with np.uint8 dtype).

Actual behaviour

After rotating images with np.rot90() cv2.line() raises an error, claiming the array is not compatible.

Steps to reproduce

  • example code
import numpy as np
import cv2

img = np.zeros((10, 10), dtype=np.uint8)

img_rot = np.rot90(img)

img_line = cv2.line(img, (0, 0), (9, 9), 255, 2)

cv2.line(img_rot, (0, 0), (9, 9), 255, 2)
  • error
Traceback (most recent call last):
  File "cv2bug.py", line 10, in <module>
    cv2.line(img_rot, (0, 0), (9, 9), 255, 2)
cv2.error: OpenCV(4.10.0) :-1: error: (-5:Bad argument) in function 'line'
> Overload resolution failed:
>  - Layout of the output array img is incompatible with cv::Mat
>  - Expected Ptr<cv::UMat> for argument 'img'```
  • operating system
sw_vers
ProductName:		macOS
ProductVersion:		15.1
BuildVersion:		24B83
  • architecture (e.g. x86)
uname -m
x86_64
pip show opencv-python numpy

Name: opencv-python
Version: 4.10.0.84
Summary: Wrapper package for OpenCV python bindings.
Home-page: https://github.com/opencv/opencv-python
<...>

Name: numpy
Version: 2.0.2
Summary: Fundamental package for array computing in Python
Home-page: https://numpy.org
<...>
  • other info

I tested some other cv2 drawing functions and get the same result (for example cv2.circle())

I also tested numpy 1.26.1 and got the same result.

I have double checked cv2.rot90() doesn't change the dtype of the array

print(f"{img_rot.dtype = }") # output: img_rot.dtype = dtype('uint8')

Arguably this could be an issue with np.rot90(). However, since other cv2 functions works like normal my initial guess was to start here. For instance, image can be displayed, saved and loaded.

cv2.imshow("img_rot", img_rot)
cv2.imwrite("imgrot.png", img_rot)
img_rot = cv2.imread("imgrot.png")

Lastly, I've noted that if the image is saved and loaded, it works as expected.

import numpy as np
import cv2

img = np.zeros((10, 10), dtype=np.uint8)

img_rot = np.rot90(img)

img_line = cv2.line(img, (0, 0), (9, 9), 255, 2)

cv2.imwrite("imgrot.png", img_rot)
img_rot = cv2.imread("imgrot.png")

cv2.line(img_rot, (0, 0), (9, 9), 255, 2) # No error
Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • I'm using the latest version of opencv-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant