forked from msproul/AlpacaPi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_opencv.sh
executable file
·241 lines (197 loc) · 6.11 KB
/
install_opencv.sh
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
###############################################################################
# script to install opencv version 3.3.1
# by Mark Sproul
###############################################################################
### Mar 27, 2020 <MLS> Started on install script
### Mar 27, 2020 <MLS> Working!!!!!
### Jul 6, 2020 <MLS> Install of 3.3.1 failed on Raspberry-Pi 4
### Jul 7, 2020 <MLS> Now will install 3.3.1 or 3.2.0, which ever is present
### Jan 25, 2021 <MLS> Took 5 hours on a Jetson-Nano
### Feb 8, 2021 <MLS> Added system update
### Feb 8, 2021 <MLS> Added log file
### Feb 18, 2021 <MLS> Added more logging
###############################################################################
# https://opencv.org/releases/page/4/
BASE_DIR=`pwd`
LOGFILENAME=$BASE_DIR/"opencvinstall-log.txt"
echo $LOGFILENAME
echo "*******************************************************" >> $LOGFILENAME
echo -n "Start time=" >> $LOGFILENAME
date >> $LOGFILENAME
clear
echo "********************************************************************"
echo "This script installs opencv version 3.3.1 on a linux machine"
echo "WARNING: The build portion can easily take 4 hours on an R-Pi!!!!"
echo "WARNING: It took 5 hours on a Jetson-nano!!!!"
echo "********************************************************************"
echo -n "Hit return to continue, ^C to abort"
read WAITINPUT
echo "First we are going to do a system update"
echo -n "Hit return to continue, ^C to abort"
read WAITINPUT
echo " >sudo apt-get update"
echo -n "Hit return to continue, ^C to abort"
read WAITINPUT
echo "running 'apt-get update'" >> $LOGFILENAME
sudo apt-get update
echo "Installing libjpeg-dev"
echo "Installing libjpeg-dev" >> $LOGFILENAME
sudo apt-get install libjpeg-dev
echo "Checking for required programs..."
echo "Checking for make and cmake"
MAKE_VERSION_LNCNT=`make -version | wc -l`
CMAKE_VERSION_LNGCNT=`cmake -version | wc -l`
if [ $MAKE_VERSION_LNCNT -ge 1 ]
then
echo "make is installed"
echo "make is installed" >> $LOGFILENAME
else
echo "make is missing!!!!!!!!!!!!!!"
echo "make is missing!!!!!!!!!!!!!!" >> $LOGFILENAME
exit
fi
OPENCV_INSTALL_DIR="opencv"
mkdir $OPENCV_INSTALL_DIR
if [ -d $OPENCV_INSTALL_DIR ]
then
echo "Successfully created $OPENCV_INSTALL_DIR directory"
else
echo "Failed to create $OPENCV_INSTALL_DIR directory"
exit
fi
echo "Installing libgtk2.0-dev"
echo "Installing libgtk2.0-dev" >> $LOGFILENAME
sudo apt-get install libgtk2.0-dev
if [ $CMAKE_VERSION_LNGCNT -ge 1 ]
then
echo "cmake is installed"
echo "cmake is installed" >> $LOGFILENAME
else
echo "cmake is missing!!!!!!!!!!!!!!!!"
echo -n "Do you want to install cmake? [y/n]"
read WAITINPUT
if [ $WAITINPUT = "y" ]
then
echo "Installing cmake with apt-get"
echo "Installing cmake with apt-get" >> $LOGFILENAME
sudo apt-get install cmake
else
echo "Aborting, cant install without cmake."
echo "Aborting, cant install without cmake." >> $LOGFILENAME
exit
fi
fi
echo -n "Hit return to continue, ^C to abort"
read WAITINPUT
cd $OPENCV_INSTALL_DIR
##########################################################
# lets check to see which version is available
if [ -f "opencv-3.3.1.tar.gz" ]
then
OPENCV_TARFILE="opencv-3.3.1.tar.gz"
OPENCV_DIR="opencv-3.3.1"
OPENCV_WGET_FILE="https://github.com/opencv/opencv/archive/3.3.1.tar.gz"
OPENCV_REMOTE_FILE="3.3.1.tar.gz"
ISZIP=0
elif [ -f "opencv-3.2.0.tar.gz" ]
then
OPENCV_TARFILE="opencv-3.2.0.tar.gz"
OPENCV_DIR="opencv-3.2.0"
OPENCV_WGET_FILE="https://github.com/opencv/opencv/archive/3.2.0.tar.gz"
OPENCV_REMOTE_FILE="3.2.0.tar.gz"
ISZIP=0
else
echo "Valid version of Opencv was not found, tyring to download!!!!!"
echo "Getting ready to try downloading"
OPENCV_TARFILE="opencv-3.3.1.tar.gz"
OPENCV_DIR="opencv-3.3.1"
OPENCV_WGET_FILE="https://github.com/opencv/opencv/archive/3.3.1.tar.gz"
OPENCV_REMOTE_FILE="3.3.1.tar.gz"
ISZIP=0
fi
echo
echo
echo "Getting ready to install $OPENCV_DIR"
echo -n "Hit return to continue, ^C to abort"
read WAITINPUT
#OPENCV_TARFILE="opencv-3.4.9.zip"
#OPENCV_DIR="opencv-3.4.9"
#OPENCV_WGET_FILE="https://github.com/opencv/opencv/archive/3.4.9.zip"
#OPENCV_REMOTE_FILE="3.4.9.zip"
#ISZIP=1
#OPENCV_TARFILE="opencv-3.4.0.zip"
#OPENCV_DIR="opencv-3.4.0"
#OPENCV_WGET_FILE="https://github.com/opencv/opencv/archive/3.4.0.tar.gz"
#OPENCV_REMOTE_FILE="3.4.0.tar.gz"
#ISZIP=0
if [ -f $OPENCV_TARFILE ]
then
echo "$OPENCV_TARFILE is present"
else
echo "Downloading $OPENCV_WGET_FILE" >> $LOGFILENAME
echo "Getting ready to download $OPENCV_TARFILE"
echo -n "Hit return to continue, ^C to abort"
read WAITINPUT
wget $OPENCV_WGET_FILE
mv $OPENCV_REMOTE_FILE $OPENCV_TARFILE
fi
if [ -d $OPENCV_DIR ]
then
echo "$OPENCV_DIR already exists"
else
if [ -f $OPENCV_TARFILE ]
then
if [ $ISZIP -eq 1]
then
echo "Unzipping $OPENCV_TARFILE"
echo -n "Hit return to continue"
read WAITINPUT
unzip $OPENCV_TARFILE
else
echo "un-tarring $OPENCV_TARFILE"
tar xvf $OPENCV_TARFILE
fi
else
echo "Failed to find $OPENCV_TARFILE"
fi
fi
ls -l
echo "Getting ready to build"
echo -n "Hit return to continue"
read WAITINPUT
if [ -d $OPENCV_DIR ]
then
if [ -d "$OPENCV_DIR/CMakeFiles" ]
then
echo "It appears that cmake has already been run"
else
echo "Getting ready to run cmake"
echo -n "Hit return to continue"
read WAITINPUT
echo "Running cmake" >> $LOGFILENAME
time cmake -DBUILD_opencv_cudacodec=OFF $OPENCV_DIR
fi
if [ -f Makefile ]
then
echo "********************************************************"
echo "Getting ready to run make"
echo "WARNING: This could easily take 4 hours!!!!"
echo "WARNING: It took 5 hours on a Jetson-nano!!!!"
echo "********************************************************"
echo -n "Hit return to continue"
read WAITINPUT
date >> $LOGFILENAME
time make all
echo "Getting ready to install"
echo -n "Hit return to continue"
read WAITINPUT
sudo make install
sudo ldconfig
else
echo "Makefile is missing"
fi
date >> $LOGFILENAME
#export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
#or to make the change permanent you can add /usr/local/lib to /etc/ld.so.conf
#(or something it includes) and run ldconfig as root.
fi