Created
April 26, 2018 10:19
-
-
Save rmohta/52096f7642a505d30b0ac68d48b3c956 to your computer and use it in GitHub Desktop.
Capture image from Camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import pygame.camera | |
from pygame.locals import * | |
import pygame.image | |
# pip install Pygame | |
def list_cameras(): | |
camlist = pygame.camera.list_cameras() | |
if camlist: | |
for acam in camlist: | |
print ('Available Camera: ' + acam) | |
return camlist[0] | |
def capture_image(cam_location): | |
cam = pygame.camera.Camera(cam_location,(640, 480)) | |
cam.start() | |
image = cam.get_image() | |
pygame.image.save(image, "/var/tmp/image.JPG") | |
def main(): | |
# As the camera module is optional, import it | |
# and initialize it manually. | |
#pygame.init() | |
pygame.camera.init() | |
cameraLocation = list_cameras() | |
capture_image(cameraLocation) | |
pygame.camera.quit() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment