简体   繁体   中英

gaussian smoothing using opencv

I created the following gaussian kernel in OpenCV and comparing it with the GaussianBlur function of OpenCV. However, I'm getting a black image instead of a smooth image. Can someone throw some light on this?

Mat src, dst1,dst2;
Mat gaussiankrnl(3,3,CV_32F);
Point anchor;
double delta;
int ddepth;

anchor = Point( -1, -1 );
delta = 0;
ddepth = -1;

src = imread("coins.pgm");




gaussiankrnl.at<double>(0,0) = 1/16;
gaussiankrnl.at<double>(0,1) = 2/16;
gaussiankrnl.at<double>(0,2) = 1/16;
gaussiankrnl.at<double>(1,0) = 2/16;
gaussiankrnl.at<double>(1,1) = 4/16;
gaussiankrnl.at<double>(1,2) = 2/16;
gaussiankrnl.at<double>(2,0) = 1/16;
gaussiankrnl.at<double>(2,1) = 2/16;
gaussiankrnl.at<double>(2,2) = 1/16;


filter2D(src, dst1, ddepth , gaussiankrnl, anchor, delta, BORDER_DEFAULT );

GaussianBlur(src, dst2, Size(3,3), 1.0);

imshow("result1", dst1 );
imshow("result2", dst2 );

cvWaitKey(0);
return 0;

You are dividing integers and making zero kernel.

Change 1/16 to 1.0/16.0 as well as other values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM