Ask Your Question
0

N frames summation

asked 2013-12-16 11:10:45 -0600

mahsa gravatar image

updated 2013-12-16 11:11:25 -0600

Is it possible to add N frames together in Real-time by using Opencv?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-12-17 11:34:16 -0600

updated 2013-12-17 11:34:55 -0600

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.

edit flag offensive delete link more

Comments

Thanks Median, but I am talking about the real-time...Is that work in this case since I just have access to the current frame?

mahsa gravatar imagemahsa ( 2013-12-19 02:28:29 -0600 )edit

This piece of code works on real time. matSeq will always store the latest 10 frames captured by the webcam.

Pedro Batista gravatar imagePedro Batista ( 2013-12-19 04:07:42 -0600 )edit

Question Tools

Stats

Asked: 2013-12-16 11:10:45 -0600

Seen: 178 times

Last updated: Dec 17 '13