mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Extract keypoints in one step.
* Make find_keypoints extract FAST keypoints.
This commit is contained in:
parent
93d3885a3c
commit
7a22cb3e5c
@ -245,7 +245,7 @@ static uint8_t mean_intensity(image_t *image, i_image_t *i_image, int kp_x, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void freak_find_keypoints(image_t *image, kp_t *kpts, int kpts_size, bool orient_normalized, bool scale_normalized)
|
kp_t *freak_find_keypoints(image_t *image, bool normalized, int kpts_threshold, int *kpts_size, rectangle_t *roi)
|
||||||
{
|
{
|
||||||
int thetaIdx=0;
|
int thetaIdx=0;
|
||||||
int direction0;
|
int direction0;
|
||||||
@ -254,16 +254,22 @@ void freak_find_keypoints(image_t *image, kp_t *kpts, int kpts_size, bool orient
|
|||||||
uint8_t *desc;
|
uint8_t *desc;
|
||||||
uint8_t pointsValue[kNB_POINTS];
|
uint8_t pointsValue[kNB_POINTS];
|
||||||
|
|
||||||
i_image_t i_image;
|
// Find keypoints
|
||||||
|
kp_t *kpts = fast_detect(image, kpts_threshold, kpts_size, roi);
|
||||||
|
if (*kpts_size == 0) {
|
||||||
|
return kpts;
|
||||||
|
}
|
||||||
|
|
||||||
// compute integral image
|
// compute integral image
|
||||||
|
i_image_t i_image;
|
||||||
imlib_integral_image_alloc(&i_image, image->w, image->h);
|
imlib_integral_image_alloc(&i_image, image->w, image->h);
|
||||||
imlib_integral_image(image, &i_image);
|
imlib_integral_image(image, &i_image);
|
||||||
|
|
||||||
for (size_t k=kpts_size; k--;) {
|
for (size_t k=*kpts_size; k--;) {
|
||||||
kpts[k].desc=desc=xalloc0(64);
|
kpts[k].desc=desc=xalloc0(64);
|
||||||
|
|
||||||
// estimate orientation (gradient)
|
// estimate orientation (gradient)
|
||||||
if (orient_normalized) {
|
if (normalized) {
|
||||||
thetaIdx = 0; // assign 0° to all kpts
|
thetaIdx = 0; // assign 0° to all kpts
|
||||||
kpts[k].angle = 0.0f;
|
kpts[k].angle = 0.0f;
|
||||||
} else {
|
} else {
|
||||||
@ -303,6 +309,8 @@ void freak_find_keypoints(image_t *image, kp_t *kpts, int kpts_size, bool orient
|
|||||||
}
|
}
|
||||||
|
|
||||||
imlib_integral_image_free(&i_image);
|
imlib_integral_image_free(&i_image);
|
||||||
|
|
||||||
|
return kpts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t *freak_match_keypoints(kp_t *kpts1, int kpts1_size, kp_t *kpts2, int kpts2_size, int t)
|
int16_t *freak_match_keypoints(kp_t *kpts1, int kpts1_size, kp_t *kpts2, int kpts2_size, int t)
|
||||||
|
|||||||
@ -384,7 +384,7 @@ array_t *imlib_detect_objects(struct image *image, struct cascade *cascade, stru
|
|||||||
|
|
||||||
/* FAST/FREAK Feature Extractor */
|
/* FAST/FREAK Feature Extractor */
|
||||||
kp_t *fast_detect(image_t *image, int threshold, int *ret_num_corners, rectangle_t *roi);
|
kp_t *fast_detect(image_t *image, int threshold, int *ret_num_corners, rectangle_t *roi);
|
||||||
void freak_find_keypoints(image_t *image, kp_t *kpts, int kpts_size, bool orient_normalized, bool scale_normalized);
|
kp_t *freak_find_keypoints(image_t *image, bool normalized, int kpts_threshold, int *kpts_size, rectangle_t *roi);
|
||||||
int16_t *freak_match_keypoints(kp_t *kpts1, int kpts1_size, kp_t *kpts2, int kpts2_size, int threshold);
|
int16_t *freak_match_keypoints(kp_t *kpts1, int kpts1_size, kp_t *kpts2, int kpts2_size, int threshold);
|
||||||
int freak_save_descriptor(kp_t *kpts, int kpts_size, const char *path);
|
int freak_save_descriptor(kp_t *kpts, int kpts_size, const char *path);
|
||||||
int freak_load_descriptor(kp_t **kpts_out, int *kpts_size_out, const char *path);
|
int freak_load_descriptor(kp_t **kpts_out, int *kpts_size_out, const char *path);
|
||||||
|
|||||||
@ -1027,14 +1027,11 @@ static mp_obj_t py_image_find_keypoints(uint n_args, const mp_obj_t *args, mp_ma
|
|||||||
int threshold = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_threshold), 32);
|
int threshold = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_threshold), 32);
|
||||||
bool normalized = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(qstr_from_str("normalized")), false);
|
bool normalized = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(qstr_from_str("normalized")), false);
|
||||||
|
|
||||||
// Run keypoint extractor on ROI
|
|
||||||
int kpts_size = 0;
|
int kpts_size = 0;
|
||||||
kp_t *kpts = fast_detect(image, threshold, &kpts_size, &roi);
|
// Run keypoint descriptor on ROI
|
||||||
|
kp_t *kpts = freak_find_keypoints(image, normalized, threshold, &kpts_size, &roi);
|
||||||
|
|
||||||
if (kpts_size) {
|
if (kpts_size) {
|
||||||
// Run keypoint descriptor
|
|
||||||
freak_find_keypoints(image, kpts, kpts_size, normalized, normalized);
|
|
||||||
|
|
||||||
// Return keypoints MP object
|
// Return keypoints MP object
|
||||||
py_kp_obj_t * kp_obj = m_new_obj(py_kp_obj_t);
|
py_kp_obj_t * kp_obj = m_new_obj(py_kp_obj_t);
|
||||||
kp_obj->base.type = &py_kp_type;
|
kp_obj->base.type = &py_kp_type;
|
||||||
@ -1308,8 +1305,7 @@ int py_image_descriptor_from_roi(image_t *image, const char *path, rectangle_t *
|
|||||||
int threshold = 10;
|
int threshold = 10;
|
||||||
bool normalized = false;
|
bool normalized = false;
|
||||||
|
|
||||||
kpts = fast_detect(image, threshold, &kpts_size, roi);
|
kpts = freak_find_keypoints(image, normalized, threshold, &kpts_size, roi);
|
||||||
freak_find_keypoints(image, kpts, kpts_size, normalized, normalized);
|
|
||||||
|
|
||||||
printf("Save Descriptor: KPTS(%d)\n", kpts_size);
|
printf("Save Descriptor: KPTS(%d)\n", kpts_size);
|
||||||
printf("Save Descriptor: ROI(%d %d %d %d)\n", roi->x, roi->y, roi->w, roi->h);
|
printf("Save Descriptor: ROI(%d %d %d %d)\n", roi->x, roi->y, roi->w, roi->h);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user