-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcamera.py
executable file
·136 lines (89 loc) · 3.21 KB
/
camera.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
#!/usr/bin/env python
from time import sleep
import os
import RPi.GPIO as GPIO
import subprocess
import datetime
import pygame
from pygame.locals import *
#setup pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(24,GPIO.IN)
#setup variables
count = 0
up = False
down = False
command = ""
filename = ""
#camera_pause = "650"
camera_pause = "1000"
print("Raspberry Pi - Point & Shoot Camera v2.2")
print("-with pygame and screen, and messaging")
running = True;
pygame.init()
#screen = pygame.display.set_mode((725,92))
screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN)
width, height = screen.get_size()
background = pygame.image.load("/home/pi/camera/homeimage.jpeg");
background.convert_alpha()
background = pygame.transform.scale(background,(width,height))
screen.blit(background,(0,0),(0,0,width,height))
#logo = pygame.image.load("rpilogo.jpeg");
logo = pygame.image.load("/home/pi/camera/raspberrypilogo.png")
logo = pygame.transform.scale(logo,(150,200))
screen.blit(logo,(20,0))
font = pygame.font.SysFont("verdana", 65, bold=1)
font2 = pygame.font.SysFont("verdana", 55, bold=0)
textsurface = font.render("Raspberry Pi", 1, pygame.Color(255,255,255))
screen.blit(textsurface,(20,280))
textsurface = font2.render("Point & Shoot Camera", 1, pygame.Color(255,255,255))
screen.blit(textsurface,(20,350))
def takepic(imageName):
writemessage("taking photo...")
command = "sudo raspistill -o " + imageName + " -q 100 -rot 270 -t " + camera_pause
print(command)
os.system(command)
writemessage("loading photo...")
def loadpic(imageName):
print("loading image: " + imageName)
background = pygame.image.load(imageName);
background.convert_alpha()
background = pygame.transform.scale(background,(width,height))
screen.blit(background,(0,0),(0,0,width,height))
font = pygame.font.SysFont("verdana", 40, bold=0)
textsurface = font.render(imageName, 1, pygame.Color(0,0,0))
screen.blit(textsurface,(20,0))
logo = pygame.image.load("/home/pi/camera/raspberrypilogo.png")
logo = pygame.transform.scale(logo,(75,100))
screen.blit(logo,(20,300))
def movepic(imageName):
command = "sudo mv " + imageName + " /home/pi/camera/images/" + imageName
print(command)
os.system(command)
def writemessage(message):
screen.fill(pygame.Color(0,0,0))
#screen.blit(background,(0,0),(0,0,width,height))
font = pygame.font.SysFont("verdana", 50, bold=1)
textsurface = font.render(message, 1, pygame.Color(255,255,255))
screen.blit(textsurface,(35,40))
pygame.display.update()
while running:
if(up == True):
if(GPIO.input(24)==False):
print("button 24 pressed")
now = datetime.datetime.now()
timeString = now.strftime("%Y-%m-%d_%H:%M:%S")
print("request received: " + timeString)
filename = "photo-" + timeString + ".jpg"
takepic(filename)
loadpic(filename)
movepic(filename)
up = GPIO.input(24)
count = count + 1
pygame.display.update()
sleep(.1)
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
running = False
#never hit
print("end of loop");