Reputation: 11
Code:
import cv2
trained_face_data = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
img = cv2.imread("rdj_1.png")#RDJ.png
cv2.imshow('', img)
cv2.waitKey()
print("Hello world!")
Error:
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-m9hy83n6\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
Upvotes: 1
Views: 2635
Reputation: 1244
error: (-215)" means that an assertion failed. In this case, cv::imshow asserts that the given image is non-empty: if the file does not exist, then cv2.imread() will return None; it does not raise an exception. Thus, the following code also results in the "(-215) size.width>0 && size.height>0" error
img = cv2.imread('no-such-file.jpg', 0)
cv2.imshow('image', img)
Check to make sure that the file actually exists at the specified path. If it does, it might be that the image is corrupted, or is an empty image.
also your code should be looking something like
img = cv2.imread('C:\\Filepathtoimage\image.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
Upvotes: 1