Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

what you want is simply:

Mat kernel = new Mat( 5,5, CvType.CV_32F, new Scalar(1.0/25));

there's a couple of things wrong with your previous approach:

  • Core.divide takes a scale factor, so if you use that, it should be: 1.0/25, not 25
  • dividing integers by something larger will lead to truncation, 1.0/25==0.0399, 1/25==0 !
  • a MatOfSomething is a 1d array, what you wanted was a 5x5 2d Matrix.

what you want is simply:

Mat kernel = new Mat( 5,5, CvType.CV_32F, new Scalar(1.0/25));

or, more complicated:

Mat kernel = Mat.ones(5,5, CvType.CV_32F);
Core.divide(1.0/25, kernel, kernel);

there's a couple of things wrong with your previous approach:

  • Core.divide takes a scale factor, so if you use that, it should be: 1.0/25, not 25
  • dividing integers by something larger will lead to truncation, 1.0/25==0.0399, 1/25==0 !
  • a MatOfSomething is a 1d array, what you wanted was a 5x5 2d Matrix.

what you want is simply:

Mat kernel = new Mat( 5,5, CvType.CV_32F, new Scalar(1.0/25));

or, more complicated:

Mat kernel = Mat.ones(5,5, CvType.CV_32F);
Core.divide(1.0/25, kernel, kernel);

there's a couple of things wrong with your previous approach:

  • Core.divide takes a scale factor, so if you use that, it should be: 1.0/25, not 2525 (yea, call it a misnomer)
  • dividing integers by something larger will lead to truncation, 1.0/25==0.0399, 1/25==0 !
  • a MatOfSomething is a 1d array, what you wanted was a 5x5 2d Matrix.