Processing math: 0%
ESP32 motion
All Data Structures Files Functions Variables Typedefs Macros Modules Pages
motion.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  Vector16_t
 
struct  MotionVector16_t
 MotionVector 2D with amplitude squared (for speed) More...
 
struct  MotionVector8_t
 MotionVector 2D 8bit. More...
 
struct  MotionEstPredictor
 Used for EPZS algorithm. More...
 
struct  MotionEstContext
 Exhaustive struct representing all parameter needed for all motion estimation type. More...
 

Macros

#define mmax(a, b)
 return max as the same type of input More...
 
#define mmin(a, b)
 return min as the same type of input More...
 
#define WINDOW   5
 convolution window size for lucas kanade More...
 
Algorithm selector
#define LK_OPTICAL_FLOW_8BIT   0
 
#define LK_OPTICAL_FLOW   1
 
#define BLOCK_MATCHING_ARPS   2
 
#define BLOCK_MATCHING_EPZS   3
 

Typedefs

typedef struct MotionEstPredictor MotionEstPredictor
 
typedef struct MotionEstContext MotionEstContext
 

Functions

void uninit (MotionEstContext *ctx)
 
bool init_context (MotionEstContext *ctx)
 Init & allocate context ctx accordingly to the method used. More...
 
bool motion_estimation (MotionEstContext *ctx, uint8_t *img_prev, uint8_t *img_cur)
 motion estimation wrapper More...
 
uint64_t me_comp_sad (MotionEstContext *me_ctx, int x_mb, int y_mb, int x_mv, int y_mv)
 omputes the Sum of Absolute Difference (SAD) for the given two blocks More...
 
uint8_tmotionComp (const uint8_t *imgI, const MotionVector16_t *motionVect, size_t w, size_t h, size_t mbSize)
 Compute motion compensated image's PSNR
. More...
 
Algorithm methods
bool LK_optical_flow (MotionEstContext *)
 Implement LK optical flow source from wiki and matlab : https://en.wikipedia.org/wiki/Lucas%E2%80%93Kanade_method
. More...
 
bool LK_optical_flow8 (const uint8_t *src1, const uint8_t *src2, uint8_t *v, int w, int h)
 Lucas Kanade optical 8 bit version. More...
 
bool motionEstARPS (MotionEstContext *)
 Perform Adaptive Rood Pattern Search algorithm. More...
 
bool motionEstEPZS (MotionEstContext *)
 Enhance Predictive Zonal Search block matching algo. More...
 

Macro Definition Documentation

◆ BLOCK_MATCHING_ARPS

#define BLOCK_MATCHING_ARPS   2

◆ BLOCK_MATCHING_EPZS

#define BLOCK_MATCHING_EPZS   3

◆ LK_OPTICAL_FLOW

#define LK_OPTICAL_FLOW   1

◆ LK_OPTICAL_FLOW_8BIT

#define LK_OPTICAL_FLOW_8BIT   0

◆ mmax

#define mmax (   a,
 
)
Value:
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })

return max as the same type of input

◆ mmin

#define mmin (   a,
 
)
Value:
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })

return min as the same type of input

◆ WINDOW

#define WINDOW   5

convolution window size for lucas kanade

Typedef Documentation

◆ MotionEstContext

◆ MotionEstPredictor

Function Documentation

◆ init_context()

bool init_context ( MotionEstContext ctx)

Init & allocate context ctx accordingly to the method used.

Parameters
ctx: motion estimation context object
Returns
big if true

◆ me_comp_sad()

uint64_t me_comp_sad ( MotionEstContext me_ctx,
int  x_mb,
int  y_mb,
int  x_mv,
int  y_mv 
)

omputes the Sum of Absolute Difference (SAD) for the given two blocks

SAD = \sum_{i=0}^{mbSize}\sum_{j=0}^{mbSize} |Cur_{ij}-Ref_{ij}|

Used as cost function for EPZS algorithm.

Todo:
Change ARPS algo such as it uses this function instead of its own
Parameters
me_ctx
x_mbcurr frame x located MB (MacroBlock)
y_mbcurr frame y located MB
x_mvprev frame x located MB
y_mvprev frame y located MB
Returns
uint64_t

◆ motion_estimation()

bool motion_estimation ( MotionEstContext ctx,
uint8_t img_prev,
uint8_t img_cur 
)

motion estimation wrapper

  • Will update ctx->name representation of the motion estimation algo used.
  • Will call motion estimation algo accordingly (motionEstARPS, motionEstEPZS, LK...)
  • current Motion Vector will be saved in mv_table[0].

Example usage :

MotionEstContext * motion(uint8_t *img_prev, uint8_t *img_cur, size_t w, size_t h)
{
// Generate a motion context configuration
MotionEstContext me_ctx = {.method = LK_OPTICAL_FLOW, // algorithm used
.width = w, .height = h // size of your image
};
// Init the context
init_context(&me_ctx);
// Start the motion estimation
if(!motion_estimation(&me_ctx, (uint8_t *)img_prev, (uint8_t *)img_cur)) {
// If motion fail return 0
printf("error");
return &me_ctx;
}
Note
Some algo will save previous motion into mv_table[1] and mv_table[2]
Parameters
ctxMotion vectors will be saved in (MotionVector16_t) ctx->mv_table[0]
Returns
Big if True

◆ uninit()

void uninit ( MotionEstContext ctx)
MotionEstContext
Exhaustive struct representing all parameter needed for all motion estimation type.
Definition: motion.h:77
uint8_t
unsigned char uint8_t
Definition: deflicker.h:10
LK_OPTICAL_FLOW
#define LK_OPTICAL_FLOW
Definition: motion.h:37
init_context
bool init_context(MotionEstContext *ctx)
Init & allocate context ctx accordingly to the method used.
Definition: motion.c:62
motion_estimation
bool motion_estimation(MotionEstContext *ctx, uint8_t *img_prev, uint8_t *img_cur)
motion estimation wrapper
Definition: motion.c:137
MotionEstContext::method
int method
motion estimation method (LK_OPTICAL_FLOW, BLOCK_MATCHING_ARPS, ...)
Definition: motion.h:81