samples_utility.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _SAMPLES_UTILITY_HPP_
  2. #define _SAMPLES_UTILITY_HPP_
  3. #include <opencv2/tracking.hpp>
  4. #include <opencv2/tracking/tracking_legacy.hpp>
  5. inline cv::Ptr<cv::Tracker> createTrackerByName(const std::string& name)
  6. {
  7. using namespace cv;
  8. cv::Ptr<cv::Tracker> tracker;
  9. if (name == "KCF")
  10. tracker = cv::TrackerKCF::create();
  11. else if (name == "TLD")
  12. tracker = legacy::upgradeTrackingAPI(legacy::TrackerTLD::create());
  13. else if (name == "BOOSTING")
  14. tracker = legacy::upgradeTrackingAPI(legacy::TrackerBoosting::create());
  15. else if (name == "MEDIAN_FLOW")
  16. tracker = legacy::upgradeTrackingAPI(legacy::TrackerMedianFlow::create());
  17. else if (name == "MIL")
  18. tracker = cv::TrackerMIL::create();
  19. else if (name == "GOTURN")
  20. tracker = cv::TrackerGOTURN::create();
  21. else if (name == "MOSSE")
  22. tracker = legacy::upgradeTrackingAPI(legacy::TrackerMOSSE::create());
  23. else if (name == "CSRT")
  24. tracker = cv::TrackerCSRT::create();
  25. else
  26. CV_Error(cv::Error::StsBadArg, "Invalid tracking algorithm name\n");
  27. return tracker;
  28. }
  29. inline cv::Ptr<cv::legacy::Tracker> createTrackerByName_legacy(const std::string& name)
  30. {
  31. using namespace cv;
  32. cv::Ptr<cv::legacy::Tracker> tracker;
  33. if (name == "KCF")
  34. tracker = legacy::TrackerKCF::create();
  35. else if (name == "TLD")
  36. tracker = legacy::TrackerTLD::create();
  37. else if (name == "BOOSTING")
  38. tracker = legacy::TrackerBoosting::create();
  39. else if (name == "MEDIAN_FLOW")
  40. tracker = legacy::TrackerMedianFlow::create();
  41. else if (name == "MIL")
  42. tracker = legacy::TrackerMIL::create();
  43. else if (name == "GOTURN")
  44. CV_Error(cv::Error::StsNotImplemented, "FIXIT: migration on new API is required");
  45. else if (name == "MOSSE")
  46. tracker = legacy::TrackerMOSSE::create();
  47. else if (name == "CSRT")
  48. tracker = legacy::TrackerCSRT::create();
  49. else
  50. CV_Error(cv::Error::StsBadArg, "Invalid tracking algorithm name\n");
  51. return tracker;
  52. }
  53. #endif