first working with live preview
This commit is contained in:
parent
0e7ed030fe
commit
0502f2256d
44
Fotobox.py
44
Fotobox.py
@ -1,5 +1,6 @@
|
||||
import os.path
|
||||
import time
|
||||
|
||||
from typing import List
|
||||
from PIL import Image
|
||||
from escpos.escpos import Escpos
|
||||
@ -24,10 +25,25 @@ class State(Enum):
|
||||
CHOOSE = 4
|
||||
QR = 5
|
||||
|
||||
res = (1024,768)
|
||||
|
||||
class Fotobox:
|
||||
|
||||
def __init__(self, camera):
|
||||
camera.vflip = False
|
||||
camera.hflip = True
|
||||
camera.resolution = (2592, 1944)
|
||||
camera.rotation = 270
|
||||
camera.preview_configuration.main.size = res
|
||||
camera.preview_configuration.main.format = 'BGR888'
|
||||
camera.configure("preview")
|
||||
#####################
|
||||
# here configure still capture
|
||||
self._capture_config = camera.create_still_configuration()
|
||||
camera.still_configuration.main.size = (2592, 1944)
|
||||
#####################
|
||||
camera.start()
|
||||
|
||||
self._camera = camera
|
||||
self._running: bool = True
|
||||
self._state: State = State.IDLE
|
||||
@ -64,16 +80,25 @@ class Fotobox:
|
||||
|
||||
def _shooting_callback(self):
|
||||
print("SHOT: %d/%d" % (self._shooting_timer.current(), SHOOTING_COUNT))
|
||||
|
||||
for i in range(24):
|
||||
array = self._camera.capture_array()
|
||||
img = pygame.image.frombuffer(array.data, res, 'RGB')
|
||||
screen.blit(img, (0, 0))
|
||||
pygame.display.update()
|
||||
|
||||
screen.fill((255, 255, 255))
|
||||
pygame.display.flip()
|
||||
if not DEBUG:
|
||||
time.sleep(0.2)
|
||||
|
||||
stream = io.BytesIO()
|
||||
self._camera.capture(stream, format='rgb')
|
||||
stream.seek(0)
|
||||
self._photos.append(Photo(self._shooting_timer.current(), Image.open(stream)))
|
||||
|
||||
frame = self._camera.switch_mode_and_capture_array(self._capture_config, "main")
|
||||
image = Image.fromarray(frame)
|
||||
self._photos.append(Photo(self._shooting_timer.current(), image))
|
||||
|
||||
#stream = io.BytesIO()
|
||||
#self._camera.capture(stream, format='rgb')
|
||||
#stream.seek(0)
|
||||
#self._photos.append(Photo(self._shooting_timer.current(), Image.open(stream)))
|
||||
|
||||
screen.fill((0, 0, 0))
|
||||
pygame.display.flip()
|
||||
@ -184,7 +209,10 @@ class Fotobox:
|
||||
print(new_state)
|
||||
self._state = new_state
|
||||
if new_state == State.COUNTDOWN:
|
||||
self._camera.start_preview()
|
||||
#config = self._camera.create_preview_configuration(main={"size": (PHOTO_WIDTH, PHOTO_HEIGHT)})
|
||||
#self._camera.configure(config)
|
||||
#self._camera.start_preview()
|
||||
#self._camera.start()
|
||||
self._countdown_timer.restart()
|
||||
elif new_state == State.SHOOTING:
|
||||
self._photos = []
|
||||
@ -236,7 +264,7 @@ class Fotobox:
|
||||
filename,
|
||||
))
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
img.save(path, format='JPEG', quality=95)
|
||||
img.convert('RGB').save(path, format='JPEG', quality=95)
|
||||
upload = Path("./data/photos/upload/%s" % (filename,))
|
||||
upload.parent.mkdir(parents=True, exist_ok=True)
|
||||
os.link(path, upload)
|
||||
|
||||
5
INSTALL
5
INSTALL
@ -1,7 +1,8 @@
|
||||
sudo apt update
|
||||
sudo apt install libcap-dev xinit
|
||||
sudo apt install libcap-dev xinit python3-libcamera python3-picamera2 #######??????######### libcamera-dev libcamera-apps
|
||||
|
||||
python3 -m venv venv
|
||||
|
||||
python3 -m venv venv --system-site-packages
|
||||
. venv/bin/activate
|
||||
pip install pygame qrcode escpos picamera2
|
||||
|
||||
|
||||
@ -4,4 +4,7 @@ cd "$(dirname "$0")" || exit 1
|
||||
|
||||
. venv/bin/activate
|
||||
|
||||
python main.py
|
||||
#while true; do
|
||||
python main.py
|
||||
# sleep 1
|
||||
#done
|
||||
|
||||
@ -19,7 +19,7 @@ PHOTO_HEIGHT = 1944
|
||||
|
||||
SHOOTING_COUNT: int = 2
|
||||
SHOOTING_INTERVAL: float = 0 if DEBUG else 1.75
|
||||
COUNTDOWN_COUNT: int = 1 if DEBUG else 3
|
||||
COUNTDOWN_COUNT: int = 1 if DEBUG else 1
|
||||
|
||||
CHOICE_BORDER: int = 5
|
||||
|
||||
|
||||
10
main.py
10
main.py
@ -1,17 +1,11 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import pygame
|
||||
import picamera
|
||||
import picamera2
|
||||
|
||||
from Fotobox import Fotobox
|
||||
|
||||
with picamera.PiCamera() as camera:
|
||||
camera.vflip = False
|
||||
camera.hflip = True
|
||||
camera.resolution = (2592, 1944)
|
||||
camera.rotation = 0
|
||||
camera.start_preview()
|
||||
|
||||
with picamera2.Picamera2() as camera:
|
||||
fotobox = Fotobox(camera)
|
||||
try:
|
||||
fotobox.run()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user