Commit fb292b1b authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

added PSNR function to imgproc; refactored highgui positioning test (which still fails)

parent bd49b9b8
......@@ -61,7 +61,19 @@ namespace cvtest
{
string fourccToString(int fourcc);
struct VideoFormat
{
VideoFormat() { fourcc = -1; }
VideoFormat(const string& _ext, int _fourcc) : ext(_ext), fourcc(_fourcc) {}
bool empty() const { return ext.empty(); }
string ext;
int fourcc;
};
extern const VideoFormat g_specific_fmt_list[];
}
#endif
......@@ -46,38 +46,33 @@
using namespace cv;
using namespace std;
string cvtest::fourccToString(int fourcc)
namespace cvtest
{
return format("%c%c%c%c", fourcc & 255, (fourcc >> 8) & 255, (fourcc >> 16) & 255, (fourcc >> 24) & 255);
}
struct VideoFmt
string fourccToString(int fourcc)
{
VideoFmt() { fourcc = -1; }
VideoFmt(const string& _ext, int _fourcc) : ext(_ext), fourcc(_fourcc) {}
bool empty() const { return ext.empty(); }
return format("%c%c%c%c", fourcc & 255, (fourcc >> 8) & 255, (fourcc >> 16) & 255, (fourcc >> 24) & 255);
}
string ext;
int fourcc;
};
static const VideoFmt specific_fmt_list[] =
const VideoFormat g_specific_fmt_list[] =
{
VideoFmt("avi", CV_FOURCC('m', 'p', 'e', 'g')),
VideoFmt("avi", CV_FOURCC('M', 'J', 'P', 'G')),
VideoFmt("avi", CV_FOURCC('I', 'Y', 'U', 'V')),
VideoFmt("mkv", CV_FOURCC('X', 'V', 'I', 'D')),
VideoFmt("mov", CV_FOURCC('m', 'p', '4', 'v')),
VideoFmt()
VideoFormat("avi", CV_FOURCC('m', 'p', 'e', 'g')),
VideoFormat("avi", CV_FOURCC('M', 'J', 'P', 'G')),
VideoFormat("avi", CV_FOURCC('I', 'Y', 'U', 'V')),
VideoFormat("mkv", CV_FOURCC('X', 'V', 'I', 'D')),
VideoFormat("mov", CV_FOURCC('m', 'p', '4', 'v')),
VideoFormat()
};
}
class CV_HighGuiTest : public cvtest::BaseTest
{
protected:
void ImageTest(const string& dir);
void VideoTest (const string& dir, const VideoFmt& fmt);
void VideoTest (const string& dir, const cvtest::VideoFormat& fmt);
void SpecificImageTest (const string& dir);
void SpecificVideoTest (const string& dir, const VideoFmt& fmt);
void SpecificVideoTest (const string& dir, const cvtest::VideoFormat& fmt);
CV_HighGuiTest() {}
~CV_HighGuiTest() {}
......@@ -116,16 +111,6 @@ public:
void run(int);
};
double PSNR(const Mat& m1, const Mat& m2)
{
Mat tmp;
absdiff( m1.reshape(1), m2.reshape(1), tmp);
multiply(tmp, tmp, tmp);
double MSE = 1.0/(tmp.cols * tmp.rows) * sum(tmp)[0];
return 20 * log10(255.0 / sqrt(MSE));
}
void CV_HighGuiTest::ImageTest(const string& dir)
{
......@@ -233,7 +218,7 @@ void CV_HighGuiTest::ImageTest(const string& dir)
}
void CV_HighGuiTest::VideoTest(const string& dir, const VideoFmt& fmt)
void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt)
{
string src_file = dir + "../cv/shared/video_for_test.avi";
string tmp_name = format("video.%s", fmt.ext.c_str());
......@@ -397,7 +382,7 @@ void CV_HighGuiTest::SpecificImageTest(const string& dir)
}
void CV_HighGuiTest::SpecificVideoTest(const string& dir, const VideoFmt& fmt)
void CV_HighGuiTest::SpecificVideoTest(const string& dir, const cvtest::VideoFormat& fmt)
{
string ext = fmt.ext;
int fourcc = fmt.fourcc;
......@@ -505,17 +490,23 @@ void CV_SpecificImageTest::run(int)
void CV_VideoTest::run(int)
{
for (int i = 0; !specific_fmt_list[i].empty(); ++i)
for (int i = 0; ; ++i)
{
VideoTest(ts->get_data_path(), specific_fmt_list[i]);
const cvtest::VideoFormat& fmt = cvtest::g_specific_fmt_list[i];
if( fmt.empty() )
break;
VideoTest(ts->get_data_path(), fmt);
}
}
void CV_SpecificVideoTest::run(int)
{
for (int i = 0; !specific_fmt_list[i].empty(); ++i)
for (int i = 0; ; ++i)
{
SpecificVideoTest(ts->get_data_path(), specific_fmt_list[i]);
const cvtest::VideoFormat& fmt = cvtest::g_specific_fmt_list[i];
if( fmt.empty() )
break;
SpecificVideoTest(ts->get_data_path(), fmt);
}
}
......
This diff is collapsed.
......@@ -597,6 +597,9 @@ CV_EXPORTS_W void accumulateProduct( InputArray src1, InputArray src2,
CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst,
double alpha, InputArray mask=noArray() );
//! computes PSNR image/video quality metric
CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2);
CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window = noArray());
CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type);
......
......@@ -245,6 +245,15 @@ void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom,
}
double cv::PSNR(InputArray _src1, InputArray _src2)
{
Mat src1 = _src1.getMat(), src2 = _src2.getMat();
CV_Assert( src1.depth() == CV_8U );
double diff = std::sqrt(norm(src1, src2, NORM_L2SQR)/(src1.total()*src1.channels()));
return 20*log10(255./(diff+DBL_EPSILON));
}
CV_IMPL void
cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset,
int borderType, CvScalar value )
......
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