I am trying to draw rectangles on top of frames I record from my laptop's camera using opencv2 in python.
However, the image returned from the cv2.rectangle function is None. Why?
import numpy as np
import cv2
# details of rectangle to be drawn.
x, y, h, w = (493, 305, 125, 90)
cap = cv2.VideoCapture(0)
while 1:
ret, frame = cap.read()
if not ret or not frame:
# camera didn't give us a frame.
continue
# attempt to draw a rectangle.
img = cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
# This prints out None every time! why?
print str(img)
if not img:
continue
# We never get here since img is None. :/
cv2.imshow('img', img)
I've tried adding checks as you see for if the frame from the camera is null. I've also tried making sure that the rectangle actually fits in the frame.
I'm sure my camera's working since I can successfully imshow the frame.