Skip to main content
Chemistry LibreTexts

9.23: 3-Python and Libcamera

  • Page ID
    470310
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    The easiest way to take pictures from Python is to use the libcamera picamera2library that is a local python library (it is installed with Python but you need to import it in order to use it). You should consult the Picamera2 Library manual for further information.

    
    #Script is adapted from page 6 of Picamera2 Library Manual
    from picamera2 import Picamera2
    picam2 = Picamera2()
    file_name=input("enter a file name for your picture: ")
    picam2.start_and_capture_file("/home/rebelford/Pictures/"+file_name+".jpg")
    

    You will probably want to install FFmpeg.  there are two ways you can do this.

    1. In Thonny install through Tools/Manage Packages and search for it if it is not there.
    2. In command line type
    sudo apt install -y ffmpeg
    

     

    The following script will take 10 pictures, one every one second.

    from picamera2 import Picamera2
    picam2 = Picamera2()
    file_name=input("enter a file name for your picture: ")
    picam2.start_and_capture_file("/home/rebelford/Pictures/"+file_name+"{:d}.jpg", initial_delay=2, delay=2, num_files=10)

    This page titled 9.23: 3-Python and Libcamera is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?