Saturday, August 27, 2016

My Pi 3 Install Log (7): Camera module with python or from command line

In order to use OpenCV, I need a camera.

Although a normal USB camera works, I want to try the official one for these reasons:
  • dedicated camera port
  • light weight
  • look cool putting the camera inside the enclosure




Following this page:
Getting started with picamera | Raspberry Pi Learning Resources

Test camera, command line taking pictures:
$ raspistill -o image.jpg

# to see the pictures, i noticed I don't have a pic viewer yet.
# Install few more missing (non-camera-related) packages.

$ sudo apt-get install vim  # my favourite text editor
$ sudo apt-get install gpicview    # remember my jessie is a lite, no lxdm applications were installed
$ sudo apt-get install exfat-utils exfat-fuse  # to support exfat, a n file system works for both linux and osx


sudo apt-get install shasum    # for checksum


* * *

Before trying the code on this page:
http://picamera.readthedocs.io/en/release-0.6/quickstart.html

Of course, also the python-bind camera package
$ sudo apt-get install python3-picamera

Now edit this file and save as 'camera.py'
import time
import picamera

camera = picamera.PiCamera()
try:
    camera.start_preview()
    time.sleep(10)
    camera.stop_preview()
finally:
    camera.close()
and try

$ python3 camera.py

On the monitor shows a clear 8MB pixel video with less than 1/4 sec lagging.  :)

Add this line after the sleep line to take a photo:
    camera.capture()


Labels: , ,

0 Comments:

Post a Comment

<< Home