| 152 | } |
| 153 | |
| 154 | __device__ bool computeMeanScale( |
| 155 | float* x_src_mean, float* y_src_mean, float* x_dst_mean, float* y_dst_mean, |
| 156 | float* src_scale, float* dst_scale, float* src_pt_x, float* src_pt_y, |
| 157 | float* dst_pt_x, float* dst_pt_y, CParam<float> x_src, CParam<float> y_src, |
| 158 | CParam<float> x_dst, CParam<float> y_dst, CParam<float> rnd, int i) { |
| 159 | const unsigned ridx = rnd.dims[0] * i; |
| 160 | unsigned r[4] = {(unsigned)rnd.ptr[ridx], (unsigned)rnd.ptr[ridx + 1], |
| 161 | (unsigned)rnd.ptr[ridx + 2], (unsigned)rnd.ptr[ridx + 3]}; |
| 162 | |
| 163 | // If one of the points is repeated, it's a bad samples, will still |
| 164 | // compute homography to ensure all threads pass __syncthreads() |
| 165 | bool bad = (r[0] == r[1] || r[0] == r[2] || r[0] == r[3] || r[1] == r[2] || |
| 166 | r[1] == r[3] || r[2] == r[3]); |
| 167 | |
| 168 | for (unsigned j = 0; j < 4; j++) { |
| 169 | src_pt_x[j] = x_src.ptr[r[j]]; |
| 170 | src_pt_y[j] = y_src.ptr[r[j]]; |
| 171 | dst_pt_x[j] = x_dst.ptr[r[j]]; |
| 172 | dst_pt_y[j] = y_dst.ptr[r[j]]; |
| 173 | } |
| 174 | |
| 175 | *x_src_mean = (src_pt_x[0] + src_pt_x[1] + src_pt_x[2] + src_pt_x[3]) / 4.f; |
| 176 | *y_src_mean = (src_pt_y[0] + src_pt_y[1] + src_pt_y[2] + src_pt_y[3]) / 4.f; |
| 177 | *x_dst_mean = (dst_pt_x[0] + dst_pt_x[1] + dst_pt_x[2] + dst_pt_x[3]) / 4.f; |
| 178 | *y_dst_mean = (dst_pt_y[0] + dst_pt_y[1] + dst_pt_y[2] + dst_pt_y[3]) / 4.f; |
| 179 | |
| 180 | float src_var = 0.0f, dst_var = 0.0f; |
| 181 | for (unsigned j = 0; j < 4; j++) { |
| 182 | src_var += |
| 183 | sq(src_pt_x[j] - *x_src_mean) + sq(src_pt_y[j] - *y_src_mean); |
| 184 | dst_var += |
| 185 | sq(dst_pt_x[j] - *x_dst_mean) + sq(dst_pt_y[j] - *y_dst_mean); |
| 186 | } |
| 187 | |
| 188 | src_var /= 4.f; |
| 189 | dst_var /= 4.f; |
| 190 | |
| 191 | *src_scale = sqrt(2.0f) / sqrt(src_var); |
| 192 | *dst_scale = sqrt(2.0f) / sqrt(dst_var); |
| 193 | |
| 194 | return !bad; |
| 195 | } |
| 196 | |
| 197 | #define SSPTR(Z, Y, X) (s_S[(Z)*81 + (Y)*9 + (X)]) |
| 198 |
no test coverage detected