PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/OpenCV-2.4.2/modules/calib3d/test/test_chesscorners_timing.cpp

#
C++ | 188 lines | 107 code | 35 blank | 46 comment | 13 complexity | d91447e5d4d4fe199f4386a799e27482 MD5 | raw file
Possible License(s): BSD-3-Clause
  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. #include "test_precomp.hpp"
  42. class CV_ChessboardDetectorTimingTest : public cvtest::BaseTest
  43. {
  44. public:
  45. CV_ChessboardDetectorTimingTest();
  46. protected:
  47. void run(int);
  48. };
  49. CV_ChessboardDetectorTimingTest::CV_ChessboardDetectorTimingTest()
  50. {
  51. }
  52. /* ///////////////////// chess_corner_test ///////////////////////// */
  53. void CV_ChessboardDetectorTimingTest::run( int start_from )
  54. {
  55. int code = cvtest::TS::OK;
  56. /* test parameters */
  57. char filepath[1000];
  58. char filename[1000];
  59. CvMat* _v = 0;
  60. CvPoint2D32f* v;
  61. IplImage* img = 0;
  62. IplImage* gray = 0;
  63. IplImage* thresh = 0;
  64. int idx, max_idx;
  65. int progress = 0;
  66. sprintf( filepath, "%scameracalibration/", ts->get_data_path().c_str() );
  67. sprintf( filename, "%schessboard_timing_list.dat", filepath );
  68. CvFileStorage* fs = cvOpenFileStorage( filename, 0, CV_STORAGE_READ );
  69. CvFileNode* board_list = fs ? cvGetFileNodeByName( fs, 0, "boards" ) : 0;
  70. if( !fs || !board_list || !CV_NODE_IS_SEQ(board_list->tag) ||
  71. board_list->data.seq->total % 4 != 0 )
  72. {
  73. ts->printf( cvtest::TS::LOG, "chessboard_timing_list.dat can not be readed or is not valid" );
  74. code = cvtest::TS::FAIL_MISSING_TEST_DATA;
  75. goto _exit_;
  76. }
  77. max_idx = board_list->data.seq->total/4;
  78. for( idx = start_from; idx < max_idx; idx++ )
  79. {
  80. int count0 = -1;
  81. int count = 0;
  82. CvSize pattern_size;
  83. int result, result1 = 0;
  84. const char* imgname = cvReadString((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4), "dummy.txt");
  85. int is_chessboard = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4+1), 0);
  86. pattern_size.width = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 2), -1);
  87. pattern_size.height = cvReadInt((CvFileNode*)cvGetSeqElem(board_list->data.seq,idx*4 + 3), -1);
  88. ts->update_context( this, idx-1, true );
  89. /* read the image */
  90. sprintf( filename, "%s%s", filepath, imgname );
  91. img = cvLoadImage( filename );
  92. if( !img )
  93. {
  94. ts->printf( cvtest::TS::LOG, "one of chessboard images can't be read: %s\n", filename );
  95. if( max_idx == 1 )
  96. {
  97. code = cvtest::TS::FAIL_MISSING_TEST_DATA;
  98. goto _exit_;
  99. }
  100. continue;
  101. }
  102. ts->printf(cvtest::TS::LOG, "%s: chessboard %d:\n", imgname, is_chessboard);
  103. gray = cvCreateImage( cvSize( img->width, img->height ), IPL_DEPTH_8U, 1 );
  104. thresh = cvCreateImage( cvSize( img->width, img->height ), IPL_DEPTH_8U, 1 );
  105. cvCvtColor( img, gray, CV_BGR2GRAY );
  106. count0 = pattern_size.width*pattern_size.height;
  107. /* allocate additional buffers */
  108. _v = cvCreateMat(1, count0, CV_32FC2);
  109. count = count0;
  110. v = (CvPoint2D32f*)_v->data.fl;
  111. int64 _time0 = cvGetTickCount();
  112. result = cvCheckChessboard(gray, pattern_size);
  113. int64 _time01 = cvGetTickCount();
  114. OPENCV_CALL( result1 = cvFindChessboardCorners(
  115. gray, pattern_size, v, &count, 15 ));
  116. int64 _time1 = cvGetTickCount();
  117. if( result != is_chessboard )
  118. {
  119. ts->printf( cvtest::TS::LOG, "Error: chessboard was %sdetected in the image %s\n",
  120. result ? "" : "not ", imgname );
  121. code = cvtest::TS::FAIL_INVALID_OUTPUT;
  122. goto _exit_;
  123. }
  124. if(result != result1)
  125. {
  126. ts->printf( cvtest::TS::LOG, "Warning: results differ cvCheckChessboard %d, cvFindChessboardCorners %d\n",
  127. result, result1);
  128. }
  129. int num_pixels = gray->width*gray->height;
  130. float check_chessboard_time = float(_time01 - _time0)/(float)cvGetTickFrequency(); // in us
  131. ts->printf(cvtest::TS::LOG, " cvCheckChessboard time s: %f, us per pixel: %f\n",
  132. check_chessboard_time*1e-6, check_chessboard_time/num_pixels);
  133. float find_chessboard_time = float(_time1 - _time01)/(float)cvGetTickFrequency();
  134. ts->printf(cvtest::TS::LOG, " cvFindChessboard time s: %f, us per pixel: %f\n",
  135. find_chessboard_time*1e-6, find_chessboard_time/num_pixels);
  136. cvReleaseMat( &_v );
  137. cvReleaseImage( &img );
  138. cvReleaseImage( &gray );
  139. cvReleaseImage( &thresh );
  140. progress = update_progress( progress, idx-1, max_idx, 0 );
  141. }
  142. _exit_:
  143. /* release occupied memory */
  144. cvReleaseMat( &_v );
  145. cvReleaseFileStorage( &fs );
  146. cvReleaseImage( &img );
  147. cvReleaseImage( &gray );
  148. cvReleaseImage( &thresh );
  149. if( code < 0 )
  150. ts->set_failed_test_info( code );
  151. }
  152. TEST(Calib3d_ChessboardDetector, timing) { CV_ChessboardDetectorTimingTest test; test.safe_run(); }
  153. /* End of file. */