Raspberry Pi Scripts for Images, Videos, and Timelapses

Here is a link to some Python Raspberry Pi Scripts I made that allow you to take images, videos, and timelapses. The scripts are easier to use than the command line because it automatically numbers the videos/pictures. It also has space for you to make desired camera settings changes. Currently the timelapse script takes a bunch of pictures and saves them individually, but I plan on making a version that threads them together into a video.

The first two scripts require OpenCV to be installed on the Raspberry Pi (RPi). While OpenCV is a large library that takes a while to install, the capabilities of it outweighs this hassle. It may seem slightly overkill just for taking pictures and videos on the RPi, it seemed the only way to get user keypress input. It also enables many other functions like the tracking of molecular organisms.

Here are the functions of the scripts in this repo:

  • recorder.py:
    • python script to record videos and/or take pictures with the Raspberry Pi Foldscope
    • can customize the filetype and filename for the pictures/videos
    • can save multiple pictures/videos with the same basic filename e.g. video_1.avi, video_2.avi etc.
  • video_player.py:
    • python script to play back a previously recorded video
    • can navigate frame-by-frame forward and backward
    • can save multiple pictures of the frames of the video
  • timelapse.py:
    • python script for taking timelapse pictures
    • take pictures for set intervals of time with indexed name
    • DOES NOT require OpenCV

https://github.com/bfrieds/Foldscope-Raspberry-Pi

I’m glad I finally got around to posting this. It’s been a while since I last got to use these, so there may be issues. I also plan on making a little tutorial on how to install OpenCV for anyone who may have trouble. Hopefully this will be helpful. Good luck!

-Brian

2 Comments Add yours

  1. Manu Prakash says:

    Thanks Brian. This is super useful – and also the very first scripts based post. I can only imagine wanting to implement image processing code on these scripts.

    Can you point me to real time image processing modules that would be relevant – say a simple case – I want to do a threshold operation directly on the image using raspberry PI.

    Cheers
    Manu

    1. Brian Friedenberg says:

      @manu Here is a link to the Miscillaneous Image Transformations section of the OpenCV documentation. Near the bottom, there is a section on the threshold function of OpenCV. The threshold function of OpenCV requires a grayscaled image; it cannot take a color image as an input one. The function to convert an image from color to grayscale is earlier on the list of functions in the section and is called cvtColor and can be used as follows grayImage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY). So on the script you are using, right after the for loop starts, you would convert the image to grayscale and then threshold the grayscaled image. You would then change all future occurrences of the variable frame to your variable for the thresholded image.

      There are also some more complex functions that could prove helpful located on this page such as an adaptive threshold that uses an algorithm to calculate an ideal threshold for each image.

Leave a Reply