Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV error: (-215:Assertion failed), read and display an image

Hey everyone,

previously I was able to use the OpenCV but after I did system restore, I am not able to use it anymore. I have Ubuntu 18.04 installed on WSL and working on ROS. There are two versions of OpenCV installed:

  1. 4.3.0-dev (when I check the version via python: >>>print cv2.__version__)
  2. 3.2.0 (this is when I check with: $ pkg-config --modversion opencv)

when I run this:

$ rosrun read_image show_image.py

I get this error:

read an image from file
create a window holder for the image
display the image
Traceback (most recent call last):
  File "/home/candas/catkin_ws/src/read_image/src/show_image.py", line 17, in <module>
    cv2.imshow("Image",img) # show the image, name of the display
cv2.error: OpenCV(4.3.0-dev) /home/candas/opencv_build/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

The code I am trying to run is to read and display the image:

#!/usr/bin/env python

#import numpy: the data structure that will handle an image
import numpy as np # stores all the pixels of image

#import openCV
import cv2

print 'read an image from file'
img = cv2.imread("images/apple-touch-icon-144x144-precomposed.png") 

print 'create a window holder for the image'
cv2.namedWindow("Image",cv2.WINDOW_NORMAL) # name of the window, resize

print 'display the image'
cv2.imshow("Image",img) # show the image, name of the display

Is it because, there are different versions installed? Or the way I define the path? Or CMakeLists.txt? I would be glad if you could help. Thanks

OpenCV error: (-215:Assertion failed), read and display an image

Hey everyone,

previously I was able to use the OpenCV but after I did system restore, I am not able to use it anymore. I have Ubuntu 18.04 installed on WSL and working on ROS. There are two versions of OpenCV installed:

  1. 4.3.0-dev (when I check the version via python: >>>print cv2.__version__)
  2. 3.2.0 (this is when I check with: $ pkg-config --modversion opencv)

when I run this:

$ rosrun read_image show_image.py

I get this error:

read an image from file
create a window holder for the image
display the image
Traceback (most recent call last):
  File "/home/candas/catkin_ws/src/read_image/src/show_image.py", line 17, in <module>
    cv2.imshow("Image",img) # show the image, name of the display
cv2.error: OpenCV(4.3.0-dev) /home/candas/opencv_build/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

The code I am trying to run is to read and display the image:

#!/usr/bin/env python

#import numpy: the data structure that will handle an image
import numpy as np # stores all the pixels of image

#import openCV
import cv2

print 'read an image from file'
img = cv2.imread("images/apple-touch-icon-144x144-precomposed.png") 

print 'create a window holder for the image'
cv2.namedWindow("Image",cv2.WINDOW_NORMAL) # name of the window, resize

print 'display the image'
cv2.imshow("Image",img) # show the image, name of the display

Is it because, there are different versions installed? Or the way I define the path? Or CMakeLists.txt? I would be glad if you could help. Thanks