type wrong?

asked 2015-01-20 04:39:11 -0500

lyw8120 gravatar image
    int r = img.rows;
int c = img.cols;
int MaxRadius=0;
int radius_p = 0;
r > c ? MaxRadius=c/2 : MaxRadius = r/2;
int MaxRadius_p = MaxRadius*MaxRadius;
Mat M(MaxRadius, 3, CV_32F, Scalar::all(0));
Mat_<float> & average_p = (Mat_<float>&) M;
    for (auto i=0; i<r; ++i)
for(auto j=0; j<c; ++j)
    {                   
        radius_p = std::pow((i-r/2),2)+std::pow((j-c/2),2);
        if(img.at<Vec2f>(i,j)[1] != 1 && radius_p <=MaxRadius_p)
        {
            average_p(radius_p, 0) += img.at<Vec2f>(i,j)[0];
            average_p(radius_p, 1) += 1;

        }
        else
        continue;
    }

I want to calculate the sum and count the number of pixels in an image. but it is very strange, I cannot count the number of pixels.

average_p(radius_p, 1) += 1;

this code did not work, I print them on the terminal, it shows a huge number, like this. 4.7146e+11 4.82613e+11 3.06337e+11 6.53814e+11 5.3117e+11 5.24466e+11 2.63879e+10 7.74249e+10

edit retag flag offensive close merge delete

Comments

you don't show, where img comes from, but yes, most probably 'type wrong'.

what are you trying to achieve ? get the mean of the img ? there's a function for that.

berak gravatar imageberak ( 2015-01-20 05:06:18 -0500 )edit

Have you thought about initializing your array?

FooBar gravatar imageFooBar ( 2015-01-20 06:17:25 -0500 )edit

img was a power spectrum image, and its type is float. I tried to calculate radial average.

yes, I initialized the array Mat M(MaxRadius, 3, CV_32F, Scalar::all(0)); Mat_<float> & average_p = (Mat_<float>&) M;

lyw8120 gravatar imagelyw8120 ( 2015-01-20 08:03:26 -0500 )edit