MomentsTest.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package org.opencv.test.imgproc;
  2. import org.opencv.test.OpenCVTestCase;
  3. import org.opencv.core.Core;
  4. import org.opencv.core.Mat;
  5. import org.opencv.core.CvType;
  6. import org.opencv.core.Scalar;
  7. import org.opencv.imgproc.Imgproc;
  8. import org.opencv.imgproc.Moments;
  9. public class MomentsTest extends OpenCVTestCase {
  10. Mat data;
  11. @Override
  12. protected void setUp() throws Exception {
  13. super.setUp();
  14. data = new Mat(3,3, CvType.CV_8UC1, new Scalar(1));
  15. data.row(1).setTo(new Scalar(5));
  16. }
  17. public void testAll() {
  18. Moments res = Imgproc.moments(data);
  19. assertEquals(res.m00, 21.0, EPS);
  20. assertEquals(res.m10, 21.0, EPS);
  21. assertEquals(res.m01, 21.0, EPS);
  22. assertEquals(res.m20, 35.0, EPS);
  23. assertEquals(res.m11, 21.0, EPS);
  24. assertEquals(res.m02, 27.0, EPS);
  25. assertEquals(res.m30, 63.0, EPS);
  26. assertEquals(res.m21, 35.0, EPS);
  27. assertEquals(res.m12, 27.0, EPS);
  28. assertEquals(res.m03, 39.0, EPS);
  29. assertEquals(res.mu20, 14.0, EPS);
  30. assertEquals(res.mu11, 0.0, EPS);
  31. assertEquals(res.mu02, 6.0, EPS);
  32. assertEquals(res.mu30, 0.0, EPS);
  33. assertEquals(res.mu21, 0.0, EPS);
  34. assertEquals(res.mu12, 0.0, EPS);
  35. assertEquals(res.mu03, 0.0, EPS);
  36. assertEquals(res.nu20, 0.031746031746031744, EPS);
  37. assertEquals(res.nu11, 0.0, EPS);
  38. assertEquals(res.nu02, 0.013605442176870746, EPS);
  39. assertEquals(res.nu30, 0.0, EPS);
  40. assertEquals(res.nu21, 0.0, EPS);
  41. assertEquals(res.nu12, 0.0, EPS);
  42. assertEquals(res.nu03, 0.0, EPS);
  43. }
  44. }