~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/modules/core/test/ocl/test_image2d.cpp

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

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