1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
43
#include "test_precomp.hpp"
44
#include "opencv2/calib3d/calib3d_c.h"
51
template<class T> double thres() { return 1.0; }
52
template<> double thres<float>() { return 1e-5; }
54
class CV_ReprojectImageTo3DTest : public cvtest::BaseTest
57
CV_ReprojectImageTo3DTest() {}
58
~CV_ReprojectImageTo3DTest() {}
64
ts->set_failed_test_info(cvtest::TS::OK);
68
progress = update_progress( progress, 1, 14, 0 );
69
runCase<float, float>(++caseId, -100.f, 100.f);
70
progress = update_progress( progress, 2, 14, 0 );
71
runCase<int, float>(++caseId, -100, 100);
72
progress = update_progress( progress, 3, 14, 0 );
73
runCase<short, float>(++caseId, -100, 100);
74
progress = update_progress( progress, 4, 14, 0 );
75
runCase<unsigned char, float>(++caseId, 10, 100);
76
progress = update_progress( progress, 5, 14, 0 );
78
runCase<float, int>(++caseId, -100.f, 100.f);
79
progress = update_progress( progress, 6, 14, 0 );
80
runCase<int, int>(++caseId, -100, 100);
81
progress = update_progress( progress, 7, 14, 0 );
82
runCase<short, int>(++caseId, -100, 100);
83
progress = update_progress( progress, 8, 14, 0 );
84
runCase<unsigned char, int>(++caseId, 10, 100);
85
progress = update_progress( progress, 10, 14, 0 );
87
runCase<float, short>(++caseId, -100.f, 100.f);
88
progress = update_progress( progress, 11, 14, 0 );
89
runCase<int, short>(++caseId, -100, 100);
90
progress = update_progress( progress, 12, 14, 0 );
91
runCase<short, short>(++caseId, -100, 100);
92
progress = update_progress( progress, 13, 14, 0 );
93
runCase<unsigned char, short>(++caseId, 10, 100);
94
progress = update_progress( progress, 14, 14, 0 );
97
template<class U, class V> double error(const Vec<U, 3>& v1, const Vec<V, 3>& v2) const
101
for(int i = 0; i < 3; ++i)
110
return sqrt(sum)/(sqrt(nsum)+1.);
113
template<class InT, class OutT> void runCase(int caseId, InT min, InT max)
115
typedef Vec<OutT, 3> out3d_t;
117
bool handleMissingValues = (unsigned)theRNG() % 2 == 0;
119
Mat_<InT> disp(Size(320, 240));
120
randu(disp, Scalar(min), Scalar(max));
122
if (handleMissingValues)
123
disp(disp.rows/2, disp.cols/2) = min - 1;
125
Mat_<double> Q(4, 4);
126
randu(Q, Scalar(-5), Scalar(5));
128
Mat_<out3d_t> _3dImg(disp.size());
130
CvMat cvdisp = disp; CvMat cv_3dImg = _3dImg; CvMat cvQ = Q;
131
cvReprojectImageTo3D( &cvdisp, &cv_3dImg, &cvQ, handleMissingValues );
133
if (numeric_limits<OutT>::max() == numeric_limits<float>::max())
134
reprojectImageTo3D(disp, _3dImg, Q, handleMissingValues);
136
for(int y = 0; y < disp.rows; ++y)
137
for(int x = 0; x < disp.cols; ++x)
142
static_cast<double>(x),
143
static_cast<double>(y),
144
static_cast<double>(d),
147
Mat_<double> res = Q * Mat_<double>(4, 1, from);
150
out3d_t pixel_exp = *res.ptr<Vec3d>();
151
out3d_t pixel_out = _3dImg(y, x);
153
const int largeZValue = 10000; /* see documentation */
155
if (handleMissingValues && y == disp.rows/2 && x == disp.cols/2)
157
if (pixel_out[2] == largeZValue)
160
ts->printf(cvtest::TS::LOG, "Missing values are handled improperly\n");
161
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
166
double err = error(pixel_out, pixel_exp), t = thres<OutT>();
169
ts->printf(cvtest::TS::LOG, "case %d. too big error at (%d, %d): %g vs expected %g: res = (%g, %g, %g, w=%g) vs pixel_out = (%g, %g, %g)\n",
170
caseId, x, y, err, t, res(0,0), res(1,0), res(2,0), res(3,0),
171
(double)pixel_out[0], (double)pixel_out[1], (double)pixel_out[2]);
172
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
180
TEST(Calib3d_ReprojectImageTo3D, accuracy) { CV_ReprojectImageTo3DTest test; test.safe_run(); }