average of some frames/getting error [closed]

asked 2014-01-29 06:55:25 -0600

ati gravatar image

updated 2014-01-29 09:04:22 -0600

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..

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-29 03:36:07.504566

Comments

2

You return a Mat, but the function expects float. This will collide.

Moster gravatar imageMoster ( 2014-01-29 07:32:30 -0600 )edit
1

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-01-29 07:35:07 -0600 )edit

Man didn't see that obvious mistake ...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-01-29 07:36:07 -0600 )edit
2
  • "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)

berak gravatar imageberak ( 2014-01-29 07:41:47 -0600 )edit

yes, I want it to return an empty Mat if Itimes!=1000

ati gravatar imageati ( 2014-01-29 07:51:03 -0600 )edit

I changed float to Mat...this problem solved but I got a new error...

ati gravatar imageati ( 2014-01-29 07:51:58 -0600 )edit
1

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 ...

berak gravatar imageberak ( 2014-01-29 07:54:39 -0600 )edit

Again look at this part

 cv::Mat matDistances = Mat(width, height, CV_32FC1, distances);

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-01-29 08:02:38 -0600 )edit

but this line is just for converting a float pointer to a Mat!

ati gravatar imageati ( 2014-01-29 08:04:59 -0600 )edit

@berak: You mean I should use something like buffer to store the frames?

ati gravatar imageati ( 2014-01-29 08:06:11 -0600 )edit