Ask Your Question
0

Integral image wrong values

asked 2017-05-25 15:35:05 -0500

Hello,

I'm trying to use cuda::integral method but it keeps on giving me wrong values. Here's my code:

void VarianceFilter::CUDA_nextIteration(const cv::cuda::GpuMat &img)
{
    bool OpencvIntegral = true;
    if (!enabled) return;

    CUDA_release();

    if (OpencvIntegral)
    {
        cv::Mat temp, temp2, temp3;
        CUDA_integralImg = cv::cuda::GpuMat(temp.cols +1 , temp.rows+1 , CV_32SC1);
        cuda::integral(img, CUDA_integralImg);
        cuda::sqrIntegral(img, CUDA_integralImg_squared);

        img.download(temp);
        CUDA_integralImg.download(temp2);
        CUDA_integralImg_squared.download(temp3);

        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                printf(" %d", temp.at<char>(i, j));
            }
            printf("\n");
        }
        printf("\n");

        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                printf(" %d", temp2.at<char>(i, j));
            }
            printf("\n");
        }
        printf("\n");
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                printf(" %d", temp3.at<char>(i, j));
            }
            printf("\n");
        }

}

And the results that I'm receiving :

Results

As you can see the values on integralImage aren't correct. They should be counted like this:

Integral Images pattern

I will appreciate if you could point out my mistake, Thanks a lot

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-05-25 22:34:07 -0500

berak gravatar image

updated 2017-05-25 22:39:52 -0500

your for loops are all broken, rather use a simple

 cout << some_mat << endl;

to print them out, or, if those are large, a roi of it:

 cout << some_mat(Rect(0,0,10,10)) << endl;

you'll see, everything is correct, then.

if your image is of type CV_32S, you would have to use:

mat.at<int>(y,x);

to access it, not any type you like. again, writing loops like above is bad,slow, and error-prone, avoid that at all cost !

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-05-25 15:35:05 -0500

Seen: 186 times

Last updated: May 25 '17