bonjour à toutes et tous
je partage ici un projet archi classique que j'ai monté récemment : un photobooth
j'ai réalisé la caisse en bois, la peinture, le petit montage électrique et la programmation.
le photobooth se pilote à partir d'une manette type console de jeu
il y a un projecteur en cas de manque de lumiere
on peut visualiser les photos prises (mais pas imprimer ni envoyer sur les reseaux sociaux)
c'est pas du grand art, c'est un peu vite fait, mais ça marche...enfin presque.
Je ne suis pas spécialiste python, loin s'en faut, c'est mon 1er code python.
Donc il y a des bugs et à vrai dire je compte un peu sur la communauté pour me trouver les bugs
Il y a un bug principal :
le programme se bloque par moment. il est lors impossible de sortir du prog et je suis obligé d'éteindre le raspberry.
en cherchant un peu sur le net, j'ai trouvé un moyen d'éviter d'éteindre, à travers une connexion ssh , et une obscure commande, je peux kill le prog pour reprendre la main.
apparemment le bug se produit lorsque les enfants (!) appuient sur toutes les touches en meme temps...
Si quelqu'un peu me corriger le pro je suis preneur.
si quelqu'un peut me dire comment envoyer des photos sur le forum...
sinon, voici le code :
#photobooth
#initialisation des librairie
import os
import datetime
from time import sleep
import time
import picamera
import pygame
from pygame.locals import *
from PIL import Image
import glob
#VARIABLES
photo_w = 1280 # take photos at this resolution
photo_h = 1024
screen_w = 800 # resolution of the photo booth display
screen_h = 480
photo_countdown_time = 4 # countdown time before photo is taken
photo_playback_time = 3 #duree d affichage des photos
#FONCTIONNEMENT
#pygame
pygame.init()
fenetre = pygame.display.set_mode((640,480),RESIZABLE)
#initialisation du joystick
nb_joysticks = pygame.joystick.get_count()
if nb_joysticks > 0:
mon_joystick = pygame.joystick.Joystick(0)
mon_joystick.init()
# initialisation de la camera
#Setup Camera
try:
camera = picamera.PiCamera()
except:
raise SystemExit
#Fonction surimpression de texte sur l image camera
def print_overlay(string_to_print):
camera.annotate_text = string_to_print
def remove_overlay(overlay_id):
"""
If there is an overlay, remove it
"""
#if overlay_id in self._overlays:
if overlay_id != -1:
camera.remove_overlay(overlay_id)
# overlay one image on screen
def overlay_image(image_path, duration=0, layer=3):
"""
Add an overlay (and sleep for an optional duration).
If sleep duration is not supplied, then overlay will need to be removed later.
This function returns an overlay id, which can be used to remove_overlay(id).
"""
# Load the arbitrarily sized image
img = Image.open(image_path)
# Create an image padded to the required size with
# mode 'RGB'
pad = Image.new('RGB', (
((img.size[0] + 31) // 32) * 32,
((img.size[1] + 15) // 16) * 16,
))
# Paste the original image into the padded one
pad.paste(img, (0, 0))
# Add the overlay with the padded image as the source,
# but the original image's dimensions
o_id = camera.add_overlay(pad.tobytes(), size=img.size)
o_id.layer = layer
if duration > 0:
sleep(duration)
camera.remove_overlay(o_id)
return -1 # '-1' indicates there is no overlay
else:
return o_id # we have an overlay, and will need to remove it later
#definition du repertoire photo
REAL_PATH = os.path.dirname(os.path.realpath(__file__))
PHOTO_PATH = REAL_PATH + "/photos/"
#definition du nom de fichier de la photo
def get_filename_for_images():
filename = PHOTO_PATH + str(datetime.datetime.now()).split('.')[0]
filename = filename.replace(' ', '_')
filename = filename.replace(':', '-')
filename = filename+'.jpg'
return filename
#Fonction prise de photo
def taking_photo(filename):
#countdown from #, and display countdown on screen
for counter in range(photo_countdown_time,0,-1):
print_overlay(" ..." + str(counter))
sleep(1)
camera.annotate_text = ''
#filename = "image-" + str(datetime.datetime.now())+".jpg"
camera.capture(filename, use_video_port=True)
#fonction de previsualisation des photos
def prev_photo(filename):
#filename_prefix = get_base_filename_for_images()
#camera.stop_preview()
#camera.annotate_text=filename
#fond = pygame.image.load(filename).convert()
#fenetre.blit(fond, (0,0))
#pygame.display.flip()
#Playback
#prev_overlay = False
this_overlay = overlay_image(filename, 3, 3)
# The idea here, is only remove the previous overlay after a new overlay is added.
#if prev_overlay:
# remove_overlay(prev_overlay)
#sleep(photo_playback_time)
#prev_overlay = this_overlay
#remove_overlay(prev_overlay)
def prev_all_photo():
#fonction glob liste les fichier d'un repertoire
motif = PHOTO_PATH + "*.jpg"
filelist = glob.glob(motif)
#classe les fichiers par date
filelist.sort(key=os.path.getmtime)
nbr_photo = len(filelist)-1
num_photo = nbr_photo
camera.annotate_text_size = 30
camera.annotate_text="< pressez gauche ou droite pour faire defiler les photos >"
sleep (1)
layer = 3
this_overlay = overlay_image(filelist[num_photo], False, layer)
#camera.annotate_text="preview : " + filelist[nbr_photo]
#camera.annotate_text = str(nbr_photo)
a=1
while a:
for event in pygame.event.get():
#si a=0 la boucle s'arrete
if event.type == JOYBUTTONDOWN and event.button ==1 or event.type == JOYBUTTONDOWN and event.button ==2:
#QUIT LE MODE PREVIEW
remove_overlay(this_overlay)
camera.annotate_text="PhotoMaton - pressez Bouton Jaune B - pour une photo"
a=0
#camera.annotate_text=filename
if event.type == JOYAXISMOTION and event.axis == 0 and event.value > 0:
num_photo = num_photo + 1
if num_photo > nbr_photo:
num_photo = 0
if layer == 3:
layer = 4
else:
if layer == 4:
layer = 3
prev_overlay = this_overlay
this_overlay = overlay_image(filelist[num_photo], False, layer)
remove_overlay(prev_overlay)
#camera.annotate_text="photo " + str(num_photo)
if event.type == JOYAXISMOTION and event.axis == 0 and event.value < 0:
num_photo = num_photo - 1
if num_photo < 0:
num_photo = nbr_photo
if layer == 3:
layer = 4
else:
if layer == 4:
layer = 3
prev_overlay = this_overlay
this_overlay = overlay_image(filelist[num_photo], False, layer)
remove_overlay(prev_overlay)
#camera.annotate_text="photo " + str(num_photo)
if event.type == JOYBUTTONDOWN and event.button == 4:
num_photo = num_photo - 5
if num_photo < 0:
num_photo = nbr_photo
if layer == 3:
layer = 4
else:
if layer == 4:
layer = 3
prev_overlay = this_overlay
this_overlay = overlay_image(filelist[num_photo], False, layer)
remove_overlay(prev_overlay)
if event.type == JOYBUTTONDOWN and event.button == 5:
num_photo = num_photo + 5
if num_photo > nbr_photo:
num_photo = 0
if layer == 3:
layer = 4
else:
if layer == 4:
layer = 3
prev_overlay = this_overlay
this_overlay = overlay_image(filelist[num_photo], False, layer)
remove_overlay(prev_overlay)
#Fonction variation balance des blancs
def var_awb():
if camera.awb_mode=="auto":
camera.awb_mode="tungsten"
else:
if camera.awb_mode=="tungsten":
camera.awb_mode="fluorescent"
else:
if camera.awb_mode=="fluorescent":
camera.awb_mode="incandescent"
else:
if camera.awb_mode=="incandescent":
camera.awb_mode="sunlight"
else:
if camera.awb_mode=="sunlight":
camera.awb_mode="auto"
camera.annotate_text=camera.awb_mode
#fonction variation brightness plus (luminosité)
def var_brightness():
if camera.brightness==90:
camera.brightness=0
camera.brightness=camera.brightness+10
camera.annotate_text="luminosite : " + str(camera.brightness)
#fonction variation brightness moins (luminosité)
def var_brightnessmoins():
if camera.brightness==0:
camera.brightness=100
camera.brightness=camera.brightness-10
camera.annotate_text="luminosite : " + str(camera.brightness)
#Fonction variation contraste plus
def var_contrast():
if camera.contrast==100:
camera.contrast=-10
camera.contrast=camera.contrast+10
camera.annotate_text="contraste : " + str(camera.contrast)
#Fonction variation contraste moins
def var_contrastmoins():
if camera.contrast==0:
camera.contrast=100
camera.contrast=camera.contrast-10
camera.annotate_text="contraste : " + str(camera.contrast)
#Fonction reset des parametres de la camera
def default_cam():
camera.rotation = 180
camera.awb_mode="auto"
camera.brightness = 50
camera.contrast = 0
#lancement du preview
camera.annotate_text_size = 80
camera.resolution = (photo_w, photo_h)
default_cam()
camera.start_preview()
#camera.annotate_text=camera.awb_mode
#camera.annotate_text="luminosite : " + str(camera.brightness)
#boucle principale : attend l'appuie sur une touche
a=1
while a:
for event in pygame.event.get():
#su a=0 la boucle s'arrete
if event.type == KEYDOWN:
if event.key == K_SPACE:
raise SystemExit
if event.type == JOYBUTTONDOWN:
#if event.button ==1 and event.button ==4 and event.button ==5:
if event.button ==8:
raise SystemExit
if event.button ==2:
filename = get_filename_for_images()
taking_photo(filename)
sleep(1)
prev_photo(filename)
if event.button ==1:
#filename = get_filename_for_images()
#filename="tot"
prev_all_photo()
#camera.annotate_text=filename
if event.button ==4:
camera.annotate_text="bt4"
if event.button ==5:
camera.annotate_text="bt5"
if event.button ==3:
var_awb()
if event.button ==0:
default_cam()
camera.annotate_text="parametres par defaut"
sleep(1.5)
camera.annotate_text=""
if event.type == JOYAXISMOTION and event.axis == 0 and event.value > 0:
var_contrast()
if event.type == JOYAXISMOTION and event.axis == 0 and event.value < 0:
var_contrastmoins()
if event.type == JOYAXISMOTION and event.axis == 1 and event.value < 0:
var_brightness()
if event.type == JOYAXISMOTION and event.axis == 1 and event.value > 0:
var_brightnessmoins()
mon photobooth finalisé - quelques bugs à corriger
Parce que les applications du Raspberry Pi sont illimités...
Modérateur : Francois
Retourner vers « Et tout le reste »
Aller à
- Présentez vous !
- Votre avis sur le forum
- Utiliser le Raspberry Pi
- ↳ Débutants
- ↳ En panne ?
- ↳ Utilisateurs avancés
- ↳ Les applications spécialisées du Raspberry Pi
- La domotique avec le Raspberry Pi
- ↳ Accès, alarme et vidéosurveillance
- ↳ Gestion centralisée ouverture/fermeture
- ↳ Téléphonie et télécommunication
- ↳ Gestion de la température
- ↳ La météo
- ↳ Gérer l'énergie
- ↳ Que d'eau, que d'eau !
- ↳ Robots and Co
- ↳ Des interfaces pour le Raspberry Pi
- ↳ Et tout le reste
- Les jeux sur Raspberry Pi
- ↳ Emulation de consoles sur Raspberry Pi
- ↳ Les jeux "baremetal" sur Raspberry Pi
- Les événements liés au Raspberry Pi
- ↳ Vos annonces d'événements autour du Raspberry Pi
- Les systèmes d'exploitation du Raspberry Pi
- ↳ NOOBS et NOOBS Lite
- ↳ Raspbian
- ↳ Arch Linux
- ↳ RISC OS
- ↳ OpenELEC
- ↳ Raspbmc (OSMC)
- ↳ Ubuntu MATE
- ↳ Les utilitaires et le Raspberry Pi
- ↳ Les commandes Linux
- ↳ Les autres OS
- Le matériel et les périphériques du Raspberry Pi
- ↳ Raspberry Pi (tout modèles)
- ↳ Les cartes SD et micro SD
- ↳ Le Compute Module
- ↳ Le GPIO
- ↳ Les cartes d'extension pour les Raspberry Pi
- ↳ Les BUS interfaces
- ↳ Le module caméra et ses clones
- ↳ Les alimentations
- ↳ Les sorties Vidéo et Audio du Raspberry Pi
- ↳ Le réseau sur le Raspberry Pï
- ↳ Les ports USB
- ↳ Les accessoires du Raspberry Pi
- ↳ Les clones du Raspberry Pi
- ↳ L'électronique et le Raspberry Pi
- Projets
- ↳ Projets
- La programmation du Raspberry Pi
- ↳ Python
- ↳ Scratch
- ↳ C / C++
- ↳ Java
- ↳ Assembleur
- ↳ Autres langages
- Education, formation et Raspberry Pi
- ↳ Tutoriels
- ↳ Fiches pédagogiques
- ↳ Stages d'application Raspberry Pi
- Achat-Vente
- ↳ Les petites annonces achat-vente du Raspberry Pi