test_trackers.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 "test_precomp.hpp"
  5. //#define DEBUG_TEST
  6. #ifdef DEBUG_TEST
  7. #include <opencv2/highgui.hpp>
  8. #endif
  9. namespace opencv_test { namespace {
  10. //using namespace cv::tracking;
  11. #define TESTSET_NAMES testing::Values("david", "dudek", "faceocc2")
  12. const string TRACKING_DIR = "tracking";
  13. const string FOLDER_IMG = "data";
  14. const string FOLDER_OMIT_INIT = "initOmit";
  15. #include "test_trackers.impl.hpp"
  16. //[TESTDATA]
  17. PARAM_TEST_CASE(DistanceAndOverlap, string)
  18. {
  19. string dataset;
  20. virtual void SetUp()
  21. {
  22. dataset = GET_PARAM(0);
  23. }
  24. };
  25. TEST_P(DistanceAndOverlap, MIL)
  26. {
  27. TrackerTest<Tracker, Rect> test(TrackerMIL::create(), dataset, 30, .65f, NoTransform);
  28. test.run();
  29. }
  30. TEST_P(DistanceAndOverlap, Shifted_Data_MIL)
  31. {
  32. TrackerTest<Tracker, Rect> test(TrackerMIL::create(), dataset, 30, .6f, CenterShiftLeft);
  33. test.run();
  34. }
  35. /***************************************************************************************/
  36. //Tests with scaled initial window
  37. TEST_P(DistanceAndOverlap, Scaled_Data_MIL)
  38. {
  39. TrackerTest<Tracker, Rect> test(TrackerMIL::create(), dataset, 30, .7f, Scale_1_1);
  40. test.run();
  41. }
  42. TEST_P(DistanceAndOverlap, GOTURN)
  43. {
  44. std::string model = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.prototxt");
  45. std::string weights = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.caffemodel", false);
  46. cv::TrackerGOTURN::Params params;
  47. params.modelTxt = model;
  48. params.modelBin = weights;
  49. TrackerTest<Tracker, Rect> test(TrackerGOTURN::create(params), dataset, 35, .35f, NoTransform);
  50. test.run();
  51. }
  52. INSTANTIATE_TEST_CASE_P(Tracking, DistanceAndOverlap, TESTSET_NAMES);
  53. TEST(GOTURN, memory_usage)
  54. {
  55. cv::Rect roi(145, 70, 85, 85);
  56. std::string model = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.prototxt");
  57. std::string weights = cvtest::findDataFile("dnn/gsoc2016-goturn/goturn.caffemodel", false);
  58. cv::TrackerGOTURN::Params params;
  59. params.modelTxt = model;
  60. params.modelBin = weights;
  61. cv::Ptr<Tracker> tracker = TrackerGOTURN::create(params);
  62. string inputVideo = cvtest::findDataFile("tracking/david/data/david.webm");
  63. cv::VideoCapture video(inputVideo);
  64. ASSERT_TRUE(video.isOpened()) << inputVideo;
  65. cv::Mat frame;
  66. video >> frame;
  67. ASSERT_FALSE(frame.empty()) << inputVideo;
  68. tracker->init(frame, roi);
  69. string ground_truth_bb;
  70. for (int nframes = 0; nframes < 15; ++nframes)
  71. {
  72. std::cout << "Frame: " << nframes << std::endl;
  73. video >> frame;
  74. bool res = tracker->update(frame, roi);
  75. ASSERT_TRUE(res);
  76. std::cout << "Predicted ROI: " << roi << std::endl;
  77. }
  78. }
  79. TEST(DaSiamRPN, memory_usage)
  80. {
  81. cv::Rect roi(145, 70, 85, 85);
  82. std::string model = cvtest::findDataFile("dnn/onnx/models/dasiamrpn_model.onnx", false);
  83. std::string kernel_r1 = cvtest::findDataFile("dnn/onnx/models/dasiamrpn_kernel_r1.onnx", false);
  84. std::string kernel_cls1 = cvtest::findDataFile("dnn/onnx/models/dasiamrpn_kernel_cls1.onnx", false);
  85. cv::TrackerDaSiamRPN::Params params;
  86. params.model = model;
  87. params.kernel_r1 = kernel_r1;
  88. params.kernel_cls1 = kernel_cls1;
  89. cv::Ptr<Tracker> tracker = TrackerDaSiamRPN::create(params);
  90. string inputVideo = cvtest::findDataFile("tracking/david/data/david.webm");
  91. cv::VideoCapture video(inputVideo);
  92. ASSERT_TRUE(video.isOpened()) << inputVideo;
  93. cv::Mat frame;
  94. video >> frame;
  95. ASSERT_FALSE(frame.empty()) << inputVideo;
  96. tracker->init(frame, roi);
  97. string ground_truth_bb;
  98. for (int nframes = 0; nframes < 15; ++nframes)
  99. {
  100. std::cout << "Frame: " << nframes << std::endl;
  101. video >> frame;
  102. bool res = tracker->update(frame, roi);
  103. ASSERT_TRUE(res);
  104. std::cout << "Predicted ROI: " << roi << std::endl;
  105. }
  106. }
  107. }} // namespace opencv_test::