コード例 #1
0
ファイル: match_cli.c プロジェクト: ivreo/sift_anatomy_extra
int main(int argc, char **argv)
{
    // Setting default parameters
    int n_hist = 4;
    int n_ori = 8;
    int n_bins = 36;
    int meth_flag = 1;
    float thresh = 0.6;
    int verb_flag = 0;
    char label[256];
    strcpy(label, "extra");

    // Parsing command line
    int res = parse_options(argc, argv, &n_bins, &n_hist, &n_ori,
                            &meth_flag, &thresh, &verb_flag, label);
    if (res == EXIT_FAILURE)
        return EXIT_FAILURE;

    // Memory allocation
    struct sift_keypoints* k1 = sift_malloc_keypoints();
    struct sift_keypoints* k2 = sift_malloc_keypoints();
    struct sift_keypoints* out_k1 = sift_malloc_keypoints();
    struct sift_keypoints* out_k2A = sift_malloc_keypoints();
    struct sift_keypoints* out_k2B = sift_malloc_keypoints();

    // Read input keypoint ASCII files
    int readflag = verb_flag + 1;
    sift_read_keypoints(k1, argv[1], n_hist, n_ori, n_bins, readflag);
    sift_read_keypoints(k2, argv[2], n_hist, n_ori, n_bins, readflag);


    debug("size read keys / k1 %i / k2 %i /", k1->size, k2->size);

    // Matching
    matching(k1, k2, out_k1, out_k2A, out_k2B, thresh, meth_flag);

    // Print
    print_pairs(out_k1, out_k2A);
    char name[FILENAME_MAX];
    if(verb_flag == 1){
        save_pairs_extra("OUTmatches.txt", out_k1, out_k2A, out_k2B);
        sprintf(name, "%s_im0.txt", label);
        sift_save_keypoints(out_k1, name, 1);
        sprintf(name, "%s_im1.txt", label);
        sift_save_keypoints(out_k2A, name, 1);
    }

    // Free memory
    sift_free_keypoints(k1);
    sift_free_keypoints(k2);
    sift_free_keypoints(out_k1);
    sift_free_keypoints(out_k2A);
    sift_free_keypoints(out_k2B);

    return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: lib_sift.c プロジェクト: jguinet/s2p
struct sift_keypoint_std *sift_read_keyslocation_from_file(char *filename, int *n)
{
    struct sift_parameters* p = sift_assign_default_parameters();
    int n_ori = p->n_ori;   // 8
    int n_hist = p->n_hist; // 4
    int l = n_hist*n_hist*n_ori;
    int n_bins = p->n_bins;

    // read keypoints locations from a file and
    // save them into a sift_keypoints structure
    struct sift_keypoints* keys = sift_malloc_keypoints();
    int flag = 0; // read coordinates 
    sift_read_keypoints(keys, filename, n_hist, n_ori, n_bins, flag);

    // translate the sift_keypoints structure into a flat list
    *n = keys->size;
    struct sift_keypoint_std* k = xmalloc((*n)*sizeof(struct sift_keypoint_std));
    for(int i = 0; i < keys->size; i++){
        k[i].x = keys->list[i]->x;
        k[i].y = keys->list[i]->y;
        k[i].scale = keys->list[i]->sigma;
        k[i].orientation = keys->list[i]->theta;  // 0
        for(int j=0; j<l; j++){
            k[i].descriptor[j] = keys->list[i]->descr[j]; // 0
        }
    }
    sift_free_keypoints(keys);

    return k;
}
コード例 #3
0
ファイル: lib_sift.c プロジェクト: jguinet/s2p
/** @brief Extracts oriented keypoints (without description
 *
 *
 */
struct sift_keypoint_std* sift_compute_points(const float* x, int w, int h, int *n)
{

    /** assign default parameters **/
    struct sift_parameters* p = sift_assign_default_parameters();

    /** Memory dynamic allocation */
    // WARNING 5 lists of keypoints containing intermediary states of the algorithm
    struct sift_keypoints **kk = xmalloc(5*sizeof(struct sift_keypoints*));
    for(int i = 0; i < 5; i++){
        kk[i] = sift_malloc_keypoints();
    }
    // WARNING 4 scalespace structure containing the DoG and Gaussian scalespace and the gradient
    struct sift_scalespace **ss = xmalloc(2*sizeof(struct sift_scalespace*));

    /** Algorithm */
    struct sift_keypoints* keys = sift_anatomy_without_description(x, w, h, p, ss, kk);

    /* Copy to a list of keypoints */
    *n = keys->size;
    struct sift_keypoint_std* k = xmalloc((*n)*sizeof(*k));
    for(int i = 0; i < keys->size; i++){
        k[i].x = keys->list[i]->x;
        k[i].y = keys->list[i]->y;
        k[i].scale = keys->list[i]->sigma;
        k[i].orientation = keys->list[i]->theta;
        for(int j = 0; j < 128; j++){
            k[i].descriptor[j] = 0;
        }
    }

    /* memory deallocation */
    xfree(p);
    sift_free_keypoints(keys);
    for(int i = 0; i < 5; i++){
        sift_free_keypoints(kk[i]);
    }
    xfree(kk);
    for(int i = 0; i < 2; i++){
        sift_free_scalespace(ss[i]);
    }
    xfree(ss);

    return k;
}
コード例 #4
0
int main(int argc, char **argv)
{

    if((argc != 3)&&(argc != 5)){
        print_usage();
        return EXIT_FAILURE;
    }

    // Loading image
    int w, h;
    _myfloat* im = read_image_to_gray(argv[2], &w, &h);

    // load standard method parameter
    struct sift_parameters* p = sift_assign_default_parameters();
    bool gauss_flag = true;
    if (argc  == 5){
        p->lambda_descr = atof(argv[argc-2]);
        gauss_flag = atoi(argv[argc-1]);
    }

    // load keypoints (ellipse)
    struct sift_keypoints *l = sift_malloc_keypoints();
    sift_read_ellipses(l, argv[1], p->n_hist, p->n_ori, p->n_bins, 0);
    fprintf(stderr," after read");
    estimate_scalespace_index(l, p);
    fprintf(stderr," after estimate scalespace index");

    // scalespace, gradient, orientation and description
    ellipse_sift_anatomy_orientation_and_description(im, w, h, p, l, gauss_flag);
    fprintf(stderr," after ellipse index");

    // printing ellipses
    fprintf_ellipses(stdout, l, 1);

    // memory deallocation
    sift_free_keypoints(l);
    free(im);

    return EXIT_SUCCESS;
}
コード例 #5
0
ファイル: sift_roi.c プロジェクト: jguinet/s2p
int main(int c, char *v[])
{
    // process input arguments
    if (c < 2) {
        print_help(v);
    	return 1;
    }

    // optional arguments
    const char *output_file = pick_option(&c, &v, "o", "stdout");
    bool binary = (bool) pick_option(&c, &v, "b", NULL);
    bool verbose = (bool) pick_option(&c, &v, "-verbose", NULL);
    int max_nb_pts = atoi(pick_option(&c, &v, "-max-nb-pts", "INT_MAX"));
    float thresh_dog = atof(pick_option(&c, &v, "-thresh-dog", "0.0133"));
    int ss_noct = atoi(pick_option(&c, &v, "-scale-space-noct", "8"));
    int ss_nspo = atoi(pick_option(&c, &v, "-scale-space-nspo", "3"));

    // initialise time
    struct timespec ts; portable_gettime(&ts);


    // define the rectangular region of interest (roi)
    int x, y, w, h;
    if (c == 2) {
        x = 0;
        y = 0;
    } else if (c == 6) {
        x = atoi(v[2]);
        y = atoi(v[3]);
        w = atoi(v[4]);
        h = atoi(v[5]);
    } else {
        print_help(v);
        return 1;
    }

    // read the roi in the input image
    GDALDatasetH  hDataset;
    GDALAllRegister();
    hDataset = GDALOpen( v[1], GA_ReadOnly );
    if( hDataset == NULL )
    {
        fprintf(stderr, "ERROR : can't open %s\n", v[1]);
    }
       
    GDALRasterBandH hBand;
    hBand = GDALGetRasterBand( hDataset, 1 );
    float *roi;
    roi = (float *) CPLMalloc(sizeof(float)*w*h);
    GDALRasterIO( hBand, GF_Read, x, y, w, h, 
              roi, w, h, GDT_Float32, 
              0, 0 );
    GDALClose(hBand);
    GDALClose(hDataset);
    
    
    if (verbose) print_elapsed_time(&ts, "read ROI", 35);

    // prepare sift parameters
    struct sift_parameters* p = sift_assign_default_parameters();
    p->C_DoG = thresh_dog;
    p->n_oct = ss_noct;
    p->n_spo = ss_nspo;

    // compute sift keypoints
    struct sift_scalespace **ss = (struct sift_scalespace**) malloc(4 * sizeof(struct sift_scalespace*));
    struct sift_keypoints **kk = (struct sift_keypoints**) malloc(6 * sizeof(struct sift_keypoints*));
    for (int i = 0; i < 6; i++)
        kk[i] = sift_malloc_keypoints();
    struct sift_keypoints* kpts = sift_anatomy(roi, w, h, p, ss, kk);
    if (verbose) print_elapsed_time(&ts, "run SIFT", 35);

    // add (x, y) offset to keypoints coordinates
    for (int i = 0; i < kpts->size; i++) {
        kpts->list[i]->x += y;  // in Ives' conventions x is the row index
        kpts->list[i]->y += x;
    }
    if (verbose) print_elapsed_time(&ts, "add offset", 35);

    // write to standard output
    FILE *f = fopen(output_file, "w");
    fprintf_keypoints(f, kpts, max_nb_pts, binary, 1);
    fclose(f);
    if (verbose) print_elapsed_time(&ts, "write output", 35);

    // cleanup
    CPLFree(roi);
    sift_free_keypoints(kpts);
    for (int i = 0; i < 6; i++)
        sift_free_keypoints(kk[i]);
    free(kk);
    for (int i = 0; i < 4; i++)
        sift_free_scalespace(ss[i]);
    free(ss);
    free(p);
    return 0;
}