I am trying to run a simple program that reads an image from OpenCV. However, I am getting this error:
error: ......\\modules\\highgui\\src\\window.cpp:281:
I got the same error on Windows. However, none of answers helps me. I realised that the issue is single backslash (\) instead of double backslashes (\\) on image path. For the difference, see the link.
Problematic scenario:
import cv2
mypath = "D:\temp\temp.png"
img = cv2.imread(mypath, 1)
cv2.imshow('test', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Traceback (most recent call last):
File "", line 1, in
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-2b5g8ysb\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
Fixed scenario:
import cv2
mypath = "D:\\temp\\temp.png"
img = cv2.imread(mypath, 1)
cv2.imshow('test', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
I hope it helps others who have similar experiences.