Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/calib3d/test/test_chesscorners_timing.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 "opencv2/imgproc/imgproc_c.h"
44
#include "opencv2/calib3d/calib3d_c.h"
45
46
namespace opencv_test { namespace {
47
48
class CV_ChessboardDetectorTimingTest : public cvtest::BaseTest
49
{
50
public:
51
CV_ChessboardDetectorTimingTest();
52
protected:
53
void run(int);
54
};
55
56
57
CV_ChessboardDetectorTimingTest::CV_ChessboardDetectorTimingTest()
58
{
59
}
60
61
/* ///////////////////// chess_corner_test ///////////////////////// */
62
void CV_ChessboardDetectorTimingTest::run( int start_from )
63
{
64
int code = cvtest::TS::OK;
65
66
/* test parameters */
67
std::string filepath;
68
std::string filename;
69
70
CvMat* _v = 0;
71
CvPoint2D32f* v;
72
73
IplImage img;
74
IplImage* gray = 0;
75
IplImage* thresh = 0;
76
77
int idx, max_idx;
78
int progress = 0;
79
80
filepath = cv::format("%scv/cameracalibration/", ts->get_data_path().c_str() );
81
filename = cv::format("%schessboard_timing_list.dat", filepath.c_str() );
82
CvFileStorage* fs = cvOpenFileStorage( filename.c_str(), 0, CV_STORAGE_READ );
83
CvFileNode* board_list = fs ? cvGetFileNodeByName( fs, 0, "boards" ) : 0;
84
85
if( !fs || !board_list || !CV_NODE_IS_SEQ(board_list->tag) ||
86
board_list->data.seq->total % 4 != 0 )
87
{
88
ts->printf( cvtest::TS::LOG, "chessboard_timing_list.dat can not be read or is not valid" );
89
code = cvtest::TS::FAIL_MISSING_TEST_DATA;
90
goto _exit_;
91
}
92
93
max_idx = board_list->data.seq->total/4;
94
95
for( idx = start_from; idx < max_idx; idx++ )
96
{
97
int count0 = -1;
98
int count = 0;
99
Size pattern_size;
100
int result, result1 = 0;
101
102
const char* imgname = cvReadString((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4), "dummy.txt");
103
int is_chessboard = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4+1), 0);
104
pattern_size.width = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 2), -1);
105
pattern_size.height = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 3), -1);
106
107
ts->update_context( this, idx-1, true );
108
109
/* read the image */
110
filename = cv::format("%s%s", filepath.c_str(), imgname );
111
112
cv::Mat img2 = cv::imread( filename );
113
img = cvIplImage(img2);
114
115
if( img2.empty() )
116
{
117
ts->printf( cvtest::TS::LOG, "one of chessboard images can't be read: %s\n", filename.c_str() );
118
code = cvtest::TS::FAIL_MISSING_TEST_DATA;
119
continue;
120
}
121
122
ts->printf(cvtest::TS::LOG, "%s: chessboard %d:\n", imgname, is_chessboard);
123
124
gray = cvCreateImage( cvSize( img.width, img.height ), IPL_DEPTH_8U, 1 );
125
thresh = cvCreateImage( cvSize( img.width, img.height ), IPL_DEPTH_8U, 1 );
126
cvCvtColor( &img, gray, CV_BGR2GRAY );
127
128
129
count0 = pattern_size.width*pattern_size.height;
130
131
/* allocate additional buffers */
132
_v = cvCreateMat(1, count0, CV_32FC2);
133
count = count0;
134
135
v = (CvPoint2D32f*)_v->data.fl;
136
137
int64 _time0 = cvGetTickCount();
138
result = cvCheckChessboard(gray, cvSize(pattern_size));
139
int64 _time01 = cvGetTickCount();
140
141
OPENCV_CALL( result1 = cvFindChessboardCorners(
142
gray, cvSize(pattern_size), v, &count, 15 ));
143
int64 _time1 = cvGetTickCount();
144
145
if( result != is_chessboard )
146
{
147
ts->printf( cvtest::TS::LOG, "Error: chessboard was %sdetected in the image %s\n",
148
result ? "" : "not ", imgname );
149
code = cvtest::TS::FAIL_INVALID_OUTPUT;
150
goto _exit_;
151
}
152
if(result != result1)
153
{
154
ts->printf( cvtest::TS::LOG, "Warning: results differ cvCheckChessboard %d, cvFindChessboardCorners %d\n",
155
result, result1);
156
}
157
158
int num_pixels = gray->width*gray->height;
159
float check_chessboard_time = float(_time01 - _time0)/(float)cvGetTickFrequency(); // in us
160
ts->printf(cvtest::TS::LOG, " cvCheckChessboard time s: %f, us per pixel: %f\n",
161
check_chessboard_time*1e-6, check_chessboard_time/num_pixels);
162
163
float find_chessboard_time = float(_time1 - _time01)/(float)cvGetTickFrequency();
164
ts->printf(cvtest::TS::LOG, " cvFindChessboard time s: %f, us per pixel: %f\n",
165
find_chessboard_time*1e-6, find_chessboard_time/num_pixels);
166
167
cvReleaseMat( &_v );
168
cvReleaseImage( &gray );
169
cvReleaseImage( &thresh );
170
progress = update_progress( progress, idx-1, max_idx, 0 );
171
}
172
173
_exit_:
174
175
/* release occupied memory */
176
cvReleaseMat( &_v );
177
cvReleaseFileStorage( &fs );
178
cvReleaseImage( &gray );
179
cvReleaseImage( &thresh );
180
181
if( code < 0 )
182
ts->set_failed_test_info( code );
183
}
184
185
TEST(Calib3d_ChessboardDetector, timing) { CV_ChessboardDetectorTimingTest test; test.safe_run(); }
186
187
}} // namespace
188
/* End of file. */
189
190