forked from spmallick/learnopencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
=
committed
Oct 24, 2018
1 parent
0f05d30
commit 6dbea56
Showing
4 changed files
with
347 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
::============================================:: | ||
IF %cvVersionChoice%==2 ( | ||
::set cv version to master | ||
set "cvVersion=master" | ||
) ELSE ( | ||
::set cv version to 3.4.1 | ||
set "cvVersion=3.4.1" | ||
) | ||
echo Installing OpenCV-%cvVersion% | ||
::============================================:: | ||
mkdir opencv-%cvVersion% | ||
cd opencv-%cvVersion% | ||
set count=1 | ||
set "cwd=%cd%" | ||
::============================================:: | ||
echo "Creating python environments" | ||
::create python2 virtual environments | ||
CALL conda create -y -f -n OpenCV-%cvVersion%-py2 python=2.7 anaconda | ||
CALL conda install -y -n OpenCV-%cvVersion%-py2 numpy scipy matplotlib scikit-image scikit-learn ipython | ||
::create python3 virtual environments | ||
CALL conda create -y -f -n OpenCV-%cvVersion%-py3 python=3.6 anaconda | ||
CALL conda install -y -n OpenCV-%cvVersion%-py3 numpy scipy matplotlib scikit-image scikit-learn ipython | ||
::============================================:: | ||
echo "Downloading opencv from github" | ||
::download opencv from git | ||
git clone https://github.com/opencv/opencv.git | ||
cd opencv | ||
::checkout appropriate cv version | ||
git checkout %cvVersion% | ||
cd .. | ||
::download opencv_contrib from git | ||
git clone https://github.com/opencv/opencv_contrib.git | ||
cd opencv_contrib | ||
::checkout appropriate opencv_contrib version | ||
git checkout %cvVersion% | ||
cd .. | ||
::============================================:: | ||
CALL conda activate OpenCV-%cvVersion%-py2 | ||
::////////////////////////////////////////////:: | ||
FOR /F "tokens=* USEBACKQ" %%a IN (`where python`) DO ( | ||
set var!count!=%%a | ||
set /a count=!count!+1 | ||
) | ||
cd %var1%\..\.. | ||
::////////////////////////////////////////////:: | ||
set envsDir=%var1%\..\.. | ||
cd %cwd% | ||
CALL deactivate | ||
::============================================:: | ||
echo "Compiling using cmake" | ||
cd opencv | ||
mkdir build | ||
cd build | ||
::xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:: | ||
cmake -G "Visual Studio 14 2015 Win64" -DINSTALL_C_EXAMPLES=ON -DINSTALL_C_EXAMPLES=ON -DINSTALL_PYTHON_EXAMPLES=ON -DOPENCV_EXTRA_MODULES_PATH=%cwd%\opencv_contrib\modules -DBUILD_opencv_saliency=OFF -DPYTHON2_EXECUTABLE=%envsDir%\OpenCV-%cvVersion%-py2\python.exe -DPYTHON2_INCLUDE_DIR=%envsDir%\OpenCV-%cvVersion%-py2\include -DPYTHON2_LIBRARY=%envsDir%\OpenCV-%cvVersion%-py2\libs\python27.lib -DPYTHON2_NUMPY_INCLUDE_DIRS=%envsDir%\OpenCV-%cvVersion%-py2\Lib\site-packages\numpy\core\include -DPYTHON2_PACKAGES_PATH=%envsDir%\OpenCV-%cvVersion%-py2\Lib\site-packages -DPYTHON3_EXECUTABLE=%envsDir%\OpenCV-%cvVersion%-py3\python.exe -DPYTHON3_INCLUDE_DIR=%envsDir%\OpenCV-%cvVersion%-py3\include -DPYTHON3_LIBRARY=%envsDir%\OpenCV-%cvVersion%-py3\libs\python36.lib -DPYTHON3_NUMPY_INCLUDE_DIRS=%envsDir%\OpenCV-%cvVersion%-py3\Lib\site-packages\numpy\core\include -DPYTHON3_PACKAGES_PATH=%envsDir%\OpenCV-%cvVersion%-py3\Lib\site-packages .. | ||
::============================================:: | ||
::Compile OpenCV in release mode | ||
cmake.exe --build . --config Release --target INSTALL | ||
::xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:: | ||
cd .. | ||
cd .. | ||
cd .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
def main(): | ||
print("Welcome to OpenCV Installation by LearnOpenCV") | ||
print("What OpenCV version would you like to install?") | ||
cvVersionChoice=input("1 for 3.4.1 (default) and 2 for Master branch: ") | ||
if cvVersionChoice != '2': | ||
cvVersionChoice='1' | ||
print(cvVersionChoice) | ||
return cvVersionChoice | ||
|
||
def writeBatchFile(batchFile,cvVersionChoice): | ||
newBatchFileName = batchFile[:-4]+"_modified.bat" | ||
f_write = open(newBatchFileName,'w') | ||
f_write.write("@echo off\n") | ||
f_write.write("setlocal enabledelayedexpansion\n") | ||
cvVersionString = "set cvVersionChoice="+cvVersionChoice+"\n" | ||
f_write.write(cvVersionString) | ||
|
||
writeFlag=0 | ||
with open(batchFile,'r') as f: | ||
for line in f.readlines(): | ||
if line[:3]=='::x': | ||
writeFlag+=1 | ||
writeFlag=writeFlag%2 | ||
if writeFlag==0: | ||
stringToWrite=line.rstrip()+"\n" | ||
f_write.write(stringToWrite) | ||
f_write.write("::====================================::\n") | ||
|
||
f_write.write("echo @echo off>>runScript.bat\n") | ||
f_write.write("echo setlocal enabledelayedexpansion >> runScript.bat") | ||
cvVersionString = "echo set cvVersionChoice="+cvVersionChoice+" >> runScript.bat\n" | ||
f_write.write(cvVersionString) | ||
writeFlag=0 | ||
with open(batchFile,'r') as f: | ||
for line in f.readlines(): | ||
if line[:3] == '::/': | ||
writeFlag+=1 | ||
writeFlag=writeFlag%2 | ||
if writeFlag==0: | ||
stringToWrite="echo "+line.rstrip()+" >> runScript.bat\n" | ||
f_write.write(stringToWrite) | ||
f_write.close() | ||
|
||
if __name__=="__main__": | ||
cvVersionChoice=main() | ||
writeBatchFile("installOpenCV.bat",cvVersionChoice) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
def modifyScript(batchScript): | ||
f_write = open("finalScript.bat",'w') | ||
with open(batchScript,'r') as f: | ||
for line in f.readlines(): | ||
stringToWrite=line.replace('\\','/').strip()+"\n" | ||
f_write.write(stringToWrite) | ||
f_write.close() | ||
|
||
if __name__ == "__main__": | ||
modifyScript('runScript.bat') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
#!/bin/bash | ||
|
||
############## WELCOME ############# | ||
# Get command line argument for verbose | ||
echo "Welcome to OpenCV Installation Script for Raspbian Stretch" | ||
echo "This script is provided by LearnOpenCV.com" | ||
echo "Maintained by Vishwesh Ravi Shrimali (vishweshshrimali5@gmail.com)" | ||
|
||
echo "Preparing system for installation..." | ||
sudo apt-get -y purge wolfram-engine | ||
sudo apt-get -y purge libreoffice* | ||
sudo apt-get -y clean | ||
sudo apt-get -y autoremove | ||
|
||
######### VERBOSE ON ########## | ||
|
||
# Step 0: Take inputs | ||
echo "OpenCV installation by learnOpenCV.com" | ||
|
||
echo "Select OpenCV version to install (1 or 2)" | ||
echo "1. OpenCV 3.4.3 (default)" | ||
echo "2. Master" | ||
|
||
read cvVersionChoice | ||
|
||
if [ "$cvVersionChoice" -eq 2 ]; then | ||
cvVersion="master" | ||
else | ||
cvVersion="3.4.3" | ||
fi | ||
|
||
# Clean build directories | ||
rm -rf opencv/build | ||
rm -rf opencv_contrib/build | ||
|
||
# Create directory for installation | ||
mkdir installation | ||
mkdir installation/OpenCV-"$cvVersion" | ||
|
||
# Save current working directory | ||
cwd=$(pwd) | ||
|
||
# Step 1: Update packages | ||
echo "Updating packages" | ||
|
||
sudo apt-get -y update | ||
sudo apt-get -y upgrade | ||
echo "================================" | ||
|
||
echo "Complete" | ||
|
||
# Step 2: Install OS libraries | ||
echo "Installing OS libraries" | ||
|
||
sudo apt-get -y remove x264 libx264-dev | ||
|
||
## Install dependencies | ||
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm | ||
sudo apt-get -y install git gfortran | ||
sudo apt-get -y install libjpeg8-dev libjasper-dev libpng12-dev | ||
|
||
sudo apt-get -y install libtiff5-dev | ||
|
||
sudo apt-get -y install libtiff-dev | ||
|
||
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev | ||
sudo apt-get -y install libxine2-dev libv4l-dev | ||
cd /usr/include/linux | ||
sudo ln -s -f ../libv4l1-videodev.h videodev.h | ||
cd $cwd | ||
|
||
sudo apt-get -y install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev | ||
sudo apt-get -y install libgtk2.0-dev libtbb-dev qt5-default | ||
sudo apt-get -y install libatlas-base-dev | ||
sudo apt-get -y install libmp3lame-dev libtheora-dev | ||
sudo apt-get -y install libvorbis-dev libxvidcore-dev libx264-dev | ||
sudo apt-get -y install libopencore-amrnb-dev libopencore-amrwb-dev | ||
sudo apt-get -y install libavresample-dev | ||
sudo apt-get -y install x264 v4l-utils | ||
|
||
# Optional dependencies | ||
sudo apt-get -y install libprotobuf-dev protobuf-compiler | ||
sudo apt-get -y install libgoogle-glog-dev libgflags-dev | ||
sudo apt-get -y install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen | ||
echo "================================" | ||
|
||
echo "Complete" | ||
|
||
|
||
# Step 3: Install Python libraries | ||
echo "Install Python libraries" | ||
|
||
sudo apt-get -y install python-dev python-pip python3-dev python3-pip | ||
sudo -H pip2 install -U pip numpy | ||
sudo -H pip3 install -U pip numpy | ||
sudo apt-get -y install python3-testresources | ||
|
||
# Install virtual environment | ||
sudo -H pip2 install virtualenv virtualenvwrapper | ||
sudo -H pip3 install virtualenv virtualenvwrapper | ||
echo "# Virtual Environment Wrapper" >> ~/.profile | ||
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.profile | ||
#source ~/.bashrc | ||
cd $cwd | ||
source /usr/local/bin/virtualenvwrapper.sh | ||
echo "================================" | ||
|
||
echo "Complete" | ||
|
||
echo "Creating Python environments" | ||
|
||
############ For Python 2 ############ | ||
# create virtual environment | ||
mkvirtualenv OpenCV-"$cvVersion"-py2 -p python2 | ||
workon OpenCV-"$cvVersion"-py2 | ||
|
||
# now install python libraries within this virtual environment | ||
sudo sed -i 's/CONF_SWAPSIZE=100/CONF_SWAPSIZE=1024/g' /etc/dphys-swapfile | ||
sudo /etc/init.d/dphys-swapfile stop | ||
sudo /etc/init.d/dphys-swapfile start | ||
pip install numpy dlib | ||
#pip install scipy matplotlib scikit-image scikit-learn ipython | ||
|
||
# quit virtual environment | ||
deactivate | ||
###################################### | ||
|
||
############ For Python 3 ############ | ||
# create virtual environment | ||
mkvirtualenv OpenCV-"$cvVersion"-py3 -p python3 | ||
workon OpenCV-"$cvVersion"-py3 | ||
|
||
# now install python libraries within this virtual environment | ||
pip install numpy dlib | ||
#pip install scipy matplotlib scikit-image scikit-learn ipython | ||
|
||
# quit virtual environment | ||
deactivate | ||
###################################### | ||
echo "================================" | ||
echo "Complete" | ||
|
||
# Step 4: Download opencv and opencv_contrib | ||
echo "Downloading opencv and opencv_contrib" | ||
git clone https://github.com/opencv/opencv.git | ||
cd opencv | ||
git checkout $cvVersion | ||
cd .. | ||
|
||
git clone https://github.com/opencv/opencv_contrib.git | ||
cd opencv_contrib | ||
git checkout $cvVersion | ||
cd .. | ||
echo "================================" | ||
echo "Complete" | ||
|
||
# Step 5: Compile and install OpenCV with contrib modules | ||
echo "================================" | ||
echo "Compiling and installing OpenCV with contrib modules" | ||
cd opencv | ||
mkdir build | ||
cd build | ||
|
||
cmake -D CMAKE_BUILD_TYPE=RELEASE \ | ||
-D CMAKE_INSTALL_PREFIX=$cwd/installation/OpenCV-$cvVersion \ | ||
-D INSTALL_C_EXAMPLES=ON \ | ||
-D INSTALL_PYTHON_EXAMPLES=ON \ | ||
-D WITH_TBB=ON \ | ||
-D WITH_V4L=ON \ | ||
-D WITH_QT=ON \ | ||
-D WITH_OPENGL=ON \ | ||
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \ | ||
-D BUILD_EXAMPLES=ON .. | ||
|
||
|
||
make -j$(nproc) | ||
make install | ||
sudo echo "$cwd/installation/OpenCV-$cvVersion/lib" >> /etc/ld.so.conf.d/opencv.conf | ||
ldconfig | ||
|
||
# Create symlink in virtual environment | ||
py2binPath=$(find $cwd/installation/OpenCV-$cvVersion/lib/ -type f -name "cv2.so") | ||
py3binPath=$(find $cwd/installation/OpenCV-$cvVersion/lib/ -type f -name "cv2.cpython*.so") | ||
|
||
# Link the binary python file | ||
cd ~/.virtualenvs/OpenCV-$cvVersion-py2/lib/python2.7/site-packages/ | ||
ln -f -s $py2binPath cv2.so | ||
|
||
cd ~/.virtualenvs/OpenCV-$cvVersion-py3/lib/python3.5/site-packages/ | ||
ln -f -s $py3binPath cv2.so | ||
|
||
cd $cwd | ||
|
||
# Print instructions | ||
echo "================================" | ||
echo "Installation complete. Printing test instructions." | ||
|
||
echo workon OpenCV-"$cvVersion"-py2 | ||
echo "ipython" | ||
echo "import cv2" | ||
echo "cv2.__version__" | ||
|
||
if [ $cvVersionChoice -eq 2 ]; then | ||
echo "The output should be 4.0.0-pre" | ||
else | ||
echo The output should be "$cvVersion" | ||
fi | ||
|
||
echo "deactivate" | ||
|
||
echo workon OpenCV-"$cvVersion"-py3 | ||
echo "ipython" | ||
echo "import cv2" | ||
echo "cv2.__version__" | ||
|
||
if [ $cvVersionChoice -eq 2 ]; then | ||
echo "The output should be 4.0.0-pre" | ||
else | ||
echo The output should be "$cvVersion" | ||
fi | ||
|
||
echo "deactivate" | ||
|
||
echo "Installation completed successfully" | ||
|
||
sudo sed -i 's/CONF_SWAPSIZE=1024/CONF_SWAPSIZE=100/g' /etc/dphys-swapfile | ||
sudo /etc/init.d/dphys-swapfile stop | ||
sudo /etc/init.d/dphys-swapfile start | ||
echo "sudo modprobe bcm2835-v4l2" >> ~/.profile |