EXPECT_EQ(reference.depth(), actual.depth());
EXPECT_EQ(reference.channels(), actual.channels());
- double psnr = PSNR(actual, reference);
+ double psnr = cvtest::PSNR(actual, reference);
if (psnr < eps)
{
#define SUM cvtest::TS::SUMMARY
}
const double thresDbell = 20;
- double psnr = PSNR(loaded, image);
+ double psnr = cvtest::PSNR(loaded, image);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=%s\n", psnr, ext.c_str());
continue;
}
- psnr = PSNR(buf_loaded, image);
+ psnr = cvtest::PSNR(buf_loaded, image);
if (psnr < thresDbell)
{
Mat img = frames[i];
Mat img1 = cv::cvarrToMat(ipl1);
- double psnr = PSNR(img1, img);
+ double psnr = cvtest::PSNR(img1, img);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Too low frame %d psnr = %gdb\n", i, psnr);
}
const double thresDbell = 20;
- double psnr = PSNR(loaded, image);
+ double psnr = cvtest::PSNR(loaded, image);
if (psnr < thresDbell)
{
ts->printf(ts->LOG, "Reading image from file: too big difference (=%g) with fmt=bmp\n", psnr);
continue;
}
- psnr = PSNR(buf_loaded, image);
+ psnr = cvtest::PSNR(buf_loaded, image);
if (psnr < thresDbell)
{
Mat img = images[i];
const double thresDbell = 40;
- double psnr = PSNR(img, frame);
+ double psnr = cvtest::PSNR(img, frame);
if (psnr > thresDbell)
{
return;
}
- double err = PSNR(img, img0);
+ double err = cvtest::PSNR(img, img0);
if( err < 20 )
{
checkTypeAndSizeOfMask( mask, sz );
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);
}
/*
#include "test_precomp.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());
cv::Mat noise(img.size(), img.type()), mask(img.size(), CV_8U);
rng.fill(noise,cv::RNG::NORMAL,128.0,sigma);
noise.setTo(128, mask);
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);
- if(rng(2)==0){
+ if(rng(2)==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;
- }
}
}
-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");
return (image.at<uchar>(x,y)==val);
}
-TEST(Optim_denoise_tvl1, regression_basic){
+TEST(Optim_denoise_tvl1, regression_basic)
+{
cv::RNG rng(42);
- cv::Mat img = cv::imread("lena.jpg", 0), noisy,res;
- if(img.rows!=512 || img.cols!=512){
- printf("\tplease, put lena.jpg from samples/c in the current folder\n");
- printf("\tnow, the test will fail...\n");
- ASSERT_TRUE(false);
- }
+ cv::Mat img = cv::imread(cvtest::TS::ptr()->get_data_path() + "shared/lena.png", 0), noisy, res;
+
+ ASSERT_FALSE(img.empty()) << "Error: can't open 'lena.png'";
const int obs_num=5;
- std::vector<cv::Mat> images(obs_num,cv::Mat());
- for(int i=0;i<(int)images.size();i++){
+ std::vector<cv::Mat> images(obs_num, cv::Mat());
+ for(int i=0;i<(int)images.size();i++)
+ {
make_noisy(img,images[i], 20, 0.02,rng);
//make_spotty(images[i],rng);
}
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)
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)
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)
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)
absdiff( orig, res1, diff1 );
absdiff( orig, res2, diff2 );
- double n1 = norm(diff1.reshape(1), NORM_INF, inv_mask.reshape(1));
- double n2 = norm(diff2.reshape(1), NORM_INF, inv_mask.reshape(1));
+ double n1 = cvtest::norm(diff1.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)
{
absdiff( exp1, res1, diff1 );
absdiff( exp2, res2, diff2 );
- n1 = norm(diff1.reshape(1), NORM_INF, mask.reshape(1));
- n2 = norm(diff2.reshape(1), NORM_INF, mask.reshape(1));
+ n1 = cvtest::norm(diff1.reshape(1), NORM_INF, mask.reshape(1));
+ n2 = cvtest::norm(diff2.reshape(1), NORM_INF, mask.reshape(1));
const int jpeg_thres = 3;
if (n1 > jpeg_thres || n2 > jpeg_thres)
Mat result; result_s.convertTo(result, CV_8U);
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);
}
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 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);
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
crossCorr_(const _Tp* src1, const _Tp* src2, size_t total)
Mat aff_est = estimateRigidTransform(fpts, tpts, true);
- double thres = 0.1*norm(aff);
- double d = norm(aff_est, aff, NORM_L2);
+ double thres = 0.1*cvtest::norm(aff, NORM_L2);
+ double d = cvtest::norm(aff_est, aff, NORM_L2);
if (d > thres)
{
double dB=0, nB=0;
Mat B = A - repeat(A.row(0), 3, 1), Bt = B.t();
B = Bt*B;
dB = cv::determinant(B);
- nB = norm(B);
+ nB = cvtest::norm(B, NORM_L2);
if( fabs(dB) < 0.01*nB )
continue;
}
Mat aff_est = estimateRigidTransform(img, rotated, true);
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->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;
}