Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use OpenCV inbuilt filter2D instead your own.

  Mat src=imread("dst.jpg");
  Mat dst; 
  Mat kernel=(Mat_<float>(3,3)<<  1/9.0, 1/9.0, 1/9.0,\
                                  1/9.0, 1/9.0, 1/9.0,\
                                  1/9.0, 1/9.0, 1/9.0);

  filter2D(src, dst,-1, kernel,Point(-1,-1),0,BORDER_DEFAULT );

You can use OpenCV inbuilt filter2D instead your own.

  Mat src=imread("dst.jpg");
src=imread("img.jpg");
  Mat dst; 
  Mat kernel=(Mat_<float>(3,3)<<  1/9.0, 1/9.0, 1/9.0,\
                                  1/9.0, 1/9.0, 1/9.0,\
                                  1/9.0, 1/9.0, 1/9.0);

  filter2D(src, dst,-1, kernel,Point(-1,-1),0,BORDER_DEFAULT );

In your code probably you are passing 3 channel image and accessing pixel value using 'uchar', so either pass gray image or use vec3b to access pixel value.

You can use OpenCV inbuilt filter2D instead your own.

  Mat src=imread("img.jpg");
  Mat dst; 
  Mat kernel=(Mat_<float>(3,3)<<  1/9.0, 1/9.0, 1/9.0,\
                                  1/9.0, 1/9.0, 1/9.0,\
                                  1/9.0, 1/9.0, 1/9.0);

  filter2D(src, dst,-1, kernel,Point(-1,-1),0,BORDER_DEFAULT );

In As Martin Peris said in your code probably you are passing 3 channel image and accessing pixel value using 'uchar', so either pass gray image or use vec3b to access pixel value.

You can use OpenCV inbuilt filter2D instead your own.

  Mat src=imread("img.jpg");
  Mat dst; 
  Mat kernel=(Mat_<float>(3,3)<<  1/9.0, 1/9.0, 1/9.0,\
                                  1/9.0, 1/9.0, 1/9.0,\
                                  1/9.0, 1/9.0, 1/9.0);

  filter2D(src, dst,-1, kernel,Point(-1,-1),0,BORDER_DEFAULT );