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