This commit is contained in:
gfuse
2021-06-18 14:57:59 +02:00
commit 6e6d191bda
19 changed files with 1797 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
__kernel void double_add(__global const double* A, __global const double* B, __global double* C) {
int index = get_global_id(0);
C[index] = A[index] + B[index];
};
+72
View File
@@ -0,0 +1,72 @@
// Copyright (C) 2011 Dmitri Nikulin
// Copyright (C) 2011 Monash University
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
kernel void fast_best(
read_only image2d_t scores,
global int2 * corners,
global int2 * filtered,
global int * icorner
) {
// Prepare a suitable OpenCL image sampler.
sampler_t const sampler = CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;
// Use global work item as 1D offset into corners.
int const ic = get_global_id(0);
int2 const xy = corners[ic];
// Read the candidate score.
int const p00 = read_imageui(scores, sampler, xy).x;
// Read other scores in a tight square around the candidate score.
int const p01 = read_imageui(scores, sampler, xy + (int2)(-1, -1)).x;
int const p02 = read_imageui(scores, sampler, xy + (int2)( 0, -1)).x;
int const p03 = read_imageui(scores, sampler, xy + (int2)( 1, -1)).x;
int const p04 = read_imageui(scores, sampler, xy + (int2)(-1, 0)).x;
int const p05 = read_imageui(scores, sampler, xy + (int2)( 0, 0)).x;
int const p06 = read_imageui(scores, sampler, xy + (int2)( 1, 0)).x;
int const p07 = read_imageui(scores, sampler, xy + (int2)(-1, 1)).x;
int const p08 = read_imageui(scores, sampler, xy + (int2)( 0, 1)).x;
int const p09 = read_imageui(scores, sampler, xy + (int2)( 1, 1)).x;
// Select the maximum score.
int sco = p00;
sco = max(sco, p01);
sco = max(sco, p02);
sco = max(sco, p03);
sco = max(sco, p04);
sco = max(sco, p05);
sco = max(sco, p06);
sco = max(sco, p07);
sco = max(sco, p08);
sco = max(sco, p09);
// Keep this score if it is as good as the maximum.
if (p00 >= sco) {
// Atomically append to filtered corner buffer.
filtered[atom_inc(icorner)] = xy;
}
}
+80
View File
@@ -0,0 +1,80 @@
// Copyright (C) 2021 Majid Geravand
// Copyright (C) 2021 Gfuse
__kernel void fast_gray(
__read_only image2d_t image,
__global int2 * corners,
__global int * icorner,
int fast_count
) {
// Prepare a suitable OpenCL image sampler.
sampler_t const sampler = CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;
// Use global work item as 2D image coordinates.
int const x = get_global_id(0);
int const y = get_global_id(1);
if(x>16 && x<get_image_width(image)-16 && y<get_image_height(image)-16 && y>16){
int2 const xy = (int2)(x, y);
// Read the candidate pixel.
int const p00 = read_imageui(image, sampler, xy).x;
// Read other pixels in a circle around the candidate pixel.
int const p01 = read_imageui(image, sampler, xy + (int2)( 0, 3)).x;
int const p05 = read_imageui(image, sampler, xy + (int2)( 3, 0)).x;
int const p09 = read_imageui(image, sampler, xy + (int2)( 0, -3)).x;
int const p13 = read_imageui(image, sampler, xy + (int2)(-3, 0)).x;
// Check the absolute difference of each circle pixel.
int const d01 = (abs(p01 - p00) > FAST_THRESH);
int const d05 = (abs(p05 - p00) > FAST_THRESH);
int const d09 = (abs(p09 - p00) > FAST_THRESH);
int const d13 = (abs(p13 - p00) > FAST_THRESH);
// Check if any two adjacent circle pixels have a high absolute difference.
if ((d01 && d05) ||(d05 && d09) ||(d09 && d13) ||(d13 && d01)) {
// Read other pixels in a circle around the candidate pixel.
int const p02 = read_imageui(image, sampler, xy + (int2)( 1, 3)).x;
int const p03 = read_imageui(image, sampler, xy + (int2)( 2, 2)).x;
int const p04 = read_imageui(image, sampler, xy + (int2)( 3, 1)).x;
int const p06 = read_imageui(image, sampler, xy + (int2)( 3, -1)).x;
int const p07 = read_imageui(image, sampler, xy + (int2)( 2, -2)).x;
int const p08 = read_imageui(image, sampler, xy + (int2)( 1, -3)).x;
int const p10 = read_imageui(image, sampler, xy + (int2)(-1, -3)).x;
int const p11 = read_imageui(image, sampler, xy + (int2)(-2, -2)).x;
int const p12 = read_imageui(image, sampler, xy + (int2)(-3, -1)).x;
int const p14 = read_imageui(image, sampler, xy + (int2)(-3, 1)).x;
int const p15 = read_imageui(image, sampler, xy + (int2)(-2, 2)).x;
int const p16 = read_imageui(image, sampler, xy + (int2)(-1, 3)).x;
// Select the maximum score.
int sco = p00;
sco = max(sco, p01);
sco = max(sco, p02);
sco = max(sco, p03);
sco = max(sco, p04);
sco = max(sco, p05);
sco = max(sco, p06);
sco = max(sco, p07);
sco = max(sco, p08);
sco = max(sco, p09);
sco = max(sco, p10);
sco = max(sco, p11);
sco = max(sco, p12);
sco = max(sco, p13);
sco = max(sco, p14);
sco = max(sco, p15);
// Keep this score if it is as good as the maximum.
if (p00 >= sco) {
// Atomically append to corner buffer.
int const icorn = atom_inc(icorner);
if (icorn < fast_count)
corners[icorn] = xy;
}
}
}
}
+4
View File
@@ -0,0 +1,4 @@
__kernel void int_add(__global const int* A, __global const int* B, __global int* C) {
int index = get_global_id(0);
C[index] = A[index] + B[index];
};
+372
View File
@@ -0,0 +1,372 @@
__kernel void is_corner_10_greater(__global const unsigned char* img,__global const int* x,__global const int* y, int2 image_stride, int wight, short barrier,__global unsigned char* condition) {
/*
int x_id=x[get_global_id(0)];
int y_id=y[get_global_id(1)];
printf("%d, %d \n",x_id,y_id);
int px=y_id*image_stride+x_id;
int w3 = 3*image_stride;//3*image_stride
/*
int t = (img[px] << 8) | img[px+1] - barrier;
if (!img[px-1-w3]>t) {
if (!img[px+3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
if (!img[px-w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1-w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3+image_stride]>t) {
if (!img[px+3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1-w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+3]>t) {
if (!img[px-3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2-2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+3-image_stride]>t) {
if (!img[px-3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3]>t) {
if (!img[px+2-2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-2-2*image_stride]>t) {
if (!img[px+3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]>t) {
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+2-2*image_stride]>t) {
if (!img[px-3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+1-w3]>t) {
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-w3]>t) {
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3-image_stride]>t) {
if (!img[px+1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]>t) {
if (!img[px+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+1-w3]>t) {
if (!img[px-3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-w3]>t) {
if (!img[px+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-w3]>t) {
if (!img[px+2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]>t) {
if (!img[px+1-w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3]>t) {
if (!img[px+3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3]>t) {
if (!img[px+2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1-w3]>t) {
if (!img[px+1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+1-w3]>t) {
if (!img[px+1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+2-2*image_stride]>t) {
if (!img[px-3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3+image_stride]>t) {
if (!img[px+3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-2+2*image_stride]>t) {
if (!img[px+3-image_stride]>t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+3-image_stride]>t) {
if (!img[px-1+w3]>t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
*/
};
+376
View File
@@ -0,0 +1,376 @@
__kernel void is_corner_10_less(__global const uchar* img,__global const int* x,__global const int* y,int image_stride, int wight,int barrier,
__global uchar* condition) {
int x_id=x[get_global_id(0)];
int y_id=y[get_global_id(1)];
int px=y_id*image_stride+x_id;
int w3 = 3*image_stride;//3*image_stride
int t = (img[px] << 8) | img[px+1] - barrier;
if(get_global_id(0)>100){
condition[get_global_id(1)*752+get_global_id(0)]=255;
}else{
if(condition[get_global_id(1)*752+get_global_id(0)]!=100)
condition[get_global_id(1)*752+get_global_id(0)]=0;
}
/*
if (!img[px-1-w3]<t) {
if (!img[px+3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
if (!img[px-w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1-w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3+image_stride]<t) {
if (!img[px+3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1-w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+3]<t) {
if (!img[px-3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2-2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+3-image_stride]<t) {
if (!img[px-3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3]<t) {
if (!img[px+2-2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-2-2*image_stride]<t) {
if (!img[px+3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]<t) {
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+2-2*image_stride]<t) {
if (!img[px-3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+1-w3]<t) {
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-w3]<t) {
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3-image_stride]<t) {
if (!img[px+1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]<t) {
if (!img[px+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+1-w3]<t) {
if (!img[px-3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-w3]<t) {
if (!img[px+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-w3]<t) {
if (!img[px+2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]<t) {
if (!img[px+1-w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3]<t) {
if (!img[px+3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3]<t) {
if (!img[px+2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+2-2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+1-w3]<t) {
if (!img[px+1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+1-w3]<t) {
if (!img[px+1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+2-2*image_stride]<t) {
if (!img[px-3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px-2+2*image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-3+image_stride]<t) {
if (!img[px+3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3+image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px-2+2*image_stride]<t) {
if (!img[px+3-image_stride]<t) {
condition[y_id*wight+x_id]=0;
}
if (!img[px+3]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
if (!img[px+3-image_stride]<t) {
if (!img[px-1+w3]<t) {
condition[y_id*wight+x_id]=0;
}
condition[y_id*wight+x_id]=255;
}
*/
};
+103
View File
@@ -0,0 +1,103 @@
// Copyright (C) 2011 Dmitri Nikulin
// Copyright (C) 2011 Monash University
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// Enable OpenCL 32-bit integer atomic functions.
__kernel void prefast_gray(
__read_only image2d_t image,
__global int2 * corners,
__global int * icorner,
int fast_count
) {
// Prepare a suitable OpenCL image sampler.
sampler_t const sampler = CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;
// Use global work item as 2D image coordinates.
int const x = get_global_id(0);
int const y = get_global_id(1);
if(x>16 && x<get_image_width(image)-16 && y<get_image_height(image)-16 && y>16){
int2 const xy = (int2)(x, y);
// Read the candidate pixel.
int const p00 = read_imageui(image, sampler, xy).x;
// Read other pixels in a circle around the candidate pixel.
int const p01 = read_imageui(image, sampler, xy + (int2)( 0, 3)).x;
int const p05 = read_imageui(image, sampler, xy + (int2)( 3, 0)).x;
int const p09 = read_imageui(image, sampler, xy + (int2)( 0, -3)).x;
int const p13 = read_imageui(image, sampler, xy + (int2)(-3, 0)).x;
// Check the absolute difference of each circle pixel.
int const d01 = (abs(p01 - p00) > FAST_THRESH);
int const d05 = (abs(p05 - p00) > FAST_THRESH);
int const d09 = (abs(p09 - p00) > FAST_THRESH);
int const d13 = (abs(p13 - p00) > FAST_THRESH);
// Check if any two adjacent circle pixels have a high absolute difference.
if ((d01 && d05) ||(d05 && d09) ||(d09 && d13) ||(d13 && d01)) {
// Read other pixels in a circle around the candidate pixel.
int const p02 = read_imageui(image, sampler, xy + (int2)( 1, 3)).x;
int const p03 = read_imageui(image, sampler, xy + (int2)( 2, 2)).x;
int const p04 = read_imageui(image, sampler, xy + (int2)( 3, 1)).x;
int const p06 = read_imageui(image, sampler, xy + (int2)( 3, -1)).x;
int const p07 = read_imageui(image, sampler, xy + (int2)( 2, -2)).x;
int const p08 = read_imageui(image, sampler, xy + (int2)( 1, -3)).x;
int const p10 = read_imageui(image, sampler, xy + (int2)(-1, -3)).x;
int const p11 = read_imageui(image, sampler, xy + (int2)(-2, -2)).x;
int const p12 = read_imageui(image, sampler, xy + (int2)(-3, -1)).x;
int const p14 = read_imageui(image, sampler, xy + (int2)(-3, 1)).x;
int const p15 = read_imageui(image, sampler, xy + (int2)(-2, 2)).x;
int const p16 = read_imageui(image, sampler, xy + (int2)(-1, 3)).x;
// Select the maximum score.
int sco = p00;
sco = max(sco, p01);
sco = max(sco, p02);
sco = max(sco, p03);
sco = max(sco, p04);
sco = max(sco, p05);
sco = max(sco, p06);
sco = max(sco, p07);
sco = max(sco, p08);
sco = max(sco, p09);
sco = max(sco, p10);
sco = max(sco, p11);
sco = max(sco, p12);
sco = max(sco, p13);
sco = max(sco, p14);
sco = max(sco, p15);
// Keep this score if it is as good as the maximum.
if (p00 >= sco) {
// Atomically append to corner buffer.
int const icorn = atom_inc(icorner);
if (icorn < fast_count)
corners[icorn] = xy;
}
}
}
}