summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2014-07-04 20:55:11 -0400
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2014-07-04 21:13:49 -0400
commit09fc19b83fd515e1713175d26412bc8021a9cfbd (patch)
treef6630c4b9e13f04f01e8c3edca5137a6dc094510
parentefde572cec7fc3f3e59889ed0cc6df2eafa00b79 (diff)
handdetect: Use already mapped image
No need to map again the image, it's already handled by the base class.
-rw-r--r--ext/opencv/gsthanddetect.c39
-rw-r--r--ext/opencv/gsthanddetect.h4
2 files changed, 14 insertions, 29 deletions
diff --git a/ext/opencv/gsthanddetect.c b/ext/opencv/gsthanddetect.c
index f112e070f..1ec29aa4e 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 85bb33c8c..129784f92 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;