Take picture with camera
parent
62d7913f85
commit
031796401a
|
@ -34,7 +34,7 @@ class Button:
|
||||||
self.run()
|
self.run()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print('click')
|
pass
|
||||||
|
|
||||||
class CaptureButton(Button):
|
class CaptureButton(Button):
|
||||||
countdown = 3
|
countdown = 3
|
||||||
|
@ -59,7 +59,6 @@ class CaptureButton(Button):
|
||||||
screen.blit(ren, topleft)
|
screen.blit(ren, topleft)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print(self.photoboite.clock.get_fps())
|
|
||||||
pygame.event.set_blocked((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
pygame.event.set_blocked((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
||||||
self.capture_mode = True
|
self.capture_mode = True
|
||||||
|
|
||||||
|
@ -78,7 +77,7 @@ class CaptureButton(Button):
|
||||||
self.photoboite.draw()
|
self.photoboite.draw()
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
capture.take()
|
capture.take(self.photoboite.camera)
|
||||||
pygame.time.wait(1000)
|
pygame.time.wait(1000)
|
||||||
pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
pygame.event.set_allowed((pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP))
|
||||||
self.capture_mode = False
|
self.capture_mode = False
|
||||||
|
@ -89,8 +88,8 @@ class Capture:
|
||||||
self.uid = uid
|
self.uid = uid
|
||||||
self.photos = []
|
self.photos = []
|
||||||
|
|
||||||
def take(self):
|
def take(self, camera):
|
||||||
self.photos.append(Photo(self.uid, len(self.photos)).take())
|
self.photos.append(Photo(self.uid, len(self.photos)).take(camera))
|
||||||
|
|
||||||
|
|
||||||
class Photo:
|
class Photo:
|
||||||
|
@ -98,23 +97,24 @@ class Photo:
|
||||||
self.cid = cid
|
self.cid = cid
|
||||||
self.uid = uid
|
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)
|
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
|
return self
|
||||||
|
|
||||||
|
|
||||||
class Camera:
|
class Camera:
|
||||||
def __init__(self, rect):
|
def __init__(self, rect):
|
||||||
# self.camera = picamera.PiCamera()
|
|
||||||
# self.camera.led = False
|
|
||||||
self.rect = rect
|
self.rect = rect
|
||||||
self.img = pygame.transform.scale(pygame.image.load('tournesol.jpg'), (self.rect.width, self.rect.height))
|
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):
|
def take(self, name):
|
||||||
# self.camera.capture(name + '.jpg')
|
# self.camera.capture(name + '.jpg')
|
||||||
print('Take picture!')
|
print('Take picture! ' + name)
|
||||||
|
|
||||||
def stream(self):
|
def stream(self):
|
||||||
return self.img
|
return self.img
|
||||||
|
@ -189,7 +189,7 @@ class Photoboite:
|
||||||
def event(self):
|
def event(self):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
|
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.unicode == 'q':
|
||||||
sys.exit()
|
self.quit()
|
||||||
elif event.type == pygame.MOUSEBUTTONDOWN:
|
elif event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
for button in self.buttons:
|
for button in self.buttons:
|
||||||
if button.is_pressed(event.pos):
|
if button.is_pressed(event.pos):
|
||||||
|
@ -207,4 +207,8 @@ class Photoboite:
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
|
def quit(self):
|
||||||
|
# self.camera.close()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
Photoboite().run()
|
Photoboite().run()
|
||||||
|
|
Loading…
Reference in New Issue