-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotoBooth.py
executable file
·211 lines (188 loc) · 5.79 KB
/
photoBooth.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/python
from PIL import Image
import io
import os
import picamera
import time
import RPi.GPIO as GPIO
import pygame
from pygame.locals import *
import sys
import cups
import syslog
syslog.syslog('Starting Photobooth')
#force audio out headphone jack
os.system("amixer cset numid=3 1")
# x and y Resolution of photo
xPhotoResolution = 1120
#xPhotoResolution = 1120
yPhotoResolution = 750
#yPhotoResolution = 750
#Camera Setup
camera = picamera.PiCamera()
camera.resolution = (xPhotoResolution,yPhotoResolution)
camera.vflip = True
camera.hflip = False
#Pin setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN)
GPIO.setup(22,GPIO.OUT)
GPIO.output(22,1)
input = GPIO.input(17)
prev_input = 1
#counter = 0
#Camera Start
syslog.syslog('start preview')
camera.start_preview()
camera.preview.fullscreen = True
camera.preview_alpha = 100
#Printer init
syslog.syslog('start cups connection')
conn = cups.Connection()
conn.enablePrinter('EPSON_PictureMate_PM_225')
syslog.syslog('enable printer')
#counter init here, because, whatever.
counter = 4
#pygame Setup
pygame.init()
window = pygame.display.set_mode((xPhotoResolution, yPhotoResolution))
pygame.display.set_caption('Greg and Megan!')
background = pygame.Surface(window.get_size())
background.fill((0,0,0))
font = pygame.font.Font(None,700)
messageFont = pygame.font.Font(None,200)
countFont = pygame.font.Font(None,80)
#Methods Start here:
def timestamp():
return format('%s-%s %s:%s:%s') % (time.localtime()[1],time.localtime()[2],time.localtime()[3],time.localtime()[4],time.localtime()[5])
#Pygame Counter
def startCountdown(photoCount):
countDown = 5
while countDown > 0:
if(countDown == 1):
message = ':)'
else:
message = countDown -1
background = pygame.Surface(window.get_size())
text = font.render(str(message),1,(255,255,255))
photosRemain = '%s / 4' % (photoCount)
photoCountbox = countFont.render(str(photosRemain),1,(0,255,0))
msgRectObj = photoCountbox.get_rect()
msgRectObj.topleft = (10,20)
xPos = (xPhotoResolution // 2 ) - (text.get_width()//2)
yPos = (yPhotoResolution // 2 ) - (text.get_height()//2)
background.blit(text, (xPos,yPos))
background.blit(photoCountbox, msgRectObj)
window.blit(background, (0,0))
pygame.display.flip()
if countDown == 1:
return
else:
time.sleep(1.5)
countDown = countDown -1
def compileMessage():
message = 'Please wait...'
background = pygame.Surface(window.get_size())
text = messageFont.render(str(message),1,(255,255,255))
xPos = (xPhotoResolution // 2 ) - (text.get_width()//2)
yPos = (yPhotoResolution // 2 ) - (text.get_height()//2)
background.blit(text, (xPos,yPos))
window.blit(background, (0,0))
pygame.display.flip()
def blackScreen():
background = pygame.Surface(window.get_size())
background.fill((0,0,0))
window.blit(background,(0,0))
pygame.display.flip()
def buttonPressed():
syslog.syslog('button pressed!')
now = time.time()
counter = 4
photoTaken = 1
while counter > 0:
#Countdown timer, etc.
startCountdown(photoTaken)
#capture photo
filename = 'img%s.jpg' % (counter)
start = time.time()
camera.capture(filename, use_video_port=True)
os.system("aplay -f S24_LE camera-shutter-click-03.wav")
syslog.syslog('Capture took '+ str('%.2fs' % (time.time()-start)))
counter = counter - 1
photoTaken = photoTaken +1
compileMessage()
tile_images_wrapper()
print('done with button press, %s sec'%(time.time()-now))
def tile_images_wrapper():
syslog.syslog('launching thinger that does the montage')
now = time.time()
manually_arrange()
syslog.syslog('Montage thing done! '+str('%s'%(time.time()-now)))
def manually_arrange():
syslog.syslog('inside manually arrange')
isize = (1200,3600)
first = (40,40,1160,790)
second = (40,830,1160,1580)
third = (40,1620,1160,2370)
fourth = (40,2409,1160,3159)
label = (40,3199,1160,3560)
white = (255,255,255)
inew = Image.new('RGB',isize,white)
syslog.syslog('open img4')
img4time = time.time()
img = Image.open('img4.jpg')
inew.paste(img,first)
syslog.syslog('pasted img4 in' +str('%.2fs'% (time.time()-img4time)))
#print('pasted')
img3time = time.time()
img = Image.open('img3.jpg')
inew.paste(img,second)
syslog.syslog('pasted img3 in' +str('%.2fs'% (time.time()-img3time)))
#print('pasted')
img2time = time.time()
img = Image.open('img2.jpg')
inew.paste(img,third)
syslog.syslog('pasted img2 in' +str('%.2fs'% (time.time()-img2time)))
#print('pasted')
img1time = time.time()
img = Image.open('img1.jpg')
inew.paste(img,fourth)
syslog.syslog('pasted img1 in' +str('%.2fs'% (time.time()-img1time)))
#print('pasted')
imgLabeltime = time.time()
#img = Image.open('photobooth-04.png')
#img = Image.open('photoboothwedding.png')
#img = Image.open('photoboothhalloween.png')
#img = Image.open('SBHoliday2017-01.png')
syslog.syslog('attempting open banner')
img = Image.open('GreganPhotobooth-02.png')
syslog.syslog('opened photo, attempting paste label')
inew.paste(img,label)
syslog.syslog('Pasted Label'+str('%.2fs' %(time.time()-imgLabeltime)))
start = time.time()
fileName = './archive/%s.tiff' % (timestamp())
inew.save(fileName)
syslog.syslog('Save took '+str('%.2fs' % (time.time()-start)))
start = time.time()
job_id = conn.printFile('EPSON_PictureMate_PM_225', fileName, 'test',{})
syslog.syslog('job_id: '+ str(job_id))
syslog.syslog('Send took '+ str('%.2fs' % (time.time()-start)))
#MAIN
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
GPIO.output(22,0)
sys.exit()
input = GPIO.input(17)
if ((not prev_input) and input):
GPIO.output(22,0)
buttonPressed()
blackScreen()
GPIO.output(22,1)
prev_input = input
time.sleep(0.05)