Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

type wrong?

    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