Tests and rgbe fix

pull/1474/head
Fedor Morozov 12 years ago
parent 96dfbf5d24
commit 84ea0c9a97
  1. 6
      modules/highgui/src/rgbe.cpp
  2. 25
      modules/highgui/test/test_grfmt.cpp
  3. 5
      modules/photo/src/hdr_fusion.cpp
  4. 78
      modules/photo/test/test_hdr.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);

@ -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");
vector<int>param(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);
}
}

@ -91,6 +91,7 @@ void makeHDR(InputArrayOfArrays _images, std::vector<float> exp_times, OutputArr
triangleWeights(weights);
generateResponce(responce);
float max = 0;
float *res_ptr = result.ptr<float>();
for(size_t pos = 0; pos < result.total(); pos++, res_ptr += 3) {
@ -108,8 +109,12 @@ void makeHDR(InputArrayOfArrays _images, std::vector<float> 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;
}
};

@ -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 <string>
#include <algorithm>
using namespace cv;
using namespace std;
TEST(Photo_MakeHdr, regression)
{
string folder = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
vector<string>file_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";
vector<Mat>images(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;
vector<float>times(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);
}
Loading…
Cancel
Save