test_chesscorners_badarg.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 "test_chessboardgenerator.hpp"
  43. #include "opencv2/calib3d/calib3d_c.h"
  44. namespace opencv_test { namespace {
  45. class CV_ChessboardDetectorBadArgTest : public cvtest::BadArgTest
  46. {
  47. public:
  48. CV_ChessboardDetectorBadArgTest() { flags0 = 0; }
  49. protected:
  50. void run(int);
  51. bool checkByGenerator();
  52. Mat img;
  53. Size pattern_size, pattern_size0;
  54. int flags, flags0;
  55. vector<Point2f> corners;
  56. _InputArray img_arg;
  57. _OutputArray corners_arg;
  58. void initArgs()
  59. {
  60. img_arg = img;
  61. corners_arg = corners;
  62. pattern_size = pattern_size0;
  63. flags = flags0;
  64. }
  65. void run_func()
  66. {
  67. findChessboardCorners(img_arg, pattern_size, corners_arg, flags);
  68. }
  69. };
  70. /* ///////////////////// chess_corner_test ///////////////////////// */
  71. void CV_ChessboardDetectorBadArgTest::run( int /*start_from */)
  72. {
  73. Mat bg(800, 600, CV_8U, Scalar(0));
  74. Mat_<float> camMat(3, 3);
  75. camMat << 300.f, 0.f, bg.cols/2.f, 0, 300.f, bg.rows/2.f, 0.f, 0.f, 1.f;
  76. Mat_<float> distCoeffs(1, 5);
  77. distCoeffs << 1.2f, 0.2f, 0.f, 0.f, 0.f;
  78. ChessBoardGenerator cbg(Size(8,6));
  79. vector<Point2f> exp_corn;
  80. Mat cb = cbg(bg, camMat, distCoeffs, exp_corn);
  81. /* /*//*/ */
  82. int errors = 0;
  83. flags = CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE;
  84. img = cb.clone();
  85. initArgs();
  86. pattern_size = Size(2,2);
  87. errors += run_test_case( Error::StsOutOfRange, "Invalid pattern size" );
  88. pattern_size = cbg.cornersSize();
  89. cb.convertTo(img, CV_32F);
  90. errors += run_test_case( Error::StsUnsupportedFormat, "Not 8-bit image" );
  91. cv::merge(vector<Mat>(2, cb), img);
  92. errors += run_test_case( Error::StsUnsupportedFormat, "2 channel image" );
  93. if (errors)
  94. ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
  95. else
  96. ts->set_failed_test_info(cvtest::TS::OK);
  97. }
  98. TEST(Calib3d_ChessboardDetector, badarg) { CV_ChessboardDetectorBadArgTest test; test.safe_run(); }
  99. }} // namespace
  100. /* End of file. */