Hi, I've been reading tutorials and I'm trying to detect rectangles from my webcam using OpenCV.
When I run this code, I see white specs on parts of the screen for a few frames. These white areas flicker in a familiar pattern to what I've seen image recognition do. Within 2 seconds the screen is entirely black.
Why is this happening? I'm trying to detect rectangles on the screen. Thanks!
```
import numpy as np
import
cv2 cv2
cap =
cv2.VideoCapture(0) cv2.VideoCapture(0)
while(True):
ret, img =
cap.read()
cap.read()
# Do image processing here, using img
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
contours,h = cv2.findContours(img,1,2)
for cnt in contours:
approx = cv2.approxPolyDP(cnt,0.01*cv2.arcLength(cnt,True),True)
print len(approx)
if len(approx)==4:
cv2.drawContours(img,[cnt],0,(0,0,255, 0.1),-1)
# Display the resulting frame
cv2.imshow('img',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the
capture capture
cap.release()
cv2.destroyAllWindows()
```