| 24 | |
| 25 | template<typename T> |
| 26 | unsigned susan(Array<float> &x_out, Array<float> &y_out, Array<float> &resp_out, |
| 27 | const Array<T> &in, const unsigned radius, const float diff_thr, |
| 28 | const float geom_thr, const float feature_ratio, |
| 29 | const unsigned edge) { |
| 30 | dim4 idims = in.dims(); |
| 31 | const unsigned corner_lim = in.elements() * feature_ratio; |
| 32 | |
| 33 | auto x_corners = createEmptyArray<float>(dim4(corner_lim)); |
| 34 | auto y_corners = createEmptyArray<float>(dim4(corner_lim)); |
| 35 | auto resp_corners = createEmptyArray<float>(dim4(corner_lim)); |
| 36 | auto response = createEmptyArray<T>(dim4(in.elements())); |
| 37 | auto corners_found = |
| 38 | std::shared_ptr<unsigned>(memAlloc<unsigned>(1).release(), memFree); |
| 39 | corners_found.get()[0] = 0; |
| 40 | |
| 41 | getQueue().enqueue(kernel::susan_responses<T>, response, in, idims[0], |
| 42 | idims[1], radius, diff_thr, geom_thr, edge); |
| 43 | getQueue().enqueue(kernel::non_maximal<T>, x_corners, y_corners, |
| 44 | resp_corners, corners_found, idims[0], idims[1], |
| 45 | response, edge, corner_lim); |
| 46 | getQueue().sync(); |
| 47 | |
| 48 | const unsigned corners_out = min((corners_found.get())[0], corner_lim); |
| 49 | if (corners_out == 0) { |
| 50 | x_out = createEmptyArray<float>(dim4()); |
| 51 | y_out = createEmptyArray<float>(dim4()); |
| 52 | resp_out = createEmptyArray<float>(dim4()); |
| 53 | return 0; |
| 54 | } else { |
| 55 | x_out = x_corners; |
| 56 | y_out = y_corners; |
| 57 | resp_out = resp_corners; |
| 58 | x_out.resetDims(dim4(corners_out)); |
| 59 | y_out.resetDims(dim4(corners_out)); |
| 60 | resp_out.resetDims(dim4(corners_out)); |
| 61 | return corners_out; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | #define INSTANTIATE(T) \ |
| 66 | template unsigned susan<T>( \ |