How to use Raspberry Pi Camera via Python

What we do
What we need
How we do (Hardware)
How we do (Software)
Still shots Outcome
What we do

There are lots of ways to install and use Pi camera, but at this post we're going to handle this with Python!

How we do (Hardware)

Please insert Pi camera's the other end into Pi's camera slot.

 

please note the pin order is important so carefully connect it in right order! 🙂

 

There are some pictures for raspberry pi B and raspberry pi 2 B.

 

  • Connect with Raspberry Pi Model B

 

  • Connect with Raspberry Pi 2 Model B

 

How we do (Software)
  1. Enable Pi camera via Raspberry Pi Configuration
  2. Testing taking still image and recording working
  3. Install Python drivers for Pi cam (http://picamera.readthedocs.io/en/release-1.9)
  4. Sample Python script to test Pi cam

  • Enable Pi camera via Raspberry Pi Configuration

 

sudo raspi-config

and choose 'Enable Camera', enter and finish.

 


  • Testing taking still image and recording working

 

To test capturing still image,

raspistill -o testpicture.jpg

To test video capturing,

raspivid -o testvideo.h264



  • Install Python drivers for Pi cam (http://picamera.readthedocs.io/en/release-1.9)

 

Now, we're ready to install Python drivers

sudo apt-get install python-picamera

if you're working on Python3,

sudo apt-get install python3-picamera

More information and options are available at   PICAMERA

 


  • Sample Python script to test Pi cam

 

You can write and test Python script with Raspberry Pi Camera from now on.

 

Start a preview for 10 secs

import time import picamera 
camera = picamera.PiCamera()

try:
camera.start_preview()
time.sleep(10)
camera.stop_preview()
finally:
camera.close()

Capturing to a file

import time 
import picamera

with picamera.PiCamera() as camera:
camera.resolution = (1024, 768)
camera.start_preview()
# Camera warm-up time
time.sleep(2)
camera.capture('sampleImage.jpg')

Recoding video to a file

import picamera 

with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
camera.start_recording('testing_video.h264')
camera.wait_recording(60)
camera.stop_recording()

There are tons of useful examples here at    PICAMERA

 

please look into it!

Still shots Outcome

We've just installed and learned how to use Pi camera basically.

 

so now fully ready to extend your projects with this raspberry pi with awesome camera!

 

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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