pygame图像显示溢出? (rpi照相亭)

时间:2016-05-17 01:04:40

标签: python image camera raspberry-pi pygame

设置:您好,我已经构建了一个由Raspberry Pi(如果重要的话,型号为B B)提供动力的照相平板电脑。要点是rpi相机在屏幕上显示实时图像,以便用户可以进行设置。当他们按下绿色大按钮时,它会倒计时,然后拍摄两张照片。其中一张照片通过系绳连接到我的数码单反相机。这是我最终实际使用的高质量照片。另一张照片是用rpi相机拍摄的。它在屏幕上播放了几秒钟,以便用户可以看到它的结果。

问题:在大约100张照片(~100 MB图像)后,它会停止播放屏幕上的rpi图像。其他一切都很好。它仍然拍摄我的数码单反相机上的照片,它甚至还记录了rpi相机的图像,它只是没有显示它。我还应该注意,它不会抛出任何错误或异常。 SD卡有足够的可用空间,所以这不是问题。此外,如果我退出python并再次打开它,它们一切正常(对于前100张左右的图像)。

我说实话,我不太了解pygame库......任何指针都会受到赞赏。谢谢!

代码:

import time
import picamera
import RPi.GPIO as GPIO
import atexit
import os
import sys
import pygame

#######################
### Variables Config ##
#######################

big_button = 5
led = 26
stop_button = 4
focus = 16
shoot = 12

####################
### Other Config ###
####################

GPIO.setmode(GPIO.BCM)
GPIO.setup(led,GPIO.OUT)
GPIO.setup(focus,GPIO.OUT)
GPIO.setup(shoot,GPIO.OUT)
GPIO.setup(big_button,GPIO.IN)
GPIO.setup(stop_button,GPIO.IN)
GPIO.setup(32, GPIO.OUT, initial=False)

camera = picamera.PiCamera()
camera.annotate_text_size = 70
camera.annotate_background = picamera.Color('white')
camera.annotate_foreground = picamera.Color('black')

######################
### Build a Screen ###
######################

pygame.init()
screen = pygame.display.set_mode((pygame.display.Info().current_w, pygame.display.Info().current_h), pygame.FULLSCREEN)
black = pygame.Color(0 , 0, 0)

#################
### Functions ###
#################

def shut_it_down(channel):
    print('Exiting!')
    camera.stop_preview()
    GPIO.output(led,0)
    GPIO.cleanup()
    camera.close()
    pygame.quit()
    os._exit(0)
    #os.system("sudo halt")

def take_photo():
    now = time.strftime("%Y-%m-%d-%H:%M:%S")
    try:
        GPIO.output(led, 0)
        GPIO.output(focus, 1)
        camera.annotate_text = '   Get ready!   '
        print('Get ready!')
        time.sleep(3)
        camera.annotate_text = '   I will count down from 5...   '
        print('Counting down')
        time.sleep(3)
        camera.annotate_text = '   5   '
        print('5')
        time.sleep(1)
        camera.annotate_text = '   4   '
        print('4')
        time.sleep(1)
        camera.annotate_text = '   3   '
        print('3')
        time.sleep(1)
        camera.annotate_text = '   2   '
        print('2')
        time.sleep(1)
        camera.annotate_text = '   1   '
        print('1')
        time.sleep(1)
        camera.annotate_text = ''
        print('Taking photo')
        GPIO.output(focus, 0)
        screen.fill(black)
        pygame.display.update()
        camera.stop_preview()
        GPIO.output(shoot, 1)
        camera.capture('Photos/weddingshots-' + now + '.jpg')
        time.sleep(1)
        GPIO.output(shoot, 0)

    finally:
        display_photo(now)

def display_photo(date):
    try:
        print('Displaying photo')
        img = pygame.image.load('Photos/weddingshots-' + date + '.jpg').convert()
        screen.blit(img, (0,0))
        pygame.display.update()
        time.sleep(10)
        screen.fill(black)
        pygame.display.update()
        camera.start_preview()

    except:
        print('Could not find photo')
        screen.fill(black)
        pygame.display.update()
        camera.start_preview()

    finally:
        GPIO.output(led, 1)

####################
### Main Program ###
####################

GPIO.add_event_detect(stop_button, GPIO.RISING, callback=shut_it_down, bouncetime=300)

GPIO.output(led, 1)
GPIO.output(32, 0)
print('Running')
camera.start_preview()

while True:
    GPIO.wait_for_edge(big_button, GPIO.RISING)
    time.sleep(0.2)
    take_photo()

0 个答案:

没有答案