mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
How to use the OpenCV parallel_for_ to parallelize your code {#tutorial_how_to_use_OpenCV_parallel_for_}
|
||||
==================================================================
|
||||
|
||||
@prev_tutorial{tutorial_how_to_use_ippa_conversion}
|
||||
@prev_tutorial{tutorial_interoperability_with_OpenCV_1}
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
@@ -1,146 +0,0 @@
|
||||
Intel® IPP Asynchronous C/C++ library in OpenCV {#tutorial_how_to_use_ippa_conversion}
|
||||
===============================================
|
||||
|
||||
@prev_tutorial{tutorial_interoperability_with_OpenCV_1}
|
||||
@next_tutorial{tutorial_how_to_use_OpenCV_parallel_for_}
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
The tutorial demonstrates the [Intel® IPP Asynchronous
|
||||
C/C++](http://software.intel.com/en-us/intel-ipp-preview) library usage with OpenCV. The code
|
||||
example below illustrates implementation of the Sobel operation, accelerated with Intel® IPP
|
||||
Asynchronous C/C++ functions. In this code example, @ref cv::hpp::getMat and @ref cv::hpp::getHpp
|
||||
functions are used for data conversion between
|
||||
[hppiMatrix](http://software.intel.com/en-us/node/501660) and Mat matrices.
|
||||
|
||||
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](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp).
|
||||
|
||||
@include cpp/tutorial_code/core/ippasync/ippasync_sample.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
-# Create parameters for OpenCV:
|
||||
@code{.cpp}
|
||||
VideoCapture cap;
|
||||
Mat image, gray, result;
|
||||
@endcode
|
||||
and IPP Async:
|
||||
@code{.cpp}
|
||||
hppiMatrix* src,* dst;
|
||||
hppAccel accel = 0;
|
||||
hppAccelType accelType;
|
||||
hppStatus sts;
|
||||
hppiVirtualMatrix * virtMatrix;
|
||||
@endcode
|
||||
-# Load input image or video. How to open and read video stream you can see in the
|
||||
@ref tutorial_video_input_psnr_ssim tutorial.
|
||||
@code{.cpp}
|
||||
if( useCamera )
|
||||
{
|
||||
printf("used camera\n");
|
||||
cap.open(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("used image %s\n", file.c_str());
|
||||
cap.open(file.c_str());
|
||||
}
|
||||
|
||||
if( !cap.isOpened() )
|
||||
{
|
||||
printf("can not open camera or video file\n");
|
||||
return -1;
|
||||
}
|
||||
@endcode
|
||||
-# Create accelerator instance using
|
||||
[hppCreateInstance](http://software.intel.com/en-us/node/501686):
|
||||
@code{.cpp}
|
||||
accelType = sAccel == "cpu" ? HPP_ACCEL_TYPE_CPU:
|
||||
sAccel == "gpu" ? HPP_ACCEL_TYPE_GPU:
|
||||
HPP_ACCEL_TYPE_ANY;
|
||||
|
||||
//Create accelerator instance
|
||||
sts = hppCreateInstance(accelType, 0, &accel);
|
||||
CHECK_STATUS(sts, "hppCreateInstance");
|
||||
@endcode
|
||||
-# Create an array of virtual matrices using
|
||||
[hppiCreateVirtualMatrices](http://software.intel.com/en-us/node/501700) function.
|
||||
@code{.cpp}
|
||||
virtMatrix = hppiCreateVirtualMatrices(accel, 1);
|
||||
@endcode
|
||||
-# Prepare a matrix for input and output data:
|
||||
@code{.cpp}
|
||||
cap >> image;
|
||||
if(image.empty())
|
||||
break;
|
||||
|
||||
cvtColor( image, gray, COLOR_BGR2GRAY );
|
||||
|
||||
result.create( image.rows, image.cols, CV_8U);
|
||||
@endcode
|
||||
-# Convert Mat to [hppiMatrix](http://software.intel.com/en-us/node/501660) using @ref cv::hpp::getHpp
|
||||
and call [hppiSobel](http://software.intel.com/en-us/node/474701) function.
|
||||
@code{.cpp}
|
||||
//convert Mat to hppiMatrix
|
||||
src = getHpp(gray, accel);
|
||||
dst = getHpp(result, accel);
|
||||
|
||||
sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]);
|
||||
CHECK_STATUS(sts,"hppiSobel");
|
||||
|
||||
sts = hppiConvert(accel, virtMatrix[0], 0, HPP_RND_MODE_NEAR, dst, HPP_DATA_TYPE_8U);
|
||||
CHECK_STATUS(sts,"hppiConvert");
|
||||
|
||||
// Wait for tasks to complete
|
||||
sts = hppWait(accel, HPP_TIME_OUT_INFINITE);
|
||||
CHECK_STATUS(sts, "hppWait");
|
||||
@endcode
|
||||
We use [hppiConvert](http://software.intel.com/en-us/node/501746) because
|
||||
[hppiSobel](http://software.intel.com/en-us/node/474701) returns destination matrix with
|
||||
HPP_DATA_TYPE_16S data type for source matrix with HPP_DATA_TYPE_8U type. You should check
|
||||
hppStatus after each call IPP Async function.
|
||||
|
||||
-# Create windows and show the images, the usual way.
|
||||
@code{.cpp}
|
||||
imshow("image", image);
|
||||
imshow("rez", result);
|
||||
|
||||
waitKey(15);
|
||||
@endcode
|
||||
-# Delete hpp matrices.
|
||||
@code{.cpp}
|
||||
sts = hppiFreeMatrix(src);
|
||||
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||
|
||||
sts = hppiFreeMatrix(dst);
|
||||
CHECK_DEL_STATUS(sts,"hppiFreeMatrix");
|
||||
@endcode
|
||||
-# Delete virtual matrices and accelerator instance.
|
||||
@code{.cpp}
|
||||
if (virtMatrix)
|
||||
{
|
||||
sts = hppiDeleteVirtualMatrices(accel, virtMatrix);
|
||||
CHECK_DEL_STATUS(sts,"hppiDeleteVirtualMatrices");
|
||||
}
|
||||
|
||||
if (accel)
|
||||
{
|
||||
sts = hppDeleteInstance(accel);
|
||||
CHECK_DEL_STATUS(sts, "hppDeleteInstance");
|
||||
}
|
||||
@endcode
|
||||
|
||||
Result
|
||||
------
|
||||
|
||||
After compiling the code above we can execute it giving an image or video path and accelerator type
|
||||
as an argument. For this tutorial we use baboon.png image as input. The result is below.
|
||||
|
||||

|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 61 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.8 KiB |
+1
-1
@@ -2,7 +2,7 @@ Interoperability with OpenCV 1 {#tutorial_interoperability_with_OpenCV_1}
|
||||
==============================
|
||||
|
||||
@prev_tutorial{tutorial_file_input_output_with_xml_yml}
|
||||
@next_tutorial{tutorial_how_to_use_ippa_conversion}
|
||||
@next_tutorial{tutorial_how_to_use_OpenCV_parallel_for_}
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
@@ -93,15 +93,6 @@ understanding how to manipulate the images on a pixel level.
|
||||
Look here to shed light on all this questions.
|
||||
|
||||
|
||||
- @subpage tutorial_how_to_use_ippa_conversion
|
||||
|
||||
*Compatibility:* \> OpenCV 2.0
|
||||
|
||||
*Author:* Elena Gvozdeva
|
||||
|
||||
You will see how to use the IPP Async with OpenCV.
|
||||
|
||||
|
||||
- @subpage tutorial_how_to_use_OpenCV_parallel_for_
|
||||
|
||||
*Compatibility:* \>= OpenCV 2.4.3
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 556 B |
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,72 @@
|
||||
Motion Deblur Filter {#tutorial_motion_deblur_filter}
|
||||
==========================
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
In this tutorial you will learn:
|
||||
|
||||
- what the PSF of a motion blur image is
|
||||
- how to restore a motion blur image
|
||||
|
||||
Theory
|
||||
------
|
||||
|
||||
For the degradation image model theory and the Wiener filter theory you can refer to the tutorial @ref tutorial_out_of_focus_deblur_filter "Out-of-focus Deblur Filter".
|
||||
On this page only a linear motion blur distortion is considered. The motion blur image on this page is a real world image. The blur was caused by a moving subject.
|
||||
|
||||
### What is the PSF of a motion blur image?
|
||||
|
||||
The point spread function (PSF) of a linear motion blur distortion is a line segment. Such a PSF is specified by two parameters: \f$LEN\f$ is the length of the blur and \f$THETA\f$ is the angle of motion.
|
||||
|
||||

|
||||
|
||||
### How to restore a blurred image?
|
||||
|
||||
On this page the Wiener filter is used as the restoration filter, for details you can refer to the tutorial @ref tutorial_out_of_focus_deblur_filter "Out-of-focus Deblur Filter".
|
||||
In order to synthesize the Wiener filter for a motion blur case, it needs to specify the signal-to-noise ratio (\f$SNR\f$), \f$LEN\f$ and \f$THETA\f$ of the PSF.
|
||||
|
||||
Source code
|
||||
-----------
|
||||
|
||||
You can find source code in the `samples/cpp/tutorial_code/ImgProc/motion_deblur_filter/motion_deblur_filter.cpp` of the OpenCV source code library.
|
||||
|
||||
@include cpp/tutorial_code/ImgProc/motion_deblur_filter/motion_deblur_filter.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
A motion blur image recovering algorithm consists of PSF generation, Wiener filter generation and filtering a blurred image in a frequency domain:
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/motion_deblur_filter/motion_deblur_filter.cpp main
|
||||
|
||||
A function calcPSF() forms a PSF according to input parameters \f$LEN\f$ and \f$THETA\f$ (in degrees):
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/motion_deblur_filter/motion_deblur_filter.cpp calcPSF
|
||||
|
||||
A function edgetaper() tapers the input image’s edges in order to reduce the ringing effect in a restored image:
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/motion_deblur_filter/motion_deblur_filter.cpp edgetaper
|
||||
|
||||
The functions calcWnrFilter(), fftshift() and filter2DFreq() realize an image filtration by a specified PSF in the frequency domain. The functions are copied from the tutorial
|
||||
@ref tutorial_out_of_focus_deblur_filter "Out-of-focus Deblur Filter".
|
||||
|
||||
Result
|
||||
------
|
||||
|
||||
Below you can see the real world image with motion blur distortion. The license plate is not readable on both cars. The red markers show the car’s license plate location.
|
||||

|
||||
|
||||
|
||||
Below you can see the restoration result for the black car license plate. The result has been computed with \f$LEN\f$ = 125, \f$THETA\f$ = 0, \f$SNR\f$ = 700.
|
||||

|
||||
|
||||
Below you can see the restoration result for the white car license plate. The result has been computed with \f$LEN\f$ = 78, \f$THETA\f$ = 15, \f$SNR\f$ = 300.
|
||||

|
||||
|
||||
The values of \f$SNR\f$, \f$LEN\f$ and \f$THETA\f$ were selected manually to give the best possible visual result. The \f$THETA\f$ parameter coincides with the car’s moving direction, and the
|
||||
\f$LEN\f$ parameter depends on the car’s moving speed.
|
||||
The result is not perfect, but at least it gives us a hint of the image’s content. With some effort, the car license plate is now readable.
|
||||
|
||||
@note The parameters \f$LEN\f$ and \f$THETA\f$ are the most important. You should adjust \f$LEN\f$ and \f$THETA\f$ first, then \f$SNR\f$.
|
||||
|
||||
You can also find a quick video demonstration of a license plate recovering method
|
||||
[YouTube](https://youtu.be/xSrE0hdhb4o).
|
||||
@youtube{xSrE0hdhb4o}
|
||||
+26
-26
@@ -8,54 +8,54 @@ Goal
|
||||
|
||||
In this tutorial you will learn:
|
||||
|
||||
- what is a degradation image model
|
||||
- what is PSF of out-of-focus image
|
||||
- what a degradation image model is
|
||||
- what the PSF of an out-of-focus image is
|
||||
- how to restore a blurred image
|
||||
- what is Wiener filter
|
||||
- what is a Wiener filter
|
||||
|
||||
Theory
|
||||
------
|
||||
|
||||
@note The explanation is based on the books @cite gonzalez and @cite gruzman. Also, you can refer to Matlab's tutorial [Image Deblurring in Matlab] and an article [SmartDeblur].
|
||||
@note An out-of-focus image on this page is a real world image. An out-of-focus was done manually by camera optics.
|
||||
@note The explanation is based on the books @cite gonzalez and @cite gruzman. Also, you can refer to Matlab's tutorial [Image Deblurring in Matlab] and the article [SmartDeblur].
|
||||
@note The out-of-focus image on this page is a real world image. The out-of-focus was achieved manually by camera optics.
|
||||
|
||||
### What is a degradation image model?
|
||||
|
||||
A mathematical model of the image degradation in frequency domain representation is:
|
||||
Here is a mathematical model of the image degradation in frequency domain representation:
|
||||
|
||||
\f[S = H\cdot U + N\f]
|
||||
|
||||
where
|
||||
\f$S\f$ is a spectrum of blurred (degraded) image,
|
||||
\f$U\f$ is a spectrum of original true (undegraded) image,
|
||||
\f$H\f$ is frequency response of point spread function (PSF),
|
||||
\f$H\f$ is a frequency response of point spread function (PSF),
|
||||
\f$N\f$ is a spectrum of additive noise.
|
||||
|
||||
Circular PSF is a good approximation of out-of-focus distortion. Such PSF is specified by only one parameter - radius \f$R\f$. Circular PSF is used in this work.
|
||||
The circular PSF is a good approximation of out-of-focus distortion. Such a PSF is specified by only one parameter - radius \f$R\f$. Circular PSF is used in this work.
|
||||
|
||||

|
||||
|
||||
### How to restore an blurred image?
|
||||
### How to restore a blurred image?
|
||||
|
||||
The objective of restoration (deblurring) is to obtain an estimate of the original image. Restoration formula in frequency domain is:
|
||||
The objective of restoration (deblurring) is to obtain an estimate of the original image. The restoration formula in frequency domain is:
|
||||
|
||||
\f[U' = H_w\cdot S\f]
|
||||
|
||||
where
|
||||
\f$U'\f$ is spectrum of estimation of original image \f$U\f$,
|
||||
\f$H_w\f$ is restoration filter, for example, Wiener filter.
|
||||
\f$U'\f$ is the spectrum of estimation of original image \f$U\f$, and
|
||||
\f$H_w\f$ is the restoration filter, for example, the Wiener filter.
|
||||
|
||||
### What is Wiener filter?
|
||||
### What is the Wiener filter?
|
||||
|
||||
Wiener filter is a way to restore a blurred image. Let's suppose that PSF is a real and symmetric signal, a power spectrum of the original true image and noise are not known,
|
||||
then simplified Wiener formula is:
|
||||
The Wiener filter is a way to restore a blurred image. Let's suppose that the PSF is a real and symmetric signal, a power spectrum of the original true image and noise are not known,
|
||||
then a simplified Wiener formula is:
|
||||
|
||||
\f[H_w = \frac{H}{|H|^2+\frac{1}{SNR}} \f]
|
||||
|
||||
where
|
||||
\f$SNR\f$ is signal-to-noise ratio.
|
||||
|
||||
So, in order to recover an out-of-focus image by Wiener filter, it needs to know \f$SNR\f$ and \f$R\f$ of circular PSF.
|
||||
So, in order to recover an out-of-focus image by Wiener filter, it needs to know the \f$SNR\f$ and \f$R\f$ of the circular PSF.
|
||||
|
||||
|
||||
Source code
|
||||
@@ -68,36 +68,36 @@ You can find source code in the `samples/cpp/tutorial_code/ImgProc/out_of_focus_
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
An out-of-focus image recovering algorithm consists of PSF generation, Wiener filter generation and filtering an blurred image in frequency domain:
|
||||
An out-of-focus image recovering algorithm consists of PSF generation, Wiener filter generation and filtering a blurred image in frequency domain:
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp main
|
||||
|
||||
A function calcPSF() forms an circular PSF according to input parameter radius \f$R\f$:
|
||||
A function calcPSF() forms a circular PSF according to input parameter radius \f$R\f$:
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp calcPSF
|
||||
|
||||
A function calcWnrFilter() synthesizes simplified Wiener filter \f$H_w\f$ according to formula described above:
|
||||
A function calcWnrFilter() synthesizes the simplified Wiener filter \f$H_w\f$ according to the formula described above:
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp calcWnrFilter
|
||||
|
||||
A function fftshift() rearranges PSF. This code was just copied from tutorial @ref tutorial_discrete_fourier_transform "Discrete Fourier Transform":
|
||||
A function fftshift() rearranges the PSF. This code was just copied from the tutorial @ref tutorial_discrete_fourier_transform "Discrete Fourier Transform":
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp fftshift
|
||||
|
||||
A function filter2DFreq() filters an blurred image in frequency domain:
|
||||
A function filter2DFreq() filters the blurred image in the frequency domain:
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/out_of_focus_deblur_filter/out_of_focus_deblur_filter.cpp filter2DFreq
|
||||
|
||||
Result
|
||||
------
|
||||
|
||||
Below you can see real out-of-focus image:
|
||||
Below you can see the real out-of-focus image:
|
||||

|
||||
|
||||
|
||||
Below result was done by \f$R\f$ = 53 and \f$SNR\f$ = 5200 parameters:
|
||||
And the following result has been computed with \f$R\f$ = 53 and \f$SNR\f$ = 5200 parameters:
|
||||

|
||||
|
||||
The Wiener filter was used, values of \f$R\f$ and \f$SNR\f$ were selected manually to give the best possible visual result.
|
||||
We can see that the result is not perfect, but it gives us a hint to the image content. With some difficulty, the text is readable.
|
||||
The Wiener filter was used, and values of \f$R\f$ and \f$SNR\f$ were selected manually to give the best possible visual result.
|
||||
We can see that the result is not perfect, but it gives us a hint to the image's content. With some difficulty, the text is readable.
|
||||
|
||||
@note The parameter \f$R\f$ is the most important. So you should adjust \f$R\f$ first, then \f$SNR\f$.
|
||||
@note Sometimes you can observe the ringing effect in an restored image. This effect can be reduced by several methods. For example, you can taper input image edges.
|
||||
@note Sometimes you can observe the ringing effect in a restored image. This effect can be reduced with several methods. For example, you can taper input image edges.
|
||||
|
||||
You can also find a quick video demonstration of this on
|
||||
[YouTube](https://youtu.be/0bEcE4B0XP4).
|
||||
|
||||
@@ -320,3 +320,13 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
*Author:* Karpushin Vladislav
|
||||
|
||||
You will learn how to recover an out-of-focus image by Wiener filter.
|
||||
|
||||
- @subpage tutorial_motion_deblur_filter
|
||||
|
||||
*Languages:* C++
|
||||
|
||||
*Compatibility:* \> OpenCV 2.0
|
||||
|
||||
*Author:* Karpushin Vladislav
|
||||
|
||||
You will learn how to recover an image with motion blur distortion using a Wiener filter.
|
||||
|
||||
@@ -142,8 +142,6 @@ of them, you need to download and install them on your system.
|
||||
- [Intel Integrated Performance Primitives (*IPP*)](http://software.intel.com/en-us/articles/intel-ipp/) may be used to improve the performance
|
||||
of color conversion, Haar training and DFT functions of the OpenCV library. Watch out, since
|
||||
this is not a free service.
|
||||
- [Intel IPP Asynchronous C/C++](http://software.intel.com/en-us/intel-ipp-preview) is currently focused delivering Intel Graphics
|
||||
support for advanced image processing and computer vision functions.
|
||||
- OpenCV offers a somewhat fancier and more useful graphical user interface, than the default one
|
||||
by using the [Qt framework](http://qt.nokia.com/downloads). For a quick overview of what this has to offer, look into the
|
||||
documentations *highgui* module, under the *Qt New Functions* section. Version 4.6 or later of
|
||||
@@ -204,10 +202,6 @@ libraries). If you do not need the support for some of these, you can just freel
|
||||
|
||||

|
||||
|
||||
-# For the [Intel IPP Asynchronous C/C++](http://software.intel.com/en-us/intel-ipp-preview) download the source files and set environment
|
||||
variable **IPP_ASYNC_ROOT**. It should point to
|
||||
`<your Program Files(x86) directory>/Intel/IPP Preview */ipp directory`. Here \* denotes the
|
||||
particular preview name.
|
||||
-# In case of the [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page#Download) library it is again a case of download and extract to the
|
||||
`D:/OpenCV/dep` directory.
|
||||
-# Same as above with [OpenEXR](http://www.openexr.com/downloads.html).
|
||||
@@ -319,6 +313,7 @@ libraries). If you do not need the support for some of these, you can just freel
|
||||
you are concerned about performance, build them and run.
|
||||
- *BUILD_opencv_python* -\> Self-explanatory. Create the binaries to use OpenCV from the
|
||||
Python language.
|
||||
- *BUILD_opencv_world* -\> Generate a single "opencv_world" binary (a shared or static library, depending on *BUILD_SHARED_LIBS*) including all the modules instead of a collection of separate binaries, one binary per module.
|
||||
|
||||
Press again the *Configure* button and ensure no errors are reported. If this is the case, you
|
||||
can tell CMake to create the project files by pushing the *Generate* button. Go to the build
|
||||
|
||||
Reference in New Issue
Block a user