Commit 4dc0f1b1 authored by Sarah Parker's avatar Sarah Parker

Implement global motion parameter computation

This computes global motion parameters between 2 frames by
matching corresponding points using FAST feature and then
fitting a model using RANSAC.

Change-Id: Ib6664df44090e8cfa4db9f2f9e0556931ccfe5c8
parent 162f5f79
Copyright (c) 2006, 2008 Edward Rosten
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
*Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
*Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
*Neither the name of the University of Cambridge nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This code was taken from http://www.edwardrosten.com/work/fast.html. Fast 10, 11, and 12
have been deleted.
FAST feature detectors in C Version 2.0
---------------------------------------
The files are valid C and C++ code, and have no special requirements for
compiling, and they do not depend on any libraries. Just compile them along with
the rest of your project.
To use the functions, #include "fast.h"
The corner detectors have the following prototype (where X is 9, 10, 11 or 12):
xy* fastX_detect_nonmax(const unsigned char * data, int xsize, int ysize, int stride, int threshold, int* numcorners)
Where xy is the following simple struct typedef:
typedef struct
{
int x, y;
} xy;
The image is passed in as a block of data and dimensions, and the list of
corners is returned as an array of xy structs, and an integer (numcorners)
with the number of corners returned. The data can be deallocated with free().
Nonmaximal suppression is performed on the corners. Note that the stride
is the number of bytes between rows. If your image has no padding, then this
is the same as xsize.
The detection, scoring and nonmaximal suppression are available as individual
functions. To see how to use the individual functions, see fast.c
// clang-format off
#include <stdlib.h>
#include "fast.h"
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);
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;
}
// clang-format on
// clang-format off
#ifndef FAST_H
#define FAST_H
typedef struct { int x, y; } xy;
typedef unsigned char byte;
int fast9_corner_score(const byte* p, const int pixel[], int bstart);
xy* fast9_detect(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners);
int* fast9_score(const byte* i, int stride, xy* corners, int num_corners, int b);
xy* fast9_detect_nonmax(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners);
xy* nonmax_suppression(const xy* corners, const int* scores, int num_corners, int* ret_num_nonmax);
#endif
// clang-format on
// clang-format off
/*This is mechanically generated code*/
#include <stdlib.h>
typedef struct { int x, y; } xy;
typedef unsigned char byte;
int fast9_corner_score(const byte* p, const int pixel[], int bstart)
{
int bmin = bstart;
int bmax = 255;
int b = (bmax + bmin)/2;
/*Compute the score using binary search*/
for(;;)
{
int cb = *p + b;
int c_b= *p - b;
if( p[pixel[0]] > cb)
if( p[pixel[1]] > cb)
if( p[pixel[2]] > cb)
if( p[pixel[3]] > cb)
if( p[pixel[4]] > cb)
if( p[pixel[5]] > cb)
if( p[pixel[6]] > cb)
if( p[pixel[7]] > cb)
if( p[pixel[8]] > cb)
goto is_a_corner;
else
if( p[pixel[15]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[7]] < c_b)
if( p[pixel[14]] > cb)
if( p[pixel[15]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[14]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[12]] < c_b)
if( p[pixel[13]] < c_b)
if( p[pixel[15]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[14]] > cb)
if( p[pixel[15]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[6]] < c_b)
if( p[pixel[15]] > cb)
if( p[pixel[13]] > cb)
if( p[pixel[14]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[13]] < c_b)
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[12]] < c_b)
if( p[pixel[14]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[12]] < c_b)
if( p[pixel[13]] < c_b)
if( p[pixel[14]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[13]] > cb)
if( p[pixel[14]] > cb)
if( p[pixel[15]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[13]] < c_b)
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[12]] < c_b)
if( p[pixel[14]] < c_b)
if( p[pixel[15]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[5]] < c_b)
if( p[pixel[14]] > cb)
if( p[pixel[12]] > cb)
if( p[pixel[13]] > cb)
if( p[pixel[15]] > cb)
goto is_a_corner;
else
if( p[pixel[6]] > cb)
if( p[pixel[7]] > cb)
if( p[pixel[8]] > cb)
if( p[pixel[9]] > cb)
if( p[pixel[10]] > cb)
if( p[pixel[11]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[12]] < c_b)
if( p[pixel[6]] < c_b)
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[13]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[14]] < c_b)
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[12]] < c_b)
if( p[pixel[13]] < c_b)
if( p[pixel[6]] < c_b)
goto is_a_corner;
else
if( p[pixel[15]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[6]] < c_b)
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[12]] < c_b)
if( p[pixel[13]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[12]] > cb)
if( p[pixel[13]] > cb)
if( p[pixel[14]] > cb)
if( p[pixel[15]] > cb)
goto is_a_corner;
else
if( p[pixel[6]] > cb)
if( p[pixel[7]] > cb)
if( p[pixel[8]] > cb)
if( p[pixel[9]] > cb)
if( p[pixel[10]] > cb)
if( p[pixel[11]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[12]] < c_b)
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[13]] < c_b)
if( p[pixel[14]] < c_b)
if( p[pixel[6]] < c_b)
goto is_a_corner;
else
if( p[pixel[15]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[4]] < c_b)
if( p[pixel[13]] > cb)
if( p[pixel[11]] > cb)
if( p[pixel[12]] > cb)
if( p[pixel[14]] > cb)
if( p[pixel[15]] > cb)
goto is_a_corner;
else
if( p[pixel[6]] > cb)
if( p[pixel[7]] > cb)
if( p[pixel[8]] > cb)
if( p[pixel[9]] > cb)
if( p[pixel[10]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[5]] > cb)
if( p[pixel[6]] > cb)
if( p[pixel[7]] > cb)
if( p[pixel[8]] > cb)
if( p[pixel[9]] > cb)
if( p[pixel[10]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[11]] < c_b)
if( p[pixel[5]] < c_b)
if( p[pixel[6]] < c_b)
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[12]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else if( p[pixel[13]] < c_b)
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[12]] < c_b)
if( p[pixel[6]] < c_b)
if( p[pixel[5]] < c_b)
goto is_a_corner;
else
if( p[pixel[14]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[14]] < c_b)
if( p[pixel[15]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[5]] < c_b)
if( p[pixel[6]] < c_b)
if( p[pixel[7]] < c_b)
if( p[pixel[8]] < c_b)
if( p[pixel[9]] < c_b)
if( p[pixel[10]] < c_b)
if( p[pixel[11]] < c_b)
if( p[pixel[12]] < c_b)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[11]] > cb)
if( p[pixel[12]] > cb)
if( p[pixel[13]] > cb)
if( p[pixel[14]] > cb)
if( p[pixel[15]] > cb)
goto is_a_corner;
else
if( p[pixel[6]] > cb)
if( p[pixel[7]] > cb)
if( p[pixel[8]] > cb)
if( p[pixel[9]] > cb)
if( p[pixel[10]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if( p[pixel[5]] > cb)
if( p[pixel[6]] > cb)
if( p[pixel[7]] > cb)
if( p[pixel[8]] > cb)
if( p[pixel[9]] > cb)
if( p[pixel[10]] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else