Path: blob/master/modules/calib3d/test/test_chesscorners_badarg.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// Intel License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000, Intel Corporation, all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of Intel Corporation may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "test_precomp.hpp"42#include "test_chessboardgenerator.hpp"43#include "opencv2/calib3d/calib3d_c.h"4445namespace opencv_test { namespace {4647class CV_ChessboardDetectorBadArgTest : public cvtest::BadArgTest48{49public:50CV_ChessboardDetectorBadArgTest();51protected:52void run(int);53bool checkByGenerator();5455bool cpp;5657/* cpp interface */58Mat img;59Size pattern_size;60int flags;61vector<Point2f> corners;6263/* c interface */64CvMat arr;65CvPoint2D32f* out_corners;66int* out_corner_count;676869/* c interface draw corners */70bool drawCorners;71CvMat drawCorImg;72bool was_found;7374void run_func()75{76if (cpp)77findChessboardCorners(img, pattern_size, corners, flags);78else79if (!drawCorners)80cvFindChessboardCorners( &arr, cvSize(pattern_size), out_corners, out_corner_count, flags );81else82cvDrawChessboardCorners( &drawCorImg, cvSize(pattern_size),83(CvPoint2D32f*)(corners.empty() ? 0 : &corners[0]),84(int)corners.size(), was_found);85}86};8788CV_ChessboardDetectorBadArgTest::CV_ChessboardDetectorBadArgTest()89{90cpp = false;91flags = 0;92out_corners = NULL;93out_corner_count = NULL;94drawCorners = was_found = false;95}9697/* ///////////////////// chess_corner_test ///////////////////////// */98void CV_ChessboardDetectorBadArgTest::run( int /*start_from */)99{100Mat bg(800, 600, CV_8U, Scalar(0));101Mat_<float> camMat(3, 3);102camMat << 300.f, 0.f, bg.cols/2.f, 0, 300.f, bg.rows/2.f, 0.f, 0.f, 1.f;103Mat_<float> distCoeffs(1, 5);104distCoeffs << 1.2f, 0.2f, 0.f, 0.f, 0.f;105106ChessBoardGenerator cbg(Size(8,6));107vector<Point2f> exp_corn;108Mat cb = cbg(bg, camMat, distCoeffs, exp_corn);109110/* /*//*/ */111int errors = 0;112flags = CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE;113cpp = true;114115img = cb.clone();116pattern_size = Size(2,2);117errors += run_test_case( CV_StsOutOfRange, "Invlid pattern size" );118119pattern_size = cbg.cornersSize();120cb.convertTo(img, CV_32F);121errors += run_test_case( CV_StsUnsupportedFormat, "Not 8-bit image" );122123cv::merge(vector<Mat>(2, cb), img);124errors += run_test_case( CV_StsUnsupportedFormat, "2 channel image" );125126cpp = false;127drawCorners = false;128129img = cb.clone();130arr = cvMat(img);131out_corner_count = 0;132out_corners = 0;133errors += run_test_case( CV_StsNullPtr, "Null pointer to corners" );134135drawCorners = true;136Mat cvdrawCornImg(img.size(), CV_8UC2);137drawCorImg = cvMat(cvdrawCornImg);138was_found = true;139errors += run_test_case( CV_StsUnsupportedFormat, "2 channel image" );140141142if (errors)143ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);144else145ts->set_failed_test_info(cvtest::TS::OK);146}147148TEST(Calib3d_ChessboardDetector, badarg) { CV_ChessboardDetectorBadArgTest test; test.safe_run(); }149150}} // namespace151/* End of file. */152153154