PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/source/3rd_party/opencv/sources/modules/calib3d/test/test_chesscorners_timing.cpp

https://gitlab.com/Ruggero/SparkEngine_Desktop
C++ | 184 lines | 103 code | 35 blank | 46 comment | 11 complexity | bdafc7b68e5fb963b9efebdb43f406a7 MD5 | raw file
  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. code = cvtest::TS::FAIL_MISSING_TEST_DATA;
  96. continue;
  97. }
  98. ts->printf(cvtest::TS::LOG, "%s: chessboard %d:\n", imgname, is_chessboard);
  99. gray = cvCreateImage( cvSize( img->width, img->height ), IPL_DEPTH_8U, 1 );
  100. thresh = cvCreateImage( cvSize( img->width, img->height ), IPL_DEPTH_8U, 1 );
  101. cvCvtColor( img, gray, CV_BGR2GRAY );
  102. count0 = pattern_size.width*pattern_size.height;
  103. /* allocate additional buffers */
  104. _v = cvCreateMat(1, count0, CV_32FC2);
  105. count = count0;
  106. v = (CvPoint2D32f*)_v->data.fl;
  107. int64 _time0 = cvGetTickCount();
  108. result = cvCheckChessboard(gray, pattern_size);
  109. int64 _time01 = cvGetTickCount();
  110. OPENCV_CALL( result1 = cvFindChessboardCorners(
  111. gray, pattern_size, v, &count, 15 ));
  112. int64 _time1 = cvGetTickCount();
  113. if( result != is_chessboard )
  114. {
  115. ts->printf( cvtest::TS::LOG, "Error: chessboard was %sdetected in the image %s\n",
  116. result ? "" : "not ", imgname );
  117. code = cvtest::TS::FAIL_INVALID_OUTPUT;
  118. goto _exit_;
  119. }
  120. if(result != result1)
  121. {
  122. ts->printf( cvtest::TS::LOG, "Warning: results differ cvCheckChessboard %d, cvFindChessboardCorners %d\n",
  123. result, result1);
  124. }
  125. int num_pixels = gray->width*gray->height;
  126. float check_chessboard_time = float(_time01 - _time0)/(float)cvGetTickFrequency(); // in us
  127. ts->printf(cvtest::TS::LOG, " cvCheckChessboard time s: %f, us per pixel: %f\n",
  128. check_chessboard_time*1e-6, check_chessboard_time/num_pixels);
  129. float find_chessboard_time = float(_time1 - _time01)/(float)cvGetTickFrequency();
  130. ts->printf(cvtest::TS::LOG, " cvFindChessboard time s: %f, us per pixel: %f\n",
  131. find_chessboard_time*1e-6, find_chessboard_time/num_pixels);
  132. cvReleaseMat( &_v );
  133. cvReleaseImage( &img );
  134. cvReleaseImage( &gray );
  135. cvReleaseImage( &thresh );
  136. progress = update_progress( progress, idx-1, max_idx, 0 );
  137. }
  138. _exit_:
  139. /* release occupied memory */
  140. cvReleaseMat( &_v );
  141. cvReleaseFileStorage( &fs );
  142. cvReleaseImage( &img );
  143. cvReleaseImage( &gray );
  144. cvReleaseImage( &thresh );
  145. if( code < 0 )
  146. ts->set_failed_test_info( code );
  147. }
  148. TEST(Calib3d_ChessboardDetector, timing) { CV_ChessboardDetectorTimingTest test; test.safe_run(); }
  149. /* End of file. */