0
votes

I am getting an error while running the following code.

import cv2
import numpy as np
img = cv2.imread('messi.jpg',0)
img = cv2.line(img,(0,0),(50,50),(255,0,0),5)
cv2.imshow("image",img)
cv2.waitKey(0)
cv2.destroyAllWindows()

The error says:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in unknown function, file ......\src\opencv\modules\highgui\src\window.cpp, line 261

Traceback (most recent call last):

File "F:\Computer programming\scripts\OpenCv\1.py", line 6, in cv2.imshow("image",img) cv2.error: ......\src\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0

If I remove the line:

img = cv2.line(img,(0,0),(50,50),(255,0,0),5)

the script works.

1

1 Answers

4
votes

Its because cv2.line returns None and you are assigning that to your img variable. So when you get to the next line and try to show the image, there is no image to be shown.

Replace img = cv2.line(img,(0,0),(50,50),(255,0,0),5) with cv2.line(img,(0,0),(50,50),(255,0,0),5)

Read more about cv2.circle here.