aboutsummaryrefslogtreecommitdiff
path: root/facedet.h
diff options
context:
space:
mode:
Diffstat (limited to 'facedet.h')
-rw-r--r--facedet.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/facedet.h b/facedet.h
new file mode 100644
index 0000000..097e5aa
--- /dev/null
+++ b/facedet.h
@@ -0,0 +1,55 @@
+#ifndef FACEDET_H
+#define FACEDET_H
+
+#include <stddef.h>
+
+typedef struct facedet facedet;
+
+typedef struct {
+ float x, y, w, h;
+ float lmk[5][2];
+ float score;
+} facedet_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. */
+facedet *facedet_create(int width, int height);
+void facedet_free(facedet *m);
+
+/* The input is float32 BGR in CHW order, with values in [0, 255].
+ * The returned buffer belongs to the context. */
+float *facedet_input(facedet *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 facedet_set_rgb(facedet *m, const unsigned char *rgb, int width, int height, size_t row_bytes);
+int facedet_run(facedet *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 *facedet_map(const facedet *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 facedet_decode(const facedet *m, float score_threshold, float nms_iou,
+ facedet_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. */
+facedet *facedet_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 facedet_set_rgb.
+ * Returns 0 on success, -1 on error. All detections remain unchanged on error.
+ * m must be a context returned by facedet_create_refiner. */
+int facedet_refine(facedet *m, const unsigned char *rgb, int width, int height,
+ size_t row_bytes, facedet_detection *faces, int count);
+
+#endif