how can convert raw data frames into Mat
Hello, I have using gstreamer application to convert frames into BGR format and i can use VPE/VIDEOCONVERT in gstreamer pipeline to convert data in BGR format.
Please, check some lines of codes as below:
// Taken one variable std::atomic<cv::mat*> atomicFrame;
/* * @brief Check preroll to get a new frame using callback * https://gstreamer.freedesktop.org/doc... * @return GstFlowReturn */ GstFlowReturn new_preroll(GstAppSink /appsink/, gpointer /data/) { return GST_FLOW_OK; }
/* * @brief This is a callback that get a new frame when a preroll exist * * @Param appsink * @return GstFlowReturn */ GstFlowReturn new_sample(GstAppSink *appsink, gpointer /data*/) { static int framecount = 0;
// Get caps and frame
GstSample *sample = gst_app_sink_pull_sample(appsink);
GstCaps *caps = gst_sample_get_caps(sample);
GstBuffer *buffer = gst_sample_get_buffer(sample);
GstStructure *structure = gst_caps_get_structure(caps, 0);
const int width = g_value_get_int(gst_structure_get_value(structure, "width"));
const int height = g_value_get_int(gst_structure_get_value(structure, "height"));
// Print dot every 30 frames
if(!(framecount%30)) {
g_print(".");
}
// Show caps on first frame
if(!framecount) {
g_print("caps: %s\n", gst_caps_to_string(caps));
}
framecount++;
// Get frame data
#ifdef FACE_DETECTION
GstMapInfo map;
gst_buffer_map(buffer, &map, GST_MAP_READ);
// Convert gstreamer data to OpenCV Mat
cv::Mat* prevFrame;
prevFrame = atomicFrame.exchange(new cv::Mat(cv::Size(width, height), CV_8UC3, (char*)map.data, cv::Mat::AUTO_STEP));
if(prevFrame)
{
cv::Mat picBGR;
//cv::cvtColor(prevFrame, prevFrame, COLOR_YUV2BGR_YV12);
delete prevFrame;
}
gst_buffer_unmap(buffer, &map);
#endif
gst_sample_unref(sample);
return GST_FLOW_OK;
}
If we use videoconvert in gstreamer pipeline, all frames can convert into Mat(atomicFrame.exchange) properly and we can see it on display. But when use VPE in gstreamer pipeline, i got "segmentation fault" when application try to convert frame data into Mat(atomicFrame.exchange).
So, what should be wrong in this function?.
Regards, Kishan Patel.