test_chesscorners_timing.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #include "opencv2/imgproc.hpp"
  43. #include "opencv2/calib3d.hpp"
  44. namespace opencv_test { namespace {
  45. class CV_ChessboardDetectorTimingTest : public cvtest::BaseTest
  46. {
  47. public:
  48. CV_ChessboardDetectorTimingTest();
  49. protected:
  50. void run(int);
  51. };
  52. CV_ChessboardDetectorTimingTest::CV_ChessboardDetectorTimingTest()
  53. {
  54. }
  55. /* ///////////////////// chess_corner_test ///////////////////////// */
  56. void CV_ChessboardDetectorTimingTest::run( int start_from )
  57. {
  58. int code = cvtest::TS::OK;
  59. /* test parameters */
  60. std::string filepath;
  61. std::string filename;
  62. std::vector<Point2f> v;
  63. Mat img, gray, thresh;
  64. int idx, max_idx;
  65. int progress = 0;
  66. filepath = cv::format("%scv/cameracalibration/", ts->get_data_path().c_str() );
  67. filename = cv::format("%schessboard_timing_list.dat", filepath.c_str() );
  68. cv::FileStorage fs( filename, FileStorage::READ );
  69. cv::FileNode board_list = fs["boards"];
  70. cv::FileNodeIterator bl_it = board_list.begin();
  71. if( !fs.isOpened() || !board_list.isSeq() || board_list.size() % 4 != 0 )
  72. {
  73. ts->printf( cvtest::TS::LOG, "chessboard_timing_list.dat can not be read or is not valid" );
  74. code = cvtest::TS::FAIL_MISSING_TEST_DATA;
  75. goto _exit_;
  76. }
  77. max_idx = (int)(board_list.size()/4);
  78. for( idx = 0; idx < start_from; idx++ )
  79. {
  80. bl_it += 4;
  81. }
  82. for( idx = start_from; idx < max_idx; idx++ )
  83. {
  84. Size pattern_size;
  85. std::string imgname; read(*bl_it++, imgname, "dummy.txt");
  86. int is_chessboard = 0;
  87. read(*bl_it++, is_chessboard, 0);
  88. read(*bl_it++, pattern_size.width, -1);
  89. read(*bl_it++, pattern_size.height, -1);
  90. ts->update_context( this, idx-1, true );
  91. /* read the image */
  92. filename = cv::format("%s%s", filepath.c_str(), imgname.c_str() );
  93. img = cv::imread( filename );
  94. if( img.empty() )
  95. {
  96. ts->printf( cvtest::TS::LOG, "one of chessboard images can't be read: %s\n", filename.c_str() );
  97. code = cvtest::TS::FAIL_MISSING_TEST_DATA;
  98. continue;
  99. }
  100. ts->printf(cvtest::TS::LOG, "%s: chessboard %d:\n", imgname.c_str(), is_chessboard);
  101. cvtColor(img, gray, COLOR_BGR2GRAY);
  102. int64 _time0 = cv::getTickCount();
  103. bool result = cv::checkChessboard(gray, pattern_size);
  104. int64 _time01 = cv::getTickCount();
  105. bool result1 = findChessboardCorners(gray, pattern_size, v, 15);
  106. int64 _time1 = cv::getTickCount();
  107. if( result != (is_chessboard != 0))
  108. {
  109. ts->printf( cvtest::TS::LOG, "Error: chessboard was %sdetected in the image %s\n",
  110. result ? "" : "not ", imgname.c_str() );
  111. code = cvtest::TS::FAIL_INVALID_OUTPUT;
  112. goto _exit_;
  113. }
  114. if(result != result1)
  115. {
  116. ts->printf( cvtest::TS::LOG, "Warning: results differ cvCheckChessboard %d, cvFindChessboardCorners %d\n",
  117. (int)result, (int)result1);
  118. }
  119. int num_pixels = gray.cols*gray.rows;
  120. float check_chessboard_time = float(_time01 - _time0)/(float)cv::getTickFrequency(); // in us
  121. ts->printf(cvtest::TS::LOG, " cvCheckChessboard time s: %f, us per pixel: %f\n",
  122. check_chessboard_time*1e-6, check_chessboard_time/num_pixels);
  123. float find_chessboard_time = float(_time1 - _time01)/(float)cv::getTickFrequency();
  124. ts->printf(cvtest::TS::LOG, " cvFindChessboard time s: %f, us per pixel: %f\n",
  125. find_chessboard_time*1e-6, find_chessboard_time/num_pixels);
  126. progress = update_progress( progress, idx-1, max_idx, 0 );
  127. }
  128. _exit_:
  129. if( code < 0 )
  130. ts->set_failed_test_info( code );
  131. }
  132. TEST(Calib3d_ChessboardDetector, timing) { CV_ChessboardDetectorTimingTest test; test.safe_run(); }
  133. }} // namespace
  134. /* End of file. */