Ask Your Question

Hazha's profile - activity

2019-08-27 13:59:00 -0600 received badge  Popular Question (source)
2014-05-04 14:57:57 -0600 received badge  Editor (source)
2014-05-04 11:14:09 -0600 asked a question webcam gives me black screen

Hi guys,

I am writing a program in Python which takes images in a While loop and saves it to disk. When I run it, a small window pops up which shows nothing, but a gray color.

-I did restart my PC after checking it was enabled from Device Manager.

Here is the code:

from cv2 import * from PIL import Image

while True: imageFile = "image.jpg"

# turn on the webcam
cam = VideoCapture()    
# grab an image from the camera
retval, image = cam.read()
#return a True bolean and the image if all go right
namedWindow("IMG_WIN", CV_WINDOW_AUTOSIZE)
imshow("IMG_WIN", image)  #show the image  
image.save("Desktop\Pictures" +imageFile) #save the image on disk
time.sleep(6)     #give 6 seconds before the loop goes around again

cam.release() #Closes video file or capturing device.