Ask Your Question
0

why the result of filter2D function is correct on cpu and wrong on gpu??

asked 2014-02-13 05:09:36 -0600

aurelien gravatar image

updated 2014-02-13 12:09:40 -0600

The processing on the GPU give me wrong result and noise(not randomly). This is my code :

Mat ker(3,3,CV_8S);
// gain=0
ker.at<char>(0,0)=-(1+gain),ker.at<char>(0,1)=-(1+gain),ker.at<char>(0,2)=-(1+gain);
ker.at<char>(1,0)=-(1+gain),ker.at<char>(1,1)=(1+gain)*8,ker.at<char>(1,2)=-(1+gain);
ker.at<char>(2,0)=-(1+gain),ker.at<char>(2,1)=-(1+gain),ker.at<char>(2,2)=-(1+gain);
Mat test(taille,taille,CV_8UC1,125);
for(int x=0;x<taille;x++)
{
    for(int y=0;y<taille;y++)
    {
     //   test.at<uchar>(y,x)=((x%2)^(y%2))*255; //corect
            test.at<uchar>(y,x)=x+y;
    }
}
Mat res;
Mat temp;
test.copyTo((temp,test));
GpuMat resgpu(test);

test.copyTo(res,test);
filter2D(res,res,res.depth(),ker);
filter2D(resgpu,resgpu,resgpu.depth(),ker);
vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY );
compression_params.push_back(100);

imwrite("aze.jpg",test,compression_params);
imwrite("aze_filtre.jpg",res,compression_params);
imwrite("aze_filtre_gpu.jpg",Mat(resgpu),compression_params);

correct:cpu:

image description:

wrong:gpu:

image description

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2014-02-13 11:06:50 -0600

Vladislav Vinogradov gravatar image

GPU filters don't work in-place. Use different GpuMat objects for input and output parameters:

cv::gpu::GpuMat gpuinput=...;
cv::gpu::GpuMat gpuoutput;
cv::gpu::filter2D(gpuinput,gpuoutput,gpuinput.depth(),ker);
edit flag offensive delete link more
0

answered 2014-02-17 00:59:19 -0600

aurelien gravatar image

Thanks a lot ;-)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-13 05:09:36 -0600

Seen: 616 times

Last updated: Feb 17 '14