From d6a7a6d5030a62c6b34b2dad8c89d3de1cc74baa Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Tue, 29 Oct 2013 18:14:41 +0400 Subject: [PATCH] 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. --- modules/highgui/src/cap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/cap.cpp b/modules/highgui/src/cap.cpp index c97db18..bbfcc85 100644 --- a/modules/highgui/src/cap.cpp +++ b/modules/highgui/src/cap.cpp @@ -523,7 +523,7 @@ bool VideoCapture::retrieve(Mat& image, int channel) return false; } if(_img->origin == IPL_ORIGIN_TL) - image = Mat(_img); + Mat(_img).copyTo(image); else { Mat temp(_img); -- 2.7.4