0

I installed OpenCV through Homebrew on my system and installed the opencv-python module through pip.

My code:

import cv2
img = cv2.imread("image.png")
cv2.imshow("Image", img)
cv2.waitKey(0)

The error it gives:

cv2.imshow("Image", img)
cv2.error: OpenCV(4.5.0) /tmp/opencv-20201123-26930-m95s1u/opencv-4.5.0/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

If I read through the documentation or look through other resources, I'm doing the same steps. Can anyone help me out?

1 Answers1

0

This looks like normal behaviour for OpenCV. It is probably not finding an image "image.png", make sure that the path "image.png" exists and can be read. You should be able to see what cv2 finds with print(img), which should show as a numpy ndarray.

Ivo De Jong
  • 199
  • 7