perf_detection.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2014, Biagio Montesano, 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 the copyright holders 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 "perf_precomp.hpp"
  42. namespace opencv_test { namespace {
  43. typedef perf::TestBaseWithParam<std::string> file_str;
  44. #define IMAGES \
  45. "cv/line_descriptor/cameraman.jpg", "cv/shared/lena.png"
  46. void createMatFromVec( const std::vector<KeyLine>& linesVec, Mat& output );
  47. void createMatFromVec( const std::vector<KeyLine>& linesVec, Mat& output )
  48. {
  49. output = Mat( (int) linesVec.size(), 17, CV_32FC1 );
  50. for ( int i = 0; i < (int) linesVec.size(); i++ )
  51. {
  52. std::vector<float> klData;
  53. KeyLine kl = linesVec[i];
  54. klData.push_back( kl.angle );
  55. klData.push_back( (float) kl.class_id );
  56. klData.push_back( kl.ePointInOctaveX );
  57. klData.push_back( kl.ePointInOctaveY );
  58. klData.push_back( kl.endPointX );
  59. klData.push_back( kl.endPointY );
  60. klData.push_back( kl.lineLength );
  61. klData.push_back( (float) kl.numOfPixels );
  62. klData.push_back( (float) kl.octave );
  63. klData.push_back( kl.pt.x );
  64. klData.push_back( kl.pt.y );
  65. klData.push_back( kl.response );
  66. klData.push_back( kl.sPointInOctaveX );
  67. klData.push_back( kl.sPointInOctaveY );
  68. klData.push_back( kl.size );
  69. klData.push_back( kl.startPointX );
  70. klData.push_back( kl.startPointY );
  71. float* pointerToRow = output.ptr<float>( i );
  72. for ( int j = 0; j < 17; j++ )
  73. {
  74. *pointerToRow = klData[j];
  75. pointerToRow++;
  76. }
  77. }
  78. }
  79. PERF_TEST_P(file_str, detect, testing::Values(IMAGES))
  80. {
  81. std::string filename = getDataPath( GetParam() );
  82. Mat frame = imread( filename, 1 );
  83. if( frame.empty() )
  84. FAIL()<< "Unable to load source image " << filename;
  85. Mat lines;
  86. std::vector<KeyLine> keylines;
  87. Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor();
  88. TEST_CYCLE()
  89. {
  90. bd->detect( frame, keylines );
  91. createMatFromVec( keylines, lines );
  92. }
  93. SANITY_CHECK_NOTHING();
  94. }
  95. PERF_TEST_P(file_str, detect_lsd, testing::Values(IMAGES))
  96. {
  97. std::string filename = getDataPath( GetParam() );
  98. std::cout << filename.c_str() << std::endl;
  99. Mat frame = imread( filename, 1 );
  100. if( frame.empty() )
  101. FAIL()<< "Unable to load source image " << filename;
  102. Mat lines;
  103. std::vector<KeyLine> keylines;
  104. Ptr<LSDDetector> lsd = LSDDetector::createLSDDetector();
  105. TEST_CYCLE()
  106. {
  107. lsd->detect( frame, keylines, 2, 1 );
  108. createMatFromVec( keylines, lines );
  109. }
  110. SANITY_CHECK_NOTHING();
  111. }
  112. }} // namespace