aboutsummaryrefslogtreecommitdiff
path: root/yunet.h
blob: 44b61310db8edcd918fc98b97e081c59201af3c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef YUNET_H
#define YUNET_H

#include <stddef.h>

typedef struct yunet yunet;

typedef struct {
    float x, y, w, h;
    float lmk[5][2];
    float score;
} yunet_detection;

/* Each dimension must be a multiple of 32 between 32 and 4096.
 * A context owns mutable scratch space and is not safe for concurrent calls. */
yunet *yunet_create(int width, int height);
void yunet_free(yunet *m);

/* The input is float32 BGR in CHW order, with values in [0, 255].
 * The returned buffer belongs to the context. */
float *yunet_input(yunet *m);

/* Interleaved RGB8 is converted to BGR CHW without resizing. The right and
 * bottom padding are zero. Width and height cannot exceed the context size.
 * The RGB buffer must contain at least (height-1)*row_bytes + width*3 bytes. */
int yunet_set_rgb(yunet *m, const unsigned char *rgb, int width, int height, size_t row_bytes);
int yunet_run(yunet *m);

/* Names are cls_s, obj_s, bbox_s, kps_s, with s in {8,16,32}.
 * Maps use CHW order; cls and obj contain logits, not probabilities.
 * The buffer belongs to the context and is valid until the next input change
 * or run. NULL means that no result or no matching map is available. */
const float *yunet_map(const yunet *m, const char *name, int *channels, int *height, int *width);

/* Detector contexts only. Returns the number of detections, or -1 for
 * invalid arguments/no result. Results are sorted by score after greedy NMS, in input pixel coordinates,
 * without clipping. Landmarks: right eye, left eye, nose, right/left mouth.
 * cap limits returned detections, not candidates considered before sorting. */
int yunet_decode(const yunet *m, float score_threshold, float nms_iou,
                 yunet_detection *out, int cap);

/* Returns NULL if optional refinement weights are unavailable or allocation
 * fails. This context has a fixed 160x160 BGR input for landmark refinement. */
yunet *yunet_create_refiner(void);

/* Replaces landmarks only; boxes, scores, and ordering remain unchanged.
 * Each box defines a centered square crop with side 1.3*max(width,height).
 * Bilinear sampling uses pixel centers and zero outside the RGB image.
 * RGB dimensions are 1..4096; buffer/stride requirements match yunet_set_rgb.
 * Returns 0 on success, -1 on error. All detections remain unchanged on error.
 * m must be a context returned by yunet_create_refiner. */
int yunet_refine(yunet *m, const unsigned char *rgb, int width, int height,
                  size_t row_bytes, yunet_detection *faces, int count);

#endif