Home | History | Annotate | Download | only in test
      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 "test_chessboardgenerator.hpp"
     44 #include "opencv2/calib3d/calib3d_c.h"
     45 
     46 #include <limits>
     47 
     48 using namespace std;
     49 using namespace cv;
     50 
     51 class CV_ChessboardDetectorBadArgTest : public cvtest::BadArgTest
     52 {
     53 public:
     54     CV_ChessboardDetectorBadArgTest();
     55 protected:
     56     void run(int);
     57     bool checkByGenerator();
     58 
     59     bool cpp;
     60 
     61     /* cpp interface */
     62     Mat img;
     63     Size pattern_size;
     64     int flags;
     65     vector<Point2f> corners;
     66 
     67     /* c interface */
     68     CvMat arr;
     69     CvPoint2D32f* out_corners;
     70     int* out_corner_count;
     71 
     72 
     73     /* c interface draw  corners */
     74     bool drawCorners;
     75     CvMat drawCorImg;
     76     bool was_found;
     77 
     78     void run_func()
     79     {
     80         if (cpp)
     81             findChessboardCorners(img, pattern_size, corners, flags);
     82         else
     83             if (!drawCorners)
     84                 cvFindChessboardCorners( &arr, pattern_size, out_corners, out_corner_count, flags );
     85             else
     86                 cvDrawChessboardCorners( &drawCorImg, pattern_size,
     87                     (CvPoint2D32f*)(corners.empty() ? 0 : &corners[0]),
     88                     (int)corners.size(), was_found);
     89     }
     90 };
     91 
     92 CV_ChessboardDetectorBadArgTest::CV_ChessboardDetectorBadArgTest()
     93 {
     94     cpp = false;
     95     flags = 0;
     96     out_corners = NULL;
     97     out_corner_count = NULL;
     98     drawCorners = was_found = false;
     99 }
    100 
    101 /* ///////////////////// chess_corner_test ///////////////////////// */
    102 void CV_ChessboardDetectorBadArgTest::run( int /*start_from */)
    103 {
    104     Mat bg(800, 600, CV_8U, Scalar(0));
    105     Mat_<float> camMat(3, 3);
    106     camMat << 300.f, 0.f, bg.cols/2.f, 0, 300.f, bg.rows/2.f, 0.f, 0.f, 1.f;
    107     Mat_<float> distCoeffs(1, 5);
    108     distCoeffs << 1.2f, 0.2f, 0.f, 0.f, 0.f;
    109 
    110     ChessBoardGenerator cbg(Size(8,6));
    111     vector<Point2f> exp_corn;
    112     Mat cb = cbg(bg, camMat, distCoeffs, exp_corn);
    113 
    114     /* /*//*/ */
    115     int errors = 0;
    116     flags = CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE;
    117     cpp = true;
    118 
    119     img = cb.clone();
    120     pattern_size = Size(2,2);
    121     errors += run_test_case( CV_StsOutOfRange, "Invlid pattern size" );
    122 
    123     pattern_size = cbg.cornersSize();
    124     cb.convertTo(img, CV_32F);
    125     errors += run_test_case( CV_StsUnsupportedFormat, "Not 8-bit image" );
    126 
    127     cv::merge(vector<Mat>(2, cb), img);
    128     errors += run_test_case( CV_StsUnsupportedFormat, "2 channel image" );
    129 
    130     cpp = false;
    131     drawCorners = false;
    132 
    133     img = cb.clone();
    134     arr = img;
    135     out_corner_count = 0;
    136     out_corners = 0;
    137     errors += run_test_case( CV_StsNullPtr, "Null pointer to corners" );
    138 
    139     drawCorners = true;
    140     Mat cvdrawCornImg(img.size(), CV_8UC2);
    141     drawCorImg = cvdrawCornImg;
    142     was_found = true;
    143     errors += run_test_case( CV_StsUnsupportedFormat, "2 channel image" );
    144 
    145 
    146     if (errors)
    147         ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
    148     else
    149         ts->set_failed_test_info(cvtest::TS::OK);
    150 }
    151 
    152 TEST(Calib3d_ChessboardDetector, badarg) { CV_ChessboardDetectorBadArgTest test; test.safe_run(); }
    153 
    154 /* End of file. */
    155