Skip to content

Picamera2

Carter Nelson edited this page Jun 27, 2025 · 7 revisions

Info

  • Github repo
  • PDF Users Guide
  • install via apt sudo apt install -y python3-picamera2 --no-install-recommends
  • to turn off libcamera debug output:
    • export LIBCAMERA_LOG_LEVELS=3
    • Log level values:
      • "0" - DEBUG
      • "1" - INFO
      • "2" - WARN
      • "3" - ERROR
      • "4" - FATAL

Hello Word

Basic example to capture an image to file.

from picamera2 import Picamera2

picam2 = Picamera2()

picam2.configure("still")
picam2.start()
picam2.capture_file("demo.jpg")
picam2.stop()

Manual Exposure

Basic example to capture an image to file.

from picamera2 import Picamera2

picam2 = Picamera2()

picam2.configure("still")
picam2.controls.AeEnable = False
picam2.controls.AwbEnable = False
picam2.controls.ExposureTime = 10000  # time is us
picam2.start()
picam2.capture_file("demo.jpg")
picam2.stop()

Set Image Size

Basic example to capture an image to file.

from picamera2 import Picamera2

picam2 = Picamera2()

config = picam2.create_still_configuration( {"size":(1920, 1080)} )

picam2.configure(config)
picam2.start()
picam2.capture_file("demo.jpg")
picam2.stop()

Manual and Set Image Size

Basic example to capture an image to file.

from picamera2 import Picamera2

picam2 = Picamera2()

config = picam2.create_still_configuration( {"size":(1920, 1080)} )
picam2.configure(config)

picam2.controls.AeEnable = False
picam2.controls.AwbEnable = False
picam2.controls.ExposureTime = 10000

picam2.start()
picam2.capture_file("demo.jpg")
picam2.stop()

start() and stop()

  • start(config=None, show_preview=False)link
        """
        Start the camera system running.

        Camera controls may be sent to the camera before it starts running.

        The following parameters may be supplied:

        config - if not None this is used to configure the camera. This is just a
            convenience so that you don't have to call configure explicitly.

        show_preview - whether to show a preview window. You can pass in the preview
            type or True to attempt to autodetect. If left as False you'll get no
            visible preview window but the "NULL preview" will still be run. The
            value None would mean no event loop runs at all and you would have to
            implement your own.
        """
        """Stop the camera."""
  • Setting controls before the camera starts
from picamera2 import Picamera2
picam2 = Picamera2()
picam2.configure(picam2.create_preview_configuration())
picam2.set_controls({"ExposureTime": 10000, "AnalogueGain": 1.0})
picam2.start()
  • Setting controls after the camera has started
from picamera2 import Picamera2
picam2 = Picamera2()
picam2.configure(picam2.create_preview_configuration())
picam2.start()
picam2.set_controls({"ExposureTime": 10000, "AnalogueGain": 1.0})

Clone this wiki locally