Use Python Code to Preview the Camera Image

Try out the camera preview by using Python code to activate it.

Step 1

Open Python 3 from the main menu:

Step 2

Open a new file and save it as 'photobooth.py'. It's important that you don't save it as 'picamera.py' – a file with that name is used by the system already.

Step 3

Enter the following code:

This code uses the PiCamera code library. This code library is filled with tools that make it easier for you to control the PiCamera with Python. 

Step 4

Use 'Ctrl+S' to save your program and run it by pressing 'F5'. The live camera preview will fill the screen.

The camera preview should be shown for 10 seconds and then close. Move the camera around to preview what the camera sees.

Step 5

If your preview was upside down, you can rotate it by changing the code to:

You can rotate the image by 90, 180 or 270 degrees, or you can set it to 0 to reset.

Step 6

You can change the transparency (how see-through something is) of the camera preview by setting an alpha level. Try this example code:

You can set alpha to be any value between 0 and 255.