Use fake Camera when picamera is not found
parent
f67ec8b037
commit
228ed201a6
|
@ -2,8 +2,56 @@
|
|||
|
||||
import io, os, sys, time, pygame
|
||||
|
||||
try:
|
||||
import picamera
|
||||
|
||||
class Camera:
|
||||
def __init__(self, rect):
|
||||
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)
|
||||
self.rgb = bytearray(self.rect.width * self.rect.height * 4)
|
||||
|
||||
def close(self):
|
||||
self.camera.close()
|
||||
|
||||
def take(self, name):
|
||||
self.camera.capture(name + '.jpg')
|
||||
print('Take picture! ' + name)
|
||||
|
||||
def stream(self):
|
||||
stream = io.BytesIO()
|
||||
self.camera.capture(stream, use_video_port=True, format='rgba', resize=(self.rect.width, self.rect.height))
|
||||
stream.seek(0)
|
||||
stream.readinto(self.rgb)
|
||||
stream.close()
|
||||
img = pygame.image.frombuffer(self.rgb, (self.rect.width, self.rect.height), 'RGBA')
|
||||
|
||||
return pygame.transform.flip(img, True, False)
|
||||
|
||||
def draw_on(self, screen):
|
||||
screen.blit(self.stream(), self.rect)
|
||||
|
||||
|
||||
except:
|
||||
class Camera:
|
||||
def __init__(self, rect):
|
||||
self.rect = rect
|
||||
self.img = pygame.transform.scale(pygame.image.load('tournesol.jpg'), (self.rect.width, self.rect.height))
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def take(self, name):
|
||||
print('Take picture! ' + name)
|
||||
|
||||
def draw_on(self, screen):
|
||||
screen.blit(self.img, self.rect)
|
||||
|
||||
|
||||
|
||||
class Button:
|
||||
def __init__(self, size, topleft):
|
||||
self.up_image = pygame.image.load('button-up.png').convert_alpha()
|
||||
|
@ -118,36 +166,6 @@ class Photo:
|
|||
return self
|
||||
|
||||
|
||||
class Camera:
|
||||
def __init__(self, rect):
|
||||
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)
|
||||
self.rgb = bytearray(self.rect.width * self.rect.height * 4)
|
||||
|
||||
def close(self):
|
||||
self.camera.close()
|
||||
|
||||
def take(self, name):
|
||||
self.camera.capture(name + '.jpg')
|
||||
print('Take picture! ' + name)
|
||||
|
||||
def stream(self):
|
||||
stream = io.BytesIO()
|
||||
self.camera.capture(stream, use_video_port=True, format='rgba', resize=(self.rect.width, self.rect.height))
|
||||
stream.seek(0)
|
||||
stream.readinto(self.rgb)
|
||||
stream.close()
|
||||
img = pygame.image.frombuffer(self.rgb, (self.rect.width, self.rect.height), 'RGBA')
|
||||
|
||||
return pygame.transform.flip(img, True, False)
|
||||
|
||||
def draw_on(self, screen):
|
||||
screen.blit(self.stream(), self.rect)
|
||||
|
||||
|
||||
class Photoboite:
|
||||
def __init__(self):
|
||||
self.screen = self.screen()
|
||||
|
|
Loading…
Reference in New Issue