Path: blob/master/modules/imgproc/misc/java/test/MomentsTest.java
16363 views
package org.opencv.test.imgproc;12import org.opencv.test.OpenCVTestCase;3import org.opencv.core.Core;4import org.opencv.core.Mat;5import org.opencv.core.CvType;6import org.opencv.core.Scalar;7import org.opencv.imgproc.Imgproc;8import org.opencv.imgproc.Moments;910public class MomentsTest extends OpenCVTestCase {1112Mat data;1314@Override15protected void setUp() throws Exception {16super.setUp();1718data = new Mat(3,3, CvType.CV_8UC1, new Scalar(1));19data.row(1).setTo(new Scalar(5));20}2122public void testAll() {23Moments res = Imgproc.moments(data);24assertEquals(res.m00, 21.0, EPS);25assertEquals(res.m10, 21.0, EPS);26assertEquals(res.m01, 21.0, EPS);27assertEquals(res.m20, 35.0, EPS);28assertEquals(res.m11, 21.0, EPS);29assertEquals(res.m02, 27.0, EPS);30assertEquals(res.m30, 63.0, EPS);31assertEquals(res.m21, 35.0, EPS);32assertEquals(res.m12, 27.0, EPS);33assertEquals(res.m03, 39.0, EPS);34assertEquals(res.mu20, 14.0, EPS);35assertEquals(res.mu11, 0.0, EPS);36assertEquals(res.mu02, 6.0, EPS);37assertEquals(res.mu30, 0.0, EPS);38assertEquals(res.mu21, 0.0, EPS);39assertEquals(res.mu12, 0.0, EPS);40assertEquals(res.mu03, 0.0, EPS);41assertEquals(res.nu20, 0.031746031746031744, EPS);42assertEquals(res.nu11, 0.0, EPS);43assertEquals(res.nu02, 0.013605442176870746, EPS);44assertEquals(res.nu30, 0.0, EPS);45assertEquals(res.nu21, 0.0, EPS);46assertEquals(res.nu12, 0.0, EPS);47assertEquals(res.nu03, 0.0, EPS);48}4950}515253