Error when trying to display image via OpenCV

What i’m trying to do with this is to display only the blue present in this image

import glob
import cv2
import numpy as np

boundaryh = np.array([[[76,40,0]]])
boundaryl = np.array([[[124,64,0]]])
images = np.array([cv2.imread(file) for file in glob.glob('C:\\Users\\Usuario\\Desktop\\IMG_HERE\\*.jpg')])
bmask = cv2.inRange(images,boundaryl,boundaryh)
dout = cv2.bitwise_and(images,images,bmask)
print("works")
cv2.imshow("bluedetector",dout)
cv2.waitKey(0)

When this code is executed it returns this error. I found a similar question but it doesn’t answer my issue

Traceback (most recent call last):
  File "C:\Users\Usuario\PycharmProjects\pythonProject\main.py", line 11, in <module>
    cv2.imshow("bluedetector",dout)
cv2.error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window_w32.cpp:124: error: (-215:Assertion failed) bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32) in function 'FillBitmapInfo'

  • 1

    Does this answer your question? Why does cv2.imshow() result in error in Python?

    – 

  • sort of? I checked other examples and it should output dout correctly without the path.

    – 

  • You’re not checking if imread succeeds. It returns None when it fails. And when you pass that None into imshow you get that exact error message.

    – 

Leave a Comment