average of some frames/getting error [closed]
I want to get average of 5 frames which their Itime are equal to 1000. What is the problem in my code? Why I get error in retur part?
After Editing:
cv::Mat Data::HighestTime(float *distances){
cv::Mat matDistances = Mat(width, height, CV_32FC1, distances);
Mat mean_distances;
if(Itime=1000){
for(int i=0; i<5; i++){
Mat mean_distances = matDistances;
mean_distances = mean_distances * (1/5);
}
}
return mean_distances;
}
I am going to use the returned value in another function like this:
void Data::Filter(){
HighestTime(float* distances);
medianBlur(mean_distances, mean_distances, ksize);
}
It complains that the mean_distances is not defined! should I define it as an argument to the function?
To get the average of 5 frames, I changed the code like this:
cv::Mat Data::HighestTime(float *distances){
cv::Mat matDistances = Mat(width, height, CV_32FC1, distances);
int NumberOfFrames=5;
cv::Mat mean_distances = Mat::zeros(width, height, CV_32FC1);
vector< Mat> matSequence;
matSequence.push_back(matDistances); //accumulate frames
if (matSequence.size() == NumberOfFrames+1)
{
vector<Mat>::iterator it;
it = matSequence.begin();
matSequence.erase(it);
matSequence = matSequence * 0.2f;
}
return matSequence;
}
Still I get error..
You return a Mat, but the function expects float. This will collide.
Please add the error by editing your question ... it tells us what is actually going wrong. As for your loop, you are not using your iterator internally, meaning you will not ever read something different from the distances parameter.
Man didn't see that obvious mistake ...
"I want to get average of 5 frames" - but what you do is 5 times the same thing . what is 'distances' after all ?
if ITimes != 1000 you return an empty Mat . is that on purpose ?
now guess, what (1/5) is. (and why it's not 0.2f)
yes, I want it to return an empty Mat if Itimes!=1000
I changed float to Mat...this problem solved but I got a new error...
still, to get an average, you have to accumulate 5 different frames first. your whole setup is broken.
throw it away and give it a fresh start ...
Again look at this part
There is no iteration based on you iterator i, which means that you will never grab a second different frame... This means that you are averaging 5 identical frames, which will result in the same frame again and makes no sense. Also, please read @berak his comments properly. 1/5 results in a pure integer division, which will yield 0. You want to replace it by 0.2f to have an actual float division and get the result you wish.
but this line is just for converting a float pointer to a Mat!
@berak: You mean I should use something like buffer to store the frames?