提交 0e7ca71d 编写于 作者: A Andrey Kamaev

Normalize whitespace in documentation and text files

上级 93372468
......@@ -16,7 +16,7 @@ How to update opencv_ffmpeg.dll and opencv_ffmpeg_64.dll when a new version of F
2. Install 64-bit MinGW. http://mingw-w64.sourceforge.net/
Let's assume, it's installed in C:\MSYS64
3. Copy C:\MSYS32\msys to C:\MSYS64\msys. Edit C:\MSYS64\msys\etc\fstab, change C:\MSYS32 to C:\MSYS64.
4. Now you have working MSYS32 and MSYS64 environments.
Launch, one by one, C:\MSYS32\msys\msys.bat and C:\MSYS64\msys\msys.bat to create your home directories.
......
......@@ -45,13 +45,13 @@ jasper-1.900.1 - JasPer is a collection of software
and manipulation of images. This software can handle image data in a
variety of formats. One such format supported by JasPer is the JPEG-2000
format defined in ISO/IEC 15444-1.
Copyright (c) 1999-2000 Image Power, Inc.
Copyright (c) 1999-2000 The University of British Columbia
Copyright (c) 2001-2003 Michael David Adams
The JasPer license can be found in src/libjasper.
OpenCV on Windows uses pre-built libjasper library
(lib/libjasper*). To get the latest source code,
please, visit the project homepage:
......
......@@ -3,4 +3,4 @@ Java API
********
`Java API reference external link (JavaDoc) <http://docs.opencv.org/java/>`_
\ No newline at end of file
`Java API reference external link (JavaDoc) <http://docs.opencv.org/java/>`_
\ No newline at end of file
......@@ -8,7 +8,7 @@ The package provides new OpenCV SDK that uses OpenCV Manager for library initial
* Hardware specific optimizations for all supported platforms;
* Trusted OpenCV library source. All packages with OpenCV are published on Google Play service;
* Regular updates and bug fixes;
Package consists from Library Project for Java development with Eclipse, C++ headers and libraries for native application development, javadoc samples and prebuilt binaries for ARM and X86 platforms.
To try new SDK on serial device with Google Play just install sample package and follow application messages (Google Play service access will be needed).
TO start example on device without Google Play you need to install OpenCV manager package and OpenCV binary pack for your platform from apk folder before.
......
......@@ -55,6 +55,6 @@ There is a very base code snippet implementing the async initialization with Bas
Using in Service
----------------
Default BaseLoaderCallback implementation treat application context as Activity and calls Activity.finish() method to exit in case of initialization failure.
To override this behavior you need to override finish() method of BaseLoaderCallback class and implement your own finalization method.
Default BaseLoaderCallback implementation treat application context as Activity and calls Activity.finish() method to exit in case of initialization failure.
To override this behavior you need to override finish() method of BaseLoaderCallback class and implement your own finalization method.
......@@ -13,7 +13,7 @@ void onManagerConnected()
.. method:: void onManagerConnected(int status)
Callback method that is called after OpenCV Library initialization.
:param status: status of initialization (see Initialization Status Constants).
void onPackageInstall()
......
......@@ -4,14 +4,14 @@ INSTRUCTIONS TO BUILD WIN32 PACKAGES WITH CMAKE+CPACK
- Install NSIS.
- Generate OpenCV solutions for MSVC using CMake as usual.
- In cmake-gui:
- Mark BUILD_PACKAGE
- Mark BUILD_EXAMPLES (If examples are desired to be shipped as binaries...)
- Unmark ENABLE_OPENMP, since this feature seems to have some issues yet...
- Mark INSTALL_*_EXAMPLES
- In cmake-gui:
- Mark BUILD_PACKAGE
- Mark BUILD_EXAMPLES (If examples are desired to be shipped as binaries...)
- Unmark ENABLE_OPENMP, since this feature seems to have some issues yet...
- Mark INSTALL_*_EXAMPLES
- Open the OpenCV solution and build ALL in Debug and Release.
- Build PACKAGE, from the Release configuration. An NSIS installer package will be
- Build PACKAGE, from the Release configuration. An NSIS installer package will be
created with both release and debug LIBs and DLLs.
Jose Luis Blanco, 2009/JUL/29
......@@ -7,16 +7,16 @@ Camera calibration with square chessboard
The goal of this tutorial is to learn how to calibrate a camera given a set of chessboard images.
*Test data*: use images in your data/chess folder.
*Test data*: use images in your data/chess folder.
#.
Compile opencv with samples by setting ``BUILD_EXAMPLES`` to ``ON`` in cmake configuration.
Compile opencv with samples by setting ``BUILD_EXAMPLES`` to ``ON`` in cmake configuration.
#.
Go to ``bin`` folder and use ``imagelist_creator`` to create an ``XML/YAML`` list of your images.
#.
Then, run ``calibration`` sample to get camera parameters. Use square size equal to 3cm.
Then, run ``calibration`` sample to get camera parameters. Use square size equal to 3cm.
Pose estimation
===============
......@@ -57,6 +57,6 @@ Now, let us write a code that detects a chessboard in a new image and finds its
distCoeffs, rvec, tvec, false);
#.
Calculate reprojection error like it is done in ``calibration`` sample (see ``opencv/samples/cpp/calibration.cpp``, function ``computeReprojectionErrors``).
Calculate reprojection error like it is done in ``calibration`` sample (see ``opencv/samples/cpp/calibration.cpp``, function ``computeReprojectionErrors``).
Question: how to calculate the distance from the camera origin to any of the corners?
\ No newline at end of file
Question: how to calculate the distance from the camera origin to any of the corners?
\ No newline at end of file
......@@ -3,11 +3,11 @@
*calib3d* module. Camera calibration and 3D reconstruction
-----------------------------------------------------------
Although we got most of our images in a 2D format they do come from a 3D world. Here you will learn how to find out from the 2D images information about the 3D world.
Although we got most of our images in a 2D format they do come from a 3D world. Here you will learn how to find out from the 2D images information about the 3D world.
.. include:: ../../definitions/tocDefinitions.rst
.. include:: ../../definitions/tocDefinitions.rst
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
......@@ -26,7 +26,7 @@ Although we got most of our images in a 2D format they do come from a 3D world.
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
......
......@@ -18,7 +18,7 @@ Theory
.. note::
The explanation below belongs to the book `Computer Vision: Algorithms and Applications <http://szeliski.org/Book/>`_ by Richard Szeliski
The explanation below belongs to the book `Computer Vision: Algorithms and Applications <http://szeliski.org/Book/>`_ by Richard Szeliski
From our previous tutorial, we know already a bit of *Pixel operators*. An interesting dyadic (two-input) operator is the *linear blend operator*:
......@@ -43,7 +43,7 @@ As usual, after the not-so-lengthy explanation, let's go to the code:
int main( int argc, char** argv )
{
double alpha = 0.5; double beta; double input;
double alpha = 0.5; double beta; double input;
Mat src1, src2, dst;
......@@ -69,7 +69,7 @@ As usual, after the not-so-lengthy explanation, let's go to the code:
beta = ( 1.0 - alpha );
addWeighted( src1, alpha, src2, beta, 0.0, dst);
imshow( "Linear Blend", dst );
waitKey(0);
......@@ -99,10 +99,10 @@ Explanation
#. Now we need to generate the :math:`g(x)` image. For this, the function :add_weighted:`addWeighted <>` comes quite handy:
.. code-block:: cpp
beta = ( 1.0 - alpha );
addWeighted( src1, alpha, src2, beta, 0.0, dst);
since :add_weighted:`addWeighted <>` produces:
.. math::
......@@ -110,12 +110,12 @@ Explanation
dst = \alpha \cdot src1 + \beta \cdot src2 + \gamma
In this case, :math:`\gamma` is the argument :math:`0.0` in the code above.
#. Create windows, show the images and wait for the user to end the program.
#. Create windows, show the images and wait for the user to end the program.
Result
=======
.. image:: images/Adding_Images_Tutorial_Result_0.jpg
:alt: Blending Images Tutorial - Final Result
:align: center
:align: center
......@@ -99,11 +99,11 @@ Explanation
/// 2.b. Creating rectangles
rectangle( rook_image,
Point( 0, 7*w/8.0 ),
Point( w, w),
Scalar( 0, 255, 255 ),
-1,
8 );
Point( 0, 7*w/8.0 ),
Point( w, w),
Scalar( 0, 255, 255 ),
-1,
8 );
/// 2.c. Create a few lines
MyLine( rook_image, Point( 0, 15*w/16 ), Point( w, 15*w/16 ) );
......@@ -118,16 +118,16 @@ Explanation
.. code-block:: cpp
void MyLine( Mat img, Point start, Point end )
{
int thickness = 2;
int lineType = 8;
line( img,
start,
end,
Scalar( 0, 0, 0 ),
thickness,
lineType );
}
{
int thickness = 2;
int lineType = 8;
line( img,
start,
end,
Scalar( 0, 0, 0 ),
thickness,
lineType );
}
As we can see, *MyLine* just call the function :line:`line <>`, which does the following:
......@@ -145,18 +145,18 @@ Explanation
void MyEllipse( Mat img, double angle )
{
int thickness = 2;
int lineType = 8;
ellipse( img,
Point( w/2.0, w/2.0 ),
Size( w/4.0, w/16.0 ),
angle,
0,
360,
Scalar( 255, 0, 0 ),
thickness,
lineType );
int thickness = 2;
int lineType = 8;
ellipse( img,
Point( w/2.0, w/2.0 ),
Size( w/4.0, w/16.0 ),
angle,
0,
360,
Scalar( 255, 0, 0 ),
thickness,
lineType );
}
From the code above, we can observe that the function :ellipse:`ellipse <>` draws an ellipse such that:
......@@ -176,17 +176,17 @@ Explanation
.. code-block:: cpp
void MyFilledCircle( Mat img, Point center )
{
int thickness = -1;
int lineType = 8;
circle( img,
center,
w/32.0,
Scalar( 0, 0, 255 ),
thickness,
lineType );
}
{
int thickness = -1;
int lineType = 8;
circle( img,
center,
w/32.0,
Scalar( 0, 0, 255 ),
thickness,
lineType );
}
Similar to the ellipse function, we can observe that *circle* receives as arguments:
......@@ -203,41 +203,41 @@ Explanation
.. code-block:: cpp
void MyPolygon( Mat img )
{
int lineType = 8;
/** Create some points */
Point rook_points[1][20];
rook_points[0][0] = Point( w/4.0, 7*w/8.0 );
rook_points[0][1] = Point( 3*w/4.0, 7*w/8.0 );
rook_points[0][2] = Point( 3*w/4.0, 13*w/16.0 );
rook_points[0][3] = Point( 11*w/16.0, 13*w/16.0 );
rook_points[0][4] = Point( 19*w/32.0, 3*w/8.0 );
rook_points[0][5] = Point( 3*w/4.0, 3*w/8.0 );
rook_points[0][6] = Point( 3*w/4.0, w/8.0 );
rook_points[0][7] = Point( 26*w/40.0, w/8.0 );
rook_points[0][8] = Point( 26*w/40.0, w/4.0 );
rook_points[0][9] = Point( 22*w/40.0, w/4.0 );
rook_points[0][10] = Point( 22*w/40.0, w/8.0 );
rook_points[0][11] = Point( 18*w/40.0, w/8.0 );
rook_points[0][12] = Point( 18*w/40.0, w/4.0 );
rook_points[0][13] = Point( 14*w/40.0, w/4.0 );
rook_points[0][14] = Point( 14*w/40.0, w/8.0 );
rook_points[0][15] = Point( w/4.0, w/8.0 );
rook_points[0][16] = Point( w/4.0, 3*w/8.0 );
rook_points[0][17] = Point( 13*w/32.0, 3*w/8.0 );
rook_points[0][18] = Point( 5*w/16.0, 13*w/16.0 );
rook_points[0][19] = Point( w/4.0, 13*w/16.0) ;
const Point* ppt[1] = { rook_points[0] };
int npt[] = { 20 };
fillPoly( img,
ppt,
npt,
1,
Scalar( 255, 255, 255 ),
lineType );
{
int lineType = 8;
/** Create some points */
Point rook_points[1][20];
rook_points[0][0] = Point( w/4.0, 7*w/8.0 );
rook_points[0][1] = Point( 3*w/4.0, 7*w/8.0 );
rook_points[0][2] = Point( 3*w/4.0, 13*w/16.0 );
rook_points[0][3] = Point( 11*w/16.0, 13*w/16.0 );
rook_points[0][4] = Point( 19*w/32.0, 3*w/8.0 );
rook_points[0][5] = Point( 3*w/4.0, 3*w/8.0 );
rook_points[0][6] = Point( 3*w/4.0, w/8.0 );
rook_points[0][7] = Point( 26*w/40.0, w/8.0 );
rook_points[0][8] = Point( 26*w/40.0, w/4.0 );
rook_points[0][9] = Point( 22*w/40.0, w/4.0 );
rook_points[0][10] = Point( 22*w/40.0, w/8.0 );
rook_points[0][11] = Point( 18*w/40.0, w/8.0 );
rook_points[0][12] = Point( 18*w/40.0, w/4.0 );
rook_points[0][13] = Point( 14*w/40.0, w/4.0 );
rook_points[0][14] = Point( 14*w/40.0, w/8.0 );
rook_points[0][15] = Point( w/4.0, w/8.0 );
rook_points[0][16] = Point( w/4.0, 3*w/8.0 );
rook_points[0][17] = Point( 13*w/32.0, 3*w/8.0 );
rook_points[0][18] = Point( 5*w/16.0, 13*w/16.0 );
rook_points[0][19] = Point( w/4.0, 13*w/16.0) ;
const Point* ppt[1] = { rook_points[0] };
int npt[] = { 20 };
fillPoly( img,
ppt,
npt,
1,
Scalar( 255, 255, 255 ),
lineType );
}
To draw a filled polygon we use the function :fill_poly:`fillPoly <>`. We note that:
......@@ -255,11 +255,11 @@ Explanation
.. code-block:: cpp
rectangle( rook_image,
Point( 0, 7*w/8.0 ),
Point( w, w),
Scalar( 0, 255, 255 ),
-1,
8 );
Point( 0, 7*w/8.0 ),
Point( w, w),
Scalar( 0, 255, 255 ),
-1,
8 );
Finally we have the :rectangle:`rectangle <>` function (we did not create a special function for this guy). We note that:
......
......@@ -10,7 +10,7 @@ In this tutorial you will learn how to:
.. container:: enumeratevisibleitemswithsquare
+ Access pixel values
+ Access pixel values
+ Initialize a matrix with zeros
......@@ -20,16 +20,16 @@ In this tutorial you will learn how to:
Theory
=======
.. note::
The explanation below belongs to the book `Computer Vision: Algorithms and Applications <http://szeliski.org/Book/>`_ by Richard Szeliski
The explanation below belongs to the book `Computer Vision: Algorithms and Applications <http://szeliski.org/Book/>`_ by Richard Szeliski
Image Processing
--------------------
.. container:: enumeratevisibleitemswithsquare
* A general image processing operator is a function that takes one or more input images and produces an output image.
* A general image processing operator is a function that takes one or more input images and produces an output image.
* Image transforms can be seen as:
......@@ -54,18 +54,18 @@ Brightness and contrast adjustments
* Two commonly used point processes are *multiplication* and *addition* with a constant:
.. math::
g(x) = \alpha f(x) + \beta
* The parameters :math:`\alpha > 0` and :math:`\beta` are often called the *gain* and *bias* parameters; sometimes these parameters are said to control *contrast* and *brightness* respectively.
* You can think of :math:`f(x)` as the source image pixels and :math:`g(x)` as the output image pixels. Then, more conveniently we can write the expression as:
.. math::
g(i,j) = \alpha \cdot f(i,j) + \beta
where :math:`i` and :math:`j` indicates that the pixel is located in the *i-th* row and *j-th* column.
where :math:`i` and :math:`j` indicates that the pixel is located in the *i-th* row and *j-th* column.
Code
=====
......@@ -91,7 +91,7 @@ Code
Mat image = imread( argv[1] );
Mat new_image = Mat::zeros( image.size(), image.type() );
/// Initialize values
/// Initialize values
std::cout<<" Basic Linear Transforms "<<std::endl;
std::cout<<"-------------------------"<<std::endl;
std::cout<<"* Enter the alpha value [1.0-3.0]: ";std::cin>>alpha;
......@@ -102,7 +102,7 @@ Code
{ for( int x = 0; x < image.cols; x++ )
{ for( int c = 0; c < 3; c++ )
{
new_image.at<Vec3b>(y,x)[c] =
new_image.at<Vec3b>(y,x)[c] =
saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta );
}
}
......@@ -133,41 +133,41 @@ Explanation
#. We load an image using :imread:`imread <>` and save it in a Mat object:
.. code-block:: cpp
Mat image = imread( argv[1] );
#. Now, since we will make some transformations to this image, we need a new Mat object to store it. Also, we want this to have the following features:
.. container:: enumeratevisibleitemswithsquare
* Initial pixel values equal to zero
* Same size and type as the original image
.. code-block:: cpp
Mat new_image = Mat::zeros( image.size(), image.type() );
We observe that :mat_zeros:`Mat::zeros <>` returns a Matlab-style zero initializer based on *image.size()* and *image.type()*
Mat new_image = Mat::zeros( image.size(), image.type() );
We observe that :mat_zeros:`Mat::zeros <>` returns a Matlab-style zero initializer based on *image.size()* and *image.type()*
#. Now, to perform the operation :math:`g(i,j) = \alpha \cdot f(i,j) + \beta` we will access to each pixel in image. Since we are operating with RGB images, we will have three values per pixel (R, G and B), so we will also access them separately. Here is the piece of code:
.. code-block:: cpp
for( int y = 0; y < image.rows; y++ )
{ for( int x = 0; x < image.cols; x++ )
{ for( int c = 0; c < 3; c++ )
{ new_image.at<Vec3b>(y,x)[c] =
{ new_image.at<Vec3b>(y,x)[c] =
saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta ); }
}
}
Notice the following:
.. container:: enumeratevisibleitemswithsquare
* To access each pixel in the images we are using this syntax: *image.at<Vec3b>(y,x)[c]* where *y* is the row, *x* is the column and *c* is R, G or B (0, 1 or 2).
* To access each pixel in the images we are using this syntax: *image.at<Vec3b>(y,x)[c]* where *y* is the row, *x* is the column and *c* is R, G or B (0, 1 or 2).
* Since the operation :math:`\alpha \cdot p(i,j) + \beta` can give values out of range or not integers (if :math:`\alpha` is float), we use :saturate_cast:`saturate_cast <>` to make sure the values are valid.
......@@ -175,7 +175,7 @@ Explanation
#. Finally, we create windows and show the images, the usual way.
.. code-block:: cpp
namedWindow("Original Image", 1);
namedWindow("New Image", 1);
......@@ -185,9 +185,9 @@ Explanation
waitKey(0);
.. note::
Instead of using the **for** loops to access each pixel, we could have simply used this command:
.. code-block:: cpp
image.convertTo(new_image, -1, alpha, beta);
......@@ -211,4 +211,4 @@ Result
.. image:: images/Basic_Linear_Transform_Tutorial_Result_0.jpg
:alt: Basic Linear Transform - Final Result
:align: center
:align: center
......@@ -4,22 +4,22 @@ Discrete Fourier Transform
**************************
Goal
====
====
We'll seek answers for the following questions:
We'll seek answers for the following questions:
.. container:: enumeratevisibleitemswithsquare
+ What is a Fourier transform and why use it?
+ How to do it in OpenCV?
+ What is a Fourier transform and why use it?
+ How to do it in OpenCV?
+ Usage of functions such as: :imgprocfilter:`copyMakeBorder() <copymakeborder>`, :operationsonarrays:`merge() <merge>`, :operationsonarrays:`dft() <dft>`, :operationsonarrays:`getOptimalDFTSize() <getoptimaldftsize>`, :operationsonarrays:`log() <log>` and :operationsonarrays:`normalize() <normalize>` .
Source code
===========
You can :download:`download this from here <../../../../samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp>` or find it in the :file:`samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp` of the OpenCV source code library.
You can :download:`download this from here <../../../../samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp>` or find it in the :file:`samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp` of the OpenCV source code library.
Here's a sample usage of :operationsonarrays:`dft() <dft>` :
Here's a sample usage of :operationsonarrays:`dft() <dft>` :
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp
:language: cpp
......@@ -30,11 +30,11 @@ Here's a sample usage of :operationsonarrays:`dft() <dft>` :
Explanation
===========
The Fourier Transform will decompose an image into its sinus and cosines components. In other words, it will transform an image from its spatial domain to its frequency domain. The idea is that any function may be approximated exactly with the sum of infinite sinus and cosines functions. The Fourier Transform is a way how to do this. Mathematically a two dimensional images Fourier transform is:
The Fourier Transform will decompose an image into its sinus and cosines components. In other words, it will transform an image from its spatial domain to its frequency domain. The idea is that any function may be approximated exactly with the sum of infinite sinus and cosines functions. The Fourier Transform is a way how to do this. Mathematically a two dimensional images Fourier transform is:
.. math::
F(k,l) = \displaystyle\sum\limits_{i=0}^{N-1}\sum\limits_{j=0}^{N-1} f(i,j)e^{-i2\pi(\frac{ki}{N}+\frac{lj}{N})}
F(k,l) = \displaystyle\sum\limits_{i=0}^{N-1}\sum\limits_{j=0}^{N-1} f(i,j)e^{-i2\pi(\frac{ki}{N}+\frac{lj}{N})}
e^{ix} = \cos{x} + i\sin {x}
......@@ -44,65 +44,65 @@ In this sample I'll show how to calculate and show the *magnitude* image of a Fo
1. **Expand the image to an optimal size**. The performance of a DFT is dependent of the image size. It tends to be the fastest for image sizes that are multiple of the numbers two, three and five. Therefore, to achieve maximal performance it is generally a good idea to pad border values to the image to get a size with such traits. The :operationsonarrays:`getOptimalDFTSize() <getoptimaldftsize>` returns this optimal size and we can use the :imgprocfilter:`copyMakeBorder() <copymakeborder>` function to expand the borders of an image:
.. code-block:: cpp
.. code-block:: cpp
Mat padded; //expand input image to optimal size
int m = getOptimalDFTSize( I.rows );
int n = getOptimalDFTSize( I.cols ); // on the border add zero pixels
copyMakeBorder(I, padded, 0, m - I.rows, 0, n - I.cols, BORDER_CONSTANT, Scalar::all(0));
The appended pixels are initialized with zero.
The appended pixels are initialized with zero.
2. **Make place for both the complex and the real values**. The result of a Fourier Transform is complex. This implies that for each image value the result is two image values (one per component). Moreover, the frequency domains range is much larger than its spatial counterpart. Therefore, we store these usually at least in a *float* format. Therefore we'll convert our input image to this type and expand it with another channel to hold the complex values:
.. code-block:: cpp
.. code-block:: cpp
Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};
Mat complexI;
merge(planes, 2, complexI); // Add to the expanded another plane with zeros
3. **Make the Discrete Fourier Transform**. It's possible an in-place calculation (same input as output):
3. **Make the Discrete Fourier Transform**. It's possible an in-place calculation (same input as output):
.. code-block:: cpp
.. code-block:: cpp
dft(complexI, complexI); // this way the result may fit in the source matrix
4. **Transform the real and complex values to magnitude**. A complex number has a real (*Re*) and a complex (imaginary - *Im*) part. The results of a DFT are complex numbers. The magnitude of a DFT is:
4. **Transform the real and complex values to magnitude**. A complex number has a real (*Re*) and a complex (imaginary - *Im*) part. The results of a DFT are complex numbers. The magnitude of a DFT is:
.. math::
M = \sqrt[2]{ {Re(DFT(I))}^2 + {Im(DFT(I))}^2}
Translated to OpenCV code:
Translated to OpenCV code:
.. code-block:: cpp
.. code-block:: cpp
split(complexI, planes); // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude
magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude
Mat magI = planes[0];
5. **Switch to a logarithmic scale**. It turns out that the dynamic range of the Fourier coefficients is too large to be displayed on the screen. We have some small and some high changing values that we can't observe like this. Therefore the high values will all turn out as white points, while the small ones as black. To use the gray scale values to for visualization we can transform our linear scale to a logarithmic one:
5. **Switch to a logarithmic scale**. It turns out that the dynamic range of the Fourier coefficients is too large to be displayed on the screen. We have some small and some high changing values that we can't observe like this. Therefore the high values will all turn out as white points, while the small ones as black. To use the gray scale values to for visualization we can transform our linear scale to a logarithmic one:
.. math::
M_1 = \log{(1 + M)}
Translated to OpenCV code:
Translated to OpenCV code:
.. code-block:: cpp
.. code-block:: cpp
magI += Scalar::all(1); // switch to logarithmic scale
log(magI, magI);
6. **Crop and rearrange**. Remember, that at the first step, we expanded the image? Well, it's time to throw away the newly introduced values. For visualization purposes we may also rearrange the quadrants of the result, so that the origin (zero, zero) corresponds with the image center.
6. **Crop and rearrange**. Remember, that at the first step, we expanded the image? Well, it's time to throw away the newly introduced values. For visualization purposes we may also rearrange the quadrants of the result, so that the origin (zero, zero) corresponds with the image center.
.. code-block:: cpp
.. code-block:: cpp
magI = magI(Rect(0, 0, magI.cols & -2, magI.rows & -2));
int cx = magI.cols/2;
int cy = magI.rows/2;
Mat q0(magI, Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant
Mat q0(magI, Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant
Mat q1(magI, Rect(cx, 0, cx, cy)); // Top-Right
Mat q2(magI, Rect(0, cy, cx, cy)); // Bottom-Left
Mat q3(magI, Rect(cx, cy, cx, cy)); // Bottom-Right
......@@ -116,25 +116,25 @@ In this sample I'll show how to calculate and show the *magnitude* image of a Fo
q2.copyTo(q1);
tmp.copyTo(q2);
7. **Normalize**. This is done again for visualization purposes. We now have the magnitudes, however this are still out of our image display range of zero to one. We normalize our values to this range using the :operationsonarrays:`normalize() <normalize>` function.
7. **Normalize**. This is done again for visualization purposes. We now have the magnitudes, however this are still out of our image display range of zero to one. We normalize our values to this range using the :operationsonarrays:`normalize() <normalize>` function.
.. code-block:: cpp
.. code-block:: cpp
normalize(magI, magI, 0, 1, CV_MINMAX); // Transform the matrix with float values into a
normalize(magI, magI, 0, 1, CV_MINMAX); // Transform the matrix with float values into a
// viewable image form (float between values 0 and 1).
Result
======
An application idea would be to determine the geometrical orientation present in the image. For example, let us find out if a text is horizontal or not? Looking at some text you'll notice that the text lines sort of form also horizontal lines and the letters form sort of vertical lines. These two main components of a text snippet may be also seen in case of the Fourier transform. Let us use :download:`this horizontal <../../../../samples/cpp/tutorial_code/images/imageTextN.png>` and :download:`this rotated<../../../../samples/cpp/tutorial_code/images/imageTextR.png>` image about a text.
An application idea would be to determine the geometrical orientation present in the image. For example, let us find out if a text is horizontal or not? Looking at some text you'll notice that the text lines sort of form also horizontal lines and the letters form sort of vertical lines. These two main components of a text snippet may be also seen in case of the Fourier transform. Let us use :download:`this horizontal <../../../../samples/cpp/tutorial_code/images/imageTextN.png>` and :download:`this rotated<../../../../samples/cpp/tutorial_code/images/imageTextR.png>` image about a text.
In case of the horizontal text:
In case of the horizontal text:
.. image:: images/result_normal.jpg
:alt: In case of normal text
:align: center
In case of a rotated text:
In case of a rotated text:
.. image:: images/result_rotated.jpg
:alt: In case of rotated text
......
......@@ -4,9 +4,9 @@ File Input and Output using XML and YAML files
**********************************************
Goal
====
====
You'll find answers for the following questions:
You'll find answers for the following questions:
.. container:: enumeratevisibleitemswithsquare
......@@ -18,7 +18,7 @@ You'll find answers for the following questions:
Source code
===========
You can :download:`download this from here <../../../../samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp>` or find it in the :file:`samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp` of the OpenCV source code library.
You can :download:`download this from here <../../../../samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp>` or find it in the :file:`samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp` of the OpenCV source code library.
Here's a sample code of how to achieve all the stuff enumerated at the goal list.
......@@ -31,9 +31,9 @@ Here's a sample code of how to achieve all the stuff enumerated at the goal list
Explanation
===========
Here we talk only about XML and YAML file inputs. Your output (and its respective input) file may have only one of these extensions and the structure coming from this. They are two kinds of data structures you may serialize: *mappings* (like the STL map) and *element sequence* (like the STL vector>. The difference between these is that in a map every element has a unique name through what you may access it. For sequences you need to go through them to query a specific item.
Here we talk only about XML and YAML file inputs. Your output (and its respective input) file may have only one of these extensions and the structure coming from this. They are two kinds of data structures you may serialize: *mappings* (like the STL map) and *element sequence* (like the STL vector>. The difference between these is that in a map every element has a unique name through what you may access it. For sequences you need to go through them to query a specific item.
1. **XML\\YAML File Open and Close.** Before you write any content to such file you need to open it and at the end to close it. The XML\YAML data structure in OpenCV is :xmlymlpers:`FileStorage <filestorage>`. To specify that this structure to which file binds on your hard drive you can use either its constructor or the *open()* function of this:
1. **XML\\YAML File Open and Close.** Before you write any content to such file you need to open it and at the end to close it. The XML\YAML data structure in OpenCV is :xmlymlpers:`FileStorage <filestorage>`. To specify that this structure to which file binds on your hard drive you can use either its constructor or the *open()* function of this:
.. code-block:: cpp
......@@ -42,29 +42,29 @@ Here we talk only about XML and YAML file inputs. Your output (and its respectiv
\\...
fs.open(filename, FileStorage::READ);
Either one of this you use the second argument is a constant specifying the type of operations you'll be able to on them: WRITE, READ or APPEND. The extension specified in the file name also determinates the output format that will be used. The output may be even compressed if you specify an extension such as *.xml.gz*.
Either one of this you use the second argument is a constant specifying the type of operations you'll be able to on them: WRITE, READ or APPEND. The extension specified in the file name also determinates the output format that will be used. The output may be even compressed if you specify an extension such as *.xml.gz*.
The file automatically closes when the :xmlymlpers:`FileStorage <filestorage>` objects is destroyed. However, you may explicitly call for this by using the *release* function:
The file automatically closes when the :xmlymlpers:`FileStorage <filestorage>` objects is destroyed. However, you may explicitly call for this by using the *release* function:
.. code-block:: cpp
fs.release(); // explicit close
#. **Input and Output of text and numbers.** The data structure uses the same << output operator that the STL library. For outputting any type of data structure we need first to specify its name. We do this by just simply printing out the name of this. For basic types you may follow this with the print of the value :
#. **Input and Output of text and numbers.** The data structure uses the same << output operator that the STL library. For outputting any type of data structure we need first to specify its name. We do this by just simply printing out the name of this. For basic types you may follow this with the print of the value :
.. code-block:: cpp
fs << "iterationNr" << 100;
Reading in is a simple addressing (via the [] operator) and casting operation or a read via the >> operator :
Reading in is a simple addressing (via the [] operator) and casting operation or a read via the >> operator :
.. code-block:: cpp
int itNr;
int itNr;
fs["iterationNr"] >> itNr;
itNr = (int) fs["iterationNr"];
#. **Input\\Output of OpenCV Data structures.** Well these behave exactly just as the basic C++ types:
#. **Input\\Output of OpenCV Data structures.** Well these behave exactly just as the basic C++ types:
.. code-block:: cpp
......@@ -77,7 +77,7 @@ Here we talk only about XML and YAML file inputs. Your output (and its respectiv
fs["R"] >> R; // Read cv::Mat
fs["T"] >> T;
#. **Input\\Output of vectors (arrays) and associative maps.** As I mentioned beforehand we can output maps and sequences (array, vector) too. Again we first print the name of the variable and then we have to specify if our output is either a sequence or map.
#. **Input\\Output of vectors (arrays) and associative maps.** As I mentioned beforehand we can output maps and sequences (array, vector) too. Again we first print the name of the variable and then we have to specify if our output is either a sequence or map.
For sequence before the first element print the "[" character and after the last one the "]" character:
......@@ -95,7 +95,7 @@ Here we talk only about XML and YAML file inputs. Your output (and its respectiv
fs << "{" << "One" << 1;
fs << "Two" << 2 << "}";
To read from these we use the :xmlymlpers:`FileNode <filenode>` and the :xmlymlpers:`FileNodeIterator <filenodeiterator>` data structures. The [] operator of the :xmlymlpers:`FileStorage <filestorage>` class returns a :xmlymlpers:`FileNode <filenode>` data type. If the node is sequential we can use the :xmlymlpers:`FileNodeIterator <filenodeiterator>` to iterate through the items:
To read from these we use the :xmlymlpers:`FileNode <filenode>` and the :xmlymlpers:`FileNodeIterator <filenodeiterator>` data structures. The [] operator of the :xmlymlpers:`FileStorage <filestorage>` class returns a :xmlymlpers:`FileNode <filenode>` data type. If the node is sequential we can use the :xmlymlpers:`FileNodeIterator <filenodeiterator>` to iterate through the items:
.. code-block:: cpp
......@@ -115,8 +115,8 @@ Here we talk only about XML and YAML file inputs. Your output (and its respectiv
.. code-block:: cpp
n = fs["Mapping"]; // Read mappings from a sequence
cout << "Two " << (int)(n["Two"]) << "; ";
cout << "One " << (int)(n["One"]) << endl << endl;
cout << "Two " << (int)(n["Two"]) << "; ";
cout << "One " << (int)(n["One"]) << endl << endl;
#. **Read and write your own data structures.** Suppose you have a data structure such as:
......@@ -148,7 +148,7 @@ Here we talk only about XML and YAML file inputs. Your output (and its respectiv
id = (string)node["id"];
}
Then you need to add the following functions definitions outside the class:
Then you need to add the following functions definitions outside the class:
.. code-block:: cpp
......@@ -175,17 +175,17 @@ Here we talk only about XML and YAML file inputs. Your output (and its respectiv
fs << "MyData" << m; // your own data structures
fs["MyData"] >> m; // Read your own structure_
Or to try out reading a non-existing read:
Or to try out reading a non-existing read:
.. code-block:: cpp
fs["NonExisting"] >> m; // Do not add a fs << "NonExisting" << m command for this to work
fs["NonExisting"] >> m; // Do not add a fs << "NonExisting" << m command for this to work
cout << endl << "NonExisting = " << endl << m << endl;
Result
======
Well mostly we just print out the defined numbers. On the screen of your console you could see:
Well mostly we just print out the defined numbers. On the screen of your console you could see:
.. code-block:: bash
......@@ -212,7 +212,7 @@ Well mostly we just print out the defined numbers. On the screen of your console
Tip: Open up output.xml with a text editor to see the serialized data.
Nevertheless, it's much more interesting what you may see in the output xml file:
Nevertheless, it's much more interesting what you may see in the output xml file:
.. code-block:: xml
......@@ -242,7 +242,7 @@ Nevertheless, it's much more interesting what you may see in the output xml file
<id>mydata1234</id></MyData>
</opencv_storage>
Or the YAML file:
Or the YAML file:
.. code-block:: yaml
......
......@@ -4,9 +4,9 @@ How to scan images, lookup tables and time measurement with OpenCV
*******************************************************************
Goal
====
====
We'll seek answers for the following questions:
We'll seek answers for the following questions:
.. container:: enumeratevisibleitemswithsquare
......@@ -18,11 +18,11 @@ We'll seek answers for the following questions:
Our test case
=============
Let us consider a simple color reduction method. Using the unsigned char C and C++ type for matrix item storing a channel of pixel may have up to 256 different values. For a three channel image this can allow the formation of way too many colors (16 million to be exact). Working with so many color shades may give a heavy blow to our algorithm performance. However, sometimes it is enough to work with a lot less of them to get the same final result.
Let us consider a simple color reduction method. Using the unsigned char C and C++ type for matrix item storing a channel of pixel may have up to 256 different values. For a three channel image this can allow the formation of way too many colors (16 million to be exact). Working with so many color shades may give a heavy blow to our algorithm performance. However, sometimes it is enough to work with a lot less of them to get the same final result.
In this cases it's common that we make a *color space reduction*. This means that we divide the color space current value with a new input value to end up with fewer colors. For instance every value between zero and nine takes the new value zero, every value between ten and nineteen the value ten and so on.
In this cases it's common that we make a *color space reduction*. This means that we divide the color space current value with a new input value to end up with fewer colors. For instance every value between zero and nine takes the new value zero, every value between ten and nineteen the value ten and so on.
When you divide an *uchar* (unsigned char - aka values between zero and 255) value with an *int* value the result will be also *char*. These values may only be char values. Therefore, any fraction will be rounded down. Taking advantage of this fact the upper operation in the *uchar* domain may be expressed as:
When you divide an *uchar* (unsigned char - aka values between zero and 255) value with an *int* value the result will be also *char*. These values may only be char values. Therefore, any fraction will be rounded down. Taking advantage of this fact the upper operation in the *uchar* domain may be expressed as:
.. math::
......@@ -30,11 +30,11 @@ When you divide an *uchar* (unsigned char - aka values between zero and 255) val
A simple color space reduction algorithm would consist of just passing through every pixel of an image matrix and applying this formula. It's worth noting that we do a divide and a multiplication operation. These operations are bloody expensive for a system. If possible it's worth avoiding them by using cheaper operations such as a few subtractions, addition or in best case a simple assignment. Furthermore, note that we only have a limited number of input values for the upper operation. In case of the *uchar* system this is 256 to be exact.
Therefore, for larger images it would be wise to calculate all possible values beforehand and during the assignment just make the assignment, by using a lookup table. Lookup tables are simple arrays (having one or more dimensions) that for a given input value variation holds the final output value. Its strength lies that we do not need to make the calculation, we just need to read the result.
Therefore, for larger images it would be wise to calculate all possible values beforehand and during the assignment just make the assignment, by using a lookup table. Lookup tables are simple arrays (having one or more dimensions) that for a given input value variation holds the final output value. Its strength lies that we do not need to make the calculation, we just need to read the result.
Our test case program (and the sample presented here) will do the following: read in a console line argument image (that may be either color or gray scale - console line argument too) and apply the reduction with the given console line argument integer value. In OpenCV, at the moment they are three major ways of going through an image pixel by pixel. To make things a little more interesting will make the scanning for each image using all of these methods, and print out how long it took.
Our test case program (and the sample presented here) will do the following: read in a console line argument image (that may be either color or gray scale - console line argument too) and apply the reduction with the given console line argument integer value. In OpenCV, at the moment they are three major ways of going through an image pixel by pixel. To make things a little more interesting will make the scanning for each image using all of these methods, and print out how long it took.
You can download the full source code :download:`here <../../../../samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp>` or look it up in the samples directory of OpenCV at the cpp tutorial code for the core section. Its basic usage is:
You can download the full source code :download:`here <../../../../samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp>` or look it up in the samples directory of OpenCV at the cpp tutorial code for the core section. Its basic usage is:
.. code-block:: bash
......@@ -45,25 +45,25 @@ The final argument is optional. If given the image will be loaded in gray scale
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp
:language: cpp
:tab-width: 4
:lines: 48-60
:lines: 48-60
Here we first use the C++ *stringstream* class to convert the third command line argument from text to an integer format. Then we use a simple look and the upper formula to calculate the lookup table. No OpenCV specific stuff here.
Another issue is how do we measure time? Well OpenCV offers two simple functions to achieve this :UtilitySystemFunctions:`getTickCount() <gettickcount>` and :UtilitySystemFunctions:`getTickFrequency() <gettickfrequency>`. The first returns the number of ticks of your systems CPU from a certain event (like since you booted your system). The second returns how many times your CPU emits a tick during a second. So to measure in seconds the number of time elapsed between two operations is easy as:
Another issue is how do we measure time? Well OpenCV offers two simple functions to achieve this :UtilitySystemFunctions:`getTickCount() <gettickcount>` and :UtilitySystemFunctions:`getTickFrequency() <gettickfrequency>`. The first returns the number of ticks of your systems CPU from a certain event (like since you booted your system). The second returns how many times your CPU emits a tick during a second. So to measure in seconds the number of time elapsed between two operations is easy as:
.. code-block:: cpp
double t = (double)getTickCount();
// do something ...
t = ((double)getTickCount() - t)/getTickFrequency();
t = ((double)getTickCount() - t)/getTickFrequency();
cout << "Times passed in seconds: " << t << endl;
.. _How_Image_Stored_Memory:
.. _How_Image_Stored_Memory:
How the image matrix is stored in the memory?
=============================================
As you could already read in my :ref:`matTheBasicImageContainer` tutorial the size of the matrix depends of the color system used. More accurately, it depends from the number of channels used. In case of a gray scale image we have something like:
As you could already read in my :ref:`matTheBasicImageContainer` tutorial the size of the matrix depends of the color system used. More accurately, it depends from the number of channels used. In case of a gray scale image we have something like:
.. math::
......@@ -94,14 +94,14 @@ Note that the order of the channels is inverse: BGR instead of RGB. Because in m
The efficient way
=================
When it comes to performance you cannot beat the classic C style operator[] (pointer) access. Therefore, the most efficient method we can recommend for making the assignment is:
When it comes to performance you cannot beat the classic C style operator[] (pointer) access. Therefore, the most efficient method we can recommend for making the assignment is:
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp
:language: cpp
:tab-width: 4
:lines: 125-152
Here we basically just acquire a pointer to the start of each row and go through it until it ends. In the special case that the matrix is stored in a continues manner we only need to request the pointer a single time and go all the way to the end. We need to look out for color images: we have three channels so we need to pass through three times more items in each row.
Here we basically just acquire a pointer to the start of each row and go through it until it ends. In the special case that the matrix is stored in a continues manner we only need to request the pointer a single time and go all the way to the end. We need to look out for color images: we have three channels so we need to pass through three times more items in each row.
There's another way of this. The *data* data member of a *Mat* object returns the pointer to the first row, first column. If this pointer is null you have no valid input in that object. Checking this is the simplest method to check if your image loading was a success. In case the storage is continues we can use this to go through the whole data pointer. In case of a gray scale image this would look like:
......@@ -114,17 +114,17 @@ There's another way of this. The *data* data member of a *Mat* object returns th
You would get the same result. However, this code is a lot harder to read later on. It gets even harder if you have some more advanced technique there. Moreover, in practice I've observed you'll get the same performance result (as most of the modern compilers will probably make this small optimization trick automatically for you).
The iterator (safe) method
The iterator (safe) method
==========================
In case of the efficient way making sure that you pass through the right amount of *uchar* fields and to skip the gaps that may occur between the rows was your responsibility. The iterator method is considered a safer way as it takes over these tasks from the user. All you need to do is ask the begin and the end of the image matrix and then just increase the begin iterator until you reach the end. To acquire the value *pointed* by the iterator use the * operator (add it before it).
In case of the efficient way making sure that you pass through the right amount of *uchar* fields and to skip the gaps that may occur between the rows was your responsibility. The iterator method is considered a safer way as it takes over these tasks from the user. All you need to do is ask the begin and the end of the image matrix and then just increase the begin iterator until you reach the end. To acquire the value *pointed* by the iterator use the * operator (add it before it).
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp
:language: cpp
:tab-width: 4
:lines: 154-182
In case of color images we have three uchar items per column. This may be considered a short vector of uchar items, that has been baptized in OpenCV with the *Vec3b* name. To access the n-th sub column we use simple operator[] access. It's important to remember that OpenCV iterators go through the columns and automatically skip to the next row. Therefore in case of color images if you use a simple *uchar* iterator you'll be able to access only the blue channel values.
In case of color images we have three uchar items per column. This may be considered a short vector of uchar items, that has been baptized in OpenCV with the *Vec3b* name. To access the n-th sub column we use simple operator[] access. It's important to remember that OpenCV iterators go through the columns and automatically skip to the next row. Therefore in case of color images if you use a simple *uchar* iterator you'll be able to access only the blue channel values.
On-the-fly address calculation with reference returning
=======================================================
......@@ -136,7 +136,7 @@ The final method isn't recommended for scanning. It was made to acquire or modif
:tab-width: 4
:lines: 184-216
The functions takes your input type and coordinates and calculates on the fly the address of the queried item. Then returns a reference to that. This may be a constant when you *get* the value and non-constant when you *set* the value. As a safety step in **debug mode only*** there is performed a check that your input coordinates are valid and does exist. If this isn't the case you'll get a nice output message of this on the standard error output stream. Compared to the efficient way in release mode the only difference in using this is that for every element of the image you'll get a new row pointer for what we use the C operator[] to acquire the column element.
The functions takes your input type and coordinates and calculates on the fly the address of the queried item. Then returns a reference to that. This may be a constant when you *get* the value and non-constant when you *set* the value. As a safety step in **debug mode only*** there is performed a check that your input coordinates are valid and does exist. If this isn't the case you'll get a nice output message of this on the standard error output stream. Compared to the efficient way in release mode the only difference in using this is that for every element of the image you'll get a new row pointer for what we use the C operator[] to acquire the column element.
If you need to multiple lookups using this method for an image it may be troublesome and time consuming to enter the type and the at keyword for each of the accesses. To solve this problem OpenCV has a :basicstructures:`Mat_ <id3>` data type. It's the same as Mat with the extra need that at definition you need to specify the data type through what to look at the data matrix, however in return you can use the operator() for fast access of items. To make things even better this is easily convertible from and to the usual :basicstructures:`Mat <id3>` data type. A sample usage of this you can see in case of the color images of the upper function. Nevertheless, it's important to note that the same operation (with the same runtime speed) could have been done with the :basicstructures:`at() <mat-at>` function. It's just a less to write for the lazy programmer trick.
......
......@@ -6,7 +6,7 @@ Interoperability with OpenCV 1
Goal
====
For the OpenCV developer team it's important to constantly improve the library. We are constantly thinking about methods that will ease your work process, while still maintain the libraries flexibility. The new C++ interface is a development of us that serves this goal. Nevertheless, backward compatibility remains important. We do not want to break your code written for earlier version of the OpenCV library. Therefore, we made sure that we add some functions that deal with this. In the following you'll learn:
For the OpenCV developer team it's important to constantly improve the library. We are constantly thinking about methods that will ease your work process, while still maintain the libraries flexibility. The new C++ interface is a development of us that serves this goal. Nevertheless, backward compatibility remains important. We do not want to break your code written for earlier version of the OpenCV library. Therefore, we made sure that we add some functions that deal with this. In the following you'll learn:
.. container:: enumeratevisibleitemswithsquare
......@@ -17,9 +17,9 @@ For the OpenCV developer team it's important to constantly improve the library.
General
=======
When making the switch you first need to learn some about the new data structure for images: :ref:`matTheBasicImageContainer`, this replaces the old *CvMat* and *IplImage* ones. Switching to the new functions is easier. You just need to remember a couple of new things.
When making the switch you first need to learn some about the new data structure for images: :ref:`matTheBasicImageContainer`, this replaces the old *CvMat* and *IplImage* ones. Switching to the new functions is easier. You just need to remember a couple of new things.
OpenCV 2 received reorganization. No longer are all the functions crammed into a single library. We have many modules, each of them containing data structures and functions relevant to certain tasks. This way you do not need to ship a large library if you use just a subset of OpenCV. This means that you should also include only those headers you will use. For example:
OpenCV 2 received reorganization. No longer are all the functions crammed into a single library. We have many modules, each of them containing data structures and functions relevant to certain tasks. This way you do not need to ship a large library if you use just a subset of OpenCV. This means that you should also include only those headers you will use. For example:
.. code-block:: cpp
......@@ -28,13 +28,13 @@ OpenCV 2 received reorganization. No longer are all the functions crammed into a
#include <opencv2/highgui/highgui.hpp>
All the OpenCV related stuff is put into the *cv* namespace to avoid name conflicts with other libraries data structures and functions. Therefore, either you need to prepend the *cv::* keyword before everything that comes from OpenCV or after the includes, you just add a directive to use this:
All the OpenCV related stuff is put into the *cv* namespace to avoid name conflicts with other libraries data structures and functions. Therefore, either you need to prepend the *cv::* keyword before everything that comes from OpenCV or after the includes, you just add a directive to use this:
.. code-block:: cpp
using namespace cv; // The new C++ interface API is inside this namespace. Import it.
Because the functions are already in a namespace there is no need for them to contain the *cv* prefix in their name. As such all the new C++ compatible functions don't have this and they follow the camel case naming rule. This means the first letter is small (unless it's a name, like Canny) and the subsequent words start with a capital letter (like *copyMakeBorder*).
Because the functions are already in a namespace there is no need for them to contain the *cv* prefix in their name. As such all the new C++ compatible functions don't have this and they follow the camel case naming rule. This means the first letter is small (unless it's a name, like Canny) and the subsequent words start with a capital letter (like *copyMakeBorder*).
Now, remember that you need to link to your application all the modules you use, and in case you are on Windows using the *DLL* system you will need to add, again, to the path all the binaries. For more in-depth information if you're on Windows read :ref:`Windows_Visual_Studio_How_To` and for Linux an example usage is explained in :ref:`Linux_Eclipse_Usage`.
......@@ -42,7 +42,7 @@ Now for converting the *Mat* object you can use either the *IplImage* or the *Cv
.. code-block:: cpp
Mat I;
Mat I;
IplImage pI = I;
CvMat mI = I;
......@@ -50,9 +50,9 @@ Now if you want pointers the conversion gets just a little more complicated. The
.. code-block:: cpp
Mat I;
IplImage* pI = &I.operator IplImage();
CvMat* mI = &I.operator CvMat();
Mat I;
IplImage* pI = &I.operator IplImage();
CvMat* mI = &I.operator CvMat();
One of the biggest complaints of the C interface is that it leaves all the memory management to you. You need to figure out when it is safe to release your unused objects and make sure you do so before the program finishes or you could have troublesome memory leeks. To work around this issue in OpenCV there is introduced a sort of smart pointer. This will automatically release the object when it's no longer in use. To use this declare the pointers as a specialization of the *Ptr* :
......@@ -60,11 +60,11 @@ One of the biggest complaints of the C interface is that it leaves all the memor
Ptr<IplImage> piI = &I.operator IplImage();
Converting from the C data structures to the *Mat* is done by passing these inside its constructor. For example:
Converting from the C data structures to the *Mat* is done by passing these inside its constructor. For example:
.. code-block:: cpp
Mat K(piL), L;
Mat K(piL), L;
L = Mat(pI);
A case study
......@@ -79,7 +79,7 @@ Now that you have the basics done :download:`here's <../../../../samples/cpp/tut
:tab-width: 4
:lines: 1-9, 22-25, 27-44
Here you can observe that with the new structure we have no pointer problems, although it is possible to use the old functions and in the end just transform the result to a *Mat* object.
Here you can observe that with the new structure we have no pointer problems, although it is possible to use the old functions and in the end just transform the result to a *Mat* object.
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp
:language: cpp
......@@ -87,7 +87,7 @@ Here you can observe that with the new structure we have no pointer problems, al
:tab-width: 4
:lines: 46-51
Because, we want to mess around with the images luma component we first convert from the default RGB to the YUV color space and then split the result up into separate planes. Here the program splits: in the first example it processes each plane using one of the three major image scanning algorithms in OpenCV (C [] operator, iterator, individual element access). In a second variant we add to the image some Gaussian noise and then mix together the channels according to some formula.
Because, we want to mess around with the images luma component we first convert from the default RGB to the YUV color space and then split the result up into separate planes. Here the program splits: in the first example it processes each plane using one of the three major image scanning algorithms in OpenCV (C [] operator, iterator, individual element access). In a second variant we add to the image some Gaussian noise and then mix together the channels according to some formula.
The scanning version looks like:
......@@ -97,7 +97,7 @@ The scanning version looks like:
:tab-width: 4
:lines: 55-75
Here you can observe that we may go through all the pixels of an image in three fashions: an iterator, a C pointer and an individual element access style. You can read a more in-depth description of these in the :ref:`howToScanImagesOpenCV` tutorial. Converting from the old function names is easy. Just remove the cv prefix and use the new *Mat* data structure. Here's an example of this by using the weighted addition function:
Here you can observe that we may go through all the pixels of an image in three fashions: an iterator, a C pointer and an individual element access style. You can read a more in-depth description of these in the :ref:`howToScanImagesOpenCV` tutorial. Converting from the old function names is easy. Just remove the cv prefix and use the new *Mat* data structure. Here's an example of this by using the weighted addition function:
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp
:language: cpp
......@@ -105,7 +105,7 @@ Here you can observe that we may go through all the pixels of an image in three
:tab-width: 4
:lines: 79-112
As you may observe the *planes* variable is of type *Mat*. However, converting from *Mat* to *IplImage* is easy and made automatically with a simple assignment operator.
As you may observe the *planes* variable is of type *Mat*. However, converting from *Mat* to *IplImage* is easy and made automatically with a simple assignment operator.
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp
:language: cpp
......@@ -113,14 +113,14 @@ As you may observe the *planes* variable is of type *Mat*. However, converting f
:tab-width: 4
:lines: 115-127
The new *imshow* highgui function accepts both the *Mat* and *IplImage* data structures. Compile and run the program and if the first image below is your input you may get either the first or second as output:
The new *imshow* highgui function accepts both the *Mat* and *IplImage* data structures. Compile and run the program and if the first image below is your input you may get either the first or second as output:
.. image:: images/outputInteropOpenCV1.jpg
:alt: The output of the sample
:align: center
You may observe a runtime instance of this on the `YouTube here <https://www.youtube.com/watch?v=qckm-zvo31w>`_ and you can :download:`download the source code from here <../../../../samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp>` or find it in the :file:`samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp` of the OpenCV source code library.
You may observe a runtime instance of this on the `YouTube here <https://www.youtube.com/watch?v=qckm-zvo31w>`_ and you can :download:`download the source code from here <../../../../samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp>` or find it in the :file:`samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp` of the OpenCV source code library.
.. raw:: html
......
......@@ -8,11 +8,11 @@ Mask operations on matrices are quite simple. The idea is that we recalculate ea
Our test case
=============
Let us consider the issue of an image contrast enhancement method. Basically we want to apply for every pixel of the image the following formula:
Let us consider the issue of an image contrast enhancement method. Basically we want to apply for every pixel of the image the following formula:
.. math::
I(i,j) = 5*I(i,j) - [ I(i-1,j) + I(i+1,j) + I(i,j-1) + I(i,j+1)]
I(i,j) = 5*I(i,j) - [ I(i-1,j) + I(i+1,j) + I(i,j-1) + I(i,j+1)]
\iff I(i,j)*M, \text{where }
M = \bordermatrix{ _i\backslash ^j & -1 & 0 & +1 \cr
......@@ -23,12 +23,12 @@ Let us consider the issue of an image contrast enhancement method. Basically we
The first notation is by using a formula, while the second is a compacted version of the first by using a mask. You use the mask by putting the center of the mask matrix (in the upper case noted by the zero-zero index) on the pixel you want to calculate and sum up the pixel values multiplied with the overlapped matrix values. It's the same thing, however in case of large matrices the latter notation is a lot easier to look over.
Now let us see how we can make this happen by using the basic pixel access method or by using the :filtering:`filter2D <filter2d>` function.
Now let us see how we can make this happen by using the basic pixel access method or by using the :filtering:`filter2D <filter2d>` function.
The Basic Method
================
Here's a function that will do this:
Here's a function that will do this:
.. code-block:: cpp
......@@ -49,7 +49,7 @@ Here's a function that will do this:
for(int i= nChannels;i < nChannels*(myImage.cols-1); ++i)
{
*output++ = saturate_cast<uchar>(5*current[i]
*output++ = saturate_cast<uchar>(5*current[i]
-current[i-nChannels] - current[i+nChannels] - previous[i] - next[i]);
}
}
......@@ -87,7 +87,7 @@ We'll use the plain C [] operator to access pixels. Because we need to access mu
for(int i= nChannels;i < nChannels*(myImage.cols-1); ++i)
{
*output++ = saturate_cast<uchar>(5*current[i]
*output++ = saturate_cast<uchar>(5*current[i]
-current[i-nChannels] - current[i+nChannels] - previous[i] - next[i]);
}
}
......@@ -96,7 +96,7 @@ On the borders of the image the upper notation results inexistent pixel location
.. code-block:: cpp
Result.row(0).setTo(Scalar(0)); // The top row
Result.row(0).setTo(Scalar(0)); // The top row
Result.row(Result.rows-1).setTo(Scalar(0)); // The bottom row
Result.col(0).setTo(Scalar(0)); // The left column
Result.col(Result.cols-1).setTo(Scalar(0)); // The right column
......@@ -108,19 +108,19 @@ Applying such filters are so common in image processing that in OpenCV there exi
.. code-block:: cpp
Mat kern = (Mat_<char>(3,3) << 0, -1, 0,
Mat kern = (Mat_<char>(3,3) << 0, -1, 0,
-1, 5, -1,
0, -1, 0);
Then call the :filtering:`filter2D <filter2d>` function specifying the input, the output image and the kernell to use:
Then call the :filtering:`filter2D <filter2d>` function specifying the input, the output image and the kernell to use:
.. code-block:: cpp
filter2D(I, K, I.depth(), kern );
filter2D(I, K, I.depth(), kern );
The function even has a fifth optional argument to specify the center of the kernel, and a sixth one for determining what to do in the regions where the operation is undefined (borders). Using this function has the advantage that it's shorter, less verbose and because there are some optimization techniques implemented it is usually faster than the *hand-coded method*. For example in my test while the second one took only 13 milliseconds the first took around 31 milliseconds. Quite some difference.
For example:
For example:
.. image:: images/resultMatMaskFilter2D.png
:alt: A sample output of the program
......@@ -128,7 +128,7 @@ For example:
You can download this source code from :download:`here <../../../../samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp>` or look in the OpenCV source code libraries sample directory at :file:`samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp`.
Check out an instance of running the program on our `YouTube channel <http://www.youtube.com/watch?v=7PF1tAU9se4>`_ .
Check out an instance of running the program on our `YouTube channel <http://www.youtube.com/watch?v=7PF1tAU9se4>`_ .
.. raw:: html
......
......@@ -19,13 +19,13 @@ For example in the above image you can see that the mirror of the care is nothin
OpenCV has been around ever since 2001. In those days the library was built around a *C* interface. In those days to store the image in the memory they used a C structure entitled *IplImage*. This is the one you'll see in most of the older tutorials and educational materials. The problem with this is that it brings to the table all the minuses of the C language. The biggest issue is the manual management. It builds on the assumption that the user is responsible for taking care of memory allocation and deallocation. While this is no issue in case of smaller programs once your code base start to grove larger and larger it will be more and more a struggle to handle all this rather than focusing on actually solving your development goal.
Luckily C++ came around and introduced the concept of classes making possible to build another road for the user: automatic memory management (more or less). The good news is that C++ if fully compatible with C so no compatibility issues can arise from making the change. Therefore, OpenCV with its 2.0 version introduced a new C++ interface that by taking advantage of these offers a new way of doing things. A way, in which you do not need to fiddle with memory management; making your code concise (less to write, to achieve more). The only main downside of the C++ interface is that many embedded development systems at the moment support only C. Therefore, unless you are targeting this platform, there's no point on using the *old* methods (unless you're a masochist programmer and you're asking for trouble).
Luckily C++ came around and introduced the concept of classes making possible to build another road for the user: automatic memory management (more or less). The good news is that C++ if fully compatible with C so no compatibility issues can arise from making the change. Therefore, OpenCV with its 2.0 version introduced a new C++ interface that by taking advantage of these offers a new way of doing things. A way, in which you do not need to fiddle with memory management; making your code concise (less to write, to achieve more). The only main downside of the C++ interface is that many embedded development systems at the moment support only C. Therefore, unless you are targeting this platform, there's no point on using the *old* methods (unless you're a masochist programmer and you're asking for trouble).
The first thing you need to know about *Mat* is that you no longer need to manually allocate its size and release it as soon as you do not need it. While doing this is still a possibility, most of the OpenCV functions will allocate its output data manually. As a nice bonus if you pass on an already existing *Mat* object, what already has allocated the required space for the matrix, this will be reused. In other words we use at all times only as much memory as much we must to perform the task.
*Mat* is basically a class having two data parts: the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored and so on) and a pointer to the matrix containing the pixel values (may take any dimensionality depending on the method chosen for storing) . The matrix header size is constant. However, the size of the matrix itself may vary from image to image and usually is larger by order of magnitudes. Therefore, when you're passing on images in your program and at some point you need to create a copy of the image the big price you will need to build is for the matrix itself rather than its header. OpenCV is an image processing library. It contains a large collection of image processing functions. To solve a computational challenge most of the time you will end up using multiple functions of the library. Due to this passing on images to functions is a common practice. We should not forget that we are talking about image processing algorithms, which tend to be quite computational heavy. The last thing we want to do is to further decrease the speed of your program by making unnecessary copies of potentially *large* images.
To tackle this issue OpenCV uses a reference counting system. The idea is that each *Mat* object has its own header, however the matrix may be shared between two instance of them by having their matrix pointer point to the same address. Moreover, the copy operators **will only copy the headers**, and as also copy the pointer to the large matrix too, however not the matrix itself.
To tackle this issue OpenCV uses a reference counting system. The idea is that each *Mat* object has its own header, however the matrix may be shared between two instance of them by having their matrix pointer point to the same address. Moreover, the copy operators **will only copy the headers**, and as also copy the pointer to the large matrix too, however not the matrix itself.
.. code-block:: cpp
:linenos:
......@@ -37,21 +37,21 @@ To tackle this issue OpenCV uses a reference counting system. The idea is that e
C = A; // Assignment operator
All the above objects, in the end point to the same single data matrix. Their headers are different, however making any modification using either one of them will affect all the other ones too. In practice the different objects just provide different access method to the same underlying data. Nevertheless, their header parts are different. The real interesting part comes that you can create headers that refer only to a subsection of the full data. For example, to create a region of interest (*ROI*) in an image you just create a new header with the new boundaries:
All the above objects, in the end point to the same single data matrix. Their headers are different, however making any modification using either one of them will affect all the other ones too. In practice the different objects just provide different access method to the same underlying data. Nevertheless, their header parts are different. The real interesting part comes that you can create headers that refer only to a subsection of the full data. For example, to create a region of interest (*ROI*) in an image you just create a new header with the new boundaries:
.. code-block:: cpp
:linenos:
Mat D (A, Rect(10, 10, 100, 100) ); // using a rectangle
Mat E = A(Range:all(), Range(1,3)); // using row and column boundaries
Mat E = A(Range:all(), Range(1,3)); // using row and column boundaries
Now you may ask if the matrix itself may belong to multiple *Mat* objects who will take responsibility for its cleaning when it's no longer needed. The short answer is: the last object that used it. For this a reference counting mechanism is used. Whenever somebody copies a header of a *Mat* object a counter is increased for the matrix. Whenever a header is cleaned this counter is decreased. When the counter reaches zero the matrix too is freed. Because, sometimes you will still want to copy the matrix itself too, there exists the :basicstructures:`clone() <mat-clone>` or the :basicstructures:`copyTo() <mat-copyto>` function.
.. code-block:: cpp
:linenos:
Mat F = A.clone();
Mat G;
Mat F = A.clone();
Mat G;
A.copyTo(G);
Now modifying *F* or *G* will not affect the matrix pointed by the *Mat* header. What you need to remember from all this is that:
......@@ -64,19 +64,19 @@ Now modifying *F* or *G* will not affect the matrix pointed by the *Mat* header.
* Use the :basicstructures:`clone()<mat-clone>` or the :basicstructures:`copyTo() <mat-copyto>` function to copy the underlying matrix of an image.
*Storing* methods
=================
=================
This is about how you store the pixel values. You can select the color space and the data type used. The color space refers to how we combine color components in order to code a given color. The simplest one is the gray scale. Here the colors at our disposal are black and white. The combination of these allows us to create many shades of gray.
This is about how you store the pixel values. You can select the color space and the data type used. The color space refers to how we combine color components in order to code a given color. The simplest one is the gray scale. Here the colors at our disposal are black and white. The combination of these allows us to create many shades of gray.
For *colorful* ways we have a lot more of methods to choose from. However, every one of them breaks it down to three or four basic components and the combination of this will give all others. The most popular one of this is RGB, mainly because this is also how our eye builds up colors in our eyes. Its base colors are red, green and blue. To code the transparency of a color sometimes a fourth element: alpha (A) is added.
For *colorful* ways we have a lot more of methods to choose from. However, every one of them breaks it down to three or four basic components and the combination of this will give all others. The most popular one of this is RGB, mainly because this is also how our eye builds up colors in our eyes. Its base colors are red, green and blue. To code the transparency of a color sometimes a fourth element: alpha (A) is added.
However, they are many color systems each with their own advantages:
.. container:: enumeratevisibleitemswithsquare
* RGB is the most common as our eyes use something similar, our display systems also compose colors using these.
* The HSV and HLS decompose colors into their hue, saturation and value/luminance components, which is a more natural way for us to describe colors. Using you may for example dismiss the last component, making your algorithm less sensible to light conditions of the input image.
* YCrCb is used by the popular JPEG image format.
* The HSV and HLS decompose colors into their hue, saturation and value/luminance components, which is a more natural way for us to describe colors. Using you may for example dismiss the last component, making your algorithm less sensible to light conditions of the input image.
* YCrCb is used by the popular JPEG image format.
* CIE L*a*b* is a perceptually uniform color space, which comes handy if you need to measure the *distance* of a given color to another color.
Now each of the building components has their own valid domains. This leads to the data type used. How we store a component defines just how fine control we have over its domain. The smallest data type possible is *char*, which means one byte or 8 bits. This may be unsigned (so can store values from 0 to 255) or signed (values from -127 to +127). Although in case of three components this already gives 16 million possible colors to represent (like in case of RGB) we may acquire an even finer control by using the float (4 byte = 32 bit) or double (8 byte = 64 bit) data types for each component. Nevertheless, remember that increasing the size of a component also increases the size of the whole picture in the memory.
......@@ -84,13 +84,13 @@ Now each of the building components has their own valid domains. This leads to t
Creating explicitly a *Mat* object
==================================
In the :ref:`Load_Save_Image` tutorial you could already see how to write a matrix to an image file by using the :readWriteImageVideo:` imwrite() <imwrite>` function. However, for debugging purposes it's much more convenient to see the actual values. You can achieve this via the << operator of *Mat*. However, be aware that this only works for two dimensional matrices.
In the :ref:`Load_Save_Image` tutorial you could already see how to write a matrix to an image file by using the :readWriteImageVideo:` imwrite() <imwrite>` function. However, for debugging purposes it's much more convenient to see the actual values. You can achieve this via the << operator of *Mat*. However, be aware that this only works for two dimensional matrices.
Although *Mat* is a great class as image container it is also a general matrix class. Therefore, it is possible to create and manipulate multidimensional matrices. You can create a Mat object in multiple ways:
.. container:: enumeratevisibleitemswithsquare
+ :basicstructures:`Mat() <mat-mat>` Constructor
+ :basicstructures:`Mat() <mat-mat>` Constructor
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp
:language: cpp
......@@ -103,7 +103,7 @@ Although *Mat* is a great class as image container it is also a general matrix c
For two dimensional and multichannel images we first define their size: row and column count wise.
Then we need to specify the data type to use for storing the elements and the number of channels per matrix point. To do this we have multiple definitions made according to the following convention:
Then we need to specify the data type to use for storing the elements and the number of channels per matrix point. To do this we have multiple definitions made according to the following convention:
.. code-block:: cpp
......@@ -118,7 +118,7 @@ Although *Mat* is a great class as image container it is also a general matrix c
:tab-width: 4
:lines: 35-36
The upper example shows how to create a matrix with more than two dimensions. Specify its dimension, then pass a pointer containing the size for each dimension and the rest remains the same.
The upper example shows how to create a matrix with more than two dimensions. Specify its dimension, then pass a pointer containing the size for each dimension and the rest remains the same.
+ Create a header for an already existing IplImage pointer:
......@@ -174,7 +174,7 @@ Although *Mat* is a great class as image container it is also a general matrix c
:alt: Demo image of the matrix output
:align: center
.. note::
.. note::
You can fill out a matrix with random values using the :operationsOnArrays:`randu() <randu>` function. You need to give the lower and upper value between what you want the random values:
......@@ -187,11 +187,11 @@ Although *Mat* is a great class as image container it is also a general matrix c
Print out formatting
====================
In the above examples you could see the default formatting option. Nevertheless, OpenCV allows you to format your matrix output format to fit the rules of:
In the above examples you could see the default formatting option. Nevertheless, OpenCV allows you to format your matrix output format to fit the rules of:
.. container:: enumeratevisibleitemswithsquare
+ Default
+ Default
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp
:language: cpp
......@@ -213,7 +213,7 @@ In the above examples you could see the default formatting option. Nevertheless,
:alt: Default Output
:align: center
+ Comma separated values (CSV)
+ Comma separated values (CSV)
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp
:language: cpp
......@@ -253,7 +253,7 @@ OpenCV offers support for print of other common OpenCV data structures too via t
.. container:: enumeratevisibleitemswithsquare
+ 2D Point
+ 2D Point
.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp
:language: cpp
......
......@@ -44,7 +44,7 @@ Here you will learn the about the basic building blocks of the library. A must r
.. |HowScanImag| image:: images/howToScanImages.jpg
:height: 90pt
:width: 90pt
+
.. tabularcolumns:: m{100pt} m{300pt}
......@@ -193,7 +193,7 @@ Here you will learn the about the basic building blocks of the library. A must r
*Author:* |Author_BernatG|
Did you used OpenCV before its 2.0 version? Do you wanna know what happened with your library with 2.0? Don't you know how to convert your old OpenCV programs to the new C++ interface? Look here to shed light on all this questions.
=============== ======================================================
.. |InterOOpenCV1| image:: images/interopOpenCV1.png
......@@ -208,7 +208,7 @@ Here you will learn the about the basic building blocks of the library. A must r
.. toctree::
:hidden:
../mat_the_basic_image_container/mat_the_basic_image_container
../how_to_scan_images/how_to_scan_images
../mat-mask-operations/mat-mask-operations
......
.. note::
Unfortunetly we have no tutorials into this section. Nevertheless, our tutorial writting team is working on it. If you have a tutorial suggestion or you have writen yourself a tutorial (or coded a sample code) that you would like to see here please contact us via our :opencv_group:`user group <>`.
\ No newline at end of file
Unfortunetly we have no tutorials into this section. Nevertheless, our tutorial writting team is working on it. If you have a tutorial suggestion or you have writen yourself a tutorial (or coded a sample code) that you would like to see here please contact us via our :opencv_group:`user group <>`.
\ No newline at end of file
......@@ -3,8 +3,8 @@
.. |Author_AndreyK| unicode:: Andrey U+0020 Kamaev
.. |Author_LeonidBLB| unicode:: Leonid U+0020 Beynenson
.. |Author_VsevolodG| unicode:: Vsevolod U+0020 Glumov
.. |Author_VictorE| unicode:: Victor U+0020 Eruhimov
.. |Author_ArtemM| unicode:: Artem U+0020 Myagkov
.. |Author_FernandoI| unicode:: Fernando U+0020 Iglesias U+0020 Garc U+00ED a
.. |Author_VictorE| unicode:: Victor U+0020 Eruhimov
.. |Author_ArtemM| unicode:: Artem U+0020 Myagkov
.. |Author_FernandoI| unicode:: Fernando U+0020 Iglesias U+0020 Garc U+00ED a
.. |Author_EduardF| unicode:: Eduard U+0020 Feicho
......@@ -5,9 +5,9 @@ Detection of planar objects
.. highlight:: cpp
The goal of this tutorial is to learn how to use *features2d* and *calib3d* modules for detecting known planar objects in scenes.
The goal of this tutorial is to learn how to use *features2d* and *calib3d* modules for detecting known planar objects in scenes.
*Test data*: use images in your data folder, for instance, ``box.png`` and ``box_in_scene.png``.
*Test data*: use images in your data folder, for instance, ``box.png`` and ``box_in_scene.png``.
#.
Create a new console project. Read two input images. ::
......@@ -22,7 +22,7 @@ The goal of this tutorial is to learn how to use *features2d* and *calib3d* modu
FastFeatureDetector detector(15);
vector<KeyPoint> keypoints1;
detector.detect(img1, keypoints1);
... // do the same for the second image
#.
......@@ -32,7 +32,7 @@ The goal of this tutorial is to learn how to use *features2d* and *calib3d* modu
SurfDescriptorExtractor extractor;
Mat descriptors1;
extractor.compute(img1, keypoints1, descriptors1);
... // process keypoints from the second image as well
#.
......@@ -69,4 +69,4 @@ The goal of this tutorial is to learn how to use *features2d* and *calib3d* modu
perspectiveTransform(Mat(points1), points1Projected, H);
#.
Use ``drawMatches`` for drawing inliers.
Use ``drawMatches`` for drawing inliers.
......@@ -5,166 +5,166 @@
Learn about how to use the feature points detectors, descriptors and matching framework found inside OpenCV.
.. include:: ../../definitions/tocDefinitions.rst
.. include:: ../../definitions/tocDefinitions.rst
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|Harris| **Title:** :ref:`harris_detector`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Why is it a good idea to track corners? We learn to use the Harris method to detect corners
===================== ==============================================
.. |Harris| image:: images/trackingmotion/Harris_Detector_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|ShiTomasi| **Title:** :ref:`good_features_to_track`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we use an improved method to detect corners more accuratelyI
===================== ==============================================
.. |ShiTomasi| image:: images/trackingmotion/Shi_Tomasi_Detector_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|GenericCorner| **Title:** :ref:`generic_corner_detector`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Here you will learn how to use OpenCV functions to make your personalized corner detector!
===================== ==============================================
.. |GenericCorner| image:: images/trackingmotion/Generic_Corner_Detector_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|Subpixel| **Title:** :ref:`corner_subpixeles`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Is pixel resolution enough? Here we learn a simple method to improve our accuracy.
===================== ==============================================
.. |Subpixel| image:: images/trackingmotion/Corner_Subpixeles_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|FeatureDetect| **Title:** :ref:`feature_detection`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
In this tutorial, you will use *features2d* to detect interest points.
===================== ==============================================
.. |FeatureDetect| image:: images/Feature_Detection_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|FeatureDescript| **Title:** :ref:`feature_description`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
In this tutorial, you will use *features2d* to calculate feature vectors.
===================== ==============================================
.. |FeatureDescript| image:: images/Feature_Description_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|FeatureFlann| **Title:** :ref:`feature_flann_matcher`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
In this tutorial, you will use the FLANN library to make a fast matching.
===================== ==============================================
.. |FeatureFlann| image:: images/Feature_Flann_Matcher_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|FeatureHomo| **Title:** :ref:`feature_homography`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
In this tutorial, you will use *features2d* and *calib3d* to detect an object in a scene.
===================== ==============================================
.. |FeatureHomo| image:: images/Feature_Homography_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
......@@ -175,7 +175,7 @@ Learn about how to use the feature points detectors, descriptors and matching f
*Author:* |Author_VictorE|
You will use *features2d* and *calib3d* modules for detecting known planar objects in scenes.
You will use *features2d* and *calib3d* modules for detecting known planar objects in scenes.
===================== ==============================================
......
......@@ -87,14 +87,14 @@ This tutorial code's is shown lines below. You can also download it from `here <
/// Apply corner detection
goodFeaturesToTrack( src_gray,
corners,
maxCorners,
qualityLevel,
minDistance,
Mat(),
blockSize,
useHarrisDetector,
k );
corners,
maxCorners,
qualityLevel,
minDistance,
Mat(),
blockSize,
useHarrisDetector,
k );
/// Draw corners detected
......
......@@ -98,16 +98,16 @@ How does it work?
u & v
\end{bmatrix}
\left (
\displaystyle \sum_{x,y}
\displaystyle \sum_{x,y}
w(x,y)
\begin{bmatrix}
I_x^{2} & I_{x}I_{y} \\
I_xI_{y} & I_{y}^{2}
\end{bmatrix}
\right )
\begin{bmatrix}
\end{bmatrix}
\right )
\begin{bmatrix}
u \\
v
v
\end{bmatrix}
* Let's denote:
......@@ -115,11 +115,11 @@ How does it work?
.. math::
M = \displaystyle \sum_{x,y}
w(x,y)
\begin{bmatrix}
I_x^{2} & I_{x}I_{y} \\
I_xI_{y} & I_{y}^{2}
\end{bmatrix}
w(x,y)
\begin{bmatrix}
I_x^{2} & I_{x}I_{y} \\
I_xI_{y} & I_{y}^{2}
\end{bmatrix}
* So, our equation now is:
......@@ -128,10 +128,10 @@ How does it work?
E(u,v) \approx \begin{bmatrix}
u & v
\end{bmatrix}
M
\begin{bmatrix}
M
\begin{bmatrix}
u \\
v
v
\end{bmatrix}
......
......@@ -7,7 +7,7 @@ Squeeze out every little computation power from your system by using the power o
.. include:: ../../definitions/tocDefinitions.rst
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
......@@ -18,7 +18,7 @@ Squeeze out every little computation power from your system by using the power o
*Author:* |Author_BernatG|
This will give a good grasp on how to approach coding on the GPU module, once you already know how to handle the other modules. As a test case it will port the similarity methods from the tutorial :ref:`videoInputPSNRMSSIM` to the GPU.
This will give a good grasp on how to approach coding on the GPU module, once you already know how to handle the other modules. As a test case it will port the similarity methods from the tutorial :ref:`videoInputPSNRMSSIM` to the GPU.
=============== ======================================================
......
......@@ -3,30 +3,30 @@
*highgui* module. High Level GUI and Media
------------------------------------------
This section contains valuable tutorials about how to read/save your image/video files and how to use the built-in graphical user interface of the library.
This section contains valuable tutorials about how to read/save your image/video files and how to use the built-in graphical user interface of the library.
.. include:: ../../definitions/tocDefinitions.rst
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
=============== ======================================================
|Beginners_5| *Title:* :ref:`Adding_Trackbars`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
We will learn how to add a Trackbar to our applications
=============== ======================================================
.. |Beginners_5| image:: images/Adding_Trackbars_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
......@@ -34,7 +34,7 @@ This section contains valuable tutorials about how to read/save your image/video
|hVideoInput| *Title:* :ref:`videoInputPSNRMSSIM`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_BernatG|
You will learn how to read video streams, and how to calculate similarity values such as PSNR or SSIM.
......@@ -45,7 +45,7 @@ This section contains valuable tutorials about how to read/save your image/video
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
......
......@@ -5,11 +5,11 @@ Adding a Trackbar to our applications!
* In the previous tutorials (about *linear blending* and the *brightness and contrast adjustments*) you might have noted that we needed to give some **input** to our programs, such as :math:`\alpha` and :math:`beta`. We accomplished that by entering this data using the Terminal
* Well, it is time to use some fancy GUI tools. OpenCV provides some GUI utilities (*highgui.h*) for you. An example of this is a **Trackbar**
* Well, it is time to use some fancy GUI tools. OpenCV provides some GUI utilities (*highgui.h*) for you. An example of this is a **Trackbar**
.. image:: images/Adding_Trackbars_Tutorial_Trackbar.png
:alt: Trackbar example
:align: center
:align: center
* In this tutorial we will just modify our two previous programs so that they get the input information from the trackbar.
......@@ -19,7 +19,7 @@ Goals
In this tutorial you will learn how to:
* Add a Trackbar in an OpenCV window by using :create_trackbar:`createTrackbar <>`
* Add a Trackbar in an OpenCV window by using :create_trackbar:`createTrackbar <>`
Code
=====
......@@ -33,13 +33,13 @@ Let's modify the program made in the tutorial :ref:`Adding_Images`. We will let
using namespace cv;
/// Global Variables
/// Global Variables
const int alpha_slider_max = 100;
int alpha_slider;
int alpha_slider;
double alpha;
double beta;
double beta;
/// Matrices to store images
/// Matrices to store images
Mat src1;
Mat src2;
Mat dst;
......@@ -49,12 +49,12 @@ Let's modify the program made in the tutorial :ref:`Adding_Images`. We will let
* @brief Callback for trackbar
*/
void on_trackbar( int, void* )
{
{
alpha = (double) alpha_slider/alpha_slider_max ;
beta = ( 1.0 - alpha );
addWeighted( src1, alpha, src2, beta, 0.0, dst);
imshow( "Linear Blend", dst );
}
......@@ -67,7 +67,7 @@ Let's modify the program made in the tutorial :ref:`Adding_Images`. We will let
if( !src1.data ) { printf("Error loading src1 \n"); return -1; }
if( !src2.data ) { printf("Error loading src2 \n"); return -1; }
/// Initialize values
/// Initialize values
alpha_slider = 0;
/// Create Windows
......@@ -75,13 +75,13 @@ Let's modify the program made in the tutorial :ref:`Adding_Images`. We will let
/// Create Trackbars
char TrackbarName[50];
sprintf( TrackbarName, "Alpha x %d", alpha_slider_max );
sprintf( TrackbarName, "Alpha x %d", alpha_slider_max );
createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar );
/// Show some stuff
on_trackbar( alpha_slider, 0 );
/// Wait until user press some key
waitKey(0);
return 0;
......@@ -113,7 +113,7 @@ We only analyze the code that is related to Trackbar:
createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar );
Note the following:
* Our Trackbar has a label **TrackbarName**
* The Trackbar is located in the window named **"Linear Blend"**
* The Trackbar values will be in the range from :math:`0` to **alpha_slider_max** (the minimum limit is always **zero**).
......@@ -125,21 +125,21 @@ We only analyze the code that is related to Trackbar:
.. code-block:: cpp
void on_trackbar( int, void* )
{
{
alpha = (double) alpha_slider/alpha_slider_max ;
beta = ( 1.0 - alpha );
addWeighted( src1, alpha, src2, beta, 0.0, dst);
imshow( "Linear Blend", dst );
}
Note that:
* We use the value of **alpha_slider** (integer) to get a double value for **alpha**.
* We use the value of **alpha_slider** (integer) to get a double value for **alpha**.
* **alpha_slider** is updated each time the trackbar is displaced by the user.
* We define *src1*, *src2*, *dist*, *alpha*, *alpha_slider* and *beta* as global variables, so they can be used everywhere.
Result
=======
......@@ -147,13 +147,13 @@ Result
.. image:: images/Adding_Trackbars_Tutorial_Result_0.jpg
:alt: Adding Trackbars - Windows Linux
:align: center
:align: center
* As a manner of practice, you can also add 02 trackbars for the program made in :ref:`Basic_Linear_Transform`. One trackbar to set :math:`\alpha` and another for :math:`\beta`. The output might look like:
.. image:: images/Adding_Trackbars_Tutorial_Result_1.jpg
:alt: Adding Trackbars - Lena
:align: center
:align: center
......
......@@ -27,9 +27,9 @@ As a test case where to show off these using OpenCV I've created a small program
How to read a video stream (online-camera or offline-file)?
===========================================================
Essentially, all the functionalities required for video manipulation is integrated in the :huivideo:`VideoCapture <videocapture>` C++ class. This on itself builds on the FFmpeg open source library. This is a basic dependency of OpenCV so you shouldn't need to worry about this. A video is composed of a succession of images, we refer to these in the literature as frames. In case of a video file there is a *frame rate* specifying just how long is between two frames. While for the video cameras usually there is a limit of just how many frames they can digitalize per second, this property is less important as at any time the camera sees the current snapshot of the world.
Essentially, all the functionalities required for video manipulation is integrated in the :huivideo:`VideoCapture <videocapture>` C++ class. This on itself builds on the FFmpeg open source library. This is a basic dependency of OpenCV so you shouldn't need to worry about this. A video is composed of a succession of images, we refer to these in the literature as frames. In case of a video file there is a *frame rate* specifying just how long is between two frames. While for the video cameras usually there is a limit of just how many frames they can digitalize per second, this property is less important as at any time the camera sees the current snapshot of the world.
The first task you need to do is to assign to a :huivideo:`VideoCapture <videocapture>` class its source. You can do this either via the :huivideo:`constructor <videocapture-videocapture>` or its :huivideo:`open <videocapture-open>` function. If this argument is an integer then you will bind the class to a camera, a device. The number passed here is the ID of the device, assigned by the operating system. If you have a single camera attached to your system its ID will probably be zero and further ones increasing from there. If the parameter passed to these is a string it will refer to a video file, and the string points to the location and name of the file. For example, to the upper source code a valid command line is:
The first task you need to do is to assign to a :huivideo:`VideoCapture <videocapture>` class its source. You can do this either via the :huivideo:`constructor <videocapture-videocapture>` or its :huivideo:`open <videocapture-open>` function. If this argument is an integer then you will bind the class to a camera, a device. The number passed here is the ID of the device, assigned by the operating system. If you have a single camera attached to your system its ID will probably be zero and further ones increasing from there. If the parameter passed to these is a string it will refer to a video file, and the string points to the location and name of the file. For example, to the upper source code a valid command line is:
.. code-block:: bash
......@@ -56,7 +56,7 @@ To check if the binding of the class to a video source was successful or not use
return -1;
}
Closing the video is automatic when the objects destructor is called. However, if you want to close it before this you need to call its :huivideo:`release <videocapture-release>` function. The frames of the video are just simple images. Therefore, we just need to extract them from the :huivideo:`VideoCapture <videocapture>` object and put them inside a *Mat* one. The video streams are sequential. You may get the frames one after another by the :huivideo:`read <videocapture-read>` or the overloaded >> operator:
Closing the video is automatic when the objects destructor is called. However, if you want to close it before this you need to call its :huivideo:`release <videocapture-release>` function. The frames of the video are just simple images. Therefore, we just need to extract them from the :huivideo:`VideoCapture <videocapture>` object and put them inside a *Mat* one. The video streams are sequential. You may get the frames one after another by the :huivideo:`read <videocapture-read>` or the overloaded >> operator:
.. code-block:: cpp
......@@ -64,7 +64,7 @@ Closing the video is automatic when the objects destructor is called. However, i
captRefrnc >> frameReference;
captUndTst.open(frameUnderTest);
The upper read operations will leave empty the *Mat* objects if no frame could be acquired (either cause the video stream was closed or you got to the end of the video file). We can check this with a simple if:
The upper read operations will leave empty the *Mat* objects if no frame could be acquired (either cause the video stream was closed or you got to the end of the video file). We can check this with a simple if:
.. code-block:: cpp
......@@ -73,9 +73,9 @@ The upper read operations will leave empty the *Mat* objects if no frame could b
// exit the program
}
A read method is made of a frame grab and a decoding applied on that. You may call explicitly these two by using the :huivideo:`grab <videocapture-grab>` and then the :huivideo:`retrieve <videocapture-retrieve>` functions.
A read method is made of a frame grab and a decoding applied on that. You may call explicitly these two by using the :huivideo:`grab <videocapture-grab>` and then the :huivideo:`retrieve <videocapture-retrieve>` functions.
Videos have many-many information attached to them besides the content of the frames. These are usually numbers, however in some case it may be short character sequences (4 bytes or less). Due to this to acquire these information there is a general function named :huivideo:`get <videocapture-get>` that returns double values containing these properties. Use bitwise operations to decode the characters from a double type and conversions where valid values are only integers. Its single argument is the ID of the queried property. For example, here we get the size of the frames in the reference and test case video file; plus the number of frames inside the reference.
Videos have many-many information attached to them besides the content of the frames. These are usually numbers, however in some case it may be short character sequences (4 bytes or less). Due to this to acquire these information there is a general function named :huivideo:`get <videocapture-get>` that returns double values containing these properties. Use bitwise operations to decode the characters from a double type and conversions where valid values are only integers. Its single argument is the ID of the queried property. For example, here we get the size of the frames in the reference and test case video file; plus the number of frames inside the reference.
.. code-block:: cpp
......@@ -85,7 +85,7 @@ Videos have many-many information attached to them besides the content of the fr
cout << "Reference frame resolution: Width=" << refS.width << " Height=" << refS.height
<< " of nr#: " << captRefrnc.get(CV_CAP_PROP_FRAME_COUNT) << endl;
When you are working with videos you may often want to control these values yourself. To do this there is a :huivideo:`set <videocapture-set>` function. Its first argument remains the name of the property you want to change and there is a second of double type containing the value to be set. It will return true if it succeeds and false otherwise. Good examples for this is seeking in a video file to a given time or frame:
When you are working with videos you may often want to control these values yourself. To do this there is a :huivideo:`set <videocapture-set>` function. Its first argument remains the name of the property you want to change and there is a second of double type containing the value to be set. It will return true if it succeeds and false otherwise. Good examples for this is seeking in a video file to a given time or frame:
.. code-block:: cpp
......@@ -93,7 +93,7 @@ When you are working with videos you may often want to control these values your
captRefrnc.set(CV_CAP_PROP_POS_FRAMES, 10); // go to the 10th frame of the video
// now a read operation would read the frame at the set position
For properties you can read and change look into the documentation of the :huivideo:`get <videocapture-get>` and :huivideo:`set <videocapture-set>` functions.
For properties you can read and change look into the documentation of the :huivideo:`get <videocapture-get>` and :huivideo:`set <videocapture-set>` functions.
Image similarity - PSNR and SSIM
......@@ -111,7 +111,7 @@ Then the PSNR is expressed as:
PSNR = 10 \cdot \log_{10} \left( \frac{MAX_I^2}{MSE} \right)
Here the :math:`MAX_I^2` is the maximum valid value for a pixel. In case of the simple single byte image per pixel per channel this is 255. When two images are the same the MSE will give zero, resulting in an invalid divide by zero operation in the PSNR formula. In this case the PSNR is undefined and as we'll need to handle this case separately. The transition to a logarithmic scale is made because the pixel values have a very wide dynamic range. All this translated to OpenCV and a C++ function looks like:
Here the :math:`MAX_I^2` is the maximum valid value for a pixel. In case of the simple single byte image per pixel per channel this is 255. When two images are the same the MSE will give zero, resulting in an invalid divide by zero operation in the PSNR formula. In this case the PSNR is undefined and as we'll need to handle this case separately. The transition to a logarithmic scale is made because the pixel values have a very wide dynamic range. All this translated to OpenCV and a C++ function looks like:
.. code-block:: cpp
......@@ -136,13 +136,13 @@ Here the :math:`MAX_I^2` is the maximum valid value for a pixel. In case of the
}
}
Typically result values are anywhere between 30 and 50 for video compression, where higher is better. If the images significantly differ you'll get much lower ones like 15 and so. This similarity check is easy and fast to calculate, however in practice it may turn out somewhat inconsistent with human eye perception. The **structural similarity** algorithm aims to correct this.
Typically result values are anywhere between 30 and 50 for video compression, where higher is better. If the images significantly differ you'll get much lower ones like 15 and so. This similarity check is easy and fast to calculate, however in practice it may turn out somewhat inconsistent with human eye perception. The **structural similarity** algorithm aims to correct this.
Describing the methods goes well beyond the purpose of this tutorial. For that I invite you to read the article introducing it. Nevertheless, you can get a good image of it by looking at the OpenCV implementation below.
Describing the methods goes well beyond the purpose of this tutorial. For that I invite you to read the article introducing it. Nevertheless, you can get a good image of it by looking at the OpenCV implementation below.
.. seealso::
SSIM is described more in-depth in the: "Z. Wang, A. C. Bovik, H. R. Sheikh and E. P. Simoncelli, "Image quality assessment: From error visibility to structural similarity," IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, Apr. 2004." article.
SSIM is described more in-depth in the: "Z. Wang, A. C. Bovik, H. R. Sheikh and E. P. Simoncelli, "Image quality assessment: From error visibility to structural similarity," IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, Apr. 2004." article.
.. code-block:: cpp
......@@ -162,7 +162,7 @@ Describing the methods goes well beyond the purpose of this tutorial. For that I
/***********************PRELIMINARY COMPUTING ******************************/
Mat mu1, mu2; //
Mat mu1, mu2; //
GaussianBlur(I1, mu1, Size(11, 11), 1.5);
GaussianBlur(I2, mu2, Size(11, 11), 1.5);
......@@ -199,7 +199,7 @@ Describing the methods goes well beyond the purpose of this tutorial. For that I
return mssim;
}
This will return a similarity index for each channel of the image. This value is between zero and one, where one corresponds to perfect fit. Unfortunately, the many Gaussian blurring is quite costly, so while the PSNR may work in a real time like environment (24 frame per second) this will take significantly more than to accomplish similar performance results.
This will return a similarity index for each channel of the image. This value is between zero and one, where one corresponds to perfect fit. Unfortunately, the many Gaussian blurring is quite costly, so while the PSNR may work in a real time like environment (24 frame per second) this will take significantly more than to accomplish similar performance results.
Therefore, the source code presented at the start of the tutorial will perform the PSNR measurement for each frame, and the SSIM only for the frames where the PSNR falls below an input value. For visualization purpose we show both images in an OpenCV window and print the PSNR and MSSIM values to the console. Expect to see something like:
......@@ -207,7 +207,7 @@ Therefore, the source code presented at the start of the tutorial will perform t
:alt: A sample output
:align: center
You may observe a runtime instance of this on the `YouTube here <https://www.youtube.com/watch?v=iOcNljutOgg>`_.
You may observe a runtime instance of this on the `YouTube here <https://www.youtube.com/watch?v=iOcNljutOgg>`_.
.. raw:: html
......
.. _videoWriteHighGui: Creating a video with OpenCV **************************** Goal ==== Whenever you work with video feeds you may eventually want to save your image processing result in a form of a new video file. For simple video outputs you can use the OpenCV built-in :huivideo:`VideoWriter <videowriter-videowriter>` class, designed for this. .. container:: enumeratevisibleitemswithsquare + How to create a video file with OpenCV + What type of video files you can create with OpenCV + How to extract a given color channel from a video As a simple demonstration I'll just extract one of the RGB color channels of an input video file into a new video. You can control the flow of the application from its console line arguments: .. container:: enumeratevisibleitemswithsquare + The first argument points to the video file to work on + The second argument may be one of the characters: R G B. This will specify which of the channels to extract. + The last argument is the character Y (Yes) or N (No). If this is no, the codec used for the input video file will be the same as for the output. Otherwise, a window will pop up and allow you to select yourself the codec to use. For example, a valid command line would look like: .. code-block:: bash video-write.exe video/Megamind.avi R Y The source code =============== You may also find the source code and these video file in the :file:`samples/cpp/tutorial_code/highgui/video-write/` folder of the OpenCV source library or :download:`download it from here <../../../../samples/cpp/tutorial_code/HighGUI/video-write/video-write.cpp>`. .. literalinclude:: ../../../../samples/cpp/tutorial_code/HighGUI/video-write/video-write.cpp :language: cpp :linenos: :tab-width: 4 :lines: 1-8, 21-22, 24-97 The structure of a video ======================== For start, you should have an idea of just how a video file looks. Every video file in itself is a container. The type of the container is expressed in the files extension (for example *avi*, *mov* or *mkv*). This contains multiple elements like: video feeds, audio feeds or other tracks (like for example subtitles). How these feeds are stored is determined by the codec used for each one of them. In case of the audio tracks commonly used codecs are *mp3* or *aac*. For the video files the list is somehow longer and includes names such as *XVID*, *DIVX*, *H264* or *LAGS* (*Lagarith Lossless Codec*). The full list of codecs you may use on a system depends on just what one you have installed. .. image:: images/videoFileStructure.png :alt: The Structure of the video :align: center As you can see things can get really complicated with videos. However, OpenCV is mainly a computer vision library, not a video stream, codec and write one. Therefore, the developers tried to keep this part as simple as possible. Due to this OpenCV for video containers supports only the *avi* extension, its first version. A direct limitation of this is that you cannot save a video file larger than 2 GB. Furthermore you can only create and expand a single video track inside the container. No audio or other track editing support here. Nevertheless, any video codec present on your system might work. If you encounter some of these limitations you will need to look into more specialized video writing libraries such as *FFMpeg* or codecs as *HuffYUV*, *CorePNG* and *LCL*. As an alternative, create the video track with OpenCV and expand it with sound tracks or convert it to other formats by using video manipulation programs such as *VirtualDub* or *AviSynth*. The *VideoWriter* class ======================= The content written here builds on the assumption you already read the :ref:`videoInputPSNRMSSIM` tutorial and you know how to read video files. To create a video file you just need to create an instance of the :huivideo:`VideoWriter <videowriter-videowriter>` class. You can specify its properties either via parameters in the constructor or later on via the :huivideo:`open <videowriter-open>` function. Either way, the parameters are the same: 1. The name of the output that contains the container type in its extension. At the moment only *avi* is supported. We construct this from the input file, add to this the name of the channel to use, and finish it off with the container extension. .. code-block:: cpp const string source = argv[1]; // the source file name string::size_type pAt = source.find_last_of('.'); // Find extension point const string NAME = source.substr(0, pAt) + argv[2][0] + ".avi"; // Form the new name with container #. The codec to use for the video track. Now all the video codecs have a unique short name of maximum four characters. Hence, the *XVID*, *DIVX* or *H264* names. This is called a four character code. You may also ask this from an input video by using its *get* function. Because the *get* function is a general function it always returns double values. A double value is stored on 64 bits. Four characters are four bytes, meaning 32 bits. These four characters are coded in the lower 32 bits of the *double*. A simple way to throw away the upper 32 bits would be to just convert this value to *int*: .. code-block:: cpp VideoCapture inputVideo(source); // Open input int ex = static_cast<int>(inputVideo.get(CV_CAP_PROP_FOURCC)); // Get Codec Type- Int form OpenCV internally works with this integer type and expect this as its second parameter. Now to convert from the integer form to string we may use two methods: a bitwise operator and a union method. The first one extracting from an int the characters looks like (an "and" operation, some shifting and adding a 0 at the end to close the string): .. code-block:: cpp char EXT[] = {ex & 0XFF , (ex & 0XFF00) >> 8,(ex & 0XFF0000) >> 16,(ex & 0XFF000000) >> 24, 0}; You can do the same thing with the *union* as: .. code-block:: cpp union { int v; char c[5];} uEx ; uEx.v = ex; // From Int to char via union uEx.c[4]='\0'; The advantage of this is that the conversion is done automatically after assigning, while for the bitwise operator you need to do the operations whenever you change the codec type. In case you know the codecs four character code beforehand, you can use the *CV_FOURCC* macro to build the integer: .. code-block::cpp CV_FOURCC('P','I','M,'1') // this is an MPEG1 codec from the characters to integer If you pass for this argument minus one than a window will pop up at runtime that contains all the codec installed on your system and ask you to select the one to use: .. image:: images/videoCompressSelect.png :alt: Select the codec type to use :align: center #. The frame per second for the output video. Again, here I keep the input videos frame per second by using the *get* function. #. The size of the frames for the output video. Here too I keep the input videos frame size per second by using the *get* function. #. The final argument is an optional one. By default is true and says that the output will be a colorful one (so for write you will send three channel images). To create a gray scale video pass a false parameter here. Here it is, how I use it in the sample: .. code-block:: cpp VideoWriter outputVideo; Size S = Size((int) inputVideo.get(CV_CAP_PROP_FRAME_WIDTH), //Acquire input size (int) inputVideo.get(CV_CAP_PROP_FRAME_HEIGHT)); outputVideo.open(NAME , ex, inputVideo.get(CV_CAP_PROP_FPS),S, true); Afterwards, you use the :huivideo:`isOpened() <videowriter-isopened>` function to find out if the open operation succeeded or not. The video file automatically closes when the *VideoWriter* object is destroyed. After you open the object with success you can send the frames of the video in a sequential order by using the :huivideo:`write<videowriter-write>` function of the class. Alternatively, you can use its overloaded operator << : .. code-block:: cpp outputVideo.write(res); //or outputVideo << res; Extracting a color channel from an RGB image means to set to zero the RGB values of the other channels. You can either do this with image scanning operations or by using the split and merge operations. You first split the channels up into different images, set the other channels to zero images of the same size and type and finally merge them back: .. code-block:: cpp split(src, spl); // process - extract only the correct channel for( int i =0; i < 3; ++i) if (i != channel) spl[i] = Mat::zeros(S, spl[0].type()); merge(spl, res); Put all this together and you'll get the upper source code, whose runtime result will show something around the idea: .. image:: images/resultOutputWideoWrite.png :alt: A sample output :align: center You may observe a runtime instance of this on the `YouTube here <https://www.youtube.com/watch?v=jpBwHxsl1_0>`_. .. raw:: html <div align="center"> <iframe title="Creating a video with OpenCV" width="560" height="349" src="http://www.youtube.com/embed/jpBwHxsl1_0?rel=0&loop=1" frameborder="0" allowfullscreen align="middle"></iframe> </div>
\ No newline at end of file
.. _videoWriteHighGui: Creating a video with OpenCV **************************** Goal ==== Whenever you work with video feeds you may eventually want to save your image processing result in a form of a new video file. For simple video outputs you can use the OpenCV built-in :huivideo:`VideoWriter <videowriter-videowriter>` class, designed for this. .. container:: enumeratevisibleitemswithsquare + How to create a video file with OpenCV + What type of video files you can create with OpenCV + How to extract a given color channel from a video As a simple demonstration I'll just extract one of the RGB color channels of an input video file into a new video. You can control the flow of the application from its console line arguments: .. container:: enumeratevisibleitemswithsquare + The first argument points to the video file to work on + The second argument may be one of the characters: R G B. This will specify which of the channels to extract. + The last argument is the character Y (Yes) or N (No). If this is no, the codec used for the input video file will be the same as for the output. Otherwise, a window will pop up and allow you to select yourself the codec to use. For example, a valid command line would look like: .. code-block:: bash video-write.exe video/Megamind.avi R Y The source code =============== You may also find the source code and these video file in the :file:`samples/cpp/tutorial_code/highgui/video-write/` folder of the OpenCV source library or :download:`download it from here <../../../../samples/cpp/tutorial_code/HighGUI/video-write/video-write.cpp>`. .. literalinclude:: ../../../../samples/cpp/tutorial_code/HighGUI/video-write/video-write.cpp :language: cpp :linenos: :tab-width: 4 :lines: 1-8, 21-22, 24-97 The structure of a video ======================== For start, you should have an idea of just how a video file looks. Every video file in itself is a container. The type of the container is expressed in the files extension (for example *avi*, *mov* or *mkv*). This contains multiple elements like: video feeds, audio feeds or other tracks (like for example subtitles). How these feeds are stored is determined by the codec used for each one of them. In case of the audio tracks commonly used codecs are *mp3* or *aac*. For the video files the list is somehow longer and includes names such as *XVID*, *DIVX*, *H264* or *LAGS* (*Lagarith Lossless Codec*). The full list of codecs you may use on a system depends on just what one you have installed. .. image:: images/videoFileStructure.png :alt: The Structure of the video :align: center As you can see things can get really complicated with videos. However, OpenCV is mainly a computer vision library, not a video stream, codec and write one. Therefore, the developers tried to keep this part as simple as possible. Due to this OpenCV for video containers supports only the *avi* extension, its first version. A direct limitation of this is that you cannot save a video file larger than 2 GB. Furthermore you can only create and expand a single video track inside the container. No audio or other track editing support here. Nevertheless, any video codec present on your system might work. If you encounter some of these limitations you will need to look into more specialized video writing libraries such as *FFMpeg* or codecs as *HuffYUV*, *CorePNG* and *LCL*. As an alternative, create the video track with OpenCV and expand it with sound tracks or convert it to other formats by using video manipulation programs such as *VirtualDub* or *AviSynth*. The *VideoWriter* class ======================= The content written here builds on the assumption you already read the :ref:`videoInputPSNRMSSIM` tutorial and you know how to read video files. To create a video file you just need to create an instance of the :huivideo:`VideoWriter <videowriter-videowriter>` class. You can specify its properties either via parameters in the constructor or later on via the :huivideo:`open <videowriter-open>` function. Either way, the parameters are the same: 1. The name of the output that contains the container type in its extension. At the moment only *avi* is supported. We construct this from the input file, add to this the name of the channel to use, and finish it off with the container extension. .. code-block:: cpp const string source = argv[1]; // the source file name string::size_type pAt = source.find_last_of('.'); // Find extension point const string NAME = source.substr(0, pAt) + argv[2][0] + ".avi"; // Form the new name with container #. The codec to use for the video track. Now all the video codecs have a unique short name of maximum four characters. Hence, the *XVID*, *DIVX* or *H264* names. This is called a four character code. You may also ask this from an input video by using its *get* function. Because the *get* function is a general function it always returns double values. A double value is stored on 64 bits. Four characters are four bytes, meaning 32 bits. These four characters are coded in the lower 32 bits of the *double*. A simple way to throw away the upper 32 bits would be to just convert this value to *int*: .. code-block:: cpp VideoCapture inputVideo(source); // Open input int ex = static_cast<int>(inputVideo.get(CV_CAP_PROP_FOURCC)); // Get Codec Type- Int form OpenCV internally works with this integer type and expect this as its second parameter. Now to convert from the integer form to string we may use two methods: a bitwise operator and a union method. The first one extracting from an int the characters looks like (an "and" operation, some shifting and adding a 0 at the end to close the string): .. code-block:: cpp char EXT[] = {ex & 0XFF , (ex & 0XFF00) >> 8,(ex & 0XFF0000) >> 16,(ex & 0XFF000000) >> 24, 0}; You can do the same thing with the *union* as: .. code-block:: cpp union { int v; char c[5];} uEx ; uEx.v = ex; // From Int to char via union uEx.c[4]='\0'; The advantage of this is that the conversion is done automatically after assigning, while for the bitwise operator you need to do the operations whenever you change the codec type. In case you know the codecs four character code beforehand, you can use the *CV_FOURCC* macro to build the integer: .. code-block::cpp CV_FOURCC('P','I','M,'1') // this is an MPEG1 codec from the characters to integer If you pass for this argument minus one than a window will pop up at runtime that contains all the codec installed on your system and ask you to select the one to use: .. image:: images/videoCompressSelect.png :alt: Select the codec type to use :align: center #. The frame per second for the output video. Again, here I keep the input videos frame per second by using the *get* function. #. The size of the frames for the output video. Here too I keep the input videos frame size per second by using the *get* function. #. The final argument is an optional one. By default is true and says that the output will be a colorful one (so for write you will send three channel images). To create a gray scale video pass a false parameter here. Here it is, how I use it in the sample: .. code-block:: cpp VideoWriter outputVideo; Size S = Size((int) inputVideo.get(CV_CAP_PROP_FRAME_WIDTH), //Acquire input size (int) inputVideo.get(CV_CAP_PROP_FRAME_HEIGHT)); outputVideo.open(NAME , ex, inputVideo.get(CV_CAP_PROP_FPS),S, true); Afterwards, you use the :huivideo:`isOpened() <videowriter-isopened>` function to find out if the open operation succeeded or not. The video file automatically closes when the *VideoWriter* object is destroyed. After you open the object with success you can send the frames of the video in a sequential order by using the :huivideo:`write<videowriter-write>` function of the class. Alternatively, you can use its overloaded operator << : .. code-block:: cpp outputVideo.write(res); //or outputVideo << res; Extracting a color channel from an RGB image means to set to zero the RGB values of the other channels. You can either do this with image scanning operations or by using the split and merge operations. You first split the channels up into different images, set the other channels to zero images of the same size and type and finally merge them back: .. code-block:: cpp split(src, spl); // process - extract only the correct channel for( int i =0; i < 3; ++i) if (i != channel) spl[i] = Mat::zeros(S, spl[0].type()); merge(spl, res); Put all this together and you'll get the upper source code, whose runtime result will show something around the idea: .. image:: images/resultOutputWideoWrite.png :alt: A sample output :align: center You may observe a runtime instance of this on the `YouTube here <https://www.youtube.com/watch?v=jpBwHxsl1_0>`_. .. raw:: html <div align="center"> <iframe title="Creating a video with OpenCV" width="560" height="349" src="http://www.youtube.com/embed/jpBwHxsl1_0?rel=0&loop=1" frameborder="0" allowfullscreen align="middle"></iframe> </div>
\ No newline at end of file
......
......@@ -112,21 +112,21 @@ This tutorial code's is shown lines below. You can also download it from `here <
/// Create Erosion Trackbar
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Erosion Demo",
&erosion_elem, max_elem,
Erosion );
&erosion_elem, max_elem,
Erosion );
createTrackbar( "Kernel size:\n 2n +1", "Erosion Demo",
&erosion_size, max_kernel_size,
Erosion );
&erosion_size, max_kernel_size,
Erosion );
/// Create Dilation Trackbar
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Dilation Demo",
&dilation_elem, max_elem,
Dilation );
&dilation_elem, max_elem,
Dilation );
createTrackbar( "Kernel size:\n 2n +1", "Dilation Demo",
&dilation_size, max_kernel_size,
Dilation );
&dilation_size, max_kernel_size,
Dilation );
/// Default start
Erosion( 0, 0 );
......@@ -145,8 +145,8 @@ This tutorial code's is shown lines below. You can also download it from `here <
else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
Mat element = getStructuringElement( erosion_type,
Size( 2*erosion_size + 1, 2*erosion_size+1 ),
Point( erosion_size, erosion_size ) );
Size( 2*erosion_size + 1, 2*erosion_size+1 ),
Point( erosion_size, erosion_size ) );
/// Apply the erosion operation
erode( src, erosion_dst, element );
......@@ -162,8 +162,8 @@ This tutorial code's is shown lines below. You can also download it from `here <
else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
Mat element = getStructuringElement( dilation_type,
Size( 2*dilation_size + 1, 2*dilation_size+1 ),
Point( dilation_size, dilation_size ) );
Size( 2*dilation_size + 1, 2*dilation_size+1 ),
Point( dilation_size, dilation_size ) );
/// Apply the dilation operation
dilate( src, dilation_dst, element );
imshow( "Dilation Demo", dilation_dst );
......@@ -201,8 +201,8 @@ Explanation
else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
Mat element = getStructuringElement( erosion_type,
Size( 2*erosion_size + 1, 2*erosion_size+1 ),
Point( erosion_size, erosion_size ) );
Size( 2*erosion_size + 1, 2*erosion_size+1 ),
Point( erosion_size, erosion_size ) );
/// Apply the erosion operation
erode( src, erosion_dst, element );
imshow( "Erosion Demo", erosion_dst );
......@@ -216,17 +216,17 @@ Explanation
.. code-block:: cpp
Mat element = getStructuringElement( erosion_type,
Size( 2*erosion_size + 1, 2*erosion_size+1 ),
Point( erosion_size, erosion_size ) );
Mat element = getStructuringElement( erosion_type,
Size( 2*erosion_size + 1, 2*erosion_size+1 ),
Point( erosion_size, erosion_size ) );
We can choose any of three shapes for our kernel:
.. container:: enumeratevisibleitemswithsquare
+ Rectangular box: MORPH_RECT
+ Cross: MORPH_CROSS
+ Ellipse: MORPH_ELLIPSE
+ Rectangular box: MORPH_RECT
+ Cross: MORPH_CROSS
+ Ellipse: MORPH_ELLIPSE
Then, we just have to specify the size of our kernel and the *anchor point*. If not specified, it is assumed to be in the center.
......@@ -251,8 +251,8 @@ The code is below. As you can see, it is completely similar to the snippet of co
else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
Mat element = getStructuringElement( dilation_type,
Size( 2*dilation_size + 1, 2*dilation_size+1 ),
Point( dilation_size, dilation_size ) );
Size( 2*dilation_size + 1, 2*dilation_size+1 ),
Point( dilation_size, dilation_size ) );
/// Apply the dilation operation
dilate( src, dilation_dst, element );
imshow( "Dilation Demo", dilation_dst );
......
......@@ -159,35 +159,35 @@ Code
if( display_caption( "Homogeneous Blur" ) != 0 ) { return 0; }
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 )
{ blur( src, dst, Size( i, i ), Point(-1,-1) );
{ blur( src, dst, Size( i, i ), Point(-1,-1) );
if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } }
/// Applying Gaussian blur
if( display_caption( "Gaussian Blur" ) != 0 ) { return 0; }
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 )
{ GaussianBlur( src, dst, Size( i, i ), 0, 0 );
{ GaussianBlur( src, dst, Size( i, i ), 0, 0 );
if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } }
/// Applying Median blur
if( display_caption( "Median Blur" ) != 0 ) { return 0; }
if( display_caption( "Median Blur" ) != 0 ) { return 0; }
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 )
{ medianBlur ( src, dst, i );
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 )
{ medianBlur ( src, dst, i );
if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } }
/// Applying Bilateral Filter
if( display_caption( "Bilateral Blur" ) != 0 ) { return 0; }
/// Applying Bilateral Filter
if( display_caption( "Bilateral Blur" ) != 0 ) { return 0; }
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 )
{ bilateralFilter ( src, dst, i, i*2, i/2 );
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 )
{ bilateralFilter ( src, dst, i, i*2, i/2 );
if( display_dst( DELAY_BLUR ) != 0 ) { return 0; } }
/// Wait until user press a key
display_caption( "End: Press a key!" );
/// Wait until user press a key
display_caption( "End: Press a key!" );
waitKey(0);
return 0;
waitKey(0);
return 0;
}
int display_caption( char* caption )
......
......@@ -94,7 +94,7 @@ Code
* Loads an image
* Convert the original to HSV format and separate only *Hue* channel to be used for the Histogram (using the OpenCV function :mix_channels:`mixChannels <>`)
* Let the user to enter the number of bins to be used in the calculation of the histogram.
* Calculate the histogram (and update it if the bins change) and the backprojection of the same image.
* Calculate the histogram (and update it if the bins change) and the backprojection of the same image.
* Display the backprojection and the histogram in windows.
* **Downloadable code**:
......
......@@ -124,34 +124,34 @@ Code
for( int j = 0; j < src.rows; j++ )
{ for( int i = 0; i < src.cols; i++ )
{
{
switch( ind )
{
case 0:
if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )
{
case 0:
if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )
{
map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;
map_y.at<float>(j,i) = 2*( j - src.rows*0.25 ) + 0.5 ;
}
else
{ map_x.at<float>(j,i) = 0 ;
map_y.at<float>(j,i) = 0 ;
map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;
map_y.at<float>(j,i) = 2*( j - src.rows*0.25 ) + 0.5 ;
}
else
{ map_x.at<float>(j,i) = 0 ;
map_y.at<float>(j,i) = 0 ;
}
break;
case 1:
map_x.at<float>(j,i) = i ;
map_y.at<float>(j,i) = src.rows - j ;
break;
case 1:
map_x.at<float>(j,i) = i ;
map_y.at<float>(j,i) = src.rows - j ;
break;
case 2:
map_x.at<float>(j,i) = src.cols - i ;
map_y.at<float>(j,i) = j ;
break;
map_x.at<float>(j,i) = src.cols - i ;
map_y.at<float>(j,i) = j ;
break;
case 3:
map_x.at<float>(j,i) = src.cols - i ;
map_y.at<float>(j,i) = src.rows - j ;
break;
map_x.at<float>(j,i) = src.cols - i ;
map_y.at<float>(j,i) = src.rows - j ;
break;
} // end of switch
}
}
}
ind++;
}
......@@ -241,34 +241,34 @@ Explanation
for( int j = 0; j < src.rows; j++ )
{ for( int i = 0; i < src.cols; i++ )
{
{
switch( ind )
{
case 0:
if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )
{
case 0:
if( i > src.cols*0.25 && i < src.cols*0.75 && j > src.rows*0.25 && j < src.rows*0.75 )
{
map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;
map_y.at<float>(j,i) = 2*( j - src.rows*0.25 ) + 0.5 ;
}
else
{ map_x.at<float>(j,i) = 0 ;
map_y.at<float>(j,i) = 0 ;
map_x.at<float>(j,i) = 2*( i - src.cols*0.25 ) + 0.5 ;
map_y.at<float>(j,i) = 2*( j - src.rows*0.25 ) + 0.5 ;
}
else
{ map_x.at<float>(j,i) = 0 ;
map_y.at<float>(j,i) = 0 ;
}
break;
case 1:
map_x.at<float>(j,i) = i ;
map_y.at<float>(j,i) = src.rows - j ;
break;
case 1:
map_x.at<float>(j,i) = i ;
map_y.at<float>(j,i) = src.rows - j ;
break;
case 2:
map_x.at<float>(j,i) = src.cols - i ;
map_y.at<float>(j,i) = j ;
break;
map_x.at<float>(j,i) = src.cols - i ;
map_y.at<float>(j,i) = j ;
break;
case 3:
map_x.at<float>(j,i) = src.cols - i ;
map_y.at<float>(j,i) = src.rows - j ;
break;
map_x.at<float>(j,i) = src.cols - i ;
map_y.at<float>(j,i) = src.rows - j ;
break;
} // end of switch
}
}
}
ind++;
}
......
......@@ -154,13 +154,13 @@ This tutorial code's is shown lines below. You can also download it from `here <
/// Create Trackbar to select kernel type
createTrackbar( "Element:\n 0: Rect - 1: Cross - 2: Ellipse", window_name,
&morph_elem, max_elem,
Morphology_Operations );
&morph_elem, max_elem,
Morphology_Operations );
/// Create Trackbar to choose kernel size
createTrackbar( "Kernel size:\n 2n +1", window_name,
&morph_size, max_kernel_size,
Morphology_Operations );
&morph_size, max_kernel_size,
Morphology_Operations );
/// Default start
Morphology_Operations( 0, 0 );
......@@ -211,16 +211,16 @@ Explanation
.. code-block:: cpp
createTrackbar( "Element:\n 0: Rect - 1: Cross - 2: Ellipse", window_name,
&morph_elem, max_elem,
Morphology_Operations );
&morph_elem, max_elem,
Morphology_Operations );
* The final trackbar **"Kernel Size"** returns the size of the kernel to be used (**morph_size**)
.. code-block:: cpp
createTrackbar( "Kernel size:\n 2n +1", window_name,
&morph_size, max_kernel_size,
Morphology_Operations );
&morph_size, max_kernel_size,
Morphology_Operations );
* Every time we move any slider, the user's function **Morphology_Operations** will be called to effectuate a new morphology operation and it will update the output image based on the current trackbar values.
......
......@@ -129,7 +129,7 @@ This tutorial code's is shown lines below. You can also download it from `here <
c = waitKey(10);
if( (char)c == 27 )
{ break; }
{ break; }
if( (char)c == 'u' )
{ pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) );
printf( "** Zoom In: Image x 2 \n" );
......@@ -188,7 +188,7 @@ Explanation
c = waitKey(10);
if( (char)c == 27 )
{ break; }
{ break; }
if( (char)c == 'u' )
{ pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) );
printf( "** Zoom In: Image x 2 \n" );
......
......@@ -7,502 +7,502 @@ In this section you will learn about the image processing (manipulation) functio
.. include:: ../../definitions/tocDefinitions.rst
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|ImageProcessing_1| **Title:** :ref:`Smoothing`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Let's take a look at some basic linear filters!
===================== ==============================================
.. |ImageProcessing_1| image:: images/Smoothing_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|ImageProcessing_2| **Title:** :ref:`Morphology_1`
*Compatibility:* > OpenCV 2.0
Author: |Author_AnaH|
Let's *change* the shape of objects!
===================== ==============================================
.. |ImageProcessing_2| image:: images/Morphology_1_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
================= ==================================================
|Morphology_2| **Title:** :ref:`Morphology_2`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Here we investigate different morphology operators
================= ==================================================
.. |Morphology_2| image:: images/Morphology_2_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|Pyramids| **Title:** :ref:`Pyramids`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
What if I need a bigger/smaller image?
===================== ==============================================
.. |Pyramids| image:: images/Pyramids_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|Threshold| **Title:** :ref:`Basic_Threshold`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
After so much processing, it is time to decide which pixels stay!
===================== ==============================================
.. |Threshold| image:: images/Threshold_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
+
+
===================== ==============================================
|Filter_2D| **Title:** :ref:`filter_2d`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn to design our own filters by using OpenCV functions
===================== ==============================================
.. |Filter_2D| image:: images/imgtrans/Filter_2D_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
+
+
===================== ==============================================
|CopyMakeBorder| **Title:** :ref:`copyMakeBorderTutorial`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to pad our images!
===================== ==============================================
.. |CopyMakeBorder| image:: images/imgtrans/CopyMakeBorder_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|SobelDerivatives| **Title:** :ref:`sobel_derivatives`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to calculate gradients and use them to detect edges!
===================== ==============================================
.. |SobelDerivatives| image:: images/imgtrans/Sobel_Derivatives_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|LaplaceOperator| **Title:** :ref:`laplace_operator`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn about the *Laplace* operator and how to detect edges with it.
===================== ==============================================
.. |LaplaceOperator| image:: images/imgtrans/Laplace_Operator_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|CannyDetector| **Title:** :ref:`canny_detector`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn a sophisticated alternative to detect edges.
===================== ==============================================
.. |CannyDetector| image:: images/imgtrans/Canny_Detector_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|HoughLines| **Title:** :ref:`hough_lines`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to detect lines
===================== ==============================================
.. |HoughLines| image:: images/imgtrans/Hough_Lines_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|HoughCircle| **Title:** :ref:`hough_circle`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to detect circles
===================== ==============================================
.. |HoughCircle| image:: images/imgtrans/Hough_Circle_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|Remap| **Title:** :ref:`remap`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to manipulate pixels locations
===================== ==============================================
.. |Remap| image:: images/imgtrans/Remap_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|WarpAffine| **Title:** :ref:`warp_affine`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to rotate, translate and scale our images
===================== ==============================================
.. |WarpAffine| image:: images/imgtrans/Warp_Affine_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|HistEqualization| **Title:** :ref:`histogram_equalization`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to improve the contrast in our images
===================== ==============================================
.. |HistEqualization| image:: images/histograms/Histogram_Equalization_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|HistCalculation| **Title:** :ref:`histogram_calculation`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to create and generate histograms
===================== ==============================================
.. |HistCalculation| image:: images/histograms/Histogram_Calculation_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|HistComparison| **Title:** :ref:`histogram_comparison`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn to calculate metrics between histograms
===================== ==============================================
.. |HistComparison| image:: images/histograms/Histogram_Comparison_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|BackProjection| **Title:** :ref:`back_projection`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to use histograms to find similar objects in images
===================== ==============================================
.. |BackProjection| image:: images/histograms/Back_Projection_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|TemplateMatching| **Title:** :ref:`template_matching`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to match templates in an image
===================== ==============================================
.. |TemplateMatching| image:: images/histograms/Template_Matching_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|FindContours| **Title:** :ref:`find_contours`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to find contours of objects in our image
===================== ==============================================
.. |FindContours| image:: images/shapedescriptors/Find_Contours_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|Hull| **Title:** :ref:`hull`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to get hull contours and draw them!
===================== ==============================================
.. |Hull| image:: images/shapedescriptors/Hull_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|BRC| **Title:** :ref:`bounding_rects_circles`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to obtain bounding boxes and circles for our contours.
===================== ==============================================
.. |BRC| image:: images/shapedescriptors/Bounding_Rects_Circles_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|BRE| **Title:** :ref:`bounding_rotated_ellipses`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to obtain rotated bounding boxes and ellipses for our contours.
===================== ==============================================
.. |BRE| image:: images/shapedescriptors/Bounding_Rotated_Ellipses_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|MU| **Title:** :ref:`moments`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn to calculate the moments of an image
===================== ==============================================
.. |MU| image:: images/shapedescriptors/Moments_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|PPT| **Title:** :ref:`point_polygon_test`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Where we learn how to calculate distances from the image to contours
===================== ==============================================
.. |PPT| image:: images/shapedescriptors/Point_Polygon_Test_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
......
......@@ -174,12 +174,12 @@ The tutorial code's is shown lines below. You can also download it from `here <h
/// Create Trackbar to choose type of Threshold
createTrackbar( trackbar_type,
window_name, &threshold_type,
max_type, Threshold_Demo );
window_name, &threshold_type,
max_type, Threshold_Demo );
createTrackbar( trackbar_value,
window_name, &threshold_value,
max_value, Threshold_Demo );
window_name, &threshold_value,
max_value, Threshold_Demo );
/// Call the function to initialize
Threshold_Demo( 0, 0 );
......@@ -190,7 +190,7 @@ The tutorial code's is shown lines below. You can also download it from `here <h
int c;
c = waitKey( 20 );
if( (char)c == 27 )
{ break; }
{ break; }
}
}
......@@ -245,12 +245,12 @@ Explanation
.. code-block:: cpp
createTrackbar( trackbar_type,
window_name, &threshold_type,
max_type, Threshold_Demo );
window_name, &threshold_type,
max_type, Threshold_Demo );
createTrackbar( trackbar_value,
window_name, &threshold_value,
max_value, Threshold_Demo );
window_name, &threshold_value,
max_value, Threshold_Demo );
* Wait until the user enters the threshold value, the type of thresholding (or until the program exits)
......
......@@ -20,7 +20,7 @@ In MacOS it can be done using the following command in Terminal:
cd ~/<my_working _directory>
git clone https://github.com/Itseez/opencv.git
Building OpenCV from Source, using CMake and Command Line
=========================================================
......@@ -28,10 +28,10 @@ Building OpenCV from Source, using CMake and Command Line
#. Make symbolic link for Xcode to let OpenCV build scripts find the compiler, header files etc.
.. code-block:: bash
cd /
sudo ln -s /Applications/Xcode.app/Contents/Developer Developer
#. Build OpenCV framework:
.. code-block:: bash
......
......@@ -11,7 +11,7 @@ Prerequisites
1. Having installed `Eclipse <http://www.eclipse.org/>`_ in your workstation (only the CDT plugin for C/C++ is needed). You can follow the following steps:
* Go to the Eclipse site
* Go to the Eclipse site
* Download `Eclipse IDE for C/C++ Developers <http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/heliossr2>`_ . Choose the link according to your workstation.
......@@ -20,7 +20,7 @@ Prerequisites
Making a project
=================
1. Start Eclipse. Just run the executable that comes in the folder.
1. Start Eclipse. Just run the executable that comes in the folder.
#. Go to **File -> New -> C/C++ Project**
......@@ -28,13 +28,13 @@ Making a project
:alt: Eclipse Tutorial Screenshot 0
:align: center
#. Choose a name for your project (i.e. DisplayImage). An **Empty Project** should be okay for this example.
#. Choose a name for your project (i.e. DisplayImage). An **Empty Project** should be okay for this example.
.. image:: images/a1.png
:alt: Eclipse Tutorial Screenshot 1
:align: center
#. Leave everything else by default. Press **Finish**.
#. Leave everything else by default. Press **Finish**.
#. Your project (in this case DisplayImage) should appear in the **Project Navigator** (usually at the left side of your window).
......@@ -45,7 +45,7 @@ Making a project
#. Now, let's add a source file using OpenCV:
* Right click on **DisplayImage** (in the Navigator). **New -> Folder** .
* Right click on **DisplayImage** (in the Navigator). **New -> Folder** .
.. image:: images/a4.png
:alt: Eclipse Tutorial Screenshot 4
......@@ -76,9 +76,9 @@ Making a project
image = imread( argv[1], 1 );
if( argc != 2 || !image.data )
{
{
printf( "No image data \n" );
return -1;
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
......@@ -102,7 +102,7 @@ Making a project
:align: center
.. note::
If you do not know where your opencv files are, open the **Terminal** and type:
If you do not know where your opencv files are, open the **Terminal** and type:
.. code-block:: bash
......@@ -112,56 +112,56 @@ Making a project
.. code-block:: bash
-I/usr/local/include/opencv -I/usr/local/include
-I/usr/local/include/opencv -I/usr/local/include
b. Now go to **GCC C++ Linker**,there you have to fill two spaces:
First in **Library search path (-L)** you have to write the path to where the opencv libraries reside, in my case the path is:
::
/usr/local/lib
Then in **Libraries(-l)** add the OpenCV libraries that you may need. Usually just the 3 first on the list below are enough (for simple applications) . In my case, I am putting all of them since I plan to use the whole bunch:
opencv_core
opencv_imgproc
opencv_core
opencv_imgproc
opencv_highgui
opencv_ml
opencv_video
opencv_ml
opencv_video
opencv_features2d
opencv_calib3d
opencv_objdetect
opencv_calib3d
opencv_objdetect
opencv_contrib
opencv_legacy
opencv_legacy
opencv_flann
.. image:: images/a10.png
:alt: Eclipse Tutorial Screenshot 10
:align: center
:align: center
If you don't know where your libraries are (or you are just psychotic and want to make sure the path is fine), type in **Terminal**:
.. code-block:: bash
pkg-config --libs opencv
My output (in case you want to check) was:
.. code-block:: bash
-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
-L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
Now you are done. Click **OK**
* Your project should be ready to be built. For this, go to **Project->Build all**
* Your project should be ready to be built. For this, go to **Project->Build all**
In the Console you should get something like
In the Console you should get something like
.. image:: images/a12.png
:alt: Eclipse Tutorial Screenshot 12
:align: center
:align: center
If you check in your folder, there should be an executable there.
......@@ -179,21 +179,21 @@ So, now we have an executable ready to run. If we were to use the Terminal, we w
Assuming that the image to use as the argument would be located in <DisplayImage_directory>/images/HappyLittleFish.png. We can still do this, but let's do it from Eclipse:
#. Go to **Run->Run Configurations**
#. Go to **Run->Run Configurations**
#. Under C/C++ Application you will see the name of your executable + Debug (if not, click over C/C++ Application a couple of times). Select the name (in this case **DisplayImage Debug**).
#. Under C/C++ Application you will see the name of your executable + Debug (if not, click over C/C++ Application a couple of times). Select the name (in this case **DisplayImage Debug**).
#. Now, in the right side of the window, choose the **Arguments** Tab. Write the path of the image file we want to open (path relative to the workspace/DisplayImage folder). Let's use **HappyLittleFish.png**:
.. image:: images/a14.png
:alt: Eclipse Tutorial Screenshot 14
:align: center
:align: center
#. Click on the **Apply** button and then in Run. An OpenCV window should pop up with the fish image (or whatever you used).
.. image:: images/a15.jpg
:alt: Eclipse Tutorial Screenshot 15
:align: center
:align: center
#. Congratulations! You are ready to have fun with OpenCV using Eclipse.
......@@ -238,7 +238,7 @@ Say you have or create a new file, *helloworld.cpp* in a directory called *foo*:
ADD_EXECUTABLE( helloworld helloworld.cxx )
TARGET_LINK_LIBRARIES( helloworld ${OpenCV_LIBS} )
#. Run: ``cmake-gui ..`` and make sure you fill in where opencv was built.
#. Run: ``cmake-gui ..`` and make sure you fill in where opencv was built.
#. Then click ``configure`` and then ``generate``. If it's OK, **quit cmake-gui**
......
......@@ -11,7 +11,7 @@ Using OpenCV with gcc and CMake
* The easiest way of using OpenCV in your code is to use `CMake <http://www.cmake.org/>`_. A few advantages (taken from the Wiki):
#. No need to change anything when porting between Linux and Windows
#. Can easily be combined with other tools by CMake( i.e. Qt, ITK and VTK )
#. Can easily be combined with other tools by CMake( i.e. Qt, ITK and VTK )
* If you are not familiar with CMake, checkout the `tutorial <http://www.cmake.org/cmake/help/cmake_tutorial.html>`_ on its website.
......@@ -21,7 +21,7 @@ Steps
Create a program using OpenCV
-------------------------------
Let's use a simple program such as DisplayImage.cpp shown below.
Let's use a simple program such as DisplayImage.cpp shown below.
.. code-block:: cpp
......@@ -36,9 +36,9 @@ Let's use a simple program such as DisplayImage.cpp shown below.
image = imread( argv[1], 1 );
if( argc != 2 || !image.data )
{
{
printf( "No image data \n" );
return -1;
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
......
......@@ -11,8 +11,8 @@ Required Packages
.. code-block:: bash
sudo apt-get install build-essential
sudo apt-get install build-essential
* CMake 2.6 or higher;
* Git;
* GTK+2.x or higher, including headers (libgtk2.0-dev);
......@@ -48,7 +48,7 @@ In Linux it can be achieved with the following command in Terminal:
cd ~/<my_working _directory>
git clone https://github.com/Itseez/opencv.git
Building OpenCV from Source Using CMake, Using the Command Line
===============================================================
......@@ -58,26 +58,26 @@ Building OpenCV from Source Using CMake, Using the Command Line
#. Enter the <cmake_binary_dir> and type
.. code-block:: bash
cmake [<some optional parameters>] <path to the OpenCV source directory>
For example
.. code-block:: bash
cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
#. Enter the created temporary directory (<cmake_binary_dir>) and proceed with:
.. code-block:: bash
make
sudo make install
.. note::
If the size of the created library is a critical issue (like in case of an Android build) you can use the ``install/strip`` command to get the smallest size as possible. The *stripped* version appears to be twice as small. However, we do not recommend using this unless those extra megabytes do really matter.
......@@ -5,8 +5,8 @@ Load, Modify, and Save an Image
.. note::
We assume that by now you know how to load an image using :imread:`imread <>` and to display it in a window (using :imshow:`imshow <>`). Read the :ref:`Display_Image` tutorial otherwise.
We assume that by now you know how to load an image using :imread:`imread <>` and to display it in a window (using :imshow:`imshow <>`). Read the :ref:`Display_Image` tutorial otherwise.
Goals
======
......@@ -35,9 +35,9 @@ Here it is:
{
char* imageName = argv[1];
Mat image;
Mat image;
image = imread( imageName, 1 );
if( argc != 2 || !image.data )
{
printf( " No image data \n " );
......@@ -53,7 +53,7 @@ Here it is:
namedWindow( "Gray image", CV_WINDOW_AUTOSIZE );
imshow( imageName, image );
imshow( "Gray image", gray_image );
imshow( "Gray image", gray_image );
waitKey(0);
......@@ -67,18 +67,18 @@ Explanation
* Creating a Mat object to store the image information
* Load an image using :imread:`imread <>`, located in the path given by *imageName*. Fort this example, assume you are loading a RGB image.
#. Now we are going to convert our image from RGB to Grayscale format. OpenCV has a really nice function to do this kind of transformations:
#. Now we are going to convert our image from RGB to Grayscale format. OpenCV has a really nice function to do this kind of transformations:
.. code-block:: cpp
cvtColor( image, gray_image, CV_RGB2GRAY );
As you can see, :cvt_color:`cvtColor <>` takes as arguments:
.. container:: enumeratevisibleitemswithsquare
* a source image (*image*)
* a source image (*image*)
* a destination image (*gray_image*), in which we will save the converted image.
* an additional parameter that indicates what kind of transformation will be performed. In this case we use **CV_RGB2GRAY** (self-explanatory).
......@@ -86,7 +86,7 @@ Explanation
.. code-block:: cpp
imwrite( "../../images/Gray_Image.jpg", gray_image );
imwrite( "../../images/Gray_Image.jpg", gray_image );
Which will save our *gray_image* as *Gray_Image.jpg* in the folder *images* located two levels up of my current location.
......
......@@ -130,7 +130,7 @@ Building the library
#. Install |TortoiseGit|_. Choose the 32 or 64 bit version according to the type of OS you work in. While installing, locate your msysgit (if it doesn't do that automatically). Follow the wizard -- the default options are OK for the most part.
#. Choose a directory in your file system, where you will download the OpenCV libraries to. I recommend creating a new one that has short path and no special charachters in it, for example :file:`D:/OpenCV`. For this tutorial I'll suggest you do so. If you use your own path and know, what you're doing -- it's OK.
#. Choose a directory in your file system, where you will download the OpenCV libraries to. I recommend creating a new one that has short path and no special charachters in it, for example :file:`D:/OpenCV`. For this tutorial I'll suggest you do so. If you use your own path and know, what you're doing -- it's OK.
a) Clone the repository to the selected directory. After clicking *Clone* button, a window will appear where you can select from what repository you want to download source files (https://github.com/Itseez/opencv.git) and to what directory (:file:`D:/OpenCV`).
......
......@@ -10,16 +10,16 @@ I start out from the assumption that you have read and completed with success th
:alt: You should have a folder looking like this.
:align: center
The OpenCV libraries, distributed by us, on the Microsoft Windows operating system are in a **D**\ ynamic **L**\ inked **L**\ ibraries (*DLL*). These have the advantage that all the content of the library are loaded only at runtime, on demand, and that countless programs may use the same library file. This means that if you have ten applications using the OpenCV library, no need to have around a version for each one of them. Of course you need to have the *dll* of the OpenCV on all systems where you want to run your application.
The OpenCV libraries, distributed by us, on the Microsoft Windows operating system are in a **D**\ ynamic **L**\ inked **L**\ ibraries (*DLL*). These have the advantage that all the content of the library are loaded only at runtime, on demand, and that countless programs may use the same library file. This means that if you have ten applications using the OpenCV library, no need to have around a version for each one of them. Of course you need to have the *dll* of the OpenCV on all systems where you want to run your application.
Another approach is to use static libraries that have *lib* extensions. You may build these by using our source files as described in the :ref:`Windows_Installation` tutorial. When you use this the library will be built-in inside your *exe* file. So there is no chance that the user deletes them, for some reason. As a drawback your application will be larger one and as, it will take more time to load it during its startup.
To build an application with OpenCV you need to do two things:
To build an application with OpenCV you need to do two things:
.. container:: enumeratevisibleitemswithsquare
+ *Tell* to the compiler how the OpenCV library *looks*. You do this by *showing* it the header files.
+ *Tell* to the linker from where to get the functions or data structures of OpenCV, when they are needed.
+ *Tell* to the compiler how the OpenCV library *looks*. You do this by *showing* it the header files.
+ *Tell* to the linker from where to get the functions or data structures of OpenCV, when they are needed.
If you use the *lib* system you must set the path where the library files are and specify in which one of them to look. During the build the linker will look into these libraries and add the definitions and implementation of all *used* functions and data structures to the executable file.
......@@ -27,7 +27,7 @@ To build an application with OpenCV you need to do two things:
To pass on all this information to the Visual Studio IDE you can either do it globally (so all your future projects will get these information) or locally (so only for you current project). The advantage of the global one is that you only need to do it once; however, it may be undesirable to clump all your projects all the time with all these information. In case of the global one how you do it depends on the Microsoft Visual Studio you use. There is a **2008 and previous versions** and a **2010 way** of doing it. Inside the global section of this tutorial I'll show what the main differences are.
The base item of a project in Visual Studio is a solution. A solution may contain multiple projects. Projects are the building blocks of an application. Every project will realize something and you will have a main project in which you can put together this project puzzle. In case of the many simple applications (like many of the tutorials will be) you do not need to break down the application into modules. In these cases your main project will be the only existing one. Now go create a new solution inside Visual studio by going through the :menuselection:`File --> New --> Project` menu selection. Choose *Win32 Console Application* as type. Enter its name and select the path where to create it. Then in the upcoming dialog make sure you create an empty project.
The base item of a project in Visual Studio is a solution. A solution may contain multiple projects. Projects are the building blocks of an application. Every project will realize something and you will have a main project in which you can put together this project puzzle. In case of the many simple applications (like many of the tutorials will be) you do not need to break down the application into modules. In these cases your main project will be the only existing one. Now go create a new solution inside Visual studio by going through the :menuselection:`File --> New --> Project` menu selection. Choose *Win32 Console Application* as type. Enter its name and select the path where to create it. Then in the upcoming dialog make sure you create an empty project.
.. image:: images/NewProjectVisualStudio.jpg
:alt: Which options to select
......@@ -36,7 +36,7 @@ The base item of a project in Visual Studio is a solution. A solution may contai
The *local* method
==================
Every project is built separately from the others. Due to this every project has its own rule package. Inside this rule packages are stored all the information the *IDE* needs to know to build your project. For any application there are at least two build modes: a *Release* and a *Debug* one. The *Debug* has many features that exist so you can find and resolve easier bugs inside your application. In contrast the *Release* is an optimized version, where the goal is to make the application run as fast as possible or to be as small as possible. You may figure that these modes also require different rules to use during build. Therefore, there exist different rule packages for each of your build modes. These rule packages are called inside the IDE as *project properties* and you can view and modify them by using the *Property Manger*. You can bring up this with :menuselection:`View --> Property Pages`. Expand it and you can see the existing rule packages (called *Proporty Sheets*).
Every project is built separately from the others. Due to this every project has its own rule package. Inside this rule packages are stored all the information the *IDE* needs to know to build your project. For any application there are at least two build modes: a *Release* and a *Debug* one. The *Debug* has many features that exist so you can find and resolve easier bugs inside your application. In contrast the *Release* is an optimized version, where the goal is to make the application run as fast as possible or to be as small as possible. You may figure that these modes also require different rules to use during build. Therefore, there exist different rule packages for each of your build modes. These rule packages are called inside the IDE as *project properties* and you can view and modify them by using the *Property Manger*. You can bring up this with :menuselection:`View --> Property Pages`. Expand it and you can see the existing rule packages (called *Proporty Sheets*).
.. image:: images/PropertyPageExample.jpg
:alt: An example of Property Sheet
......@@ -55,10 +55,10 @@ Use for example the *OpenCV_Debug* name. Then by selecting the sheet :menuselect
$(OPENCV_DIR)\include
.. image:: images/PropertySheetOpenCVInclude.jpg
:alt: Add the include dir like this.
:alt: Add the include dir like this.
:align: center
When adding third party libraries settings it is generally a good idea to use the power behind the environment variables. The full location of the OpenCV library may change on each system. Moreover, you may even end up yourself with moving the install directory for some reason. If you would give explicit paths inside your property sheet your project will end up not working when you pass it further to someone else who has a different OpenCV install path. Moreover, fixing this would require to manually modifying every explicit path. A more elegant solution is to use the environment variables. Anything that you put inside a parenthesis started with a dollar sign will be replaced at runtime with the current environment variables value. Here comes in play the environment variable setting we already made in our :ref:`previous tutorial <WindowsSetPathAndEnviromentVariable>`.
When adding third party libraries settings it is generally a good idea to use the power behind the environment variables. The full location of the OpenCV library may change on each system. Moreover, you may even end up yourself with moving the install directory for some reason. If you would give explicit paths inside your property sheet your project will end up not working when you pass it further to someone else who has a different OpenCV install path. Moreover, fixing this would require to manually modifying every explicit path. A more elegant solution is to use the environment variables. Anything that you put inside a parenthesis started with a dollar sign will be replaced at runtime with the current environment variables value. Here comes in play the environment variable setting we already made in our :ref:`previous tutorial <WindowsSetPathAndEnviromentVariable>`.
Next go to the :menuselection:`Linker --> General` and under the *"Additional Library Directories"* add the libs directory:
......@@ -67,7 +67,7 @@ Next go to the :menuselection:`Linker --> General` and under the *"Additional Li
$(OPENCV_DIR)\libs
.. image:: images/PropertySheetOpenCVLib.jpg
:alt: Add the library folder like this.
:alt: Add the library folder like this.
:align: center
Then you need to specify the libraries in which the linker should look into. To do this go to the :menuselection:`Linker --> Input` and under the *"Additional Dependencies"* entry add the name of all modules which you want to use:
......@@ -77,7 +77,7 @@ Then you need to specify the libraries in which the linker should look into. To
:align: center
.. image:: images/PropertySheetOpenCVLibrariesDebug.jpg
:alt: Like this.
:alt: Like this.
:align: center
The names of the libraries are as follow:
......@@ -105,33 +105,33 @@ A full list, for the currently latest trunk version would contain:
The letter *d* at the end just indicates that these are the libraries required for the debug. Now click ok to save and do the same with a new property inside the Release rule section. Make sure to omit the *d* letters from the library names and to save the property sheets with the save icon above them.
.. image:: images/PropertySheetOpenCVLibrariesRelease.jpg
:alt: And the release ones.
:alt: And the release ones.
:align: center
You can find your property sheets inside your projects directory. At this point it is a wise decision to back them up into some special directory, to always have them at hand in the future, whenever you create an OpenCV project. Note that for Visual Studio 2010 the file extension is *props*, while for 2008 this is *vsprops*.
You can find your property sheets inside your projects directory. At this point it is a wise decision to back them up into some special directory, to always have them at hand in the future, whenever you create an OpenCV project. Note that for Visual Studio 2010 the file extension is *props*, while for 2008 this is *vsprops*.
.. image:: images/PropertySheetInsideFolder.jpg
:alt: And the release ones.
:alt: And the release ones.
:align: center
Next time when you make a new OpenCV project just use the "Add Existing Property Sheet..." menu entry inside the Property Manager to easily add the OpenCV build rules.
Next time when you make a new OpenCV project just use the "Add Existing Property Sheet..." menu entry inside the Property Manager to easily add the OpenCV build rules.
.. image:: images/PropertyPageAddExisting.jpg
:alt: Use this option.
:alt: Use this option.
:align: center
The *global* method
===================
In case you find to troublesome to add the property pages to each and every one of your projects you can also add this rules to a *"global property page"*. However, this applies only to the additional include and library directories. The name of the libraries to use you still need to specify manually by using for instance: a Property page.
In case you find to troublesome to add the property pages to each and every one of your projects you can also add this rules to a *"global property page"*. However, this applies only to the additional include and library directories. The name of the libraries to use you still need to specify manually by using for instance: a Property page.
In Visual Studio 2008 you can find this under the: :menuselection:`Tools --> Options --> Projects and Solutions --> VC++ Directories`.
In Visual Studio 2008 you can find this under the: :menuselection:`Tools --> Options --> Projects and Solutions --> VC++ Directories`.
.. image:: images/VCDirectories2008.jpg
:alt: VC++ Directories in VS 2008.
:align: center
In Visual Studio 2010 this has been moved to a global property sheet which is automatically added to every project you create:
In Visual Studio 2010 this has been moved to a global property sheet which is automatically added to every project you create:
.. image:: images/VCDirectories2010.jpg
:alt: VC++ Directories in VS 2010.
......@@ -153,10 +153,10 @@ You can start a Visual Studio build from two places. Either inside from the *IDE
.. |voila| unicode:: voil U+00E1
This is important to remember when you code inside the code open and save commands. You're resources will be saved ( and queried for at opening!!!) relatively to your working directory. This is unless you give a full, explicit path as parameter for the I/O functions. In the code above we open :download:`this OpenCV logo<../../../../samples/cpp/tutorial_code/images/opencv-logo.png>`. Before starting up the application make sure you place the image file in your current working directory. Modify the image file name inside the code to try it out on other images too. Run it and |voila|:
This is important to remember when you code inside the code open and save commands. You're resources will be saved ( and queried for at opening!!!) relatively to your working directory. This is unless you give a full, explicit path as parameter for the I/O functions. In the code above we open :download:`this OpenCV logo<../../../../samples/cpp/tutorial_code/images/opencv-logo.png>`. Before starting up the application make sure you place the image file in your current working directory. Modify the image file name inside the code to try it out on other images too. Run it and |voila|:
.. image:: images/SuccessVisualStudioWindows.jpg
:alt: You should have this.
:alt: You should have this.
:align: center
Command line arguments with Visual Studio
......@@ -167,11 +167,11 @@ Throughout some of our future tutorials you'll see that the programs main input
.. code-block:: bash
:linenos:
D:
D:
CD OpenCV\MySolutionName\Release
MySolutionName.exe exampleImage.jpg
Here I first changed my drive (if your project isn't on the OS local drive), navigated to my project and start it with an example image argument. While under Linux system it is common to fiddle around with the console window on the Microsoft Windows many people come to use it almost never. Besides, adding the same argument again and again while you are testing your application is, somewhat, a cumbersome task. Luckily, in the Visual Studio there is a menu to automate all this:
Here I first changed my drive (if your project isn't on the OS local drive), navigated to my project and start it with an example image argument. While under Linux system it is common to fiddle around with the console window on the Microsoft Windows many people come to use it almost never. Besides, adding the same argument again and again while you are testing your application is, somewhat, a cumbersome task. Luckily, in the Visual Studio there is a menu to automate all this:
.. image:: images/VisualStudioCommandLineArguments.jpg
:alt: Visual Studio Command Line Arguments
......
......@@ -19,7 +19,7 @@ Follow this step by step guide to link OpenCV to iOS.
1. Create a new XCode project.
2. Now we need to link *opencv2.framework* with Xcode. Select the project Navigator in the left hand panel and click on project name.
2. Now we need to link *opencv2.framework* with Xcode. Select the project Navigator in the left hand panel and click on project name.
3. Under the TARGETS click on Build Phases. Expand Link Binary With Libraries option.
......@@ -29,10 +29,10 @@ Follow this step by step guide to link OpenCV to iOS.
.. image:: images/linking_opencv_ios.png
:alt: OpenCV iOS in Xcode
:align: center
:align: center
*Hello OpenCV iOS Application*
===============================
===============================
Now we will learn how to write a simple Hello World Application in Xcode using OpenCV.
......@@ -43,13 +43,13 @@ Now we will learn how to write a simple Hello World Application in Xcode using O
.. code-block:: cpp
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
.. image:: images/header_directive.png
:alt: header
:align: center
:align: center
.. container:: enumeratevisibleitemswithsquare
......@@ -61,7 +61,7 @@ Now we will learn how to write a simple Hello World Application in Xcode using O
.. image:: images/view_did_load.png
:alt: view did load
:align: center
:align: center
.. container:: enumeratevisibleitemswithsquare
......@@ -73,4 +73,4 @@ Now we will learn how to write a simple Hello World Application in Xcode using O
.. image:: images/output.png
:alt: output
:align: center
......@@ -21,9 +21,9 @@ In *OpenCV* all the image processing operations are done on *Mat*. iOS uses UIIm
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
CGFloat cols = image.size.width;
CGFloat rows = image.size.height;
cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels
CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to data
cols, // Width of bitmap
rows, // Height of bitmap
......@@ -32,11 +32,11 @@ In *OpenCV* all the image processing operations are done on *Mat*. iOS uses UIIm
colorSpace, // Colorspace
kCGImageAlphaNoneSkipLast |
kCGBitmapByteOrderDefault); // Bitmap info flags
CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), image.CGImage);
CGContextRelease(contextRef);
CGColorSpaceRelease(colorSpace);
return cvMat;
}
......@@ -47,9 +47,9 @@ In *OpenCV* all the image processing operations are done on *Mat*. iOS uses UIIm
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
CGFloat cols = image.size.width;
CGFloat rows = image.size.height;
cv::Mat cvMat(rows, cols, CV_8UC1); // 8 bits per component, 1 channels
CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to data
cols, // Width of bitmap
rows, // Height of bitmap
......@@ -58,11 +58,11 @@ In *OpenCV* all the image processing operations are done on *Mat*. iOS uses UIIm
colorSpace, // Colorspace
kCGImageAlphaNoneSkipLast |
kCGBitmapByteOrderDefault); // Bitmap info flags
CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), image.CGImage);
CGContextRelease(contextRef);
CGColorSpaceRelease(colorSpace);
return cvMat;
}
......@@ -81,15 +81,15 @@ After the processing we need to convert it back to UIImage.
{
NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize()*cvMat.total()];
CGColorSpaceRef colorSpace;
if (cvMat.elemSize() == 1) {
colorSpace = CGColorSpaceCreateDeviceGray();
} else {
colorSpace = CGColorSpaceCreateDeviceRGB();
}
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
// Creating CGImage from cv::Mat
CGImageRef imageRef = CGImageCreate(cvMat.cols, //width
cvMat.rows, //height
......@@ -103,15 +103,15 @@ After the processing we need to convert it back to UIImage.
false, //should interpolate
kCGRenderingIntentDefault //intent
);
// Getting UIImage from CGImage
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace);
return finalImage;
return finalImage;
}
*Output*
......@@ -119,9 +119,9 @@ After the processing we need to convert it back to UIImage.
.. image:: images/output.jpg
:alt: header
:align: center
:align: center
Check out an instance of running code with more Image Effects on `YouTube <http://www.youtube.com/watch?v=Ko3K_xdhJ1I>`_ .
Check out an instance of running code with more Image Effects on `YouTube <http://www.youtube.com/watch?v=Ko3K_xdhJ1I>`_ .
.. raw:: html
......
......@@ -69,7 +69,7 @@
.. toctree::
:hidden:
../hello/hello
../image_manipulation/image_manipulation
../video_processing/video_processing
......@@ -17,35 +17,35 @@ Including OpenCV library in your iOS project
The OpenCV library comes as a so-called framework, which you can directly drag-and-drop into your XCode project. Download the latest binary from <http://sourceforge.net/projects/opencvlibrary/files/opencv-ios/>. Alternatively follow this guide :ref:`iOS-Installation` to compile the framework manually. Once you have the framework, just drag-and-drop into XCode:
.. image:: images/xcode_hello_ios_framework_drag_and_drop.png
.. image:: images/xcode_hello_ios_framework_drag_and_drop.png
Also you have to locate the prefix header that is used for all header files in the project. The file is typically located at "ProjectName/Supporting Files/ProjectName-Prefix.pch". There, you have add an include statement to import the opencv library. However, make sure you include opencv before you include UIKit and Foundation, because else you will get some weird compile errors that some macros like min and max are defined multiple times. For example the prefix header could look like the following:
.. code-block:: objc
:linenos:
//
// Prefix header for all source files of the 'VideoFilters' target in the 'VideoFilters' project
//
#import <Availability.h>
#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."
#endif
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
:linenos:
//
// Prefix header for all source files of the 'VideoFilters' target in the 'VideoFilters' project
//
#import <Availability.h>
#ifndef __IPHONE_4_0
#warning "This project uses features only available in iOS SDK 4.0 and later."
#endif
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
Example video frame processing project
--------------------------------------
User Interface
......@@ -53,63 +53,63 @@ User Interface
First, we create a simple iOS project, for example Single View Application. Then, we create and add an UIImageView and UIButton to start the camera and display the video frames. The storyboard could look like that:
.. image:: images/xcode_hello_ios_viewcontroller_layout.png
.. image:: images/xcode_hello_ios_viewcontroller_layout.png
Make sure to add and connect the IBOutlets and IBActions to the corresponding ViewController:
.. code-block:: objc
:linenos:
@interface ViewController : UIViewController
{
IBOutlet UIImageView* imageView;
IBOutlet UIButton* button;
}
- (IBAction)actionStart:(id)sender;
@end
:linenos:
@interface ViewController : UIViewController
{
IBOutlet UIImageView* imageView;
IBOutlet UIButton* button;
}
- (IBAction)actionStart:(id)sender;
@end
Adding the Camera
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We add a camera controller to the view controller and initialize it when the view has loaded:
.. code-block:: objc
:linenos:
#import <opencv2/highgui/cap_ios.h>
using namespace cv;
@interface ViewController : UIViewController
{
...
CvVideoCamera* videoCamera;
}
...
@property (nonatomic, retain) CvVideoCamera* videoCamera;
@end
:linenos:
#import <opencv2/highgui/cap_ios.h>
using namespace cv;
@interface ViewController : UIViewController
{
...
CvVideoCamera* videoCamera;
}
...
@property (nonatomic, retain) CvVideoCamera* videoCamera;
@end
.. code-block:: objc
:linenos:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
self.videoCamera.grayscale = NO;
}
:linenos:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
self.videoCamera.grayscale = NO;
}
In this case, we initialize the camera and provide the imageView as a target for rendering each frame. CvVideoCamera is basically a wrapper around AVFoundation, so we provie as properties some of the AVFoundation camera options. For example we want to use the front camera, set the video size to 352x288 and a video orientation (the video camera normally outputs in landscape mode, which results in transposed data when you design a portrait application).
The property defaultFPS sets the FPS of the camera. If the processing is less fast than the desired FPS, frames are automatically dropped.
......@@ -143,7 +143,7 @@ Additionally, we have to manually add framework dependencies of the opencv frame
* Foundation
.. image:: images/xcode_hello_ios_frameworks_add_dependencies.png
.. image:: images/xcode_hello_ios_frameworks_add_dependencies.png
Processing frames
......@@ -152,35 +152,35 @@ Processing frames
We follow the delegation pattern, which is very common in iOS, to provide access to each camera frame. Basically, the View Controller has to implement the CvVideoCameraDelegate protocol and has to be set as delegate to the video camera:
.. code-block:: objc
:linenos:
@interface ViewController : UIViewController<CvVideoCameraDelegate>
:linenos:
@interface ViewController : UIViewController<CvVideoCameraDelegate>
.. code-block:: objc
:linenos:
- (void)viewDidLoad
{
...
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.delegate = self;
...
}
:linenos:
- (void)viewDidLoad
{
...
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.delegate = self;
...
}
.. code-block:: objc
:linenos:
:linenos:
#pragma mark - Protocol CvVideoCameraDelegate
#pragma mark - Protocol CvVideoCameraDelegate
#ifdef __cplusplus
- (void)processImage:(Mat&)image;
{
// Do some OpenCV stuff with the image
}
#endif
#ifdef __cplusplus
- (void)processImage:(Mat&)image;
{
// Do some OpenCV stuff with the image
}
#endif
Note that we are using C++ here (cv::Mat).
Important: You have to rename the view controller's extension .m into .mm, so that the compiler compiles it under the assumption of Objective-C++ (Objective-C and C++ mixed). Then, __cplusplus is defined when the compiler is processing the file for C++ code. Therefore, we put our code within a block where __cplusplus is defined.
......@@ -193,18 +193,18 @@ From here you can start processing video frames. For example the following snipp
.. code-block:: objc
:linenos:
- (void)processImage:(Mat&)image;
{
// Do some OpenCV stuff with the image
Mat image_copy;
cvtColor(image, image_copy, CV_BGRA2BGR);
// invert image
bitwise_not(image_copy, image_copy);
cvtColor(image_copy, image, CV_BGR2BGRA);
}
:linenos:
- (void)processImage:(Mat&)image;
{
// Do some OpenCV stuff with the image
Mat image_copy;
cvtColor(image, image_copy, CV_BGRA2BGR);
// invert image
bitwise_not(image_copy, image_copy);
cvtColor(image_copy, image, CV_BGR2BGRA);
}
Start!
......@@ -213,14 +213,14 @@ Start!
Finally, we have to tell the camera to actually start/stop working. The following code will start the camera when you press the button, assuming you connected the UI properly:
.. code-block:: objc
:linenos:
#pragma mark - UI Actions
- (IBAction)actionStart:(id)sender;
{
[self.videoCamera start];
}
:linenos:
#pragma mark - UI Actions
- (IBAction)actionStart:(id)sender;
{
[self.videoCamera start];
}
......
......@@ -10,7 +10,7 @@ In this tutorial you will learn how to:
.. container:: enumeratevisibleitemswithsquare
+ Use the OpenCV functions :svms:`CvSVM::train <cvsvm-train>` to build a classifier based on SVMs and :svms:`CvSVM::predict <cvsvm-predict>` to test its performance.
+ Use the OpenCV functions :svms:`CvSVM::train <cvsvm-train>` to build a classifier based on SVMs and :svms:`CvSVM::predict <cvsvm-predict>` to test its performance.
What is a SVM?
==============
......@@ -36,14 +36,14 @@ Then, the operation of the SVM algorithm is based on finding the hyperplane that
.. image:: images/optimal-hyperplane.png
:alt: The Optimal hyperplane
:align: center
:align: center
How is the optimal hyperplane computed?
=======================================
Let's introduce the notation used to define formally a hyperplane:
.. math::
.. math::
f(x) = \beta_{0} + \beta^{T} x,
where :math:`\beta` is known as the *weight vector* and :math:`\beta_{0}` as the *bias*.
......@@ -106,7 +106,7 @@ Explanation
.. code-block:: cpp
Mat trainingDataMat(3, 2, CV_32FC1, trainingData);
Mat labelsMat (3, 1, CV_32FC1, labels);
Mat labelsMat (3, 1, CV_32FC1, labels);
2. **Set up SVM's parameters**
......@@ -143,7 +143,7 @@ Explanation
.. code-block:: cpp
Vec3b green(0,255,0), blue (255,0,0);
for (int i = 0; i < image.rows; ++i)
for (int j = 0; j < image.cols; ++j)
{
......@@ -152,8 +152,8 @@ Explanation
if (response == 1)
image.at<Vec3b>(j, i) = green;
else
if (response == -1)
else
if (response == -1)
image.at<Vec3b>(j, i) = blue;
}
......@@ -184,5 +184,5 @@ Results
.. image:: images/result.png
:alt: The seperated planes
:align: center
:align: center
......@@ -5,9 +5,9 @@
Use the powerfull machine learning classes for statistical classification, regression and clustering of data.
.. include:: ../../definitions/tocDefinitions.rst
.. include:: ../../definitions/tocDefinitions.rst
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
......@@ -18,7 +18,7 @@ Use the powerfull machine learning classes for statistical classification, regre
*Author:* |Author_FernandoI|
Learn what a Suport Vector Machine is.
Learn what a Suport Vector Machine is.
============ ==============================================
......@@ -26,7 +26,7 @@ Use the powerfull machine learning classes for statistical classification, regre
:height: 90pt
:width: 90pt
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
......@@ -51,6 +51,6 @@ Use the powerfull machine learning classes for statistical classification, regre
.. toctree::
:hidden:
../introduction_to_svm/introduction_to_svm
../non_linear_svms/non_linear_svms
......@@ -5,23 +5,23 @@
Ever wondered how your digital camera detects peoples and faces? Look here to find out!
.. include:: ../../definitions/tocDefinitions.rst
.. include:: ../../definitions/tocDefinitions.rst
+
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
===================== ==============================================
|CascadeClassif| **Title:** :ref:`cascade_classifier`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
Here we learn how to use *objdetect* to find objects in our images or videos
===================== ==============================================
.. |CascadeClassif| image:: images/Cascade_Classifier_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
......
......@@ -3,7 +3,7 @@
*video* module. Video analysis
-----------------------------------------------------------
Look here in order to find use on your video stream algoritms like: motion extraction, feature tracking and foreground extractions.
Look here in order to find use on your video stream algoritms like: motion extraction, feature tracking and foreground extractions.
.. include:: ../../definitions/noContent.rst
......
......@@ -78,7 +78,7 @@ First, we create an instance of a keypoint detector. All detectors inherit the a
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);
We create an instance of descriptor extractor. The most of OpenCV descriptors inherit ``DescriptorExtractor`` abstract interface. Then we compute descriptors for each of the keypoints. The output ``Mat`` of the ``DescriptorExtractor::compute`` method contains a descriptor in a row *i* for each *i*-th keypoint. Note that the method can modify the keypoints vector by removing the keypoints such that a descriptor for them is not defined (usually these are the keypoints near image border). The method makes sure that the ouptut keypoints and descriptors are consistent with each other (so that the number of keypoints is equal to the descriptors row count). ::
We create an instance of descriptor extractor. The most of OpenCV descriptors inherit ``DescriptorExtractor`` abstract interface. Then we compute descriptors for each of the keypoints. The output ``Mat`` of the ``DescriptorExtractor::compute`` method contains a descriptor in a row *i* for each *i*-th keypoint. Note that the method can modify the keypoints vector by removing the keypoints such that a descriptor for them is not defined (usually these are the keypoints near image border). The method makes sure that the ouptut keypoints and descriptors are consistent with each other (so that the number of keypoints is equal to the descriptors row count). ::
// matching descriptors
BruteForceMatcher<L2<float> > matcher;
......
......@@ -13,7 +13,7 @@ Images
Load an image from a file: ::
Mat img = imread(filename)
If you read a jpg file, a 3 channel image is created by default. If you need a grayscale image, use: ::
Mat img = imread(filename, 0);
......@@ -23,14 +23,14 @@ If you read a jpg file, a 3 channel image is created by default. If you need a g
Save an image to a file: ::
imwrite(filename, img);
.. note:: format of the file is determined by its extension.
.. note:: use ``imdecode`` and ``imencode`` to read and write image from/to memory rather than a file.
XML/YAML
--------
TBD
Basic operations with images
......@@ -85,7 +85,7 @@ Memory management and reference counting
// .. fill the array
Mat pointsMat = Mat(points).reshape(1);
As a result we get a 32FC1 matrix with 3 columns instead of 32FC3 matrix with 1 column. ``pointsMat`` uses data from ``points`` and will not deallocate the memory when destroyed. In this particular instance, however, developer has to make sure that lifetime of ``points`` is longer than of ``pointsMat``.
As a result we get a 32FC1 matrix with 3 columns instead of 32FC3 matrix with 1 column. ``pointsMat`` uses data from ``points`` and will not deallocate the memory when destroyed. In this particular instance, however, developer has to make sure that lifetime of ``points`` is longer than of ``pointsMat``.
If we need to copy the data, this is done using, for example, ``Mat::copyTo`` or ``Mat::clone``: ::
Mat img = imread("image.jpg");
......@@ -115,7 +115,7 @@ A convertion from \texttt{Mat} to C API data structures: ::
IplImage img1 = img;
CvMat m = img;
Note that there is no data copying here.
Note that there is no data copying here.
Conversion from color to grey scale: ::
......
......@@ -6,7 +6,7 @@ Cascade Classifier Training
Introduction
============
The work with a cascade classifier inlcudes two major stages: training and detection.
The work with a cascade classifier inlcudes two major stages: training and detection.
Detection stage is described in a documentation of ``objdetect`` module of general OpenCV documentation. Documentation gives some basic information about cascade classifier.
Current guide is describing how to train a cascade classifier: preparation of a training data and running the training application.
......@@ -18,10 +18,10 @@ There are two applications in OpenCV to train cascade classifier: ``opencv_haart
Note that ``opencv_traincascade`` application can use TBB for multi-threading. To use it in multicore mode OpenCV must be built with TBB.
Also there are some auxilary utilities related to the training.
Also there are some auxilary utilities related to the training.
* ``opencv_createsamples`` is used to prepare a training dataset of positive and test samples. ``opencv_createsamples`` produces dataset of positive samples in a format that is supported by both ``opencv_haartraining`` and ``opencv_traincascade`` applications. The output is a file with \*.vec extension, it is a binary format which contains images.
* ``opencv_performance`` may be used to evaluate the quality of classifiers, but for trained by ``opencv_haartraining`` only. It takes a collection of marked up images, runs the classifier and reports the performance, i.e. number of found objects, number of missed objects, number of false alarms and other information.
Since ``opencv_haartraining`` is an obsolete application, only ``opencv_traincascade`` will be described futher. ``opencv_createsamples`` utility is needed to prepare a training data for ``opencv_traincascade``, so it will be described too.
......@@ -36,7 +36,7 @@ Negative Samples
Negative samples are taken from arbitrary images. These images must not contain detected objects. Negative samples are enumerated in a special file. It is a text file in which each line contains an image filename (relative to the directory of the description file) of negative sample image. This file must be created manually. Note that negative samples and sample images are also called background samples or background samples images, and are used interchangeably in this document. Described images may be of different sizes. But each image should be (but not nessesarily) larger then a training window size, because these images are used to subsample negative image to the training size.
An example of description file:
Directory structure:
.. code-block:: text
......@@ -45,14 +45,14 @@ Directory structure:
img1.jpg
img2.jpg
bg.txt
File bg.txt:
.. code-block:: text
img/img1.jpg
img/img2.jpg
Positive Samples
----------------
Positive samples are created by ``opencv_createsamples`` utility. They may be created from a single image with object or from a collection of previously marked up images.
......@@ -66,37 +66,37 @@ Command line arguments:
* ``-vec <vec_file_name>``
Name of the output file containing the positive samples for training.
* ``-img <image_file_name>``
Source object image (e.g., a company logo).
* ``-bg <background_file_name>``
Background description file; contains a list of images which are used as a background for randomly distorted versions of the object.
* ``-num <number_of_samples>``
Number of positive samples to generate.
* ``-bgcolor <background_color>``
Background color (currently grayscale images are assumed); the background color denotes the transparent color. Since there might be compression artifacts, the amount of color tolerance can be specified by ``-bgthresh``. All pixels withing ``bgcolor-bgthresh`` and ``bgcolor+bgthresh`` range are interpreted as transparent.
* ``-bgthresh <background_color_threshold>``
* ``-inv``
If specified, colors will be inverted.
* ``-randinv``
If specified, colors will be inverted randomly.
* ``-maxidev <max_intensity_deviation>``
Maximal intensity deviation of pixels in foreground samples.
* ``-maxxangle <max_x_rotation_angle>``
* ``-maxyangle <max_y_rotation_angle>``
......@@ -104,15 +104,15 @@ Command line arguments:
* ``-maxzangle <max_z_rotation_angle>``
Maximum rotation angles must be given in radians.
* ``-show``
Useful debugging option. If specified, each sample will be shown. Pressing ``Esc`` will continue the samples creation process without.
* ``-w <sample_width>``
Width (in pixels) of the output samples.
* ``-h <sample_height>``
Height (in pixels) of the output samples.
......@@ -123,7 +123,7 @@ The source image is rotated randomly around all three axes. The chosen angle is
Positive samples also may be obtained from a collection of previously marked up images. This collection is described by a text file similar to background description file. Each line of this file corresponds to an image. The first element of the line is the filename. It is followed by the number of object instances. The following numbers are the coordinates of objects bounding rectangles (x, y, width, height).
An example of description file:
Directory structure:
.. code-block:: text
......@@ -132,27 +132,27 @@ Directory structure:
img1.jpg
img2.jpg
info.dat
File info.dat:
.. code-block:: text
img/img1.jpg 1 140 100 45 45
img/img2.jpg 2 100 200 50 50 50 30 25 25
Image img1.jpg contains single object instance with the following coordinates of bounding rectangle: (140, 100, 45, 45). Image img2.jpg contains two object instances.
In order to create positive samples from such collection, ``-info`` argument should be specified instead of ``-img``:
* ``-info <collection_file_name>``
Description file of marked up images collection.
The scheme of samples creation in this case is as follows. The object instances are taken from images. Then they are resized to target samples size and stored in output vec-file. No distortion is applied, so the only affecting arguments are ``-w``, ``-h``, ``-show`` and ``-num``.
``opencv_createsamples`` utility may be used for examining samples stored in positive samples file. In order to do this only ``-vec``, ``-w`` and ``-h`` parameters should be specified.
Note that for training, it does not matter how vec-files with positive samples are generated. But ``opencv_createsamples`` utility is the only one way to collect/create a vector file of positive samples, provided by OpenCV.
Note that for training, it does not matter how vec-files with positive samples are generated. But ``opencv_createsamples`` utility is the only one way to collect/create a vector file of positive samples, provided by OpenCV.
Example of vec-file is available here ``opencv/data/vec_files/trainingfaces_24-24.vec``. It can be used to train a face detector with the following window size: ``-w 24 -h 24``.
......@@ -165,99 +165,99 @@ Command line arguments of ``opencv_traincascade`` application grouped by purpose
#.
Common arguments:
* ``-data <cascade_dir_name>``
Where the trained classifier should be stored.
* ``-vec <vec_file_name>``
vec-file with positive samples (created by ``opencv_createsamples`` utility).
* ``-bg <background_file_name>``
Background description file.
* ``-numPos <number_of_positive_samples>``
* ``-numNeg <number_of_negative_samples>``
Number of positive/negative samples used in training for every classifier stage.
* ``-numStages <number_of_stages>``
Number of cascade stages to be trained.
* ``-precalcValBufSize <precalculated_vals_buffer_size_in_Mb>``
Size of buffer for precalculated feature values (in Mb).
* ``-precalcIdxBufSize <precalculated_idxs_buffer_size_in_Mb>``
Size of buffer for precalculated feature indices (in Mb). The more memory you have the faster the training process.
* ``-baseFormatSave``
This argument is actual in case of Haar-like features. If it is specified, the cascade will be saved in the old format.
#.
Cascade parameters:
* ``-stageType <BOOST(default)>``
Type of stages. Only boosted classifier are supported as a stage type at the moment.
* ``-featureType<{HAAR(default), LBP}>``
Type of features: ``HAAR`` - Haar-like features, ``LBP`` - local binary patterns.
* ``-w <sampleWidth>``
* ``-h <sampleHeight>``
Size of training samples (in pixels). Must have exactly the same values as used during training samples creation (``opencv_createsamples`` utility).
#.
Boosted classifer parameters:
* ``-bt <{DAB, RAB, LB, GAB(default)}>``
Type of boosted classifiers: ``DAB`` - Discrete AdaBoost, ``RAB`` - Real AdaBoost, ``LB`` - LogitBoost, ``GAB`` - Gentle AdaBoost.
* ``-minHitRate <min_hit_rate>``
Minimal desired hit rate for each stage of the classifier. Overall hit rate may be estimated as (min_hit_rate^number_of_stages).
* ``-maxFalseAlarmRate <max_false_alarm_rate>``
Maximal desired false alarm rate for each stage of the classifier. Overall false alarm rate may be estimated as (max_false_alarm_rate^number_of_stages).
* ``-weightTrimRate <weight_trim_rate>``
Specifies whether trimming should be used and its weight. A decent choice is 0.95.
* ``-maxDepth <max_depth_of_weak_tree>``
Maximal depth of a weak tree. A decent choice is 1, that is case of stumps.
* ``-maxWeakCount <max_weak_tree_count>``
Maximal count of weak trees for every cascade stage. The boosted classifier (stage) will have so many weak trees (``<=maxWeakCount``), as needed to achieve the given ``-maxFalseAlarmRate``.
#.
Haar-like feature parameters:
* ``-mode <BASIC (default) | CORE | ALL>``
Selects the type of Haar features set used in training. ``BASIC`` use only upright features, while ``ALL`` uses the full set of upright and 45 degree rotated feature set. See [Rainer2002]_ for more details.
#.
#.
Local Binary Patterns parameters:
Local Binary Patterns don't have parameters.
After the ``opencv_traincascade`` application has finished its work, the trained cascade will be saved in cascade.xml file in the folder, which was passed as ``-data`` parameter. Other files in this folder are created for the case of interrupted training, so you may delete them after completion of training.
......
......@@ -1462,7 +1462,7 @@ Reconstructs points by triangulation.
:param points4D: 4xN array of reconstructed points in homogeneous coordinates.
The function reconstructs 3-dimensional points (in homogeneous coordinates) by using their observations with a stereo camera. Projections matrices can be obtained from :ocv:func:`stereoRectify`.
The function reconstructs 3-dimensional points (in homogeneous coordinates) by using their observations with a stereo camera. Projections matrices can be obtained from :ocv:func:`stereoRectify`.
.. seealso::
......
......@@ -4,19 +4,19 @@ Changelog
Release 0.05
------------
This library is now included in the official OpenCV distribution (from 2.4 on).
This library is now included in the official OpenCV distribution (from 2.4 on).
The :ocv:class`FaceRecognizer` is now an :ocv:class:`Algorithm`, which better fits into the overall
OpenCV API.
OpenCV API.
To reduce the confusion on user side and minimize my work, libfacerec and OpenCV
have been synchronized and are now based on the same interfaces and implementation.
To reduce the confusion on user side and minimize my work, libfacerec and OpenCV
have been synchronized and are now based on the same interfaces and implementation.
The library now has an extensive documentation:
* The API is explained in detail and with a lot of code examples.
* The face recognition guide I had written for Python and GNU Octave/MATLAB has been adapted to the new OpenCV C++ ``cv::FaceRecognizer``.
* The face recognition guide I had written for Python and GNU Octave/MATLAB has been adapted to the new OpenCV C++ ``cv::FaceRecognizer``.
* A tutorial for gender classification with Fisherfaces.
* A tutorial for face recognition in videos (e.g. webcam).
* A tutorial for face recognition in videos (e.g. webcam).
Release highlights
......@@ -27,8 +27,8 @@ Release highlights
Release 0.04
------------
This version is fully Windows-compatible and works with OpenCV 2.3.1. Several
bugfixes, but none influenced the recognition rate.
This version is fully Windows-compatible and works with OpenCV 2.3.1. Several
bugfixes, but none influenced the recognition rate.
Release highlights
++++++++++++++++++
......@@ -40,9 +40,9 @@ Release highlights
Release 0.03
------------
Reworked the library to provide separate implementations in cpp files, because
it's the preferred way of contributing OpenCV libraries. This means the library
is not header-only anymore. Slight API changes were done, please see the
Reworked the library to provide separate implementations in cpp files, because
it's the preferred way of contributing OpenCV libraries. This means the library
is not header-only anymore. Slight API changes were done, please see the
documentation for details.
Release highlights
......@@ -55,9 +55,9 @@ Release highlights
Release 0.02
------------
Reworked the library to provide separate implementations in cpp files, because
it's the preferred way of contributing OpenCV libraries. This means the library
is not header-only anymore. Slight API changes were done, please see the
Reworked the library to provide separate implementations in cpp files, because
it's the preferred way of contributing OpenCV libraries. This means the library
is not header-only anymore. Slight API changes were done, please see the
documentation for details.
Release highlights
......@@ -80,7 +80,7 @@ Release highlights
* Eigenfaces [TP91]_
* Fisherfaces [BHK97]_
* Local Binary Patterns Histograms [AHP04]_
* Added persistence facilities to store the models with a common API.
* Unit Tests (using `gtest <http://code.google.com/p/googletest/>`_).
* Providing a CMakeLists.txt to enable easy cross-platform building.
......@@ -201,7 +201,7 @@ For the first source code example, I'll go through it with you. I am first givin
.. literalinclude:: src/facerec_eigenfaces.cpp
:language: cpp
:linenos:
The source code for this demo application is also available in the ``src`` folder coming with this documentation:
* :download:`src/facerec_eigenfaces.cpp <src/facerec_eigenfaces.cpp>`
......
......@@ -6,7 +6,7 @@ Introduction
Saving and loading a :ocv:class:`FaceRecognizer` is very important. Training a FaceRecognizer can be a very time-intense task, plus it's often impossible to ship the whole face database to the user of your product. The task of saving and loading a FaceRecognizer is easy with :ocv:class:`FaceRecognizer`. You only have to call :ocv:func:`FaceRecognizer::load` for loading and :ocv:func:`FaceRecognizer::save` for saving a :ocv:class:`FaceRecognizer`.
I'll adapt the Eigenfaces example from the :doc:`../facerec_tutorial`: Imagine we want to learn the Eigenfaces of the `AT&T Facedatabase <http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html>`_, store the model to a YAML file and then load it again.
I'll adapt the Eigenfaces example from the :doc:`../facerec_tutorial`: Imagine we want to learn the Eigenfaces of the `AT&T Facedatabase <http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html>`_, store the model to a YAML file and then load it again.
From the loaded model, we'll get a prediction, show the mean, Eigenfaces and the image reconstruction.
......
......@@ -111,7 +111,7 @@ An example. If the haar-cascade is at ``C:/opencv/data/haarcascades/haarcascade_
facerec_video.exe C:/opencv/data/haarcascades/haarcascade_frontalface_default.xml C:/facerec/data/celebrities.txt 1
That's it.
That's it.
Results
-------
......
......@@ -66,8 +66,8 @@ Splits an element set into equivalency classes.
:param vec: Set of elements stored as a vector.
:param labels: Output vector of labels. It contains as many elements as ``vec``. Each label ``labels[i]`` is a 0-based cluster index of ``vec[i]`` .
:param labels: Output vector of labels. It contains as many elements as ``vec``. Each label ``labels[i]`` is a 0-based cluster index of ``vec[i]`` .
:param predicate: Equivalence predicate (pointer to a boolean function of two arguments or an instance of the class that has the method ``bool operator()(const _Tp& a, const _Tp& b)`` ). The predicate returns ``true`` when the elements are certainly in the same class, and returns ``false`` if they may or may not be in the same class.
The generic function ``partition`` implements an
......
......@@ -12,30 +12,30 @@ The CommandLineParser class is designed for command line arguments parsing
.. ocv:function:: CommandLineParser::CommandLineParser(int argc, const char * const argv[], const std::string keys)
:param argc:
:param argv:
:param keys:
:param argc:
:param argv:
:param keys:
.. ocv:function:: T CommandLineParser::get<T>(const std::string& name, bool space_delete = true)
:param name:
:param space_delete:
:param name:
:param space_delete:
.. ocv:function:: T CommandLineParser::get<T>(int index, bool space_delete = true)
:param index:
:param space_delete:
:param index:
:param space_delete:
.. ocv:function:: bool CommandLineParser::has(const std::string& name)
:param name:
:param name:
.. ocv:function:: bool CommandLineParser::check()
.. ocv:function:: void CommandLineParser::about(std::string message)
:param message:
:param message:
.. ocv:function:: void CommandLineParser::printMessage()
......@@ -78,7 +78,7 @@ Syntax:
::
const std::string keys =
const std::string keys =
"{help h usage ? | | print this message }"
"{@image1 | | image1 for compare }"
"{@image2 | | image2 for compare }"
......
......@@ -405,8 +405,8 @@ The number of pixels along the line is stored in ``LineIterator::count`` . The m
for(int i = 0; i < it.count; i++, ++it)
buf[i] = *(const Vec3b)*it;
// alternative way of iterating through the line
// alternative way of iterating through the line
for(int i = 0; i < it2.count; i++, ++it2)
{
Vec3b val = img.at<Vec3b>(it2.pos());
......
......@@ -91,8 +91,8 @@ you can use::
Ptr<T> ptr = new T(...);
That is, ``Ptr<T> ptr`` encapsulates a pointer to a ``T`` instance and a reference counter associated with the pointer. See the
:ocv:class:`Ptr`
That is, ``Ptr<T> ptr`` encapsulates a pointer to a ``T`` instance and a reference counter associated with the pointer. See the
:ocv:class:`Ptr`
description for details.
.. _AutomaticAllocation:
......
......@@ -2283,7 +2283,7 @@ PCA constructors
* **CV_PCA_DATA_AS_COL** indicates that the input samples are stored as matrix columns.
:param maxComponents: maximum number of components that PCA should retain; by default, all the components are retained.
:param retainedVariance: Percentage of variance that PCA should retain. Using this parameter will let the PCA decided how many components to retain but it will always keep at least 2.
The default constructor initializes an empty PCA structure. The other constructors initialize the structure and call
......@@ -2312,7 +2312,7 @@ Performs Principal Component Analysis of the supplied dataset.
* **CV_PCA_DATA_AS_COL** indicates that the input samples are stored as matrix columns.
:param maxComponents: maximum number of components that PCA should retain; by default, all the components are retained.
:param retainedVariance: Percentage of variance that PCA should retain. Using this parameter will let the PCA decided how many components to retain but it will always keep at least 2.
The operator performs PCA of the supplied dataset. It is safe to reuse the same PCA structure for multiple datasets. That is, if the structure has been previously used with another dataset, the existing internal data is reclaimed and the new ``eigenvalues``, ``eigenvectors`` , and ``mean`` are allocated and computed.
......
......@@ -41,7 +41,7 @@ Abstract base class for computing descriptors for image keypoints. ::
In this interface, a keypoint descriptor can be represented as a
dense, fixed-dimension vector of a basic type. Most descriptors
dense, fixed-dimension vector of a basic type. Most descriptors
follow this pattern as it simplifies computing
distances between descriptors. Therefore, a collection of
descriptors is represented as
......
......@@ -34,7 +34,7 @@ Lixin Fan, Jutta Willamowski, Cedric Bray, 2004. ::
BOWTrainer::add
-------------------
Adds descriptors to a training set.
Adds descriptors to a training set.
.. ocv:function:: void BOWTrainer::add( const Mat& descriptors )
......@@ -60,7 +60,7 @@ Returns the count of all descriptors stored in the training set.
BOWTrainer::cluster
-----------------------
Clusters train descriptors.
Clusters train descriptors.
.. ocv:function:: Mat BOWTrainer::cluster() const
......@@ -110,7 +110,7 @@ Class to compute an image descriptor using the *bag of visual words*. Such a com
#. Compute descriptors for a given image and its keypoints set.
#. Find the nearest visual words from the vocabulary for each keypoint descriptor.
#. Compute the bag-of-words image descriptor as is a normalized histogram of vocabulary words encountered in the image. The ``i``-th bin of the histogram is a frequency of ``i``-th word of the vocabulary in the given image.
The class declaration is the following: ::
class BOWImgDescriptorExtractor
......
......@@ -10,11 +10,11 @@ Clusters features using hierarchical k-means algorithm.
.. ocv:function:: template<typename Distance> int flann::hierarchicalClustering(const Mat& features, Mat& centers, const cvflann::KMeansIndexParams& params, Distance d = Distance())
:param features: The points to be clustered. The matrix must have elements of type ``Distance::ElementType``.
:param centers: The centers of the clusters obtained. The matrix must have type ``Distance::ResultType``. The number of rows in this matrix represents the number of clusters desired, however, because of the way the cut in the hierarchical tree is chosen, the number of clusters computed will be the highest number of the form ``(branching-1)*k+1`` that's lower than the number of clusters desired, where ``branching`` is the tree's branching factor (see description of the KMeansIndexParams).
:param centers: The centers of the clusters obtained. The matrix must have type ``Distance::ResultType``. The number of rows in this matrix represents the number of clusters desired, however, because of the way the cut in the hierarchical tree is chosen, the number of clusters computed will be the highest number of the form ``(branching-1)*k+1`` that's lower than the number of clusters desired, where ``branching`` is the tree's branching factor (see description of the KMeansIndexParams).
:param params: Parameters used in the construction of the hierarchical k-means tree.
:param d: Distance to be used for clustering.
The method clusters the given feature vectors by constructing a hierarchical k-means tree and choosing a cut in the tree that minimizes the cluster's variance. It returns the number of clusters found.
......@@ -868,7 +868,7 @@ Performs pure non local means denoising without any simplification, and thus it
.. seealso::
:ocv:func:`fastNlMeansDenoising`
gpu::FastNonLocalMeansDenoising
-------------------------------
.. ocv:class:: gpu::FastNonLocalMeansDenoising
......@@ -894,19 +894,19 @@ Perform image denoising using Non-local Means Denoising algorithm http://www.ipo
:param src: Input 8-bit 1-channel, 2-channel or 3-channel image.
:param dst: Output image with the same size and type as ``src`` .
:param h: Parameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise
:param search_window: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater search_window - greater denoising time. Recommended value 21 pixels
:param block_size: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
:param stream: Stream for the asynchronous invocations.
This function expected to be applied to grayscale images. For colored images look at ``FastNonLocalMeansDenoising::labMethod``.
This function expected to be applied to grayscale images. For colored images look at ``FastNonLocalMeansDenoising::labMethod``.
.. seealso::
.. seealso::
:ocv:func:`fastNlMeansDenoising`
gpu::FastNonLocalMeansDenoising::labMethod()
......@@ -920,21 +920,21 @@ Modification of ``FastNonLocalMeansDenoising::simpleMethod`` for color images
:param dst: Output image with the same size and type as ``src`` .
:param h_luminance: Parameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise
:param float: The same as h but for color components. For most images value equals 10 will be enought to remove colored noise and do not distort colors
:param search_window: Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater search_window - greater denoising time. Recommended value 21 pixels
:param block_size: Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
:param stream: Stream for the asynchronous invocations.
The function converts image to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``FastNonLocalMeansDenoising::simpleMethod`` function.
.. seealso::
.. seealso::
:ocv:func:`fastNlMeansDenoisingColored`
gpu::alphaComp
-------------------
Composites two images using alpha opacity values contained in each image.
......
......@@ -185,7 +185,7 @@ Reduces a matrix to a vector.
* **CV_REDUCE_MIN** The output is the minimum (column/row-wise) of all rows/columns of the matrix.
:param dtype: When it is negative, the destination vector will have the same type as the source matrix. Otherwise, its type will be ``CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels())`` .
The function ``reduce`` reduces the matrix to a vector by treating the matrix rows/columns as a set of 1D vectors and performing the specified operation on the vectors until a single row/column is obtained. For example, the function can be used to compute horizontal and vertical projections of a raster image. In case of ``CV_REDUCE_SUM`` and ``CV_REDUCE_AVG`` , the output may have a larger element bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction modes.
.. seealso:: :ocv:func:`reduce`
......@@ -20,7 +20,7 @@ Reads an image from a buffer in memory.
:param buf: Input array or vector of bytes.
:param flags: The same flags as in :ocv:func:`imread` .
:param dst: The optional output placeholder for the decoded matrix. It can save the image reallocations when the function is called repeatedly for images of the same size.
The function reads an image from the specified buffer in the memory.
......@@ -74,12 +74,12 @@ Loads an image from a file.
:param filename: Name of file to be loaded.
:param flags: Flags specifying the color type of a loaded image:
* 1 -
* CV_LOAD_IMAGE_ANYDEPTH -
* 1 -
* CV_LOAD_IMAGE_ANYDEPTH -
CV_LOAD_IMAGE_COLOR
CV_LOAD_IMAGE_GRAYSCALE
* **>0** Return a 3-channel color image.
.. note:: In the current implementation the alpha channel, if any, is stripped from the output image. Use negative value if you need the alpha channel.
......
......@@ -16,4 +16,4 @@ The license does not permit the following uses:
You may not use, or allow anyone else to use the icons to create pornographic, libelous, obscene, or defamatory material.
All icon files are provided "as is". You agree not to hold IconEden.com liable for any damages that may occur due to use, or inability to use, icons or image data from IconEden.com.
\ No newline at end of file
All icon files are provided "as is". You agree not to hold IconEden.com liable for any damages that may occur due to use, or inability to use, icons or image data from IconEden.com.
\ No newline at end of file
......@@ -174,7 +174,7 @@ Compares two histograms.
* **CV_COMP_INTERSECT** Intersection
* **CV_COMP_BHATTACHARYYA** Bhattacharyya distance
* **CV_COMP_HELLINGER** Synonym for ``CV_COMP_BHATTACHARYYA``
The functions ``compareHist`` compare two dense or two sparse histograms using the specified method:
......
......@@ -9,7 +9,7 @@ CvKNearest
----------
.. ocv:class:: CvKNearest : public CvStatModel
The class implements K-Nearest Neighbors model as described in the beginning of this section.
The class implements K-Nearest Neighbors model as described in the beginning of this section.
CvKNearest::CvKNearest
----------------------
......@@ -39,7 +39,7 @@ Trains the model.
:param updateBase: Specifies whether the model is trained from scratch (``update_base=false``), or it is updated using the new training data (``update_base=true``). In the latter case, the parameter ``maxK`` must not be larger than the original value.
The method trains the K-Nearest model. It follows the conventions of the generic :ocv:func:`CvStatModel::train` approach with the following limitations:
The method trains the K-Nearest model. It follows the conventions of the generic :ocv:func:`CvStatModel::train` approach with the following limitations:
* Only ``CV_ROW_SAMPLE`` data layout is supported.
* Input variables are all ordered.
......
此差异已折叠。
......@@ -177,7 +177,7 @@ Loads a classifier from a file.
CascadeClassifier::read
---------------------------
Reads a classifier from a FileStorage node.
Reads a classifier from a FileStorage node.
.. ocv:function:: bool CascadeClassifier::read(const FileNode& node)
......
......@@ -16,8 +16,8 @@ Returns the list of devices
.. ocv:function:: int ocl::getDevice(std::vector<Info>& oclinfo, int devicetype = CVCL_DEVICE_TYPE_GPU)
:param oclinfo: Output vector of ``ocl::Info`` structures
:param devicetype: One of ``CVCL_DEVICE_TYPE_GPU``, ``CVCL_DEVICE_TYPE_CPU`` or ``CVCL_DEVICE_TYPE_DEFAULT``.
the function must be called before any other ``cv::ocl`` functions; it initializes ocl runtime.
此差异已折叠。
......@@ -7,5 +7,5 @@ photo. Computational Photography
.. toctree::
:maxdepth: 2
inpainting
inpainting
denoising
......@@ -9,7 +9,7 @@ detail::CameraParams
Describes camera parameters.
.. note:: Translation is assumed to be zero during the whole stitching pipeline.
.. note:: Translation is assumed to be zero during the whole stitching pipeline.
::
......
此差异已折叠。
此差异已折叠。
文件模式从 100755 更改为 100644
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册