Giter Site home page Giter Site logo

raspberry-pi-open-cv's Introduction

raspberry-pi-open-cv

Small program allowing video manipulation using OpenCV along some popular image analyzing techniques.

Made for demonstration of Raspberry Pi possibilities.

Usage

General usage:

python3 record.py --func $FUN --width $WIDTH --height $HEIGHT

For example:

python3 record.py --func gauss-threshold --width 300 --height 400

Parameters

Provide params using --param_name.

fun – function that is applied on captured video data. One of:

  • basic-threshold
  • gauss-threshold
  • sobel-det – sobel edge detection
  • laplacian-det – laplacian edge detection
  • canny-edge-det – Canny edge detection
  • face-recognition – face recognition function
  • cartoon
  • none – no function is applied on video

Installation on Raspberry Pi 3B+

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.

Preparing the device

Expand filesystem

Make the filesystem take up the whole SD card.

raspi-config --expand-rootfs

Increase swap size

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

Dependencies

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

Installing OpenCV

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

Virtual Python environment

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

Preparation

pip3 install numpy
cd ~/opencv-$VERSION
mkdir build
cd build

Compiling

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

Installing

sudo make install
sudo ldconfig

Renaming the library

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

Verification

python3
import cv2
cv2.__version__

Sources

Installing OpenCV 3.4.3 on Raspberry Pi 3 Model B+

Install guide: Raspberry Pi 3 + Raspbian Jessie + OpenCV 3

OpenCV

raspberry-pi-open-cv's People

Contributors

osdnk avatar ajopek avatar tchayen avatar

Stargazers

Marcin Aman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.