Skip to content

Instantly share code, notes, and snippets.

@pydemia
Created December 7, 2017 13:48
Show Gist options
  • Save pydemia/ddff5a28aa419cbc4e6228f14ae9d5f6 to your computer and use it in GitHub Desktop.
Save pydemia/ddff5a28aa419cbc4e6228f14ae9d5f6 to your computer and use it in GitHub Desktop.
Raspberry Pi
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 7 22:40:11 2017
@author: Young Ju Kim
"""
import time, pygame, matplotlib, math
import scipy as sp
from pygame.locals import KEYDOWN
import numpy as np
from PIL import Image, ImageDraw, ImageFont
import picamera
from picamera.array import PiRGBArray
camera = picamera.PiCamera()
camera.resolution = (480,320)
video = PiRGBArray(camera, size=(480,320))
pygame.init()
screen = pygame.display.set_mode((320,480))
pygame.display.set_caption("Test")
try:
for frameBuf in camera.capture_continuous(video, format ="rgb", use_video_port=True):
frame = np.rot90(frameBuf.array)
video.truncate(0)
frame = pygame.surfarray.make_surface(frame)
screen.fill([0,0,0])
screen.blit(frame, (0,0))
pygame.display.update()
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == pygame.K_s:
camera.capture('/home/pi/workspaces/camera/a.png', format='png')
elif event.key == pygame.K_q:
raise KeyboardInterrupt
elif event.type == pygame.QUIT:
raise KeyboardInterrupt
except KeyboardInterrupt as SystemExit:
pygame.quit()
camera.close()
video.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment