KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flandmark_detector.h
Go to the documentation of this file.
1 /* =========================================================================== *
2  |
3  | Copyright (c) 1994-2011 by Kobus Barnard (author)
4  |
5  | Personal and educational use of this code is granted, provided that this
6  | header is kept intact, and that the authorship is not misrepresented, that
7  | its use is acknowledged in publications, and relevant papers are cited.
8  |
9  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10  |
11  | Please note that the code in this file has not necessarily been adequately
12  | tested. Naturally, there is no guarantee of performance, support, or fitness
13  | for any particular task. Nonetheless, I am interested in hearing about
14  | problems that you encounter.
15  |
16  | Author: Jinyan Guan
17  * =========================================================================== */
18 
19 /* $Id: flandmark_detector.h 18301 2014-11-26 19:17:13Z ksimek $ */
20 /*
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation; either version 3 of the License, or
24  * (at your option) any later version.
25  *
26  * Written (W) 2012 Michal Uricar
27  * Copyright (C) 2012 Michal Uricar
28  */
29 
30 #ifndef KJB_FLANDMARK_DETECTOR_H_
31 #define KJB_FLANDMARK_DETECTOR_H_
32 
33 #ifdef KJB_HAVE_OPENCV
34 
36 //#include <cv.h>
37 //#include <cvaux.h>
38 #include <wrap_opencv_cpp/cv.h>
39 #include <i_cpp/i_image.h>
41 
42 namespace kjb {
43 namespace flandmark {
44 // index row-order matrices
45 #define INDEX(ROW, COL, NUM_ROWS) ((COL)*(NUM_ROWS)+(ROW))
46 #define ROW(IDX, ROWS) (((IDX)-1) % (ROWS))
47 #define COL(IDX, ROWS) (((IDX)-1) / (ROWS))
48 
49 typedef struct psig_struct {
50  int * disp;
51  int ROWS, COLS;
52 } FLANDMARK_PSIG;
53 
54 typedef struct options_struct {
55  uint8_t M;
56  int * S;
57  int bw[2], bw_margin[2];
58  FLANDMARK_PSIG *PsiGS0, *PsiGS1, *PsiGS2;
59  int PSIG_ROWS[3], PSIG_COLS[3];
60 } FLANDMARK_Options;
61 
62 typedef struct lbp_struct {
63  int winSize[2];
64  uint8_t hop;
65  uint32_t *wins;
66  int WINS_ROWS, WINS_COLS;
67 } FLANDMARK_LBP;
68 
69 typedef struct data_struct {
70  FLANDMARK_LBP * lbp;
71  int imSize[2];
72  int * mapTable;
73  FLANDMARK_Options options;
74 } FLANDMARK_Data;
75 
76 typedef struct model_struct {
77  double * W;
78  int W_ROWS, W_COLS;
79  FLANDMARK_Data data;
80  uint8_t *normalizedImageFrame;
81  double *bb;
82  float *sf;
83 } FLANDMARK_Model;
84 
85 typedef struct psi_struct {
86  char * data;
87  uint32_t PSI_ROWS, PSI_COLS;
88 } FLANDMARK_PSI;
89 
90 typedef struct psi_sparse {
91  uint32_t * idxs;
92  uint32_t PSI_ROWS, PSI_COLS;
93 } FLANDMARK_PSI_SPARSE;
94 // -------------------------------------------------------------------------
95 
96 enum EError_T {
97  NO_ERR=0,
98  ERROR_M=1,
99  ERROR_BW=2,
100  ERROR_BW_MARGIN=3,
101  ERROR_W=4,
102  ERROR_DATA_IMAGES=5,
103  ERROR_DATA_MAPTABLE=6,
104  ERROR_DATA_LBP=7,
105  ERROR_DATA_OPTIONS_S=8,
106  ERROR_DATA_OPTIONS_PSIG=9,
107  UNKNOWN_ERROR=100
108 };
109 
110 // read / write structure Model from / to file procedures
111 
120 FLANDMARK_Model * flandmark_init(const char* filename);
121 
130 void flandmark_write_model(const char* filename, FLANDMARK_Model* model);
131 
141 EError_T flandmark_check_model(FLANDMARK_Model* model, FLANDMARK_Model* tst);
142 
150 void flandmark_free(FLANDMARK_Model* model);
151 
152 // getPsiMat (calls LBP features computation - liblbpfeatures from LIBOCAS)
159 void flandmark_get_psi_mat(FLANDMARK_PSI* Psi, FLANDMARK_Model* model, int lbpidx);
160 
168 void flandmark_get_psi_mat_sparse(FLANDMARK_PSI_SPARSE* Psi, FLANDMARK_Model* model, int lbpidx);
169 
170 // dot product maximization with max-index return
178 void flandmark_maximize_gdotprod(double *maximum, double *idx, const double *first, const double *second, const int *third, const int cols, const int tsize);
179 
185 int flandmark_get_normalized_image_frame(IplImage *input, const int bbox[], double *bb, uint8_t *face_img, FLANDMARK_Model *model);
186 
191 int flandmark_imcrop(IplImage *input, IplImage *output, const CvRect region);
192 
197 void flandmark_argmax(double *smax, FLANDMARK_Options *options, const int *mapTable, FLANDMARK_PSI_SPARSE *Psi_sparse, double **q, double **g);
198 
209 int flandmark_detect_base(uint8_t *face_image, FLANDMARK_Model *model, double *landmarks);
210 
217 int flandmark_detect(IplImage *img, int * bbox, FLANDMARK_Model *model, double *landmarks, int * bw_margin = 0);
218 
219 std::vector<double> flandmark_detect
220 (
221  const Image& img,
222  const Axis_aligned_rectangle_2d& box,
223  FLANDMARK_Model* model,
224  int * bw_margin = 0
225 );
226 
227 }} //namespace kjb::flandmark
228 
229 #endif /* KJB_HAVE_OPENCV */
230 #endif /* KJB_LIBFLD_DETECTOR_H_ */
disp(num2str([lambda(1, 1) lambda(2, 2)])) r
#define W(X)
Definition: Wide.h:45
Class representing an axis-aligned, 2D rectangle.
Code for a wrapper class around the C struct KJB_Image.