OpenCv Mat to GstBuffer -> appsrc, possible buffer underflow?

philippe renon philippe_renon at yahoo.fr
Fri Feb 3 16:32:19 UTC 2017


 Hi,
OpenCV will often convert images to grey scale before applying some algorithm on it.The shifting is probablu due to a stride issue.

Did you look at the various opencv plugins in gst-plugins-bad ?It has all the code samples you need to convert cvMat to GstBuffer.
I am working on a OpenCV based camera calibration/undistort plugin for gstreamer.It is wip but can be found here : filnet / LibrePilot / source / ground / gcs / src / libs / gstreamer / plugins / cameracalibration — Bitbucket
While working on that plugin, I also struggled with gstreamer vs opencv image formats.What I understood is captured here : https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/gst-libs/gst/opencv/gstopencvutils.cpp



    Le Vendredi 3 février 2017 14h09, borisRobson <brandon.robsonclarke at paxton.co.uk> a écrit :
 

 Hi all

I have a project which aims to de-warp a fisheye camera, using two gstreamer
pipelines with opencv processing in between:
|  input-pipe                              |  OpenCV processing          
|  output-pipe
|  rtsprc -> decodebin -> appsink  |  gst-buf -> cvMat -> gstbuf |  appsrc
-> videoparse -> videoconvert ->                                                                                                
xvimagesink

I can save the image from the cvMat and the result is as I expect, however
the image shown in xvimagesink is grayscale and constantly shifting upwards
and to the left. (Best I could do on description there)

<http://gstreamer-devel.966125.n4.nabble.com/file/n4681701/xvimagesink.png> 
<http://gstreamer-devel.966125.n4.nabble.com/file/n4681701/dewarped.png> 

The code where I suspect the problem is:
(conv is the Mat shown in the attached image)
//get outputize & allocate mem block
    gint outSize = conv.cols * conv.rows * inBpp;
    GstMemory *outMem = gst_allocator_alloc(NULL, outSize, NULL);    

    //assign frame data to mem
    GstMapInfo outMap;
    if(!gst_memory_map(outMem, &outMap, GST_MAP_WRITE))
    {
        g_printerr("could not map outMem\n");
        return;
    }

    memcpy(outMap.data, conv.data, outMap.size);

    gst_memory_unmap(outMem, &outMap);

    GstBuffer *outbuf;
    outbuf = gst_buffer_new();

    gst_buffer_insert_memory(outbuf, -1,outMem);

    GstVideoMeta *outmeta = new GstVideoMeta();
    outmeta = gst_buffer_add_video_meta(outbuf,GST_VIDEO_FRAME_FLAG_NONE,
GST_VIDEO_FORMAT_RGB, conv.cols, conv.rows );

    //set timestamp values
    GST_BUFFER_DURATION(outbuf) = (GstClockTime)40000000;
    GST_BUFFER_DTS(outbuf) = GST_CLOCK_TIME_NONE;
    GST_BUFFER_PTS(outbuf) = timestamp;
    timestamp += GST_BUFFER_DURATION(outbuf);

    GST_BUFFER_FLAG_SET(outbuf, GST_BUFFER_FLAG_LIVE);

    //ref buffer to give copy to appsrc
    gst_buffer_ref(outbuf);

    GstFlowReturn ret;
    ret = gst_app_src_push_buffer((GstAppSrc*)asrc, outbuf);
    if(ret != GST_FLOW_OK)
    {
        g_printerr("could not push buffer\n");
        g_printerr("ret enum: %i\n", ret);
    }

    //dec. ref count so that we can edit data on next run
    gst_buffer_unref(outbuf);


I have tried adding extra conversion stages in my out-pipe but to no effect.
Has anyone had experience with this before or is able to spot some rookie
error I'm making?
Thanks
Brandon


                        




--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/OpenCv-Mat-to-GstBuffer-appsrc-possible-buffer-underflow-tp4681701.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel at lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20170203/8848125d/attachment.html>


More information about the gstreamer-devel mailing list