First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered Oct 22 '18

berak gravatar image

do not use pointers to cv::Mat, that's always a terrible idea (defeats the internal refcounting)

you also need to deep-copy your prevFrame, because the external gstreamer buffer will no more be valid. so:

cv::Mat prevFrame; // NO pointer !

GstMapInfo map;
gst_buffer_map(buffer, &map, GST_MAP_READ);
// Convert gstreamer data to OpenCV Mat
Mat frame = cv::Mat(cv::Size(width, height), CV_8UC3, (char*)map.data, cv::Mat::AUTO_STEP); 
// NO new !

if (!prevFame.empty()) {
    // do calculation with frame & prevFrame
}
frame.copyTo(prevFrame); // deep copy !

// no delete !
click to hide/show revision 2
No.2 Revision

do not use pointers to cv::Mat, that's always a terrible idea (defeats the internal refcounting)

you also need to deep-copy your prevFrame, because the external gstreamer buffer will no more be valid. so:

cv::Mat prevFrame; // NO pointer !

some loop {

    GstMapInfo map;
 gst_buffer_map(buffer, &map, GST_MAP_READ);
 // Convert gstreamer data to OpenCV Mat
 Mat frame = cv::Mat(cv::Size(width, height), CV_8UC3, (char*)map.data, cv::Mat::AUTO_STEP); 
 // NO new !

 if (!prevFame.empty()) {
     // do calculation with frame & prevFrame
 }
 frame.copyTo(prevFrame); // deep copy !

 // no delete !
}
click to hide/show revision 3
No.3 Revision

do not use pointers to cv::Mat, that's always a terrible idea (defeats the internal refcounting)

you also need to deep-copy your prevFrame, because the external gstreamer buffer will no more be valid. so:

cv::Mat prevFrame; // NO pointer !

some loop {

    GstMapInfo map;
    gst_buffer_map(buffer, &map, GST_MAP_READ);
    // Convert gstreamer data to OpenCV Mat
    Mat frame = cv::Mat(cv::Size(width, frame(cv::Size(width, height), CV_8UC3, (char*)map.data, cv::Mat::AUTO_STEP); 
    // NO new !

    if (!prevFame.empty()) {
        // do calculation with frame & prevFrame
    }
    frame.copyTo(prevFrame); // deep copy !

    // no delete !
}
click to hide/show revision 4
No.4 Revision

do not use pointers to cv::Mat, that's always a terrible idea (defeats the internal refcounting)

you also need to deep-copy your prevFrame, because the external gstreamer buffer will no more be valid. so:

cv::Mat prevFrame; // NO pointer !

some loop {

    GstMapInfo map;
    gst_buffer_map(buffer, &map, GST_MAP_READ);
    // Convert gstreamer data to OpenCV Mat
    Mat frame(cv::Size(width, height), CV_8UC3, (char*)map.data, cv::Mat::AUTO_STEP); 
    // NO new !

    if (!prevFame.empty()) (! prevFame.empty()) {
        // do calculation with frame & prevFrame
    }
    frame.copyTo(prevFrame); // deep copy !

    // no delete !

    gst_buffer_unmap(buffer, &map);    
}