我正在从 GstVideoFrame 中将帧提取到 Opencv Mat 中。然后在Mat中处理该帧。
custom_transform_frame_ip (GstVideoFilter *filter, GstVideoFrame *frame)
{
/*** convert GstVideoFrame to opencv format ***/
GstMapInfo map_info;
Mat cvframe;
if (!gst_buffer_map ((frame->buffer), &map_info, GST_MAP_READ)) {
gst_buffer_unmap ((frame->buffer), &map_info);
cout << "gst bufer map failed" << endl;
return GST_FLOW_ERROR;
}
cout << "frame width: "<< frame->info.width << "height: " << frame->info.height << endl;
//cvframe = Mat::zeros(/*1080*/frame->info.width, /*1920*/frame->info.height, CV_8UC3);
cvframe = cv::Mat(/*1080*/frame->info.width, /*1920*/frame->info.height, CV_8UC3, (char *)map_info.data, cv::Mat::AUTO_STEP);
/*** drawing custom polygon ROI on the Mat frame ***/
/***************************************************/
/****** convert Mat frame back to GstVideoFrame ******/
/*memcpy (map_info.data, cvframe.data, map_info.size);
gst_buffer_map(frame->buffer, &map_info, GST_MAP_WRITE);*/
/**************************************************/
gst_buffer_unmap ((frame->buffer), &map_info);
return;
}
现在我想把这个 Mat 帧放回到 GstVideoFrame 中,这样管道的进一步流程就不会受到影响。
我尝试将 Mat frame.data memcpy 到 GstVideoFrame->GstVideoInfo.Data 字段中。这不奏效。我确信这是错误的做法。
我想知道两件事:
如果我在第一部分上是正确的,即从 GstVideoFrame 提取帧到 Opencv Mat。
如何将此 Mat 框架放入与我提取它的位置相同的 GstVideoFrame 结构中。或者我可以创建另一个 GstVideoFrame 并使用处理后的 Mat 帧复制相同的数据,然后进一步传递。
事实证明我们已经就地访问了像素数据。因此无需在处理后将数据复制到某处。 GstVideoFrame通过Mat操作后就会得到处理后的数据。