void run_cpu(guchar *image, int width, int height, int channels) { char *img = (char *)malloc(width * height * sizeof(char)); memcpy(img, image, (size_t)(width * height * sizeof(char))); //average_blur(width, height, img); char *x_component = (char *)malloc(width * height * sizeof(char)); char *y_component = (char *)malloc(width * height * sizeof(char)); float *xx_grad = (float *)malloc(width * height * sizeof(float)); float *xy_grad = (float *)malloc(width * height * sizeof(float)); float *yy_grad = (float *)malloc(width * height * sizeof(float)); float *harris = (float *)malloc(width * height * sizeof(float)); memcpy(x_component, image, (size_t)(width * height * sizeof(char))); memcpy(y_component, image, (size_t)(width * height * sizeof(char))); compute_xgrad(width, height, x_component, img); compute_ygrad(width, height, y_component, img); gradient_matrix(width, height, x_component, y_component, xx_grad, xy_grad, yy_grad); average_blur(width, height, xx_grad); average_blur(width, height, xy_grad); average_blur(width, height, yy_grad); harris_corner(width, height, harris, xx_grad, xy_grad, yy_grad); nonmax_suppression(width, height, harris); threshold(width, height, image, harris); }
xy* fast9_detect_nonmax(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners) { xy* corners; int num_corners; int* scores; xy* nonmax; corners = fast9_detect(im, xsize, ysize, stride, b, &num_corners); printf("Original number of corners found %d\n",num_corners); printf("Found %d corners\n",num_corners); FILE *fid = fopen("detected_all.txt","w"); fprintf(fid,"# Detected points for original FAST-9\n"); fprintf(fid,"%d\n",num_corners); for( int i = 0; i < num_corners; i++ ) { fprintf(fid,"%d %d\n",corners[i].x,corners[i].y); } fclose(fid); scores = fast9_score(im, stride, corners, num_corners, b); nonmax = nonmax_suppression(corners, scores, num_corners, ret_num_corners); free(corners); free(scores); return nonmax; }
vec2i* fast12_detect_nonmax(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners, FastStorage &storage) { vec2i* corners; int num_corners; int* scores; vec2i* nonmax; corners = ::ml::fast12::fast12_detect(im, xsize, ysize, stride, b, &num_corners, storage); scores = ::ml::fast12::fast12_score(im, stride, corners, num_corners, b, storage); nonmax = nonmax_suppression(corners, scores, num_corners, ret_num_corners, storage); return nonmax; }
vec2i* fast9_detect_nonmax(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners) { vec2i* corners; int num_corners; int* scores; vec2i* nonmax; corners = ::ml::fast9::fast9_detect(im, xsize, ysize, stride, b, &num_corners); scores = ::ml::fast9::fast9_score(im, stride, corners, num_corners, b); nonmax = nonmax_suppression(corners, scores, num_corners, ret_num_corners); free(corners); free(scores); return nonmax; }
xy* fast12_detect_nonmax(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners) { xy* corners; int num_corners; int* scores; xy* nonmax; corners = fast12_detect(im, xsize, ysize, stride, b, &num_corners); scores = fast12_score(im, stride, corners, num_corners, b); nonmax = nonmax_suppression(corners, scores, num_corners, ret_num_corners); free(corners); free(scores); return nonmax; }
//////////////////////////////////////////////////////////////////////////////// //! Run the multiresolution filter on the CPU //////////////////////////////////////////////////////////////////////////////// void run_cpu(guchar *image, int width, int height, int channels) { guchar *img = (guchar *)malloc(width * height * sizeof(guchar)); memcpy(img, image, (size_t)(width * height * sizeof(guchar))); average_blur(width, height, img); char *x_component = (char *)malloc(width * height * sizeof(char)); char *y_component = (char *)malloc(width * height * sizeof(char)); double *xx_grad = (double *)malloc(width * height * sizeof(double)); double *xy_grad = (double *)malloc(width * height * sizeof(double)); double *yy_grad = (double *)malloc(width * height * sizeof(double)); double *harris = (double *)malloc(width * height * sizeof(double)); memcpy(x_component, img, (size_t)(width * height * sizeof(char))); memcpy(y_component, img, (size_t)(width * height * sizeof(char))); compute_xgrad(width, height, x_component, img); compute_ygrad(width, height, y_component, img); //gradient_magnitude(width, height, x_component, y_component, image); gradient_matrix(width, height, x_component, y_component, xx_grad, xy_grad, yy_grad); harris_corner(width, height, harris, xx_grad, xy_grad, yy_grad); nonmax_suppression(width, height, harris); threshold(width, height, image, harris); /* int i, j; for(i = 0; i < height; i++) { for(j = 0; j < width; j++) { printf("%f ", harris[i * width + j]); } printf("\n"); }*/ }
void NxUtils::DetectCorners( float * Cotrners2D, const unsigned char * im, int xsize, int ysize, int stride, int b, int* ret_num_corners, bool nonmax_sup, NxFastCornerDetectionType Type ) { //xy * ret = fast12_detect( im, xsize, ysize, stride, b, ret_num_corners); //xy * ret = fast9_detect_nonmax( im, xsize, ysize, stride, b, ret_num_corners); xy * corners = NULL; xy * nonmax_corners = NULL; int num_corners=0, num_nonmax=0; int* scores=0; if(Type == NxFast9) corners = fast9_detect(im, xsize, ysize, stride, b, &num_corners ); else if(Type == NxFast10) corners = fast10_detect(im, xsize, ysize, stride, b, &num_corners ); else if(Type == NxFast11) corners = fast11_detect(im, xsize, ysize, stride, b, &num_corners ); else corners = fast12_detect(im, xsize, ysize, stride, b, &num_corners ); //Compute scores if(nonmax_sup) { if(Type == NxFast9) scores = fast9_score(im, stride, corners, num_corners, b); else if(Type == NxFast10) scores = fast10_score(im, stride, corners, num_corners, b); else if(Type == NxFast11) scores = fast11_score(im, stride, corners, num_corners, b); else scores = fast12_score(im, stride, corners, num_corners, b); } *ret_num_corners = num_corners; int y = 0; int numCorners= *ret_num_corners; for(int i = 0; i < numCorners; i++){ Cotrners2D[y] = corners[i].x; Cotrners2D[y+1] = corners[i].y; y += 2; } //*ret_corners = corners; //Do nonmax suppression if need be if(nonmax_sup) { nonmax_corners = nonmax_suppression(corners, scores, num_corners, & num_nonmax); *ret_num_corners = num_nonmax; int y = 0; int numCorners= *ret_num_corners; for(int i = 0; i < numCorners; i++){ Cotrners2D[y] = nonmax_corners[i].x; Cotrners2D[y+1] = nonmax_corners[i].y; y += 2; } free(corners); } free(scores); }