Commit 79b7d071 authored by Nicolas Dufresne's avatar Nicolas Dufresne

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
parent 63d4c895
......@@ -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;
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment