-
Notifications
You must be signed in to change notification settings - Fork 0
/
opencv-raspi4
146 lines (118 loc) · 4.24 KB
/
opencv-raspi4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# to get the current status
$ sudo rpi-eeprom-update
# if needed, to update the firmware
$ sudo rpi-eeprom-update -a
$ sudo reboot
Before you install OpenCV on your Raspberry Pi 4,
it is time for a final version check. Many readers just jump into the guide,
skipping the introduction, often because they have already an operating system working.
For those, please give the command uname -a and check your version.
Do you have the 32-bit version, armv7l, please continue
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install cmake gfortran
$ sudo apt-get install libjpeg-dev libtiff-dev libgif-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install libgtk2.0-dev libcanberra-gtk*
$ sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev
$ sudo apt-get install libtbb2 libtbb-dev libdc1394-22-dev libv4l-dev
$ sudo apt-get install libopenblas-dev libatlas-base-dev libblas-dev
$ sudo apt-get install libjasper-dev liblapack-dev libhdf5-dev
$ sudo apt-get install protobuf-compiler
Qt is an open-source toolkit for the development of cross-platform graphical user interfaces.
It also works on the Raspberry Pi.
The software can be used to beautify OpenCV windows and other user interfaces,
such as sliders and checkboxes. It is absolutely not mandatory for the working of OpenCV,
only to embellish the look. Must be said, that using Qt5 will slow down your OpenCV by a few percent.
If you go for the fastest possible apps, don't use it.
# only install if you want Qt5
# to beautify your OpenCV GUI
$ sudo apt-get install qt5-default
$ cd ~
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.2.zip
$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.2.zip
$ unzip opencv.zip
$ unzip opencv_contrib.zip
$ mv opencv-4.5.2 opencv
$ mv opencv_contrib-4.5.2 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
$ cd ~/opencv/
$ mkdir build
$ cd build
$ 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 WITH_OPENCL=OFF \
-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_opencv_python3=TRUE \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF ..
$ sudo nano /etc/dphys-swapfile
This command opens Nano, a very lightweight text editor,
with the system file dphys-swapfile. With the arrow keys,
you can move the cursor to the CONF_SWAPSIZE line where the new value 2048 can be entered.
Next, close the session with the <Ctrl+X> key combination.
With <Y> and <Enter> changes are being saved in the same file.
$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
$ make -j4
$ sudo make install
$ sudo ldconfig
# cleaning (frees 300 KB)
$ make clean
$ sudo apt-get update
$ sudo nano /etc/dphys-swapfile
set CONF_SWAPSIZE=100 with the Nano text editor
$ cd ~
$ rm opencv.zip
$ rm opencv_contrib.zip
$ sudo reboot
$ cd ~/.virtualenvs/cv450/lib/python3.7/site-packages
$ ln -s /usr/local/lib/python3.7/site-packages/cv2/python-3.7/cv2.cpython-37m-arm-linux-gnueabihf.so
$ cd ~
# Python 2
$ cd ~/opencv/build/lib/
$ sudo cp cv2.so /usr/local/lib/python2.7/dist-packages/cv2/python-2.7
# Python 3
$ cd ~/opencv/build/lib/python3
$ sudo cp cv2.cpython-37m-arm-linux-gnueabihf.so \
/usr/local/lib/python3.7/dist-packages/cv2/python-3.7
$ cd ~/opencv
$ sudo rm -r build
# just a tip to save some space
$ sudo rm -rf ~/opencv
$ sudo rm -rf ~/opencv_contrib
$ python
>>> import cv2
>>> print( cv2.getBuildInformation())