| 14 | using namespace af; |
| 15 | |
| 16 | static void fast_demo(bool console) { |
| 17 | // Load image |
| 18 | array img_color; |
| 19 | if (console) |
| 20 | img_color = loadImage(ASSETS_DIR "/examples/images/square.png", true); |
| 21 | else |
| 22 | img_color = loadImage(ASSETS_DIR "/examples/images/man.jpg", true); |
| 23 | // Convert the image from RGB to gray-scale |
| 24 | array img = colorSpace(img_color, AF_GRAY, AF_RGB); |
| 25 | // For visualization in ArrayFire, color images must be in the [0.0f-1.0f] |
| 26 | // interval |
| 27 | img_color /= 255.f; |
| 28 | |
| 29 | features feat = fast(img, 20.0f, 9, true, 0.05); |
| 30 | |
| 31 | float* h_x = feat.getX().host<float>(); |
| 32 | float* h_y = feat.getY().host<float>(); |
| 33 | |
| 34 | // Draw draw_len x draw_len crosshairs where the corners are |
| 35 | const int draw_len = 3; |
| 36 | for (size_t f = 0; f < feat.getNumFeatures(); f++) { |
| 37 | int x = h_x[f]; |
| 38 | int y = h_y[f]; |
| 39 | img_color(y, seq(x - draw_len, x + draw_len), 0) = 0.f; |
| 40 | img_color(y, seq(x - draw_len, x + draw_len), 1) = 1.f; |
| 41 | img_color(y, seq(x - draw_len, x + draw_len), 2) = 0.f; |
| 42 | |
| 43 | // Draw vertical line of (draw_len * 2 + 1) pixels centered on the |
| 44 | // corner Set only the first channel to 1 (green lines) |
| 45 | img_color(seq(y - draw_len, y + draw_len), x, 0) = 0.f; |
| 46 | img_color(seq(y - draw_len, y + draw_len), x, 1) = 1.f; |
| 47 | img_color(seq(y - draw_len, y + draw_len), x, 2) = 0.f; |
| 48 | } |
| 49 | |
| 50 | freeHost(h_x); |
| 51 | freeHost(h_y); |
| 52 | |
| 53 | printf("Features found: %zu\n", feat.getNumFeatures()); |
| 54 | |
| 55 | if (!console) { |
| 56 | af::Window wnd("FAST Feature Detector"); |
| 57 | |
| 58 | // Previews color image with green crosshairs |
| 59 | while (!wnd.close()) wnd.image(img_color); |
| 60 | } else { |
| 61 | af_print(feat.getX()); |
| 62 | af_print(feat.getY()); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | int main(int argc, char** argv) { |
| 67 | int device = argc > 1 ? atoi(argv[1]) : 0; |