1
+ // This file is part of OpenCV project.
2
+ // It is subject to the license terms in the LICENSE file found in the top-level directory
3
+ // of this distribution and at http://opencv.org/license.html.
4
+
1
5
/*
2
- By downloading, copying, installing or using the software you agree to this
3
- license. If you do not agree to this license, do not download, install,
4
- copy or use the software.
5
- License Agreement
6
- For Open Source Computer Vision Library
7
- (3-clause BSD License)
8
- Copyright (C) 2013, OpenCV Foundation, all rights reserved.
9
- Third party copyrights are property of their respective owners.
10
- Redistribution and use in source and binary forms, with or without modification,
11
- are permitted provided that the following conditions are met:
12
- * Redistributions of source code must retain the above copyright notice,
13
- this list of conditions and the following disclaimer.
14
- * Redistributions in binary form must reproduce the above copyright notice,
15
- this list of conditions and the following disclaimer in the documentation
16
- and/or other materials provided with the distribution.
17
- * Neither the names of the copyright holders nor the names of the contributors
18
- may be used to endorse or promote products derived from this software
19
- without specific prior written permission.
20
- This software is provided by the copyright holders and contributors "as is" and
21
- any express or implied warranties, including, but not limited to, the implied
22
- warranties of merchantability and fitness for a particular purpose are
23
- disclaimed. In no event shall copyright holders or contributors be liable for
24
- any direct, indirect, incidental, special, exemplary, or consequential damages
25
- (including, but not limited to, procurement of substitute goods or services;
26
- loss of use, data, or profits; or business interruption) however caused
27
- and on any theory of liability, whether in contract, strict liability,
28
- or tort (including negligence or otherwise) arising in any way out of
29
- the use of this software, even if advised of the possibility of such damage.
30
-
31
- This file was part of GSoC Project: Facemark API for OpenCV
6
+ This file contains results of GSoC Project: Facemark API for OpenCV
32
7
Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc
33
8
Student: Laksono Kurnianggoro
34
9
Mentor: Delia Passalacqua
@@ -45,29 +20,36 @@ Mentor: Delia Passalacqua
45
20
46
21
#include " opencv2/face.hpp"
47
22
#include " opencv2/objdetect.hpp"
48
- #include " opencv2/objdetect/objdetect_c.h"
49
- #include " opencv2/imgproc/types_c.h"
23
+ #include < vector>
24
+ #include < string>
25
+
50
26
51
27
namespace cv {
52
28
namespace face {
53
29
54
30
// ! @addtogroup face
55
31
// ! @{
56
- struct CV_EXPORTS_W CParams{
32
+
33
+ typedef bool (*FN_FaceDetector)(InputArray, OutputArray, void * userData);
34
+
35
+ struct CParams {
57
36
String cascade; // !< the face detector
58
37
double scaleFactor; // !< Parameter specifying how much the image size is reduced at each image scale.
59
38
int minNeighbors; // !< Parameter specifying how many neighbors each candidate rectangle should have to retain it.
60
39
Size minSize; // !< Minimum possible object size.
61
40
Size maxSize; // !< Maximum possible object size.
62
41
63
- CParams (
42
+ CV_EXPORTS CParams (
64
43
String cascade_model,
65
44
double sf = 1.1 ,
66
45
int minN = 3 ,
67
46
Size minSz = Size(30 , 30 ),
68
47
Size maxSz = Size()
69
48
);
49
+
50
+ CascadeClassifier face_cascade;
70
51
};
52
+
71
53
/* * @brief Default face detector
72
54
This function is mainly utilized by the implementation of a Facemark Algorithm.
73
55
End users are advised to use function Facemark::getFaces which can be manually defined
@@ -76,7 +58,7 @@ and circumvented to the algorithm by Facemark::setFaceDetector.
76
58
@param image The input image to be processed.
77
59
@param faces Output of the function which represent region of interest of the detected faces.
78
60
Each face is stored in cv::Rect container.
79
- @param extra_params extra parameters
61
+ @param params detector parameters
80
62
81
63
<B>Example of usage</B>
82
64
@code
@@ -89,11 +71,7 @@ for(int j=0;j<faces.size();j++){
89
71
cv::imshow("detection", frame);
90
72
@endcode
91
73
*/
92
- /* other option: move this function inside Facemark as default face detector*/
93
- CV_EXPORTS bool getFaces ( InputArray image,
94
- OutputArray faces,
95
- void * extra_params
96
- );
74
+ CV_EXPORTS bool getFaces (InputArray image, OutputArray faces, CParams* params);
97
75
98
76
/* * @brief A utility to load list of paths to training image and annotation file.
99
77
@param imageList The specified file contains paths to the training images.
@@ -109,7 +87,6 @@ std::vector<String> images_train;
109
87
std::vector<String> landmarks_train;
110
88
loadDatasetList(imageFiles,ptsFiles,images_train,landmarks_train);
111
89
@endcode
112
-
113
90
*/
114
91
CV_EXPORTS_W bool loadDatasetList (String imageList,
115
92
String annotationList,
@@ -138,13 +115,12 @@ cv::String imageFiles = "../data/images_train.txt";
138
115
cv::String ptsFiles = "../data/points_train.txt";
139
116
std::vector<String> images;
140
117
std::vector<std::vector<Point2f> > facePoints;
141
- loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0 );
118
+ loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0f );
142
119
@endcode
143
120
*/
144
-
145
121
CV_EXPORTS_W bool loadTrainingData ( String filename , std::vector<String> & images,
146
122
OutputArray facePoints,
147
- char delim = ' ' , float offset = 0.0 );
123
+ char delim = ' ' , float offset = 0 .0f );
148
124
149
125
/* * @brief A utility to load facial landmark information from the dataset.
150
126
@@ -163,7 +139,7 @@ cv::String imageFiles = "../data/images_train.txt";
163
139
cv::String ptsFiles = "../data/points_train.txt";
164
140
std::vector<String> images;
165
141
std::vector<std::vector<Point2f> > facePoints;
166
- loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0 );
142
+ loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0f );
167
143
@endcode
168
144
169
145
example of content in the images_train.txt
@@ -182,11 +158,10 @@ example of content in the points_train.txt
182
158
/home/user/ibug/image_006.pts
183
159
@endcode
184
160
*/
185
-
186
161
CV_EXPORTS_W bool loadTrainingData ( String imageList, String groundTruth,
187
162
std::vector<String> & images,
188
163
OutputArray facePoints,
189
- float offset = 0.0 );
164
+ float offset = 0 .0f );
190
165
191
166
/* * @brief A utility to load facial landmark information from a given file.
192
167
@@ -197,7 +172,7 @@ CV_EXPORTS_W bool loadTrainingData( String imageList, String groundTruth,
197
172
<B>Example of usage</B>
198
173
@code
199
174
std::vector<Point2f> points;
200
- face::loadFacePoints("filename.txt", points, 0.0 );
175
+ face::loadFacePoints("filename.txt", points, 0.0f );
201
176
@endcode
202
177
203
178
The annotation file should follow the default format which is
@@ -213,9 +188,8 @@ n_points: 68
213
188
where n_points is the number of points considered
214
189
and each point is represented as its position in x and y.
215
190
*/
216
-
217
191
CV_EXPORTS_W bool loadFacePoints ( String filename, OutputArray points,
218
- float offset = 0.0 );
192
+ float offset = 0 .0f );
219
193
220
194
/* * @brief Utility to draw the detected facial landmark points
221
195
@@ -365,40 +339,42 @@ class CV_EXPORTS_W Facemark : public virtual Algorithm
365
339
std::vector<std::vector<Point2f> > landmarks;
366
340
facemark->fit(image, faces, landmarks);
367
341
@endcode
342
+
343
+ TODO remove "config" from here
368
344
*/
369
- virtual bool fit ( InputArray image,\
370
- InputArray faces,\
371
- InputOutputArray landmarks,\
345
+ virtual bool fit ( InputArray image,
346
+ InputArray faces,
347
+ InputOutputArray landmarks,
372
348
void * config = 0 )=0;
373
349
374
350
/* * @brief Set a user defined face detector for the Facemark algorithm.
375
- @param f The user defined face detector function
351
+ @param detector The user defined face detector function
352
+ @param userData Detector parameters
353
+
376
354
<B>Example of usage</B>
377
355
@code
378
- facemark->setFaceDetector(myDetector);
356
+ MyDetectorParameters detectorParameters(...);
357
+ facemark->setFaceDetector(myDetector, &detectorParameters);
379
358
@endcode
380
359
381
360
Example of a user defined face detector
382
361
@code
383
- bool myDetector( InputArray image, OutputArray ROIs ){
384
- std::vector<Rect> & faces = *(std::vector<Rect>*) ROIs.getObj();
385
- faces.clear();
386
-
387
- Mat img = image.getMat();
388
-
362
+ bool myDetector( InputArray image, OutputArray faces, void* userData)
363
+ {
364
+ MyDetectorParameters* params = (MyDetectorParameters*)userData;
389
365
// -------- do something --------
390
366
}
391
367
@endcode
368
+
369
+ TODO Lifetime of detector parameters is uncontrolled. Rework interface design to "Ptr<FaceDetector>".
392
370
*/
393
- virtual bool setFaceDetector (bool (*f)(InputArray , OutputArray, void * ) )=0;
371
+ virtual bool setFaceDetector (FN_FaceDetector detector, void * userData = 0 )=0;
394
372
395
373
/* * @brief Detect faces from a given image using default or user defined face detector.
396
374
Some Algorithm might not provide a default face detector.
397
375
398
376
@param image Input image.
399
- @param faces Output of the function which represent region of interest of the detected faces.
400
- Each face is stored in cv::Rect container.
401
- @param extra_params Optional extra-parameters for the face detector function.
377
+ @param faces Output of the function which represent region of interest of the detected faces. Each face is stored in cv::Rect container.
402
378
403
379
<B>Example of usage</B>
404
380
@code
@@ -409,7 +385,7 @@ class CV_EXPORTS_W Facemark : public virtual Algorithm
409
385
}
410
386
@endcode
411
387
*/
412
- virtual bool getFaces ( InputArray image , OutputArray faces, void * extra_params= 0 )=0;
388
+ virtual bool getFaces (InputArray image, OutputArray faces)=0;
413
389
414
390
/* * @brief Get data from an algorithm
415
391
@@ -427,13 +403,10 @@ class CV_EXPORTS_W Facemark : public virtual Algorithm
427
403
cout<<s0<<endl;
428
404
@endcode
429
405
*/
430
- virtual bool getData (void * items=0 )=0;
406
+ virtual bool getData (void * items=0 )=0; // FIXIT
431
407
}; /* Facemark*/
432
408
433
409
// ! @}
434
-
435
410
} /* namespace face */
436
411
} /* namespace cv */
437
-
438
-
439
412
#endif // __OPENCV_FACELANDMARK_HPP__
0 commit comments