]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/opencv_example.cpp
OpenCV: cosmetics.
[vlc] / modules / video_filter / opencv_example.cpp
index 310e16f717762bfe704ee4eb4d2e60b3013adcbd..59e1862a9e9f653a3bd351a5d7d3930f3753dbd9 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <cxcore.h>
-#include <cv.h>
-#include <highgui.h>
-
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_filter.h>
+#include <vlc_vout.h>
 #include "filter_common.h"
 #include <vlc_image.h>
 #include "filter_event_info.h"
 
+#include <cxcore.h>
+#include <cv.h>
+
 /*****************************************************************************
  * filter_sys_t : filter descriptor
  *****************************************************************************/
@@ -110,7 +110,7 @@ static int OpenFilter( vlc_object_t *p_this )
         msg_Err( p_filter, "Could not set %s", VIDEO_FILTER_EVENT_VARIABLE);
 
     //OpenCV init specific to this example
-    char* filename = config_GetPsz( p_filter, "opencv-haarcascade-file" );
+    char* filename = var_InheritString( p_filter, "opencv-haarcascade-file" );
     p_filter->p_sys->p_cascade = (CvHaarClassifierCascade*)cvLoad( filename, 0, 0, 0 );
     p_filter->p_sys->p_storage = cvCreateMemStorage(0);
     free( filename );
@@ -132,9 +132,7 @@ static void CloseFilter( vlc_object_t *p_this )
     if( p_filter->p_sys->p_storage )
         cvReleaseMemStorage( &p_filter->p_sys->p_storage );
 
-    if (NULL != p_filter->p_sys->event_info.p_region)
-        free(p_filter->p_sys->event_info.p_region);
-
+    free( p_filter->p_sys->event_info.p_region );
     free( p_sys );
 
     var_Destroy( p_filter->p_libvlc, VIDEO_FILTER_EVENT_VARIABLE);
@@ -173,7 +171,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         msg_Err( p_filter, "no image" );
         return NULL;
     }
-    if ((p_pic->format.i_chroma != VLC_FOURCC('I','4','2','0')))
+    if ((p_pic->format.i_chroma != VLC_CODEC_I420))
     {
         msg_Err( p_filter, "wrong chroma - use I420" );
         return NULL;
@@ -186,36 +184,28 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
 
     //perform face detection
     cvClearMemStorage(p_filter->p_sys->p_storage);
-    CvSeq* faces = NULL;
     if( p_filter->p_sys->p_cascade )
     {
         //we should make some of these params config variables
-        faces = cvHaarDetectObjects( p_img[0], p_filter->p_sys->p_cascade,
+        CvSeq *faces = cvHaarDetectObjects( p_img[0], p_filter->p_sys->p_cascade,
             p_filter->p_sys->p_storage, 1.15, 5, CV_HAAR_DO_CANNY_PRUNING,
                                             cvSize(20, 20) );
         //create the video_filter_region_info_t struct
-        CvRect* r;
         if (faces && (faces->total > 0))
         {
             //msg_Dbg( p_filter, "Found %d face(s)", faces->total );
-            if (NULL != p_filter->p_sys->event_info.p_region)
-            {
-                free(p_filter->p_sys->event_info.p_region);
-                p_filter->p_sys->event_info.p_region = NULL;
-            }
-            if( NULL == ( p_filter->p_sys->event_info.p_region =
-                  (video_filter_region_info_t *)malloc(faces->total*sizeof(video_filter_region_info_t))))
-            {
+            free( p_filter->p_sys->event_info.p_region );
+            p_filter->p_sys->event_info.p_region = (video_filter_region_info_t*)
+                    calloc( faces->total, sizeof(video_filter_region_info_t));
+            if( !p_filter->p_sys->event_info.p_region )
                 return NULL;
-            }
-            memset(p_filter->p_sys->event_info.p_region, 0, faces->total*sizeof(video_filter_region_info_t));
             p_filter->p_sys->event_info.i_region_size = faces->total;
         }
 
         //populate the video_filter_region_info_t struct
         for( i = 0; i < (faces ? faces->total : 0); i++ )
         {
-            r = (CvRect*)cvGetSeqElem( faces, i );
+            CvRect *r = (CvRect*)cvGetSeqElem( faces, i );
             pt1.x = r->x*scale;
             pt2.x = (r->x+r->width)*scale;
             pt1.y = r->y*scale;