Commit a0a46b0d authored by Bernat Gabor's avatar Bernat Gabor

Added a video input tutorial with PSNR and SSIM.

parent caec96a1
......@@ -355,6 +355,7 @@ extlinks = {'cvt_color': ('http://opencv.willowgarage.com/documentation/cpp/imgp
'imgprocfilter':('http://opencv.itseez.com/modules/imgproc/doc/filtering.html#%s', None),
'svms':('http://opencv.itseez.com/modules/ml/doc/support_vector_machines.html#%s', None),
'xmlymlpers':('http://opencv.itseez.com/modules/core/doc/xml_yaml_persistence.html#%s', None),
'huivideo' : ('http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html#%s', None),
'filtering':('http://opencv.itseez.com/modules/imgproc/doc/filtering.html#%s', None),
'point_polygon_test' : ('http://opencv.willowgarage.com/documentation/cpp/imgproc_structural_analysis_and_shape_descriptors.html#cv-pointpolygontest%s', None)
}
......
......@@ -5,6 +5,7 @@
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}
......@@ -14,6 +15,8 @@ This section contains valuable tutorials about how to read/save your image/video
|Beginners_5| *Title:* :ref:`Adding_Trackbars`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_AnaH|
We will learn how to add a Trackbar to our applications
......@@ -23,6 +26,25 @@ This section contains valuable tutorials about how to read/save your image/video
:height: 90pt
:width: 90pt
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
=============== ======================================================
|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.
=============== ======================================================
.. |hVideoInput| image:: images/video-input-psnr-ssim.png
:height: 90pt
:width: 90pt
.. raw:: latex
\pagebreak
......@@ -31,3 +53,4 @@ This section contains valuable tutorials about how to read/save your image/video
:hidden:
../trackbar/trackbar
../video-input-psnr-ssim/video-input-psnr-ssim
// Video Image PSNR and SSIM
#include <iostream> // for standard I/O
#include <string> // for strings
#include <iomanip> // for controlling float print precision
......@@ -38,14 +37,14 @@ int main(int argc, char *argv[], char *window_name)
const string sourceReference = argv[1],sourceCompareWith = argv[2];
int psnrTriggerValue, delay;
conv << argv[3] << argv[4]; // put in the strings
conv << argv[3] << endl << argv[4]; // put in the strings
conv >> psnrTriggerValue >> delay;// take out the numbers
char c;
int frameNum = -1; // Frame counter
VideoCapture captRefrnc(sourceReference),
captUndTst(sourceCompareWith);
captUndTst(sourceCompareWith);
if ( !captRefrnc.isOpened())
{
......@@ -60,9 +59,9 @@ int main(int argc, char *argv[], char *window_name)
}
Size refS = Size((int) captRefrnc.get(CV_CAP_PROP_FRAME_WIDTH),
(int) captRefrnc.get(CV_CAP_PROP_FRAME_HEIGHT)),
uTSi = Size((int) captUndTst.get(CV_CAP_PROP_FRAME_WIDTH),
(int) captUndTst.get(CV_CAP_PROP_FRAME_HEIGHT));
(int) captRefrnc.get(CV_CAP_PROP_FRAME_HEIGHT)),
uTSi = Size((int) captUndTst.get(CV_CAP_PROP_FRAME_WIDTH),
(int) captUndTst.get(CV_CAP_PROP_FRAME_HEIGHT));
if (refS != uTSi)
{
......@@ -74,16 +73,16 @@ int main(int argc, char *argv[], char *window_name)
const char* WIN_RF = "Reference";
// Windows
namedWindow(WIN_RF, CV_WINDOW_AUTOSIZE );
namedWindow(WIN_UT, CV_WINDOW_AUTOSIZE );
cvMoveWindow(WIN_RF, 400 , 0); //750, 2 (bernat =0)
cvMoveWindow(WIN_UT, refS.width, 0); //1500, 2
namedWindow(WIN_RF, CV_WINDOW_AUTOSIZE );
namedWindow(WIN_UT, CV_WINDOW_AUTOSIZE );
cvMoveWindow(WIN_RF, 400 , 0); //750, 2 (bernat =0)
cvMoveWindow(WIN_UT, refS.width, 0); //1500, 2
cout << "Frame resolution: Width=" << refS.width << " Height=" << refS.height
<< " of nr#: " << captRefrnc.get(CV_CAP_PROP_FRAME_COUNT) << endl;
cout << "Reference frame resolution: Width=" << refS.width << " Height=" << refS.height
<< " of nr#: " << captRefrnc.get(CV_CAP_PROP_FRAME_COUNT) << endl;
cout << "PSNR trigger value " <<
setiosflags(ios::fixed) << setprecision(3) << psnrTriggerValue << endl;
setiosflags(ios::fixed) << setprecision(3) << psnrTriggerValue << endl;
Mat frameReference, frameUnderTest;
double psnrV;
......@@ -101,24 +100,24 @@ int main(int argc, char *argv[], char *window_name)
}
++frameNum;
cout <<"Frame:" << frameNum;
cout <<"Frame:" << frameNum <<"# ";
///////////////////////////////// PSNR ////////////////////////////////////////////////////
psnrV = getPSNR(frameReference,frameUnderTest); //get PSNR
cout << setiosflags(ios::fixed) << setprecision(3) << psnrV << "dB";
//////////////////////////////////// MSSIM /////////////////////////////////////////////////
if (psnrV < psnrTriggerValue)
if (psnrV < psnrTriggerValue && psnrV)
{
mssimV = getMSSIM(frameReference,frameUnderTest);
cout << " MSSIM: "
<< "R" << setiosflags(ios::fixed) << setprecision(3) << mssimV.val[2] * 100
<< "G" << setiosflags(ios::fixed) << setprecision(3) << mssimV.val[1] * 100
<< "B" << setiosflags(ios::fixed) << setprecision(3) << mssimV.val[0] * 100;
<< " R " << setiosflags(ios::fixed) << setprecision(2) << mssimV.val[2] * 100 << "%"
<< " G " << setiosflags(ios::fixed) << setprecision(2) << mssimV.val[1] * 100 << "%"
<< " B " << setiosflags(ios::fixed) << setprecision(2) << mssimV.val[0] * 100 << "%";
}
cout << endl;
cout << endl;
////////////////////////////////// Show Image /////////////////////////////////////////////
imshow( WIN_RF, frameReference);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment