Skip to content

Commit d743a4c

Browse files
committed
Merge pull request opencv#9506 from alalek:ocl_fix_canny_ub_9496
2 parents 02d98d3 + e3b12bd commit d743a4c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

modules/imgproc/src/opencl/canny.cl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ __kernel void stage1_with_sobel(__global const uchar *src, int src_step, int src
221221
int value = 1;
222222
if (mag0 > low_thr)
223223
{
224-
int a = (y / (float)x) * TG22;
225-
int b = (y / (float)x) * TG67;
224+
float x_ = abs(x);
225+
float y_ = abs(y);
226226

227-
a = min((int)abs(a), 1) + 1;
228-
b = min((int)abs(b), 1);
227+
int a = (y_ * TG22 >= x_) ? 2 : 1;
228+
int b = (y_ * TG67 >= x_) ? 1 : 0;
229229

230230
// a = { 1, 2 }
231231
// b = { 0, 1 }
@@ -342,11 +342,11 @@ __kernel void stage1_without_sobel(__global const uchar *dxptr, int dx_step, int
342342
int value = 1;
343343
if (mag0 > low_thr)
344344
{
345-
int a = (y / (float)x) * TG22;
346-
int b = (y / (float)x) * TG67;
345+
float x_ = abs(x);
346+
float y_ = abs(y);
347347

348-
a = min((int)abs(a), 1) + 1;
349-
b = min((int)abs(b), 1);
348+
int a = (y_ * TG22 >= x_) ? 2 : 1;
349+
int b = (y_ * TG67 >= x_) ? 1 : 0;
350350

351351
int dir3 = (a * b) & (((x ^ y) & 0x80000000) >> 31);
352352
int dir = a * b + 2 * dir3;

0 commit comments

Comments
 (0)