Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 !

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 !
}

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 !
}

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);    
}