| 161 | |
| 162 | template<typename T> |
| 163 | __global__ void centroid_angle(const float* x_in, const float* y_in, |
| 164 | float* orientation_out, |
| 165 | const unsigned total_feat, CParam<T> image, |
| 166 | const unsigned patch_size) { |
| 167 | unsigned f = blockDim.x * blockIdx.x + threadIdx.x; |
| 168 | |
| 169 | if (f < total_feat) { |
| 170 | unsigned x = (unsigned)round(x_in[f]); |
| 171 | unsigned y = (unsigned)round(y_in[f]); |
| 172 | |
| 173 | unsigned r = patch_size / 2; |
| 174 | if (x < r || y < r || x > image.dims[1] - r || y > image.dims[0] - r) |
| 175 | return; |
| 176 | |
| 177 | T m01 = (T)0, m10 = (T)0; |
| 178 | unsigned patch_size_sq = patch_size * patch_size; |
| 179 | for (unsigned k = threadIdx.y; k < patch_size_sq; k += blockDim.y) { |
| 180 | int i = k / patch_size - r; |
| 181 | int j = k % patch_size - r; |
| 182 | |
| 183 | // Calculate first order moments |
| 184 | T p = image.ptr[(x + i) * image.dims[0] + y + j]; |
| 185 | m01 += j * p; |
| 186 | m10 += i * p; |
| 187 | } |
| 188 | |
| 189 | m01 = block_reduce_sum(m01); |
| 190 | m10 = block_reduce_sum(m10); |
| 191 | |
| 192 | if (threadIdx.y == 0) { |
| 193 | float angle = atan2((float)m01, (float)m10); |
| 194 | orientation_out[f] = angle; |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | template<typename T> |
| 200 | inline __device__ T get_pixel(unsigned x, unsigned y, const float ori, |
nothing calls this directly
no test coverage detected