Small program allowing video manipulation using OpenCV along some popular image analyzing techniques.
Made for demonstration of Raspberry Pi possibilities.
General usage:
python3 record.py --func $FUN --width $WIDTH --height $HEIGHT
For example:
python3 record.py --func gauss-threshold --width 300 --height 400
Provide params using --param_name
.
fun
– function that is applied on captured video data. One of:
basic-threshold
gauss-threshold
sobel-det
– sobel edge detectionlaplacian-det
– laplacian edge detectioncanny-edge-det
– Canny edge detectionface-recognition
– face recognition functioncartoon
none
– no function is applied on video
Installation instructions taking from plain Raspbian to OpenCV-equipped Raspberry. Tested on Raspberry Pi 3B+.
NOTE: you can also run the installation script from install.sh which will do the whole thing automatically.
Make the filesystem take up the whole SD card.
raspi-config --expand-rootfs
It will be handy for the installation that demands huge amounts of RAM.
export SWAPSIZE=2048
# Stop the swap.
sudo dphys-swapfile swapoff
# Make swap bigger (=> 2048MB).
sed -i "/CONF_SWAPSIZE=.*/CONF_SWAPSIZE=$SWAPSIZE/" /etc/dphys-swapfile
# Create and initialize the swapfile.
dphys-swapfile setup
# Start the swap.
sudo dphys-swapfile swapon
Note: commands are separated as there are layers of dependencies
sudo apt-get update && \
sudo apt-get upgrade && \
sudo apt-get install build-essential cmake pkg-config && \
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev && \
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev && \
sudo apt-get install libxvidcore-dev libx264-dev && \
sudo apt-get install libgtk2.0-dev libgtk-3-dev && \
sudo apt-get install libatlas-base-dev gfortran && \
sudo apt-get install python3-dev
Save library version as this appears several times later on.
export VERSION=3.4.3
cd ~
wget -O opencv.zip "https://github.com/Itseez/opencv/archive/$VERSION.zip"
unzip opencv.zip
wget -O opencv_contrib.zip "https://github.com/Itseez/opencv_contrib/archive/$VERSION.zip"
unzip opencv_contrib.zip
sudo pip3 install virtualenv virtualenvwrapper
sudo rm -rf ~/.cache/pip
echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.profile
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.profile
source ~/.profile
mkvirtualenv cv -p python3
workon cv
pip3 install numpy
cd ~/opencv-$VERSION
mkdir build
cd build
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-$VERSION/modules \
-D BUILD_EXAMPLES=ON ..
Dis gonna b good
make
sudo make install
sudo ldconfig
ls -l /usr/local/lib/python3.5/site-packages
# cv2.cpython-35m-arm-linux-gnueabihf.so -> cv2.so
# export FILENAME=cv2.cpython-35m-arm-linux-gnueabihf.so
cd /usr/local/lib/python3.5/site-packages/
sudo mv $FILENAME cv2.so
cd ~/.virtualenvs/cv/lib/python3.5/site-packages/
ln -s /usr/local/lib/python3.5/site-packages/cv2.so cv2.so
python3
import cv2
cv2.__version__
Installing OpenCV 3.4.3 on Raspberry Pi 3 Model B+