Last active
June 3, 2018 14:09
-
-
Save Lauszus/c8ce73f3177d6455c27c to your computer and use it in GitHub Desktop.
Install OpenCV on minimal Raspbian image for use with: https://github.com/Lauszus/ImageAnalysisWithMicrocomputer30330
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# Based on: http://www.pyimagesearch.com/2015/10/26/how-to-install-opencv-3-on-raspbian-jessie | |
sudo apt-get -y install build-essential git-core cmake pkg-config | |
sudo apt-get -y install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev | |
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev | |
sudo apt-get -y install libxvidcore-dev libx264-dev | |
sudo apt-get -y install libgtk2.0-dev | |
sudo apt-get -y install libatlas-base-dev gfortran | |
sudo apt-get -y install python2.7-dev python-numpy | |
sudo apt-get -y install unzip | |
# Use Github API to find latest release version: | |
version="$(curl -s https://api.github.com/repos/opencv/opencv/releases | python -mjson.tool | grep 'tag_name' | cut -d'"' -f4 | sort -rn | head -1)" | |
cd | |
wget -O opencv.zip https://github.com/opencv/opencv/archive/$version.zip | |
unzip -o opencv.zip | |
rm opencv.zip | |
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/$version.zip | |
unzip -o opencv_contrib.zip | |
rm opencv_contrib.zip | |
cd ~/opencv-$version | |
mkdir build | |
cd build | |
cmake -D CMAKE_BUILD_TYPE=RELEASE \ | |
-D CMAKE_INSTALL_PREFIX=/usr/local \ | |
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-$version/modules \ | |
-D ENABLE_NEON=ON \ | |
-D WITH_V4L=ON \ | |
-D INSTALL_C_EXAMPLES=ON \ | |
-D INSTALL_PYTHON_EXAMPLES=ON \ | |
-D BUILD_EXAMPLES=ON .. | |
make -j4 | |
sudo make install | |
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf' | |
sudo ldconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/debian-pi/raspbian-ua-netinst | |
$ wget `curl -s https://api.github.com/repos/debian-pi/raspbian-ua-netinst/releases/latest | python -mjson.tool | grep 'browser_download_url' | grep 'img.bz2' | cut -d'"' -f4` -O raspbian-ua-netinst.img.bz2 | |
$ bunzip2 raspbian-ua-netinst.img.bz2 | |
$ diskutil list | |
$ diskutil unmountDisk /dev/diskX | |
$ sudo dd bs=1m if=`ls raspbian-ua-netinst-*.img` of=/dev/rdiskX | |
$ diskutil eject /dev/diskX | |
# Login: | |
# Username: root | |
# Password: raspbian | |
$ passwd | |
$ apt-get install avahi-daemon | |
$ ssh root@pi.local | |
# https://www.raspberrypi.org/documentation/linux/usage/users.md | |
$ adduser pi | |
$ apt-get install sudo | |
$ usermod -a -G sudo,video pi # Add user to sudo and video group, so one can use sudo and the Raspberry camera works | |
# Optional: give passwordless sudo access: | |
$ visudo | |
# pi ALL = NOPASSWD: ALL | |
# Optional: use improved memory management performance functions and create swap: | |
$ sudo apt-get install raspi-copies-and-fills | |
$ sudo dd if=/dev/zero of=/swap bs=1M count=512 | |
$ sudo mkswap /swap | |
$ sudo sh -c 'echo "/swap none swap sw 0 0" >> /etc/fstab' | |
$ exit | |
# https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md | |
$ ssh pi@pi.local 'mkdir ~/.ssh' | |
$ cat ~/.ssh/id_rsa.pub | ssh pi@pi.local 'cat >> .ssh/authorized_keys' | |
$ ssh pi@pi.local | |
$ sudo locale-gen en_US en_US.UTF-8 | |
$ echo -e "export LC_ALL=\"en_US.UTF-8\"\nexport LANG=\"en_US.UTF-8\"" >> ~/.bash_profile | |
$ . ~/.bash_profile | |
$ sudo apt-get install apt-utils | |
$ sudo apt-get install keyboard-configuration | |
$ sudo apt-get install raspi-config rpi-update | |
# Expand partition, fix locals, timezone, keyboard layout, enable camera, optional overclock | |
$ sudo raspi-config | |
# Reboot | |
$ sudo apt-get update | |
$ sudo apt-get upgrade | |
$ sudo rpi-update | |
$ sudo reboot | |
# Install OpenCV | |
$ curl https://gist.githubusercontent.com/Lauszus/c8ce73f3177d6455c27c/raw/install_opencv.sh | bash | |
# X11 | |
$ sudo apt-get install xorg | |
# Run script on display remotely | |
$ echo "export DISPLAY=:0" >> ~/.bash_profile | |
# https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspistill.md | |
# Should now be able to show pictures: | |
$ raspistill -o cam.jpg | |
# UV4L | |
# Install instructions (source: http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14): | |
$ curl http://www.linux-projects.org/listing/uv4l_repo/lrkey.asc | sudo apt-key add - | |
$ sudo sh -c 'echo "deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/ wheezy main" >> /etc/apt/sources.list' | |
$ sudo apt-get update | |
$ sudo apt-get install uv4l uv4l-raspicam | |
# Optional: | |
$ sudo apt-get install uv4l-raspicam-extras | |
$ sudo service uv4l_raspicam restart | |
# Configuration: /etc/uv4l/uv4l-raspicam.conf | |
# Remove preview: nopreview = yes | |
# Example (based on http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=16#example4): | |
$ wget http://linux-projects.org/downloads/examples/opencv_test.cpp | |
$ g++ `pkg-config --cflags opencv` -o `basename opencv_test.cpp .cpp` opencv_test.cpp `pkg-config --libs opencv` -L/usr/lib/uv4l/uv4lext/armv6l -luv4lext -Wl,-rpath,'/usr/lib/uv4l/uv4lext/armv6l' | |
$ uv4l --driver raspicam --auto-video_nr --encoding yuv420 --width 320 --height 240 # Manually load uv4l if you have not installed the optional uv4l-raspicam-extras package | |
$ ./opencv_test | |
# Makefile: https://github.com/Lauszus/ImageAnalysisWithMicrocomputer30330/blob/master/ZomBuster/src/Makefile | |
# i3 | |
$ sudo apt-get install i3 | |
$ sudo apt-get autoremove | |
$ sudo apt-get autoclean | |
# Disable Camera module LED: | |
$ sudo sh -c 'echo "disable_camera_led=1" >> /boot/config.txt' | |
# WiringPi | |
$ sudo apt-get -y install build-essential git-core make | |
$ git clone git://git.drogon.net/wiringPi | |
$ cd wiringPi | |
$ ./build | |
# Test WiringPi | |
$ gpio -v | |
$ gpio readall | |
# WiFi | |
# Check that driver is detected | |
$ dmesg | grep -i wlan | |
# Scan | |
$ sudo apt-get install wireless-tools | |
$ sudo iwlist wlan0 scan | |
# Replace SSID and PASSWORD with your the network name and password | |
$ sudo sh -c 'echo "\nallow-hotplug wlan0\nauto wlan0\niface wlan0 inet dhcp\n\twpa-ssid \"SSID\"\n\twpa-psk \"PASSWORD\"\n" >> /etc/network/interfaces' | |
$ sudo /etc/init.d/networking restart | |
# Make sure interface is detected | |
$ sudo ifconfig wlan0 | |
# Upload and compile on remote machine | |
scp main.cpp pi@pi.local:~/ImageAnalysisWithMicrocomputer30330/ZomBuster/src && ssh pi@pi.local "make -j4 -C ~/ImageAnalysisWithMicrocomputer30330/ZomBuster/src" | |
# Mount file system | |
$ sshfs pi@pi.local:~/ImageAnalysisWithMicrocomputer30330/ZomBuster/src ~/sshfs -o noappledouble | |
$ umount ~/sshfs | |
# Reference: | |
# http://www.pyimagesearch.com/2015/10/26/how-to-install-opencv-3-on-raspbian-jessie | |
# http://milq.github.io/install-opencv-ubuntu-debian | |
# https://github.com/milq/scripts-ubuntu-debian/blob/master/install-opencv.sh | |
# http://raspberrypi.stackexchange.com/questions/27232/installing-opencv-3-0-on-raspberry-pi-b | |
# https://github.com/jayrambhia/Install-OpenCV | |
# https://help.ubuntu.com/community/OpenCV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
gpio mode 8 up # Input with internal pull-up resistor | |
#echo "Compiling..." | |
#make -C ~/ImageAnalysisWithMicrocomputer30330/ZomBuster/src 1> /dev/null | |
echo "Press button to start" | |
while true; do | |
while [ $(gpio read 8) == 1 ]; do | |
sleep .1 # Wait until button is pressed | |
done | |
while [ $(gpio read 8) == 0 ]; do | |
sleep .1 # Wait until button is released again | |
done | |
echo "Starting..." | |
sudo ~/ImageAnalysisWithMicrocomputer30330/ZomBuster/src/bin/main 2> /dev/null | |
while [ $(gpio read 8) == 0 ]; do | |
sleep .1 # Wait until button is released again | |
done | |
echo -e "\nPress button to restart" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment