From 43628ab86851656d6af5fb171f2216fbb99e653d Mon Sep 17 00:00:00 2001 From: Kirill Kornyakov Date: Wed, 3 Aug 2011 09:43:36 +0000 Subject: [PATCH] java: bugfix in RotatedRect, one test fixed --- .../src/org/opencv/test/OpenCVTestCase.java | 16 ++++----- .../org/opencv/test/calib3d/calib3dTest.java | 3 +- .../org/opencv/test/core/RotatedRectTest.java | 12 +++---- .../org/opencv/test/imgproc/imgprocTest.java | 36 +++++++++---------- modules/java/src/java/core+RotatedRect.java | 10 +++--- 5 files changed, 38 insertions(+), 39 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index 9cf80fa5c..0eb8069ff 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -38,6 +38,7 @@ public class OpenCVTestCase extends TestCase { // TODO: OpenCVTestCase refactorings // - rename matrices + // - create methods gray0() and create src1 explicitly // - create some masks // - use truth member everywhere @@ -82,8 +83,7 @@ public class OpenCVTestCase extends TestCase { dst = new Mat(); assertTrue(dst.empty()); - truth = new Mat(); - assertTrue(truth.empty()); + truth = null; colorBlack = new Scalar(0); @@ -96,11 +96,11 @@ public class OpenCVTestCase extends TestCase { gray128 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(128)); gray255 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); - gray_16u_256 = new Mat(matSize, matSize, CvType.CV_16U, new Scalar(256)); - gray_16s_1024 = new Mat(matSize, matSize, CvType.CV_16S, new Scalar(1024)); - grayRnd = new Mat(matSize, matSize, CvType.CV_8U); Core.randu(grayRnd, 0, 256); + + gray_16u_256 = new Mat(matSize, matSize, CvType.CV_16U, new Scalar(256)); + gray_16s_1024 = new Mat(matSize, matSize, CvType.CV_16S, new Scalar(1024)); gray0_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(0.0)); gray1_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(1.0)); @@ -112,9 +112,9 @@ public class OpenCVTestCase extends TestCase { grayRnd_32f = new Mat(matSize, matSize, CvType.CV_32F); Core.randu(grayRnd_32f, 0, 256); - gray0_32f_1d = new Mat(1, matSize, CvType.CV_32F, new Scalar(0.0)); - gray0_64f = new Mat(matSize, matSize, CvType.CV_64F, new Scalar(0.0)); + + gray0_32f_1d = new Mat(1, matSize, CvType.CV_32F, new Scalar(0.0)); gray0_64f_1d = new Mat(1, matSize, CvType.CV_64F, new Scalar(0.0)); rgba0 = new Mat(matSize, matSize, CvType.CV_8UC4, Scalar.all(0)); @@ -224,7 +224,7 @@ public class OpenCVTestCase extends TestCase { assertEquals(expected.width, actual.width); assertEquals(expected.height, actual.height); } - + public static void assertMatEqual(Mat m1, Mat m2) { compareMats(m1, m2, true); } diff --git a/modules/java/android_test/src/org/opencv/test/calib3d/calib3dTest.java b/modules/java/android_test/src/org/opencv/test/calib3d/calib3dTest.java index 6712618c3..fecf57555 100644 --- a/modules/java/android_test/src/org/opencv/test/calib3d/calib3dTest.java +++ b/modules/java/android_test/src/org/opencv/test/calib3d/calib3dTest.java @@ -245,8 +245,7 @@ public class calib3dTest extends OpenCVTestCase { List pts1 = new ArrayList(); List pts2 = new ArrayList(); - int minFundamentalMatPoints = 9; // FIXME: probably should be 8 (see - // ticket #1262) + int minFundamentalMatPoints = 9; // FIXME: probably should be 8 (see ticket #1262) for (int i = 0; i < minFundamentalMatPoints; i++) { double x = Math.random() * 100 - 50; double y = Math.random() * 100 - 50; diff --git a/modules/java/android_test/src/org/opencv/test/core/RotatedRectTest.java b/modules/java/android_test/src/org/opencv/test/core/RotatedRectTest.java index 297e34e08..1fc7fbe7b 100644 --- a/modules/java/android_test/src/org/opencv/test/core/RotatedRectTest.java +++ b/modules/java/android_test/src/org/opencv/test/core/RotatedRectTest.java @@ -141,15 +141,15 @@ public class RotatedRectTest extends OpenCVTestCase { } public void testRotatedRectDoubleArray() { - double[] vals = {1, 2, 3, 4, 5}; + double[] vals = {1.5, 2.6, 3.7, 4.2, 5.1}; RotatedRect rr = new RotatedRect(vals); assertNotNull(rr); - assertEquals(1., rr.center.x); - assertEquals(2., rr.center.y); - assertEquals(3., rr.size.width); - assertEquals(4., rr.size.height); - assertEquals(5., rr.angle); + assertEquals(1.5, rr.center.x); + assertEquals(2.6, rr.center.y); + assertEquals(3.7, rr.size.width); + assertEquals(4.2, rr.size.height); + assertEquals(5.1, rr.angle); } public void testRotatedRectPointSizeDouble() { diff --git a/modules/java/android_test/src/org/opencv/test/imgproc/imgprocTest.java b/modules/java/android_test/src/org/opencv/test/imgproc/imgprocTest.java index a941013c1..bfff46833 100644 --- a/modules/java/android_test/src/org/opencv/test/imgproc/imgprocTest.java +++ b/modules/java/android_test/src/org/opencv/test/imgproc/imgprocTest.java @@ -524,22 +524,22 @@ public class imgprocTest extends OpenCVTestCase { } public void testCornerSubPix() { - Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(128)); - - Point truthPosition = new Point(img.cols()/2, img.rows()/2); - - Rect r = new Rect(new Point(0, 0), truthPosition); - Core.rectangle(img, r.tl(), r.br(), new Scalar(0), -1/*TODO: CV_FILLED*/); - - List corners = new ArrayList(); - corners.add(new Point(truthPosition.x+1, truthPosition.y+1)); - - Size winSize = new Size(2, 2); - Size zeroZone = new Size(-1, -1); - TermCriteria criteria = new TermCriteria(2/*TODO: CV_TERMCRIT_EPS*/, 0, 0.01); - - Imgproc.cornerSubPix(img, corners, winSize, zeroZone, criteria); - assertPointEquals(truthPosition, corners.get(0), weakEPS); + Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(128)); + + Point truthPosition = new Point(img.cols() / 2, img.rows() / 2); + + Rect r = new Rect(new Point(0, 0), truthPosition); + Core.rectangle(img, r.tl(), r.br(), new Scalar(0), -1/* TODO: CV_FILLED */); + + List corners = new ArrayList(); + corners.add(new Point(truthPosition.x + 1, truthPosition.y + 1)); + + Size winSize = new Size(2, 2); + Size zeroZone = new Size(-1, -1); + TermCriteria criteria = new TermCriteria(2/* TODO: CV_TERMCRIT_EPS */, 0, 0.01); + + Imgproc.cornerSubPix(img, corners, winSize, zeroZone, criteria); + assertPointEquals(truthPosition, corners.get(0), weakEPS); } public void testCvtColorMatMatInt() { @@ -1157,11 +1157,11 @@ public class imgprocTest extends OpenCVTestCase { cameraMatrix.put(1, 0, 0, 1, 2); cameraMatrix.put(2, 0, 0, 0, 1); + distCoeffs.put(0, 0, 1.0, 3.0, 2.0, 4); + truth = new Mat(3, 3, CvType.CV_32F); truth.put(0, 0, 0, 0, 0); truth.put(1, 0, 0, 0, 0); truth.put(2, 0, 0, 3, 0); - - distCoeffs.put(0, 0, 1.0, 3.0, 2.0, 4); // TODO: No documentation for this function // Imgproc.initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize, // 5.0, m1type, truthput1, truthput2); diff --git a/modules/java/src/java/core+RotatedRect.java b/modules/java/src/java/core+RotatedRect.java index c6e43b089..c60bd2731 100644 --- a/modules/java/src/java/core+RotatedRect.java +++ b/modules/java/src/java/core+RotatedRect.java @@ -26,11 +26,11 @@ public class RotatedRect { public void set(double[] vals) { if(vals!=null) { - center.x = vals.length>0 ? (int)vals[0] : 0; - center.x = vals.length>1 ? (int)vals[1] : 0; - size.width = vals.length>2 ? (int)vals[2] : 0; - size.height = vals.length>3 ? (int)vals[3] : 0; - angle = vals.length>4 ? (int)vals[4] : 0; + center.x = vals.length>0 ? (double)vals[0] : 0; + center.y = vals.length>1 ? (double)vals[1] : 0; + size.width = vals.length>2 ? (double)vals[2] : 0; + size.height = vals.length>3 ? (double)vals[3] : 0; + angle = vals.length>4 ? (double)vals[4] : 0; } else { center.x = 0; center.x = 0;