From 84ea0c9a97bcc9c5ef52e62488c3cfbfc9c0e0fd Mon Sep 17 00:00:00 2001 From: Fedor Morozov Date: Mon, 24 Jun 2013 05:54:58 +0400 Subject: [PATCH] Tests and rgbe fix --- modules/highgui/src/rgbe.cpp | 6 +-- modules/highgui/test/test_grfmt.cpp | 25 +++++++++ modules/photo/src/hdr_fusion.cpp | 5 ++ modules/photo/test/test_hdr.cpp | 78 +++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 modules/photo/test/test_hdr.cpp diff --git a/modules/highgui/src/rgbe.cpp b/modules/highgui/src/rgbe.cpp index 2403be71e1..645f681aa0 100644 --- a/modules/highgui/src/rgbe.cpp +++ b/modules/highgui/src/rgbe.cpp @@ -56,8 +56,8 @@ // feel free to modify it to suit your needs. // Some opencv specific changes have been added: -// inline define specified, channel order changed (to ger bgr by default), -// error handler uses CV_Error. +// inline define specified, error handler uses CV_Error, +// defines changed to work in bgr color space. // // posted to http://www.graphics.cornell.edu/~bjw/ // written by Bruce Walter (bjw@graphics.cornell.edu) 5/26/95 @@ -380,7 +380,7 @@ int RGBE_ReadPixels_RLE(FILE *fp, float *data, int scanline_width, } if ((rgbe[0] != 2)||(rgbe[1] != 2)||(rgbe[2] & 0x80)) { /* this file is not run length encoded */ - rgbe2float(&data[0],&data[1],&data[2],rgbe); + rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],&data[RGBE_DATA_BLUE],rgbe); data += RGBE_DATA_SIZE; free(scanline_buffer); return RGBE_ReadPixels(fp,data,scanline_width*num_scanlines-1); diff --git a/modules/highgui/test/test_grfmt.cpp b/modules/highgui/test/test_grfmt.cpp index 7fc80b2c17..5464a9ce9c 100644 --- a/modules/highgui/test/test_grfmt.cpp +++ b/modules/highgui/test/test_grfmt.cpp @@ -406,3 +406,28 @@ TEST(Highgui_WebP, encode_decode_lossy_webp) } #endif + +TEST(Highgui_hdr, regression) +{ + string folder = string(cvtest::TS::ptr()->get_data_path()) + "../cv/hdr/"; + string name_rle = folder + "grand_canal_rle.hdr"; + string name_no_rle = folder + "grand_canal_no_rle.hdr"; + Mat img_rle = imread(name_rle, -1); + ASSERT_FALSE(img_rle.empty()) << "Could not open " << name_rle; + Mat img_no_rle = imread(name_no_rle, -1); + ASSERT_FALSE(img_no_rle.empty()) << "Could not open " << name_no_rle; + + double min = 0.0, max = 1.0; + minMaxLoc(abs(img_rle - img_no_rle), &min, &max); + ASSERT_FALSE(max > 0); + string tmp_file_name = tempfile(".hdr"); + vectorparam(1); + for(int i = 0; i < 2; i++) { + param[0] = i; + imwrite(tmp_file_name, img_rle, param); + Mat written_img = imread(tmp_file_name, -1); + ASSERT_FALSE(written_img.empty()) << "Could not open " << tmp_file_name; + minMaxLoc(abs(img_rle - written_img), &min, &max); + ASSERT_FALSE(max > 0); + } +} diff --git a/modules/photo/src/hdr_fusion.cpp b/modules/photo/src/hdr_fusion.cpp index ba0a4c94ce..23f8ecb1ad 100644 --- a/modules/photo/src/hdr_fusion.cpp +++ b/modules/photo/src/hdr_fusion.cpp @@ -91,6 +91,7 @@ void makeHDR(InputArrayOfArrays _images, std::vector exp_times, OutputArr triangleWeights(weights); generateResponce(responce); + float max = 0; float *res_ptr = result.ptr(); for(size_t pos = 0; pos < result.total(); pos++, res_ptr += 3) { @@ -108,8 +109,12 @@ void makeHDR(InputArrayOfArrays _images, std::vector exp_times, OutputArr } for(int channel = 0; channel < 3; channel++) { res_ptr[channel] = exp(sum[channel] / weight_sum); + if(res_ptr[channel] > max) { + max = res_ptr[channel]; + } } } + result = result / max; } }; \ No newline at end of file diff --git a/modules/photo/test/test_hdr.cpp b/modules/photo/test/test_hdr.cpp new file mode 100644 index 0000000000..6b93aab2c8 --- /dev/null +++ b/modules/photo/test/test_hdr.cpp @@ -0,0 +1,78 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// 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 +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// 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" +#include +#include + +using namespace cv; +using namespace std; + +TEST(Photo_MakeHdr, regression) +{ + string folder = string(cvtest::TS::ptr()->get_data_path()) + "hdr/"; + + vectorfile_names(3); + file_names[0] = folder + "grand_canal_1_45.jpg"; + file_names[1] = folder + "grand_canal_1_180.jpg"; + file_names[2] = folder + "grand_canal_1_750.jpg"; + vectorimages(3); + for(int i = 0; i < 3; i++) { + images[i] = imread(file_names[i]); + ASSERT_FALSE(images[i].empty()) << "Could not load input image " << file_names[i]; + } + + string expected_path = folder + "grand_canal_rle.hdr"; + Mat expected = imread(expected_path, -1); + ASSERT_FALSE(expected.empty()) << "Could not load input image " << expected_path; + + vectortimes(3); + times[0] = 1.0f/45.0f; + times[1] = 1.0f/180.0f; + times[2] = 1.0f/750.0f; + + Mat result; + makeHDR(images, times, result); + double min = 0.0, max = 1.0; + minMaxLoc(abs(result - expected), &min, &max); + ASSERT_TRUE(max < 0.01); +} \ No newline at end of file