raspberry pi

Raspberry Pi Camera Setting

Rasberry pi camera

There are two ways to convert images or record Raspberry Pi Camera videos using Python scripts

You call the raspistill command with subprocess.call.

  • Or you can use the picamera module, with which you can directly control the camera using python code.

This section only covers the second variant. The first thing you need to do is get the package Install python3-picamera for Python 3 or python-picamera for Python 2 – or both versions:

In the Python code, you first create a PiCamera object, which then gives you a lot of Methods. The most important are:

  • capture: takes a photo and saves it to a file.
  • start_recording: starts a video recording and saves the film in a File.
  • stop_recording: ends the video recording.
  • close: closes access to the camera.

The following paragraphs describe only the most important functions of the picamera Module. A comprehensive reference of all classes and methods as well as a lot of examples can be found in the online documentation. There are a lot of them there advanced use cases described, e.g. the transmission of images and Videos on the network or the use of a buffer for a predefined time, whereby the oldest recording is then overwritten by the current one becomes (circular stream).

Amazon Purchase Links:

Raspberry Pi

raspberry pi 4 4gb kit

Wireless Keyboard and Mouse for raspberry pi:

Night vision Camera for Raspberry Pi:

Oled HDMI touch display for raspberry pi:

TOP10 Best Raspberry Pi Kits

Other Tools and Components:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Take pictures in its simplest form, the application of the picamera module looks like this:

capture supports the bitmap formats JPEG, PNG and GIF, among others. The method tries to identify the desired format based on the file name. At File names without an identifier must be specified using the optional parameter format = ‘xxx’. For the JPEG format, you can use the optional parameter

quality = n specify the desired image quality in the range between 1 and 100.

The default setting is 85. The higher the value, the better the image quality. At the same time, however, the size of the file also increases. The standard image size is 1920 x 1200 pixels. Do you want bigger or bigger ones smaller pictures, specify resize = (width, height). However, you have to be careful that the ratio of width and height remains unchanged – otherwise the images are distorted!

If you want the recording to be very fast, specify use_video_port = True.

The picamera module then picks up the video interface of the camera. That can be done clearly faster, but the resulting images are less sharp.

With capture_sequence you can record entire sequences of images. In the first parameter must a list of files to be passed. With the following parameters takes picamera an impressive 16 frames per second on:

capture_continuous works similarly to capture_sequence, but it is generated

The method the file names themselves. To do this, build the character string in the file name {counter} or {timestamp}. This pattern is then followed by a scrolling counter or replaced by the current date and time. Optional you can format these numbers or times with format codes for example:

You can even combine {counter} and {timestamp} in one string. capture_sequence returns a generator, so it must be used in a loop. In each loop pass, the method creates a generator object, which you do not have to evaluate further.

The following script runs endlessly until it is terminated with (Ctrl) + (C). It takes images continuously and saves them under the name image-nn.jpg, where nn is the Second of the recording time. Existing images will be overwritten.

The current directory therefore always contains image files with recordings of the last 60 seconds available.

Record videos

start_recording records videos and encodes them either in H.264 or in M-JPEG format. The desired format either has the extension .h264 or .mjpeg of the file name or must be entered with the optional parameter format = ‘h264 | mjpeg’. It is mostly before the start of the recording It is advisable to reduce the resolution with camera.resulution.

stop_recording ends the recording. When you record a video of 10 seconds , it is recommended to use wait_ instead of time.sleep bridge recording. The advantage of this method over sleep is that an error occurred during recording (e.g. insufficient space to store the or save the video file) leads to the immediate end of the program. The error message occurs with sleep on the other hand only after the specified sleep break has elapsed. The following applet takes a 10 second video at a resolution of 800 x 600 pixels on:


Play videos: On the Raspberry Pi you can play H.264 videos directly with the omxplayer. However, this program is overwhelmed with M-JPEG recordings. The remedy Installation of the video player VLC with sudo apt-get install vlc. The program is, however, quite extensive and takes up around 100 MB of storage space. In addition, the VLC version from the Raspbian package sources does not use any hardware Accelerated playback. That’s why the program is only for videos in lower resolution suitable.

Control camera parameters

There are many camera parameters you can set before taking a photo or video set, e.g. the resolution, the brightness or the contrast (see table1). A detailed reference of all parameters can be found in the API documentation of the picamera module:

Table 1: Selected camera parameters

parameter importance values Default
Brightness brightness 0 to 100 50
Contrast contrast –100 to 100 0
Crop To the crop the image (x, y, b, h) (0.0, 0.0, 1.0, 1.0)
Framerate frames per second 1 to 30 30
Resolution Image resolution (b, h) (1920, 1200)
Rotation Rotation of the image 0, 90, 180, 270 0
Saturation Color saturation –100 to 100 0
sharpness Sharpness –100 to 100 0

The following mini-program creates nine recordings with different settings:


Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button