Merge new changes
authorFedor Morozov <f-morozov@ya.ru>
Wed, 18 Sep 2013 14:21:45 +0000 (18:21 +0400)
committerFedor Morozov <f-morozov@ya.ru>
Wed, 18 Sep 2013 14:21:45 +0000 (18:21 +0400)
1  2 
modules/photo/src/calibrate.cpp
modules/photo/test/test_hdr.cpp

@@@ -80,14 -100,13 +100,12 @@@ public
              Mat B = Mat::zeros(A.rows, 1, CV_32F);
  
              int eq = 0;
-             for(int i = 0; i < samples; i++) {
-                 int pos = 3 * (rand() % images[0].total()) + channel;
+             for(size_t i = 0; i < sample_points.size(); i++) {
 -
                  for(size_t j = 0; j < images.size(); j++) {
  
-                     int val = (images[j].ptr() + pos)[0];
+                     int val = images[j].ptr()[3*(sample_points[i].y * images[j].cols + sample_points[j].x) + channel];
                      A.at<float>(eq, val) = w.at<float>(val);
-                     A.at<float>(eq, 256 + i) = -w.at<float>(val);
+                     A.at<float>(eq, LDR_SIZE + i) = -w.at<float>(val);
                      B.at<float>(eq, 0) = w.at<float>(val) * log(times[j]);        
                      eq++;
                  }
@@@ -185,9 -185,31 +185,33 @@@ TEST(Photo_MergeDebevec, regression
        Ptr<MergeDebevec> merge = createMergeDebevec();
  
        Mat result, expected;
-       loadImage(test_path + "merge/debevec.exr", expected);
+       loadImage(test_path + "merge/debevec.hdr", expected);
        merge->process(images, result, times, response);
-       imwrite("test.exr", result);
++
+     Ptr<Tonemap> map = createTonemap();
+     map->process(result, result);
+     map->process(expected, expected);
+       checkEqual(expected, result, 1e-2f);
+ }
+ TEST(Photo_MergeRobertson, regression)
+ {
+       string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
+       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);
+     Ptr<Tonemap> map = createTonemap();
+     map->process(result, result);
+     map->process(expected, expected);
++
        checkEqual(expected, result, 1e-2f);
  }
  
@@@ -201,7 -223,25 +225,26 @@@ TEST(Photo_CalibrateDebevec, regression
        loadExposureSeq(test_path + "exposures/", images, times);
      loadResponseCSV(test_path + "calibrate/debevec.csv", expected);
        Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();
-     srand(1);
++
+       calibrate->process(images, response, times);
+     Mat diff = abs(response - expected);
+     diff = diff.mul(1.0f / response);
+     double max;
+     minMaxLoc(diff, NULL, &max);
+     ASSERT_FALSE(max > 0.1);
+ }
+ TEST(Photo_CalibrateRobertson, regression)
+ {
+       string test_path = string(cvtest::TS::ptr()->get_data_path()) + "hdr/";
+       vector<Mat> images;
+       vector<float> times;
+       Mat response, expected;
+       loadExposureSeq(test_path + "exposures/", images, times);
+     loadResponseCSV(test_path + "calibrate/robertson.csv", expected);
+       Ptr<CalibrateRobertson> calibrate = createCalibrateRobertson();
        calibrate->process(images, response, times);
      checkEqual(expected, response, 1e-3f);
 -}
 +}