Skip to content

Instantly share code, notes, and snippets.

@CarlosGS
CarlosGS / lightweight_camera_motion.py
Last active January 9, 2022 17:15
Connect to an MJPG stream and compute the general direction of motion (like optic flow, but lighter). The script first crops and downsamples the JPG frames using the JPEGtran library, to allow processing in low power platforms like the Raspberry Pi.
###############################################################
# File: lightweight_camera_motion.py
# Description: Connect to an MJPG stream and compute the
# general direction of motion.
# The script first crops and downsamples the
# JPEG frames using the JPEGtran library,
# to allow processing in low power platforms
# like the Raspberry Pi.
#
# Author: Carlos Garcia-Saura (@CarlosGS) - 2018
@CarlosGS
CarlosGS / raspberry_fast_capture.py
Last active February 26, 2024 04:16
Fast reading from the raspberry camera with Python, Numpy, and OpenCV. See the comments for more details.
# Fast reading from the raspberry camera with Python, Numpy, and OpenCV
# Allows to process grayscale video up to 124 FPS (tested in Raspberry Zero Wifi with V2.1 camera)
#
# Made by @CarlosGS in May 2017
# Club de Robotica - Universidad Autonoma de Madrid
# http://crm.ii.uam.es/
# License: Public Domain, attribution appreciated
import cv2
import numpy as np
#!/usr/bin/python
# Generates and sets a random background representing a simulated Levy flight (https://en.wikipedia.org/wiki/Levy_flight)
# of 5 robots (starting at the center of the display)
# You can add the following lines to .bashrc so the wallpaper is updated everytime a terminal is opened
# python /home/carlosgs/wallpaper/generate_background.py & # Refresh the wallpaper in a background process
# BG_WP_PID=$!
# disown $BG_WP_PID # Hide stdout output from the previous command