install.sh 2.4 KB

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