From 09fc19b83fd515e1713175d26412bc8021a9cfbd Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Fri, 4 Jul 2014 20:55:11 -0400 Subject: [PATCH] handdetect: Use already mapped image No need to map again the image, it's already handled by the base class. --- ext/opencv/gsthanddetect.c | 39 +++++++++++++-------------------------- ext/opencv/gsthanddetect.h | 4 +--- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/ext/opencv/gsthanddetect.c b/ext/opencv/gsthanddetect.c index f112e07..1ec29aa 100644 --- a/ext/opencv/gsthanddetect.c +++ b/ext/opencv/gsthanddetect.c @@ -156,8 +156,6 @@ gst_handdetect_finalize (GObject * obj) { GstHanddetect *filter = GST_HANDDETECT (obj); - if (filter->cvImage) - cvReleaseImage (&filter->cvImage); if (filter->cvGray) cvReleaseImage (&filter->cvGray); if (filter->cvStorage) @@ -368,10 +366,6 @@ gst_handdetect_set_caps (GstOpencvVideoFilter * transform, cvReleaseImage (&filter->cvGray); filter->cvGray = cvCreateImage (cvSize (in_width, in_height), IPL_DEPTH_8U, 1); - if (filter->cvImage) - cvReleaseImage (&filter->cvImage); - filter->cvImage = - cvCreateImage (cvSize (in_width, in_height), IPL_DEPTH_8U, 3); if (!filter->cvStorage) filter->cvStorage = cvCreateMemStorage (0); @@ -392,25 +386,20 @@ gst_handdetect_transform_ip (GstOpencvVideoFilter * transform, GstBuffer * buffer, IplImage * img) { GstHanddetect *filter = GST_HANDDETECT (transform); - GstMapInfo info; CvSeq *hands; CvRect *r; GstStructure *s; GstMessage *m; int i; - buffer = gst_buffer_make_writable (buffer); - gst_buffer_map (buffer, &info, GST_MAP_READWRITE); - - filter->cvImage->imageData = (char *) info.data; - /* cvt to gray colour space for hand detect */ - cvCvtColor (filter->cvImage, filter->cvGray, CV_RGB2GRAY); - cvClearMemStorage (filter->cvStorage); - /* check detection cascades */ if (!filter->cvCascade_fist || !filter->cvCascade_palm) return GST_FLOW_OK; + /* cvt to gray colour space for hand detect */ + cvCvtColor (img, filter->cvGray, CV_RGB2GRAY); + cvClearMemStorage (filter->cvStorage); + /* detect FIST gesture fist */ hands = cvHaarDetectObjects (filter->cvGray, filter->cvCascade_fist, @@ -425,18 +414,16 @@ gst_handdetect_transform_ip (GstOpencvVideoFilter * transform, int min_distance, distance; CvRect temp_r; CvPoint c; - /* set frame buffer writable */ - if (filter->display) { - buffer = gst_buffer_make_writable (buffer); - GST_DEBUG_OBJECT (filter, "%d FIST gestures detected\n", - (int) hands->total); - } + + GST_DEBUG_OBJECT (filter, "%d FIST gestures detected\n", + (int) hands->total); + /* Go through all detected FIST gestures to get the best one * prev_r => previous hand * best_r => best hand in this frame */ /* set min_distance for init comparison */ - min_distance = filter->cvImage->width + filter->cvImage->height; + min_distance = img->width + img->height; /* Init filter->prev_r */ temp_r = cvRect (0, 0, 0, 0); if (filter->prev_r == NULL) @@ -502,7 +489,7 @@ gst_handdetect_transform_ip (GstOpencvVideoFilter * transform, center.y = cvRound ((filter->best_r->y + filter->best_r->height * 0.5)); radius = cvRound ((filter->best_r->width + filter->best_r->height) * 0.25); - cvCircle (filter->cvImage, center, radius, CV_RGB (0, 0, 200), 1, 8, 0); + cvCircle (img, center, radius, CV_RGB (0, 0, 200), 1, 8, 0); } } else { /* if NO FIST gesture, detecting PALM gesture */ @@ -529,7 +516,7 @@ gst_handdetect_transform_ip (GstOpencvVideoFilter * transform, * best_r => best hand in this frame */ /* suppose a min_distance for init comparison */ - min_distance = filter->cvImage->width + filter->cvImage->height; + min_distance = img->width + img->height; /* Init filter->prev_r */ temp_r = cvRect (0, 0, 0, 0); if (filter->prev_r == NULL) @@ -611,11 +598,11 @@ gst_handdetect_transform_ip (GstOpencvVideoFilter * transform, center.y = cvRound ((filter->best_r->y + filter->best_r->height * 0.5)); radius = cvRound ((filter->best_r->width + filter->best_r->height) * 0.25); - cvCircle (filter->cvImage, center, radius, CV_RGB (0, 0, 200), 1, 8, 0); + cvCircle (img, center, radius, CV_RGB (0, 0, 200), 1, 8, 0); } } } - gst_buffer_unmap (buffer, &info); + /* Push out the incoming buffer */ return GST_FLOW_OK; } diff --git a/ext/opencv/gsthanddetect.h b/ext/opencv/gsthanddetect.h index 85bb33c..129784f 100644 --- a/ext/opencv/gsthanddetect.h +++ b/ext/opencv/gsthanddetect.h @@ -87,10 +87,8 @@ struct _GstHanddetect guint roi_height; /* opencv - * cvImage - image from video cam, - * cvGray - cvt cvImage to gray colour + * cvGray - image to gray colour */ - IplImage *cvImage; IplImage *cvGray; CvHaarClassifierCascade *cvCascade_fist; CvHaarClassifierCascade *cvCascade_palm; -- 2.7.4