ESP32 motion
motion.c File Reference


More...

#include "motion.h"
#include <math.h>
#include <assert.h>
#include <string.h>
#include "esp_heap_caps.h"
#include "esp_log.h"

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...
 

Detailed Description


motion header

Author
Thomas Pegot
Thomas Pegot

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