cv2cvtest part2

pull/2592/head
Ilya Lavrenov 11 years ago
parent 5600bc54f4
commit 4a63b3dd90
  1. 2
      modules/highgui/test/test_ffmpeg.cpp
  2. 12
      modules/highgui/test/test_video_io.cpp
  3. 2
      modules/highgui/test/test_video_pos.cpp
  4. 2
      modules/legacy/test/test_stereomatching.cpp
  5. 35
      modules/optim/test/test_denoise_tvl1.cpp
  6. 8
      modules/photo/test/test_denoising.cpp
  7. 8
      modules/photo/test/test_inpaint.cpp
  8. 2
      modules/stitching/test/test_blenders.cpp
  9. 1
      modules/ts/include/opencv2/ts.hpp
  10. 6
      modules/ts/src/ts_func.cpp
  11. 10
      modules/video/test/test_estimaterigid.cpp

@ -329,7 +329,7 @@ public:
EXPECT_EQ(reference.depth(), actual.depth()); EXPECT_EQ(reference.depth(), actual.depth());
EXPECT_EQ(reference.channels(), actual.channels()); EXPECT_EQ(reference.channels(), actual.channels());
double psnr = PSNR(actual, reference); double psnr = cvtest::PSNR(actual, reference);
if (psnr < eps) if (psnr < eps)
{ {
#define SUM cvtest::TS::SUMMARY #define SUM cvtest::TS::SUMMARY

@ -198,7 +198,7 @@ void CV_HighGuiTest::ImageTest(const string& dir)
} }
const double thresDbell = 20; const double thresDbell = 20;
double psnr = PSNR(loaded, image); double psnr = cvtest::PSNR(loaded, image);
if (psnr < thresDbell) if (psnr < thresDbell)
{ {
ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str()); ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str());
@ -235,7 +235,7 @@ void CV_HighGuiTest::ImageTest(const string& dir)
continue; continue;
} }
psnr = PSNR(buf_loaded, image); psnr = cvtest::PSNR(buf_loaded, image);
if (psnr < thresDbell) if (psnr < thresDbell)
{ {
@ -316,7 +316,7 @@ void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt
Mat img = frames[i]; Mat img = frames[i];
Mat img1 = cv::cvarrToMat(ipl1); Mat img1 = cv::cvarrToMat(ipl1);
double psnr = PSNR(img1, img); double psnr = cvtest::PSNR(img1, img);
if (psnr < thresDbell) if (psnr < thresDbell)
{ {
ts->printf(ts->LOG, "Too low frame %d psnr = %gdb\n", i, psnr); ts->printf(ts->LOG, "Too low frame %d psnr = %gdb\n", i, psnr);
@ -371,7 +371,7 @@ void CV_HighGuiTest::SpecificImageTest(const string& dir)
} }
const double thresDbell = 20; const double thresDbell = 20;
double psnr = PSNR(loaded, image); double psnr = cvtest::PSNR(loaded, image);
if (psnr < thresDbell) if (psnr < thresDbell)
{ {
ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=bmp\n", psnr); ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=bmp\n", psnr);
@ -408,7 +408,7 @@ void CV_HighGuiTest::SpecificImageTest(const string& dir)
continue; continue;
} }
psnr = PSNR(buf_loaded, image); psnr = cvtest::PSNR(buf_loaded, image);
if (psnr < thresDbell) if (psnr < thresDbell)
{ {
@ -521,7 +521,7 @@ void CV_HighGuiTest::SpecificVideoTest(const string& dir, const cvtest::VideoFor
Mat img = images[i]; Mat img = images[i];
const double thresDbell = 40; const double thresDbell = 40;
double psnr = PSNR(img, frame); double psnr = cvtest::PSNR(img, frame);
if (psnr > thresDbell) if (psnr > thresDbell)
{ {

@ -160,7 +160,7 @@ public:
return; return;
} }
double err = PSNR(img, img0); double err = cvtest::PSNR(img, img0);
if( err < 20 ) if( err < 20 )
{ {

@ -278,7 +278,7 @@ float dispRMS( const Mat& computedDisp, const Mat& groundTruthDisp, const Mat& m
checkTypeAndSizeOfMask( mask, sz ); checkTypeAndSizeOfMask( mask, sz );
pointsCount = countNonZero(mask); pointsCount = countNonZero(mask);
} }
return 1.f/sqrt((float)pointsCount) * (float)norm(computedDisp, groundTruthDisp, NORM_L2, mask); return 1.f/sqrt((float)pointsCount) * (float)cvtest::norm(computedDisp, groundTruthDisp, NORM_L2, mask);
} }
/* /*

@ -41,7 +41,8 @@
#include "test_precomp.hpp" #include "test_precomp.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
void make_noisy(const cv::Mat& img, cv::Mat& noisy, double sigma, double pepper_salt_ratio,cv::RNG& rng){ void make_noisy(const cv::Mat& img, cv::Mat& noisy, double sigma, double pepper_salt_ratio,cv::RNG& rng)
{
noisy.create(img.size(), img.type()); noisy.create(img.size(), img.type());
cv::Mat noise(img.size(), img.type()), mask(img.size(), CV_8U); cv::Mat noise(img.size(), img.type()), mask(img.size(), CV_8U);
rng.fill(noise,cv::RNG::NORMAL,128.0,sigma); rng.fill(noise,cv::RNG::NORMAL,128.0,sigma);
@ -54,34 +55,36 @@ void make_noisy(const cv::Mat& img, cv::Mat& noisy, double sigma, double pepper_
noise.setTo(128, mask); noise.setTo(128, mask);
cv::addWeighted(noisy, 1, noise, 1, -128, noisy); cv::addWeighted(noisy, 1, noise, 1, -128, noisy);
} }
void make_spotty(cv::Mat& img,cv::RNG& rng, int r=3,int n=1000){
for(int i=0;i<n;i++){ void make_spotty(cv::Mat& img,cv::RNG& rng, int r=3,int n=1000)
{
for(int i=0;i<n;i++)
{
int x=rng(img.cols-r),y=rng(img.rows-r); int x=rng(img.cols-r),y=rng(img.rows-r);
if(rng(2)==0){ if(rng(2)==0)
img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)0; img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)0;
}else{ else
img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)255; img(cv::Range(y,y+r),cv::Range(x,x+r))=(uchar)255;
} }
}
} }
bool validate_pixel(const cv::Mat& image,int x,int y,uchar val){ bool validate_pixel(const cv::Mat& image,int x,int y,uchar val)
{
printf("test: image(%d,%d)=%d vs %d - %s\n",x,y,(int)image.at<uchar>(x,y),val,(val==image.at<uchar>(x,y))?"true":"false"); printf("test: image(%d,%d)=%d vs %d - %s\n",x,y,(int)image.at<uchar>(x,y),val,(val==image.at<uchar>(x,y))?"true":"false");
return (image.at<uchar>(x,y)==val); return (image.at<uchar>(x,y)==val);
} }
TEST(Optim_denoise_tvl1, regression_basic){ TEST(Optim_denoise_tvl1, regression_basic)
{
cv::RNG rng(42); cv::RNG rng(42);
cv::Mat img = cv::imread("lena.jpg", 0), noisy,res; cv::Mat img = cv::imread(cvtest::TS::ptr()->get_data_path() + "shared/lena.png", 0), noisy, res;
if(img.rows!=512 || img.cols!=512){
printf("\tplease, put lena.jpg from samples/c in the current folder\n"); ASSERT_FALSE(img.empty()) << "Error: can't open 'lena.png'";
printf("\tnow, the test will fail...\n");
ASSERT_TRUE(false);
}
const int obs_num=5; const int obs_num=5;
std::vector<cv::Mat> images(obs_num,cv::Mat()); std::vector<cv::Mat> images(obs_num, cv::Mat());
for(int i=0;i<(int)images.size();i++){ for(int i=0;i<(int)images.size();i++)
{
make_noisy(img,images[i], 20, 0.02,rng); make_noisy(img,images[i], 20, 0.02,rng);
//make_spotty(images[i],rng); //make_spotty(images[i],rng);
} }

@ -73,7 +73,7 @@ TEST(Photo_DenoisingGrayscale, regression)
DUMP(result, expected_path + ".res.png"); DUMP(result, expected_path + ".res.png");
ASSERT_EQ(0, norm(result != expected)); ASSERT_EQ(0, cvtest::norm(result, expected, NORM_L2));
} }
TEST(Photo_DenoisingColored, regression) TEST(Photo_DenoisingColored, regression)
@ -93,7 +93,7 @@ TEST(Photo_DenoisingColored, regression)
DUMP(result, expected_path + ".res.png"); DUMP(result, expected_path + ".res.png");
ASSERT_EQ(0, norm(result != expected)); ASSERT_EQ(0, cvtest::norm(result, expected, NORM_L2));
} }
TEST(Photo_DenoisingGrayscaleMulti, regression) TEST(Photo_DenoisingGrayscaleMulti, regression)
@ -118,7 +118,7 @@ TEST(Photo_DenoisingGrayscaleMulti, regression)
DUMP(result, expected_path + ".res.png"); DUMP(result, expected_path + ".res.png");
ASSERT_EQ(0, norm(result != expected)); ASSERT_EQ(0, cvtest::norm(result, expected, NORM_L2));
} }
TEST(Photo_DenoisingColoredMulti, regression) TEST(Photo_DenoisingColoredMulti, regression)
@ -143,7 +143,7 @@ TEST(Photo_DenoisingColoredMulti, regression)
DUMP(result, expected_path + ".res.png"); DUMP(result, expected_path + ".res.png");
ASSERT_EQ(0, norm(result != expected)); ASSERT_EQ(0, cvtest::norm(result, expected, NORM_L2));
} }
TEST(Photo_White, issue_2646) TEST(Photo_White, issue_2646)

@ -91,8 +91,8 @@ void CV_InpaintTest::run( int )
absdiff( orig, res1, diff1 ); absdiff( orig, res1, diff1 );
absdiff( orig, res2, diff2 ); absdiff( orig, res2, diff2 );
double n1 = norm(diff1.reshape(1), NORM_INF, inv_mask.reshape(1)); double n1 = cvtest::norm(diff1.reshape(1), NORM_INF, inv_mask.reshape(1));
double n2 = norm(diff2.reshape(1), NORM_INF, inv_mask.reshape(1)); double n2 = cvtest::norm(diff2.reshape(1), NORM_INF, inv_mask.reshape(1));
if (n1 != 0 || n2 != 0) if (n1 != 0 || n2 != 0)
{ {
@ -103,8 +103,8 @@ void CV_InpaintTest::run( int )
absdiff( exp1, res1, diff1 ); absdiff( exp1, res1, diff1 );
absdiff( exp2, res2, diff2 ); absdiff( exp2, res2, diff2 );
n1 = norm(diff1.reshape(1), NORM_INF, mask.reshape(1)); n1 = cvtest::norm(diff1.reshape(1), NORM_INF, mask.reshape(1));
n2 = norm(diff2.reshape(1), NORM_INF, mask.reshape(1)); n2 = cvtest::norm(diff2.reshape(1), NORM_INF, mask.reshape(1));
const int jpeg_thres = 3; const int jpeg_thres = 3;
if (n1 > jpeg_thres || n2 > jpeg_thres) if (n1 > jpeg_thres || n2 > jpeg_thres)

@ -73,6 +73,6 @@ TEST(MultiBandBlender, CanBlendTwoImages)
Mat result; result_s.convertTo(result, CV_8U); Mat result; result_s.convertTo(result, CV_8U);
Mat expected = imread(string(cvtest::TS::ptr()->get_data_path()) + "stitching/baboon_lena.png"); Mat expected = imread(string(cvtest::TS::ptr()->get_data_path()) + "stitching/baboon_lena.png");
double rmsErr = norm(expected, result, NORM_L2) / sqrt(double(expected.size().area())); double rmsErr = cvtest::norm(expected, result, NORM_L2) / sqrt(double(expected.size().area()));
ASSERT_LT(rmsErr, 1e-3); ASSERT_LT(rmsErr, 1e-3);
} }

@ -129,6 +129,7 @@ CV_EXPORTS void minMaxLoc(const Mat& src, double* minval, double* maxval,
CV_EXPORTS double norm(InputArray src, int normType, InputArray mask=noArray()); CV_EXPORTS double norm(InputArray src, int normType, InputArray mask=noArray());
CV_EXPORTS double norm(InputArray src1, InputArray src2, int normType, InputArray mask=noArray()); CV_EXPORTS double norm(InputArray src1, InputArray src2, int normType, InputArray mask=noArray());
CV_EXPORTS Scalar mean(const Mat& src, const Mat& mask=Mat()); CV_EXPORTS Scalar mean(const Mat& src, const Mat& mask=Mat());
CV_EXPORTS double PSNR(InputArray src1, InputArray src2);
CV_EXPORTS bool cmpUlps(const Mat& data, const Mat& refdata, int expMaxDiff, double* realMaxDiff, vector<int>* idx); CV_EXPORTS bool cmpUlps(const Mat& data, const Mat& refdata, int expMaxDiff, double* realMaxDiff, vector<int>* idx);

@ -1399,6 +1399,12 @@ double norm(InputArray _src1, InputArray _src2, int normType, InputArray _mask)
return isRelative ? result / (cvtest::norm(src2, normType) + DBL_EPSILON) : result; return isRelative ? result / (cvtest::norm(src2, normType) + DBL_EPSILON) : result;
} }
double PSNR(InputArray _src1, InputArray _src2)
{
CV_Assert( _src1.depth() == CV_8U );
double diff = std::sqrt(cvtest::norm(_src1, _src2, NORM_L2SQR)/(_src1.total()*_src1.channels()));
return 20*log10(255./(diff+DBL_EPSILON));
}
template<typename _Tp> static double template<typename _Tp> static double
crossCorr_(const _Tp* src1, const _Tp* src2, size_t total) crossCorr_(const _Tp* src1, const _Tp* src2, size_t total)

@ -109,8 +109,8 @@ bool CV_RigidTransform_Test::testNPoints(int from)
Mat aff_est = estimateRigidTransform(fpts, tpts, true); Mat aff_est = estimateRigidTransform(fpts, tpts, true);
double thres = 0.1*norm(aff); double thres = 0.1*cvtest::norm(aff, NORM_L2);
double d = norm(aff_est, aff, NORM_L2); double d = cvtest::norm(aff_est, aff, NORM_L2);
if (d > thres) if (d > thres)
{ {
double dB=0, nB=0; double dB=0, nB=0;
@ -120,7 +120,7 @@ bool CV_RigidTransform_Test::testNPoints(int from)
Mat B = A - repeat(A.row(0), 3, 1), Bt = B.t(); Mat B = A - repeat(A.row(0), 3, 1), Bt = B.t();
B = Bt*B; B = Bt*B;
dB = cv::determinant(B); dB = cv::determinant(B);
nB = norm(B); nB = cvtest::norm(B, NORM_L2);
if( fabs(dB) < 0.01*nB ) if( fabs(dB) < 0.01*nB )
continue; continue;
} }
@ -154,11 +154,11 @@ bool CV_RigidTransform_Test::testImage()
Mat aff_est = estimateRigidTransform(img, rotated, true); Mat aff_est = estimateRigidTransform(img, rotated, true);
const double thres = 0.033; const double thres = 0.033;
if (norm(aff_est, aff, NORM_INF) > thres) if (cvtest::norm(aff_est, aff, NORM_INF) > thres)
{ {
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY); ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
ts->printf( cvtest::TS::LOG, "Threshold = %f, norm of difference = %f", thres, ts->printf( cvtest::TS::LOG, "Threshold = %f, norm of difference = %f", thres,
norm(aff_est, aff, NORM_INF) ); cvtest::norm(aff_est, aff, NORM_INF) );
return false; return false;
} }

Loading…
Cancel
Save