Hi, Does anyone know how can I capture frames of a video in cpp, using opencv without memory leakage problem? [closed]

asked 2019-07-07 15:31:28 -0600

sina gravatar image

Hi, I'm using VideoCapture (OpenCV) to capture frames of a video in cpp. As I read forums, there is a memory leakage problem while reading frames in a "while" and this cannot be solved by any command like "release". Also, I read that this is solved in last version of OpenCV. But because of some problems, I'd rather to avoid changing OpenCv version and I'm looking for a command or some changes in OpenCV source code to solve this problem. Also I saw "Memory leak in every thread #9745", but I don't know how to use it to solve this problem. Any help will be appreciated, Sina.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-20 04:40:13.870471

Comments

Please show your code.

sjhalayka gravatar imagesjhalayka ( 2019-07-07 16:22:55 -0600 )edit

os ? opencv version ? code ? what did you build, and how ?

we can't help without further information !

berak gravatar imageberak ( 2019-07-07 23:58:19 -0600 )edit
1

Sorry, I didn't know I should say them.

OpenCV version: 3.4.5,(I used CMake to build it)
OS : Windows 10,
I'm using Qt-creator to make a software using c++.

#include <opencv2/opencv.hpp>
using namespace cv ; 
VideoCapture cap;
 int main() { 
string s = "A string containing Video file's Address" ;
cap.open(s) ; 
Mat frame;
int totalframenumber = int(cap.get(CV_CAP_PROP_FRAME_COUNT));
int framenumber = 1 ;
while(framenumber < totalframenumber) {
cap >> frame ;
framenumber++ ; 
frame.release(); 
} 
 cap.release() ;
}

For example when I analyze a video which is about 28 minutes with frame size 640*360, It needs about 1GB RAM. I've checked the code and this happens because of "cap >> frame;" . Thank you

sina gravatar imagesina ( 2019-07-08 02:06:06 -0600 )edit