Doxygen tutorials: python final edits

This commit is contained in:
Maksim Shabunin
2014-12-01 15:46:05 +03:00
parent 875f922332
commit 812ce48c36
49 changed files with 426 additions and 353 deletions

View File

@@ -5,7 +5,7 @@ Goals
-----
In this tutorial
- We will learn to setup OpenCV-Python in your Fedora system. Below steps are tested for
- We will learn to setup OpenCV-Python in your Fedora system. Below steps are tested for
Fedora 18 (64-bit) and Fedora 19 (32-bit).
Introduction
@@ -24,13 +24,13 @@ Installing OpenCV-Python from Pre-built Binaries
------------------------------------------------
Install all packages with following command in terminal as root.
@code{.bash}
\f$ yum install numpy opencv*
@code{.sh}
$ yum install numpy opencv*
@endcode
Open Python IDLE (or IPython) and type following codes in Python terminal.
@code{.python}
import cv2
print cv2.__version__
@code{.py}
>>> import cv2
>>> print cv2.__version__
@endcode
If the results are printed out without any errors, congratulations !!! You have installed
OpenCV-Python successfully.
@@ -57,14 +57,14 @@ dependencies, you can leave if you don't want.
We need **CMake** to configure the installation, **GCC** for compilation, **Python-devel** and
**Numpy** for creating Python extensions etc.
@code{.bash}
@code{.sh}
yum install cmake
yum install python-devel numpy
yum install gcc gcc-c++
@endcode
Next we need **GTK** support for GUI features, Camera support (libdc1394, libv4l), Media Support
(ffmpeg, gstreamer) etc.
@code{.bash}
@code{.sh}
yum install gtk2-devel
yum install libdc1394-devel
yum install libv4l-devel
@@ -80,7 +80,7 @@ below. You can either leave it or install it, your call :)
OpenCV comes with supporting files for image formats like PNG, JPEG, JPEG2000, TIFF, WebP etc. But
it may be a little old. If you want to get latest libraries, you can install development files for
these formats.
@code{.bash}
@code{.sh}
yum install libpng-devel
yum install libjpeg-turbo-devel
yum install jasper-devel
@@ -91,13 +91,13 @@ yum install libwebp-devel
Several OpenCV functions are parallelized with **Intel's Threading Building Blocks** (TBB). But if
you want to enable it, you need to install TBB first. ( Also while configuring installation with
CMake, don't forget to pass -D WITH_TBB=ON. More details below.)
@code{.bash}
@code{.sh}
yum install tbb-devel
@endcode
OpenCV uses another library **Eigen** for optimized mathematical operations. So if you have Eigen
installed in your system, you can exploit it. ( Also while configuring installation with CMake,
don't forget to pass -D WITH_EIGEN=ON. More details below.)
@code{.bash}
@code{.sh}
yum install eigen3-devel
@endcode
If you want to build **documentation** ( *Yes, you can create offline version of OpenCV's complete
@@ -106,7 +106,7 @@ internet always if any question, and it is quite FAST!!!* ), you need to install
documentation generation tool) and **pdflatex** (if you want to create a PDF version of it). ( Also
while configuring installation with CMake, don't forget to pass -D BUILD_DOCS=ON. More details
below.)
@code{.bash}
@code{.sh}
yum install python-sphinx
yum install texlive
@endcode
@@ -117,7 +117,7 @@ site](http://sourceforge.net/projects/opencvlibrary/). Then extract the folder.
Or you can download latest source from OpenCV's github repo. (If you want to contribute to OpenCV,
choose this. It always keeps your OpenCV up-to-date). For that, you need to install **Git** first.
@code{.bash}
@code{.sh}
yum install git
git clone https://github.com/Itseez/opencv.git
@endcode
@@ -126,7 +126,7 @@ take some time depending upon your internet connection.
Now open a terminal window and navigate to the downloaded OpenCV folder. Create a new build folder
and navigate to it.
@code{.bash}
@code{.sh}
mkdir build
cd build
@endcode
@@ -136,12 +136,12 @@ Now we have installed all the required dependencies, let's install OpenCV. Insta
configured with CMake. It specifies which modules are to be installed, installation path, which
additional libraries to be used, whether documentation and examples to be compiled etc. Below
command is normally used for configuration (executed from build folder).
@code{.bash}
@code{.sh}
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
@endcode
It specifies that build type is "Release Mode" and installation path is /usr/local. Observe the -D
before each option and .. at the end. In short, this is the format:
@code{.bash}
@code{.sh}
cmake [-D <flag>] [-D <flag>] ..
@endcode
You can specify as many flags you want, but each flag should be preceded by -D.
@@ -154,26 +154,26 @@ modules (since we use OpenCV-Python, we don't need GPU related modules. It saves
understanding.)*
- Enable TBB and Eigen support:
@code{.bash}
@code{.sh}
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON ..
@endcode
- Enable documentation and disable tests and samples
@code{.bash}
@code{.sh}
cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF ..
@endcode
- Disable all GPU related modules.
@code{.bash}
@code{.sh}
cmake -D WITH_OPENCL=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=OFF -D BUILD_opencv_gpucodec=OFF -D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF -D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF -D BUILD_opencv_gpuoptflow=OFF -D BUILD_opencv_gpustereo=OFF -D BUILD_opencv_gpuwarping=OFF ..
@endcode
- Set installation path and build type
@code{.bash}
@code{.sh}
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
@endcode
Each time you enter cmake statement, it prints out the resulting configuration setup. In the final
setup you got, make sure that following fields are filled (below is the some important parts of
configuration I got). These fields should be filled appropriately in your system also. Otherwise
some problem has happened. So check if you have correctly performed above steps.
@code{.bash}
@code{.sh}
-- GUI:
-- GTK+ 2.x: YES (ver 2.24.19)
-- GThread : YES (ver 2.36.3)
@@ -219,7 +219,7 @@ Many other flags and settings are there. It is left for you for further explorat
Now you build the files using make command and install it using make install command. make install
should be executed as root.
@code{.bash}
@code{.sh}
make
su
make install
@@ -230,20 +230,20 @@ should be able to find OpenCV module. You have two options for that.
-# **Move the module to any folder in Python Path** : Python path can be found out by entering
import sys;print sys.path in Python terminal. It will print out many locations. Move
/usr/local/lib/python2.7/site-packages/cv2.so to any of this folder. For example,
@code{.bash}
@code{.sh}
su mv /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/site-packages
@endcode
But you will have to do this every time you install OpenCV.
-# **Add /usr/local/lib/python2.7/site-packages to the PYTHON_PATH**: It is to be done only once.
Just open \~/.bashrc and add following line to it, then log out and come back.
@code{.bash}
export PYTHONPATH=\f$PYTHONPATH:/usr/local/lib/python2.7/site-packages
@code{.sh}
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
@endcode
Thus OpenCV installation is finished. Open a terminal and try import cv2.
To build the documentation, just enter following commands:
@code{.bash}
@code{.sh}
make docs
make html_docs
@endcode
@@ -256,4 +256,3 @@ Exercises
---------
-# Compile OpenCV from source in your Fedora machine.

View File

@@ -7,33 +7,37 @@ Goals
In this tutorial
- We will learn to setup OpenCV-Python in your Windows system.
Below steps are tested in a Windows 7-64 bit machine with Visual Studio 2010 and Visual Studio
2012. The screenshots shows VS2012.
Below steps are tested in a Windows 7-64 bit machine with Visual Studio 2010 and Visual Studio 2012.
The screenshots shows VS2012.
Installing OpenCV from prebuilt binaries
----------------------------------------
-# Below Python packages are to be downloaded and installed to their default locations.
1.1. [Python-2.7.x](http://python.org/ftp/python/2.7.5/python-2.7.5.msi).
1.2.
[Numpy](http://sourceforge.net/projects/numpy/files/NumPy/1.7.1/numpy-1.7.1-win32-superpack-python2.7.exe/download).
1.3.
[Matplotlib](https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.3.0/matplotlib-1.3.0.win32-py2.7.exe)
(*Matplotlib is optional, but recommended since we use it a lot in our tutorials*).
-# [Python-2.7.x](http://python.org/ftp/python/2.7.5/python-2.7.5.msi).
-# [Numpy](http://sourceforge.net/projects/numpy/files/NumPy/1.7.1/numpy-1.7.1-win32-superpack-python2.7.exe/download).
-# [Matplotlib](https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.3.0/matplotlib-1.3.0.win32-py2.7.exe) (*Matplotlib is optional, but recommended since we use it a lot in our tutorials*).
-# Install all packages into their default locations. Python will be installed to **C:/Python27/**.
3. After installation, open Python IDLE. Enter import numpy and make sure Numpy is working fine.
4. Download latest OpenCV release from [sourceforge
-# After installation, open Python IDLE. Enter import numpy and make sure Numpy is working fine.
-# Download latest OpenCV release from [sourceforge
site](http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.6/OpenCV-2.4.6.0.exe/download)
and double-click to extract it.
5. Goto **opencv/build/python/2.7** folder.
6. Copy **cv2.pyd** to **C:/Python27/lib/site-packages**.
7. Open Python IDLE and type following codes in Python terminal.
\>\>\> import cv2 \>\>\> print cv2.__version__
-# Goto **opencv/build/python/2.7** folder.
-# Copy **cv2.pyd** to **C:/Python27/lib/site-packages**.
-# Open Python IDLE and type following codes in Python terminal.
@code
>>> import cv2
>>> print cv2.__version__
@endcode
If the results are printed out without any errors, congratulations !!! You have installed
OpenCV-Python successfully.
@@ -43,55 +47,54 @@ Building OpenCV from source
-# Download and install Visual Studio and CMake.
1.1. [Visual Studio 2012](http://go.microsoft.com/?linkid=9816768)
1.2. [CMake](http://www.cmake.org/files/v2.8/cmake-2.8.11.2-win32-x86.exe)
-# [Visual Studio 2012](http://go.microsoft.com/?linkid=9816768)
-# [CMake](http://www.cmake.org/files/v2.8/cmake-2.8.11.2-win32-x86.exe)
-# Download and install necessary Python packages to their default locations
2.1. [Python 2.7.x](http://python.org/ftp/python/2.7.5/python-2.7.5.msi)
2.2.
[Numpy](http://sourceforge.net/projects/numpy/files/NumPy/1.7.1/numpy-1.7.1-win32-superpack-python2.7.exe/download)
2.3.
[Matplotlib](https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.3.0/matplotlib-1.3.0.win32-py2.7.exe)
(*Matplotlib is optional, but recommended since we use it a lot in our tutorials.*)
-# [Python 2.7.x](http://python.org/ftp/python/2.7.5/python-2.7.5.msi)
@note In this case, we are using 32-bit binaries of Python packages. But if you want to use OpenCV
for x64, 64-bit binaries of Python packages are to be installed. Problem is that, there is no
official 64-bit binaries of Numpy. You have to build it on your own. For that, you have to use the
same compiler used to build Python. When you start Python IDLE, it shows the compiler details. You
can get more [information here](http://stackoverflow.com/q/2676763/1134940). So your system must
have the same Visual Studio version and build Numpy from source.
-# [Numpy](http://sourceforge.net/projects/numpy/files/NumPy/1.7.1/numpy-1.7.1-win32-superpack-python2.7.exe/download)
@note Another method to have 64-bit Python packages is to use ready-made Python distributions from
third-parties like [Anaconda](http://www.continuum.io/downloads),
[Enthought](https://www.enthought.com/downloads/) etc. It will be bigger in size, but will have
everything you need. Everything in a single shell. You can also download 32-bit versions also. 3.
Make sure Python and Numpy are working fine.
-# [Matplotlib](https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.3.0/matplotlib-1.3.0.win32-py2.7.exe)
(*Matplotlib is optional, but recommended since we use it a lot in our tutorials.*)
@note In this case, we are using 32-bit binaries of Python packages. But if you want to use
OpenCV for x64, 64-bit binaries of Python packages are to be installed. Problem is that, there
is no official 64-bit binaries of Numpy. You have to build it on your own. For that, you have to
use the same compiler used to build Python. When you start Python IDLE, it shows the compiler
details. You can get more [information here](http://stackoverflow.com/q/2676763/1134940). So
your system must have the same Visual Studio version and build Numpy from source.
@note Another method to have 64-bit Python packages is to use ready-made Python distributions
from third-parties like [Anaconda](http://www.continuum.io/downloads),
[Enthought](https://www.enthought.com/downloads/) etc. It will be bigger in size, but will have
everything you need. Everything in a single shell. You can also download 32-bit versions also.
-# Make sure Python and Numpy are working fine.
-# Download OpenCV source. It can be from
[Sourceforge](http://sourceforge.net/projects/opencvlibrary/) (for official release version) or
from [Github](https://github.com/Itseez/opencv) (for latest source).
5. Extract it to a folder, opencv and create a new folder build in it.
6. Open CMake-gui (*Start \> All Programs \> CMake-gui*)
7. Fill the fields as follows (see the image below):
-# Extract it to a folder, opencv and create a new folder build in it.
-# Open CMake-gui (*Start \> All Programs \> CMake-gui*)
-# Fill the fields as follows (see the image below):
7.1. Click on **Browse Source...** and locate the opencv folder.
7.2. Click on **Browse Build...** and locate the build folder we created.
7.3. Click on **Configure**.
![image](images/Capture1.jpg)
7.4. It will open a new window to select the compiler. Choose appropriate compiler (here,
Visual Studio 11) and click **Finish**.
![image](images/Capture2.png)
7.5. Wait until analysis is finished.
-# Click on **Browse Source...** and locate the opencv folder.
-# Click on **Browse Build...** and locate the build folder we created.
-# Click on **Configure**.
![image](images/Capture1.jpg)
-# It will open a new window to select the compiler. Choose appropriate compiler (here,
Visual Studio 11) and click **Finish**.
![image](images/Capture2.png)
-# Wait until analysis is finished.
-# You will see all the fields are marked in red. Click on the **WITH** field to expand it. It
decides what extra features you need. So mark appropriate fields. See the below image:
@@ -103,33 +106,37 @@ Make sure Python and Numpy are working fine.
![image](images/Capture5.png)
-# Remaining fields specify what modules are to be built. Since GPU modules are not yet supported
-# Remaining fields specify what modules are to be built. Since GPU modules are not yet supported
by OpenCV-Python, you can completely avoid it to save time (But if you work with them, keep it
there). See the image below:
![image](images/Capture6.png)
-# Now click on **ENABLE** field to expand it. Make sure **ENABLE_SOLUTION_FOLDERS** is unchecked
-# Now click on **ENABLE** field to expand it. Make sure **ENABLE_SOLUTION_FOLDERS** is unchecked
(Solution folders are not supported by Visual Studio Express edition). See the image below:
![image](images/Capture7.png)
-# Also make sure that in the **PYTHON** field, everything is filled. (Ignore
-# Also make sure that in the **PYTHON** field, everything is filled. (Ignore
PYTHON_DEBUG_LIBRARY). See image below:
![image](images/Capture80.png)
-# Finally click the **Generate** button.
14. Now go to our **opencv/build** folder. There you will find **OpenCV.sln** file. Open it with
-# Finally click the **Generate** button.
-# Now go to our **opencv/build** folder. There you will find **OpenCV.sln** file. Open it with
Visual Studio.
15. Check build mode as **Release** instead of **Debug**.
16. In the solution explorer, right-click on the **Solution** (or **ALL_BUILD**) and build it. It
-# Check build mode as **Release** instead of **Debug**.
-# In the solution explorer, right-click on the **Solution** (or **ALL_BUILD**) and build it. It
will take some time to finish.
17. Again, right-click on **INSTALL** and build it. Now OpenCV-Python will be installed.
-# Again, right-click on **INSTALL** and build it. Now OpenCV-Python will be installed.
![image](images/Capture8.png)
-# Open Python IDLE and enter import cv2. If no error, it is installed correctly.
-# Open Python IDLE and enter import cv2. If no error, it is installed correctly.
@note We have installed with no other support like TBB, Eigen, Qt, Documentation etc. It would be
difficult to explain it here. A more detailed video will be added soon or you can just hack around.
@@ -140,6 +147,5 @@ Additional Resources
Exercises
---------
-# If you have a windows machine, compile the OpenCV from source. Do all kinds of hacks. If you
meet any problem, visit OpenCV forum and explain your problem.
If you have a windows machine, compile the OpenCV from source. Do all kinds of hacks. If you meet
any problem, visit OpenCV forum and explain your problem.