<html><head></head><body><div style="color:#000; background-color:#fff; font-family:lucida console, sans-serif;font-size:13px"><div id="yui_3_16_0_ym19_1_1486138417230_10235"><span></span></div> <div class="qtdSeparateBR" id="yui_3_16_0_ym19_1_1486138417230_10274"><div id="yui_3_16_0_ym19_1_1486138417230_12329">Hi,</div><div id="yui_3_16_0_ym19_1_1486138417230_12802"><br></div><div id="yui_3_16_0_ym19_1_1486138417230_12592" dir="ltr">OpenCV will often convert images to grey scale before applying some algorithm on it.</div><div dir="ltr" id="yui_3_16_0_ym19_1_1486138417230_12848">The shifting is probablu due to a stride issue.</div><div dir="ltr" id="yui_3_16_0_ym19_1_1486138417230_12633"><br></div><div id="yui_3_16_0_ym19_1_1486138417230_12328"><br></div><div id="yui_3_16_0_ym19_1_1486138417230_10329">Did you look at the various opencv plugins in gst-plugins-bad ?</div><div id="yui_3_16_0_ym19_1_1486138417230_10349">It has all the code samples you need to convert cvMat to GstBuffer.</div><div><br></div><div id="yui_3_16_0_ym19_1_1486138417230_12289">I am working on a OpenCV based camera calibration/undistort plugin for gstreamer.</div><div dir="ltr" id="yui_3_16_0_ym19_1_1486138417230_12263">It is wip but can be found here : <a href="https://bitbucket.org/filnet/librepilot/src/d5713c26f2abd33920bf2cf0f816fc285939f29c/ground/gcs/src/libs/gstreamer/plugins/cameracalibration/?at=video_wip" class="enhancr2_3d568461-81f6-77f1-eca8-28e6bb1d81a0" id="yui_3_16_0_ym19_1_1486138417230_12262">filnet / LibrePilot    / source  / ground  / gcs  / src  / libs  / gstreamer  / plugins  / cameracalibration   — Bitbucket</a></div><br><div id="yui_3_16_0_ym19_1_1486138417230_12198">While working on that plugin, I also struggled with gstreamer vs opencv image formats.</div><div id="yui_3_16_0_ym19_1_1486138417230_14833" dir="ltr">What I understood is captured here : <a href="https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/gst-libs/gst/opencv/gstopencvutils.cpp" id="yui_3_16_0_ym19_1_1486138417230_14836" class="">https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/gst-libs/gst/opencv/gstopencvutils.cpp</a><br></div><div id="yui_3_16_0_ym19_1_1486138417230_14844"><br></div><div id="yui_3_16_0_ym19_1_1486138417230_14907"><br></div><br></div><div class="yahoo_quoted" id="yui_3_16_0_ym19_1_1486138417230_10271" style="display: block;"> <div style="font-family: lucida console, sans-serif; font-size: 13px;" id="yui_3_16_0_ym19_1_1486138417230_10270"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;" id="yui_3_16_0_ym19_1_1486138417230_10269"> <div dir="ltr" id="yui_3_16_0_ym19_1_1486138417230_10273"><font id="yui_3_16_0_ym19_1_1486138417230_10272" size="2" face="Arial"> Le Vendredi 3 février 2017 14h09, borisRobson <brandon.robsonclarke@paxton.co.uk> a écrit :<br></font></div>  <br><br> <div class="y_msg_container" id="yui_3_16_0_ym19_1_1486138417230_10268">Hi all<br><br>I have a project which aims to de-warp a fisheye camera, using two gstreamer<br>pipelines with opencv processing in between:<br>|   input-pipe                              |   OpenCV processing          <br>|  output-pipe<br>|  rtsprc -> decodebin -> appsink  |   gst-buf -> cvMat -> gstbuf |  appsrc<br>-> videoparse -> videoconvert ->                                                                                                 <br>xvimagesink<br><br>I can save the image from the cvMat and the result is as I expect, however<br>the image shown in xvimagesink is grayscale and constantly shifting upwards<br>and to the left. (Best I could do on description there)<br><br><<a href="http://gstreamer-devel.966125.n4.nabble.com/file/n4681701/xvimagesink.png" target="_blank" id="yui_3_16_0_ym19_1_1486138417230_12689">http://gstreamer-devel.966125.n4.nabble.com/file/n4681701/xvimagesink.png</a>> <br><<a href="http://gstreamer-devel.966125.n4.nabble.com/file/n4681701/dewarped.png" target="_blank" id="yui_3_16_0_ym19_1_1486138417230_10368">http://gstreamer-devel.966125.n4.nabble.com/file/n4681701/dewarped.png</a>> <br><br>The code where I suspect the problem is:<br>(conv is the Mat shown in the attached image)<br>//get outputize & allocate mem block<br>    gint outSize = conv.cols * conv.rows * inBpp;<br>    GstMemory *outMem = gst_allocator_alloc(NULL, outSize, NULL);    <br><br>    //assign frame data to mem<br>    GstMapInfo outMap;<br>    if(!gst_memory_map(outMem, &outMap, GST_MAP_WRITE))<br>    {<br>        g_printerr("could not map outMem\n");<br>        return;<br>    }<br><br>    memcpy(outMap.data, conv.data, outMap.size);<br><br>    gst_memory_unmap(outMem, &outMap);<br><br>    GstBuffer *outbuf;<br>    outbuf = gst_buffer_new();<br><br>    gst_buffer_insert_memory(outbuf, -1,outMem);<br><br>    GstVideoMeta *outmeta = new GstVideoMeta();<br>    outmeta = gst_buffer_add_video_meta(outbuf,GST_VIDEO_FRAME_FLAG_NONE,<br>GST_VIDEO_FORMAT_RGB, conv.cols, conv.rows );<br><br>    //set timestamp values<br>    GST_BUFFER_DURATION(outbuf) = (GstClockTime)40000000;<br>    GST_BUFFER_DTS(outbuf) = GST_CLOCK_TIME_NONE;<br>    GST_BUFFER_PTS(outbuf) = timestamp;<br>    timestamp += GST_BUFFER_DURATION(outbuf);<br><br>    GST_BUFFER_FLAG_SET(outbuf, GST_BUFFER_FLAG_LIVE);<br><br>    //ref buffer to give copy to appsrc<br>    gst_buffer_ref(outbuf);<br><br>    GstFlowReturn ret;<br>    ret = gst_app_src_push_buffer((GstAppSrc*)asrc, outbuf);<br>    if(ret != GST_FLOW_OK)<br>    {<br>        g_printerr("could not push buffer\n");<br>        g_printerr("ret enum: %i\n", ret);<br>    }<br><br>    //dec. ref count so that we can edit data on next run<br>    gst_buffer_unref(outbuf);<br><br><br>I have tried adding extra conversion stages in my out-pipe but to no effect.<br>Has anyone had experience with this before or is able to spot some rookie<br>error I'm making?<br>Thanks<br>Brandon<br><br><br>                        <br><br><br><br><br>--<br>View this message in context: <a href="http://gstreamer-devel.966125.n4.nabble.com/OpenCv-Mat-to-GstBuffer-appsrc-possible-buffer-underflow-tp4681701.html" target="_blank">http://gstreamer-devel.966125.n4.nabble.com/OpenCv-Mat-to-GstBuffer-appsrc-possible-buffer-underflow-tp4681701.html</a><br>Sent from the GStreamer-devel mailing list archive at Nabble.com.<br>_______________________________________________<br>gstreamer-devel mailing list<br><a ymailto="mailto:gstreamer-devel@lists.freedesktop.org" href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><br><a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" target="_blank">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br><br><br></div>  </div> </div>  </div></div></body></html>