Added a Region of Interest feature to the fast9 corner detector

This commit is contained in:
Manos Kyriakakis
2017-06-01 13:44:16 +02:00
parent b61dba70ac
commit c5e432cb09
3 changed files with 26 additions and 8 deletions
@@ -47,13 +47,14 @@ static void fast_make_offsets(int32_t *pixel, uint16_t row_stride, uint8_t pixel
* @param[in] *num_corners reference to the amount of corners found, set by this function * @param[in] *num_corners reference to the amount of corners found, set by this function
* @param[in] *ret_corners_length the length of the array *ret_corners. * @param[in] *ret_corners_length the length of the array *ret_corners.
* @param[in] *ret_corners array which contains the corners that were detected. * @param[in] *ret_corners array which contains the corners that were detected.
* @param[in] *roi array of format [x0 y0 x1 y1] describing the region of interest in the image where the corners will be detected. If null, the whole image is used.
*/ */
void fast9_detect(struct image_t *img, uint8_t threshold, uint16_t min_dist, uint16_t x_padding, uint16_t y_padding, uint16_t *num_corners, uint16_t *ret_corners_length,struct point_t *ret_corners) { void fast9_detect(struct image_t *img, uint8_t threshold, uint16_t min_dist, uint16_t x_padding, uint16_t y_padding, uint16_t *num_corners, uint16_t *ret_corners_length,struct point_t *ret_corners, uint16_t *roi) {
uint32_t corner_cnt = 0;
uint32_t corner_cnt = 0;
int pixel[16]; int pixel[16];
int16_t i; int16_t i;
uint16_t x, y, x_min, x_max, y_min; uint16_t x, y, x_min, x_max, y_min, x_start, x_end, y_start, y_end;
uint8_t need_skip; uint8_t need_skip;
// Set the pixel size // Set the pixel size
uint8_t pixel_size = 1; uint8_t pixel_size = 1;
@@ -61,15 +62,29 @@ void fast9_detect(struct image_t *img, uint8_t threshold, uint16_t min_dist, uin
pixel_size = 2; pixel_size = 2;
} }
if (!roi){
x_start = 3 + x_padding;
y_start = 3 + y_padding;
x_end =img->w - 3 - x_padding;
y_end =img->h - 3 - y_padding;
}
else{
x_start = roi[0] > 0 ? roi[0] : 3 + x_padding;
y_start = roi[1] > 0 ? roi[1] : 3 + y_padding;
x_end = roi[2] < (img->w - 3 - x_padding) ? roi[2] : img->w - 3 - x_padding;
y_end = roi[3] < (img->h - 3 - y_padding) ? roi[3] : img->h - 3 - y_padding;
}
// Calculate the pixel offsets // Calculate the pixel offsets
fast_make_offsets(pixel, img->w, pixel_size); fast_make_offsets(pixel, img->w, pixel_size);
// Go trough all the pixels (minus the borders) // Go trough all the pixels (minus the borders and inside the requested roi)
for (y = 3 + y_padding; y < img->h - 3 - y_padding; y++) { for (y = y_start; y < y_end; y++) {
if (min_dist > 0) y_min = y - min_dist; if (min_dist > 0) y_min = y - min_dist;
for (x = 3 + x_padding; x < img->w - 3 - x_padding; x++) { for (x = x_start; x < x_end; x++) {
// First check if we aren't in range vertical (TODO: fix less intensive way) // First check if we aren't in range vertical (TODO: fix less intensive way)
if (min_dist > 0) { if (min_dist > 0) {
@@ -3678,3 +3693,4 @@ static void fast_make_offsets(int32_t *pixel, uint16_t row_stride, uint8_t pixel
pixel[14] = -2 * pixel_size + row_stride * 2 * pixel_size; pixel[14] = -2 * pixel_size + row_stride * 2 * pixel_size;
pixel[15] = -1 * pixel_size + row_stride * 3 * pixel_size; pixel[15] = -1 * pixel_size + row_stride * 3 * pixel_size;
} }
@@ -37,6 +37,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "std.h" #include "std.h"
#include "lib/vision/image.h" #include "lib/vision/image.h"
void fast9_detect(struct image_t *img, uint8_t threshold, uint16_t min_dist, uint16_t x_padding, uint16_t y_padding, uint16_t *num_corners,uint16_t *ret_corners_length,struct point_t *ret_corners); void fast9_detect(struct image_t *img, uint8_t threshold, uint16_t min_dist, uint16_t x_padding, uint16_t y_padding, uint16_t *num_corners,uint16_t *ret_corners_length,struct point_t *ret_corners, uint16_t *roi);
#endif #endif
@@ -279,10 +279,12 @@ void calc_fast9_lukas_kanade(struct opticflow_t *opticflow, struct opticflow_sta
// FAST corner detection // FAST corner detection
// TODO: There is something wrong with fast9_detect destabilizing FPS. This problem is reduced with putting min_distance // TODO: There is something wrong with fast9_detect destabilizing FPS. This problem is reduced with putting min_distance
// to 0 (see defines), however a more permanent solution should be considered // to 0 (see defines), however a more permanent solution should be considered
// last parameter (for ROI detection) set to NULL because feature management is not implemented yet.
fast9_detect(img, opticflow->fast9_threshold, opticflow->fast9_min_distance, fast9_detect(img, opticflow->fast9_threshold, opticflow->fast9_min_distance,
opticflow->fast9_padding, opticflow->fast9_padding, &result->corner_cnt, opticflow->fast9_padding, opticflow->fast9_padding, &result->corner_cnt,
&opticflow->fast9_rsize, &opticflow->fast9_rsize,
opticflow->fast9_ret_corners); opticflow->fast9_ret_corners,
0);
// Adaptive threshold // Adaptive threshold
if (opticflow->fast9_adaptive) { if (opticflow->fast9_adaptive) {