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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
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.
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.
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.
42 #include "test_precomp.hpp"
43 #include "opencv2/core/core_c.h"
45 namespace opencv_test { namespace {
47 class CV_UndistortPointsBadArgTest : public cvtest::BadArgTest
50 CV_UndistortPointsBadArgTest();
58 //static const int N_POINTS = 1;
59 static const int N_POINTS2 = 2;
65 cv::Mat distortion_coeffs;
67 std::vector<cv::Point2f> dst_points;
71 CV_UndistortPointsBadArgTest::CV_UndistortPointsBadArgTest ()
75 void CV_UndistortPointsBadArgTest::run_func()
77 cv::undistortPoints(src_points,dst_points,camera_mat,distortion_coeffs,R,P);
80 void CV_UndistortPointsBadArgTest::run(int)
82 //RNG& rng = ts->get_rng();
86 img_size.height = 600;
87 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};
88 double dist[4] = {0.01,0.02,0.001,0.0005};
89 double s_points[N_POINTS2] = {
90 static_cast<double>(img_size.width) / 4.0,
91 static_cast<double>(img_size.height) / 4.0,
93 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};
94 double r[9] = {1,0,0,0,1,0,0,0,1};
96 CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
97 CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
98 CvMat _P_orig = cvMat(3,3,CV_64F,p);
99 CvMat _R_orig = cvMat(3,3,CV_64F,r);
100 CvMat _src_points_orig = cvMat(1,4,CV_64FC2,s_points);
102 camera_mat = cv::cvarrToMat(&_camera_mat_orig);
103 distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
104 P = cv::cvarrToMat(&_P_orig);
105 R = cv::cvarrToMat(&_R_orig);
106 src_points = cv::cvarrToMat(&_src_points_orig);
108 src_points.create(2, 2, CV_32FC2);
109 errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
110 src_points = cv::cvarrToMat(&_src_points_orig);
112 src_points.create(1, 4, CV_64FC2);
113 errcount += run_test_case( CV_StsAssert, "Invalid input data matrix type" );
114 src_points = cv::cvarrToMat(&_src_points_orig);
116 src_points = cv::Mat();
117 errcount += run_test_case( CV_StsBadArg, "Input data matrix is not continuous" );
118 src_points = cv::cvarrToMat(&_src_points_orig);
121 ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
126 class CV_InitUndistortRectifyMapBadArgTest : public cvtest::BadArgTest
129 CV_InitUndistortRectifyMapBadArgTest();
138 cv::Mat new_camera_mat;
139 cv::Mat distortion_coeffs;
146 CV_InitUndistortRectifyMapBadArgTest::CV_InitUndistortRectifyMapBadArgTest ()
150 void CV_InitUndistortRectifyMapBadArgTest::run_func()
152 cv::initUndistortRectifyMap(camera_mat,distortion_coeffs,R,new_camera_mat,img_size,mat_type,mapx,mapy);
155 void CV_InitUndistortRectifyMapBadArgTest::run(int)
159 img_size.width = 800;
160 img_size.height = 600;
161 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};
162 double dist[4] = {0.01,0.02,0.001,0.0005};
163 std::vector<float> arr_mapx(img_size.width*img_size.height);
164 std::vector<float> arr_mapy(img_size.width*img_size.height);
165 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};
166 double r[9] = {1,0,0,0,1,0,0,0,1};
168 CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
169 CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
170 CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
171 CvMat _R_orig = cvMat(3,3,CV_64F,r);
172 CvMat _mapx_orig = cvMat(img_size.height,img_size.width,CV_32FC1,&arr_mapx[0]);
173 CvMat _mapy_orig = cvMat(img_size.height,img_size.width,CV_32FC1,&arr_mapy[0]);
174 int mat_type_orig = CV_32FC1;
176 camera_mat = cv::cvarrToMat(&_camera_mat_orig);
177 distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
178 new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
179 R = cv::cvarrToMat(&_R_orig);
180 mapx = cv::cvarrToMat(&_mapx_orig);
181 mapy = cv::cvarrToMat(&_mapy_orig);
184 errcount += run_test_case( CV_StsAssert, "Invalid map matrix type" );
185 mat_type = mat_type_orig;
187 camera_mat.create(3, 2, CV_32F);
188 errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
189 camera_mat = cv::cvarrToMat(&_camera_mat_orig);
191 R.create(4, 3, CV_32F);
192 errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
193 R = cv::cvarrToMat(&_R_orig);
195 distortion_coeffs.create(6, 1, CV_32F);
196 errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
197 distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
200 ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
205 class CV_UndistortBadArgTest : public cvtest::BadArgTest
208 CV_UndistortBadArgTest();
218 cv::Mat new_camera_mat;
219 cv::Mat distortion_coeffs;
225 CV_UndistortBadArgTest::CV_UndistortBadArgTest ()
229 void CV_UndistortBadArgTest::run_func()
231 cv::undistort(src,dst,camera_mat,distortion_coeffs,new_camera_mat);
234 void CV_UndistortBadArgTest::run(int)
238 img_size.width = 800;
239 img_size.height = 600;
240 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};
241 double dist[4] = {0.01,0.02,0.001,0.0005};
242 std::vector<float> arr_src(img_size.width*img_size.height);
243 std::vector<float> arr_dst(img_size.width*img_size.height);
244 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};
246 CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
247 CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
248 CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
249 CvMat _src_orig = cvMat(img_size.height,img_size.width,CV_32FC1,&arr_src[0]);
250 CvMat _dst_orig = cvMat(img_size.height,img_size.width,CV_32FC1,&arr_dst[0]);
252 camera_mat = cv::cvarrToMat(&_camera_mat_orig);
253 distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
254 new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
255 src = cv::cvarrToMat(&_src_orig);
256 dst = cv::cvarrToMat(&_dst_orig);
258 camera_mat.create(5, 5, CV_64F);
259 errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
262 ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
265 TEST(Calib3d_UndistortPoints, badarg) { CV_UndistortPointsBadArgTest test; test.safe_run(); }
266 TEST(Calib3d_InitUndistortRectifyMap, badarg) { CV_InitUndistortRectifyMapBadArgTest test; test.safe_run(); }
267 TEST(Calib3d_Undistort, badarg) { CV_UndistortBadArgTest test; test.safe_run(); }