#include <cstdio>
#include <cstdlib>
static void harris_demo(bool console)
{
    
    if (console)
        img_color = 
loadImage(ASSETS_DIR 
"/examples/images/square.png", 
true);
    else
        img_color = 
loadImage(ASSETS_DIR 
"/examples/images/man.jpg", 
true);
    
    
    img_color /= 255.f;
    
    
    
    
    
    
    
    array idet = ixx * iyy - ixy * ixy;
     
    array response = idet - 0.04f * (itr * itr);
     
    
    
    array corners = response > 1e5f;
     corners = corners * response;
    
    
    corners = (corners == max_resp) * corners;
    
    float* h_corners = corners.
host<
float>();
     unsigned good_corners = 0;
    
    const int draw_len = 3;
    for (
int y = draw_len; y < img_color.
dims(0) - draw_len; y++) {
         for (
int x = draw_len; x < img_color.
dims(1) - draw_len; x++) {
             
            if (h_corners[x * corners.
dims(0) + y] > 1e5f) {
                 
                
                img_color(y, 
seq(x-draw_len, x+draw_len), 0) = 0.f;
                img_color(y, 
seq(x-draw_len, x+draw_len), 1) = 1.f;
                img_color(y, 
seq(x-draw_len, x+draw_len), 2) = 0.f;
                
                
                img_color(
seq(y-draw_len, y+draw_len), x, 0) = 0.f;
                img_color(
seq(y-draw_len, y+draw_len), x, 1) = 1.f;
                img_color(
seq(y-draw_len, y+draw_len), x, 2) = 0.f;
                good_corners++;
            }
        }
    }
    printf("Corners found: %u\n", good_corners);
    if (!console) {
        
    } else {
        
        
        const int good_corners = corners_x.
dims()[0];
         std::cout << "Corners found: " << good_corners << std::endl << std::endl;
    }
}
int main(int argc, char** argv)
{
    int device = argc > 1 ? atoi(argv[1]) : 0;
    bool console = argc > 2 ? argv[2][0] == '-' : false;
    try {
        std::cout << "** ArrayFire Harris Corner Detector Demo **" << std::endl << std::endl;
        harris_demo(console);
        std::cerr << ae.
what() << std::endl;
        throw;
    }
    return 0;
}