Assertion failure : size.width0 && size.height0 in function imshow
The image fails to load (probably because you forgot the leading /
in the path). imread
then returns None. Passing None
to imshow
causes it to try to create a window of size 0x0, which fails.
The poor error handling in cv
probably owes to its quite thin wrapper layer on the C++ implementation (where returning NULL on error is a common practice).
OpenCV(4.2.0) error: (-215:Assertion failed) size.width0 && size.height0 in function 'cv::imshow'
Basically, this error tells you that you are trying to show an empty / non existent image. Please do check:
- The path: I think the problem comes from
cv2.imread()
. If the path is incorrect, theimg
variable will be empty.
The way you tried to read the image is almost right:
img = cv2.imread(C:\Users\someone\Documents\python\____The Useless Installer____\PY\colorpic)
The way it should be:
- double backslash for escaping the
"\"
character which has a special meaning in programming languages - you do need to enter the format of the picture (
jpeg
,png
, etc..). - you need to pass this argument as a
'string'
or"string"
Therefore try img = cv2.imread("C:\\Users\\someone\\Documents\\python\\____The Useless Installer____\\PY\\colorpic.jpg")
Related Topics
How to Plot Nan Values as a Special Color with Imshow in Matplotlib
What Is the Most Pythonic Way to Check If an Object Is a Number
How to Install Python 3.X and 2.X on the Same Windows Computer
Python: Platform Independent Way to Modify Path Environment Variable
How Does the Key Argument in Python's Sorted Function Work
How to Terminate a Thread When Main Program Ends
How to Get the Largest Integer One Can Use in Python
How to Get Item's Position in a List
Calculating Difference Between Two Rows in Python/Pandas
Is There a Clever Way to Pass the Key to Defaultdict's Default_Factory
Underscore VS Double Underscore with Variables and Methods
Python - Add Pythonpath During Command Line Module Run
How to Include Related Model Fields Using Django Rest Framework
Python Read JSON File and Modify
How to Move Pandas Data from Index to Column After Multiple Groupby
What's the Difference Between _Builtin_ and _Builtins_