test_match_template.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  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. //
  13. // Copyright (C) 2010-2012, Multicoreware, Inc., 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. ///////////////////////////////////////////// matchTemplate //////////////////////////////////////////////////////////
  49. CV_ENUM(MatchTemplType, CV_TM_CCORR, CV_TM_CCORR_NORMED, CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED)
  50. PARAM_TEST_CASE(MatchTemplate, MatDepth, Channels, MatchTemplType, bool)
  51. {
  52. int type;
  53. int depth;
  54. int method;
  55. bool use_roi;
  56. TEST_DECLARE_INPUT_PARAMETER(image);
  57. TEST_DECLARE_INPUT_PARAMETER(templ);
  58. TEST_DECLARE_OUTPUT_PARAMETER(result);
  59. virtual void SetUp()
  60. {
  61. type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
  62. depth = GET_PARAM(0);
  63. method = GET_PARAM(2);
  64. use_roi = GET_PARAM(3);
  65. }
  66. void generateTestData()
  67. {
  68. Size image_roiSize = randomSize(2, 100);
  69. Size templ_roiSize = Size(randomInt(1, image_roiSize.width), randomInt(1, image_roiSize.height));
  70. Size result_roiSize = Size(image_roiSize.width - templ_roiSize.width + 1,
  71. image_roiSize.height - templ_roiSize.height + 1);
  72. const double upValue = 256;
  73. Border imageBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
  74. randomSubMat(image, image_roi, image_roiSize, imageBorder, type, -upValue, upValue);
  75. Border templBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
  76. randomSubMat(templ, templ_roi, templ_roiSize, templBorder, type, -upValue, upValue);
  77. Border resultBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
  78. randomSubMat(result, result_roi, result_roiSize, resultBorder, CV_32FC1, -upValue, upValue);
  79. UMAT_UPLOAD_INPUT_PARAMETER(image);
  80. UMAT_UPLOAD_INPUT_PARAMETER(templ);
  81. UMAT_UPLOAD_OUTPUT_PARAMETER(result);
  82. }
  83. void Near()
  84. {
  85. bool isNormed =
  86. method == TM_CCORR_NORMED ||
  87. method == TM_SQDIFF_NORMED ||
  88. method == TM_CCOEFF_NORMED;
  89. if (isNormed)
  90. OCL_EXPECT_MATS_NEAR(result, 3e-2);
  91. else
  92. OCL_EXPECT_MATS_NEAR_RELATIVE_SPARSE(result, 1.5e-2);
  93. }
  94. };
  95. OCL_TEST_P(MatchTemplate, Mat)
  96. {
  97. for (int j = 0; j < test_loop_times; j++)
  98. {
  99. generateTestData();
  100. OCL_OFF(cv::matchTemplate(image_roi, templ_roi, result_roi, method));
  101. OCL_ON(cv::matchTemplate(uimage_roi, utempl_roi, uresult_roi, method));
  102. Near();
  103. }
  104. }
  105. OCL_INSTANTIATE_TEST_CASE_P(ImageProc, MatchTemplate, Combine(
  106. Values(CV_8U, CV_32F),
  107. Values(1, 2, 3, 4),
  108. MatchTemplType::all(),
  109. Bool())
  110. );
  111. } } // namespace opencv_test::ocl
  112. #endif