facedetect: don't skip faces
authorStefan Sauer <ensonic@users.sf.net>
Thu, 15 Mar 2012 21:22:12 +0000 (22:22 +0100)
committerStefan Sauer <ensonic@users.sf.net>
Thu, 15 Mar 2012 21:34:45 +0000 (22:34 +0100)
Skipping faces at this point makes us lie about the num-ber of faces and also
causes leaks.

ext/opencv/gstfacedetect.c

index 01126710e9f00947d09fdc2ed7990568353b3cb9..cff13e7954faa0d17d07d8036f7c5b49f2ae1798 100644 (file)
@@ -514,8 +514,6 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
 
     for (i = 0; i < (faces ? faces->total : 0); i++) {
       CvRect *r = (CvRect *) cvGetSeqElem (faces, i);
-      GValue value = { 0 };
-      GstStructure *s;
       guint mw = filter->min_size_width / 8;
       guint mh = filter->min_size_height / 8;
       guint rnx, rny, rnw, rnh;
@@ -578,50 +576,51 @@ gst_face_detect_transform_ip (GstOpencvVideoFilter * base, GstBuffer * buf,
           i, faces->total, r->x, r->y, r->width, r->height,
           have_eyes, have_nose, have_mouth);
 
-      /* ignore 'face' where we don't fix mount/nose/eyes ? */
-      if (!(have_eyes && have_nose && have_mouth))
-        continue;
-
-      s = gst_structure_new ("face",
-          "x", G_TYPE_UINT, r->x,
-          "y", G_TYPE_UINT, r->y,
-          "width", G_TYPE_UINT, r->width,
-          "height", G_TYPE_UINT, r->height, NULL);
-      if (nose && nose->total) {
-        CvRect *sr = (CvRect *) cvGetSeqElem (nose, 0);
-        GST_LOG_OBJECT (filter, "nose/%d: x,y = %4u,%4u: w.h = %4u,%4u",
-            nose->total, rnx + sr->x, rny + sr->y, sr->width, sr->height);
-        gst_structure_set (s,
-            "nose->x", G_TYPE_UINT, rnx + sr->x,
-            "nose->y", G_TYPE_UINT, rny + sr->y,
-            "nose->width", G_TYPE_UINT, sr->width,
-            "nose->height", G_TYPE_UINT, sr->height, NULL);
-      }
-      if (mouth && mouth->total) {
-        CvRect *sr = (CvRect *) cvGetSeqElem (mouth, 0);
-        GST_LOG_OBJECT (filter, "mouth/%d: x,y = %4u,%4u: w.h = %4u,%4u",
-            mouth->total, rmx + sr->x, rmy + sr->y, sr->width, sr->height);
-        gst_structure_set (s,
-            "mouth->x", G_TYPE_UINT, rmx + sr->x,
-            "mouth->y", G_TYPE_UINT, rmy + sr->y,
-            "mouth->width", G_TYPE_UINT, sr->width,
-            "mouth->height", G_TYPE_UINT, sr->height, NULL);
-      }
-      if (eyes && eyes->total) {
-        CvRect *sr = (CvRect *) cvGetSeqElem (eyes, 0);
-        GST_LOG_OBJECT (filter, "eyes/%d: x,y = %4u,%4u: w.h = %4u,%4u",
-            eyes->total, rex + sr->x, rey + sr->y, sr->width, sr->height);
-        gst_structure_set (s,
-            "eyes->x", G_TYPE_UINT, rex + sr->x,
-            "eyes->y", G_TYPE_UINT, rey + sr->y,
-            "eyes->width", G_TYPE_UINT, sr->width,
-            "eyes->height", G_TYPE_UINT, sr->height, NULL);
-      }
+      if (msg) {
+        GValue value = { 0 };
+        GstStructure *s;
+
+        s = gst_structure_new ("face",
+            "x", G_TYPE_UINT, r->x,
+            "y", G_TYPE_UINT, r->y,
+            "width", G_TYPE_UINT, r->width,
+            "height", G_TYPE_UINT, r->height, NULL);
+        if (nose && nose->total) {
+          CvRect *sr = (CvRect *) cvGetSeqElem (nose, 0);
+          GST_LOG_OBJECT (filter, "nose/%d: x,y = %4u,%4u: w.h = %4u,%4u",
+              nose->total, rnx + sr->x, rny + sr->y, sr->width, sr->height);
+          gst_structure_set (s,
+              "nose->x", G_TYPE_UINT, rnx + sr->x,
+              "nose->y", G_TYPE_UINT, rny + sr->y,
+              "nose->width", G_TYPE_UINT, sr->width,
+              "nose->height", G_TYPE_UINT, sr->height, NULL);
+        }
+        if (mouth && mouth->total) {
+          CvRect *sr = (CvRect *) cvGetSeqElem (mouth, 0);
+          GST_LOG_OBJECT (filter, "mouth/%d: x,y = %4u,%4u: w.h = %4u,%4u",
+              mouth->total, rmx + sr->x, rmy + sr->y, sr->width, sr->height);
+          gst_structure_set (s,
+              "mouth->x", G_TYPE_UINT, rmx + sr->x,
+              "mouth->y", G_TYPE_UINT, rmy + sr->y,
+              "mouth->width", G_TYPE_UINT, sr->width,
+              "mouth->height", G_TYPE_UINT, sr->height, NULL);
+        }
+        if (eyes && eyes->total) {
+          CvRect *sr = (CvRect *) cvGetSeqElem (eyes, 0);
+          GST_LOG_OBJECT (filter, "eyes/%d: x,y = %4u,%4u: w.h = %4u,%4u",
+              eyes->total, rex + sr->x, rey + sr->y, sr->width, sr->height);
+          gst_structure_set (s,
+              "eyes->x", G_TYPE_UINT, rex + sr->x,
+              "eyes->y", G_TYPE_UINT, rey + sr->y,
+              "eyes->width", G_TYPE_UINT, sr->width,
+              "eyes->height", G_TYPE_UINT, sr->height, NULL);
+        }
 
-      g_value_init (&value, GST_TYPE_STRUCTURE);
-      gst_value_set_structure (&value, s);
-      gst_value_list_append_value (&facelist, &value);
-      g_value_unset (&value);
+        g_value_init (&value, GST_TYPE_STRUCTURE);
+        gst_value_set_structure (&value, s);
+        gst_value_list_append_value (&facelist, &value);
+        g_value_unset (&value);
+      }
 
       if (do_display) {
         CvPoint center;