| 1 | #include <cvd/fast_corner.h> |
| 2 | |
| 3 | #include <cvd/utility.h> |
| 4 | #include <list> |
| 5 | #include <vector> |
| 6 | using namespace CVD; |
| 7 | using namespace std; |
| 8 | #include <emmintrin.h> |
| 9 | |
| 10 | #include "cvd_src/SSE2/faster_corner_utilities.h" |
| 11 | #include "cvd_src/fast/prototypes.h" |
| 12 | namespace CVD |
| 13 | { |
| 14 | #include "cvd_src/corner_10.h" |
| 15 | |
| 16 | template <bool Aligned> |
| 17 | void faster_corner_detect_10(const BasicImage<byte>& I, std::vector<ImageRef>& corners, const int barrier) |
| 18 | { |
| 19 | const int row_stride = I.row_stride(); |
| 20 | const int stride = 3 * row_stride; |
| 21 | |
| 22 | const __m128i barriers = _mm_set1_epi8((byte)barrier); |
| 23 | |
| 24 | int xend = I.size().x - 3; |
| 25 | xend -= (I.size().x - 3) % 16; |
| 26 | |
| 27 | for(int y = 3; y < I.size().y - 3; y++) |
| 28 | { |
| 29 | for(int x = 3; x < 16; x++) |
| 30 | if(is_corner_10<Less>(&I[y][x], I.row_stride(), barrier) || is_corner_10<Greater>(&I[y][x], I.row_stride(), barrier)) |
| 31 | corners.push_back(ImageRef(x, y)); |
| 32 | |
| 33 | for(int x = 16; x < xend; x += 16) |
| 34 | { |
| 35 | const byte* p = &I[y][x]; |
| 36 | __m128i lo, hi; |
| 37 | { |
| 38 | const __m128i here = load_si128<Aligned>((const __m128i*)(p)); |
| 39 | lo = _mm_subs_epu8(here, barriers); |
| 40 | hi = _mm_adds_epu8(barriers, here); |
| 41 | } |
| 42 | unsigned int ans_b, ans_e; |
| 43 | { |
| 44 | __m128i top = load_si128<Aligned>((const __m128i*)(p - stride)); |
| 45 | __m128i bottom = load_si128<Aligned>((const __m128i*)(p + stride)); |
| 46 | |
| 47 | CHECK_BARRIER(lo, hi, top, ans_b); |
| 48 | CHECK_BARRIER(lo, hi, bottom, ans_e); |
| 49 | if(!(ans_b | ans_e)) |
| 50 | continue; |
| 51 | } |
| 52 | |
| 53 | unsigned int ans_m, ans_p, possible; |
| 54 | { |
| 55 | __m128i ul = _mm_loadu_si128((const __m128i*)(p - 2 - 2 * row_stride)); |
| 56 | __m128i lr = _mm_loadu_si128((const __m128i*)(p + 2 + 2 * row_stride)); |
| 57 | CHECK_BARRIER(lo, hi, ul, ans_m); |
| 58 | CHECK_BARRIER(lo, hi, lr, ans_p); |
| 59 | possible = (ans_m & ans_b) | (ans_e & ans_p); |
| 60 | if(!possible) |
| 61 | continue; |
| 62 | } |
| 63 | |
| 64 | unsigned int ans_o, ans_n; |
| 65 | { |
| 66 | __m128i ll = _mm_loadu_si128((const __m128i*)(p - 2 + 2 * row_stride)); |
| 67 | __m128i ur = _mm_loadu_si128((const __m128i*)(p + 2 - 2 * row_stride)); |
| 68 | CHECK_BARRIER(lo, hi, ll, ans_o); |
| 69 | CHECK_BARRIER(lo, hi, ur, ans_n); |
| 70 | possible &= ans_o | (ans_b & ans_n); |
| 71 | possible &= ans_n | (ans_e & ans_o); |
| 72 | if(!possible) |
| 73 | continue; |
| 74 | } |
| 75 | |
| 76 | unsigned int ans_h, ans_k; |
| 77 | { |
| 78 | __m128i left = _mm_loadu_si128((const __m128i*)(p - 3)); |
| 79 | __m128i right = _mm_loadu_si128((const __m128i*)(p + 3)); |
| 80 | CHECK_BARRIER(lo, hi, left, ans_h); |
| 81 | CHECK_BARRIER(lo, hi, right, ans_k); |
| 82 | possible &= ans_h | (ans_n & ans_k & ans_p); |
| 83 | possible &= ans_k | (ans_m & ans_h & ans_o); |
| 84 | if(!possible) |
| 85 | continue; |
| 86 | } |
| 87 | |
| 88 | unsigned int ans_a, ans_c; |
| 89 | { |
| 90 | __m128i a = _mm_loadu_si128((const __m128i*)(p - 1 - stride)); |
| 91 | __m128i c = _mm_insert_epi16(_mm_srli_si128(a, 2), *(const unsigned short*)(p + 15 - stride), 7); |
| 92 | //__m128i c = _mm_loadu_si128((const __m128i*)(p+1-stride)); |
| 93 | CHECK_BARRIER(lo, hi, a, ans_a); |
| 94 | CHECK_BARRIER(lo, hi, c, ans_c); |
| 95 | possible &= ans_a | (ans_e & ans_p); |
| 96 | possible &= ans_c | (ans_o & ans_e); |
| 97 | if(!possible) |
| 98 | continue; |
| 99 | } |
| 100 | |
| 101 | unsigned int ans_d, ans_f; |
| 102 | { |
| 103 | __m128i d = _mm_loadu_si128((const __m128i*)(p - 1 + stride)); |
| 104 | __m128i f = _mm_insert_epi16(_mm_srli_si128(d, 2), *(const unsigned short*)(p + 15 + stride), 7); |
| 105 | //__m128i f = _mm_loadu_si128((const __m128i*)(p+1+stride)); |
| 106 | CHECK_BARRIER(lo, hi, d, ans_d); |
| 107 | CHECK_BARRIER(lo, hi, f, ans_f); |
| 108 | const unsigned int ans_abc = ans_a & ans_b & ans_c; |
| 109 | possible &= ans_d | (ans_abc & ans_n); |
| 110 | possible &= ans_f | (ans_m & ans_abc); |
| 111 | if(!possible) |
| 112 | continue; |
| 113 | } |
| 114 | |
| 115 | unsigned int ans_g, ans_i; |
| 116 | { |
| 117 | __m128i g = _mm_loadu_si128((const __m128i*)(p - 3 - row_stride)); |
| 118 | __m128i ii = _mm_loadu_si128((const __m128i*)(p - 3 + row_stride)); |
| 119 | CHECK_BARRIER(lo, hi, g, ans_g); |
| 120 | CHECK_BARRIER(lo, hi, ii, ans_i); |
| 121 | possible &= ans_g | (ans_f & ans_p & ans_k); |
| 122 | possible &= ans_i | (ans_c & ans_n & ans_k); |
| 123 | if(!possible) |
| 124 | continue; |
| 125 | } |
| 126 | |
| 127 | unsigned int ans_j, ans_l; |
| 128 | { |
| 129 | __m128i jj = _mm_loadu_si128((const __m128i*)(p + 3 - row_stride)); |
| 130 | __m128i l = _mm_loadu_si128((const __m128i*)(p + 3 + row_stride)); |
| 131 | CHECK_BARRIER(lo, hi, jj, ans_j); |
| 132 | CHECK_BARRIER(lo, hi, l, ans_l); |
| 133 | const unsigned int ans_ghi = ans_g & ans_h & ans_i; |
| 134 | possible &= ans_j | (ans_d & ans_o & ans_ghi); |
| 135 | possible &= ans_l | (ans_m & ans_a & ans_ghi); |
| 136 | if(!possible) |
| 137 | continue; |
| 138 | } |
| 139 | |
| 140 | possible |= (possible >> 16); |
| 141 | //if(possible & 0x0f) //Does this make it faster? |
| 142 | { |
| 143 | if(possible & (1 << 0)) |
| 144 | corners.push_back(ImageRef(x + 0, y)); |
| 145 | if(possible & (1 << 1)) |
| 146 | corners.push_back(ImageRef(x + 1, y)); |
| 147 | if(possible & (1 << 2)) |
| 148 | corners.push_back(ImageRef(x + 2, y)); |
| 149 | if(possible & (1 << 3)) |
| 150 | corners.push_back(ImageRef(x + 3, y)); |
| 151 | if(possible & (1 << 4)) |
| 152 | corners.push_back(ImageRef(x + 4, y)); |
| 153 | if(possible & (1 << 5)) |
| 154 | corners.push_back(ImageRef(x + 5, y)); |
| 155 | if(possible & (1 << 6)) |
| 156 | corners.push_back(ImageRef(x + 6, y)); |
| 157 | if(possible & (1 << 7)) |
| 158 | corners.push_back(ImageRef(x + 7, y)); |
| 159 | } |
| 160 | //if(possible & 0xf0) //Does this mak( , fast)r? |
| 161 | { |
| 162 | if(possible & (1 << 8)) |
| 163 | corners.push_back(ImageRef(x + 8, y)); |
| 164 | if(possible & (1 << 9)) |
| 165 | corners.push_back(ImageRef(x + 9, y)); |
| 166 | if(possible & (1 << 10)) |
| 167 | corners.push_back(ImageRef(x + 10, y)); |
| 168 | if(possible & (1 << 11)) |
| 169 | corners.push_back(ImageRef(x + 11, y)); |
| 170 | if(possible & (1 << 12)) |
| 171 | corners.push_back(ImageRef(x + 12, y)); |
| 172 | if(possible & (1 << 13)) |
| 173 | corners.push_back(ImageRef(x + 13, y)); |
| 174 | if(possible & (1 << 14)) |
| 175 | corners.push_back(ImageRef(x + 14, y)); |
| 176 | if(possible & (1 << 15)) |
| 177 | corners.push_back(ImageRef(x + 15, y)); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | for(int x = xend; x < I.size().x - 3; x++) |
| 182 | if(is_corner_10<Less>(&I[y][x], I.row_stride(), barrier) || is_corner_10<Greater>(&I[y][x], I.row_stride(), barrier)) |
| 183 | corners.push_back(ImageRef(x, y)); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void fast_corner_detect_10(const BasicImage<byte>& I, std::vector<ImageRef>& corners, int barrier) |
| 188 | { |
| 189 | if(I.size().x < 22) |
| 190 | { |
| 191 | fast_corner_detect_plain_10(I, corners, barrier); |
| 192 | return; |
| 193 | } |
| 194 | else if(I.size().x < 22 || I.size().y < 7) |
| 195 | return; |
| 196 | |
| 197 | if(is_aligned<16>(I[0]) && is_aligned<16>(I[1])) |
| 198 | faster_corner_detect_10<true>(I, corners, barrier); |
| 199 | else |
| 200 | faster_corner_detect_10<false>(I, corners, barrier); |
| 201 | } |
| 202 | } |