test_image2d.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // Copyright (C) 2014, Itseez, Inc., all rights reserved.
  5. // Third party copyrights are property of their respective owners.
  6. #include "../test_precomp.hpp"
  7. #include "opencv2/ts/ocl_test.hpp"
  8. #ifdef HAVE_OPENCL
  9. namespace opencv_test {
  10. namespace ocl {
  11. TEST(Image2D, createAliasEmptyUMat)
  12. {
  13. if (cv::ocl::haveOpenCL())
  14. {
  15. UMat um;
  16. EXPECT_FALSE(cv::ocl::Image2D::canCreateAlias(um));
  17. }
  18. else
  19. std::cout << "OpenCL runtime not found. Test skipped." << std::endl;
  20. }
  21. TEST(Image2D, createImage2DWithEmptyUMat)
  22. {
  23. if (cv::ocl::haveOpenCL())
  24. {
  25. UMat um;
  26. EXPECT_ANY_THROW(cv::ocl::Image2D image(um));
  27. }
  28. else
  29. std::cout << "OpenCL runtime not found. Test skipped." << std::endl;
  30. }
  31. TEST(Image2D, createAlias)
  32. {
  33. if (cv::ocl::haveOpenCL())
  34. {
  35. const cv::ocl::Device & d = cv::ocl::Device::getDefault();
  36. int minor = d.deviceVersionMinor(), major = d.deviceVersionMajor();
  37. // aliases is OpenCL 1.2 extension
  38. if (1 < major || (1 == major && 2 <= minor))
  39. {
  40. UMat um(128, 128, CV_8UC1);
  41. bool isFormatSupported = false, canCreateAlias = false;
  42. EXPECT_NO_THROW(isFormatSupported = cv::ocl::Image2D::isFormatSupported(CV_8U, 1, false));
  43. EXPECT_NO_THROW(canCreateAlias = cv::ocl::Image2D::canCreateAlias(um));
  44. if (isFormatSupported && canCreateAlias)
  45. {
  46. EXPECT_NO_THROW(cv::ocl::Image2D image(um, false, true));
  47. }
  48. else
  49. std::cout << "Impossible to create alias for selected image. Test skipped." << std::endl;
  50. }
  51. }
  52. else
  53. std::cout << "OpenCL runtime not found. Test skipped" << std::endl;
  54. }
  55. TEST(Image2D, turnOffOpenCL)
  56. {
  57. if (cv::ocl::haveOpenCL())
  58. {
  59. // save the current state
  60. bool useOCL = cv::ocl::useOpenCL();
  61. bool isFormatSupported = false;
  62. cv::ocl::setUseOpenCL(true);
  63. UMat um(128, 128, CV_8UC1);
  64. cv::ocl::setUseOpenCL(false);
  65. EXPECT_NO_THROW(isFormatSupported = cv::ocl::Image2D::isFormatSupported(CV_8U, 1, true));
  66. if (isFormatSupported)
  67. {
  68. EXPECT_NO_THROW(cv::ocl::Image2D image(um));
  69. }
  70. else
  71. std::cout << "CV_8UC1 is not supported for OpenCL images. Test skipped." << std::endl;
  72. // reset state to the previous one
  73. cv::ocl::setUseOpenCL(useOCL);
  74. }
  75. else
  76. std::cout << "OpenCL runtime not found. Test skipped." << std::endl;
  77. }
  78. } } // namespace opencv_test::ocl
  79. #endif // HAVE_OPENCL