mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #8253 from adl1995:master
* Update linux_install.markdown Grammar improvements, fixed typos. * Update tutorials.markdown Improvements in grammar. * Update table_of_content_calib3d.markdown * Update camera_calibration_square_chess.markdown Improvements in grammar. Added answer. * Update tutorials.markdown * Update erosion_dilatation.markdown * Update table_of_content_imgproc.markdown * Update warp_affine.markdown * Update camera_calibration_square_chess.markdown Removed extra space. * Update gpu_basics_similarity.markdown Grammatical improvements, fixed typos. * Update trackbar.markdown Improvement for better understanding.
This commit is contained in:
committed by
Alexander Alekhin
parent
da0b1d8821
commit
bc7f6fc44c
@@ -6,12 +6,12 @@ Goal
|
||||
|
||||
In this tutorial you will learn how to:
|
||||
|
||||
- Apply two very common morphology operators: Dilation and Erosion. For this purpose, you will use
|
||||
- Apply two very common morphological operators: Erosion and Dilation. For this purpose, you will use
|
||||
the following OpenCV functions:
|
||||
- @ref cv::erode
|
||||
- @ref cv::dilate
|
||||
|
||||
Cool Theory
|
||||
Interesting fact
|
||||
-----------
|
||||
|
||||
@note The explanation below belongs to the book **Learning OpenCV** by Bradski and Kaehler.
|
||||
@@ -21,7 +21,7 @@ Morphological Operations
|
||||
|
||||
- In short: A set of operations that process images based on shapes. Morphological operations
|
||||
apply a *structuring element* to an input image and generate an output image.
|
||||
- The most basic morphological operations are two: Erosion and Dilation. They have a wide array of
|
||||
- The most basic morphological operations are: Erosion and Dilation. They have a wide array of
|
||||
uses, i.e. :
|
||||
- Removing noise
|
||||
- Isolation of individual elements and joining disparate elements in an image.
|
||||
@@ -32,19 +32,19 @@ Morphological Operations
|
||||
|
||||
### Dilation
|
||||
|
||||
- This operations consists of convoluting an image \f$A\f$ with some kernel (\f$B\f$), which can have any
|
||||
- This operations consists of convolving an image \f$A\f$ with some kernel (\f$B\f$), which can have any
|
||||
shape or size, usually a square or circle.
|
||||
- The kernel \f$B\f$ has a defined *anchor point*, usually being the center of the kernel.
|
||||
- As the kernel \f$B\f$ is scanned over the image, we compute the maximal pixel value overlapped by
|
||||
\f$B\f$ and replace the image pixel in the anchor point position with that maximal value. As you can
|
||||
deduce, this maximizing operation causes bright regions within an image to "grow" (therefore the
|
||||
name *dilation*). Take as an example the image above. Applying dilation we can get:
|
||||
name *dilation*). Take the above image as an example. Applying dilation we can get:
|
||||
|
||||

|
||||
|
||||
The background (bright) dilates around the black regions of the letter.
|
||||
|
||||
To better grasp the idea and avoid possible confusion, in this another example we have inverted the original
|
||||
To better grasp the idea and avoid possible confusion, in this other example we have inverted the original
|
||||
image such as the object in white is now the letter. We have performed two dilatations with a rectangular
|
||||
structuring element of size `3x3`.
|
||||
|
||||
@@ -54,8 +54,8 @@ The dilatation makes the object in white bigger.
|
||||
|
||||
### Erosion
|
||||
|
||||
- This operation is the sister of dilation. What this does is to compute a local minimum over the
|
||||
area of the kernel.
|
||||
- This operation is the sister of dilation. It computes a local minimum over the
|
||||
area of given kernel.
|
||||
- As the kernel \f$B\f$ is scanned over the image, we compute the minimal pixel value overlapped by
|
||||
\f$B\f$ and replace the image pixel under the anchor point with that minimal value.
|
||||
- Analagously to the example for dilation, we can apply the erosion operator to the original image
|
||||
@@ -64,7 +64,7 @@ The dilatation makes the object in white bigger.
|
||||
|
||||

|
||||
|
||||
In the same manner, the corresponding image resulting of the erosion operation on the inverted original image (two erosions
|
||||
In similar manner, the corresponding image results by applying erosion operation on the inverted original image (two erosions
|
||||
with a rectangular structuring element of size `3x3`):
|
||||
|
||||

|
||||
@@ -74,14 +74,14 @@ The erosion makes the object in white smaller.
|
||||
Code
|
||||
----
|
||||
|
||||
This tutorial code's is shown lines below. You can also download it from
|
||||
This tutorial's code is shown below. You can also download it
|
||||
[here](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp)
|
||||
@include samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
-# Most of the stuff shown is known by you (if you have any doubt, please refer to the tutorials in
|
||||
-# Most of the material shown here is trivial (if you have any doubt, please refer to the tutorials in
|
||||
previous sections). Let's check the general structure of the program:
|
||||
|
||||
- Load an image (can be BGR or grayscale)
|
||||
@@ -118,8 +118,8 @@ Explanation
|
||||
|
||||
- That is all. We are ready to perform the erosion of our image.
|
||||
@note Additionally, there is another parameter that allows you to perform multiple erosions
|
||||
(iterations) at once. We are not using it in this simple tutorial, though. You can check out the
|
||||
Reference for more details.
|
||||
(iterations) at once. However, We haven't used it in this simple tutorial. You can check out the
|
||||
reference for more details.
|
||||
|
||||
-# **dilation:**
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ Theory
|
||||
|
||||
### What is an Affine Transformation?
|
||||
|
||||
-# It is any transformation that can be expressed in the form of a *matrix multiplication* (linear
|
||||
-# A transformation that can be expressed in the form of a *matrix multiplication* (linear
|
||||
transformation) followed by a *vector addition* (translation).
|
||||
-# From the above, We can use an Affine Transformation to express:
|
||||
-# From the above, we can use an Affine Transformation to express:
|
||||
|
||||
-# Rotations (linear transformation)
|
||||
-# Translations (vector addition)
|
||||
@@ -25,7 +25,7 @@ Theory
|
||||
you can see that, in essence, an Affine Transformation represents a **relation** between two
|
||||
images.
|
||||
|
||||
-# The usual way to represent an Affine Transform is by using a \f$2 \times 3\f$ matrix.
|
||||
-# The usual way to represent an Affine Transformation is by using a \f$2 \times 3\f$ matrix.
|
||||
|
||||
\f[
|
||||
A = \begin{bmatrix}
|
||||
@@ -49,7 +49,7 @@ Theory
|
||||
\f]
|
||||
|
||||
Considering that we want to transform a 2D vector \f$X = \begin{bmatrix}x \\ y\end{bmatrix}\f$ by
|
||||
using \f$A\f$ and \f$B\f$, we can do it equivalently with:
|
||||
using \f$A\f$ and \f$B\f$, we can do the same with:
|
||||
|
||||
\f$T = A \cdot \begin{bmatrix}x \\ y\end{bmatrix} + B\f$ or \f$T = M \cdot [x, y, 1]^{T}\f$
|
||||
|
||||
@@ -60,35 +60,35 @@ Theory
|
||||
|
||||
### How do we get an Affine Transformation?
|
||||
|
||||
-# Excellent question. We mentioned that an Affine Transformation is basically a **relation**
|
||||
-# We mentioned that an Affine Transformation is basically a **relation**
|
||||
between two images. The information about this relation can come, roughly, in two ways:
|
||||
-# We know both \f$X\f$ and T and we also know that they are related. Then our job is to find \f$M\f$
|
||||
-# We know both \f$X\f$ and T and we also know that they are related. Then our task is to find \f$M\f$
|
||||
-# We know \f$M\f$ and \f$X\f$. To obtain \f$T\f$ we only need to apply \f$T = M \cdot X\f$. Our information
|
||||
for \f$M\f$ may be explicit (i.e. have the 2-by-3 matrix) or it can come as a geometric relation
|
||||
between points.
|
||||
|
||||
-# Let's explain a little bit better (b). Since \f$M\f$ relates 02 images, we can analyze the simplest
|
||||
-# Let's explain this in a better way (b). Since \f$M\f$ relates 2 images, we can analyze the simplest
|
||||
case in which it relates three points in both images. Look at the figure below:
|
||||
|
||||

|
||||
|
||||
the points 1, 2 and 3 (forming a triangle in image 1) are mapped into image 2, still forming a
|
||||
triangle, but now they have changed notoriously. If we find the Affine Transformation with these
|
||||
3 points (you can choose them as you like), then we can apply this found relation to the whole
|
||||
pixels in the image.
|
||||
3 points (you can choose them as you like), then we can apply this found relation to all the
|
||||
pixels in an image.
|
||||
|
||||
Code
|
||||
----
|
||||
|
||||
-# **What does this program do?**
|
||||
- Loads an image
|
||||
- Applies an Affine Transform to the image. This Transform is obtained from the relation
|
||||
- Applies an Affine Transform to the image. This transform is obtained from the relation
|
||||
between three points. We use the function @ref cv::warpAffine for that purpose.
|
||||
- Applies a Rotation to the image after being transformed. This rotation is with respect to
|
||||
the image center
|
||||
- Waits until the user exits the program
|
||||
|
||||
-# The tutorial code's is shown lines below. You can also download it from
|
||||
-# The tutorial's code is shown below. You can also download it here
|
||||
[here](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp)
|
||||
@include samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp
|
||||
|
||||
@@ -113,10 +113,10 @@ Explanation
|
||||
@code{.cpp}
|
||||
warp_dst = Mat::zeros( src.rows, src.cols, src.type() );
|
||||
@endcode
|
||||
-# **Affine Transform:** As we explained lines above, we need two sets of 3 points to derive the
|
||||
affine transform relation. Take a look:
|
||||
-# **Affine Transform:** As we explained in lines above, we need two sets of 3 points to derive the
|
||||
affine transform relation. Have a look:
|
||||
@code{.cpp}
|
||||
srcTri[0] = Point2f( 0,0 );
|
||||
srcTri[0] = Point2f( 0, 0 );
|
||||
srcTri[1] = Point2f( src.cols - 1, 0 );
|
||||
srcTri[2] = Point2f( 0, src.rows - 1 );
|
||||
|
||||
@@ -124,7 +124,7 @@ Explanation
|
||||
dstTri[1] = Point2f( src.cols*0.85, src.rows*0.25 );
|
||||
dstTri[2] = Point2f( src.cols*0.15, src.rows*0.7 );
|
||||
@endcode
|
||||
You may want to draw the points to make a better idea of how they change. Their locations are
|
||||
You may want to draw these points to get a better idea on how they change. Their locations are
|
||||
approximately the same as the ones depicted in the example figure (in the Theory section). You
|
||||
may note that the size and orientation of the triangle defined by the 3 points change.
|
||||
|
||||
@@ -133,9 +133,9 @@ Explanation
|
||||
@code{.cpp}
|
||||
warp_mat = getAffineTransform( srcTri, dstTri );
|
||||
@endcode
|
||||
We get as an output a \f$2 \times 3\f$ matrix (in this case **warp_mat**)
|
||||
We get a \f$2 \times 3\f$ matrix as an output (in this case **warp_mat**)
|
||||
|
||||
-# We apply the Affine Transform just found to the src image
|
||||
-# We then apply the Affine Transform just found to the src image
|
||||
@code{.cpp}
|
||||
warpAffine( src, warp_dst, warp_mat, warp_dst.size() );
|
||||
@endcode
|
||||
|
||||
@@ -41,7 +41,7 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Theodore Tsesmelis
|
||||
|
||||
Here we will show how we can use different morphology operators to extract horizontal and vertical lines
|
||||
Here we will show how we can use different morphological operators to extract horizontal and vertical lines
|
||||
|
||||
- @subpage tutorial_pyramids
|
||||
|
||||
@@ -57,7 +57,7 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Ana Huamán
|
||||
|
||||
After so much processing, it is time to decide which pixels stay!
|
||||
After so much processing, it is time to decide which pixels stay
|
||||
|
||||
- @subpage tutorial_threshold_inRange
|
||||
|
||||
@@ -81,7 +81,7 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Ana Huamán
|
||||
|
||||
Where we learn how to pad our images!
|
||||
Where we learn how to pad our images
|
||||
|
||||
- @subpage tutorial_sobel_derivatives
|
||||
|
||||
@@ -89,7 +89,7 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Ana Huamán
|
||||
|
||||
Where we learn how to calculate gradients and use them to detect edges!
|
||||
Where we learn how to calculate gradients and use them to detect edges
|
||||
|
||||
- @subpage tutorial_laplace_operator
|
||||
|
||||
@@ -97,7 +97,7 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Ana Huamán
|
||||
|
||||
Where we learn about the *Laplace* operator and how to detect edges with it.
|
||||
Where we learn about the *Laplace* operator and how to detect edges with it
|
||||
|
||||
- @subpage tutorial_canny_detector
|
||||
|
||||
@@ -105,7 +105,7 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Ana Huamán
|
||||
|
||||
Where we learn a sophisticated alternative to detect edges.
|
||||
Where we learn a sophisticated alternative to detect edges
|
||||
|
||||
- @subpage tutorial_hough_lines
|
||||
|
||||
@@ -193,7 +193,7 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Ana Huamán
|
||||
|
||||
Where we learn how to get hull contours and draw them!
|
||||
Where we learn how to get hull contours and draw them
|
||||
|
||||
- @subpage tutorial_bounding_rects_circles
|
||||
|
||||
@@ -201,7 +201,7 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Ana Huamán
|
||||
|
||||
Where we learn how to obtain bounding boxes and circles for our contours.
|
||||
Where we learn how to obtain bounding boxes and circles for our contours
|
||||
|
||||
- @subpage tutorial_bounding_rotated_ellipses
|
||||
|
||||
@@ -209,7 +209,7 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Ana Huamán
|
||||
|
||||
Where we learn how to obtain rotated bounding boxes and ellipses for our contours.
|
||||
Where we learn how to obtain rotated bounding boxes and ellipses for our contours
|
||||
|
||||
- @subpage tutorial_moments
|
||||
|
||||
@@ -233,4 +233,4 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
|
||||
*Author:* Theodore Tsesmelis
|
||||
|
||||
Where we learn to segment objects using Laplacian filtering, the Distance Transformation and the Watershed algorithm.
|
||||
Where we learn to segment objects using Laplacian filtering, the Distance Transformation and the Watershed algorithm.
|
||||
|
||||
Reference in New Issue
Block a user