Error: OpenCV(4.11.0) 👎 error: (-5:Bad argument) in function 'imshow'

I’m interested in image processing with python. I use macbook air M2 macos sequoia 15.4. I’m developing python code on anaconda spyder ide. I keep getting the following error:

error: OpenCV(4.11.0) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
>  - mat is not a numpy array, neither a scalar
>  - Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
>  - Expected Ptr<cv::UMat> for argument 'mat'

My code is as follows:

import cv2
import numpy as np

img = np.zeros((512, 512, 3), np.uint8)
cv2.imshow("original_image", img)

cv2.waitKey(0) 
cv2.destroyAllWindows()

Although it gives an error in the numpy array, it does not give an error when I read an image from outside.
I checked all the values ​​of the data type and they are theoretically compatible but opencv gives an incompatibility error. Also this code is working on windows machine. And also I try to run this code diffirent ide, but I take same error, unfortunately.
How can I solve this problem?

that code cannot have caused that exception.

please review.

Thanks for your interest,
As seen in the image, it gives an error like this. However, after writing here, I did some more research and discovered that it was related to the version of opencv for some reason. I am currently using the current version of opencv. When I downgrade to version 4.10, the problem is fixed. I think there was an update to the input sent to opencv in version 4.11 and it especially affects Linux-based systems. The question is, how should we adjust the array inputs created with numpy in Linux-based systems in the current version?

1 Like

alright… that is puzzling.

I’m unfortunately not in a position to try to repro this on anything close to your system.

that code should have worked flawlessly, on linux, on windows, and on macos. if anything like this were encountered by anyone else, linux having a much greater market share than macos… I think those people would have asked about it on Stack Overflow, but I didn’t see any of that. I strongly doubt this has anything to do with linux. likely it’s a macos/M2 issue.

if this really works on 4.10 but not on 4.11, you should file an issue on opencv’s github (I didn’t see any existing issues that fit). if you open an issue, you should link to this forum thread for context.

if you can try this on a slightly different setup, that’d be great. maybe it’ll fare better on standard python (not anaconda). maybe not. maybe spyder has an effect (try in a plain terminal). maybe not. either way, that’s useful info to have.

I have got this error problem too. I use Window 11 and opencv in version 4.11.0.86
I would like to know how to install opencv in version by select vesion or downgrade.
I use pip install that they install only last version only (4.11.0.86).


Okay i already install opencv in 4.10.0.82 . but It 'still error when import numpy (2.2.4 )


I try opencv in each vesion, This error will happen when i use opencv over version 4.10.0.82
(It’s begin at 4.10.0.84)

a few minutes ago I’ve installed Python for the first time in my life, this script is one of of the first python scripts that I’ve tried but it seems to be working

OS: Windows10
Python 3.13
numpy: 2.2.4 (installed with “pip install numpy”)
opencv: 4.11.0, built with cudawarp’s Build OpenCV (including Python) with CUDA on Windows guide

I don’t know the exact version of my opencv but the files inside opencv-4.11.0.zip are dated to 08.01.2025