test_blend.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. // @Authors
  18. // Nathan, liujun@multicorewareinc.com
  19. //
  20. // Redistribution and use in source and binary forms, with or without modification,
  21. // are permitted provided that the following conditions are met:
  22. //
  23. // * Redistribution's of source code must retain the above copyright notice,
  24. // this list of conditions and the following disclaimer.
  25. //
  26. // * Redistribution's in binary form must reproduce the above copyright notice,
  27. // this list of conditions and the following disclaimer in the documentation
  28. // and/or other materials provided with the distribution.
  29. //
  30. // * The name of the copyright holders may not be used to endorse or promote products
  31. // derived from this software without specific prior written permission.
  32. //
  33. // This software is provided by the copyright holders and contributors as is and
  34. // any express or implied warranties, including, but not limited to, the implied
  35. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  36. // In no event shall the Intel Corporation or contributors be liable for any direct,
  37. // indirect, incidental, special, exemplary, or consequential damages
  38. // (including, but not limited to, procurement of substitute goods or services;
  39. // loss of use, data, or profits; or business interruption) however caused
  40. // and on any theory of liability, whether in contract, strict liability,
  41. // or tort (including negligence or otherwise) arising in any way out of
  42. // the use of this software, even if advised of the possibility of such damage.
  43. //
  44. //M*/
  45. #include "../test_precomp.hpp"
  46. #include "opencv2/ts/ocl_test.hpp"
  47. #ifdef HAVE_OPENCL
  48. namespace opencv_test {
  49. namespace ocl {
  50. PARAM_TEST_CASE(BlendLinear, MatDepth, Channels, bool)
  51. {
  52. int depth, channels;
  53. bool useRoi;
  54. TEST_DECLARE_INPUT_PARAMETER(src1);
  55. TEST_DECLARE_INPUT_PARAMETER(src2);
  56. TEST_DECLARE_INPUT_PARAMETER(weights2);
  57. TEST_DECLARE_INPUT_PARAMETER(weights1);
  58. TEST_DECLARE_OUTPUT_PARAMETER(dst);
  59. virtual void SetUp()
  60. {
  61. depth = GET_PARAM(0);
  62. channels = GET_PARAM(1);
  63. useRoi = GET_PARAM(2);
  64. }
  65. void random_roi()
  66. {
  67. const int type = CV_MAKE_TYPE(depth, channels);
  68. const double upValue = 256;
  69. Size roiSize = randomSize(1, MAX_VALUE);
  70. Border src1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
  71. randomSubMat(src1, src1_roi, roiSize, src1Border, type, -upValue, upValue);
  72. Border src2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
  73. randomSubMat(src2, src2_roi, roiSize, src2Border, type, -upValue, upValue);
  74. Border weights1Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
  75. randomSubMat(weights1, weights1_roi, roiSize, weights1Border, CV_32FC1, -upValue, upValue);
  76. Border weights2Border = randomBorder(0, useRoi ? MAX_VALUE : 0);
  77. randomSubMat(weights2, weights2_roi, roiSize, weights2Border, CV_32FC1, 1e-2, upValue);
  78. weights2_roi -= weights1_roi;
  79. CV_Assert(checkNorm2(weights2_roi, weights2(Rect(weights2Border.lef, weights2Border.top,
  80. roiSize.width, roiSize.height))) < 1e-6);
  81. Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
  82. randomSubMat(dst, dst_roi, roiSize, dstBorder, type, 5, 16);
  83. UMAT_UPLOAD_INPUT_PARAMETER(src1);
  84. UMAT_UPLOAD_INPUT_PARAMETER(src2);
  85. UMAT_UPLOAD_INPUT_PARAMETER(weights1);
  86. UMAT_UPLOAD_INPUT_PARAMETER(weights2);
  87. UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
  88. }
  89. void Near(double eps = 0.0)
  90. {
  91. OCL_EXPECT_MATS_NEAR(dst, eps);
  92. }
  93. };
  94. OCL_TEST_P(BlendLinear, Accuracy)
  95. {
  96. for (int i = 0; i < test_loop_times; ++i)
  97. {
  98. random_roi();
  99. OCL_OFF(cv::blendLinear(src1_roi, src2_roi, weights1_roi, weights2_roi, dst_roi));
  100. OCL_ON(cv::blendLinear(usrc1_roi, usrc2_roi, uweights1_roi, uweights2_roi, udst_roi));
  101. Near(depth <= CV_32S ? 1.0 : 0.5);
  102. }
  103. }
  104. OCL_INSTANTIATE_TEST_CASE_P(ImgProc, BlendLinear, Combine(testing::Values(CV_8U, CV_32F), OCL_ALL_CHANNELS, Bool()));
  105. } } // namespace opencv_test::ocl
  106. #endif