Home » Archives for ovidiu.parvu@gmail.com

Author: ovidiu.parvu@gmail.com

How do you validate a computational model of a system evolving in time and space?

To be more specific the question should be how do you validate a computational model of a system evolving in time and space relative to a specification describing its expected behaviour? One possible answer to this question is multidimensional spatio-temporal model checking.

To explain what I mean by this let us first describe “traditional” model checking.

Model checking

What?

Model checking is a method for automatically validating a computational model relative to a specification.

How?

The computational model is an abstract representation of a real life system which describes how the system changes its state over time. The state of the system is described by the values of a set of state variables. Therefore in more abstract terms a computational model describes how a set of state variables change their value over time.

The specification comprises a collection of statements encoded in formal languages which can describe how the state of a system changes over time. Such languages are called temporal logics. The reason for employing temporal logics instead of natural languages (e.g. English) is that the former have a fixed syntax and semantics while the latter do not (e.g. metaphors use the same words/syntax but have different semantics depending on the context in which they are used).

Each statement in the specification describes how a subset of state variables are expected to change their value over time. Therefore the model checking problem is to verify if the state variables of a system change their value over time as described in the specification by verifying all possible states of the system.

Why?

Model checking is a method employed for proving that a model is (in)valid relative to a specification because it considers all possible states of the system. This is in contrast to testing based approaches which can only show the presence but not the absence of errors in a model because they usually consider only a subset of the possible system states.

Multidimensional model checking

Traditional model checking approaches usually assume that the state of the system can be represented by a set of real-valued state variables. Consequently the employed temporal logics contain language constructs which enable reasoning about real values (e.g. arithmetic operators +, -, *, /).

However in case of systems which evolve both in time and space there is an additional need to represent the state of the system using multidimensional state variables (e.g. a matrix representing a discretised 2D space). Moreover the employed temporal logic should additionally contain spatial functions which enable reasoning about how geometric properties (e.g. area) of the systems change over time.

In order to address this issue multidimensional spatio-temporal model checking was developed. The main extra features of multidimensional spatio-temporal compared to traditional model checking are:

  • Multidimensional state variables for encoding space;
  • Functions for automatically computing geometric properties of the system at a given state;
  • A quantitative spatio-temporal logic which extends traditional temporal logics with space related functions.

If interested in a more rigurous scientific description of multidimensional model checking please visit the recently published open access paper and website. Examples of the potential impact multidimensional model checking could have on industry are given on my personal PhD project research website.

Linear minimum area enclosing triangle implementation

Problem

Given an arbitrary set of points in the 2D Euclidean plane compute the enclosing triangle having the minimum area.

Minimal area enclosing triangle example
Figure 1: An example of a set of points in the 2D Euclidean plane (highlighted in green) and the corresponding minimal area enclosing triangle (highlighted in red).

Theoretical solution

Based on an elegant geometric characterization provided by Klee and Laskowski O’Rourke developed a linear algorithm for addressing the above problem; see the An optimal algorithm for finding minimal enclosing triangles paper for more details.

Implementation

A detailed description of all required algorithms is provided in the Implementation of linear minimum area enclosing triangle algorithm paper and a C++ implementation of these algorithms is made freely available at https://github.com/ovidiuparvu/minimal-area-triangle.

International Study Group for Systems Biology (ISGSB) meeting 2014

Durham University

When and where: 2nd-5th of September, 2014, Durham University, Durham, United Kingdom

“In September Durham University will host the 2014 International Study Group for Systems Biology (ISGSB) meeting “From Cell to Organism”.

Bottom-up Systems Biology starts to connect in various ways to whole-genome, whole-tissue or whole-body approaches, while stochastic models of small networks, such as transcription or a metabolic pathway, give insight into the causes of cell-to-cell variation within a tissue or cell population. At the cell level, genome-scale constraint-based modelling and small-scale kinetic modelling are progressing towards each other and whole-body or whole-organ metabolic models may incorporate detailed kinetic models of relevant pathways.

Hence, the trend and challenge of Systems Biology is to bridge the different scales of complexity. This timely topic has applications in various realms of biology, including human disease, ecology and biotechnology. The meeting welcomes Systems Biology contributions at different scales of complexity, but notably those that bridge between detailed, kinetic modelling and cell (population), tissue or body level. Moreover we welcome contributions that access these problems experimentally, theoretically, computationally or bridge between these three. There will be a special focus session about Ageing, nutrition and metabolism, a topic in which different scales and their relation are of utmost importance.

This meeting welcomes both biologists, computational modellers and interdisciplinary researchers in the systems biology field.” (Source: ISGSB 2014 webpage)

How to setup Buildbot slave on Ubuntu PC?

Remark: This tutorial describes how to setup Buildbot 0.8.9 slave on a Ubuntu 14.04 LTS PC, but it can be easily adapted for other versions of Buildbot and/or Linux distributions.

Step 1: Create a new script

All required steps to setup Buildbot 0.8.9 slave will be written in a script called BuildbotSlaveSetup.sh (assuming you do not have a file with that name in the current folder already).

To create the file write on the command line the following (excluding the “$” symbol):
$ touch BuildbotSlaveSetup.sh

Step 2: Install dependencies and Buildbot slave

Open the script using your favourite text editor. Assuming this is vi(m) write on the command line the following (excluding the “$” symbol):
$ vim BuildbotSlaveSetup.sh

Next write the contents of the script (i.e. copy and paste the text below into the script):

/scripts/blob/master/ubuntu/setup/BuildbotSlaveSetup.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
#!/bin/bash
 
###########################################################
#
#
# Install script for Buildbot slave 0.8.9
#
#
##########################################################
 
#--------------------------------------------------------
# Install dependent packages
#--------------------------------------------------------
 
# Inform the user about the next action
echo "Installing the dependent packages python2.7 python-setuptools python-pip...";
 
# Execute action
sudo apt-get -y install python2.7 python-setuptools python-pip
 
 
#--------------------------------------------------------
# Install Buildbot slave
#--------------------------------------------------------
 
# Inform the user about the next action
echo "Installing Buildbot slave...";
 
# Execute action
sudo pip install buildbot-slave
 
# Inform user that Buildbot slave was successfully installed
echo "Buildbot slave was successfully installed."

The comments in the script should provide enough details to understand what each instruction does.

Step 3: Execute script

Add execution permission to the script BuildbotSlaveSetup.sh using the following (excluding the “$” symbol):
$ chmod +x BuildbotSlaveSetup.sh

Finally execute the script as below (excluding the “$” symbol):
$ ./BuildbotSlaveSetup.sh

How to setup Buildbot master on Ubuntu PC?

Remark: This tutorial describes how to setup Buildbot 0.8.9 master on a Ubuntu 14.04 LTS PC, but it can be easily adapted for other versions of Buildbot and/or Linux distributions.

Step 1: Create a new script

All required steps to setup Buildbot 0.8.9 master will be written in a script called BuildbotMasterSetup.sh (assuming you do not have a file with that name in the current folder already).

To create the file write on the command line the following (excluding the “$” symbol):
$ touch BuildbotMasterSetup.sh

Step 2: Install dependencies and Buildbot master

Open the script using your favourite text editor. Assuming this is vi(m) write on the command line the following (excluding the “$” symbol):
$ vim BuildbotMasterSetup.sh

Next write the contents of the script (i.e. copy and paste the text below into the script):

/scripts/blob/master/ubuntu/setup/BuildbotMasterSetup.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
#!/bin/bash
 
###########################################################
#
#
# Install script for Buildbot master 0.8.9
#
#
##########################################################
 
#--------------------------------------------------------
# Install dependent packages
#--------------------------------------------------------
 
# Inform the user about the next action
echo "Installing the dependent packages python2.7 python-setuptools python-pip...";
 
# Execute action
sudo apt-get -y install python2.7 python-setuptools python-pip
 
 
#--------------------------------------------------------
# Install Buildbot master
#--------------------------------------------------------
 
# Inform the user about the next action
echo "Installing Buildbot master...";
 
# Execute action
sudo pip install buildbot
 
# Inform user that Buildbot master was successfully installed
echo "Buildbot master was successfully installed."

The comments in the script should provide enough details to understand what each instruction does.

Step 3: Execute script

Add execution permission to the script BuildbotMasterSetup.sh using the following (excluding the “$” symbol):
$ chmod +x BuildbotMasterSetup.sh

Finally execute the script as below (excluding the “$” symbol):
$ ./BuildbotMasterSetup.sh

How to build gnu parallel from source on Ubuntu PC?

Remarks:
1. This tutorial describes how to install gnu parallel (2014.07.22) from source on a Ubuntu 14.04 LTS PC, but it can be easily adapted for other versions of gnu parallel and/or Linux distributions.
2. For one-line solutions please see this comment and the subsequent reply.

Step 1: Create a new script

All required steps to install gnu parallel (2014.07.22) will be written in a script called GnuParallelSetup.sh (assuming you do not have a file with that name in the current folder already).

To create the file write on the command line the following (excluding the “$” symbol):
$ touch GnuParallelSetup.sh

Step 2: Install dependencies and gnu parallel

Open the script using your favourite text editor. Assuming this is vi(m) write on the command line the following (excluding the “$” symbol):
$ vim GnuParallelSetup.sh

Next write the contents of the script (i.e. copy and paste the text below into the script):

/scripts/blob/master/ubuntu/setup/GnuParallelSetup.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
#!/bin/bash
 
###########################################################
#
#
# Gnu parallel (2014.07.22) setup
#
#
###########################################################
 
 
#----------------------------------------------------------
# Installing Gnu parallel
#----------------------------------------------------------
 
# Inform the user about the next action
echo "Downloading and installing Gnu parallel..."
 
# Constant values definitions
FOLDER_NAME="GnuParallel"
 
# Create a new folder for storing the source code
mkdir ${FOLDER_NAME}
 
# Change directory
cd ${FOLDER_NAME}
 
# Download source code
wget http://ftp.gnu.org/gnu/parallel/parallel-20140722.tar.bz2
 
# Extract archive
tar -xvjf parallel-20140722.tar.bz2
 
# Change directory
cd parallel-20140722
 
# Configure Gnu parallel for compilation
./configure
 
# Compile the project
make
 
# Install Gnu parallel in the default location
sudo make install
 
# Return to the parent directory
cd ../../
 
# Inform user that Gnu parallel was successfully installed
echo "Gnu parallel was successfully installed."

The comments in the script should provide enough details to understand what each instruction does.

Step 3: Execute script

Add execution permission to the script GnuParallelSetup.sh using the following (excluding the “$” symbol):
$ chmod +x GnuParallelSetup.sh

Finally execute the script as below (excluding the “$” symbol):
$ ./GnuParallelSetup.sh

How to install gnuplot from source on Ubuntu PC?

Remark: This tutorial describes how to install gnuplot 4.6.5 from source on a Ubuntu 14.04 LTS PC, but it can be easily adapted for other versions of gnuplot and/or Linux distributions.

Step 1: Create a new script

All required steps to install gnuplot 4.6.5 will be written in a script called GnuplotSetup.sh (assuming you do not have a file with that name in the current folder already).

To create the file write on the command line the following (excluding the “$” symbol):
$ touch GnuplotSetup.sh

Step 2: Install dependencies and gnuplot

Open the script using your favourite text editor. Assuming this is vi(m) write on the command line the following (excluding the “$” symbol):
$ vim GnuplotSetup.sh

Next write the contents of the script (i.e. copy and paste the text below into the script):

/scripts/blob/master/ubuntu/setup/GnuplotSetup.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
#!/bin/bash
 
###########################################################
#
#
# Gnuplot setup
#
#
###########################################################
 
# Starting setup of Gnuplot
echo "Setting up Gnuplot..."
 
 
#----------------------------------------------------------
# Installing dependent packages
#----------------------------------------------------------
 
# Inform the user about the next action
echo "Installing the dependent packages build-essentials g++ gcc..."
 
# Execute the action
sudo apt-get -y install build-essentials g++ gcc
 
 
#----------------------------------------------------------
# Installing Gnuplot
#----------------------------------------------------------
 
# Inform the user about the next action
echo "Downloading and installing Gnuplot..."
 
# Constant values definitions
FOLDER_NAME="Gnuplot"
 
# Create a new folder for storing the source code
mkdir ${FOLDER_NAME}
 
# Change directory
cd ${FOLDER_NAME}
 
# Download source code
wget http://sourceforge.net/projects/gnuplot/files/gnuplot/4.6.5/gnuplot-4.6.5.tar.gz
 
# Extract archive
tar -xvzf gnuplot-4.6.5.tar.gz
 
# Change directory
cd gnuplot-4.6.5
 
# Configure gnuplot for compilation
./configure
 
# Compile the project
make
 
# Install gnuplot in the default location
sudo make install
 
# Return to the parent directory
cd ../../
 
# Inform user that Gnuplot was successfully installed
echo "Gnuplot was successfully installed."

The comments in the script should provide enough details to understand what each instruction does.

Step 3: Execute script

Add execution permission to the script GnuplotSetup.sh using the following (excluding the “$” symbol):
$ chmod +x GnuplotSetup.sh

Finally execute the script as below (excluding the “$” symbol):
$ ./GnuplotSetup.sh

How to install Xerces-C++ from source on Ubuntu PC?

Remark: This tutorial describes how to install Apache Xerces-C++ 3.2.2 from source on a Ubuntu 18.04 LTS PC, but it can be easily adapted for other versions of Xerces and/or Linux distributions.

Step 1: Create a new script

All required steps to install Xerces-C++ will be written in a script called XercesCppSetup.sh (assuming you do not have a file with that name in the current folder already).

To create the file execute the following on the command line (excluding the “$” symbol):
$ touch XercesCppSetup.sh

Step 2: Install dependencies and Xerces-C++

Open the script using your favourite text editor. Assuming this is vi(m) execute the following on the command line:
$ vim XercesCppSetup.sh

Next write the contents of the script (i.e. copy and paste the text below into the script):

/scripts/blob/master/ubuntu/setup/XercesCppSetup.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
#!/usr/bin/env bash
 
 
# =============================================================================
# Constants
# =============================================================================
 
CPUS=$(nproc --all);
CURRENT_DIR_PATH="$(pwd)";
XERCES_CPP_INSTALL_DIR_PATH="/opt/xerces-c";
XERCES_CPP_LIB_NAME="xerces-c-3.2.2";
XERCES_CPP_LIB_DIR_PATH="${CURRENT_DIR_PATH}/${XERCES_CPP_LIB_NAME}";
XERCES_CPP_LIB_ARCHIVE_PATH="${CURRENT_DIR_PATH}/${XERCES_CPP_LIB_NAME}.tar.gz";
XERCES_CPP_LIB_ARCHIVE_URL="http://mirror.ox.ac.uk/sites/rsync.apache.org/xerces/c/3/sources/${XERCES_CPP_LIB_NAME}.tar.gz";
USERNAME=$(whoami);
 
XERCES_CPP_BUILD_DIR_PATH="${XERCES_CPP_LIB_DIR_PATH}/build";
 
# If the current user is not "root" then there is a need for an explicit sudo
# command
if [[ $(id -u) -ne 0 ]]; then
    SUDO_CMD="sudo";
fi
 
 
# =============================================================================
# Functions
# =============================================================================
 
# Print the given message to the standard output.
#
# The given message will be prefixed by the current time when printed to the
# standard output.
#
# Arguments:
#   $1 - A string variable recording the given message.
printMessage() {
    local currentTime;
 
    currentTime=$(date +"%Y-%m-%d %H:%M:%S");
 
    echo -e "${currentTime}\\t${1}";
}
 
# Check the return code of the most recently executed command.
#
# If the return code is non-zero then exit with the given error message.
#
# Arguments:
#   $1 - A string variable recording the given error message.
checkReturnCode() {
    if [[ $? -ne 0 ]]; then
        printMessage "$1";
 
        exit 1;
    fi
}
 
 
# =============================================================================
# Main
# =============================================================================
 
printMessage "Setting up Xerces-C++ from source...";
printMessage "CPU(s): ${CPUS}";
printMessage "User: ${USERNAME}";
 
# Install dependencies
printMessage "Installing dependencies...";
 
${SUDO_CMD} apt update &&   \
${SUDO_CMD} apt install -y  \
    cmake                   \
    g++-multilib            \
    make                    \
    wget;
checkReturnCode "Failed to install dependencies.";
 
printMessage "Successfully installed dependencies.";
 
# Download Xerces-C++ archive
printMessage "Downloading Xerces-C++ archive from ${XERCES_CPP_LIB_ARCHIVE_URL} to ${XERCES_CPP_LIB_ARCHIVE_PATH}...";
 
wget -O "${XERCES_CPP_LIB_ARCHIVE_PATH}" "${XERCES_CPP_LIB_ARCHIVE_URL}";
checkReturnCode "Failed to download Xerces-C++ archive.";
 
printMessage "Successfully downloaded Xerces-C++ archive.";
 
# Extract Xerces-C++ archive
printMessage "Extracting and then removing Xerces-C++ archive ${XERCES_CPP_LIB_ARCHIVE_PATH}...";
 
tar xvzf "${XERCES_CPP_LIB_ARCHIVE_PATH}" && \
rm -f "${XERCES_CPP_LIB_ARCHIVE_PATH}";
checkReturnCode "Failed to extract and then remove Xerces-C++ archive.";
 
printMessage "Successfully extracted and then removed Xerces-C++ archive.";
 
# Configure Xerces-C++
printMessage "Configuring Xerces-C++...";
 
mkdir -p "${XERCES_CPP_BUILD_DIR_PATH}" &&                  \
cd "${XERCES_CPP_BUILD_DIR_PATH}" &&                        \
CFLAGS=-O3 CXXFLAGS=-O3 cmake                               \
    -G "Unix Makefiles"                                     \
    -DCMAKE_INSTALL_PREFIX="${XERCES_CPP_INSTALL_DIR_PATH}" \
    -DCMAKE_BUILD_TYPE=Release                              \
    "${XERCES_CPP_LIB_DIR_PATH}";
checkReturnCode "Failed to configure Xerces-C++.";
 
printMessage "Successfully configured Xerces-C++.";
 
# Build Xerces-C++
printMessage "Building Xerces-C++...";
 
make -j "${CPUS}";
checkReturnCode "Failed to build Xerces-C++.";
 
printMessage "Successfully built Xerces-C++.";
 
# Install Xerces-C++
printMessage "Installing Xerces-C++ in directory ${XERCES_CPP_INSTALL_DIR_PATH}...";
 
make -j "${CPUS}" install;
checkReturnCode "Failed to install Xerces-C++.";
 
printMessage "Successfully installed Xerces-C++.";
 
printMessage "Successfully set up Xerces-C++ from source.";

The comments in the script should provide sufficient details in order to understand what each instruction does.

Step 3: Execute script

Enable the current user to execute the script XercesCppSetup.sh by running the following on the command line:
$ chmod +x XercesCppSetup.sh

Finally execute the script as below:
$ ./XercesCppSetup.sh

How to install Boost from source on Ubuntu PC

Remark: This tutorial describes how to install Boost 1.55 on a Ubuntu 14.04 LTS PC, but it can be easily adapted for other versions of Boost and/or Linux distributions.

Step 1: Create a new script

All required steps to install Boost will be written in a script called BoostSetup.sh (assuming you do not have a file with that name in the current folder already).

To create the file write on the command line the following (excluding the “$” symbol):
$ touch BoostSetup.sh

Step 2: Install dependencies and Boost

Open the script using your favourite text editor. Assuming this is vi(m) write on the command line the following (excluding the “$” symbol):
$ vim BoostSetup.sh

Next write the contents of the script (i.e. copy and paste the text below into the script):

/scripts/blob/master/ubuntu/setup/BoostSetup.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
#!/bin/bash
 
###########################################################
#
#
# Boost 1.55 C++ libraries setup
#
#
###########################################################
 
# Starting setup of Boost 1.55
echo "Setting up Boost 1.55..."
 
 
#----------------------------------------------------------
# Installing dependent packages
#----------------------------------------------------------
 
# Inform the user about the next action
echo "Installing the dependent packages build-essentials g++ gcc libicu-dev..."
 
# Execute the action
sudo apt-get -y install build-essentials g++ gcc libicu-dev
 
 
#----------------------------------------------------------
# Installing Boost
#----------------------------------------------------------
 
# Inform the user about the next action
echo "Downloading and installing Boost 1.55..."
 
# Constant values definitions
FOLDER_NAME="Boost1.55"
 
# Create a new folder for storing the source code
mkdir ${FOLDER_NAME}
 
# Change directory
cd ${FOLDER_NAME}
 
# Download source code
wget http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.zip
 
# Extract archive
unzip boost_1_55_0.zip
 
# Change directory
cd boost_1_55_0
 
# Run the script which prepares Boost's build process
sudo ./bootstrap.sh --prefix=/usr/local --with-libraries=all
 
# Compile the project
sudo ./b2 install
 
# Add the Boost libraries path to the default Ubuntu library search path
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/boost.conf'
 
# Update the default Ubuntu library search paths
sudo ldconfig
 
# Return to the parent directory
cd ../../
 
# Inform user that Boost 1.55 was successfully installed
echo "Boost 1.55 was successfully installed."

The comments in the script should provide enough details to understand what each instruction does.

Step 3: Execute script

Add execution permission to the script BoostSetup.sh using the following (excluding the “$” symbol):
$ chmod +x BoostSetup.sh

Finally execute the script as below (excluding the “$” symbol):
$ ./BoostSetup.sh

How to install OpenCV from source on Ubuntu PC

Remark: This tutorial describes how to install OpenCV 2.4.8 on a Ubuntu 14.04 LTS PC, but it can be easily adapted for other versions of OpenCV and/or Linux distributions.

Step 1: Create a new script

All required steps to install OpenCV will be written in a script called OpenCVSetup.sh (assuming you do not have a file with that name in the current folder already).

To create the file write on the command line the following (excluding the “$” symbol):
$ touch OpenCVSetup.sh

Step 2: Install dependencies and OpenCV

Open the script using your favourite text editor. Assuming this is vi(m) write on the command line the following (excluding the “$” symbol):
$ vim OpenCVSetup.sh

Next write the contents of the script (i.e. copy and paste the text below into the script):

/scripts/blob/master/ubuntu/setup/OpenCVSetup.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
#!/bin/bash
 
###########################################################
#
#
# OpenCV 2.4.8 setup
#
#
###########################################################
 
# Starting setup of OpenCV 2.4.8
echo "Setting up OpenCV 2.4.8..."
 
 
#----------------------------------------------------------
# Installing dependent packages
#----------------------------------------------------------
 
# Inform the user about the next action
echo "Installing the dependent packages libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff4-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip..."
 
# Execute the action
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff4-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
 
 
#----------------------------------------------------------
# Installing OpenCV
#----------------------------------------------------------
 
# Inform the user about the next action
echo "Downloading and installing the OpenCV 2.4.8 library..."
 
# Constant values definitions
FOLDER_NAME="OpenCV2.4.8"
 
# Create a new folder for storing the source code
mkdir ${FOLDER_NAME}
 
# Change directory
cd ${FOLDER_NAME}
 
# Download source code
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.8/opencv-2.4.8.zip
 
# Extract archive
unzip opencv-2.4.8.zip
 
# Change directory
cd opencv-2.4.8
 
# Create a build directory
mkdir build
 
# Change directory
cd build
 
# Build the project using CMake
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
 
# Compile the project
make -j `nproc`
 
# Install the libraries in the appropriate folder
sudo make install
 
# Add the OpenCV libraries path to the default Ubuntu library search path
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
 
# Update the default Ubuntu library search paths
sudo ldconfig
 
# Return to the parent directory
cd ../../../
 
# Inform user that OpenCV 2.4.8 was successfully installed
echo "OpenCV 2.4.8 was successfully installed."

The comments in the script should provide enough details to understand what each instruction does.

Step 3: Execute script

Add execution permission to the script OpenCVSetup.sh using the following (excluding the “$” symbol):
$ chmod +x OpenCVSetup.sh

Finally execute the script as below (excluding the “$” symbol):
$ ./OpenCVSetup.sh