1 /*
2  * GStreamer
3  * Copyright (C) 2005 Thomas Vander Stichele <thomas@apestaart.org>
4  * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
5  * Copyright (C) 2008 Michael Sheldon <mike@mikeasoft.com>
6  * Copyright (C) 2011 Stefan Sauer <ensonic@users.sf.net>
7  * Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com>
8  * Copyright (C) 2018 Nicola Murino <nicola.murino@gmail.com>
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27  *
28  * Alternatively, the contents of this file may be used under the
29  * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
30  * which case the following provisions apply instead of the ones
31  * mentioned above:
32  *
33  * This library is free software; you can redistribute it and/or
34  * modify it under the terms of the GNU Library General Public
35  * License as published by the Free Software Foundation; either
36  * version 2 of the License, or (at your option) any later version.
37  *
38  * This library is distributed in the hope that it will be useful,
39  * but WITHOUT ANY WARRANTY; without even the implied warranty of
40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
41  * Library General Public License for more details.
42  *
43  * You should have received a copy of the GNU Library General Public
44  * License along with this library; if not, write to the
45  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
46  * Boston, MA 02110-1301, USA.
47  */
48 
49 #ifndef __GST_FACE_DETECT_H__
50 #define __GST_FACE_DETECT_H__
51 
52 #include <gst/gst.h>
53 #include <gst/opencv/gstopencvvideofilter.h>
54 #include <opencv2/objdetect.hpp>
55 
56 G_BEGIN_DECLS
57 /* #defines don't like whitespacey bits */
58 #define GST_TYPE_FACE_DETECT \
59   (gst_face_detect_get_type())
60 #define GST_FACE_DETECT(obj) \
61   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FACE_DETECT,GstFaceDetect))
62 #define GST_FACE_DETECT_CLASS(klass) \
63   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FACE_DETECT,GstFaceDetectClass))
64 #define GST_IS_FACE_DETECT(obj) \
65   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FACE_DETECT))
66 #define GST_IS_FACE_DETECT_CLASS(klass) \
67   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FACE_DETECT))
68 typedef struct _GstFaceDetect GstFaceDetect;
69 typedef struct _GstFaceDetectClass GstFaceDetectClass;
70 
71 /**
72  * GstFaceDetectUpdates
73  * @GST_FACEDETECT_UPDATES_EVERY_FRAME: Send bus update messages for every frame
74  * @GST_FACEDETECT_UPDATES_ON_CHANGE: Send bus update messages on change (face detected/not detected)
75  * @GST_FACEDETECT_UPDATES_ON_FACE: Send bus update messages when a face is detected
76  * @GST_FACEDETECT_UPDATES_NONE: No bus update messages
77  *
78  * Bus messages update scheme
79  */
80 enum _GstFaceDetectUpdates {
81   GST_FACEDETECT_UPDATES_EVERY_FRAME      = 0,
82   GST_FACEDETECT_UPDATES_ON_CHANGE        = 1,
83   GST_FACEDETECT_UPDATES_ON_FACE          = 2,
84   GST_FACEDETECT_UPDATES_NONE             = 3
85 };
86 
87 struct _GstFaceDetect
88 {
89   GstOpencvVideoFilter element;
90 
91   gboolean display;
92   gboolean face_detected;
93 
94   gchar *face_profile;
95   gchar *nose_profile;
96   gchar *mouth_profile;
97   gchar *eyes_profile;
98   gdouble scale_factor;
99   gint min_neighbors;
100   gint flags;
101   gint min_size_width;
102   gint min_size_height;
103   gint min_stddev;
104   gint updates;
105 
106   cv::Mat cvGray;
107   cv::CascadeClassifier *cvFaceDetect;
108   cv::CascadeClassifier *cvNoseDetect;
109   cv::CascadeClassifier *cvMouthDetect;
110   cv::CascadeClassifier *cvEyesDetect;
111 };
112 
113 struct _GstFaceDetectClass
114 {
115   GstOpencvVideoFilterClass parent_class;
116 };
117 
118 GType gst_face_detect_get_type (void);
119 
120 gboolean gst_face_detect_plugin_init (GstPlugin * plugin);
121 
122 G_END_DECLS
123 #endif /* __GST_FACE_DETECT_H__ */
124