2013-09-05 18:10:53 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
2013-06-24 09:54:58 +08:00
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
2013-08-03 05:45:20 +08:00
|
|
|
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
2013-06-24 09:54:58 +08:00
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of the copyright holders may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
void loadImage(string path, Mat &img)
|
2013-07-21 17:48:57 +08:00
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
img = imread(path, -1);
|
|
|
|
ASSERT_FALSE(img.empty()) << "Could not load input image " << path;
|
2013-07-21 17:48:57 +08:00
|
|
|
}
|
|
|
|
|
2013-11-19 12:14:44 +08:00
|
|
|
void checkEqual(Mat img0, Mat img1, double threshold, const string& name)
|
2013-07-21 17:48:57 +08:00
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
double max = 1.0;
|
|
|
|
minMaxLoc(abs(img0 - img1), NULL, &max);
|
2013-11-19 12:14:44 +08:00
|
|
|
ASSERT_FALSE(max > threshold) << "max=" << max << " threshold=" << threshold << " method=" << name;
|
2013-08-01 07:24:47 +08:00
|
|
|
}
|
|
|
|
|
2013-08-03 05:45:20 +08:00
|
|
|
static vector<float> DEFAULT_VECTOR;
|
|
|
|
void loadExposureSeq(String path, vector<Mat>& images, vector<float>& times = DEFAULT_VECTOR)
|
2013-08-01 07:24:47 +08:00
|
|
|
{
|
2013-08-03 05:45:20 +08:00
|
|
|
ifstream list_file((path + "list.txt").c_str());
|
2013-09-24 03:40:06 +08:00
|
|
|
ASSERT_TRUE(list_file.is_open());
|
|
|
|
string name;
|
|
|
|
float val;
|
|
|
|
while(list_file >> name >> val) {
|
|
|
|
Mat img = imread(path + name);
|
|
|
|
ASSERT_FALSE(img.empty()) << "Could not load input image " << path + name;
|
|
|
|
images.push_back(img);
|
|
|
|
times.push_back(1 / val);
|
|
|
|
}
|
|
|
|
list_file.close();
|
2013-08-01 07:24:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void loadResponseCSV(String path, Mat& response)
|
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
response = Mat(256, 1, CV_32FC3);
|
2013-09-03 18:05:14 +08:00
|
|
|
ifstream resp_file(path.c_str());
|
2013-09-24 03:40:06 +08:00
|
|
|
for(int i = 0; i < 256; i++) {
|
|
|
|
for(int c = 0; c < 3; c++) {
|
|
|
|
resp_file >> response.at<Vec3f>(i)[c];
|
2013-08-28 06:17:49 +08:00
|
|
|
resp_file.ignore(1);
|
2013-09-24 03:40:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
resp_file.close();
|
2013-07-21 17:48:57 +08:00
|
|
|
}
|
|
|
|
|
2013-07-31 20:05:31 +08:00
|
|
|
TEST(Photo_Tonemap, regression)
|
2013-06-24 09:54:58 +08:00
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/tonemap/";
|
|
|
|
|
|
|
|
Mat img, expected, result;
|
|
|
|
loadImage(test_path + "image.hdr", img);
|
|
|
|
float gamma = 2.2f;
|
|
|
|
|
2013-08-06 00:35:48 +08:00
|
|
|
Ptr<Tonemap> linear = createTonemap(gamma);
|
2013-09-24 03:40:06 +08:00
|
|
|
linear->process(img, result);
|
|
|
|
loadImage(test_path + "linear.png", expected);
|
|
|
|
result.convertTo(result, CV_8UC3, 255);
|
2013-11-19 12:14:44 +08:00
|
|
|
checkEqual(result, expected, 3, "Simple");
|
2013-09-24 03:40:06 +08:00
|
|
|
|
|
|
|
Ptr<TonemapDrago> drago = createTonemapDrago(gamma);
|
|
|
|
drago->process(img, result);
|
|
|
|
loadImage(test_path + "drago.png", expected);
|
|
|
|
result.convertTo(result, CV_8UC3, 255);
|
2013-11-19 12:14:44 +08:00
|
|
|
checkEqual(result, expected, 3, "Drago");
|
2013-09-24 03:40:06 +08:00
|
|
|
|
|
|
|
Ptr<TonemapDurand> durand = createTonemapDurand(gamma);
|
|
|
|
durand->process(img, result);
|
|
|
|
loadImage(test_path + "durand.png", expected);
|
|
|
|
result.convertTo(result, CV_8UC3, 255);
|
2013-11-19 12:14:44 +08:00
|
|
|
checkEqual(result, expected, 3, "Durand");
|
2013-09-24 03:40:06 +08:00
|
|
|
|
|
|
|
Ptr<TonemapReinhard> reinhard = createTonemapReinhard(gamma);
|
|
|
|
reinhard->process(img, result);
|
|
|
|
loadImage(test_path + "reinhard.png", expected);
|
|
|
|
result.convertTo(result, CV_8UC3, 255);
|
2013-11-19 12:14:44 +08:00
|
|
|
checkEqual(result, expected, 3, "Reinhard");
|
2013-09-24 03:40:06 +08:00
|
|
|
|
|
|
|
Ptr<TonemapMantiuk> mantiuk = createTonemapMantiuk(gamma);
|
|
|
|
mantiuk->process(img, result);
|
|
|
|
loadImage(test_path + "mantiuk.png", expected);
|
|
|
|
result.convertTo(result, CV_8UC3, 255);
|
2013-11-19 12:14:44 +08:00
|
|
|
checkEqual(result, expected, 3, "Mantiuk");
|
2013-07-12 20:03:53 +08:00
|
|
|
}
|
|
|
|
|
2013-08-01 07:24:47 +08:00
|
|
|
TEST(Photo_AlignMTB, regression)
|
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
const int TESTS_COUNT = 100;
|
|
|
|
string folder = string(cvtest::TS::ptr()->get_data_path()) + "shared/";
|
|
|
|
|
|
|
|
string file_name = folder + "lena.png";
|
|
|
|
Mat img;
|
|
|
|
loadImage(file_name, img);
|
|
|
|
cvtColor(img, img, COLOR_RGB2GRAY);
|
|
|
|
|
|
|
|
int max_bits = 5;
|
|
|
|
int max_shift = 32;
|
|
|
|
srand(static_cast<unsigned>(time(0)));
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
Ptr<AlignMTB> align = createAlignMTB(max_bits);
|
|
|
|
|
|
|
|
for(int i = 0; i < TESTS_COUNT; i++) {
|
|
|
|
Point shift(rand() % max_shift, rand() % max_shift);
|
|
|
|
Mat res;
|
|
|
|
align->shiftMat(img, res, shift);
|
|
|
|
Point calc = align->calculateShift(img, res);
|
|
|
|
errors += (calc != -shift);
|
|
|
|
}
|
|
|
|
ASSERT_TRUE(errors < 5) << errors << " errors";
|
2013-08-01 07:24:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Photo_MergeMertens, regression)
|
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
|
2013-08-01 07:24:47 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
vector<Mat> images;
|
2013-08-03 05:45:20 +08:00
|
|
|
loadExposureSeq((test_path + "exposures/").c_str() , images);
|
2013-08-01 07:24:47 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
Ptr<MergeMertens> merge = createMergeMertens();
|
2013-08-01 07:24:47 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
Mat result, expected;
|
|
|
|
loadImage(test_path + "merge/mertens.png", expected);
|
|
|
|
merge->process(images, result);
|
|
|
|
result.convertTo(result, CV_8UC3, 255);
|
2013-11-19 12:14:44 +08:00
|
|
|
checkEqual(expected, result, 3, "Mertens");
|
2014-01-10 06:10:00 +08:00
|
|
|
|
|
|
|
Mat uniform(100, 100, CV_8UC3);
|
|
|
|
uniform = Scalar(0, 255, 0);
|
|
|
|
|
|
|
|
images.clear();
|
|
|
|
images.push_back(uniform);
|
|
|
|
|
|
|
|
merge->process(images, result);
|
|
|
|
result.convertTo(result, CV_8UC3, 255);
|
|
|
|
checkEqual(uniform, result, 1e-2f, "Mertens");
|
2013-08-01 07:24:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Photo_MergeDebevec, regression)
|
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
|
2013-08-01 07:24:47 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
vector<Mat> images;
|
|
|
|
vector<float> times;
|
|
|
|
Mat response;
|
|
|
|
loadExposureSeq(test_path + "exposures/", images, times);
|
|
|
|
loadResponseCSV(test_path + "exposures/response.csv", response);
|
2013-08-01 07:24:47 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
Ptr<MergeDebevec> merge = createMergeDebevec();
|
2013-08-01 07:24:47 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
Mat result, expected;
|
|
|
|
loadImage(test_path + "merge/debevec.hdr", expected);
|
|
|
|
merge->process(images, result, times, response);
|
2013-09-18 22:21:45 +08:00
|
|
|
|
2013-09-17 04:39:22 +08:00
|
|
|
Ptr<Tonemap> map = createTonemap();
|
|
|
|
map->process(result, result);
|
|
|
|
map->process(expected, expected);
|
|
|
|
|
2013-11-19 12:14:44 +08:00
|
|
|
checkEqual(expected, result, 1e-2f, "Debevec");
|
2013-09-06 21:30:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Photo_MergeRobertson, regression)
|
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
|
2013-09-06 21:30:43 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
vector<Mat> images;
|
|
|
|
vector<float> times;
|
|
|
|
loadExposureSeq(test_path + "exposures/", images, times);
|
|
|
|
Ptr<MergeRobertson> merge = createMergeRobertson();
|
|
|
|
Mat result, expected;
|
|
|
|
loadImage(test_path + "merge/robertson.hdr", expected);
|
|
|
|
merge->process(images, result, times);
|
2013-09-18 22:21:45 +08:00
|
|
|
|
2017-06-03 21:57:23 +08:00
|
|
|
#ifdef __aarch64__
|
|
|
|
const float eps = 6.f;
|
|
|
|
#else
|
|
|
|
const float eps = 5.f;
|
|
|
|
#endif
|
|
|
|
checkEqual(expected, result, eps, "MergeRobertson");
|
2013-08-01 07:24:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Photo_CalibrateDebevec, regression)
|
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
|
2013-08-01 07:24:47 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
vector<Mat> images;
|
|
|
|
vector<float> times;
|
|
|
|
Mat response, expected;
|
|
|
|
loadExposureSeq(test_path + "exposures/", images, times);
|
2013-08-28 06:17:49 +08:00
|
|
|
loadResponseCSV(test_path + "calibrate/debevec.csv", expected);
|
2013-09-24 03:40:06 +08:00
|
|
|
Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();
|
2013-09-18 22:21:45 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
calibrate->process(images, response, times);
|
2013-09-05 18:41:35 +08:00
|
|
|
Mat diff = abs(response - expected);
|
|
|
|
diff = diff.mul(1.0f / response);
|
|
|
|
double max;
|
|
|
|
minMaxLoc(diff, NULL, &max);
|
|
|
|
ASSERT_FALSE(max > 0.1);
|
2013-08-01 07:24:47 +08:00
|
|
|
}
|
2013-09-06 21:30:43 +08:00
|
|
|
|
|
|
|
TEST(Photo_CalibrateRobertson, regression)
|
|
|
|
{
|
2013-09-24 03:40:06 +08:00
|
|
|
string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
|
2013-09-06 21:30:43 +08:00
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
vector<Mat> images;
|
|
|
|
vector<float> times;
|
|
|
|
Mat response, expected;
|
|
|
|
loadExposureSeq(test_path + "exposures/", images, times);
|
2013-09-06 21:30:43 +08:00
|
|
|
loadResponseCSV(test_path + "calibrate/robertson.csv", expected);
|
|
|
|
|
2013-09-24 03:40:06 +08:00
|
|
|
Ptr<CalibrateRobertson> calibrate = createCalibrateRobertson();
|
|
|
|
calibrate->process(images, response, times);
|
2017-05-11 17:25:18 +08:00
|
|
|
checkEqual(expected, response, 1e-1f, "CalibrateRobertson");
|
2013-08-01 07:24:47 +08:00
|
|
|
}
|