How to programmatically capture a webcam photo

前端 未结 2 1460
-上瘾入骨i
-上瘾入骨i 2021-01-30 18:40

What\'s the simplest way in Ubuntu 11.10 to programmatically guide (either from Bash or Python) the user to capture a webcam photo of themselves?

I can launch a simple a

2条回答
  •  后悔当初
    2021-01-30 19:04

    I like using pygame for that - it does not require you to open a Pygame SDL window, unlike when you want to use it to capture keyboard events, for example.

    import pygame.camera
    pygame.camera.init()
    cam = pygame.camera.Camera(pygame.camera.list_cameras()[0])
    cam.start()
    img = cam.get_image()
    import pygame.image
    pygame.image.save(img, "photo.bmp")
    pygame.camera.quit()
    

    Though Pygame will only save uncompressed "bmp" files - you may want to combine it with PIL to write to other formats.

提交回复
热议问题