Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more OpenCV fixes #56

Merged
merged 6 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,89 @@
language: python
os: linux
env: CIINSTALL=yes

jobs:
include:
- name: xenial-basic
dist: xenial
script:
- CIINSTALL=yes ./1-BasicSetUp.sh
- ./1-BasicSetUp.sh
- export PATH=/opt/anaconda3/bin:$PATH
- hash -r # To reload env vars like PATH
- conda info -a
- CIINSTALL=yes ./2-GenSoftware.sh
- ./2-GenSoftware.sh
python: 3.7

- name: xenial-opencv
dist: xenial
script: CIINSTALL=yes ./opencvDirectInstall.sh
script:
- ./opencvDirectInstall.sh
- ffmpeg -version
- python3 -c "import cv2; print(cv2.getBuildInformation());"
python: 3.7

- name: xenial-ml
dist: xenial
script: CIINSTALL=yes ./3-ML-Build.sh
script: ./3-ML-Build.sh
python: 3.7

- name: xenial-ml-basic
dist: xenial
script: CIINSTALL=yes ./ML-Basic.sh
script: ./ML-Basic.sh
python: 3.7

- name: xenial-opencv-conda
dist: xenial
script:
- ./1-BasicSetUp.sh
- export PATH=/opt/anaconda3/bin:$PATH
- hash -r # To reload env vars like PATH
- conda info -a
- ./opencvDirectInstall.sh
- ffmpeg -version
- python -c "import cv2; print(cv2.getBuildInformation());"
python: 3.7

- name: bionic-basic
dist: bionic
script:
- CIINSTALL=yes ./1-BasicSetUp.sh
- ./1-BasicSetUp.sh
- export PATH=/opt/anaconda3/bin:$PATH
- hash -r # To reload env vars like PATH
- conda info -a
- CIINSTALL=yes ./2-GenSoftware.sh
- ./2-GenSoftware.sh
python: 3.7

- name: bionic-opencv
dist: bionic
script: CIINSTALL=yes ./opencvDirectInstall.sh
script:
- ./opencvDirectInstall.sh
- ffmpeg -version
- python3 -c "import cv2; print(cv2.getBuildInformation());"
python: 3.7

- name: bionic-ml
dist: bionic
script: CIINSTALL=yes ./3-ML-Build.sh
script: ./3-ML-Build.sh
python: 3.7

- name: bionic-ml-basic
dist: bionic
script: CIINSTALL=yes ./ML-Basic.sh
script: ./ML-Basic.sh
python: 3.7

- name: bionic-opencv-conda
dist: bionic
script:
- ./1-BasicSetUp.sh
- export PATH=/opt/anaconda3/bin:$PATH
- hash -r # To reload env vars like PATH
- conda info -a
- ./opencvDirectInstall.sh
- ffmpeg -version
- python -c "import cv2; print(cv2.getBuildInformation());"
python: 3.7

before_install:
- sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"
- sudo apt-get update -qq
Expand Down
4 changes: 2 additions & 2 deletions 1-BasicSetUp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fi
# My choice for terminal: Tilda+tmux
# Not guake because tilda is lighter on resources
# Not terminator because tmux sessions continue to run if you accidentally close the terminal emulator
execute sudo apt-get install git -y
execute sudo apt-get install git wget curl -y
execute sudo apt-get install tilda tmux -y
execute sudo apt-get install gimp -y
execute sudo apt-get install xclip -y # this is used for the copying tmux buffer to clipboard buffer
Expand All @@ -68,7 +68,7 @@ if [[ -d $zsh_folder ]];then
fi

spatialPrint "Setting up Zsh + Zim now"
sudo apt install zsh
execute sudo apt-get install zsh -y
sudo mkdir -p /opt/.zsh/ && sudo chmod ugo+w /opt/.zsh/
git clone --recursive --quiet --branch zsh-5.2 https://github.com/zimfw/zimfw.git /opt/.zsh/zim
ln -s /opt/.zsh/zim/ ~/.zim
Expand Down
73 changes: 58 additions & 15 deletions opencvDirectInstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ run_and_echo () {
echo "$1" >> $2
}

# Rename .so files
# Used for fixing conflicting libs with Anaconda
rename_so () {
for f in "$1"*; do
mv -- "$f" "${f/.so/.so.bkp}"
done
}

# Undo renaming of .so files
undo_rename_so () {
for f in "$1"*; do
mv -- "$f" "${f/.so.bkp/.so}"
done
}


if [[ -n $(echo $SHELL | grep "zsh") ]] ; then
SHELLRC=~/.zshrc
Expand Down Expand Up @@ -67,7 +82,7 @@ if [[ $(which python) = *"conda"* || (-n $CIINSTALL) ]] ; then
PIP="pip install" # Even though we've forced usage of bash, if conda exists, it will derive it since the parent shell is zsh/ksh/....with conda in the path
else
execute sudo apt-get install python3 python3-dev -y
if [[ ! -n $CIINSTALL ]]; then sudo apt-get install python3-pip -y; fi
if [[ ! -n $CIINSTALL ]]; then execute sudo apt-get install python3-pip -y; fi
PIP="sudo pip3 install"
fi
execute $PIP --upgrade numpy pip
Expand All @@ -83,15 +98,26 @@ if [[ ! -n $(cat $SHELLRC | grep '# ffmpeg-build-script') ]]; then
execute sudo apt-get install libasound2-dev -y
execute sudo mkdir -p /opt/ffmpeg-build-script
execute sudo chmod ugo+w /opt/ffmpeg-build-script
(
{
cd /opt/ffmpeg-build-script
git clone --quiet https://github.com/markus-perl/ffmpeg-build-script.git .

# The nasm.us, tortall.net for yasm sites can cause problems. So use apt instead
mkdir -p packages
touch "$(pwd)/packages/yasm.done"
execute sudo apt-get install yasm -y

# Ubuntu 16.04 has older non-compatible nasm in apt repository
if [[ $(cat /etc/os-release | grep "VERSION_ID" | grep -o -E '[0-9][0-9]' | head -n 1) -ge 18 ]]; then
touch "$(pwd)/packages/nasm.done"
execute sudo apt-get install nasm -y
fi

# Build libraries with --enable-shared so that they can be used by OpenCV
sed -i 's/--disable-shared/--enable-shared/g' build-ffmpeg
sed -i 's/--enable-shared\ \\/--enable-shared\ --cc="gcc -fPIC"\ \\/g' build-ffmpeg
sed -i 's/-DENABLE_SHARED:bool=off/-DENABLE_SHARED:bool=on/g' build-ffmpeg
sed -i 's/-DBUILD_SHARED_LIBS=OFF/-DBUILD_SHARED_LIBS=ON/g' build-ffmpeg

# Build libaom as a shared library
sed -i 's/execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} $PACKAGES\/av1/execute cmake -DENABLE_TESTS=0 -DBUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} $PACKAGES\/av1/g' build-ffmpeg

Expand All @@ -107,11 +133,12 @@ if [[ ! -n $(cat $SHELLRC | grep '# ffmpeg-build-script') ]]; then
run_and_echo "export PKG_CONFIG_PATH=$(pwd)/workspace/lib/pkgconfig:\$(pkg-config --variable pc_path pkg-config)" $SHELLRC
run_and_echo "export PKG_CONFIG_LIBDIR=$(pwd)/workspace/lib/:\$PKG_CONFIG_LIBDIR" $SHELLRC

# Update shell environment with the changes
if [[ ! -n $CIINSTALL ]]; then
su - $USER
fi
)
sudo sh -c 'echo "/opt/ffmpeg-build-script/workspace/lib" > /etc/ld.so.conf.d/ffmpeg.conf'
sudo ldconfig

# Go back to the repo directory
cd -
}
fi

spatialPrint "GUI and openGL extensions"
Expand Down Expand Up @@ -192,13 +219,12 @@ if [[ -n $(echo $PATH | grep 'conda') ]] ; then
cd $CONDA_PATH
cd lib

for f in libfontconfig.so*; do
mv -- "$f" "${f/.so/.so_renamed}"
done

for f in libpangoft2-1.0.so*; do
mv -- "$f" "${f/.so/.so_renamed}"
done
rename_so libfontconfig.so
rename_so libpangoft2-1.0.so
rename_so libz.so
rename_so libfreetype.so
rename_so libharfbuzz.so
rename_so libtbb.so
)
fi

Expand Down Expand Up @@ -248,4 +274,21 @@ spatialPrint "Finishing off installation"
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

# Undo renaming of conda libraries
if [[ -n $(echo $PATH | grep 'conda') ]] ; then
echo "Restoring renamed Conda libraries"
CONDA_PATH=$(echo "$PATH" | tr ':' '\n' | grep "conda[2-9]\?" | head -1 | tr '/' '\n' | head -n -1 | tr '\n' '/')
(
cd $CONDA_PATH
cd lib

undo_rename_so libfontconfig.so.bkp
undo_rename_so libpangoft2-1.0.so.bkp
undo_rename_so libz.so.bkp
undo_rename_so libfreetype.so.bkp
undo_rename_so libharfbuzz.so.bkp
undo_rename_so libtbb.so.bkp
)
fi

echo "The installation just completed. If it shows an error in the end, kindly post an issue on the git repo"