diff options
author | Nicolas Dufresne <nicolas.dufresne@collabora.com> | 2016-12-01 21:55:04 -0500 |
---|---|---|
committer | Nicolas Dufresne <nicolas.dufresne@collabora.com> | 2016-12-01 21:56:10 -0500 |
commit | 79b7d071624d6bbab4b1d2e19df4200cf2dcffde (patch) | |
tree | 71f7422961a2baabacd615f5c6c650eef00ce3a2 /ext/opencv | |
parent | 63d4c89560d1a000059955ace56846a06afb9e46 (diff) | |
download | gstreamer-plugins-bad-79b7d071624d6bbab4b1d2e19df4200cf2dcffde.tar.gz |
edgedetect: 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
Diffstat (limited to 'ext/opencv')
-rw-r--r-- | ext/opencv/gstedgedetect.cpp | 14 | ||||
-rw-r--r-- | ext/opencv/gstedgedetect.h | 7 |
2 files changed, 8 insertions, 13 deletions
diff --git a/ext/opencv/gstedgedetect.cpp b/ext/opencv/gstedgedetect.cpp index b05aa3116..c3db49917 100644 --- a/ext/opencv/gstedgedetect.cpp +++ b/ext/opencv/gstedgedetect.cpp @@ -118,7 +118,6 @@ gst_edge_detect_finalize (GObject * obj) GstEdgeDetect *filter = GST_EDGE_DETECT (obj); if (filter->cvEdge != NULL) { - cvReleaseImage (&filter->cvCEdge); cvReleaseImage (&filter->cvGray); cvReleaseImage (&filter->cvEdge); } @@ -249,12 +248,10 @@ gst_edge_detect_set_caps (GstOpencvVideoFilter * transform, GstEdgeDetect *filter = GST_EDGE_DETECT (transform); if (filter->cvEdge != NULL) { - cvReleaseImage (&filter->cvCEdge); cvReleaseImage (&filter->cvGray); cvReleaseImage (&filter->cvEdge); } - filter->cvCEdge = cvCreateImage (cvSize (out_width, out_height), IPL_DEPTH_8U, out_channels); filter->cvGray = cvCreateImage (cvSize (in_width, in_height), IPL_DEPTH_8U, 1); filter->cvEdge = cvCreateImage (cvSize (in_width, in_height), IPL_DEPTH_8U, 1); @@ -266,23 +263,18 @@ gst_edge_detect_transform (GstOpencvVideoFilter * base, GstBuffer * buf, IplImage * img, GstBuffer * outbuf, IplImage * outimg) { GstEdgeDetect *filter = GST_EDGE_DETECT (base); - GstMapInfo out_info; cvCvtColor (img, filter->cvGray, CV_RGB2GRAY); cvCanny (filter->cvGray, filter->cvEdge, filter->threshold1, filter->threshold2, filter->aperture); - cvZero (filter->cvCEdge); + cvZero (outimg); if (filter->mask) { - cvCopy (img, filter->cvCEdge, filter->cvEdge); + cvCopy (img, outimg, filter->cvEdge); } else { - cvCvtColor (filter->cvEdge, filter->cvCEdge, CV_GRAY2RGB); + cvCvtColor (filter->cvEdge, outimg, CV_GRAY2RGB); } - gst_buffer_map (outbuf, &out_info, GST_MAP_WRITE); - memcpy (out_info.data, filter->cvCEdge->imageData, - gst_buffer_get_size (outbuf)); - return GST_FLOW_OK; } diff --git a/ext/opencv/gstedgedetect.h b/ext/opencv/gstedgedetect.h index ff6226689..af1cb8efc 100644 --- a/ext/opencv/gstedgedetect.h +++ b/ext/opencv/gstedgedetect.h @@ -71,9 +71,12 @@ struct _GstEdgeDetect gboolean mask; - int threshold1, threshold2, aperture; + int threshold1; + int threshold2; + int aperture; - IplImage *cvEdge, *cvGray, *cvCEdge; + IplImage *cvEdge; + IplImage *cvGray; }; struct _GstEdgeDetectClass |