Let op: De uitvoering van dit script duurt een tijd omdat er source-code gecompileerd moet worden!

Je kunt dit daarom het beste uitvoeren op een Raspberry 4 of 5.

!#/bin/bash
#
#  Zie voor wat je verder moet doen nadat je dit script hebt gedraaid!!!!
##

# https://qengineering.eu/deep-learning-examples-on-raspberry-32-64-os.html
#
# https://qengineering.eu/install-tensorflow-2.2.0-on-raspberry-pi-4.html
# en https://www.pantechsolutions.net/blog/installing-library-packages-in-raspberry-pi/ voor OpenCV
#
#  Please make sure you have latest pip3 and python3 version installed, 
#  otherwise, pip may come with the message:  ".whl is not a supported wheel on this platform".
#
#
# get a fresh start
 sudo apt-get update
 sudo apt-get upgrade

# Python3 en pip3 installeren
sudo apt-get install python3-pip
sudo apt-get update 
sudo apt-get upgrade -y
sudo apt-get install python3 -y

# remove old versions, if not placed in a virtual environment (let pip search for them)
 sudo pip uninstall tensorflow
 sudo pip3 uninstall tensorflow


# We gaan eerst Python 3.8 installeren
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz
tar xf Python-3.8.0.tar.xz
cd Python-3.8.0
./configure --prefix=/usr/local/opt/python-3.8.0
make -j 4

sudo make altinstall
cd ..
sudo rm -r Python-3.8.0
sudo rm Python-3.8.0.tar.xz
alias python='/usr/bin/python3.8'
. ~/.bashrc
# Let’s make Python 3.8 the default version, make aliases
sudo update-alternatives --config python
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
ls /usr/bin/python*
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 0

update-alternatives --list python
sudo update-alternatives --config python
python -V

echo "Nu gaan we TensorFlow 2.2.0 installeren..."

# install the dependencies 
 sudo apt-get install gfortran -y
 sudo apt-get install libhdf5-dev libc-ares-dev libeigen3-dev -y
 sudo apt-get install libatlas-base-dev libopenblas-dev libblas-dev  -y
 sudo apt-get install openmpi-bin libopenmpi-dev -y
 sudo apt-get install liblapack-dev cython -y
 sudo pip3 install keras_applications==1.0.8 --no-deps
 sudo pip3 install keras_preprocessing==1.1.0 --no-deps
 sudo pip3 install -U --user six wheel mock
 sudo -H pip3 install pybind11
 sudo -H pip3 install h5py==2.10.0
# upgrade setuptools 40.8.0 -> 52.0.0
 sudo -H pip3 install --upgrade setuptools
# install gdown to download from Google drive
# pip install gdown
 pip3 install gdown
# copy binairy
 sudo cp ~/.local/bin/gdown /usr/local/bin/gdown
# download the wheel
 gdown https://drive.google.com/uc?id=11mujzVaFqa7R1_lB7q0kVPW22Ol51MPg
# install TensorFlow
 sudo -H pip3 install tensorflow-2.2.0-cp37-cp37m-linux_armv7l.whl
pip3 install keras
# and complete the installation by rebooting
sudo reboot


# OpenCV
# https://qengineering.eu/install-opencv-4.5-on-raspberry-pi-4.html
#
# Dependencies
cd
sudo mkdir opencv
 sudo apt-get update
 sudo apt-get upgrade -y
 sudo apt-get install cmake gfortran -y
 sudo apt-get install libjpeg-dev libtiff-dev libgif-dev -y
 sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev -y
 sudo apt-get install libgtk2.0-dev libcanberra-gtk*  -y
 sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev  -y
 sudo apt-get install libtbb2 libtbb-dev libdc1394-22-dev libv4l-dev -y
 sudo apt-get install libopenblas-dev libatlas-base-dev libblas-dev -y
 sudo apt-get install libjasper-dev liblapack-dev libhdf5-dev -y
 sudo apt-get install protobuf-compiler  -y

# Qt5
# only install if you want Qt5 to beautify your OpenCV GUI
# sudo apt-get install qt5-default -y
# mv opencv-4.5.0 opencv
# mv opencv_contrib-4.5.0 opencv_contrib

# get version
 python3 --version
# get location
 which python 3.7
# merge VIRTUALENVWRAPPER_PYTHON=location/version
 echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.7" >> ~/.bashrc
# reload profile
 source ~/.bashrc

 sudo pip3 install virtualenv
 sudo pip3 install virtualenvwrapper
 echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
 echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
 source ~/.bashrc
 mkvirtualenv cv450
# without sudo!:
pip3 install numpy

 sudo mkdir ~/opencv/
 cd ~/opencv/
 mkdir build
 cd build

# OpenCV 4.5.0
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D ENABLE_NEON=ON -D ENABLE_VFPV3=ON -D WITH_OPENMP=ON -D BUILD_TIFF=ON -D WITH_FFMPEG=ON -D WITH_TBB=ON -D BUILD_TBB=ON -D BUILD_TESTS=OFF -D WITH_EIGEN=OFF -D WITH_GSTREAMER=OFF -D WITH_V4L=ON -D WITH_LIBV4L=ON -D WITH_VTK=OFF -D WITH_QT=OFF -D OPENCV_ENABLE_NONFREE=ON -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_opencv_python3=TRUE -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_EXAMPLES=OFF ..