perf_trackers.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "perf_precomp.hpp"
  5. #include <opencv2/tracking/tracking_legacy.hpp>
  6. namespace opencv_test { namespace {
  7. using namespace perf;
  8. //using namespace cv::tracking;
  9. typedef tuple<string, int, Rect> TrackingParams_t;
  10. std::vector<TrackingParams_t> getTrackingParams()
  11. {
  12. std::vector<TrackingParams_t> params {
  13. TrackingParams_t("david/data/david.webm", 300, Rect(163,62,47,56)),
  14. TrackingParams_t("dudek/data/dudek.webm", 1, Rect(123,87,132,176)),
  15. TrackingParams_t("faceocc2/data/faceocc2.webm", 1, Rect(118,57,82,98))
  16. };
  17. return params;
  18. }
  19. class Tracking : public perf::TestBaseWithParam<TrackingParams_t>
  20. {
  21. public:
  22. template<typename ROI_t = Rect2d, typename Tracker>
  23. void runTrackingTest(const Ptr<Tracker>& tracker, const TrackingParams_t& params);
  24. };
  25. template<typename ROI_t, typename Tracker>
  26. void Tracking::runTrackingTest(const Ptr<Tracker>& tracker, const TrackingParams_t& params)
  27. {
  28. const int N = 10;
  29. string video = get<0>(params);
  30. int startFrame = get<1>(params);
  31. //int endFrame = startFrame + N;
  32. Rect boundingBox = get<2>(params);
  33. string videoPath = findDataFile(std::string("cv/tracking/") + video);
  34. VideoCapture c;
  35. c.open(videoPath);
  36. ASSERT_TRUE(c.isOpened()) << videoPath;
  37. #if 0
  38. // c.set(CAP_PROP_POS_FRAMES, startFrame);
  39. #else
  40. if (startFrame)
  41. std::cout << "startFrame = " << startFrame << std::endl;
  42. for (int i = 0; i < startFrame; i++)
  43. {
  44. Mat dummy_frame;
  45. c >> dummy_frame;
  46. ASSERT_FALSE(dummy_frame.empty()) << i << ": " << videoPath;
  47. }
  48. #endif
  49. // decode frames into memory (don't measure decoding performance)
  50. std::vector<Mat> frames;
  51. for (int i = 0; i < N; ++i)
  52. {
  53. Mat frame;
  54. c >> frame;
  55. ASSERT_FALSE(frame.empty()) << "i=" << i;
  56. frames.push_back(frame);
  57. }
  58. std::cout << "frame size = " << frames[0].size() << std::endl;
  59. PERF_SAMPLE_BEGIN();
  60. {
  61. tracker->init(frames[0], (ROI_t)boundingBox);
  62. for (int i = 1; i < N; ++i)
  63. {
  64. ROI_t rc;
  65. tracker->update(frames[i], rc);
  66. ASSERT_FALSE(rc.empty());
  67. }
  68. }
  69. PERF_SAMPLE_END();
  70. SANITY_CHECK_NOTHING();
  71. }
  72. //==================================================================================================
  73. PERF_TEST_P(Tracking, Boosting, testing::ValuesIn(getTrackingParams()))
  74. {
  75. auto tracker = legacy::TrackerBoosting::create();
  76. runTrackingTest(tracker, GetParam());
  77. }
  78. PERF_TEST_P(Tracking, TLD, testing::ValuesIn(getTrackingParams()))
  79. {
  80. auto tracker = legacy::TrackerTLD::create();
  81. runTrackingTest(tracker, GetParam());
  82. }
  83. }} // namespace