In [0]:
import time
import picamera

with picamera.PiCamera() as camera:
    camera.start_preview()
    camera.hflip = True
    camera.vflip = True
    time.sleep(2)
    camera.capture('image.jpg')
    camera.stop_preview()
    
# preview
from IPython.display import Image
Image(filename='image.jpg')

Image in a dark

Record a video


In [0]:
import picamera
from time import sleep
from fractions import Fraction

with picamera.PiCamera() as camera:
    camera.hflip = True
    camera.vflip = True
    camera.resolution = (1280, 720)
    # Set a framerate of 1/6fps, then set shutter
    # speed to 6s and ISO to 800
    camera.framerate = Fraction(1, 6)
    camera.shutter_speed = 6000000
    camera.exposure_mode = 'off'
    camera.iso = 800
    # Give the camera a good long time to measure AWB
    # (you may wish to use fixed AWB instead)
    sleep(10)
    # Finally, capture an image with a 6s exposure. Due
    # to mode switching on the still port, this will take
    # longer than 6 seconds
    camera.capture('dark.jpg')
    
from IPython.display import Image
Image(filename='dark.jpg')

# install MP4Box program apt-get install gpac


In [0]:
import os
import picamera

#cleanup
try:
    os.unlink('my_video.mp4')
    os.unlink('my_video.h264')
except: pass
    
with picamera.PiCamera() as camera:
    camera.hflip = True
    camera.vflip = True
    camera.resolution = (640, 480)
    camera.start_recording('my_video.h264')
    camera.wait_recording(10)
    camera.stop_recording()
    
from subprocess import check_call
check_call("MP4Box -fps 30 -add my_video.h264 my_video.mp4", shell=True)

from IPython.display import HTML
HTML("""
<video width="320" height="240" controls>
  <source src="files/my_video.mp4" type="video/mp4">
</video>
""")

Hihg speed video


In [0]:
# doesnt work yet
import os
import picamera

try:
    os.unlink('my_video.mp4')
    os.unlink('my_video.h264')
except: pass

with picamera.PiCamera() as camera:
    camera.hflip = True
    camera.vflip = True
    camera.resolution = (640, 480)
    camera.framerate = 90
    camera.start_recording('my_video.h264')
    camera.wait_recording(10)
    camera.stop_recording()
    
from subprocess import check_call
check_call("MP4Box -fps 30 -add my_video.h264 my_video.mp4", shell=True)

from IPython.display import HTML
HTML("""
<video width="320" height="240" controls>
  <source src="files/my_video.mp4" type="video/mp4">
</video>
""")

Timelapse video

sudo apt-get -y install libav-tools


In [0]:
from subprocess import check_call
check_call("rm -rf output/*", shell=True)

import time
import picamera
with picamera.PiCamera() as camera:
    camera.resolution = (1240, 1024)
    camera.start_preview()
    try:
        for i, filename in enumerate(camera.capture_continuous('output/image{counter:02d}.jpg')):
            time.sleep(1)
            if i == 10:
                break
    finally:
        camera.stop_preview()
 

check_call("avconv -r 1 -i output/image%02d.jpg -r 10 -vcodec libx264 -crf 10 -g 15 output/tl.mp4", shell=True)

In [0]: