-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPi Camera
188 lines (161 loc) · 5.1 KB
/
Pi Camera
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
import time, picamera, pygame
from pygame.locals import *
from tkinter import *
def take_picture():
#opens the camera and takes the picture a a resolutuion of 800 by 600.
#saves it as image.jpg
global name
with picamera.PiCamera() as camera:
name = name_()
angle = angle_()
camera.rotation = angle
camera.start_preview()
time.sleep(5)
camera.resolution = (int(x), int(y))
camera.capture('/home/pi/Desktop/' + name + '.jpg')
camera.stop_preview()
def timelaspe():
global name
with picamera.PiCamera() as camera:
name = name_()
angle = angle_()
time_ = int(input("How long of a pause would you like between images? "))
ammount = int(input("How many images would you like to take? "))
camera.rotation = angle
count = 0
for i in range(ammount):
camera.start_preview()
time.sleep(time_)
camera.resolution = (int(x), int(y))
camera.capture('/home/pi/Desktop/' + name + str(count) + '.jpg')
count += 1
camera.stop_preview()
def open_image():
#opens a pygame window and pastes the image onto it
pygame.display.init
background_image = pygame.image.load(name + ".jpg")
screen = pygame.display.set_mode((int(x), int(y)))
screen.blit(background_image,(0,0))
pygame.display.flip()
def close_image():
#closes the pygame window
pygame.quit()
def display_timelaspe():
pygame.display.init
loop = True
count = 0
try:
while loop:
count += 1
background_image = pygame.image.load(name + str(count) + ".jpg")
screen = pygame.display.set_mode((int(x), int(y)))
screen.blit(background_image,(0,0))
pygame.display.flip()
time.sleep(0.2)
except:
pygame.quit()
def image_size_button():
global size
root = Tk()
class Application(Frame):
def small_(self):
global size
size = "400 by 200"
root.quit()
Frame.destroy(self)
def large_(self):
global size
size = "1000 by 700"
root.quit()
Frame.destroy(self)
def medium_(self):
global size
size = "800 by 600"
root.quit()
Frame.destroy(self)
def createwidgets(self):
#set frame with the button on it
self.small = Button(self)
self.small["text"] = "Small",
self.small["command"] = self.small_
self.small.pack({"side": "left"})
self.medium = Button(self)
self.medium["text"] = "Medium"
self.medium["command"] = self.medium_
self.medium.pack({"side": "left"})
self.large = Button(self)
self.large["text"] = "large",
self.large["command"] = self.large_
self.large.pack({"side": "left"})
def __init__(self, master=None):
#assembley the frame
Frame.__init__(self, master)
self.pack()
self.createwidgets()
def choose():
#figure out wicth button were pressed
global size, x, y
app = Application(master=root)
app.mainloop()
if size == "400 by 200":
x = 400
y = 200
elif size == "800 by 600":
x = 800
y = 600
elif size == "1000 by 700":
x = 1000
y = 700
choose()
try:
self.destroy()
except:
print("")
def name_():
name = input("what would you like to call the image? ")
return name
def angle_():
loop = True
while loop:
angle = input("What rotation would you like the picture taken at? ")
_angle = int(angle) % 90
if _angle == 0:
loop = False
return angle
else:
print("Can only accept 0, 90, 180, 270, 360")
def choice():
root = Tk()
class Application(Frame):
def image(self):
image_size_button()
take_picture()
open_image()
time.sleep(5)
close_image()
root.quit()
Frame.destroy(self)
def timelaspe_(self):
image_size_button()
timelaspe()
display_timelaspe()
root.quit()
Frame.destroy(self)
def createwidgets(self):
#set frame with the button on it
self.image_ = Button(self)
self.image_["text"] = "take picture"
self.image_["command"] = self.image
self.image_.pack({"side": "left"})
self.timelaspe__ = Button(self)
self.timelaspe__["text"] = "take timelaspe"
self.timelaspe__["command"] = self.timelaspe_
self.timelaspe__.pack({"side": "left"})
def __init__(self, master=None):
#assembley the frame
Frame.__init__(self, master)
self.pack()
self.createwidgets()
app = Application(master=root)
app.mainloop()
choice()