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