Taking pictures and video with Python 3 and Raspberry Pi Camera module

Plug the camera module into the designated port of your Raspberry Pi. Then enable the camera via raspi-config. There are many tutorials on how to do this. We don’t want to bore you.

Install picamera library for Python 3: sudo apt-get install python3-picamera
Write and save the following in a python file: sudo nano pitest.py

import picamera
from time import sleep

camera = picamera.PiCamera()

camera.capture('image.jpg') #taking a picture and save it in image.jpg

camera.start_preview()
camera.vflip = True #vertical flip if you have your cam turned upside down like ours
camera.hflip = True #horizontal flip if you have your cam turned upside down like ours

camera.brightness = 60

#video recording
camera.start_recording('video.h264')
sleep(5)
camera.stop_recording()

Run it: sudo python3 camtest.py

Simple and awesome right?!

Now you can combine it with pan & tilt kit and mjpg streamer for basic surveillance cam project.

Further reading:

(Visited 1,166 times, 1 visits today)