Reputation:
I am working with opencv using python. I have problem with cv2.imshow()
. I wrote this code :
import numpy as np
import cv2
img=np.zeros((512,512),np.uint8)
img=cv2.line(img,(0,0),(511,511),(255,0,0),5)
while(True):
cv2.imshow('img',img)
if cv2.waitKey(1) & 0xFF==ord('q'):
break
I get this error :
error: (-215) size.width>0 && size.height>0 in function imshow
I have tried cv2.imshow()
without cv2.line()
it works fine.
how to solve with cv2.line()
, cv2.rectanlge()
functions ?
Upvotes: 1
Views: 79
Reputation: 15018
Looking at the docs:
Python: cv2.line(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) → None
The return type is None
, but you assign that to img
. Just use:
cv2.line(img,(0,0),(511,511),(255,0,0),5)
This is the same for all cv2
functions.
Upvotes: 2
Reputation:
You don't need to do img = cv2.line
.
The line will draw as long as you specify image in the first positional argument. Do this and see the difference.
cv2.line(img, (0, 0), (511, 511), (255, 0, 0), 5)
cv2.imshow('img', img)
Upvotes: 1