Path: blob/master/modules/calib3d/test/test_chesscorners_timing.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 "opencv2/imgproc/imgproc_c.h"43#include "opencv2/calib3d/calib3d_c.h"4445namespace opencv_test { namespace {4647class CV_ChessboardDetectorTimingTest : public cvtest::BaseTest48{49public:50CV_ChessboardDetectorTimingTest();51protected:52void run(int);53};545556CV_ChessboardDetectorTimingTest::CV_ChessboardDetectorTimingTest()57{58}5960/* ///////////////////// chess_corner_test ///////////////////////// */61void CV_ChessboardDetectorTimingTest::run( int start_from )62{63int code = cvtest::TS::OK;6465/* test parameters */66std::string filepath;67std::string filename;6869CvMat* _v = 0;70CvPoint2D32f* v;7172IplImage img;73IplImage* gray = 0;74IplImage* thresh = 0;7576int idx, max_idx;77int progress = 0;7879filepath = cv::format("%scv/cameracalibration/", ts->get_data_path().c_str() );80filename = cv::format("%schessboard_timing_list.dat", filepath.c_str() );81CvFileStorage* fs = cvOpenFileStorage( filename.c_str(), 0, CV_STORAGE_READ );82CvFileNode* board_list = fs ? cvGetFileNodeByName( fs, 0, "boards" ) : 0;8384if( !fs || !board_list || !CV_NODE_IS_SEQ(board_list->tag) ||85board_list->data.seq->total % 4 != 0 )86{87ts->printf( cvtest::TS::LOG, "chessboard_timing_list.dat can not be read or is not valid" );88code = cvtest::TS::FAIL_MISSING_TEST_DATA;89goto _exit_;90}9192max_idx = board_list->data.seq->total/4;9394for( idx = start_from; idx < max_idx; idx++ )95{96int count0 = -1;97int count = 0;98Size pattern_size;99int result, result1 = 0;100101const char* imgname = cvReadString((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4), "dummy.txt");102int is_chessboard = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4+1), 0);103pattern_size.width = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 2), -1);104pattern_size.height = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 3), -1);105106ts->update_context( this, idx-1, true );107108/* read the image */109filename = cv::format("%s%s", filepath.c_str(), imgname );110111cv::Mat img2 = cv::imread( filename );112img = cvIplImage(img2);113114if( img2.empty() )115{116ts->printf( cvtest::TS::LOG, "one of chessboard images can't be read: %s\n", filename.c_str() );117code = cvtest::TS::FAIL_MISSING_TEST_DATA;118continue;119}120121ts->printf(cvtest::TS::LOG, "%s: chessboard %d:\n", imgname, is_chessboard);122123gray = cvCreateImage( cvSize( img.width, img.height ), IPL_DEPTH_8U, 1 );124thresh = cvCreateImage( cvSize( img.width, img.height ), IPL_DEPTH_8U, 1 );125cvCvtColor( &img, gray, CV_BGR2GRAY );126127128count0 = pattern_size.width*pattern_size.height;129130/* allocate additional buffers */131_v = cvCreateMat(1, count0, CV_32FC2);132count = count0;133134v = (CvPoint2D32f*)_v->data.fl;135136int64 _time0 = cvGetTickCount();137result = cvCheckChessboard(gray, cvSize(pattern_size));138int64 _time01 = cvGetTickCount();139140OPENCV_CALL( result1 = cvFindChessboardCorners(141gray, cvSize(pattern_size), v, &count, 15 ));142int64 _time1 = cvGetTickCount();143144if( result != is_chessboard )145{146ts->printf( cvtest::TS::LOG, "Error: chessboard was %sdetected in the image %s\n",147result ? "" : "not ", imgname );148code = cvtest::TS::FAIL_INVALID_OUTPUT;149goto _exit_;150}151if(result != result1)152{153ts->printf( cvtest::TS::LOG, "Warning: results differ cvCheckChessboard %d, cvFindChessboardCorners %d\n",154result, result1);155}156157int num_pixels = gray->width*gray->height;158float check_chessboard_time = float(_time01 - _time0)/(float)cvGetTickFrequency(); // in us159ts->printf(cvtest::TS::LOG, " cvCheckChessboard time s: %f, us per pixel: %f\n",160check_chessboard_time*1e-6, check_chessboard_time/num_pixels);161162float find_chessboard_time = float(_time1 - _time01)/(float)cvGetTickFrequency();163ts->printf(cvtest::TS::LOG, " cvFindChessboard time s: %f, us per pixel: %f\n",164find_chessboard_time*1e-6, find_chessboard_time/num_pixels);165166cvReleaseMat( &_v );167cvReleaseImage( &gray );168cvReleaseImage( &thresh );169progress = update_progress( progress, idx-1, max_idx, 0 );170}171172_exit_:173174/* release occupied memory */175cvReleaseMat( &_v );176cvReleaseFileStorage( &fs );177cvReleaseImage( &gray );178cvReleaseImage( &thresh );179180if( code < 0 )181ts->set_failed_test_info( code );182}183184TEST(Calib3d_ChessboardDetector, timing) { CV_ChessboardDetectorTimingTest test; test.safe_run(); }185186}} // namespace187/* End of file. */188189190