-
Notifications
You must be signed in to change notification settings - Fork 57
/
opencv.sh
executable file
·135 lines (111 loc) · 3.56 KB
/
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
#!/bin/bash
# source: https://gist.github.com/phatblat/1713458
# Save script's current directory
DIR=$(pwd)
set -e
set -u
set -x
echo "################################"
echo "# OpenCV 2 or 3 from ppa/source"
echo "################################"
echo "#"
echo "# Install opencv from an ubuntu ppa by default,"
echo "# otherwise install from source"
echo "#"
echo "# github.com/opencv/opencv"
echo "# github.com/opencv/opencv_contrib"
echo "#"
echo "# WARNING: IF ROS OR OTHER OPENCV BINARIES, or BINARIES THAT DEPEND ON ARE ALREADY INSTALLED"
echo "# THERE MAY BE INVISIBLE CONFLICTS AND CRASHES IN THE SOFTWARE YOU RUN. IF YOU INSTALL OPENCV FROM"
echo "# SOURCE ALL PACKAGES THAT USE OPENCV SHOULD ALSO BE COMPILED FROM SOURCE TO AVOID DIFFICULT TO"
echo "# DIAGNOSE CRASHES!!!"
echo "#"
echo "# TO CHECK WITH ROS KINETIC RUN:"
echo "# dpkg -L ros-kinetic-opencv3"
echo "#"
echo "# To check if the ubuntu ppa libopencv-nonfree-dev installed by this script is present run:"
echo "#"
echo "# dpkg -L libopencv-nonfree-dev"
echo "# dpkg -L libopencv-dev"
# TODO(ahundt) finish 2.x & 3.x compilation script!
#branch="3.2.0" # install opencv 3.x from source
# branch="2.4.13.2" # install opencv 2.x from source
branch="ppa" # install from nonsecure ppa (default)
sudo apt-get install -y build-essential
sudo apt-get install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
OS=`uname`
case $OS in
'Linux')
OS='Linux'
. /etc/lsb-release # get ubuntu version number
# only install
if [ "$DISTRIB_RELEASE" = "14.04" ]; then
# TODO(ahundt) add ROS indigo specific opencv3 install
# http://wiki.ros.org/opencv3
# https://github.com/ros-gbp/opencv3-release
if [ -f "/opt/ros/indigo/setup.zsh" ]; then
sudo apt-get install python-bloom
fi
fi
;;
'FreeBSD')
OS='FreeBSD'
alias ls='ls -G'
;;
'WindowsNT')
OS='Windows'
;;
'Darwin')
OS='Mac'
;;
'SunOS')
OS='Solaris'
;;
'AIX') ;;
*) ;;
esac
if [ "$branch" = "ppa" ]; then
sudo add-apt-repository --yes ppa:xqms/opencv-nonfree
sudo apt-get update
sudo apt-get install libopencv-nonfree-dev
else
# TODO(ahundt) finish writing compilation from source and test
# compile from source
cd ~/src
if [ ! -d ~/src/opencv ]
then
git clone https://github.com/Itseez/opencv.git
fi
cd opencv
git pull
git checkout ${branch}
if [ $branch = "2.4.13.2"]; then
# more params at: https://github.com/opencv/opencv/blob/2.4.13.2/CMakeLists.txt
# more params at: https://github.com/Homebrew/homebrew-science/blob/master/opencv.rb
CMAKE_PARAMS="-DWITH_CUDA=ON -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCUDA_GENERATION=Kepler -DOPENCV_ENABLE_NONFREE=ON"
fi
# install OpenCV Contrib repository with nonfree components
if [ $branch = "3.2.0"]; then
# Opencv3 compilation with opencv_contrib
# TODO(ahundt) not complete!
cd ~/src/
if [ ! -d ~/src/opencv_contrib ]
then
git clone https://github.com/Itseez/opencv_contrib.git
fi
cd opencv_contrib
git pull
git checkout ${branch}
# TODO(ahundt) set cmake params appropriately for opencv 3
# more params at: https://github.com/Homebrew/homebrew-science/blob/master/opencv3.rb
CMAKE_PARAMS="-DWITH_CUDA=ON -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCUDA_GENERATION=Kepler -DOPENCV_ENABLE_NONFREE=ON"
fi
cd ~/src/opencv
git pull
mkdir -p build
cd build
cmake .. ${CMAKE_PARAMS}
make -j && sudo make install
fi # end build from source
cd $DIR