0
votes

code:

import cv2

import numpy as np

from matplotlib import pyplot as plt

img = cv2.imread('test1.jpg',cv2.IMREAD_GRAYSCALE)

cv2.imshow('image',img)

cv2.waitKey(0)

cv2.destroyAllWindows()

error:

Traceback (most recent call last): File "C:\Users\user\Desktop\folder\python file", line 6, in cv2.imshow('image',img)

cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-h4wtvo23\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

2
There is not an image called test1.jpg in the directory in which your program is running.Mark Setchell

2 Answers

1
votes

Seems like your the path to the image does not exist or is corrupted (empty). Probably the former. Make sure you set the correct path to the image test1.jpg either by making sure that the path is set correctly from the directory you are running the program from, or using the absolute path.

1
votes

I had similar problem when working with opencv in c++, the problem was solved when I used the full path to both the model and the image. Do this to make sure that the path is indeed the problem. If so, I recommend using pathlib package to manage paths in your code, it'll help avoid path issues in the future.