GStreamer Plugin using OpenCV corrupts Video and Images
Mandar Joshi
emailmandar at gmail.com
Wed Dec 30 18:12:16 PST 2015
Hello everyone,
I am writing a simple GStreamer element that converts incoming frame
into grayscale using OpenCV. The relevant part of the *tranform (*
function is
-------------------------------------------------------------------------------------------------------
GstMytest *filter = GST_MYTEST (trans);
guint bufsize;
gchar *outbuf;
GstMapInfo map;
if (gst_buffer_map (in, &map, GST_MAP_READ) == FALSE) {
g_print ("gst_buffer_map failed\n");
exit (1);
}
Mat image(Size(640,480), CV_8UC3, (char*)map.data, Mat::AUTO_STEP);
Mat edges;
cvtColor(image, edges, CV_BGR2GRAY);
unsigned char *processedData = (unsigned char*)edges.data;
imwrite("snapshot.png",edges);
gst_buffer_fill(out, 0, processedData, 640*480*1);
gst_buffer_unmap (in, &map);
return GST_FLOW_OK;
-------------------------------------------------------------------------------------------------------------
This gives me an output like this http://imgur.com/LQDEPRH
It is live video but it's corrupted somehow.
Replacing cvtColor with edges=image and setting 640*480*3 in
gst_buffer_fill gives me untouched live video. Doing processing with
cvtColor seems to be causing the problem.
The pipeline I use is
GST_PLUGIN_PATH=. gst-launch-1.0 -v videotestsrc !
video/x-raw,height=480,width=640,format=BGR ! videoconvert ! mytest !
xvimagesink sync=false
For compiling this plugin are:
g++ gstmytest.c -fPIC -c -o gstmytest.o `pkg-config --cflags
gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 opencv`
g++ -shared -o libgstmytest.so gstmytest.o `pkg-config --libs
gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 opencv`
I am using
gstreamer1-1.6.2-1.fc23.x86_64
opencv-2.4.12.3-1.fc23.x86_64
I've attached the source. Please have a look
Regards
Mandar Joshi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gstmytest.c
Type: text/x-csrc
Size: 6223 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20151231/dfc08047/attachment-0001.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gstmytest.h
Type: text/x-chdr
Size: 960 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20151231/dfc08047/attachment-0001.h>
More information about the gstreamer-devel
mailing list