Skip to content

Instantly share code, notes, and snippets.

@Starbuck5
Last active April 12, 2022 19:58
Show Gist options
  • Save Starbuck5/7cc985d99b85da5c975d5c649e00748b to your computer and use it in GitHub Desktop.
Save Starbuck5/7cc985d99b85da5c975d5c649e00748b to your computer and use it in GitHub Desktop.
Simple mirror using pygame.camera
import pygame
import pygame.camera
pygame.init()
pygame.camera.init()
desired_size = (1280, 720)
cameras = pygame.camera.list_cameras()
cam = pygame.camera.Camera(cameras[0], desired_size)
cam.set_controls(hflip=True)
cam.start()
width, height = cam.get_size()
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Mirror")
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
running = False
if cam.query_image():
screen.blit(cam.get_image(), (0,0))
pygame.display.flip()
clock.tick(144)
cam.stop()
pygame.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment