PageRenderTime 206ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/cv/src/latentsvmdetector.cpp

https://github.com/SCS-B3C/OpenCV2-2
C++ | 125 lines | 70 code | 14 blank | 41 comment | 14 complexity | 9dc4baad318ef0f003d0570038b14aee 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. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #include "cvtest.h"
  43. #include <string>
  44. using namespace cv;
  45. const int num_detections = 3;
  46. const float true_scores[3] = {-0.383931f, -0.825876f, -0.959934f};
  47. const float score_thr = 0.05f;
  48. const CvRect true_bounding_boxes[3] = {cvRect(0, 45, 362, 452), cvRect(304, 0, 64, 80), cvRect(236, 0, 108, 59)};
  49. class CV_LatentSVMDetectorTest : public CvTest
  50. {
  51. public:
  52. CV_LatentSVMDetectorTest();
  53. ~CV_LatentSVMDetectorTest();
  54. protected:
  55. void run(int);
  56. private:
  57. bool isEqual(CvRect r1, CvRect r2);
  58. };
  59. CV_LatentSVMDetectorTest::CV_LatentSVMDetectorTest(): CvTest( "latentsvmdetector", "cvLatentSvmDetectObjects" )
  60. {
  61. support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
  62. }
  63. CV_LatentSVMDetectorTest::~CV_LatentSVMDetectorTest() {}
  64. bool CV_LatentSVMDetectorTest::isEqual(CvRect r1, CvRect r2)
  65. {
  66. return ((r1.x == r2.x) && (r1.y == r2.y) && (r1.width == r2.width) && (r1.height == r2.height));
  67. }
  68. void CV_LatentSVMDetectorTest::run( int /* start_from */)
  69. {
  70. string img_path = string(ts->get_data_path()) + "latentsvmdetector/cat.jpg";
  71. string model_path = string(ts->get_data_path()) + "latentsvmdetector/cat.xml";
  72. IplImage* image = cvLoadImage(img_path.c_str());
  73. if (!image)
  74. {
  75. ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
  76. return;
  77. }
  78. CvLatentSvmDetector* detector = cvLoadLatentSvmDetector(model_path.c_str());
  79. if (!detector)
  80. {
  81. ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA );
  82. cvReleaseImage(&image);
  83. return;
  84. }
  85. CvMemStorage* storage = cvCreateMemStorage(0);
  86. CvSeq* detections = 0;
  87. detections = cvLatentSvmDetectObjects(image, detector, storage);
  88. if (detections->total != num_detections)
  89. {
  90. ts->set_failed_test_info( CvTS::FAIL_MISMATCH );
  91. }
  92. else
  93. {
  94. ts->set_failed_test_info(CvTS::OK);
  95. for (int i = 0; i < detections->total; i++)
  96. {
  97. CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, i );
  98. CvRect bounding_box = detection.rect;
  99. float score = detection.score;
  100. if ((!isEqual(bounding_box, true_bounding_boxes[i])) || (fabs(score - true_scores[i]) > score_thr))
  101. {
  102. ts->set_failed_test_info( CvTS::FAIL_MISMATCH );
  103. break;
  104. }
  105. }
  106. }
  107. cvReleaseMemStorage( &storage );
  108. cvReleaseLatentSvmDetector( &detector );
  109. cvReleaseImage( &image );
  110. }
  111. CV_LatentSVMDetectorTest latentsvmdetector_test;