install.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. sudo apt update || exit 1
  3. sudo apt upgrade -y || exit 1
  4. sudo apt install python3 python3-pip python3-tk python3-pil python3-pil.imagetk -y || exit 1
  5. python3 -m pip install --upgrade pip || exit 1
  6. python3 -m pip install pyserial || exit 1
  7. python3 -m pip install opencv-contrib-python || exit 1
  8. python3 -m pip install pillow || exit 1
  9. python3 -m pip install pyglet || exit 1
  10. python3 -m pip install noise || exit 1
  11. python3 -m pip install numpy || exit 1
  12. sudo apt-get install cmake gfortran \
  13. libjpeg-dev libtiff-dev libgif-dev \
  14. libavcodec-dev libavformat-dev libswscale-dev \
  15. libgtk2.0-dev libcanberra-gtk* \
  16. libxvidcore-dev libx264-dev libgtk-3-dev \
  17. libtbb2 libtbb-dev libdc1394-22-dev libv4l-dev \
  18. libopenblas-dev libatlas-base-dev libblas-dev \
  19. libjasper-dev liblapack-dev libhdf5-dev \
  20. protobuf-compiler -y
  21. cd ~/Downloads
  22. wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.0.zip
  23. wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.0.zip
  24. unzip opencv.zip
  25. unzip opencv_contrib.zip
  26. mv opencv-4.5.0 opencv
  27. mv opencv_contrib-4.5.0 opencv_contrib
  28. cd opencv/
  29. mkdir build
  30. cd build
  31. cmake -D CMAKE_BUILD_TYPE=RELEASE \
  32. -D CMAKE_INSTALL_PREFIX=/usr/local \
  33. -D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib/modules \
  34. -D ENABLE_NEON=ON \
  35. -D ENABLE_VFPV3=ON \
  36. -D WITH_OPENMP=ON \
  37. -D BUILD_TIFF=ON \
  38. -D WITH_FFMPEG=ON \
  39. -D WITH_TBB=ON \
  40. -D BUILD_TBB=ON \
  41. -D BUILD_TESTS=OFF \
  42. -D WITH_EIGEN=OFF \
  43. -D WITH_V4L=ON \
  44. -D WITH_LIBV4L=ON \
  45. -D WITH_VTK=OFF \
  46. -D WITH_QT=OFF \
  47. -D OPENCV_ENABLE_NONFREE=ON \
  48. -D INSTALL_C_EXAMPLES=OFF \
  49. -D INSTALL_PYTHON_EXAMPLES=OFF \
  50. -D BUILD_NEW_PYTHON_SUPPORT=ON \
  51. -D BUILD_opencv_python3=TRUE \
  52. -D OPENCV_GENERATE_PKGCONFIG=ON \
  53. -D BUILD_EXAMPLES=OFF ..
  54. # enlarge swapfile for building on raspi
  55. sudo cp /etc/dphys-swapfile /etc/dphys-swapfile.bak
  56. echo "CONF_SWAPFILE=2048" | sudo tee /etc/dphys-swapfile
  57. sudo systemctl stop dphys-swapfile
  58. sudo systemctl start dphys-swapfile
  59. # build opencv
  60. make -j4
  61. sudo make install
  62. sudo ldconfig
  63. make clean
  64. sudo apt-get update
  65. cd ~/Downloads
  66. rm opencv.zip
  67. rm opencv_contrib.zip
  68. # restore swapfile
  69. sudo cp /etc/dphys-swapfile.bak /etc/dphys-swapfile
  70. echo "reboot to finish!"