ESP32 motion
motion.h
Go to the documentation of this file.
1 
6 #ifndef MOTION_H
7 #define MOTION_H
8 
9 #ifdef __cplusplus
10 extern "C"{
11 #endif
12 
13 #include <stdint.h>
14 #include <stdbool.h>
15 #include <stdlib.h>
16 
18 #define mmax(a,b) \
19  ({ __typeof__ (a) _a = (a); \
20  __typeof__ (b) _b = (b); \
21  _a > _b ? _a : _b; })
22 
24 #define mmin(a,b) \
25  ({ __typeof__ (a) _a = (a); \
26  __typeof__ (b) _b = (b); \
27  _a < _b ? _a : _b; })
28 
30 #define WINDOW 5
31 
36 #define LK_OPTICAL_FLOW_8BIT 0
37 #define LK_OPTICAL_FLOW 1
38 #define BLOCK_MATCHING_ARPS 2
39 #define BLOCK_MATCHING_EPZS 3
40 
42 typedef struct { int16_t x, y; } Vector16_t;
43 
48 typedef struct {
49  int16_t vx;
50  int16_t vy;
51  uint16_t mag2;
53 
58 typedef struct {
59  int8_t vx;
60  int8_t vy;
62 
67 typedef struct MotionEstPredictor {
68  int mvs[10][2];
69  int nb;
71 
72 
77 typedef struct MotionEstContext{
78  char name[20];
81  int method;
82  int max;
83  int width,
85  // linewidth, ///< images width * depth (= width * 3 if rgb)
93 
94  int mbSize,
97 
98  int pred_x,
101 
103 
106  uint64_t (*get_cost) (struct MotionEstContext *self, int x_mb, int y_mb, int x_mv, int y_mv);
107  bool (*motion_func) (struct MotionEstContext *self);
109 
110 void uninit(MotionEstContext *ctx);
111 
117 bool init_context(MotionEstContext *ctx);
118 
151 bool motion_estimation(MotionEstContext *ctx, uint8_t *img_prev, uint8_t *img_cur);
152 
167 uint64_t me_comp_sad(MotionEstContext *me_ctx, int x_mb, int y_mb, int x_mv, int y_mv);
168 
212 
227 bool LK_optical_flow8(const uint8_t *src1, const uint8_t *src2, uint8_t *v, int w, int h);
228 
237 
252 
266 uint8_t *motionComp(const uint8_t *imgI, const MotionVector16_t *motionVect, size_t w, size_t h,
267  size_t mbSize);
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 #endif
Vector16_t
Definition: motion.h:42
MotionEstContext::motion_func
bool(* motion_func)(struct MotionEstContext *self)
Definition: motion.h:107
MotionEstContext::b_width
b_width
blocks width
Definition: motion.h:90
MotionEstContext::mv_table
MotionVector16_t * mv_table[3]
motion vectors of current & prev
Definition: motion.h:102
uninit
void uninit(MotionEstContext *ctx)
Definition: motion.c:35
MotionEstContext::log2_mbSize
int log2_mbSize
log2 of macro block size
Definition: motion.h:95
MotionEstContext::mbSize
int mbSize
macro block size
Definition: motion.h:94
Vector16_t::y
int16_t y
Definition: motion.h:42
MotionEstContext::data_ref
uint8_t * data_ref
prev image
Definition: motion.h:80
MotionEstContext::b_height
b_height
blocks height
Definition: motion.h:91
MotionEstContext::width
int width
images width
Definition: motion.h:83
MotionEstContext
struct MotionEstContext MotionEstContext
MotionEstContext::preds
MotionEstPredictor preds[2]
predictor for EPZS ([1] : Set B, [2] : Set C)
Definition: motion.h:100
MotionEstContext::max
int max
max motion vector magĀ²
Definition: motion.h:82
MotionEstContext::pred_y
int pred_y
median predictor y in Set A
Definition: motion.h:99
MotionVector8_t::vy
int8_t vy
Definition: motion.h:60
MotionEstPredictor::nb
int nb
Definition: motion.h:69
MotionVector8_t::vx
int8_t vx
Definition: motion.h:59
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%93K...
Definition: lucas_kanade_opitcal_flow.c:47
MotionEstContext::height
int height
images height
Definition: motion.h:84
MotionVector16_t::vy
int16_t vy
Definition: motion.h:50
MotionVector16_t::mag2
uint16_t mag2
Definition: motion.h:51
MotionVector16_t
MotionVector 2D with amplitude squared (for speed)
Definition: motion.h:48
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.
Definition: lucas_kanade_opitcal_flow.c:157
MotionEstContext::name
char name[20]
Definition: motion.h:78
MotionEstContext::b_count
b_count
nb of blocks
Definition: motion.h:92
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
MotionEstPredictor
Used for EPZS algorithm.
Definition: motion.h:67
MotionVector16_t::vx
int16_t vx
Definition: motion.h:49
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 .
Definition: block_matching.c:52
MotionEstContext::data_cur
uint8_t * data_cur
current image
Definition: motion.h:79
MotionVector8_t
MotionVector 2D 8bit.
Definition: motion.h:58
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
Definition: motion.c:161
MotionEstContext::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
Definition: motion.h:106
motionEstARPS
bool motionEstARPS(MotionEstContext *)
Perform Adaptive Rood Pattern Search algorithm.
Definition: block_matching.c:95
init_context
bool init_context(MotionEstContext *ctx)
Init & allocate context ctx accordingly to the method used.
Definition: motion.c:62
motionEstEPZS
bool motionEstEPZS(MotionEstContext *)
Enhance Predictive Zonal Search block matching algo.
Definition: epzs.c:117
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
MotionEstPredictor::mvs
int mvs[10][2]
Definition: motion.h:68
MotionEstPredictor
struct MotionEstPredictor MotionEstPredictor
MotionEstContext::search_param
int search_param
parameter p in ARPS
Definition: motion.h:96
MotionEstContext::pred_x
int pred_x
median predictor x in Set A
Definition: motion.h:98