-
Notifications
You must be signed in to change notification settings - Fork 0
/
photoBoothWorking.py
executable file
·196 lines (171 loc) · 5 KB
/
photoBoothWorking.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
#!/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 threading
# x and y Resolution of photo
xPhotoResolution = 1120
yPhotoResolution = 750
#Camera Setup
camera = picamera.PiCamera()
camera.resolution = (xPhotoResolution,yPhotoResolution)
camera.vflip = True
camera.hflip = True
#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
camera.start_preview()
camera.preview.fullscreen = True
camera.preview_alpha = 100
#Printer init
conn = cups.Connection()
#counter init here, because, whatever.
counter = 4
#pygame Setup
pygame.mixer.pre_init(44100,-16,2,2048)
pygame.init()
pygame.mixer.music.load('shutter.mp3')
fpsClock = pygame.time.Clock()
window = pygame.display.set_mode((xPhotoResolution, yPhotoResolution))
pygame.display.set_caption('Paul and Jess 11.15.2014!')
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()
countDown = countDown -1
time.sleep(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():
print('button pressed!')
now = time.time()
counter = 4
photoTaken = 1
while counter > 0:
#stream = io.BytesIO()
#Countdown timer, etc.
startCountdown(photoTaken)
#capture photo
filename = 'img%s.png' % (counter)
start = time.time()
camera.capture(filename, format='png', use_video_port=True)
pygame.mixer.music.play()
print('Capture took %.2fs' % (time.time()-start))
#stream.seek(0)
#photos.append(Image.open(stream))
#stream.seek(0)
#stream.truncate()
#pygame.mixer.music.play()
print('picture taken! %s of 4') % photoTaken
counter = counter - 1
photoTaken = photoTaken +1
compileMessage()
tile_images_wrapper()
print('done with button press, %s sec'%(time.time()-now))
def tile_images_wrapper():
print('launching thinger that does the montage')
now = time.time()
manually_arrange()
print('Montage thing done! %s'%(time.time()-now))
def manually_arrange():
#print('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)
print('made new image')
img = Image.open('img4.png')
inew.paste(img,first)
print('pasted')
img = Image.open('img3.png')#.resize((560,375))
inew.paste(img,second)
print('pasted')
img = Image.open('img2.png')#.resize((560,375))
inew.paste(img,third)
print('pasted')
img = Image.open('img1.png')#.resize((560,375))
inew.paste(img,fourth)
print('pasted')
img = Image.open('photoboothwedding.png')
#img = Image.open('photoboothhalloween.png')
inew.paste(img,label)
print('pasted')
start = time.time()
fileName = './archive/%s.tiff' % (timestamp())
inew.save(fileName)
print('SAVE took %.2fs' % (time.time()-start))
start = time.time()
conn.printFile('EPSON_PictureMate_PM_225', fileName, 'test',{})
print('Send took %.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)