Take picture with camera

master
Guillaume Dott 2017-09-29 12:35:52 +02:00
parent 62d7913f85
commit 031796401a
1 changed files with 15 additions and 11 deletions

View File

@ -34,7 +34,7 @@ class Button:
self.run()
def run(self):
print('click')
pass
class CaptureButton(Button):
countdown = 3
@ -59,7 +59,6 @@ class CaptureButton(Button):
screen.blit(ren, topleft)
def run(self):
print(self.photoboite.clock.get_fps())
pygame.event.set_blocked((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
self.capture_mode = True
@ -78,7 +77,7 @@ class CaptureButton(Button):
self.photoboite.draw()
pygame.display.flip()
capture.take()
capture.take(self.photoboite.camera)
pygame.time.wait(1000)
pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
self.capture_mode = False
@ -89,8 +88,8 @@ class Capture:
self.uid = uid
self.photos = []
def take(self):
self.photos.append(Photo(self.uid, len(self.photos)).take())
def take(self, camera):
self.photos.append(Photo(self.uid, len(self.photos)).take(camera))
class Photo:
@ -98,23 +97,24 @@ class Photo:
self.cid = cid
self.uid = uid
def take(self):
def take(self, camera):
self.name = "%s-%04d-%04d" % (time.strftime('%Y%m%d-%H%M%S'), self.cid, self.uid)
print("Capture " + self.name)
camera.take(self.name)
return self
class Camera:
def __init__(self, rect):
# self.camera = picamera.PiCamera()
# self.camera.led = False
self.rect = rect
self.img = pygame.transform.scale(pygame.image.load('tournesol.jpg'), (self.rect.width, self.rect.height))
# self.camera = picamera.PiCamera()
# self.camera.led = False
# self.camera.resolution = (self.rect.width, self.rect.height)
def take(self, name):
# self.camera.capture(name + '.jpg')
print('Take picture!')
print('Take picture! ' + name)
def stream(self):
return self.img
@ -189,7 +189,7 @@ class Photoboite:
def event(self):
for event in pygame.event.get():
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
sys.exit()
self.quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
for button in self.buttons:
if button.is_pressed(event.pos):
@ -207,4 +207,8 @@ class Photoboite:
pygame.display.flip()
def quit(self):
# self.camera.close()
sys.exit()
Photoboite().run()