test_trackerParametersIO.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include <opencv2/tracking/tracking_legacy.hpp>
  6. //using namespace cv::tracking::legacy;
  7. namespace opencv_test { namespace {
  8. TEST(MEDIAN_FLOW_Parameters, IO)
  9. {
  10. legacy::TrackerMedianFlow::Params parameters;
  11. parameters.maxLevel = 10;
  12. parameters.maxMedianLengthOfDisplacementDifference = 11;
  13. parameters.pointsInGrid = 12;
  14. parameters.winSize = Size(6, 5);
  15. parameters.winSizeNCC = Size(41, 40);
  16. parameters.termCriteria.maxCount = 100;
  17. parameters.termCriteria.epsilon = 0.1;
  18. FileStorage fsWriter("parameters.xml", FileStorage::WRITE + FileStorage::MEMORY);
  19. parameters.write(fsWriter);
  20. String serializedParameters = fsWriter.releaseAndGetString();
  21. FileStorage fsReader(serializedParameters, FileStorage::READ + FileStorage::MEMORY);
  22. legacy::TrackerMedianFlow::Params readParameters;
  23. readParameters.read(fsReader.root());
  24. ASSERT_EQ(parameters.maxLevel, readParameters.maxLevel);
  25. ASSERT_EQ(parameters.maxMedianLengthOfDisplacementDifference,
  26. readParameters.maxMedianLengthOfDisplacementDifference);
  27. ASSERT_EQ(parameters.pointsInGrid, readParameters.pointsInGrid);
  28. ASSERT_EQ(parameters.winSize, readParameters.winSize);
  29. ASSERT_EQ(parameters.winSizeNCC, readParameters.winSizeNCC);
  30. ASSERT_EQ(parameters.termCriteria.epsilon, readParameters.termCriteria.epsilon);
  31. ASSERT_EQ(parameters.termCriteria.maxCount, readParameters.termCriteria.maxCount);
  32. }
  33. TEST(MEDIAN_FLOW_Parameters, Default_Value_If_Absent)
  34. {
  35. legacy::TrackerMedianFlow::Params defaultParameters;
  36. FileStorage fsReader(String("%YAML 1.0"), FileStorage::READ + FileStorage::MEMORY);
  37. legacy::TrackerMedianFlow::Params readParameters;
  38. readParameters.read(fsReader.root());
  39. ASSERT_EQ(defaultParameters.maxLevel, readParameters.maxLevel);
  40. ASSERT_EQ(defaultParameters.maxMedianLengthOfDisplacementDifference,
  41. readParameters.maxMedianLengthOfDisplacementDifference);
  42. ASSERT_EQ(defaultParameters.pointsInGrid, readParameters.pointsInGrid);
  43. ASSERT_EQ(defaultParameters.winSize, readParameters.winSize);
  44. ASSERT_EQ(defaultParameters.winSizeNCC, readParameters.winSizeNCC);
  45. ASSERT_EQ(defaultParameters.termCriteria.epsilon, readParameters.termCriteria.epsilon);
  46. ASSERT_EQ(defaultParameters.termCriteria.maxCount, readParameters.termCriteria.maxCount);
  47. }
  48. TEST(KCF_Parameters, IO)
  49. {
  50. legacy::TrackerKCF::Params parameters;
  51. parameters.sigma = 0.3f;
  52. parameters.lambda = 0.02f;
  53. parameters.interp_factor = 0.08f;
  54. parameters.output_sigma_factor = 1.0f/ 32.0f;
  55. parameters.resize=false;
  56. parameters.max_patch_size=90*90;
  57. parameters.split_coeff=false;
  58. parameters.wrap_kernel=true;
  59. parameters.desc_npca = TrackerKCF::CN;
  60. parameters.desc_pca = TrackerKCF::GRAY;
  61. parameters.compress_feature=false;
  62. parameters.compressed_size=3;
  63. parameters.pca_learning_rate=0.2f;
  64. FileStorage fsWriter("parameters.xml", FileStorage::WRITE + FileStorage::MEMORY);
  65. parameters.write(fsWriter);
  66. String serializedParameters = fsWriter.releaseAndGetString();
  67. FileStorage fsReader(serializedParameters, FileStorage::READ + FileStorage::MEMORY);
  68. legacy::TrackerKCF::Params readParameters;
  69. readParameters.read(fsReader.root());
  70. ASSERT_DOUBLE_EQ(parameters.sigma, readParameters.sigma);
  71. ASSERT_DOUBLE_EQ(parameters.lambda, readParameters.lambda);
  72. ASSERT_DOUBLE_EQ(parameters.interp_factor, readParameters.interp_factor);
  73. ASSERT_DOUBLE_EQ(parameters.output_sigma_factor, readParameters.output_sigma_factor);
  74. ASSERT_EQ(parameters.resize, readParameters.resize);
  75. ASSERT_EQ(parameters.max_patch_size, readParameters.max_patch_size);
  76. ASSERT_EQ(parameters.split_coeff, readParameters.split_coeff);
  77. ASSERT_EQ(parameters.wrap_kernel, readParameters.wrap_kernel);
  78. ASSERT_EQ(parameters.desc_npca, readParameters.desc_npca);
  79. ASSERT_EQ(parameters.desc_pca, readParameters.desc_pca);
  80. ASSERT_EQ(parameters.compress_feature, readParameters.compress_feature);
  81. ASSERT_EQ(parameters.compressed_size, readParameters.compressed_size);
  82. ASSERT_DOUBLE_EQ(parameters.pca_learning_rate, readParameters.pca_learning_rate);
  83. }
  84. TEST(KCF_Parameters, Default_Value_If_Absent)
  85. {
  86. legacy::TrackerKCF::Params defaultParameters;
  87. FileStorage fsReader(String("%YAML 1.0"), FileStorage::READ + FileStorage::MEMORY);
  88. legacy::TrackerKCF::Params readParameters;
  89. readParameters.read(fsReader.root());
  90. ASSERT_DOUBLE_EQ(defaultParameters.sigma, readParameters.sigma);
  91. ASSERT_DOUBLE_EQ(defaultParameters.lambda, readParameters.lambda);
  92. ASSERT_DOUBLE_EQ(defaultParameters.interp_factor, readParameters.interp_factor);
  93. ASSERT_DOUBLE_EQ(defaultParameters.output_sigma_factor, readParameters.output_sigma_factor);
  94. ASSERT_EQ(defaultParameters.resize, readParameters.resize);
  95. ASSERT_EQ(defaultParameters.max_patch_size, readParameters.max_patch_size);
  96. ASSERT_EQ(defaultParameters.split_coeff, readParameters.split_coeff);
  97. ASSERT_EQ(defaultParameters.wrap_kernel, readParameters.wrap_kernel);
  98. ASSERT_EQ(defaultParameters.desc_npca, readParameters.desc_npca);
  99. ASSERT_EQ(defaultParameters.desc_pca, readParameters.desc_pca);
  100. ASSERT_EQ(defaultParameters.compress_feature, readParameters.compress_feature);
  101. ASSERT_EQ(defaultParameters.compressed_size, readParameters.compressed_size);
  102. ASSERT_DOUBLE_EQ(defaultParameters.pca_learning_rate, readParameters.pca_learning_rate);
  103. }
  104. }} // namespace