Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 - OpenCV & cv2.error: (-215) Unable to show captured image

Tags:

python

opencv

I am trying to using opencv-3.3.0, cv2 & python3.5.

But, I can't seem to show image I have captured.

  • I read all the documentation.
  • I tried all possible answers.
  • But, I still unsuccessful.

What am I missing?

Code:

import numpy as np
import cv2

img=cv2.imread("F:/Train/sreen.png")
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

The Error:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file D:\Build\OpenCV\opencv-3.3.0\moules\highgui\src\window.cpp, line 333 
Traceback (most recent call last):
File "F:\IQ_option\OpenCV\run.py", line 5, in <module>
    cv2.imshow('image',img)
cv2.error: D:\Build\OpenCV\opencv-3.3.0\modules\highgui\src\window.cpp:333: error: (-215) size.width>0 && size.height>0 in function cv::imshow

The image:

My Code.

like image 531
J.Doe Avatar asked Dec 05 '25 09:12

J.Doe


2 Answers

The only reason for this to not work is that the file you are trying here isn't loaded properly in the imread command. The loaded image is non existent due to which it says that size.width and size.height > 0.

You can check if either the file is present in your specified location or not. Also, you might need to use double \\ while providing the full path of the .png file you want to display. Also, it might be that .png files are not supported here. You may try any other .jpg image file instead and retry. An example would be like this:

img = cv2.imread('C:\\Users\\fakepath\\Pictures\\Messi.jpg', cv2.IMREAD_COLOR)

Worked for me.

like image 182
CodeHunter Avatar answered Dec 07 '25 22:12

CodeHunter


import os
os.environ['OPENCV_IO_MAX_IMAGE_PIXELS']=str(2**64)
import cv2 

Before importing cv2, you should set environ to solve the error. It works for me.

like image 35
user11455554 Avatar answered Dec 07 '25 23:12

user11455554



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!