This forum is disabled, please visit https://forum.opencv.org

1 | initial version |

OpenCV has very few functions that designed to work with videos. Some functions for tracking, some for optical flow, and that pretty much it. Nothing was designed for the tasks you described. But you don't really need those - functions that work with pairs of images are enough for calculation of mean or standard deviation. Here an example (i assume that you use images of unsigned chars):

Mat meanImage(Size(W,H),CV_32S,Scalar(0)); // allocate matrix of integers and set its values to zero for(i=0; i<n; i++)="" meanimage="" +="frame[i];" sum="" of="" all="" images="" meanimage="" =="" n;<="" p="">

As a result meanImage became the mean image you wanted. And since this approach access memory in effective way, it will be MUCH faster than any approach that tries to accumulate values along the time line.

StdDev can be calculated in the same way (you may use functions like pow() or multiply()).

2 | No.2 Revision |

OpenCV has very few functions that designed to work with videos. Some functions for tracking, some for optical flow, and that pretty much it. Nothing was designed for the tasks you described. But you don't really need those - functions that work with pairs of images are enough for calculation of mean or standard deviation. Here an example (i assume that you use images of unsigned chars):

~~Mat meanImage(Size(W,H),CV_32S,Scalar(0)); // allocate ~~Allocate matrix of integers and set its values to ~~zero
~~zero: Mat meanImage(Size(W,H),CV_32S,Scalar(0));
Sum of all images: for(i=0; ~~i<n; i++)="" meanimage="" +="frame[i];" sum="" of="" all="" images="" meanimage="" =="" n;<="" p="">
~~i < N; i++) meanImage += frame[i];
Divide by N to get mean: meanImage /= N;

StdDev can be calculated in the same way (you may use functions like pow() or multiply()).

~~As a result meanImage became the mean image you wanted. And since ~~Since this approach access memory in effective way, it will be MUCH faster than any approach that tries to accumulate values along the time line.

StdDev can be calculated in the same way (you may use functions like pow() or multiply()).

3 | No.3 Revision |

OpenCV has very few functions that designed to work with videos. Some functions for tracking, some for optical flow, and that pretty much it. Nothing was designed for the tasks you described. But you don't really need those - functions that work with pairs of images are enough for calculation of mean or standard deviation. Here an example (i assume that you use images of unsigned chars):

Allocate matrix of integers and set its values to zero: Mat ~~meanImage(Size(W,H),CV_32S,Scalar(0));
~~meanImage(Size(W,H),CV_32S,Scalar(0));

Sum of all images: for(i=0; i < N; i++) meanImage += ~~frame[i];
~~frame[i];

Divide by N to get mean: meanImage /= N;

StdDev can be calculated in the same way (you may use functions like pow() or multiply()).

Since this approach access memory in effective way, it will be MUCH faster than any approach that tries to accumulate values along the time line.

4 | No.4 Revision |

OpenCV has very few functions that designed to work with videos. Some functions for tracking, some for optical flow, and that pretty much it. Nothing was designed for the tasks you described. But you don't really need ~~those - ~~those, functions that work with pairs of images are enough for calculation of mean or standard deviation. Here an example (i assume that you use images of unsigned chars):

Allocate ~~matrix ~~image of integers and set ~~its ~~their values to zero: Mat meanImage(Size(W,H),CV_32S,Scalar(0));

Sum of all images: for(i=0; i < N; i++) meanImage += frame[i];

Divide by N to get mean: meanImage /= N;

StdDev can be calculated in the same way (you may use functions like pow() or multiply()).

Since this approach access memory in effective way, it will be MUCH faster than any approach that tries to accumulate values along the time line.

5 | No.5 Revision |

~~OpenCV has ~~Your program will be much faster if instead of extracting pixels from different frames (which may be very ~~few functions that designed to work with videos. Some functions for tracking, some for optical flow, and that pretty much it. Nothing was designed for the tasks you described. But you don't really need those, ~~inefficient in terms of memory access), it will use functions that work with pairs of ~~images ~~images. Those are enough for calculation of mean or standard deviation. Here an ~~example (i assume that you use images of unsigned chars):~~example:

Allocate image of integers and set their values to ~~zero: ~~zero. Use array of floats or doubles if large values are expected: Mat meanImage(Size(W,H),CV_32S,Scalar(0));

~~Sum ~~Calculate sum of all ~~images: ~~frames: for(i=0; i < N; i++) meanImage += frame[i];

Divide by N to get mean: meanImage /= N;

StdDev can be calculated in the same way (you may use functions like pow() or ~~multiply()). ~~multiply()).

Since this approach access memory in effective way, it will be MUCH faster than any approach that tries to accumulate values along the time line.

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.