Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/features2d/src/opencl/akaze.cl
16339 views
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
6
/**
7
* @brief This function computes the Perona and Malik conductivity coefficient g2
8
* g2 = 1 / (1 + dL^2 / k^2)
9
* @param lx First order image derivative in X-direction (horizontal)
10
* @param ly First order image derivative in Y-direction (vertical)
11
* @param dst Output image
12
* @param k Contrast factor parameter
13
*/
14
__kernel void
15
AKAZE_pm_g2(__global const float* lx, __global const float* ly, __global float* dst,
16
float k, int size)
17
{
18
int i = get_global_id(0);
19
// OpenCV plays with dimensions so we need explicit check for this
20
if (!(i < size))
21
{
22
return;
23
}
24
25
const float k2inv = 1.0f / (k * k);
26
dst[i] = 1.0f / (1.0f + ((lx[i] * lx[i] + ly[i] * ly[i]) * k2inv));
27
}
28
29
__kernel void
30
AKAZE_nld_step_scalar(__global const float* lt, int lt_step, int lt_offset, int rows, int cols,
31
__global const float* lf, __global float* dst, float step_size)
32
{
33
/* The labeling scheme for this five star stencil:
34
[ a ]
35
[ -1 c +1 ]
36
[ b ]
37
*/
38
// column-first indexing
39
int i = get_global_id(1);
40
int j = get_global_id(0);
41
42
// OpenCV plays with dimensions so we need explicit check for this
43
if (!(i < rows && j < cols))
44
{
45
return;
46
}
47
48
// get row indexes
49
int a = (i - 1) * cols;
50
int c = (i ) * cols;
51
int b = (i + 1) * cols;
52
// compute stencil
53
float res = 0.0f;
54
if (i == 0) // first rows
55
{
56
if (j == 0 || j == (cols - 1))
57
{
58
res = 0.0f;
59
} else
60
{
61
res = (lf[c + j] + lf[c + j + 1])*(lt[c + j + 1] - lt[c + j]) +
62
(lf[c + j] + lf[c + j - 1])*(lt[c + j - 1] - lt[c + j]) +
63
(lf[c + j] + lf[b + j ])*(lt[b + j ] - lt[c + j]);
64
}
65
} else if (i == (rows - 1)) // last row
66
{
67
if (j == 0 || j == (cols - 1))
68
{
69
res = 0.0f;
70
} else
71
{
72
res = (lf[c + j] + lf[c + j + 1])*(lt[c + j + 1] - lt[c + j]) +
73
(lf[c + j] + lf[c + j - 1])*(lt[c + j - 1] - lt[c + j]) +
74
(lf[c + j] + lf[a + j ])*(lt[a + j ] - lt[c + j]);
75
}
76
} else // inner rows
77
{
78
if (j == 0) // first column
79
{
80
res = (lf[c + 0] + lf[c + 1])*(lt[c + 1] - lt[c + 0]) +
81
(lf[c + 0] + lf[b + 0])*(lt[b + 0] - lt[c + 0]) +
82
(lf[c + 0] + lf[a + 0])*(lt[a + 0] - lt[c + 0]);
83
} else if (j == (cols - 1)) // last column
84
{
85
res = (lf[c + j] + lf[c + j - 1])*(lt[c + j - 1] - lt[c + j]) +
86
(lf[c + j] + lf[b + j ])*(lt[b + j ] - lt[c + j]) +
87
(lf[c + j] + lf[a + j ])*(lt[a + j ] - lt[c + j]);
88
} else // inner stencil
89
{
90
res = (lf[c + j] + lf[c + j + 1])*(lt[c + j + 1] - lt[c + j]) +
91
(lf[c + j] + lf[c + j - 1])*(lt[c + j - 1] - lt[c + j]) +
92
(lf[c + j] + lf[b + j ])*(lt[b + j ] - lt[c + j]) +
93
(lf[c + j] + lf[a + j ])*(lt[a + j ] - lt[c + j]);
94
}
95
}
96
97
dst[c + j] = res * step_size;
98
}
99
100
/**
101
* @brief Compute determinant from hessians
102
* @details Compute Ldet by (Lxx.mul(Lyy) - Lxy.mul(Lxy)) * sigma
103
*
104
* @param lxx spatial derivates
105
* @param lxy spatial derivates
106
* @param lyy spatial derivates
107
* @param dst output determinant
108
* @param sigma determinant will be scaled by this sigma
109
*/
110
__kernel void
111
AKAZE_compute_determinant(__global const float* lxx, __global const float* lxy, __global const float* lyy,
112
__global float* dst, float sigma, int size)
113
{
114
int i = get_global_id(0);
115
// OpenCV plays with dimensions so we need explicit check for this
116
if (!(i < size))
117
{
118
return;
119
}
120
121
dst[i] = (lxx[i] * lyy[i] - lxy[i] * lxy[i]) * sigma;
122
}
123
124