summaryrefslogtreecommitdiff
path: root/tests/examples
diff options
context:
space:
mode:
authorLuis de Bethencourt <luis@debethencourt.com>2015-08-10 16:51:17 +0100
committerLuis de Bethencourt <luis@debethencourt.com>2015-08-10 18:58:55 +0100
commit53a9374eb559b0e7e245a615ed23bb4c83022b6a (patch)
tree004e8497aec3f43b9d3c215c2a58059f39d9544a /tests/examples
parentb7777b91812c58dc5f8a365c1e13b3de7116ead4 (diff)
examples: facedetect: make volume control optional
Diffstat (limited to 'tests/examples')
-rw-r--r--tests/examples/opencv/gstfacedetect_test.c69
1 files changed, 45 insertions, 24 deletions
diff --git a/tests/examples/opencv/gstfacedetect_test.c b/tests/examples/opencv/gstfacedetect_test.c
index 5b7869887..1337c2fef 100644
--- a/tests/examples/opencv/gstfacedetect_test.c
+++ b/tests/examples/opencv/gstfacedetect_test.c
@@ -29,6 +29,7 @@
GstElement *playbin, *pipeline;
GstElement *v4l2src, *videoscale, *videoconvert_in, *facedetect,
*videoconvert_out, *autovideosink;
+static gboolean ctrlvol = FALSE;
static GstBusSyncReply
bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
@@ -42,7 +43,6 @@ bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
gchar *contents;
gint i;
guint size = 0;
- gdouble volume = 0.0;
/* select msg */
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT ||
@@ -81,13 +81,6 @@ bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
if (size != 0) {
GstState state;
- faces_value = gst_value_list_get_value (value, 0);
- faces_structure = gst_value_get_structure (faces_value);
- have_mouth_y = gst_structure_has_field (faces_structure, "mouth->y");
- have_mouth_x = gst_structure_has_field (faces_structure, "mouth->x");
- have_nose_y = gst_structure_has_field (faces_structure, "nose->y");
- have_nose_x = gst_structure_has_field (faces_structure, "nose->x");
-
/* if paused, set to playing */
gst_element_get_state (GST_ELEMENT (playbin), &state, NULL,
GST_CLOCK_TIME_NONE);
@@ -95,22 +88,33 @@ bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
gst_element_set_state (GST_ELEMENT (playbin), GST_STATE_PLAYING);
}
- /* get the volume value */
- g_object_get (G_OBJECT (playbin), "volume", &volume, NULL);
-
- /* media operation - hide your mouth for down the volume of the video */
- if (have_mouth_y == 0 && have_mouth_x == 0) {
- volume = volume - 0.5;
- if (volume <= 0.5)
- volume = 0.0;
- g_object_set (G_OBJECT (playbin), "volume", volume, NULL);
- }
- /* media operation - hide your nose for up the volume of the video */
- if (have_nose_y == 0 && have_nose_x == 0) {
- volume = volume + 0.5;
- if (volume >= 9.5)
- volume = 10.0;
- g_object_set (G_OBJECT (playbin), "volume", volume, NULL);
+ if (ctrlvol) {
+ gdouble volume;
+
+ faces_value = gst_value_list_get_value (value, 0);
+ faces_structure = gst_value_get_structure (faces_value);
+ have_mouth_y = gst_structure_has_field (faces_structure, "mouth->y");
+ have_mouth_x = gst_structure_has_field (faces_structure, "mouth->x");
+ have_nose_y = gst_structure_has_field (faces_structure, "nose->y");
+ have_nose_x = gst_structure_has_field (faces_structure, "nose->x");
+
+ /* get the volume value */
+ g_object_get (G_OBJECT (playbin), "volume", &volume, NULL);
+
+ /* media operation - hide your mouth for down the volume of the video */
+ if (have_mouth_y == 0 && have_mouth_x == 0) {
+ volume = volume - 0.5;
+ if (volume <= 0.5)
+ volume = 0.0;
+ g_object_set (G_OBJECT (playbin), "volume", volume, NULL);
+ }
+ /* media operation - hide your nose for up the volume of the video */
+ if (have_nose_y == 0 && have_nose_x == 0) {
+ volume = volume + 0.5;
+ if (volume >= 9.5)
+ volume = 10.0;
+ g_object_set (G_OBJECT (playbin), "volume", volume, NULL);
+ }
}
/* if face is not detected */
} else {
@@ -130,6 +134,23 @@ main (gint argc, gchar ** argv)
GstBus *bus;
gchar *uri;
+ GOptionEntry options[] = {
+ {"control-volume", 'c', 0, G_OPTION_ARG_NONE, &ctrlvol,
+ "Control the volume by hiding the nose or mouth", NULL},
+ {NULL}
+ };
+ GOptionContext *ctx;
+ GError *err = NULL;
+
+ ctx = g_option_context_new ("<video file>\n\nfacedetect test application.");
+ g_option_context_add_main_entries (ctx, options, NULL);
+ g_option_context_add_group (ctx, gst_init_get_option_group ());
+ if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
+ g_print ("Error initializing: %s\n", err->message);
+ exit (1);
+ }
+ g_option_context_free (ctx);
+
if (argc < 2) {
fprintf (stderr, "oops, please give a file to play\n");
return -1;