I'm accessing my c310 logitech webcam in python with pygame in an attempt to take pictures and save them. My final goal is to take a new picture every minute for 24 hours to make a timelapse. Here is the code to take a single picture:
#!/usr/bin/python import os import pygame, sys import time from pygame.locals import * import pygame.camera #initialize pygame pygame.init() pygame.camera.init() cam = pygame.camera.Camera('/dev/video0') cam.start() #take a picture image = cam.get_image() x = 1 #save picture alpha = 'picture%d.jpg' % (x) pygame.image.save(image, alpha) cam.stop() pygame.quit()
My issue is that after running this code from the command prompt and then attempting to run the code again (even after waiting several seconds), I get the error:
Traceback (most recent call last): File "Picture1.py", line 13, in <module> cam.start() SystemError: Cannot open '/dev/video0': 16, Device or resource busy
I'm not sure why I get this error, as I use cam.stop() and pygame.quit() at the end of my code, so nothing should be using the camera after I run it. Everything is updated. Has anyone run into this error before?