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 ...@@ -61,7 +61,19 @@ namespace cvtest
{ {
string fourccToString(int fourcc); 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 #endif
...@@ -46,38 +46,33 @@ ...@@ -46,38 +46,33 @@
using namespace cv; using namespace cv;
using namespace std; 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; } return format("%c%c%c%c", fourcc & 255, (fourcc >> 8) & 255, (fourcc >> 16) & 255, (fourcc >> 24) & 255);
VideoFmt(const string& _ext, int _fourcc) : ext(_ext), fourcc(_fourcc) {} }
bool empty() const { return ext.empty(); }
string ext; const VideoFormat g_specific_fmt_list[] =
int fourcc;
};
static const VideoFmt specific_fmt_list[] =
{ {
VideoFmt("avi", CV_FOURCC('m', 'p', 'e', 'g')), VideoFormat("avi", CV_FOURCC('m', 'p', 'e', 'g')),
VideoFmt("avi", CV_FOURCC('M', 'J', 'P', 'G')), VideoFormat("avi", CV_FOURCC('M', 'J', 'P', 'G')),
VideoFmt("avi", CV_FOURCC('I', 'Y', 'U', 'V')), VideoFormat("avi", CV_FOURCC('I', 'Y', 'U', 'V')),
VideoFmt("mkv", CV_FOURCC('X', 'V', 'I', 'D')), VideoFormat("mkv", CV_FOURCC('X', 'V', 'I', 'D')),
VideoFmt("mov", CV_FOURCC('m', 'p', '4', 'v')), VideoFormat("mov", CV_FOURCC('m', 'p', '4', 'v')),
VideoFmt() VideoFormat()
}; };
}
class CV_HighGuiTest : public cvtest::BaseTest class CV_HighGuiTest : public cvtest::BaseTest
{ {
protected: protected:
void ImageTest(const string& dir); 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 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() {}
~CV_HighGuiTest() {} ~CV_HighGuiTest() {}
...@@ -116,16 +111,6 @@ public: ...@@ -116,16 +111,6 @@ public:
void run(int); 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) void CV_HighGuiTest::ImageTest(const string& dir)
{ {
...@@ -233,7 +218,7 @@ 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 src_file = dir + "../cv/shared/video_for_test.avi";
string tmp_name = format("video.%s", fmt.ext.c_str()); string tmp_name = format("video.%s", fmt.ext.c_str());
...@@ -397,7 +382,7 @@ void CV_HighGuiTest::SpecificImageTest(const string& dir) ...@@ -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; string ext = fmt.ext;
int fourcc = fmt.fourcc; int fourcc = fmt.fourcc;
...@@ -505,17 +490,23 @@ void CV_SpecificImageTest::run(int) ...@@ -505,17 +490,23 @@ void CV_SpecificImageTest::run(int)
void CV_VideoTest::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) 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, ...@@ -597,6 +597,9 @@ CV_EXPORTS_W void accumulateProduct( InputArray src1, InputArray src2,
CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst, CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst,
double alpha, InputArray mask=noArray() ); 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 Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window = noArray());
CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type); 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, ...@@ -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 CV_IMPL void
cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset, cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset,
int borderType, CvScalar value ) 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