IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

PhotoBooth raspberry PI2


Sujet :

Python

  1. #1
    Candidat au Club
    Homme Profil pro
    Debutant
    Inscrit en
    Janvier 2016
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Debutant

    Informations forums :
    Inscription : Janvier 2016
    Messages : 8
    Points : 2
    Points
    2
    Par défaut PhotoBooth raspberry PI2
    Bonjour,
    Je suis un petit nouveau de la programmation, je débute.

    Avec plusieurs mariages a venir dans la famille, je me suis lancer dans la construction d'un photobooth avec:
    - une carte RPI2
    - un reflex numérique Canon 450D avec son flash

    j'ai trouvé sur le net cette construction réalisé par Chris Evans, où il met à disposition l'ensemble de sa réalisation mais avec la PiCamera

    - lien de la réalisation http://www.drumminhands.com/2014/06/...i-photo-booth/
    - lien du code sur github https://github.com/drumminhands/drumminhands_photobooth

    et voici le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    #!/usr/bin/env python
    # created by chris@drumminhands.com
    # see instructions at http://www.drumminhands.com/2014/06/15/raspberry-pi-photo-booth/
     
    import os
    import glob
    import time
    import traceback
    from time import sleep
    import RPi.GPIO as GPIO
    import picamera # http://picamera.readthedocs.org/en/release-1.4/install2.html
    import atexit
    import sys
    import socket
    import pygame
    import pytumblr # https://github.com/tumblr/pytumblr
    import config
    from signal import alarm, signal, SIGALRM, SIGKILL
     
    ########################
    ### Variables Config ###
    ########################
    led1_pin = 15 # LED 1
    led2_pin = 19 # LED 2
    led3_pin = 21 # LED 3
    led4_pin = 23 # LED 4
    button1_pin = 22 # pin for the big red button
    button2_pin = 18 # pin for button to shutdown the pi
    button3_pin = 16 # pin for button to end the program, but not shutdown the pi
     
    post_online = 1 # default 1. Change to 0 if you don't want to upload pics.
    total_pics = 4 # number of pics to be taken
    capture_delay = 2 # delay between pics
    prep_delay = 3 # number of seconds at step 1 as users prep to have photo taken
    gif_delay = 100 # How much time between frames in the animated gif
    restart_delay = 5 # how long to display finished message before beginning a new session
     
    monitor_w = 800
    monitor_h = 480
    transform_x = 640 # how wide to scale the jpg when replaying
    transfrom_y = 480 # how high to scale the jpg when replaying
    offset_x = 80 # how far off to left corner to display photos
    offset_y = 0 # how far off to left corner to display photos
    replay_delay = 1 # how much to wait in-between showing pics on-screen after taking
    replay_cycles = 2 # how many times to show each photo on-screen after taking
     
    test_server = 'www.google.com'
    real_path = os.path.dirname(os.path.realpath(__file__))
     
    # Setup the tumblr OAuth Client
    client = pytumblr.TumblrRestClient(
        config.consumer_key,
        config.consumer_secret,
        config.oath_token,
        config.oath_secret,
    );
     
    ####################
    ### Other Config ###
    ####################
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(led1_pin,GPIO.OUT) # LED 1
    GPIO.setup(led2_pin,GPIO.OUT) # LED 2
    GPIO.setup(led3_pin,GPIO.OUT) # LED 3
    GPIO.setup(led4_pin,GPIO.OUT) # LED 4
    GPIO.setup(button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 1
    GPIO.setup(button2_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 2
    GPIO.setup(button3_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 3
    GPIO.output(led1_pin,False);
    GPIO.output(led2_pin,False);
    GPIO.output(led3_pin,False);
    GPIO.output(led4_pin,False); #for some reason the pin turns on at the beginning of the program. why?????????????????????????????????
     
    #################
    ### Functions ###
    #################
     
    def cleanup():
      print('Ended abruptly')
      GPIO.cleanup()
    atexit.register(cleanup)
     
    def shut_it_down(channel):  
        print "Shutting down..." 
        GPIO.output(led1_pin,True);
        GPIO.output(led2_pin,True);
        GPIO.output(led3_pin,True);
        GPIO.output(led4_pin,True);
        time.sleep(3)
        os.system("sudo halt")
     
    def exit_photobooth(channel):
        print "Photo booth app ended. RPi still running" 
        GPIO.output(led1_pin,True);
        time.sleep(3)
        sys.exit()
     
    def clear_pics(foo): #why is this function being passed an arguments?
        #delete files in folder on startup
    	files = glob.glob(config.file_path + '*')
    	for f in files:
    		os.remove(f) 
    	#light the lights in series to show completed
    	print "Deleted previous pics"
    	GPIO.output(led1_pin,False); #turn off the lights
    	GPIO.output(led2_pin,False);
    	GPIO.output(led3_pin,False);
    	GPIO.output(led4_pin,False)
    	pins = [led1_pin, led2_pin, led3_pin, led4_pin]
    	for p in pins:
    		GPIO.output(p,True); 
    		sleep(0.25)
    		GPIO.output(p,False);
    		sleep(0.25)
     
    def is_connected():
      try:
        # see if we can resolve the host name -- tells us if there is
        # a DNS listening
        host = socket.gethostbyname(test_server)
        # connect to the host -- tells us if the host is actually
        # reachable
        s = socket.create_connection((host, 80), 2)
        return True
      except:
         pass
      return False    
     
    def init_pygame():
        pygame.init()
        size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
        pygame.display.set_caption('Photo Booth Pics')
        pygame.mouse.set_visible(False) #hide the mouse cursor	
        return pygame.display.set_mode(size, pygame.FULLSCREEN)
     
    def show_image(image_path):
        screen = init_pygame()
        img=pygame.image.load(image_path) 
        img = pygame.transform.scale(img,(transform_x,transfrom_y))
        screen.blit(img,(offset_x,offset_y))
        pygame.display.flip()
     
    def display_pics(jpg_group):
        # this section is an unbelievable nasty hack - for some reason Pygame
        # needs a keyboardinterrupt to initialise in some limited circs (second time running)
     
        class Alarm(Exception):
            pass
        def alarm_handler(signum, frame):
            raise Alarm
        signal(SIGALRM, alarm_handler)
        alarm(3)
        try:
            screen = init_pygame()
     
            alarm(0)
        except Alarm:
            raise KeyboardInterrupt
        for i in range(0, replay_cycles): #show pics a few times
    		for i in range(1, total_pics+1): #show each pic
    			filename = config.file_path + jpg_group + "-0" + str(i) + ".jpg"
                            show_image(filename);
    			time.sleep(replay_delay) # pause 
     
    # define the photo taking function for when the big button is pressed 
    def start_photobooth(): 
    	################################# Begin Step 1 ################################# 
    	show_image(real_path + "/blank.png")
    	print "Get Ready"
    	GPIO.output(led1_pin,True);
    	show_image(real_path + "/instructions.png")
    	sleep(prep_delay) 
    	GPIO.output(led1_pin,False)
     
    	show_image(real_path + "/blank.png")
     
    	camera = picamera.PiCamera()
    	pixel_width = 500 #use a smaller size to process faster, and tumblr will only take up to 500 pixels wide for animated gifs
    	pixel_height = monitor_h * pixel_width // monitor_w
    	camera.resolution = (pixel_width, pixel_height) 
    	camera.vflip = True
    	camera.hflip = False
    	camera.saturation = -100 # comment out this line if you want color images
    	camera.start_preview()
     
    	sleep(2) #warm up camera
     
    	################################# Begin Step 2 #################################
    	print "Taking pics" 
    	now = time.strftime("%Y-%m-%d-%H:%M:%S") #get the current date and time for the start of the filename
    	try: #take the photos
    		for i, filename in enumerate(camera.capture_continuous(config.file_path + now + '-' + '{counter:02d}.jpg')):
    			GPIO.output(led2_pin,True) #turn on the LED
    			print(filename)
    			sleep(0.25) #pause the LED on for just a bit
    			GPIO.output(led2_pin,False) #turn off the LED
    			sleep(capture_delay) # pause in-between shots
    			if i == total_pics-1:
    				break
    	finally:
    		camera.stop_preview()
    		camera.close()
    	########################### Begin Step 3 #################################
    	print "Creating an animated gif" 
    	if post_online:
    		show_image(real_path + "/uploading.png")
    	else:
    		show_image(real_path + "/processing.png")
     
    	GPIO.output(led3_pin,True) #turn on the LED
    	graphicsmagick = "gm convert -delay " + str(gif_delay) + " " + config.file_path + now + "*.jpg " + config.file_path + now + ".gif" 
    	os.system(graphicsmagick) #make the .gif
    	print "Uploading to tumblr. Please check " + config.tumblr_blog + ".tumblr.com soon."
     
    	if post_online: # turn off posting pics online in the variable declarations at the top of this document
    		connected = is_connected() #check to see if you have an internet connection
    		while connected: 
    			try:
    				file_to_upload = config.file_path + now + ".gif"
    				client.create_photo(config.tumblr_blog, state="published", tags=["drumminhandsPhotoBooth"], data=file_to_upload)
    				break
    			except ValueError:
    				print "Oops. No internect connection. Upload later."
    				try: #make a text file as a note to upload the .gif later
    					file = open(config.file_path + now + "-FILENOTUPLOADED.txt",'w')   # Trying to create a new file or open one
    					file.close()
    				except:
    					print('Something went wrong. Could not write file.')
    					sys.exit(0) # quit Python
    	GPIO.output(led3_pin,False) #turn off the LED
     
    	########################### Begin Step 4 #################################
    	GPIO.output(led4_pin,True) #turn on the LED
    	try:
    		display_pics(now)
    	except Exception, e:
    		tb = sys.exc_info()[2]
    		traceback.print_exception(e.__class__, e, tb)
    	pygame.quit()
    	print "Done"
    	GPIO.output(led4_pin,False) #turn off the LED
     
    	if post_online:
    		show_image(real_path + "/finished.png")
    	else:
    		show_image(real_path + "/finished2.png")
     
    	time.sleep(restart_delay)
    	show_image(real_path + "/intro.png");
     
    ####################
    ### Main Program ###
    ####################
     
    # when a falling edge is detected on button2_pin and button3_pin, regardless of whatever   
    # else is happening in the program, their function will be run   
    GPIO.add_event_detect(button2_pin, GPIO.FALLING, callback=shut_it_down, bouncetime=300) 
     
    #choose one of the two following lines to be un-commented
    GPIO.add_event_detect(button3_pin, GPIO.FALLING, callback=exit_photobooth, bouncetime=300) #use third button to exit python. Good while developing
    #GPIO.add_event_detect(button3_pin, GPIO.FALLING, callback=clear_pics, bouncetime=300) #use the third button to clear pics stored on the SD card from previous events
     
    # delete files in folder on startup
    files = glob.glob(config.file_path + '*')
    for f in files:
        os.remove(f)
     
    print "Photo booth app running..." 
    GPIO.output(led1_pin,True); #light up the lights to show the app is running
    GPIO.output(led2_pin,True);
    GPIO.output(led3_pin,True);
    GPIO.output(led4_pin,True);
    time.sleep(3)
    GPIO.output(led1_pin,False); #turn off the lights
    GPIO.output(led2_pin,False);
    GPIO.output(led3_pin,False);
    GPIO.output(led4_pin,False);
     
    show_image(real_path + "/intro.png");
     
    while True:
            GPIO.wait_for_edge(button1_pin, GPIO.FALLING)
    	time.sleep(0.2) #debounce
    	start_photobooth()
    Pensez vous que l'on peut remplacer les commande de la Picamera et utiliser Gphoto2 et les commandes suivante

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    gphoto2 --capture-image-and-download #prend une photo et la télécharge dans la foulée sur le pc
    gphoto2 --capture-image --interval 10 #prend une image toutes les 10 secondes
    Merci de votre aide

    Loic

  2. #2
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Salut,

    Citation Envoyé par eole_35 Voir le message
    Pensez vous que l'on peut remplacer les commande de la Picamera et utiliser Gphoto2 et les commandes suivante
    Oui : http://bazaar.launchpad.net/~vincent...camerahandler/

    La partie remote control est en début de construction, je préviens.

  3. #3
    Candidat au Club
    Homme Profil pro
    Debutant
    Inscrit en
    Janvier 2016
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Debutant

    Informations forums :
    Inscription : Janvier 2016
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    le code principal en français

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    #!/usr/bin/env python
    # Créé par chris@drumminhands.com
    # Voir les instructions sur http://www.drumminhands.com/2014/06/15/raspberry-pi-photo-booth/
     
    import os
    import glob
    import time
    import traceback
    from time import sleep
    import RPi.GPIO as GPIO
    import picamera # http://picamera.readthedocs.org/en/release-1.4/install2.html
    import atexit
    import sys
    import socket
    import pygame
    import pytumblr # https://github.com/tumblr/pytumblr
    import config
    from signal import alarm, signal, SIGALRM, SIGKILL
     
    ########################
    ### Variables Config ###
    ########################
    led1_pin = 15 # LED 1
    led2_pin = 19 # LED 2
    led3_pin = 21 # LED 3
    led4_pin = 23 # LED 4
    button1_pin = 22 # pin pour le gros bouton rouge (déclencheur)
    button2_pin = 18 # pin pour arrêter la carte RPI2
    button3_pin = 16 # pin arrêter le programme 
     
    post_online = 1 # par défaut 1. Mettre à 0 si vous ne souhaitez par mettre en ligne les photos.
    total_pics = 4 # nombre de photos à prendre
    capture_delay = 2 # délai entre les photos
    prep_delay = 3 # Temps d'attente à l'etape 1 en seconde pour la préparation de l'utilistaeur
    gif_delay = 100 # Temps entre les images du fichier Gif animé
    restart_delay = 5 # Temps pour afficher le message terminé avant de commencer une nouvelle session
     
    monitor_w = 800
    monitor_h = 480
    transform_x = 640 # Largeur de l'image jpg lors de l'affichage en lecture
    transfrom_y = 480 # Hauteur de l'image jpg lors de l'affichage en lecture
    offset_x = 80 # Distance du coin gauche pour l'affichage de la photo axe X
    offset_y = 0 # Distance du coin gauche pour l'affichage de la photo axe Y
    replay_delay = 1 # Temps d'attente entre les 2 affichages après la prise devue
    replay_cycles = 2 # Nombres d'affichage de chaque photos après la prise de vue
     
    test_server = 'www.google.com'
    real_path = os.path.dirname(os.path.realpath(__file__))
     
    # Configuration du client tumblr OAuth
    client = pytumblr.TumblrRestClient(
        config.consumer_key,
        config.consumer_secret,
        config.oath_token,
        config.oath_secret,
    );
     
    ####################
    ### Other Config ###
    ####################
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(led1_pin,GPIO.OUT) # LED 1
    GPIO.setup(led2_pin,GPIO.OUT) # LED 2
    GPIO.setup(led3_pin,GPIO.OUT) # LED 3
    GPIO.setup(led4_pin,GPIO.OUT) # LED 4
    GPIO.setup(button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 1
    GPIO.setup(button2_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 2
    GPIO.setup(button3_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 3
    GPIO.output(led1_pin,False);
    GPIO.output(led2_pin,False);
    GPIO.output(led3_pin,False);
    GPIO.output(led4_pin,False); #Pour une raison quelconque, la broche se met en marche au début du programme. Pourquoi?????????????????????????????????
     
    #################
    ### Functions ###
    #################
     
    def cleanup():
      print('Ended abruptly')
      GPIO.cleanup()
    atexit.register(cleanup)
     
    def shut_it_down(channel):  
        print "Shutting down..." 
        GPIO.output(led1_pin,True);
        GPIO.output(led2_pin,True);
        GPIO.output(led3_pin,True);
        GPIO.output(led4_pin,True);
        time.sleep(3)
        os.system("sudo halt")
     
    def exit_photobooth(channel):
        print "Photo booth app ended. RPi still running" 
        GPIO.output(led1_pin,True);
        time.sleep(3)
        sys.exit()
     
    def clear_pics(foo): #why is this function being passed an arguments?
        #suprimer les fichiers du dossier au démarrage
    	files = glob.glob(config.file_path + '*')
    	for f in files:
    		os.remove(f) 
    	#Allumer light les lumières en série pour montrer complétées
    	print "Deleted previous pics"
    	GPIO.output(led1_pin,False); #éteindre les lumières
    	GPIO.output(led2_pin,False);
    	GPIO.output(led3_pin,False);
    	GPIO.output(led4_pin,False)
    	pins = [led1_pin, led2_pin, led3_pin, led4_pin]
    	for p in pins:
    		GPIO.output(p,True); 
    		sleep(0.25)
    		GPIO.output(p,False);
    		sleep(0.25)
     
    def is_connected():
      try:
        # Voir si nous pouvons résesoudre le nom d'hote - Nous dit si il y a
        # un DNS
        host = socket.gethostbyname(test_server)
        # Connecter à l'hôte - nous dit si l'hôte est en faite
        # accessible
        s = socket.create_connection((host, 80), 2)
        return True
      except:
         pass
      return False    
     
    def init_pygame():
        pygame.init()
        size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
        pygame.display.set_caption('Photo Booth Pics')
        pygame.mouse.set_visible(False) #hide the mouse cursor	
        return pygame.display.set_mode(size, pygame.FULLSCREEN)
     
    def show_image(image_path):
        screen = init_pygame()
        img=pygame.image.load(image_path) 
        img = pygame.transform.scale(img,(transform_x,transfrom_y))
        screen.blit(img,(offset_x,offset_y))
        pygame.display.flip()
     
    def display_pics(jpg_group):
        # this section is an unbelievable nasty hack - for some reason Pygame
        # needs a keyboardinterrupt to initialise in some limited circs (second time running)
     
        class Alarm(Exception):
            pass
        def alarm_handler(signum, frame):
            raise Alarm
        signal(SIGALRM, alarm_handler)
        alarm(3)
        try:
            screen = init_pygame()
     
            alarm(0)
        except Alarm:
            raise KeyboardInterrupt
        for i in range(0, replay_cycles): #montrer les phtotos un nomnre de fois
    		for i in range(1, total_pics+1): #montrer chaque phtots
    			filename = config.file_path + jpg_group + "-0" + str(i) + ".jpg"
                            show_image(filename);
    			time.sleep(replay_delay) # pause 
     
    # Définir la prise de photo lorsque la fonction gros bouton est pressé
    def start_photobooth(): 
    	################################# Begin Step 1 ################################# 
    	show_image(real_path + "/blank.png")
    	print "Get Ready"
    	GPIO.output(led1_pin,True);
    	show_image(real_path + "/instructions.png")
    	sleep(prep_delay) 
    	GPIO.output(led1_pin,False)
     
    	show_image(real_path + "/blank.png")
     
    	camera = picamera.PiCamera()
    	pixel_width = 500 #Utilisation d'une taille plus petite pour traiter plus rapidement, et Tumblr ne prendra jusqu'à 500 pixels de large pour les gifs animés
    	pixel_height = monitor_h * pixel_width // monitor_w
    	camera.resolution = (pixel_width, pixel_height) 
    	camera.vflip = True
    	camera.hflip = False
    	camera.saturation = -100 # modifier cette ligne si vous voulez des images en couleur
    	camera.start_preview()
     
    	sleep(2) #evite de chauffer la camera
     
    	################################# Begin Step 2 #################################
    	print "Taking pics" 
    	now = time.strftime("%Y-%m-%d-%H:%M:%S") #get the current date and time for the start of the filename
    	try: #prendre les photos
    		for i, filename in enumerate(camera.capture_continuous(config.file_path + now + '-' + '{counter:02d}.jpg')):
    			GPIO.output(led2_pin,True) #Activer la LED
    			print(filename)
    			sleep(0.25) #Eteindre la LED le temps d'un BIT
    			GPIO.output(led2_pin,False) #Eteindre la LED
    			sleep(capture_delay) # Pause entre 2 prises de phtos
    			if i == total_pics-1:
    				break
    	finally:
    		camera.stop_preview()
    		camera.close()
    	########################### Begin Step 3 #################################
    	print "Creating an animated gif" 
    	if post_online:
    		show_image(real_path + "/uploading.png")
    	else:
    		show_image(real_path + "/processing.png")
     
    	GPIO.output(led3_pin,True) #Activer la LED
    	graphicsmagick = "gm convert -delay " + str(gif_delay) + " " + config.file_path + now + "*.jpg " + config.file_path + now + ".gif" 
    	os.system(graphicsmagick) #Creer le  .gif
    	print "Uploading to tumblr. Please check " + config.tumblr_blog + ".tumblr.com soon."
     
    	if post_online: # tdésactiver l'affichage des photos en ligne dans les déclarations de variables en haut de ce document
    		connected = is_connected() #Verifie pour savoir si il y a une connection internet
    		while connected: 
    			try:
    				file_to_upload = config.file_path + now + ".gif"
    				client.create_photo(config.tumblr_blog, state="published", tags=["drumminhandsPhotoBooth"], data=file_to_upload)
    				break
    			except ValueError:
    				print "Oops. No internect connection. Upload later."
    				try: #Créer un fichier texte comme note pour télécharger le .gif plus tard
    					file = open(config.file_path + now + "-FILENOTUPLOADED.txt",'w')   #ssayer de créer un nouveau fichier ou en ouvrir un
    					file.close()
    				except:
    					print('Something went wrong. Could not write file.')
    					sys.exit(0) #  quitter Python
    	GPIO.output(led3_pin,False) #Eteindre la LED
     
    	########################### Begin Step 4 #################################
    	GPIO.output(led4_pin,True) #Activer la LED
    	try:
    		display_pics(now)
    	except Exception, e:
    		tb = sys.exc_info()[2]
    		traceback.print_exception(e.__class__, e, tb)
    	pygame.quit()
    	print "Done"
    	GPIO.output(led4_pin,False) #Eteindre la LED
     
    	if post_online:
    		show_image(real_path + "/finished.png")
    	else:
    		show_image(real_path + "/finished2.png")
     
    	time.sleep(restart_delay)
    	show_image(real_path + "/intro.png");
     
    ####################
    ### Main Program ###
    ####################
     
    # Quand un front descendant est détecté sur button2_pin et button3_pin, quelles que soient   
    # autre à qui se passe dans le programme, leur fonction sera exécuté   
    GPIO.add_event_detect(button2_pin, GPIO.FALLING, callback=shut_it_down, bouncetime=300) 
     
    #choose l'une des deux lignes suivantes Mettre le sympbole commentaire# sur la ligne n
    GPIO.add_event_detect(button3_pin, GPIO.FALLING, callback=exit_photobooth, bouncetime=300) #Utiliser le troisième bouton pour quitter python. Bon, tout en développant
    #GPIO.add_event_detect(button3_pin, GPIO.FALLING, callback=clear_pics, bouncetime=300) #Utiliser le troisième bouton pour effacer les photos stockées sur la carte SD des événements précédents
     
    # Supprimer des fichiers dans le dossier au démarrage
    files = glob.glob(config.file_path + '*')
    for f in files:
        os.remove(f)
     
    print "Photo booth app running..." 
    GPIO.output(led1_pin,True); #Activer les LED pour montrer que l'application est en marche
    GPIO.output(led2_pin,True);
    GPIO.output(led3_pin,True);
    GPIO.output(led4_pin,True);
    time.sleep(3)
    GPIO.output(led1_pin,False); #Eteindre les LED
    GPIO.output(led2_pin,False);
    GPIO.output(led3_pin,False);
    GPIO.output(led4_pin,False);
     
    show_image(real_path + "/intro.png");
     
    while True:
            GPIO.wait_for_edge(button1_pin, GPIO.FALLING)
    	time.sleep(0.2) #debounce
    	start_photobooth()
    VinsS
    je regarde le code cette après midi

    Merci

    LOIC

  4. #4
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Dans la version française tu as transformé incorrectement la ligne 160.

  5. #5
    Candidat au Club
    Homme Profil pro
    Debutant
    Inscrit en
    Janvier 2016
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Debutant

    Informations forums :
    Inscription : Janvier 2016
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    Citation Envoyé par VinsS Voir le message
    Dans la version française tu as transformé incorrectement la ligne 160.
    en français
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    for i in range(1, total_pics+1): #montrer chaque photos
    en anglais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    for i in range(1, total_pics+1): #show each pic
    mais je ne vois pas la différence

  6. #6
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Sorry, mon clavier s'est trompé, c'est la ligne 260
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    GPIO.add_event_detect(button3_pin, GPIO.FALLING, callback=exit_putilisé on hotobooth, bouncetime=300)

  7. #7
    Candidat au Club
    Homme Profil pro
    Debutant
    Inscrit en
    Janvier 2016
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Debutant

    Informations forums :
    Inscription : Janvier 2016
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    Citation Envoyé par VinsS Voir le message
    Sorry, mon clavier s'est trompé, c'est la ligne 260
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    GPIO.add_event_detect(button3_pin, GPIO.FALLING, callback=exit_putilisé on hotobooth, bouncetime=300)
    oui je vais le modifié
    merci

  8. #8
    Candidat au Club
    Homme Profil pro
    Debutant
    Inscrit en
    Janvier 2016
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Debutant

    Informations forums :
    Inscription : Janvier 2016
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    Bonsoir

    Je viens de prendre connaissance du code

    J'ai pris le temps d'essayer de comprendre le langage python car je suis vraiment novice

    j'ai copier le code et je vais insérer certain passage pour remplacer la camera pi
    il faut que j'arrive a écrire cela


    Attendre une pression sur un bouton
    Une fois que le bouton est enfoncé, la première lumière pendant quelques secondes, signifie aux utilisateurs de se préparer
    Montrer la vidéo en temps réel aperçu sur l'écran
    Prendre la photo et telecharger, puis la renommer avec un horodatage dans le nom de fichier
    Allumer la lumière "Pose"
    Répétez quatre fois
    Traiter les images
    Éteignez l'écran de prévisualisation
    Clignoter la lumière "Téléchargement"
    Mélanger les quatre images JPEG dans une nouvelle animation gif (envisager d'ajouter un pied de page à toutes les photos)
    Télécharger sur Tumblr (depuis Tumblr gère nativement gifs animés)
    Arrête de clignoter la lumière
    Fini
    Allumer la lumière "Fait" pendant quelques secondes
    Rejouer les images sur l'écran à quelques reprises pour la gratification instantanée des clients
    Attendre une autre appuyez sur la touche
    Fermer


    et si je ne me trompe pas gphoto intervient que lors :
    - de l'affichage en temps reel
    - de la prise de vue
    - du téléchargement

    je continu
    Bonne soiree

  9. #9
    Candidat au Club
    Homme Profil pro
    Debutant
    Inscrit en
    Janvier 2016
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Debutant

    Informations forums :
    Inscription : Janvier 2016
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    Bonjour
    je continu sur mon projet malgré le peu de temps que je dispose, j'ai trouvé un code "exemple" dans GITHUB Python-gphoto2 mais cela ne fonctionne pas correctement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    !/usr/bin/env python
     
    # python-gphoto2 - Python interface to libgphoto2
    # http://github.com/jim-easterbrook/python-gphoto2
    # Copyright (C) 2015  Jim Easterbrook  jim@jim-easterbrook.me.uk
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    from __future__ import print_function
     
    import logging
    import os
    import subprocess
    import sys
     
    import gphoto2 as gp
     
    def main():
        logging.basicConfig(
            format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
        gp.check_result(gp.use_python_logging())
        context = gp.gp_context_new()
        camera = gp.check_result(gp.gp_camera_new())
        gp.check_result(gp.gp_camera_init(camera, context))
        print('Capturing image')
        file_path = gp.check_result(gp.gp_camera_capture(
            camera, gp.GP_CAPTURE_IMAGE, context))
        print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))
        target = os.path.join('/tmp', file_path.name)
        print('Copying image to', target)
        camera_file = gp.check_result(gp.gp_camera_file_get(
                camera, file_path.folder, file_path.name,
                gp.GP_FILE_TYPE_NORMAL, context))
        gp.check_result(gp.gp_file_save(camera_file, target))
        subprocess.call(['xdg-open', target])
        gp.check_result(gp.gp_camera_exit(camera, context))
        return 0
     
    if __name__ == "__main__":
        sys.exit(main())
    par contre, sous terminal la commande:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    gphoto2 --capture-image-and-download
    cela fonctionne tres bien comme l'ensemble des commandes en directe

    Si une personne peux m'expliquer
    En vous remerciant d'avance

    Loic

  10. #10
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 287
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 287
    Points : 36 776
    Points
    36 776
    Par défaut
    Salut,

    Citation Envoyé par eole_35 Voir le message
    je continu sur mon projet malgré le peu de temps que je dispose, j'ai trouvé un code "exemple" dans GITHUB Python-gphoto2 mais cela ne fonctionne pas correctement
    "cela ne fonctionne pas correctement" sans illustration de ce que vous essayez de faire et les messages d'erreurs que çà retourne...

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  11. #11
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Non, le binding que tu as trouvé ne prend en charge que la fonctionnalité de récupération des images de l'appareil et aucune autre.

    Donc pas de capture avec python-gphoto2.

    Mais ça fonctionne très bien avec subprocess.

  12. #12
    Candidat au Club
    Homme Profil pro
    Debutant
    Inscrit en
    Janvier 2016
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Debutant

    Informations forums :
    Inscription : Janvier 2016
    Messages : 8
    Points : 2
    Points
    2
    Par défaut
    Je me suis offert une camera pi et lors de son utilisation avec le code de base, j'ai une erreur de code lors de son lancement via terminal que je ne comprends pas

    Si quelqu'un peux me l'expliquer je le remercie d'avance

    Loic

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    Traceback (most recent call last):
     File "drumminhands_photobooth.py", line 256, in <module>
       GPIO.add_event_detect(button2_pin, GPIO.FALLING, callback=shut_it_down, bouncetime=300) 
    AttributeError: 'module' object has no attribute 'add_event_detect'
    Ended abruptly
    Error in atexit._run_exitfuncs:
    Traceback (most recent call last):
     File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
       func(*targs, **kargs)
     File "drumminhands_photobooth.py", line 79, in cleanup
       GPIO.cleanup()
    AttributeError: 'module' object has no attribute 'cleanup'
    Error in sys.exitfunc:
    Traceback (most recent call last):
     File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
       func(*targs, **kargs)
     File "drumminhands_photobooth.py", line 79, in cleanup
       GPIO.cleanup()
    AttributeError: 'module' object has no attribute 'cleanup'

Discussions similaires

  1. [Lazarus] [Raspberry Pi2] Développement d'applications
    Par BYLS07 dans le forum Lazarus
    Réponses: 2
    Dernier message: 16/11/2015, 18h33
  2. Raspberry Pi2 et windows Iot
    Par mermich dans le forum Raspberry Pi
    Réponses: 2
    Dernier message: 25/05/2015, 21h52
  3. [Lazarus] Raspberry Pi2 : Unit Rpi_hal
    Par BYLS07 dans le forum Lazarus
    Réponses: 0
    Dernier message: 22/04/2015, 15h58
  4. Raspberry pi2 + dalle tactile
    Par satore dans le forum Raspberry Pi
    Réponses: 0
    Dernier message: 17/04/2015, 15h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo