-
Notifications
You must be signed in to change notification settings - Fork 0
/
shutter.py
executable file
·164 lines (152 loc) · 4.12 KB
/
shutter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/python
# graphicsmagick
# python-game
#sudo python-dev python-pip ; sudo pip install wiringpi2
import picamera
import time
from time import sleep
import os
import subprocess
import pygame
import random
import RPi.GPIO as GPIO
import wiringpi2 as wiringpi
import pifacedigitalio as p
p.init()
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(25, 1)
wiringpi.pinMode(24, 1)
wiringpi.pinMode(22, 1)
camera = picamera.PiCamera()
WIDTH=800
HEIGHT=600
def dotext(countdown,FONTSIZE,LEFT):
screen.fill(black)
text = countdown
font = pygame.font.Font('freesansbold.ttf', FONTSIZE)
font_surf = font.render(text, True, textcol)
font_rect = font_surf.get_rect()
font_rect.left = LEFT
font_rect.top = 150
screen.blit(font_surf, font_rect)
camera.preview_alpha = 200
pygame.display.update()
# INIT CAMERA
def initcamera():
# camera = picamera.PiCamera()
camera.vflip = False
camera.hflip = False
camera.brightness = 60
camera.led = False
camera.image_effect = 'none'
camera.start_preview()
def changeeffect(EFFECT):
# camera = picamera.PiCamera()
#camera.stop_preview()
camera.stop_preview()
# camera.close()
# sleep(2)
# camera.vflip = True
# camera.hflip = False
# camera.brightness = 60
# camera.led = False
camera.image_effect = EFFECT
camera.start_preview()
effects = ['solarize','oilpaint','hatch','gpen','pastel','washedout','posterise','negative','sketch','emboss','colorswap','cartoon','none']
effectnumber = 0
initcamera()
# BUILD A SCREEN
pygame.init()
pygame.mouse.set_visible(0)
screen = pygame.display.set_mode((WIDTH,HEIGHT))
black = pygame.Color(0, 0, 0)
textcol = pygame.Color(255, 255, 255)
#screen.fill(black)
p.digital_write(3,1) #turn on
p.digital_write(4,1) #turn on
while True:
# my_input = wiringpi.digitalRead(25)
my_input = p.digital_read(0)
effect = p.digital_read(1)
# shutoff = wiringpi.digitalRead(24)
shutoff = p.digital_read(2)
# effect = wiringpi.digitalRead(22)
if shutoff == 1:
# restart = "service shutterpi stop"
# subprocess.call(restart)
pygame.quit()
break
if effect == 1:
effect = effects[effectnumber]
effectnumber = (effectnumber + 1) % len(effects)
# dotext('', 150, 150)
changeeffect(effect)
dotext(effect, 100, 150)
sleep(1)
dotext('', 150, 150)
if my_input == 1:
p.digital_write(3,0) #turn off
p.digital_write(4,0) #turn off
count=0
while (count < 4):
camera.start_preview()
# TAKE A PHOTO
now = time.strftime("%Y%m%d%H%M%S")
name=now + ".jpg"
sleep(1)
dotext('Ready..', 150, 150)
sleep(1)
dotext('3', 300, 300)
sleep(1)
dotext('2', 300, 300)
sleep(1)
dotext('1', 300, 300)
sleep(1)
dotext('Smile :)', 150, 150)
sleep(1)
dotext('', 200, 200)
p.digital_write(0,1)
p.digital_write(1,1)
sleep(0.1)
p.digital_write(0,0)
p.digital_write(1,0)
playsound = "/usr/bin/play /home/pi/camera-shutter.oga &"
#os.system(playsound)
subprocess.call(playsound,shell=True)
#sleep(.5)
camera.capture(name, format='jpeg', resize=(WIDTH,HEIGHT))
p.digital_write(0,1)
p.digital_write(1,1)
sleep(0.1)
p.digital_write(0,0)
p.digital_write(1,0)
#camera.stop_preview()
#READ IMAGE AND PUT ON SCREEN
#img = pygame.image.load(name)
#screen.blit(img, (0, 0))
#pygame.display.update()
makeborder = "gm convert " + name + " -border 8x2 new-" + name
os.system(makeborder)
# WAIT A BIT
#sleep(1)
count+=1
# camera.start_preview()
# CEATE PHOTOBOOTH STRIPS OF PHOTOS
dotext('thinking..', 150, 100)
singlestrip = "gm convert $(ls new*.jpg) -append singlestrip.jpg"
os.system(singlestrip)
doublestrip = "gm convert singlestrip.jpg singlestrip.jpg +append strip-" + now + ".jpg"
os.system(doublestrip)
# DELETE TEMPORARY FILES
cleanup = "rm new*.jpg *strip.jpg"
os.system(cleanup)
dotext('printing..', 150, 100)
printing = "lp"
#os.system(printing)
dotext('', 150, 150)
changeeffect('none')
p.digital_write(3,1) #turn on
p.digital_write(4,1) #turn on
# CLOSE CLEANLY AND EXIT
sleep(0.5)
# pygame.quit()