Last active
August 29, 2015 14:06
-
-
Save karaage0703/eb56080374176d210c88 to your computer and use it in GitHub Desktop.
taking picture and preview program for Nakayoshi 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
#!/usr/bin/python | |
# -*0 coding: utf-8 -*- | |
import RPi.GPIO as GPIO | |
import time | |
import picamera | |
import os | |
import pygame | |
import random | |
# GPIO pin | |
LeftSh = 17 | |
RightSh = 18 | |
UpSw = 27 | |
RightSw = 22 | |
LowSw = 23 | |
LeftSw = 24 | |
RightLowSw = 10 | |
LeftLowSw = 9 | |
# GPIO setting | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(RightSh, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
GPIO.setup(LeftSh, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
GPIO.setup(UpSw, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
GPIO.setup(RightSw, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
GPIO.setup(LowSw, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
GPIO.setup(LeftSw, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
GPIO.setup(RightLowSw, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
GPIO.setup(LeftLowSw, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
pygame.init() | |
size = (pygame.display.Info().current_w, pygame.display.Info().current_h) | |
print "Framebuffer size: %d x %d" % (size[0], size[1]) | |
screen = pygame.display.set_mode(size, pygame.FULLSCREEN) | |
def screen_clear(): | |
screen.fill((0,0,0)) | |
pygame.display.update() | |
def shutter(channel): | |
print "shutter" | |
screen_clear() | |
with picamera.PiCamera() as camera: | |
camera.resolution = (1024,768) | |
camera.start_preview() | |
time.sleep(2) # initialize camera | |
camera.capture('./data/cameratest.jpg') | |
def preview(channel): | |
print "preview" | |
img = pygame.image.load("./data/cameratest.jpg").convert() | |
img = pygame.transform.scale(img, (pygame.display.Info().current_w, pygame.display.Info().current_h)) | |
#img = pygame.transform.scale(img, (656,416)) | |
screen.blit(img, (0,0)) | |
pygame.display.update() | |
GPIO.add_event_detect(RightSh, GPIO.FALLING, callback=shutter, bouncetime=300) | |
GPIO.add_event_detect(LeftSh, GPIO.FALLING, callback=preview, bouncetime=300) | |
try: | |
GPIO.wait_for_edge(UpSw, GPIO.FALLING) | |
except KeyboardInterrupt: | |
GPIO.cleanup() # clean up GPIO on CTRL+C exit | |
GPIO.cleanup() # clean up GPIO on normal exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment