#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];
 
        printf("Corners found: %d\n\n", good_corners);
 
    }
}
 
int main(int argc, char** argv) {
    int device   = argc > 1 ? atoi(argv[1]) : 0;
    bool console = argc > 2 ? argv[2][0] == '-' : false;
 
    try {
        printf("** ArrayFire Harris Corner Detector Demo **\n\n");
        harris_demo(console);
 
        fprintf(stderr, 
"%s\n", ae.
what());
        throw;
    }
 
    return 0;
}
Window object to render af::arrays.
A multi dimensional data container.
dim4 dims() const
Get dimensions of the array.
T * host() const
Copy array data to host and return host pointer.
An ArrayFire exception class.
virtual const char * what() const
Returns an error message for the exception in a string format.
seq is used to create sequences for indexing af::array
void grad(array &dx, array &dy, const array &in)
C++ Interface for calculating the gradients.
array constant(T val, const dim4 &dims, const dtype ty=(af_dtype) dtype_traits< T >::ctype)
C++ Interface to generate an array with elements set to a specified value.
void freeHost(const void *ptr)
Free memory allocated internally by ArrayFire.
void setDevice(const int device)
Sets the current device.
void image(const array &in, const char *title=NULL)
Renders the input array as an image to the window.
bool close()
Check if window is marked for close.
array colorSpace(const array &image, const CSpace to, const CSpace from)
C++ Interface wrapper for colorspace conversion.
array dilate(const array &in, const array &mask)
C++ Interface for image dilation (max filter)
array gaussianKernel(const int rows, const int cols, const double sig_r=0, const double sig_c=0)
C++ Interface for generating gausian kernels.
array loadImage(const char *filename, const bool is_color=false)
C++ Interface for loading an image.
array where(const array &in)
C++ Interface to locate the indices of the non-zero values in an array.
array convolve(const array &signal, const array &filter, const convMode mode=AF_CONV_DEFAULT, const convDomain domain=AF_CONV_AUTO)
C++ Interface for convolution any(one through three) dimensional signals.