2
votes

I just don't seem to get this small piece of code to work. I searched a lot for this error, but usually it had different reasons. The error is only related to cv2.rectangle, because commenting this out solves the problem and the image is normally shown. I first thought it had to do something with my cv2, but if this was the case cv2.imread wouldn't work either right?

Any insights is greatly appreciated :)

import numpy as np
import cv2

img = cv2.imread('some-pic.jpg')

#This line gives the error, no problems when commented
img = cv2.rectangle(img, (3, 3), (5, 5), (255,0,0))

cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Error

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20140819-1745/modules/highgui/src/window.cpp, line 261 Traceback (most recent call last): File "face-detect-simple.py", line 9, in cv2.imshow('img',img) cv2.error: /tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20140819-1745/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

Specs

Ubuntu 12.04.5 LTS

OpenCV 2.4.9

Python 2.7.3

2

2 Answers

3
votes

as of 2.4.9 , cv2.rectangle does not return anything. you probably got that from tutorials about upcoming opencv3.0

1
votes

Just remove the "img =" portion while drawing the rectangle. It has to do with the version of openCV.