error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘imshow’

I wanted to try OpenCV in python, so I thought I’d start with a simple image display… so I set up a simple script, but I immediately got an error.

「error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘imshow’」

The script I ran (test.py) is as follows. It is very simple.

import cv2
bgr = cv2.imread('/home/malt/fruits.jpg')

cv2.imshow("image", bgr)
cv2.waitKey()

A quick google search revealed that the error occurred in line 4, imshow, as shown, but the image may not have been read in line 2, the first step.
The images for this sample were taken from a website, but I made a mistake here.



https://github.com/opencv/opencv/blob/master/samples/data/fruits.jpg

I used wget to get it from the above, and the actual image file uri was the following.

https://raw.githubusercontent.com/opencv/opencv/master/samples/data/fruits.jpg

It was a mistake.
When I checked the first file I got, I found that it could not be opened as an image, so I used wget to get it again and ran the above script.
This time, the image was displayed correctly.
By the way, this sample script has “waitKey()” at the end, so if you activate the window with the image shown below and press any key, the script will exit.