Bonjour à tous,
J’essaie désespérément que créer un programme en python qui sera mise en place dans un raspberry.
Ce programme aurait pour effet lorsque l’on appuie sur un bouton, de déclencher une caméra py et d’enregistrer l’image sur un serveur distant.
les utilisateurs se trouvant devant un fond vert, auraient la surprise après la prise de vue de se voir sur un fond remplacé par le programme.
Après de multiples recherches, j’ai trouvé une ébauche de code qui peut mettre utile. Le souci est que je suis bloqué une multitude de modification et étant extrêmement novice je galère pas mal à trouver une solution.
Aujourd’hui je suis bloqué au niveau du décompte sur l’affichage ‹ Attention ›, et le programme ne va pas plus loin.
Pouvez-vous m’aider ?
Comment puis-je avoir la prévisualisation de l’image en plein écran ?
#!/usr/bin/python3
-- coding: utf-8 -
import imageio
import matplotlib.pyplot as plt
import image
import numpy as np
import RPi.GPIO as GPIO
import time
from datetime import datetime
from PIL import Image
import pygame
from pygame.locals import *
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
pygame.init()
screen = pygame.display.set_mode((0,0),pygame.FULLSCREEN)
width, height = screen.get_size()
def PrisePhoto(NomPhoto,width,height):
command = « sudo raspistill -f -t 5000 -w « +width+ » -h « +height+ » -awb auto -ifx none -p , »+width+","+height+" -o « + NomPhoto + » -q 100"
os.system(command)
def AfficherPhoto(NomPhoto): # affiche NomPhoto
print("loading image: " + NomPhoto)
background = pygame.image.load(NomPhoto)
background.convert_alpha()
background = pygame.transform.scale(background,(width,height))
screen.blit(background,(0,0),(0,0,width,height))
pygame.display.flip()
def decompte():
AfficherTexte(" Attention")
def AfficherTexte(message): # pour pouvoir afficher des messages sur un font noir
screen.fill(pygame.Color(0,0,0))
font = pygame.font.SysFont(« verdana », 150, bold=1)
textsurface = font.render(message, 1, pygame.Color(255,255,255))
screen.blit(textsurface,(35,40))
pygame.display.update()
def AfficherTexteTransparent(message): # pour pouvoir afficher des messages en conservant le font
font = pygame.font.SysFont(« verdana », 100, bold=1)
textsurface = font.render(message, 1, pygame.Color(255,255,255))
screen.blit(textsurface,(35,40))
pygame.display.update()
def AfficherTexteAccueil(message): # Afficher un Texte sur l’image d’accueil (ou à la place)
font = pygame.font.SysFont(« verdana », 50, bold=1)
textsurface = font.render(message, 1, pygame.Color(100,150,200))
screen.blit(textsurface,(35,40))
pygame.display.update()
def Vert(ivert,ipaysage):
fvert = imageio.imread(ivert)
paysage = imageio.imread(ipaysage)
absc = fvert.shape[0]
ordo = fvert.shape[1]
im = Image.new(« RGB », (ordo,absc), « white »)
pic = np.array(im)
im=pic
for k in range(absc):
for j in range(ordo):
if fvert[k,j][0]<200 and fvert[k,j][1]>=200 and fvert[k,j][2]<200:
im[k,j]=paysage[k,j]
else:
im[k,j]=fvert[k,j]
imageio.imsave(""+ img_final +"", im)
if (os.path.isdir("/home/pi/Desktop/photos") == False):
os.mkdir("/home/pi/Desktop/photos")
os.chmod("/home/pi/Desktop/photos",0o777)
AfficherPhoto("/home/pi/Photomaton/accueil.png")
while True :
try:
print ("\n attente boucle")
GPIO.wait_for_edge(24, GPIO.FALLING)
decompte()
#on génère le nom de la photo avec heure_min_sec
date_today = datetime.now()
nom_image = date_today.strftime('%d_%m_%H_%M_%S')
img_final = "/home/pi/Desktop/photos_final/"+'FINAL_'+ date_today.strftime('%d_%m_%H_%M_%S')+".jpeg"
#on déclenche la prise de photo
#chemin_photo = '/media/pi/UNTITLED/photos/'+nom_image+'.jpeg'
chemin_photo = '/home/pi/Desktop/photos/'+nom_image+'.jpeg'
#chemin_paysage = Chemin de la photo de ton paysage
chemin_paysage = '/home/pi/Desktop/photos/neige.jpeg'
PrisePhoto(chemin_photo) #Déclenchement de la prise de photo
Vert(chemin_photo,chemin_paysage,) #Remplacement du vert
AfficherTexte(" Merci ! ")
#on affiche la photo
time.sleep(1)
AfficherPhoto(img_final)
#on affiche un message
AfficherTexteTransparent("Très jolie photo ! Merci pour votre participation ...")
time.sleep(5) #Ajout d'un temps d'affichage afin de repartir sur l'accueil ensuite
#on recommence en rechargeant l'écran d'accueil
AfficherPhoto("/home/pi/Photomaton/accueil.png")
if (GPIO.input(24) == 0): #si le bouton est encore enfoncé (son etat sera 0)
print ("Ho ; bouton appuyé !!! Je dois sortir ; c'est le chef qui l'a dit !")
break # alors on sort du while
except KeyboardInterrupt:
print (‹ sortie du programme! ›)
raise
GPIO.cleanup()