From 02b20f6158a859bed3aec066d740333c3e868585 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Thu, 1 Dec 2016 21:36:13 -0500 Subject: cvsobel: Avoid extra copy of the output image Simply produce the result into the output image provided by the base class. This avoid useless copy. This also removes unchecked buffer map and ensure that GstVideoMeta is respected (for stride mostly). https://bugzilla.gnome.org/show_bug.cgi?id=775377 --- ext/opencv/gstcvsobel.cpp | 14 +++----------- ext/opencv/gstcvsobel.h | 1 - 2 files changed, 3 insertions(+), 12 deletions(-) (limited to 'ext/opencv') diff --git a/ext/opencv/gstcvsobel.cpp b/ext/opencv/gstcvsobel.cpp index a7197d9c3..8c329cbd9 100644 --- a/ext/opencv/gstcvsobel.cpp +++ b/ext/opencv/gstcvsobel.cpp @@ -116,7 +116,6 @@ gst_cv_sobel_finalize (GObject * obj) GstCvSobel *filter = GST_CV_SOBEL (obj); if (filter->cvSobel != NULL) { - cvReleaseImage (&filter->cvCSobel); cvReleaseImage (&filter->cvGray); cvReleaseImage (&filter->cvSobel); } @@ -192,12 +191,10 @@ gst_cv_sobel_set_caps (GstOpencvVideoFilter * transform, GstCvSobel *filter = GST_CV_SOBEL (transform); if (filter->cvSobel != NULL) { - cvReleaseImage (&filter->cvCSobel); cvReleaseImage (&filter->cvGray); cvReleaseImage (&filter->cvSobel); } - filter->cvCSobel = cvCreateImage (cvSize (in_width, in_height), IPL_DEPTH_8U, in_channels); filter->cvGray = cvCreateImage (cvSize (in_width, in_height), IPL_DEPTH_8U, 1); filter->cvSobel = cvCreateImage (cvSize (out_width, out_height), IPL_DEPTH_8U, 1); @@ -265,23 +262,18 @@ gst_cv_sobel_transform (GstOpencvVideoFilter * base, GstBuffer * buf, IplImage * img, GstBuffer * outbuf, IplImage * outimg) { GstCvSobel *filter = GST_CV_SOBEL (base); - GstMapInfo out_info; cvCvtColor (img, filter->cvGray, CV_RGB2GRAY); cvSobel (filter->cvGray, filter->cvSobel, filter->x_order, filter->y_order, filter->aperture_size); - cvZero (filter->cvCSobel); + cvZero (outimg); if (filter->mask) { - cvCopy (img, filter->cvCSobel, filter->cvSobel); + cvCopy (img, outimg, filter->cvSobel); } else { - cvCvtColor (filter->cvSobel, filter->cvCSobel, CV_GRAY2RGB); + cvCvtColor (filter->cvSobel, outimg, CV_GRAY2RGB); } - gst_buffer_map (outbuf, &out_info, GST_MAP_WRITE); - memcpy (out_info.data, filter->cvCSobel->imageData, - gst_buffer_get_size (outbuf)); - return GST_FLOW_OK; } diff --git a/ext/opencv/gstcvsobel.h b/ext/opencv/gstcvsobel.h index ffe78d81a..616bfd3d3 100644 --- a/ext/opencv/gstcvsobel.h +++ b/ext/opencv/gstcvsobel.h @@ -72,7 +72,6 @@ struct _GstCvSobel gint aperture_size; gboolean mask; - IplImage *cvCSobel; IplImage *cvGray; IplImage *cvSobel; }; -- cgit v1.2.3