fa001
Posts: 89
Joined: Wed Jan 02, 2013 8:25 pm

Re: Photo Booth Help

Mon Jan 13, 2020 5:25 pm

The use of tabs vs spaces depends on the editor/environment you are using. If you are using Thorny and it wants spaces change to spaces. You will just have to remember to use spaces instead of tabs if you edit the file.

home/pi should be the correct directory. If blank is not in the correct space you should get an error message that it could not be found. That message will show where the program is looking for it.

I am a little confused, are you trying to run the program from within Thorny or are you using the command line?

User avatar
RottieGirl
Posts: 82
Joined: Sun Mar 05, 2017 3:36 pm
Location: Manitoba, Canada

Re: Photo Booth Help

Tue Jan 14, 2020 5:51 pm

I'm just trying to run it. I click onto the file to open it & Thonny opens it up.
Raspbian has changed a bit from when you helped me with this.

fa001
Posts: 89
Joined: Wed Jan 02, 2013 8:25 pm

Re: Photo Booth Help

Tue Jan 14, 2020 6:44 pm

I have not done a lot of work through Thorny.
Perhaps you can try the command line.
Try typing sudo python3 ScriptName in the terminal. I do not remember what we ended up calling the photobooth script so replace ScriptName with the correct name of the script.

In case you do not know what the terminal is:
"On the Raspberry Pi (running Raspbian), the default terminal application is LXTerminal. This is known as a 'terminal emulator', this means that it emulates the old style video terminals (from before graphical user interfaces were developed) in a graphical environment. The application can be found on the Raspberry Pi desktop."

User avatar
RottieGirl
Posts: 82
Joined: Sun Mar 05, 2017 3:36 pm
Location: Manitoba, Canada

Re: Photo Booth Help

Tue Jan 14, 2020 7:50 pm

I found a link on side of Thonny that had said switch, so I did that. I managed to get it running. I tried the camera & oops...the camera stuff wasn't installed. Did that. Got it running again. Tried again to take a picture. It took 1 picture, then I got an error.

Here's the error:
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
mmal: mmal_vc_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG): ENOMEM
mmal: mmal_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG)(0x2925110) (ENOMEM)

Backend terminated or disconnected.Fatal Python error: Segmentation fault

Thread 0x71fb2460 (most recent call first):
File "/home/pi/PiPhotoBooth, Button and Keyboard.py", line 90 in slideshow
File "/usr/lib/python3.7/threading.py", line 865 in run
File "/usr/lib/python3.7/threading.py", line 917 in _bootstrap_inner
File "/usr/lib/python3.7/threading.py", line 885 in _bootstrap

Current thread 0x76febad0 (most recent call first):
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 1331 in _get_framesize
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 1325 in __repr__
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 889 in export_value
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 903 in export_variables
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 950 in _export_stack
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1039 in _prepare_user_exception
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1157 in wrapper
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1198 in execute_source
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 840 in _execute_source
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 826 in _execute_file
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 387 in _cmd_Run
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 195 in handle_command
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 137 in mainloop
File "/usr/lib/python3/dist-packages/thonny/backend_launcher.py", line 76 in <module> Use 'Stop/Restart' to restart ...

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Python 3.7.3 (/usr/bin/python3)
>>> %Run 'PiPhotoBooth, Button and Keyboard.py'
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/PiPhotoBooth, Button and Keyboard.py", line 93, in slideshow
displayImage(randomFile)
File "/home/pi/PiPhotoBooth, Button and Keyboard.py", line 80, in displayImage
img = pygame.image.load(file)
pygame.error: Unsupported image format

mmal: mmal_vc_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG): ENOMEM
mmal: mmal_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG)(0x1f57110) (ENOMEM)

Backend terminated or disconnected.Fatal Python error: Segmentation fault

Current thread 0x76fe4ad0 (most recent call first):
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 1331 in _get_framesize
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 1325 in __repr__
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 889 in export_value
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 903 in export_variables
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 950 in _export_stack
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1039 in _prepare_user_exception
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1157 in wrapper
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 1198 in execute_source
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 840 in _execute_source
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 826 in _execute_file
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 387 in _cmd_Run
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 195 in handle_command
File "/usr/lib/python3/dist-packages/thonny/backend.py", line 137 in mainloop
File "/usr/lib/python3/dist-packages/thonny/backend_launcher.py", line 76 in <module> Use 'Stop/Restart' to restart ...

User avatar
RottieGirl
Posts: 82
Joined: Sun Mar 05, 2017 3:36 pm
Location: Manitoba, Canada

Re: Photo Booth Help

Tue Jan 14, 2020 8:14 pm

Trying to figure out how to actually download Python 3. Maybe that will help. Just can't get it to go

fa001
Posts: 89
Joined: Wed Jan 02, 2013 8:25 pm

Re: Photo Booth Help

Tue Jan 14, 2020 8:21 pm

Python3 should be already part of the system.
You should do an update / upgrade of your system:

In a terminal window.

First, update your system's package list by entering the following command:

sudo apt update

Next, upgrade all your installed packages to their latest versions with the following command:

sudo apt full-upgrade

hippy
Posts: 6497
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Photo Booth Help

Tue Jan 14, 2020 8:41 pm

RottieGirl wrote:
Tue Jan 14, 2020 7:50 pm
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
mmal: mmal_vc_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG): ENOMEM
mmal: mmal_port_enable: failed to enable port vc.ril.image_encode:out:0(JPEG)(0x2925110) (ENOMEM)

Backend terminated or disconnected.Fatal Python error: Segmentation fault
I believe "ENOMEM" are "Out of Memory" errors, 'mmal' fails, exits, whatever is expecting that to have work then goes down in flames.

fa001
Posts: 89
Joined: Wed Jan 02, 2013 8:25 pm

Re: Photo Booth Help

Tue Jan 14, 2020 9:42 pm

I again suggest that you try it from a terminal window as suggested above. Or if you think that memory is an issue exit the GUI and run from the command line.

User avatar
joelostinspace
Posts: 39
Joined: Sat Aug 10, 2019 2:51 pm
Location: Earth

Re: Photo Booth Help

Wed Jan 15, 2020 5:29 am

@rottiegirl maybe you pi is fried due to excessive heat- try and take a simple photo

Code: Select all

from time import sleep
from picamera import PiCamera
import datetime as dt

cam= PiCamera()
cam.resolution= (1024, 768)
cam.start_preview()
sleep(3)
image_name= dt.datetime.now().strftime('%Y-%m-%d-%H_%M_%S')+'.jpg'
cam.capture(image_name)
sleep(2)
cam.stop_preview()

I just saw this thread and copied the code on page 2- I missed the conversation about the blank jpeg so I ran it and it hung on the processing the image so I modified the code to create a new blank image. You need a folder named images just like before, I commented out the print

Code: Select all

# Raspberry Pi - Photo Booth
#
# Copyright (c) 2014, John Croucher - www.jcroucher.com
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, 
# are permitted provided that the following conditions are met:
# 
# 1. Redistributions of source code must retain the above copyright notice, this 
# list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright notice, this 
# list of conditions and the following disclaimer in the documentation and/or other 
# materials provided with the distribution.
# 
# 3. Neither the name of the copyright holder nor the names of its contributors may 
# be used to endorse or promote products derived from this software without specific 
# prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
# THE POSSIBILITY OF SUCH DAMAGE.


import RPi.GPIO as GPIO
import time
from threading import Thread
import picamera
import PIL
from PIL import Image
# import cups
import os
import sys
import pygame
import random

slideshowRunning = True
basewidth = 177 # Used for merging the photos onto one
printPhoto = False
imgPath = './images/tmp'
input_state = True


# Push button for starting the photo sequence
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Display surface
pygame.init()

pygame.mouse.set_visible(0)

w = pygame.display.Info().current_w
h = pygame.display.Info().current_h

screenSize = (w, h)

screen = pygame.display.set_mode(screenSize, pygame.FULLSCREEN) # Full screen the display with no window


# Used for loading a random photo for the slideshow
def random_file(dir):
	files = [os.path.join(path, filename)
		for path, dirs, files in os.walk(dir)
		for filename in files]

	return random.choice(files)


def displayImage(file):
	screen.fill((0,0,0))

	img = pygame.image.load(file) 
	img = pygame.transform.scale(img,(w,h)) # Make the image full screen
	screen.blit(img,(0,0))
	pygame.display.flip() # update the display


# Display a random image
def slideshow():
	while True:

		if slideshowRunning == True:
	
			checkEvents()

			randomFile = random_file('./images/')
			
			displayImage(randomFile)
	
			time.sleep(2) # pause 

# Handle events like keypress
def checkEvents():
	global input_state
	for event in pygame.event.get():
		# Shutdown the application if quit event or escape key is pressed
		if event.type == pygame.QUIT or ( event.type is pygame.KEYDOWN and event.key == pygame.K_ESCAPE ):
			slideshowRunning = False
			pygame.quit()
			sys.exit()

		if event.type is pygame.KEYDOWN and event.key == pygame.K_f: # Switch the display mode between full screen and windowed
			if screen.get_flags() & pygame.FULLSCREEN:
				pygame.display.set_mode(screenSize)
			else:
				pygame.display.set_mode(screenSize,pygame.FULLSCREEN)
		if event.type is pygame.KEYDOWN and event.key == pygame.K_p:
			input_state = False

# On screen text message
def displayStatus(status):
	screen.fill((0,0,0))
	
	font = pygame.font.SysFont("monospace",24)
	text = font.render(status,True,(255,255,255))

	# Display in the center of the screen
	textrect = text.get_rect()
	textrect.centerx = screen.get_rect().centerx
	textrect.centery = screen.get_rect().centery

	screen.blit(text,textrect)
	
	pygame.display.flip() # update the display
	

# Merge all photos onto one ready for printing
def combineImages():
	displayStatus('Please wait. Processing Images')
			
	# Do the merging
	blankImage = Image.new("RGB",(354,280))

	image1 = Image.open(imgPath + '/image1.jpg')		
	image1 = image1.resize((177,140),PIL.Image.ANTIALIAS)
	blankImage.paste(image1, (0,4))

	image2 = Image.open(imgPath + '/image2.jpg')		
	image2 = image2.resize((177,140),PIL.Image.ANTIALIAS)
	blankImage.paste(image2, (0,144))

	image3 = Image.open(imgPath + '/image3.jpg')		
	image3 = image3.resize((177,140),PIL.Image.ANTIALIAS)
	blankImage.paste(image3, (177,4))

	image4 = Image.open(imgPath + '/image4.jpg')		
	image4 = image4.resize((177,140),PIL.Image.ANTIALIAS)
	blankImage.paste(image4, (177,144))

	blankImage.save(imgPath + '/combined.png', 'PNG')


# Print the photo
def printPhoto():
	global input_state
	if printPhoto == True:
		displayStatus('Printing')

		conn = cups.Connection()
		printers = conn.getPrinters()
		printer_name = printers.keys()[0]
		conn.printFile(printer_name, imgPath + '/combined.jpg',"TITLE",{})

		time.sleep(2)

# Thread for the slideshow
t = Thread(target=slideshow)
t.start()

with picamera.PiCamera() as camera:

	while True:
		
		checkEvents() # Needed to check for keypresses and close signals

		# Putton press to start the photo sequence
		# input_state = GPIO.input(17)
		if input_state == False:
	
			# Stop the slideshow
			slideshowRunning = False

			# Start the camera preview
			camera.start_preview()

			# Make the destination path for the photos
			if not os.path.exists(imgPath):
				os.mkdir(imgPath)

			# Loop through the 4 photo taking sequences
			for pNum in range (1,5):
				camera.annotate_text = 'Photo ' + str(pNum) + ' of 4'
				time.sleep(1)

				for countDown in range (3,0,-1):
					camera.annotate_text = str(countDown)
					time.sleep(1)
	
				camera.annotate_text = ''
				camera.capture( imgPath + '/image' + str(pNum) + '.jpg')
				time.sleep(1)
			
			# Stop the camera preview so we can return to the pygame surface
			camera.stop_preview()

			combineImages()

			#printPhoto()

			displayImage( imgPath + '/combined.png' ) # Display a preview of the combined image

			time.sleep(5)

			# Move the temp files to a new dir based on the current timestamp so they can be retrieved later
			os.rename(imgPath, './images/' + str(int(time.time())))

			# Restart the slideshow
			slideshowRunning = True

			input_state = True	
			


I would rather live in a world where my life is surrounded by mystery than a world so small that my mind could comprehend it.


--- Harry Emerson Fosdick

User avatar
RottieGirl
Posts: 82
Joined: Sun Mar 05, 2017 3:36 pm
Location: Manitoba, Canada

Re: Photo Booth Help

Wed Jan 15, 2020 6:29 pm

@joelostinspace, I'll give it a try & let you know how everything goes.

I know that when I had used it on our anniversary, 2 1/2yrs ago, the temp icon came on. We put a fan on it to cool it down. Hope it didn't kill it.

Update: test picture work. Script for photo booth did not.

User avatar
joelostinspace
Posts: 39
Joined: Sat Aug 10, 2019 2:51 pm
Location: Earth

Re: Photo Booth Help

Thu Jan 16, 2020 5:03 am

possible check your memory in this thread https://www.raspberrypi.org/forums/view ... 47#p717845

Code: Select all

 sudo apt-get install memtester
in teminal, then you can rule out your memory.

I would rather live in a world where my life is surrounded by mystery than a world so small that my mind could comprehend it.


--- Harry Emerson Fosdick

User avatar
RottieGirl
Posts: 82
Joined: Sun Mar 05, 2017 3:36 pm
Location: Manitoba, Canada

Re: Photo Booth Help

Thu Jan 16, 2020 6:18 pm

Thanks. I'll have to give it a check

Return to “Other projects”