fixing #1808, Java API improvements

This commit is contained in:
Andrey Pavlenko
2012-04-19 14:21:56 +00:00
parent 13427c0cdf
commit 2513f5d3c7
23 changed files with 736 additions and 326 deletions

View File

@@ -4,6 +4,7 @@ import org.opencv.calib3d.Calib3d;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfDouble;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.MatOfPoint3f;
import org.opencv.core.Point;
@@ -174,15 +175,17 @@ public class Calib3dTest extends OpenCVTestCase {
public void testFindChessboardCornersMatSizeMat() {
Size patternSize = new Size(9, 6);
Calib3d.findChessboardCorners(grayChess, patternSize, dst);
assertTrue(!dst.empty());
MatOfPoint2f corners = new MatOfPoint2f();
Calib3d.findChessboardCorners(grayChess, patternSize, corners);
assertTrue(!corners.empty());
}
public void testFindChessboardCornersMatSizeMatInt() {
Size patternSize = new Size(9, 6);
Calib3d.findChessboardCorners(grayChess, patternSize, dst, Calib3d.CALIB_CB_ADAPTIVE_THRESH + Calib3d.CALIB_CB_NORMALIZE_IMAGE
MatOfPoint2f corners = new MatOfPoint2f();
Calib3d.findChessboardCorners(grayChess, patternSize, corners, Calib3d.CALIB_CB_ADAPTIVE_THRESH + Calib3d.CALIB_CB_NORMALIZE_IMAGE
+ Calib3d.CALIB_CB_FAST_CHECK);
assertTrue(!dst.empty());
assertTrue(!corners.empty());
}
public void testFindCirclesGridDefaultMatSizeMat() {
@@ -515,7 +518,7 @@ public class Calib3dTest extends OpenCVTestCase {
Mat rvec = new Mat();
Mat tvec = new Mat();
Calib3d.solvePnP(points3d, points2d, intrinsics, new Mat(), rvec, tvec);
Calib3d.solvePnP(points3d, points2d, intrinsics, new MatOfDouble(), rvec, tvec);
Mat truth_rvec = new Mat(3, 1, CvType.CV_64F);
truth_rvec.put(0, 0, 0, Math.PI / 2, 0);

View File

@@ -1284,14 +1284,14 @@ public class CoreTest extends OpenCVTestCase {
rgba0.setTo(new Scalar(10, 20, 30, 40));
List<Mat> src = Arrays.asList(rgba0);
List<Mat> dst = Arrays.asList(gray3, gray2, gray1, gray0, getMat(CvType.CV_8UC3, 0, 0, 0));
MatOfInt fromTo = new MatOfInt(1, new int[]
{ 3, 0,
MatOfInt fromTo = new MatOfInt(
3, 0,
3, 1,
2, 2,
0, 3,
2, 4,
1, 5,
0, 6 }
0, 6
);
Core.mixChannels(src, dst, fromTo);

View File

@@ -189,9 +189,11 @@ public class BruteForceHammingLUTDescriptorMatcherTest extends OpenCVTestCase {
matcher.match(query, train, matches);
/*
OpenCVTestRunner.Log("matches found: " + matches.size());
for (DMatch m : matches.toArray())
OpenCVTestRunner.Log(m.toString());
*/
assertArrayDMatchEquals(truth, matches.toArray(), EPS);
}

View File

@@ -9,6 +9,7 @@ import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfInt;
import org.opencv.core.MatOfInt4;
import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Point;
@@ -242,9 +243,9 @@ public class ImgprocTest extends OpenCVTestCase {
public void testCalcBackProject() {
List<Mat> images = Arrays.asList(grayChess);
MatOfInt channels = new MatOfInt(1, new int[]{0});
MatOfInt histSize = new MatOfInt(1, new int[]{10});
MatOfFloat ranges = new MatOfFloat(1, 0f, 256f);
MatOfInt channels = new MatOfInt(0);
MatOfInt histSize = new MatOfInt(10);
MatOfFloat ranges = new MatOfFloat(0f, 256f);
Mat hist = new Mat();
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
@@ -259,9 +260,9 @@ public class ImgprocTest extends OpenCVTestCase {
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat() {
List<Mat> images = Arrays.asList(gray128);
MatOfInt channels = new MatOfInt(1, new int[]{0});
MatOfInt histSize = new MatOfInt(1, new int[]{10});
MatOfFloat ranges = new MatOfFloat(1, 0f, 256f);
MatOfInt channels = new MatOfInt(0);
MatOfInt histSize = new MatOfInt(10);
MatOfFloat ranges = new MatOfFloat(0f, 256f);
Mat hist = new Mat();
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
@@ -276,9 +277,9 @@ public class ImgprocTest extends OpenCVTestCase {
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2d() {
List<Mat> images = Arrays.asList(gray255, gray128);
MatOfInt channels = new MatOfInt(1, 0, 1);
MatOfInt histSize = new MatOfInt(1, 10, 10);
MatOfFloat ranges = new MatOfFloat(1, 0f, 256f, 0f, 256f);
MatOfInt channels = new MatOfInt(0, 1);
MatOfInt histSize = new MatOfInt(10, 10);
MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
Mat hist = new Mat();
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
@@ -293,9 +294,9 @@ public class ImgprocTest extends OpenCVTestCase {
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean() {
List<Mat> images = Arrays.asList(gray255, gray128);
MatOfInt channels = new MatOfInt(1, 0, 1);
MatOfInt histSize = new MatOfInt(1, 10, 10);
MatOfFloat ranges = new MatOfFloat(1, 0f, 256f, 0f, 256f);
MatOfInt channels = new MatOfInt(0, 1);
MatOfInt histSize = new MatOfInt(10, 10);
MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
Mat hist = new Mat();
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges, true);
@@ -382,27 +383,67 @@ public class ImgprocTest extends OpenCVTestCase {
}
public void testConvexHullMatMat() {
Mat points = new Mat(1, 6, CvType.CV_32FC2);
points.put(0, 0, 2, 0, 4, 0, 3, 2, 0, 2, 2, 1, 3, 1);
MatOfPoint points = new MatOfPoint(
new Point(20, 0),
new Point(40, 0),
new Point(30, 20),
new Point(0, 20),
new Point(20, 10),
new Point(30, 10)
);
Imgproc.convexHull(points, dst);
Mat expHull = new Mat(4, 1, CvType.CV_32FC2);
expHull.put(0, 0, 4, 0, 3, 2, 0, 2, 2, 0);
MatOfPoint expHull = new MatOfPoint(
new Point(40, 0),
new Point(30, 20),
new Point(0, 20),
new Point(20, 0)
);
assertMatEqual(expHull, dst, EPS);
}
public void testConvexHullMatMatBooleanBoolean() {
Mat points = new Mat(1, 6, CvType.CV_32FC2);
points.put(0, 0, 2, 0, 4, 0, 3, 2, 0, 2, 2, 1, 3, 1);
MatOfPoint points = new MatOfPoint(
new Point(2, 0),
new Point(4, 0),
new Point(3, 2),
new Point(0, 2),
new Point(2, 1),
new Point(3, 1)
);
Imgproc.convexHull(points, dst, true, true);
// TODO_: write better test (last param == false)
Mat expHull = new Mat(4, 1, CvType.CV_32FC2);
expHull.put(0, 0, 0, 2, 3, 2, 4, 0, 2, 0);
MatOfPoint expHull = new MatOfPoint(
new Point(0, 2),
new Point(3, 2),
new Point(4, 0),
new Point(2, 0)
);
assertMatEqual(expHull, dst, EPS);
}
public void testConvexityDefects() {
MatOfPoint points = new MatOfPoint(
new Point(20, 0),
new Point(40, 0),
new Point(30, 20),
new Point(0, 20),
new Point(20, 10),
new Point(30, 10)
);
MatOfPoint hull = new MatOfPoint();
Imgproc.convexHull(points, hull, false, false);
MatOfInt4 convexityDefects = new MatOfInt4();
Imgproc.convexityDefects(points, hull, convexityDefects);
assertMatEqual(new MatOfInt4(3, 0, 5, 3620), convexityDefects);
}
public void testCopyMakeBorderMatMatIntIntIntIntInt() {
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1));
@@ -1277,11 +1318,11 @@ public class ImgprocTest extends OpenCVTestCase {
}
public void testIsContourConvex() {
MatOfPoint2f contour1 = new MatOfPoint2f(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4));
MatOfPoint contour1 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4));
assertFalse(Imgproc.isContourConvex(contour1));
MatOfPoint2f contour2 = new MatOfPoint2f(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6));
MatOfPoint contour2 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6));
assertTrue(Imgproc.isContourConvex(contour2));
}

View File

@@ -1,6 +1,6 @@
package org.opencv.test.imgproc;
import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfFloat6;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.imgproc.Subdiv2D;
@@ -50,7 +50,7 @@ public class Subdiv2DTest extends OpenCVTestCase {
s2d.insert( new Point(20, 10) );
s2d.insert( new Point(20, 20) );
s2d.insert( new Point(10, 20) );
MatOfFloat triangles = new MatOfFloat();
MatOfFloat6 triangles = new MatOfFloat6();
s2d.getTriangleList(triangles);
assertEquals(10, triangles.rows());
/*