Deleted all trailing whitespace.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user