test_undistort_badarg.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. #include "test_precomp.hpp"
  42. #include "opencv2/core/core_c.h"
  43. namespace opencv_test { namespace {
  44. class CV_UndistortPointsBadArgTest : public cvtest::BadArgTest
  45. {
  46. public:
  47. CV_UndistortPointsBadArgTest();
  48. protected:
  49. void run(int);
  50. void run_func();
  51. private:
  52. //common
  53. cv::Size img_size;
  54. //static const int N_POINTS = 1;
  55. static const int N_POINTS2 = 2;
  56. //C++
  57. cv::Mat camera_mat;
  58. cv::Mat R;
  59. cv::Mat P;
  60. cv::Mat distortion_coeffs;
  61. cv::Mat src_points;
  62. std::vector<cv::Point2f> dst_points;
  63. };
  64. CV_UndistortPointsBadArgTest::CV_UndistortPointsBadArgTest ()
  65. {
  66. }
  67. void CV_UndistortPointsBadArgTest::run_func()
  68. {
  69. cv::undistortPoints(src_points,dst_points,camera_mat,distortion_coeffs,R,P);
  70. }
  71. void CV_UndistortPointsBadArgTest::run(int)
  72. {
  73. //RNG& rng = ts->get_rng();
  74. int errcount = 0;
  75. //initializing
  76. img_size.width = 800;
  77. img_size.height = 600;
  78. 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};
  79. double dist[4] = {0.01,0.02,0.001,0.0005};
  80. double s_points[N_POINTS2] = {
  81. static_cast<double>(img_size.width) / 4.0,
  82. static_cast<double>(img_size.height) / 4.0,
  83. };
  84. 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};
  85. double r[9] = {1,0,0,0,1,0,0,0,1};
  86. CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
  87. CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
  88. CvMat _P_orig = cvMat(3,3,CV_64F,p);
  89. CvMat _R_orig = cvMat(3,3,CV_64F,r);
  90. CvMat _src_points_orig = cvMat(1,4,CV_64FC2,s_points);
  91. camera_mat = cv::cvarrToMat(&_camera_mat_orig);
  92. distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
  93. P = cv::cvarrToMat(&_P_orig);
  94. R = cv::cvarrToMat(&_R_orig);
  95. src_points = cv::cvarrToMat(&_src_points_orig);
  96. src_points.create(2, 2, CV_32FC2);
  97. errcount += run_test_case( CV_StsAssert, "Invalid input data matrix size" );
  98. src_points = cv::cvarrToMat(&_src_points_orig);
  99. src_points.create(1, 4, CV_64FC2);
  100. errcount += run_test_case( CV_StsAssert, "Invalid input data matrix type" );
  101. src_points = cv::cvarrToMat(&_src_points_orig);
  102. src_points = cv::Mat();
  103. errcount += run_test_case( CV_StsBadArg, "Input data matrix is not continuous" );
  104. src_points = cv::cvarrToMat(&_src_points_orig);
  105. //------------
  106. ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
  107. }
  108. //=========
  109. class CV_InitUndistortRectifyMapBadArgTest : public cvtest::BadArgTest
  110. {
  111. public:
  112. CV_InitUndistortRectifyMapBadArgTest();
  113. protected:
  114. void run(int);
  115. void run_func();
  116. private:
  117. cv::Size img_size;
  118. cv::Mat camera_mat;
  119. cv::Mat R;
  120. cv::Mat new_camera_mat;
  121. cv::Mat distortion_coeffs;
  122. cv::Mat mapx;
  123. cv::Mat mapy;
  124. int mat_type;
  125. };
  126. CV_InitUndistortRectifyMapBadArgTest::CV_InitUndistortRectifyMapBadArgTest ()
  127. {
  128. }
  129. void CV_InitUndistortRectifyMapBadArgTest::run_func()
  130. {
  131. cv::initUndistortRectifyMap(camera_mat,distortion_coeffs,R,new_camera_mat,img_size,mat_type,mapx,mapy);
  132. }
  133. void CV_InitUndistortRectifyMapBadArgTest::run(int)
  134. {
  135. int errcount = 0;
  136. //initializing
  137. img_size.width = 800;
  138. img_size.height = 600;
  139. 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};
  140. double dist[4] = {0.01,0.02,0.001,0.0005};
  141. std::vector<float> arr_mapx(img_size.width*img_size.height);
  142. std::vector<float> arr_mapy(img_size.width*img_size.height);
  143. 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};
  144. double r[9] = {1,0,0,0,1,0,0,0,1};
  145. CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
  146. CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
  147. CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
  148. CvMat _R_orig = cvMat(3,3,CV_64F,r);
  149. CvMat _mapx_orig = cvMat(img_size.height,img_size.width,CV_32FC1,&arr_mapx[0]);
  150. CvMat _mapy_orig = cvMat(img_size.height,img_size.width,CV_32FC1,&arr_mapy[0]);
  151. int mat_type_orig = CV_32FC1;
  152. camera_mat = cv::cvarrToMat(&_camera_mat_orig);
  153. distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
  154. new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
  155. R = cv::cvarrToMat(&_R_orig);
  156. mapx = cv::cvarrToMat(&_mapx_orig);
  157. mapy = cv::cvarrToMat(&_mapy_orig);
  158. mat_type = CV_64F;
  159. errcount += run_test_case( CV_StsAssert, "Invalid map matrix type" );
  160. mat_type = mat_type_orig;
  161. camera_mat.create(3, 2, CV_32F);
  162. errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
  163. camera_mat = cv::cvarrToMat(&_camera_mat_orig);
  164. R.create(4, 3, CV_32F);
  165. errcount += run_test_case( CV_StsAssert, "Invalid R data matrix size" );
  166. R = cv::cvarrToMat(&_R_orig);
  167. distortion_coeffs.create(6, 1, CV_32F);
  168. errcount += run_test_case( CV_StsAssert, "Invalid distortion coefficients data matrix size" );
  169. distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
  170. //------------
  171. ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
  172. }
  173. //=========
  174. class CV_UndistortBadArgTest : public cvtest::BadArgTest
  175. {
  176. public:
  177. CV_UndistortBadArgTest();
  178. protected:
  179. void run(int);
  180. void run_func();
  181. private:
  182. //common
  183. cv::Size img_size;
  184. cv::Mat camera_mat;
  185. cv::Mat new_camera_mat;
  186. cv::Mat distortion_coeffs;
  187. cv::Mat src;
  188. cv::Mat dst;
  189. };
  190. CV_UndistortBadArgTest::CV_UndistortBadArgTest ()
  191. {
  192. }
  193. void CV_UndistortBadArgTest::run_func()
  194. {
  195. cv::undistort(src,dst,camera_mat,distortion_coeffs,new_camera_mat);
  196. }
  197. void CV_UndistortBadArgTest::run(int)
  198. {
  199. int errcount = 0;
  200. //initializing
  201. img_size.width = 800;
  202. img_size.height = 600;
  203. 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};
  204. double dist[4] = {0.01,0.02,0.001,0.0005};
  205. std::vector<float> arr_src(img_size.width*img_size.height);
  206. std::vector<float> arr_dst(img_size.width*img_size.height);
  207. 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};
  208. CvMat _camera_mat_orig = cvMat(3,3,CV_64F,cam);
  209. CvMat _distortion_coeffs_orig = cvMat(1,4,CV_64F,dist);
  210. CvMat _new_camera_mat_orig = cvMat(3,3,CV_64F,arr_new_camera_mat);
  211. CvMat _src_orig = cvMat(img_size.height,img_size.width,CV_32FC1,&arr_src[0]);
  212. CvMat _dst_orig = cvMat(img_size.height,img_size.width,CV_32FC1,&arr_dst[0]);
  213. camera_mat = cv::cvarrToMat(&_camera_mat_orig);
  214. distortion_coeffs = cv::cvarrToMat(&_distortion_coeffs_orig);
  215. new_camera_mat = cv::cvarrToMat(&_new_camera_mat_orig);
  216. src = cv::cvarrToMat(&_src_orig);
  217. dst = cv::cvarrToMat(&_dst_orig);
  218. camera_mat.create(5, 5, CV_64F);
  219. errcount += run_test_case( CV_StsAssert, "Invalid camera data matrix size" );
  220. //------------
  221. ts->set_failed_test_info(errcount > 0 ? cvtest::TS::FAIL_BAD_ARG_CHECK : cvtest::TS::OK);
  222. }
  223. TEST(Calib3d_UndistortPoints, badarg) { CV_UndistortPointsBadArgTest test; test.safe_run(); }
  224. TEST(Calib3d_InitUndistortRectifyMap, badarg) { CV_InitUndistortRectifyMapBadArgTest test; test.safe_run(); }
  225. TEST(Calib3d_Undistort, badarg) { CV_UndistortBadArgTest test; test.safe_run(); }
  226. }} // namespace
  227. /* End of file. */