How to convert a buffer of decoded data in the pipeline to a OpenCV Mat

Hi, guys.
gst-launch-1.0 rtspsrc location=rtsp://admin:extremevision201@ latency=300 ! rtph264depay ! h264parse ! omxh264dec ! videoconvert ! xvimagesink

I want to convert the buffer of the videoconvert plugin to a Opencv Mat, when copying the data of the buffer to cv::mat,get the wrong result.

cv::Mat img(720, 1280, CV_8UC3);

buffer = GST_PAD_PROBE_INFO_BUFFER (info);

buffer = gst_buffer_make_writable (buffer);

/* Making a buffer writable can fail (for example if it

  • cannot be copied and is used more than once)
    if (buffer == NULL)
    return GST_PAD_PROBE_OK;

/* Mapping a buffer can fail (non-writable) */
if (gst_buffer_map (buffer, &map, GST_MAP_WRITE)) {
ptr = (guint16 *);
memcpy(, ptr, 1080x720x3);
cv::namedWindow(“Input”, WINDOW_AUTOSIZE);
cv::imshow(“Input”, img);