Exemplo n.º 1
0
/* Wrapper to set the options for the SIFT3D struct. The argument mx shall be
 * a struct with the following fields:
 *      -peakThresh
 *      -cornerThresh
 *      -numKpLevels
 *      -sigmaN
 *      -sigma0
 *
 * Any other fields are ignored. Empty fields are replaced with the defaults. 
 *
 * Returns SIFT3D_SUCCESS on success, SIFT3D_FAILURE otherwise. */
int mex_set_opts_SIFT3D(const mxArray *const mx) {

        SIFT3D sift3d;
        const mxArray *mxFirstOctave, *mxPeakThresh, *mxCornerThresh, 
                *mxNumKpLevels, *mxSigmaN, *mxSigma0;

        // Verify inputs
        if (mxIsEmpty(mx) || !mxIsStruct(mx))
                return SIFT3D_FAILURE;

        // Get the option arrays
        if ((mxPeakThresh = mxGetField(mx, 0, "peakThresh")) == NULL ||
                (mxCornerThresh = mxGetField(mx, 0, "cornerThresh")) == NULL ||
                (mxNumKpLevels = mxGetField(mx, 0, "numKpLevels")) == NULL ||
                (mxSigmaN = mxGetField(mx, 0, "sigmaN")) == NULL ||
                (mxSigma0 = mxGetField(mx, 0, "sigma0")) == NULL)
                return SIFT3D_FAILURE;

        // Initialize intermediates
        if (init_SIFT3D(&sift3d))
                return SIFT3D_FAILURE;

        // Set the non-empty options in our new SIFT3D struct
        if (!mxIsEmpty(mxPeakThresh) && 
                set_peak_thresh_SIFT3D(&sift3d, mxGetScalar(mxPeakThresh)))
                goto mex_set_opts_SIFT3D_quit;
        if (!mxIsEmpty(mxCornerThresh) &&
                set_corner_thresh_SIFT3D(&sift3d, mxGetScalar(mxCornerThresh)))
                goto mex_set_opts_SIFT3D_quit;
        if (!mxIsEmpty(mxNumKpLevels) &&
                set_num_kp_levels_SIFT3D(&sift3d, 
                (int) mxGetScalar(mxNumKpLevels)))
                goto mex_set_opts_SIFT3D_quit;
        if (!mxIsEmpty(mxSigmaN) &&
                set_sigma_n_SIFT3D(&sift3d, mxGetScalar(mxSigmaN)))
                goto mex_set_opts_SIFT3D_quit;
        if (!mxIsEmpty(mxSigma0) &&
                set_sigma0_SIFT3D(&sift3d, mxGetScalar(mxSigma0)))
                goto mex_set_opts_SIFT3D_quit;

        // Set the options in the Reg_SIFT3D struct
        if (set_SIFT3D_Reg_SIFT3D(&reg, &sift3d))
                goto mex_set_opts_SIFT3D_quit;

        // Clean up
        cleanup_SIFT3D(&sift3d);

        return SIFT3D_SUCCESS;

mex_set_opts_SIFT3D_quit:
        cleanup_SIFT3D(&sift3d);
        return SIFT3D_FAILURE;
}
Exemplo n.º 2
0
/* This illustrates how to use SIFT3D within a function, and free all memory
 * afterwards. */
int demo(void) {

	Image im, draw;
        Mat_rm keys;
	SIFT3D sift3d;
	Keypoint_store kp;
	SIFT3D_Descriptor_store desc;

        // Initialize the intermediates
        init_Keypoint_store(&kp);
        init_SIFT3D_Descriptor_store(&desc);
        init_im(&im);
        init_im(&draw);
        if (init_Mat_rm(&keys, 0, 0, DOUBLE, SIFT3D_FALSE))
                return 1; 

        if (init_SIFT3D(&sift3d)) {
                cleanup_Mat_rm(&keys);
                return 1;
        }

        // Read the image
        if (im_read(im_path, &im))
                goto demo_quit;

        // Detect keypoints
	if (SIFT3D_detect_keypoints(&sift3d, &im, &kp))
                goto demo_quit;

        // Write the keypoints to a file
        if (write_Keypoint_store(keys_path, &kp))
                goto demo_quit;
        printf("Keypoints written to %s. \n", keys_path);

        // Extract descriptors
        if (SIFT3D_extract_descriptors(&sift3d, &kp, &desc))
                goto demo_quit;

        // Write the descriptors to a file
        if (write_SIFT3D_Descriptor_store(desc_path, &desc))
                goto demo_quit;
        printf("Descriptors written to %s. \n", desc_path);

        // Convert the keypoints to a matrix 
        if (Keypoint_store_to_Mat_rm(&kp, &keys))
                goto demo_quit;

        // Draw the keypoints
        if (draw_points(&keys, im.dims, 1, &draw))
                goto demo_quit;

        // Write the drawn keypoints to a file
        if (im_write(draw_path, &draw))
                goto demo_quit;
        printf("Keypoints drawn in %s. \n", draw_path);

        // Clean up
        im_free(&im);
        im_free(&draw);
        cleanup_Mat_rm(&keys);
        cleanup_SIFT3D(&sift3d);
        cleanup_Keypoint_store(&kp);
        cleanup_SIFT3D_Descriptor_store(&desc);

        return 0;

demo_quit:
        // Clean up and return an error
        im_free(&im);
        im_free(&draw);
        cleanup_Mat_rm(&keys);
        cleanup_SIFT3D(&sift3d);
        cleanup_Keypoint_store(&kp);
        cleanup_SIFT3D_Descriptor_store(&desc);

        return 1;
}