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
This commit is contained in:
Nicolas Dufresne 2016-12-01 21:55:04 -05:00
parent 63d4c89560
commit 79b7d07162
2 changed files with 8 additions and 13 deletions

View file

@ -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;
}

View file

@ -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