ESP32 motion
ALGO_GROUP

Functions

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

Variables

int16_t x
 
int16_t y
 
int16_t vx
 
int16_t vy
 
uint16_t mag2
 
int8_t vx
 
int8_t vy
 
int mvs [10][2]
 
int nb
 
char name [20]
 
uint8_tdata_cur
 current image More...
 
uint8_tdata_ref
 prev image More...
 
int method
 motion estimation method (LK_OPTICAL_FLOW, BLOCK_MATCHING_ARPS, ...) More...
 
int max
 max motion vector magĀ² More...
 
int width
 images width More...
 
int height
 images height More...
 
uint64_t(* get_cost )(struct MotionEstContext *self, int x_mb, int y_mb, int x_mv, int y_mv)
 pointer to motion estimation function More...
 
bool(* motion_func )(struct MotionEstContext *self)
 

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

Block Matching (EPZS, ARPS) element related

 b_width
 blocks width More...
 
 b_height
 blocks height More...
 
 b_count
 nb of blocks More...
 
int mbSize
 macro block size More...
 
int log2_mbSize
 log2 of macro block size More...
 
int search_param
 parameter p in ARPS More...
 
int pred_x
 median predictor x in Set A More...
 
int pred_y
 median predictor y in Set A More...
 
MotionEstPredictor preds [2]
 predictor for EPZS ([1] : Set B, [2] : Set C) More...
 
MotionVector16_tmv_table [3]
 motion vectors of current & prev More...
 

Detailed Description

Function Documentation

◆ LK_optical_flow()

bool LK_optical_flow ( MotionEstContext )

Implement LK optical flow source from wiki and matlab : https://en.wikipedia.org/wiki/Lucas%E2%80%93Kanade_method
.

This method is based on Taylor series resolution:

\[ I(x+\Delta x,y+\Delta y,t+\Delta t) = I(x,y,t) + \frac{\partial I}{\partial x}\,\Delta x+\frac{\partial I}{\partial y}\,\Delta y+\frac{\partial I}{\partial t} \, \Delta t+{} \]

Which can be rewritten:

\[ \frac{\partial I}{\partial x}V_x+\frac{\partial I}{\partial y}V_y+\frac{\partial I}{\partial t} = 0 \]

Lucas Kanade reorder this equation as matrix such as:

\[ A = \begin{bmatrix} I_x(q_1) & I_y(q_1) \\[10pt] I_x(q_2) & I_y(q_2) \\[10pt] \vdots & \vdots \\[10pt] I_x(q_n) & I_y(q_n) \end{bmatrix} \quad\quad\quad v = \begin{bmatrix} V_x\\[10pt] V_y \end{bmatrix} \quad\quad\quad b = \begin{bmatrix} -I_t(q_1) \\[10pt] -I_t(q_2) \\[10pt] \vdots \\[10pt] -I_t(q_n) \end{bmatrix} \]

Then the solution can be reduced as : \( A^T A v=A^T b \) or \( \mathrm{v}=(A^T A)^{-1}A^T b \)

Parameters
me_ctxMotion estimation context with me_ctx->method = 'LK_OPTICAL_FLOW'
Returns
Big if True

◆ LK_optical_flow8()

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.

Same as LK_optical_flow except the output is a uint8 table instead of vector16. Then only the squared magnitude will be saved (no vx, vy) and normalize to [0..255]

Parameters
[in]src1pointer to grayscale buffer image instant t.
[in]src2pointer to grayscale buffer image instant t+1.
[in]wwidth
[in]hheight
[out]vimage 8bit depth output of squared magnitude
Returns
Big if True

◆ motionComp()

uint8_t* motionComp ( const uint8_t imgI,
const MotionVector16_t motionVect,
size_t  w,
size_t  h,
size_t  mbSize 
)

Compute motion compensated image's PSNR
.

\[ \text{PSNR} = 10 \log_{10}\frac {(\text{peak to peak value of original data})^2}{\text{MSE}} \]

Parameters
imgP: original image of size w * h
imgComp: compensated image of size w * h
w: width of image
h: height of image
n: the peak value of possible of any pixel in the img
Returns
motion compensated image's psnr

◆ motionEstARPS()

bool motionEstARPS ( MotionEstContext )

Perform Adaptive Rood Pattern Search algorithm.

Parameters
me_ctxMotion estimation context with me_ctx->method = 'BLOCK_MATCHING_ARPS'
Returns
Big if true

◆ motionEstEPZS()

bool motionEstEPZS ( MotionEstContext )

Enhance Predictive Zonal Search block matching algo.

Implemented from article DOI: 10.15406/oajs.2017.01.00002

Note
: me_search_epzs function is taken from ffmpeg libavfilter and rearrange accordingly ffmpeg version of EPZS perform better than the one from the paper. The difference is related to the definition of predictors set A,B and C. More details in me_search_eps note.
Parameters
me_ctxMotion estimation context with me_ctx->method = 'BLOCK_MATCHING_EPZS'
Returns
big if true

Variable Documentation

◆ b_count

b_count

nb of blocks

◆ b_height

b_height

blocks height

◆ b_width

b_width

blocks width

◆ data_cur

uint8_t* data_cur

current image

◆ data_ref

uint8_t * data_ref

prev image

◆ get_cost

uint64_t(* get_cost(struct MotionEstContext *self, int x_mb, int y_mb, int x_mv, int y_mv)

pointer to motion estimation function

◆ height

int height

images height

◆ log2_mbSize

int log2_mbSize

log2 of macro block size

◆ mag2

uint16_t mag2

Squared magnitude $mag2 = vx^2 + vy^2$

◆ max

int max

max motion vector magĀ²

◆ mbSize

int mbSize

macro block size

◆ method

int method

motion estimation method (LK_OPTICAL_FLOW, BLOCK_MATCHING_ARPS, ...)

◆ motion_func

bool(* motion_func(struct MotionEstContext *self)

◆ mv_table

MotionVector16_t* mv_table[3]

motion vectors of current & prev

◆ mvs

int mvs[10][2]

table of mv predictor

◆ name

char name[20]

◆ nb

int nb

number of predictor added

◆ pred_x

int pred_x

median predictor x in Set A

◆ pred_y

int pred_y

median predictor y in Set A

◆ preds

predictor for EPZS ([1] : Set B, [2] : Set C)

◆ search_param

int search_param

parameter p in ARPS

◆ vx [1/2]

int16_t vx

guess..

◆ vx [2/2]

int8_t vx

guess..

◆ vy [1/2]

int16_t vy

guess..

◆ vy [2/2]

int8_t vy

guess..

◆ width

int width

images width

◆ x

int16_t x

◆ y

int16_t y