Updated sample files documentation inclusions
This commit is contained in:
@@ -15,21 +15,14 @@ Source code
|
||||
-----------
|
||||
|
||||
You can [download this from here
|
||||
](samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp) or
|
||||
](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp) or
|
||||
find it in the
|
||||
`samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp` of the
|
||||
OpenCV source code library.
|
||||
|
||||
Here's a sample usage of @ref cv::dft() :
|
||||
|
||||
@dontinclude cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp
|
||||
@until highgui.hpp
|
||||
@skipline iostream
|
||||
@skip main
|
||||
@until {
|
||||
@skip filename
|
||||
@until return 0;
|
||||
@until }
|
||||
@includelineno cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
@@ -147,7 +140,7 @@ An application idea would be to determine the geometrical orientation present in
|
||||
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
|
||||
[this horizontal ](samples/data/imageTextN.png) and [this rotated](samples/data/imageTextR.png)
|
||||
[this horizontal ](https://github.com/Itseez/opencv/tree/master/samples/data/imageTextN.png) and [this rotated](https://github.com/Itseez/opencv/tree/master/samples/data/imageTextR.png)
|
||||
image about a text.
|
||||
|
||||
In case of the horizontal text:
|
||||
|
@@ -16,18 +16,13 @@ Source code
|
||||
-----------
|
||||
|
||||
You can [download this from here
|
||||
](samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp) or find it in the
|
||||
](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp) or find it in the
|
||||
`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.
|
||||
|
||||
@dontinclude cpp/tutorial_code/core/file_input_output/file_input_output.cpp
|
||||
|
||||
@until std;
|
||||
@skip class MyData
|
||||
@until return 0;
|
||||
@until }
|
||||
@includelineno cpp/tutorial_code/core/file_input_output/file_input_output.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
@@ -51,7 +51,7 @@ three major ways of going through an image pixel by pixel. To make things a litt
|
||||
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 [here
|
||||
](samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp) or look it up in
|
||||
](https://github.com/Itseez/opencv/tree/master/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{.bash}
|
||||
how_to_scan_images imageName.jpg intValueToReduce [G]
|
||||
@@ -59,10 +59,7 @@ how_to_scan_images imageName.jpg intValueToReduce [G]
|
||||
The final argument is optional. If given the image will be loaded in gray scale format, otherwise
|
||||
the RGB color way is used. The first thing is to calculate the lookup table.
|
||||
|
||||
@dontinclude cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp
|
||||
|
||||
@skip int divideWith
|
||||
@until table[i]
|
||||
@snippet how_to_scan_images.cpp dividewith
|
||||
|
||||
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.
|
||||
@@ -107,9 +104,7 @@ 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:
|
||||
|
||||
@skip Mat& ScanImageAndReduceC
|
||||
@until return
|
||||
@until }
|
||||
@snippet how_to_scan_images.cpp scan-c
|
||||
|
||||
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
|
||||
@@ -141,9 +136,7 @@ considered a safer way as it takes over these tasks from the user. All you need
|
||||
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).
|
||||
|
||||
@skip ScanImageAndReduceIterator
|
||||
@until return
|
||||
@until }
|
||||
@snippet how_to_scan_images.cpp scan-iterator
|
||||
|
||||
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
|
||||
@@ -161,9 +154,7 @@ what type we are looking at the image. It's no different here as you need manual
|
||||
type to use at the automatic lookup. You can observe this in case of the gray scale images for the
|
||||
following source code (the usage of the + @ref cv::at() function):
|
||||
|
||||
@skip ScanImageAndReduceRandomAccess
|
||||
@until return
|
||||
@until }
|
||||
@snippet how_to_scan_images.cpp scan-random
|
||||
|
||||
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
|
||||
@@ -192,14 +183,11 @@ OpenCV has a function that makes the modification without the need from you to w
|
||||
the image. We use the @ref cv::LUT() function of the core module. First we build a Mat type of the
|
||||
lookup table:
|
||||
|
||||
@dontinclude cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp
|
||||
|
||||
@skip Mat lookUpTable
|
||||
@until p[i] = table[i]
|
||||
@snippet how_to_scan_images.cpp table-init
|
||||
|
||||
Finally call the function (I is our input image and J the output one):
|
||||
|
||||
@skipline LUT
|
||||
@snippet how_to_scan_images.cpp table-use
|
||||
|
||||
Performance Difference
|
||||
----------------------
|
||||
|
@@ -16,7 +16,7 @@ Code
|
||||
|
||||
You may also find the source code in the
|
||||
`samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp` file of the OpenCV source library or
|
||||
download it from [here](samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp).
|
||||
download it from [here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp).
|
||||
|
||||
@includelineno cpp/tutorial_code/core/ippasync/ippasync_sample.cpp
|
||||
|
||||
|
@@ -85,7 +85,7 @@ L = Mat(pI);
|
||||
A case study
|
||||
------------
|
||||
|
||||
Now that you have the basics done [here's](samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp)
|
||||
Now that you have the basics done [here's](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp)
|
||||
an example that mixes the usage of the C interface with the C++ one. You will also find it in the
|
||||
sample directory of the OpenCV source code library at the
|
||||
`samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp` .
|
||||
@@ -93,18 +93,13 @@ To further help on seeing the difference the programs supports two modes: one mi
|
||||
one pure C++. If you define the *DEMO_MIXED_API_USE* you'll end up using the first. The program
|
||||
separates the color planes, does some modifications on them and in the end merge them back together.
|
||||
|
||||
@dontinclude cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp
|
||||
@until namespace cv
|
||||
@skip ifdef
|
||||
@until endif
|
||||
@skip main
|
||||
@until endif
|
||||
@snippet interoperability_with_OpenCV_1.cpp head
|
||||
@snippet interoperability_with_OpenCV_1.cpp start
|
||||
|
||||
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.
|
||||
|
||||
@skip convert image
|
||||
@until split
|
||||
@snippet interoperability_with_OpenCV_1.cpp new
|
||||
|
||||
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:
|
||||
@@ -114,8 +109,7 @@ image some Gaussian noise and then mix together the channels according to some f
|
||||
|
||||
The scanning version looks like:
|
||||
|
||||
@skip #if 1
|
||||
@until #else
|
||||
@snippet interoperability_with_OpenCV_1.cpp scanning
|
||||
|
||||
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
|
||||
@@ -123,14 +117,12 @@ description of these in the @ref tutorial_how_to_scan_images tutorial. Convertin
|
||||
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:
|
||||
|
||||
@until planes[0]
|
||||
@until endif
|
||||
@snippet interoperability_with_OpenCV_1.cpp noisy
|
||||
|
||||
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.
|
||||
|
||||
@skip merge(planes
|
||||
@until #endif
|
||||
@snippet interoperability_with_OpenCV_1.cpp end
|
||||
|
||||
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
|
||||
@@ -140,7 +132,7 @@ output:
|
||||
|
||||
You may observe a runtime instance of this on the [YouTube
|
||||
here](https://www.youtube.com/watch?v=qckm-zvo31w) and you can [download the source code from here
|
||||
](samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp)
|
||||
](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp)
|
||||
or find it in the
|
||||
`samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp`
|
||||
of the OpenCV source code library.
|
||||
|
@@ -133,7 +133,7 @@ For example:
|
||||

|
||||
|
||||
You can download this source code from [here
|
||||
](samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp) or look in the
|
||||
](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp) or look in the
|
||||
OpenCV source code libraries sample directory at
|
||||
`samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp`.
|
||||
|
||||
|
@@ -144,16 +144,13 @@ file by using the @ref cv::imwrite() function. However, for debugging purposes i
|
||||
convenient to see the actual values. You can do this using the \<\< operator of *Mat*. Be aware that
|
||||
this only works for two dimensional matrices.
|
||||
|
||||
@dontinclude cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp
|
||||
|
||||
Although *Mat* works really well as an 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:
|
||||
|
||||
- @ref cv::Mat::Mat Constructor
|
||||
|
||||
@skip Mat M(2
|
||||
@until cout
|
||||
@snippet mat_the_basic_image_container.cpp constructor
|
||||
|
||||

|
||||
|
||||
@@ -162,7 +159,7 @@ object in multiple ways:
|
||||
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 constructed according to the following
|
||||
convention:
|
||||
@code{.cpp}
|
||||
@code
|
||||
CV_[The number of bits per item][Signed or Unsigned][Type Prefix]C[The channel number]
|
||||
@endcode
|
||||
For instance, *CV_8UC3* means we use unsigned char types that are 8 bit long and each pixel has
|
||||
@@ -173,18 +170,15 @@ object in multiple ways:
|
||||
|
||||
- Use C/C++ arrays and initialize via constructor
|
||||
|
||||
@skip int sz
|
||||
@until Mat L
|
||||
@snippet mat_the_basic_image_container.cpp init
|
||||
|
||||
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.
|
||||
|
||||
- @ref cv::Mat::create function:
|
||||
@code
|
||||
M.create(4,4, CV_8UC(2));
|
||||
cout << "M = "<< endl << " " << M << endl << endl;
|
||||
@endcode
|
||||
|
||||
@snippet mat_the_basic_image_container.cpp create
|
||||
|
||||

|
||||
|
||||
@@ -194,30 +188,26 @@ object in multiple ways:
|
||||
- MATLAB style initializer: @ref cv::Mat::zeros , @ref cv::Mat::ones , @ref cv::Mat::eye . Specify size and
|
||||
data type to use:
|
||||
|
||||
@skip Mat E
|
||||
@until cout
|
||||
@snippet mat_the_basic_image_container.cpp matlab
|
||||
|
||||

|
||||
|
||||
- For small matrices you may use comma separated initializers:
|
||||
|
||||
@skip Mat C
|
||||
@until cout
|
||||
@snippet mat_the_basic_image_container.cpp comma
|
||||
|
||||

|
||||
|
||||
- Create a new header for an existing *Mat* object and @ref cv::Mat::clone or @ref cv::Mat::copyTo it.
|
||||
|
||||
@skip Mat RowClone
|
||||
@until cout
|
||||
@snippet mat_the_basic_image_container.cpp clone
|
||||
|
||||

|
||||
|
||||
@note
|
||||
You can fill out a matrix with random values using the @ref cv::randu() function. You need to
|
||||
give the lower and upper value for the random values:
|
||||
@skip Mat R
|
||||
@until randu
|
||||
@snippet mat_the_basic_image_container.cpp random
|
||||
|
||||
|
||||
Output formatting
|
||||
@@ -227,25 +217,23 @@ In the above examples you could see the default formatting option. OpenCV, howev
|
||||
format your matrix output:
|
||||
|
||||
- Default
|
||||
@skipline (default)
|
||||
@snippet mat_the_basic_image_container.cpp out-default
|
||||

|
||||
|
||||
- Python
|
||||
@skipline (python)
|
||||
@snippet mat_the_basic_image_container.cpp out-python
|
||||

|
||||
|
||||
- Comma separated values (CSV)
|
||||
@skipline (csv)
|
||||
@snippet mat_the_basic_image_container.cpp out-csv
|
||||

|
||||
|
||||
- Numpy
|
||||
@code
|
||||
cout << "R (numpy) = " << endl << format(R, Formatter::FMT_NUMPY ) << endl << endl;
|
||||
@endcode
|
||||
@snippet mat_the_basic_image_container.cpp out-numpy
|
||||

|
||||
|
||||
- C
|
||||
@skipline (c)
|
||||
@snippet mat_the_basic_image_container.cpp out-c
|
||||

|
||||
|
||||
Output of other common items
|
||||
@@ -254,27 +242,23 @@ Output of other common items
|
||||
OpenCV offers support for output of other common OpenCV data structures too via the \<\< operator:
|
||||
|
||||
- 2D Point
|
||||
@skip Point2f P
|
||||
@until cout
|
||||
@snippet mat_the_basic_image_container.cpp out-point2
|
||||

|
||||
|
||||
- 3D Point
|
||||
@skip Point3f P3f
|
||||
@until cout
|
||||
@snippet mat_the_basic_image_container.cpp out-point3
|
||||

|
||||
|
||||
- std::vector via cv::Mat
|
||||
@skip vector<float> v
|
||||
@until cout
|
||||
@snippet mat_the_basic_image_container.cpp out-vector
|
||||

|
||||
|
||||
- std::vector of points
|
||||
@skip vector<Point2f> vPoints
|
||||
@until cout
|
||||
@snippet mat_the_basic_image_container.cpp out-vector-points
|
||||

|
||||
|
||||
Most of the samples here have been included in a small console application. You can download it from
|
||||
[here](samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp)
|
||||
[here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp)
|
||||
or in the core section of the cpp samples.
|
||||
|
||||
You can also find a quick video demonstration of this on
|
||||
|
Reference in New Issue
Block a user