test_gftt.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
  13. // Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
  14. // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. //
  18. // Redistribution and use in source and binary forms, with or without modification,
  19. // are permitted provided that the following conditions are met:
  20. //
  21. // * Redistribution's of source code must retain the above copyright notice,
  22. // this list of conditions and the following disclaimer.
  23. //
  24. // * Redistribution's in binary form must reproduce the above copyright notice,
  25. // this list of conditions and the following disclaimer in the documentation
  26. // and/or other materials provided with the distribution.
  27. //
  28. // * The name of the copyright holders may not be used to endorse or promote products
  29. // derived from this software without specific prior written permission.
  30. //
  31. // This software is provided by the copyright holders and contributors "as is" and
  32. // any express or implied warranties, including, but not limited to, the implied
  33. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  34. // In no event shall the Intel Corporation or contributors be liable for any direct,
  35. // indirect, incidental, special, exemplary, or consequential damages
  36. // (including, but not limited to, procurement of substitute goods or services;
  37. // loss of use, data, or profits; or business interruption) however caused
  38. // and on any theory of liability, whether in contract, strict liability,
  39. // or tort (including negligence or otherwise) arising in any way out of
  40. // the use of this software, even if advised of the possibility of such damage.
  41. //
  42. //M*/
  43. #include "../test_precomp.hpp"
  44. #include "opencv2/ts/ocl_test.hpp"
  45. #ifdef HAVE_OPENCL
  46. namespace opencv_test {
  47. namespace ocl {
  48. //////////////////////////// GoodFeaturesToTrack //////////////////////////
  49. PARAM_TEST_CASE(GoodFeaturesToTrack, double, bool)
  50. {
  51. double minDistance;
  52. bool useRoi;
  53. static const int maxCorners;
  54. static const double qualityLevel;
  55. TEST_DECLARE_INPUT_PARAMETER(src);
  56. UMat points, upoints;
  57. std::vector<float> quality, uquality;
  58. virtual void SetUp()
  59. {
  60. minDistance = GET_PARAM(0);
  61. useRoi = GET_PARAM(1);
  62. }
  63. void generateTestData()
  64. {
  65. Mat frame = readImage("../gpu/opticalflow/rubberwhale1.png", IMREAD_GRAYSCALE);
  66. ASSERT_FALSE(frame.empty()) << "could not load gpu/opticalflow/rubberwhale1.png";
  67. Size roiSize = frame.size();
  68. Border srcBorder = randomBorder(0, useRoi ? 2 : 0);
  69. randomSubMat(src, src_roi, roiSize, srcBorder, frame.type(), 5, 256);
  70. src_roi.copyTo(frame);
  71. UMAT_UPLOAD_INPUT_PARAMETER(src);
  72. }
  73. void UMatToVector(const UMat & um, std::vector<Point2f> & v) const
  74. {
  75. v.resize(um.size().area());
  76. um.copyTo(Mat(um.size(), CV_32FC2, &v[0]));
  77. }
  78. };
  79. const int GoodFeaturesToTrack::maxCorners = 1000;
  80. const double GoodFeaturesToTrack::qualityLevel = 0.01;
  81. OCL_TEST_P(GoodFeaturesToTrack, Accuracy)
  82. {
  83. for (int j = 0; j < test_loop_times; ++j)
  84. {
  85. generateTestData();
  86. std::vector<Point2f> upts, pts;
  87. OCL_OFF(cv::goodFeaturesToTrack(src_roi, points, maxCorners, qualityLevel, minDistance, noArray(), quality));
  88. ASSERT_FALSE(points.empty());
  89. UMatToVector(points, pts);
  90. OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance, noArray(), uquality));
  91. ASSERT_FALSE(upoints.empty());
  92. UMatToVector(upoints, upts);
  93. ASSERT_EQ(pts.size(), quality.size());
  94. ASSERT_EQ(upts.size(), uquality.size());
  95. ASSERT_EQ(upts.size(), pts.size());
  96. int mistmatch = 0;
  97. for (size_t i = 0; i < pts.size(); ++i)
  98. {
  99. Point2i a = upts[i], b = pts[i];
  100. bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1 &&
  101. std::abs(quality[i] - uquality[i]) <= 3.f * FLT_EPSILON * std::max(quality[i], uquality[i]);
  102. if (!eq)
  103. ++mistmatch;
  104. }
  105. double bad_ratio = static_cast<double>(mistmatch) / pts.size();
  106. ASSERT_GE(1e-2, bad_ratio);
  107. }
  108. }
  109. OCL_TEST_P(GoodFeaturesToTrack, EmptyCorners)
  110. {
  111. generateTestData();
  112. usrc_roi.setTo(Scalar::all(0));
  113. OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance, noArray(), uquality));
  114. ASSERT_TRUE(upoints.empty());
  115. ASSERT_TRUE(uquality.empty());
  116. }
  117. OCL_INSTANTIATE_TEST_CASE_P(Imgproc, GoodFeaturesToTrack,
  118. ::testing::Combine(testing::Values(0.0, 3.0), Bool()));
  119. } } // namespace opencv_test::ocl
  120. #endif