Ask Your Question

Revision history [back]

Yes. You can do this by accumulating 10 Mat in a vector<mat> and then sum that result. Here is a piece of code that might be helpful.

VideoCapture cap;   //videocapture object
vector<Mat> matSeq; //where you'll accumulate frames
int numFamesToKeep = 10; //number of frames to keep
Mat frame;

cap.start(0);
while(1)
{
    cap.getFrame(frame);

    matSeq.push_back(frame.clone()); //accumulate frame

    if (matSeq.size() == numFramesToKeep + 1) //keep only 10 frames by deleting 11th
    {
        vector<Mat>::iterator it;
        it = _matSeq.begin();
        _matSeq.erase(it);
    }
}

Now that you have 10 sequential frames accumulated, summing them is pretty trivial, you can even use the + operator.

Yes. You can do this by accumulating 10 Mat in a vector<mat> and then sum that result. Here is a piece of code that might be helpful.

VideoCapture cap;   //videocapture object
vector<Mat> matSeq; //where you'll accumulate frames
int numFamesToKeep = 10; //number of frames to keep
Mat frame;

cap.start(0);
while(1)
{
    cap.getFrame(frame);

    matSeq.push_back(frame.clone()); //accumulate frame

    if (matSeq.size() == numFramesToKeep + 1) //keep only 10 frames by deleting 11th
    {
        vector<Mat>::iterator it;
        it = _matSeq.begin();
matSeq.begin();
 _matSeq.erase(it);
matSeq.erase(it);
    }
}

Now that you have 10 sequential frames accumulated, summing them is pretty trivial, you can even use the + operator.