perf_trackers.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. namespace opencv_test { namespace {
  6. using namespace perf;
  7. typedef tuple<string, int, Rect> TrackingParams_t;
  8. std::vector<TrackingParams_t> getTrackingParams()
  9. {
  10. std::vector<TrackingParams_t> params {
  11. TrackingParams_t("david/data/david.webm", 300, Rect(163,62,47,56)),
  12. TrackingParams_t("dudek/data/dudek.webm", 1, Rect(123,87,132,176)),
  13. TrackingParams_t("faceocc2/data/faceocc2.webm", 1, Rect(118,57,82,98))
  14. };
  15. return params;
  16. }
  17. class Tracking : public perf::TestBaseWithParam<TrackingParams_t>
  18. {
  19. public:
  20. template<typename ROI_t = Rect2d, typename Tracker>
  21. void runTrackingTest(const Ptr<Tracker>& tracker, const TrackingParams_t& params);
  22. };
  23. template<typename ROI_t, typename Tracker>
  24. void Tracking::runTrackingTest(const Ptr<Tracker>& tracker, const TrackingParams_t& params)
  25. {
  26. const int N = 10;
  27. string video = get<0>(params);
  28. int startFrame = get<1>(params);
  29. //int endFrame = startFrame + N;
  30. Rect boundingBox = get<2>(params);
  31. string videoPath = findDataFile(std::string("cv/tracking/") + video);
  32. VideoCapture c;
  33. c.open(videoPath);
  34. if (!c.isOpened())
  35. throw SkipTestException("Can't open video file");
  36. #if 0
  37. // c.set(CAP_PROP_POS_FRAMES, startFrame);
  38. #else
  39. if (startFrame)
  40. std::cout << "startFrame = " << startFrame << std::endl;
  41. for (int i = 0; i < startFrame; i++)
  42. {
  43. Mat dummy_frame;
  44. c >> dummy_frame;
  45. ASSERT_FALSE(dummy_frame.empty()) << i << ": " << videoPath;
  46. }
  47. #endif
  48. // decode frames into memory (don't measure decoding performance)
  49. std::vector<Mat> frames;
  50. for (int i = 0; i < N; ++i)
  51. {
  52. Mat frame;
  53. c >> frame;
  54. ASSERT_FALSE(frame.empty()) << "i=" << i;
  55. frames.push_back(frame);
  56. }
  57. std::cout << "frame size = " << frames[0].size() << std::endl;
  58. PERF_SAMPLE_BEGIN();
  59. {
  60. tracker->init(frames[0], (ROI_t)boundingBox);
  61. for (int i = 1; i < N; ++i)
  62. {
  63. ROI_t rc;
  64. tracker->update(frames[i], rc);
  65. ASSERT_FALSE(rc.empty());
  66. }
  67. }
  68. PERF_SAMPLE_END();
  69. SANITY_CHECK_NOTHING();
  70. }
  71. //==================================================================================================
  72. PERF_TEST_P(Tracking, MIL, testing::ValuesIn(getTrackingParams()))
  73. {
  74. auto tracker = TrackerMIL::create();
  75. runTrackingTest<Rect>(tracker, GetParam());
  76. }
  77. PERF_TEST_P(Tracking, GOTURN, testing::ValuesIn(getTrackingParams()))
  78. {
  79. std::string model = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.prototxt");
  80. std::string weights = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.caffemodel", false);
  81. TrackerGOTURN::Params params;
  82. params.modelTxt = model;
  83. params.modelBin = weights;
  84. auto tracker = TrackerGOTURN::create(params);
  85. runTrackingTest<Rect>(tracker, GetParam());
  86. }
  87. }} // namespace