Commit d6a7a6d5 authored by Roman Donchenko's avatar Roman Donchenko

VideoCapture: copy the captured frame, to avoid dangling Mats

Previously, VideoCapture::retrieve would return a Mat that referenced
the internal IplImage. Since the latter is rewritten every time a
frame is captured, it means that if the user captures two frames in a row,
the first frame would reference nothing. Similar if a user captures a frame,
then destroys the VideoCapture instance.

Note that the other branch of the if isn't affected, since flip allocates
a new Mat.
parent c5e8a9a2
...@@ -523,7 +523,7 @@ bool VideoCapture::retrieve(Mat& image, int channel) ...@@ -523,7 +523,7 @@ bool VideoCapture::retrieve(Mat& image, int channel)
return false; return false;
} }
if(_img->origin == IPL_ORIGIN_TL) if(_img->origin == IPL_ORIGIN_TL)
image = Mat(_img); Mat(_img).copyTo(image);
else else
{ {
Mat temp(_img); Mat temp(_img);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment