Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/calib3d/test/test_undistort_badarg.cpp
16337 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
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.
8
//
9
//
10
// Intel License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2000, Intel Corporation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of Intel Corporation may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#include "test_precomp.hpp"
43
#include "opencv2/calib3d/calib3d_c.h"
44
45
namespace opencv_test { namespace {
46
47
class CV_UndistortPointsBadArgTest : public cvtest::BadArgTest
48
{
49
public:
50
CV_UndistortPointsBadArgTest();
51
protected:
52
void run(int);
53
void run_func();
54
55
private:
56
//common
57
cv::Size img_size;
58
bool useCPlus;
59
//static const int N_POINTS = 1;
60
static const int N_POINTS2 = 2;
61
62
//C
63
CvMat* _camera_mat;
64
CvMat* matR;
65
CvMat* matP;
66
CvMat* _distortion_coeffs;
67
CvMat* _src_points;
68
CvMat* _dst_points;
69
70
71
//C++
72
cv::Mat camera_mat;
73
cv::Mat R;
74
cv::Mat P;
75
cv::Mat distortion_coeffs;
76
cv::Mat src_points;
77
std::vector<cv::Point2f> dst_points;
78
79
};
80
81
CV_UndistortPointsBadArgTest::CV_UndistortPointsBadArgTest ()
82
{
83
useCPlus = false;
84
_camera_mat = matR = matP = _distortion_coeffs = _src_points = _dst_points = NULL;
85
}
86
87
void CV_UndistortPointsBadArgTest::run_func()
88
{
89
if (useCPlus)
90
{
91
cv::undistortPoints(src_points,dst_points,camera_mat,distortion_coeffs,R,P);
92
}
93
else
94
{
95
cvUndistortPoints(_src_points,_dst_points,_camera_mat,_distortion_coeffs,matR,matP);
96
}
97
}
98
99
void CV_UndistortPointsBadArgTest::run(int)
100
{
101
//RNG& rng = ts->get_rng();
102
int errcount = 0;
103
useCPlus = false;
104
//initializing
105
img_size.width = 800;
106
img_size.height = 600;
107
double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
108
double dist[4] = {0.01,0.02,0.001,0.0005};
109
double s_points[N_POINTS2] = {
110
static_cast<double>(img_size.width) / 4.0,
111
static_cast<double>(img_size.height) / 4.0,
112
};
113
double d_points[N_POINTS2];
114
double p[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
115
double r[9] = {1,0,0,0,1,0,0,0,1};
116
117
CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
118
CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
119
CvMat _P_orig = cvMat(3,3,CV_64F,p);
120
CvMat _R_orig = cvMat(3,3,CV_64F,r);
121
CvMat _src_points_orig = cvMat(1,4,CV_64FC2,s_points);
122
CvMat _dst_points_orig = cvMat(1,4,CV_64FC2,d_points);
123
124
_camera_mat = &_camera_mat_orig;
125
_distortion_coeffs = &_distortion_coeffs_orig;
126
matP = &_P_orig;
127
matR = &_R_orig;
128
_src_points = &_src_points_orig;
129
_dst_points = &_dst_points_orig;
130
131
//tests
132
CvMat* temp1;
133
CvMat* temp;
134
IplImage* temp_img = cvCreateImage(cvSize(img_size.width,img_size.height),8,3);
135
136
//-----------
137
temp = (CvMat*)temp_img;
138
_src_points = temp;
139
errcount += run_test_case( CV_StsAssert, "Input data is not CvMat*" );
140
_src_points = &_src_points_orig;
141
142
temp = (CvMat*)temp_img;
143
_dst_points = temp;
144
errcount += run_test_case( CV_StsAssert, "Output data is not CvMat*" );
145
_dst_points = &_dst_points_orig;
146
147
temp = cvCreateMat(2,3,CV_64F);
148
_src_points = temp;
149
errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
150
_src_points = &_src_points_orig;
151
cvReleaseMat(&temp);
152
153
temp = cvCreateMat(2,3,CV_64F);
154
_dst_points = temp;
155
errcount += run_test_case(CV_StsAssert, "Invalid output data matrix size" );
156
_dst_points = &_dst_points_orig;
157
cvReleaseMat(&temp);
158
159
temp = cvCreateMat(1,3,CV_64F);
160
temp1 = cvCreateMat(4,1,CV_64F);
161
_dst_points = temp;
162
_src_points = temp1;
163
errcount += run_test_case(CV_StsAssert, "Output and input data sizes mismatch" );
164
_dst_points = &_dst_points_orig;
165
_src_points = &_src_points_orig;
166
cvReleaseMat(&temp);
167
cvReleaseMat(&temp1);
168
169
temp = cvCreateMat(1,3,CV_32S);
170
_dst_points = temp;
171
errcount += run_test_case(CV_StsAssert, "Invalid output data matrix type" );
172
_dst_points = &_dst_points_orig;
173
cvReleaseMat(&temp);
174
175
temp = cvCreateMat(1,3,CV_32S);
176
_src_points = temp;
177
errcount += run_test_case(CV_StsAssert, "Invalid input data matrix type" );
178
_src_points = &_src_points_orig;
179
cvReleaseMat(&temp);
180
//------------
181
temp = cvCreateMat(2,3,CV_64F);
182
_camera_mat = temp;
183
errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
184
_camera_mat = &_camera_mat_orig;
185
cvReleaseMat(&temp);
186
187
temp = cvCreateMat(3,4,CV_64F);
188
_camera_mat = temp;
189
errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
190
_camera_mat = &_camera_mat_orig;
191
cvReleaseMat(&temp);
192
193
temp = (CvMat*)temp_img;
194
_camera_mat = temp;
195
errcount += run_test_case( CV_StsAssert, "Camera data is not CvMat*" );
196
_camera_mat = &_camera_mat_orig;
197
//----------
198
199
temp = (CvMat*)temp_img;
200
_distortion_coeffs = temp;
201
errcount += run_test_case( CV_StsAssert, "Distortion coefficients data is not CvMat*" );
202
_distortion_coeffs = &_distortion_coeffs_orig;
203
204
temp = cvCreateMat(1,6,CV_64F);
205
_distortion_coeffs = temp;
206
errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
207
_distortion_coeffs = &_distortion_coeffs_orig;
208
cvReleaseMat(&temp);
209
210
temp = cvCreateMat(3,3,CV_64F);
211
_distortion_coeffs = temp;
212
errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
213
_distortion_coeffs = &_distortion_coeffs_orig;
214
cvReleaseMat(&temp);
215
//----------
216
temp = (CvMat*)temp_img;
217
matR = temp;
218
errcount += run_test_case( CV_StsAssert, "R data is not CvMat*" );
219
matR = &_R_orig;
220
221
temp = cvCreateMat(4,3,CV_64F);
222
matR = temp;
223
errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
224
matR = &_R_orig;
225
cvReleaseMat(&temp);
226
227
temp = cvCreateMat(3,2,CV_64F);
228
matR = temp;
229
errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
230
matR = &_R_orig;
231
cvReleaseMat(&temp);
232
233
//-----------
234
temp = (CvMat*)temp_img;
235
matP = temp;
236
errcount += run_test_case( CV_StsAssert, "P data is not CvMat*" );
237
matP = &_P_orig;
238
239
temp = cvCreateMat(4,3,CV_64F);
240
matP = temp;
241
errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );
242
matP = &_P_orig;
243
cvReleaseMat(&temp);
244
245
temp = cvCreateMat(3,2,CV_64F);
246
matP = temp;
247
errcount += run_test_case( CV_StsAssert, "Invalid P data matrix size" );
248
matP = &_P_orig;
249
cvReleaseMat(&temp);
250
//------------
251
//C++ tests
252
useCPlus = true;
253
254
camera_mat = cv::cvarrToMat(&_camera_mat_orig);
255
distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
256
P = cv::cvarrToMat(&_P_orig);
257
R = cv::cvarrToMat(&_R_orig);
258
src_points = cv::cvarrToMat(&_src_points_orig);
259
260
temp = cvCreateMat(2,2,CV_32FC2);
261
src_points = cv::cvarrToMat(temp);
262
errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
263
src_points = cv::cvarrToMat(&_src_points_orig);
264
cvReleaseMat(&temp);
265
266
temp = cvCreateMat(1,4,CV_64FC2);
267
src_points = cv::cvarrToMat(temp);
268
errcount += run_test_case( CV_StsAssert, "Invalid input data matrix type" );
269
src_points = cv::cvarrToMat(&_src_points_orig);
270
cvReleaseMat(&temp);
271
272
src_points = cv::Mat();
273
errcount += run_test_case( CV_StsAssert, "Input data matrix is not continuous" );
274
src_points = cv::cvarrToMat(&_src_points_orig);
275
cvReleaseMat(&temp);
276
277
278
279
//------------
280
cvReleaseImage(&temp_img);
281
ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
282
}
283
284
285
//=========
286
class CV_InitUndistortRectifyMapBadArgTest : public cvtest::BadArgTest
287
{
288
public:
289
CV_InitUndistortRectifyMapBadArgTest();
290
protected:
291
void run(int);
292
void run_func();
293
294
private:
295
//common
296
cv::Size img_size;
297
bool useCPlus;
298
299
//C
300
CvMat* _camera_mat;
301
CvMat* matR;
302
CvMat* _new_camera_mat;
303
CvMat* _distortion_coeffs;
304
CvMat* _mapx;
305
CvMat* _mapy;
306
307
308
//C++
309
cv::Mat camera_mat;
310
cv::Mat R;
311
cv::Mat new_camera_mat;
312
cv::Mat distortion_coeffs;
313
cv::Mat mapx;
314
cv::Mat mapy;
315
int mat_type;
316
317
};
318
319
CV_InitUndistortRectifyMapBadArgTest::CV_InitUndistortRectifyMapBadArgTest ()
320
{
321
useCPlus = false;
322
_camera_mat = matR = _new_camera_mat = _distortion_coeffs = _mapx = _mapy = NULL;
323
}
324
325
void CV_InitUndistortRectifyMapBadArgTest::run_func()
326
{
327
if (useCPlus)
328
{
329
cv::initUndistortRectifyMap(camera_mat,distortion_coeffs,R,new_camera_mat,img_size,mat_type,mapx,mapy);
330
}
331
else
332
{
333
cvInitUndistortRectifyMap(_camera_mat,_distortion_coeffs,matR,_new_camera_mat,_mapx,_mapy);
334
}
335
}
336
337
void CV_InitUndistortRectifyMapBadArgTest::run(int)
338
{
339
int errcount = 0;
340
//initializing
341
img_size.width = 800;
342
img_size.height = 600;
343
double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
344
double dist[4] = {0.01,0.02,0.001,0.0005};
345
float* arr_mapx = new float[img_size.width*img_size.height];
346
float* arr_mapy = new float[img_size.width*img_size.height];
347
double arr_new_camera_mat[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
348
double r[9] = {1,0,0,0,1,0,0,0,1};
349
350
CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
351
CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
352
CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
353
CvMat _R_orig = cvMat(3,3,CV_64F,r);
354
CvMat _mapx_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapx);
355
CvMat _mapy_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_mapy);
356
int mat_type_orig = CV_32FC1;
357
358
_camera_mat = &_camera_mat_orig;
359
_distortion_coeffs = &_distortion_coeffs_orig;
360
_new_camera_mat = &_new_camera_mat_orig;
361
matR = &_R_orig;
362
_mapx = &_mapx_orig;
363
_mapy = &_mapy_orig;
364
mat_type = mat_type_orig;
365
366
//tests
367
useCPlus = true;
368
CvMat* temp;
369
370
//C++ tests
371
useCPlus = true;
372
373
camera_mat = cv::cvarrToMat(&_camera_mat_orig);
374
distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
375
new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
376
R = cv::cvarrToMat(&_R_orig);
377
mapx = cv::cvarrToMat(&_mapx_orig);
378
mapy = cv::cvarrToMat(&_mapy_orig);
379
380
381
mat_type = CV_64F;
382
errcount += run_test_case( CV_StsAssert, "Invalid map matrix type" );
383
mat_type = mat_type_orig;
384
385
temp = cvCreateMat(3,2,CV_32FC1);
386
camera_mat = cv::cvarrToMat(temp);
387
errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
388
camera_mat = cv::cvarrToMat(&_camera_mat_orig);
389
cvReleaseMat(&temp);
390
391
temp = cvCreateMat(4,3,CV_32FC1);
392
R = cv::cvarrToMat(temp);
393
errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
394
R = cv::cvarrToMat(&_R_orig);
395
cvReleaseMat(&temp);
396
397
temp = cvCreateMat(6,1,CV_32FC1);
398
distortion_coeffs = cv::cvarrToMat(temp);
399
errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
400
distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
401
cvReleaseMat(&temp);
402
403
//------------
404
delete[] arr_mapx;
405
delete[] arr_mapy;
406
ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
407
}
408
409
410
//=========
411
class CV_UndistortBadArgTest : public cvtest::BadArgTest
412
{
413
public:
414
CV_UndistortBadArgTest();
415
protected:
416
void run(int);
417
void run_func();
418
419
private:
420
//common
421
cv::Size img_size;
422
bool useCPlus;
423
424
//C
425
CvMat* _camera_mat;
426
CvMat* _new_camera_mat;
427
CvMat* _distortion_coeffs;
428
CvMat* _src;
429
CvMat* _dst;
430
431
432
//C++
433
cv::Mat camera_mat;
434
cv::Mat new_camera_mat;
435
cv::Mat distortion_coeffs;
436
cv::Mat src;
437
cv::Mat dst;
438
439
};
440
441
CV_UndistortBadArgTest::CV_UndistortBadArgTest ()
442
{
443
useCPlus = false;
444
_camera_mat = _new_camera_mat = _distortion_coeffs = _src = _dst = NULL;
445
}
446
447
void CV_UndistortBadArgTest::run_func()
448
{
449
if (useCPlus)
450
{
451
cv::undistort(src,dst,camera_mat,distortion_coeffs,new_camera_mat);
452
}
453
else
454
{
455
cvUndistort2(_src,_dst,_camera_mat,_distortion_coeffs,_new_camera_mat);
456
}
457
}
458
459
void CV_UndistortBadArgTest::run(int)
460
{
461
int errcount = 0;
462
//initializing
463
img_size.width = 800;
464
img_size.height = 600;
465
double cam[9] = {150.f, 0.f, img_size.width/2.f, 0, 300.f, img_size.height/2.f, 0.f, 0.f, 1.f};
466
double dist[4] = {0.01,0.02,0.001,0.0005};
467
float* arr_src = new float[img_size.width*img_size.height];
468
float* arr_dst = new float[img_size.width*img_size.height];
469
double arr_new_camera_mat[9] = {155.f, 0.f, img_size.width/2.f+img_size.width/50.f, 0, 310.f, img_size.height/2.f+img_size.height/50.f, 0.f, 0.f, 1.f};
470
471
CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
472
CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
473
CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
474
CvMat _src_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_src);
475
CvMat _dst_orig = cvMat(img_size.height,img_size.width,CV_32FC1,arr_dst);
476
477
_camera_mat = &_camera_mat_orig;
478
_distortion_coeffs = &_distortion_coeffs_orig;
479
_new_camera_mat = &_new_camera_mat_orig;
480
_src = &_src_orig;
481
_dst = &_dst_orig;
482
483
//tests
484
useCPlus = true;
485
CvMat* temp;
486
CvMat* temp1;
487
488
//C tests
489
useCPlus = false;
490
491
temp = cvCreateMat(800,600,CV_32F);
492
temp1 = cvCreateMat(800,601,CV_32F);
493
_src = temp;
494
_dst = temp1;
495
errcount += run_test_case( CV_StsAssert, "Input and output data matrix sizes mismatch" );
496
_src = &_src_orig;
497
_dst = &_dst_orig;
498
cvReleaseMat(&temp);
499
cvReleaseMat(&temp1);
500
501
temp = cvCreateMat(800,600,CV_32F);
502
temp1 = cvCreateMat(800,600,CV_64F);
503
_src = temp;
504
_dst = temp1;
505
errcount += run_test_case( CV_StsAssert, "Input and output data matrix types mismatch" );
506
_src = &_src_orig;
507
_dst = &_dst_orig;
508
cvReleaseMat(&temp);
509
cvReleaseMat(&temp1);
510
511
//C++ tests
512
useCPlus = true;
513
514
camera_mat = cv::cvarrToMat(&_camera_mat_orig);
515
distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
516
new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
517
src = cv::cvarrToMat(&_src_orig);
518
dst = cv::cvarrToMat(&_dst_orig);
519
520
//------------
521
delete[] arr_src;
522
delete[] arr_dst;
523
ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
524
}
525
526
TEST(Calib3d_UndistortPoints, badarg) { CV_UndistortPointsBadArgTest test; test.safe_run(); }
527
TEST(Calib3d_InitUndistortRectifyMap, badarg) { CV_InitUndistortRectifyMapBadArgTest test; test.safe_run(); }
528
TEST(Calib3d_Undistort, badarg) { CV_UndistortBadArgTest test; test.safe_run(); }
529
530
}} // namespace
531
/* End of file. */
532
533