Commit 2513f5d3 authored by Andrey Pavlenko's avatar Andrey Pavlenko

fixing #1808, Java API improvements

parent 13427c0c
...@@ -4,6 +4,7 @@ import org.opencv.calib3d.Calib3d; ...@@ -4,6 +4,7 @@ import org.opencv.calib3d.Calib3d;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.MatOfDouble;
import org.opencv.core.MatOfPoint2f; import org.opencv.core.MatOfPoint2f;
import org.opencv.core.MatOfPoint3f; import org.opencv.core.MatOfPoint3f;
import org.opencv.core.Point; import org.opencv.core.Point;
...@@ -174,15 +175,17 @@ public class Calib3dTest extends OpenCVTestCase { ...@@ -174,15 +175,17 @@ public class Calib3dTest extends OpenCVTestCase {
public void testFindChessboardCornersMatSizeMat() { public void testFindChessboardCornersMatSizeMat() {
Size patternSize = new Size(9, 6); Size patternSize = new Size(9, 6);
Calib3d.findChessboardCorners(grayChess, patternSize, dst); MatOfPoint2f corners = new MatOfPoint2f();
assertTrue(!dst.empty()); Calib3d.findChessboardCorners(grayChess, patternSize, corners);
assertTrue(!corners.empty());
} }
public void testFindChessboardCornersMatSizeMatInt() { public void testFindChessboardCornersMatSizeMatInt() {
Size patternSize = new Size(9, 6); 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); + Calib3d.CALIB_CB_FAST_CHECK);
assertTrue(!dst.empty()); assertTrue(!corners.empty());
} }
public void testFindCirclesGridDefaultMatSizeMat() { public void testFindCirclesGridDefaultMatSizeMat() {
...@@ -515,7 +518,7 @@ public class Calib3dTest extends OpenCVTestCase { ...@@ -515,7 +518,7 @@ public class Calib3dTest extends OpenCVTestCase {
Mat rvec = new Mat(); Mat rvec = new Mat();
Mat tvec = 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); Mat truth_rvec = new Mat(3, 1, CvType.CV_64F);
truth_rvec.put(0, 0, 0, Math.PI / 2, 0); truth_rvec.put(0, 0, 0, Math.PI / 2, 0);
......
...@@ -1284,14 +1284,14 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1284,14 +1284,14 @@ public class CoreTest extends OpenCVTestCase {
rgba0.setTo(new Scalar(10, 20, 30, 40)); rgba0.setTo(new Scalar(10, 20, 30, 40));
List<Mat> src = Arrays.asList(rgba0); List<Mat> src = Arrays.asList(rgba0);
List<Mat> dst = Arrays.asList(gray3, gray2, gray1, gray0, getMat(CvType.CV_8UC3, 0, 0, 0)); List<Mat> dst = Arrays.asList(gray3, gray2, gray1, gray0, getMat(CvType.CV_8UC3, 0, 0, 0));
MatOfInt fromTo = new MatOfInt(1, new int[] MatOfInt fromTo = new MatOfInt(
{ 3, 0, 3, 0,
3, 1, 3, 1,
2, 2, 2, 2,
0, 3, 0, 3,
2, 4, 2, 4,
1, 5, 1, 5,
0, 6 } 0, 6
); );
Core.mixChannels(src, dst, fromTo); Core.mixChannels(src, dst, fromTo);
......
...@@ -189,9 +189,11 @@ public class BruteForceHammingLUTDescriptorMatcherTest extends OpenCVTestCase { ...@@ -189,9 +189,11 @@ public class BruteForceHammingLUTDescriptorMatcherTest extends OpenCVTestCase {
matcher.match(query, train, matches); matcher.match(query, train, matches);
/*
OpenCVTestRunner.Log("matches found: " + matches.size()); OpenCVTestRunner.Log("matches found: " + matches.size());
for (DMatch m : matches.toArray()) for (DMatch m : matches.toArray())
OpenCVTestRunner.Log(m.toString()); OpenCVTestRunner.Log(m.toString());
*/
assertArrayDMatchEquals(truth, matches.toArray(), EPS); assertArrayDMatchEquals(truth, matches.toArray(), EPS);
} }
......
...@@ -9,6 +9,7 @@ import org.opencv.core.CvType; ...@@ -9,6 +9,7 @@ import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.MatOfFloat; import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfInt; import org.opencv.core.MatOfInt;
import org.opencv.core.MatOfInt4;
import org.opencv.core.MatOfPoint; import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfPoint2f; import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Point; import org.opencv.core.Point;
...@@ -242,9 +243,9 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -242,9 +243,9 @@ public class ImgprocTest extends OpenCVTestCase {
public void testCalcBackProject() { public void testCalcBackProject() {
List<Mat> images = Arrays.asList(grayChess); List<Mat> images = Arrays.asList(grayChess);
MatOfInt channels = new MatOfInt(1, new int[]{0}); MatOfInt channels = new MatOfInt(0);
MatOfInt histSize = new MatOfInt(1, new int[]{10}); MatOfInt histSize = new MatOfInt(10);
MatOfFloat ranges = new MatOfFloat(1, 0f, 256f); MatOfFloat ranges = new MatOfFloat(0f, 256f);
Mat hist = new Mat(); Mat hist = new Mat();
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges); Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
...@@ -259,9 +260,9 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -259,9 +260,9 @@ public class ImgprocTest extends OpenCVTestCase {
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat() { public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat() {
List<Mat> images = Arrays.asList(gray128); List<Mat> images = Arrays.asList(gray128);
MatOfInt channels = new MatOfInt(1, new int[]{0}); MatOfInt channels = new MatOfInt(0);
MatOfInt histSize = new MatOfInt(1, new int[]{10}); MatOfInt histSize = new MatOfInt(10);
MatOfFloat ranges = new MatOfFloat(1, 0f, 256f); MatOfFloat ranges = new MatOfFloat(0f, 256f);
Mat hist = new Mat(); Mat hist = new Mat();
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges); Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
...@@ -276,9 +277,9 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -276,9 +277,9 @@ public class ImgprocTest extends OpenCVTestCase {
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2d() { public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2d() {
List<Mat> images = Arrays.asList(gray255, gray128); List<Mat> images = Arrays.asList(gray255, gray128);
MatOfInt channels = new MatOfInt(1, 0, 1); MatOfInt channels = new MatOfInt(0, 1);
MatOfInt histSize = new MatOfInt(1, 10, 10); MatOfInt histSize = new MatOfInt(10, 10);
MatOfFloat ranges = new MatOfFloat(1, 0f, 256f, 0f, 256f); MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
Mat hist = new Mat(); Mat hist = new Mat();
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges); Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
...@@ -293,9 +294,9 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -293,9 +294,9 @@ public class ImgprocTest extends OpenCVTestCase {
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean() { public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean() {
List<Mat> images = Arrays.asList(gray255, gray128); List<Mat> images = Arrays.asList(gray255, gray128);
MatOfInt channels = new MatOfInt(1, 0, 1); MatOfInt channels = new MatOfInt(0, 1);
MatOfInt histSize = new MatOfInt(1, 10, 10); MatOfInt histSize = new MatOfInt(10, 10);
MatOfFloat ranges = new MatOfFloat(1, 0f, 256f, 0f, 256f); MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
Mat hist = new Mat(); Mat hist = new Mat();
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges, true); Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges, true);
...@@ -382,28 +383,68 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -382,28 +383,68 @@ public class ImgprocTest extends OpenCVTestCase {
} }
public void testConvexHullMatMat() { public void testConvexHullMatMat() {
Mat points = new Mat(1, 6, CvType.CV_32FC2); MatOfPoint points = new MatOfPoint(
points.put(0, 0, 2, 0, 4, 0, 3, 2, 0, 2, 2, 1, 3, 1); 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); Imgproc.convexHull(points, dst);
Mat expHull = new Mat(4, 1, CvType.CV_32FC2); MatOfPoint expHull = new MatOfPoint(
expHull.put(0, 0, 4, 0, 3, 2, 0, 2, 2, 0); new Point(40, 0),
new Point(30, 20),
new Point(0, 20),
new Point(20, 0)
);
assertMatEqual(expHull, dst, EPS); assertMatEqual(expHull, dst, EPS);
} }
public void testConvexHullMatMatBooleanBoolean() { public void testConvexHullMatMatBooleanBoolean() {
Mat points = new Mat(1, 6, CvType.CV_32FC2); MatOfPoint points = new MatOfPoint(
points.put(0, 0, 2, 0, 4, 0, 3, 2, 0, 2, 2, 1, 3, 1); 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); Imgproc.convexHull(points, dst, true, true);
// TODO_: write better test (last param == false) // TODO_: write better test (last param == false)
Mat expHull = new Mat(4, 1, CvType.CV_32FC2); MatOfPoint expHull = new MatOfPoint(
expHull.put(0, 0, 0, 2, 3, 2, 4, 0, 2, 0); new Point(0, 2),
new Point(3, 2),
new Point(4, 0),
new Point(2, 0)
);
assertMatEqual(expHull, dst, EPS); 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() { public void testCopyMakeBorderMatMatIntIntIntIntInt() {
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1)); Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1));
int border = 2; int border = 2;
...@@ -1277,11 +1318,11 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -1277,11 +1318,11 @@ public class ImgprocTest extends OpenCVTestCase {
} }
public void testIsContourConvex() { 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)); 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)); assertTrue(Imgproc.isContourConvex(contour2));
} }
......
package org.opencv.test.imgproc; package org.opencv.test.imgproc;
import org.opencv.core.MatOfFloat; import org.opencv.core.MatOfFloat6;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Rect; import org.opencv.core.Rect;
import org.opencv.imgproc.Subdiv2D; import org.opencv.imgproc.Subdiv2D;
...@@ -50,7 +50,7 @@ public class Subdiv2DTest extends OpenCVTestCase { ...@@ -50,7 +50,7 @@ public class Subdiv2DTest extends OpenCVTestCase {
s2d.insert( new Point(20, 10) ); s2d.insert( new Point(20, 10) );
s2d.insert( new Point(20, 20) ); s2d.insert( new Point(20, 20) );
s2d.insert( new Point(10, 20) ); s2d.insert( new Point(10, 20) );
MatOfFloat triangles = new MatOfFloat(); MatOfFloat6 triangles = new MatOfFloat6();
s2d.getTriangleList(triangles); s2d.getTriangleList(triangles);
assertEquals(10, triangles.rows()); assertEquals(10, triangles.rows());
/* /*
......
...@@ -209,8 +209,9 @@ type_dict = { ...@@ -209,8 +209,9 @@ type_dict = {
"vector_int" : { "j_type" : "MatOfInt", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<int> %(n)s", "suffix" : "J" }, "vector_int" : { "j_type" : "MatOfInt", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<int> %(n)s", "suffix" : "J" },
"vector_float" : { "j_type" : "MatOfFloat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<float> %(n)s", "suffix" : "J" }, "vector_float" : { "j_type" : "MatOfFloat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<float> %(n)s", "suffix" : "J" },
"vector_double" : { "j_type" : "MatOfDouble", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<double> %(n)s", "suffix" : "J" }, "vector_double" : { "j_type" : "MatOfDouble", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<double> %(n)s", "suffix" : "J" },
"vector_Vec4f" : { "j_type" : "MatOfFloat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec4f> %(n)s", "suffix" : "J" }, "vector_Vec4i" : { "j_type" : "MatOfInt4", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec4i> %(n)s", "suffix" : "J" },
"vector_Vec6f" : { "j_type" : "MatOfFloat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec6f> %(n)s", "suffix" : "J" }, "vector_Vec4f" : { "j_type" : "MatOfFloat4", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec4f> %(n)s", "suffix" : "J" },
"vector_Vec6f" : { "j_type" : "MatOfFloat6", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec6f> %(n)s", "suffix" : "J" },
"vector_Mat" : { "j_type" : "List<Mat>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Mat> %(n)s", "suffix" : "J" }, "vector_Mat" : { "j_type" : "List<Mat>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Mat> %(n)s", "suffix" : "J" },
...@@ -219,6 +220,7 @@ type_dict = { ...@@ -219,6 +220,7 @@ type_dict = {
"vector_vector_char" : { "j_type" : "List<MatOfByte>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<char> > %(n)s" }, "vector_vector_char" : { "j_type" : "List<MatOfByte>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<char> > %(n)s" },
"vector_vector_Point" : { "j_type" : "List<MatOfPoint>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point> > %(n)s" }, "vector_vector_Point" : { "j_type" : "List<MatOfPoint>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point> > %(n)s" },
"vector_vector_Point2f" : { "j_type" : "List<MatOfPoint2f>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point2f> > %(n)s" }, "vector_vector_Point2f" : { "j_type" : "List<MatOfPoint2f>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point2f> > %(n)s" },
"vector_vector_Point3f" : { "j_type" : "List<MatOfPoint3f>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point3f> > %(n)s" },
"Mat" : { "j_type" : "Mat", "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),), "Mat" : { "j_type" : "Mat", "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
"jni_var" : "Mat& %(n)s = *((Mat*)%(n)s_nativeObj)", "jni_var" : "Mat& %(n)s = *((Mat*)%(n)s_nativeObj)",
...@@ -505,8 +507,10 @@ func_arg_fix = { ...@@ -505,8 +507,10 @@ func_arg_fix = {
'cornerSubPix' : { 'corners' : 'vector_Point2f', }, 'cornerSubPix' : { 'corners' : 'vector_Point2f', },
'minEnclosingCircle' : { 'points' : 'vector_Point2f', }, 'minEnclosingCircle' : { 'points' : 'vector_Point2f', },
'findHomography' : { 'srcPoints' : 'vector_Point2f', 'dstPoints' : 'vector_Point2f', }, 'findHomography' : { 'srcPoints' : 'vector_Point2f', 'dstPoints' : 'vector_Point2f', },
'solvePnP' : { 'objectPoints' : 'vector_Point3f', 'imagePoints' : 'vector_Point2f', }, 'solvePnP' : { 'objectPoints' : 'vector_Point3f', 'imagePoints' : 'vector_Point2f',
'solvePnPRansac' : { 'objectPoints' : 'vector_Point3f', 'imagePoints' : 'vector_Point2f', }, 'distCoeffs' : 'vector_double' },
'solvePnPRansac' : { 'objectPoints' : 'vector_Point3f', 'imagePoints' : 'vector_Point2f',
'distCoeffs' : 'vector_double' },
'calcOpticalFlowPyrLK' : { 'prevPts' : 'vector_Point2f', 'nextPts' : 'vector_Point2f', 'calcOpticalFlowPyrLK' : { 'prevPts' : 'vector_Point2f', 'nextPts' : 'vector_Point2f',
'status' : 'vector_uchar', 'err' : 'vector_float', }, 'status' : 'vector_uchar', 'err' : 'vector_float', },
'fitEllipse' : { 'points' : 'vector_Point2f', }, 'fitEllipse' : { 'points' : 'vector_Point2f', },
...@@ -526,8 +530,14 @@ func_arg_fix = { ...@@ -526,8 +530,14 @@ func_arg_fix = {
'meanStdDev' : {'mean' : 'vector_double', 'stddev' : 'vector_double'}, 'meanStdDev' : {'mean' : 'vector_double', 'stddev' : 'vector_double'},
'drawContours' : {'contours' : 'vector_vector_Point'}, 'drawContours' : {'contours' : 'vector_vector_Point'},
'findContours' : {'contours' : 'vector_vector_Point'}, 'findContours' : {'contours' : 'vector_vector_Point'},
'convexityDefects' : {'contour' : 'vector_Point'}, 'convexityDefects' : {'contour' : 'vector_Point', 'convexityDefects' : 'vector_Vec4i'},
'isContourConvex' : { 'contour' : 'vector_Point2f', }, 'isContourConvex' : { 'contour' : 'vector_Point', },
'convexHull' : {'points' : 'vector_Point'},
'projectPoints' : { 'objectPoints' : 'vector_Point3f', 'imagePoints' : 'vector_Point2f',
'distCoeffs' : 'vector_double' },
'initCameraMatrix2D' : {'objectPoints' : 'vector_vector_Point3f', 'imagePoints' : 'vector_vector_Point2f', },
'findChessboardCorners' : { 'corners' : 'vector_Point2f' },
'drawChessboardCorners' : { 'corners' : 'vector_Point2f' },
}, # '', i.e. no class }, # '', i.e. no class
} # func_arg_fix } # func_arg_fix
...@@ -903,15 +913,22 @@ extern "C" { ...@@ -903,15 +913,22 @@ extern "C" {
def get_imports(self, scope_classname, ctype): def get_imports(self, scope_classname, ctype):
imports = self.classes[scope_classname or self.Module].imports imports = self.classes[scope_classname or self.Module].imports
if ctype.startswith('vector_vector'):
imports.add("org.opencv.core.Mat")
imports.add("java.util.List")
imports.add("org.opencv.utils.Converters")
self.get_imports(scope_classname, ctype.replace('vector_vector', 'vector'))
return
if ctype.startswith('vector'): if ctype.startswith('vector'):
imports.add("org.opencv.core.Mat") imports.add("org.opencv.core.Mat")
if type_dict[ctype]['j_type'].startswith('MatOf'): if type_dict[ctype]['j_type'].startswith('MatOf'):
imports.add("org.opencv.core." + type_dict[ctype]['j_type']) imports.add("org.opencv.core." + type_dict[ctype]['j_type'])
return #TMP return
else: else:
imports.add("java.util.List") imports.add("java.util.List")
imports.add("org.opencv.utils.Converters") imports.add("org.opencv.utils.Converters")
ctype = ctype.replace('vector_', '') self.get_imports(scope_classname, ctype.replace('vector_', ''))
return
j_type = '' j_type = ''
if ctype in type_dict: if ctype in type_dict:
j_type = type_dict[ctype]['j_type'] j_type = type_dict[ctype]['j_type']
...@@ -919,6 +936,7 @@ extern "C" { ...@@ -919,6 +936,7 @@ extern "C" {
imports.add("org.opencv.core." + j_type) imports.add("org.opencv.core." + j_type)
if j_type == 'String': if j_type == 'String':
imports.add("java.lang.String") imports.add("java.lang.String")
return
...@@ -1083,13 +1101,7 @@ extern "C" { ...@@ -1083,13 +1101,7 @@ extern "C" {
tail = ")" tail = ")"
j_type = type_dict[ret_type]["j_type"] j_type = type_dict[ret_type]["j_type"]
if j_type.startswith('MatOf'): if j_type.startswith('MatOf'):
ret_val += "new " + j_type + "(" ret_val += j_type + ".fromNativeAddr("
m_t = re.match('vector_(\w+)', ret_type)
m_ch = re.match('vector_Vec(\d+)', ret_type)
if m_ch:
ret_val += m_ch.group(1) + ', '
elif m_t.group(1) in ('char', 'uchar', 'int', 'float', 'double'):
ret_val += '1, '
else: else:
ret_val = "Mat retValMat = new Mat(" ret_val = "Mat retValMat = new Mat("
j_prologue.append( j_type + ' retVal = new Array' + j_type+'();') j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')
......
...@@ -281,6 +281,32 @@ void Mat_to_vector_vector_Point(Mat& mat, vector< vector< Point > >& vv_pt) ...@@ -281,6 +281,32 @@ void Mat_to_vector_vector_Point(Mat& mat, vector< vector< Point > >& vv_pt)
} }
} }
void Mat_to_vector_vector_Point2f(Mat& mat, vector< vector< Point2f > >& vv_pt)
{
vector<Mat> vm;
vm.reserve( mat.rows );
Mat_to_vector_Mat(mat, vm);
for(size_t i=0; i<vm.size(); i++)
{
vector<Point2f> vpt;
Mat_to_vector_Point2f(vm[i], vpt);
vv_pt.push_back(vpt);
}
}
void Mat_to_vector_vector_Point3f(Mat& mat, vector< vector< Point3f > >& vv_pt)
{
vector<Mat> vm;
vm.reserve( mat.rows );
Mat_to_vector_Mat(mat, vm);
for(size_t i=0; i<vm.size(); i++)
{
vector<Point3f> vpt;
Mat_to_vector_Point3f(vm[i], vpt);
vv_pt.push_back(vpt);
}
}
#ifdef HAVE_OPENCV_FEATURES2D #ifdef HAVE_OPENCV_FEATURES2D
void Mat_to_vector_vector_KeyPoint(Mat& mat, vector< vector< KeyPoint > >& vv_kp) void Mat_to_vector_vector_KeyPoint(Mat& mat, vector< vector< KeyPoint > >& vv_kp)
{ {
...@@ -361,6 +387,19 @@ void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& mat) ...@@ -361,6 +387,19 @@ void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& mat)
vector_Mat_to_Mat(vm, mat); vector_Mat_to_Mat(vm, mat);
} }
void vector_vector_Point_to_Mat(vector< vector< Point > >& vv_pt, Mat& mat)
{
vector<Mat> vm;
vm.reserve( vv_pt.size() );
for(size_t i=0; i<vv_pt.size(); i++)
{
Mat m;
vector_Point_to_Mat(vv_pt[i], m);
vm.push_back(m);
}
vector_Mat_to_Mat(vm, mat);
}
void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat) void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat)
{ {
vector<Mat> vm; vector<Mat> vm;
...@@ -374,19 +413,24 @@ void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat) ...@@ -374,19 +413,24 @@ void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat)
vector_Mat_to_Mat(vm, mat); vector_Mat_to_Mat(vm, mat);
} }
void vector_vector_Point_to_Mat(vector< vector< Point > >& vv_pt, Mat& mat) void vector_vector_Point3f_to_Mat(vector< vector< Point3f > >& vv_pt, Mat& mat)
{ {
vector<Mat> vm; vector<Mat> vm;
vm.reserve( vv_pt.size() ); vm.reserve( vv_pt.size() );
for(size_t i=0; i<vv_pt.size(); i++) for(size_t i=0; i<vv_pt.size(); i++)
{ {
Mat m; Mat m;
vector_Point_to_Mat(vv_pt[i], m); vector_Point3f_to_Mat(vv_pt[i], m);
vm.push_back(m); vm.push_back(m);
} }
vector_Mat_to_Mat(vm, mat); vector_Mat_to_Mat(vm, mat);
} }
void vector_Vec4i_to_Mat(vector<Vec4i>& v_vec, Mat& mat)
{
mat = Mat(v_vec, true);
}
void vector_Vec4f_to_Mat(vector<Vec4f>& v_vec, Mat& mat) void vector_Vec4f_to_Mat(vector<Vec4f>& v_vec, Mat& mat)
{ {
mat = Mat(v_vec, true); mat = Mat(v_vec, true);
......
...@@ -37,6 +37,7 @@ void vector_Point3i_to_Mat(std::vector<cv::Point3i>& v_point, cv::Mat& mat); ...@@ -37,6 +37,7 @@ void vector_Point3i_to_Mat(std::vector<cv::Point3i>& v_point, cv::Mat& mat);
void vector_Point3f_to_Mat(std::vector<cv::Point3f>& v_point, cv::Mat& mat); void vector_Point3f_to_Mat(std::vector<cv::Point3f>& v_point, cv::Mat& mat);
void vector_Point3d_to_Mat(std::vector<cv::Point3d>& v_point, cv::Mat& mat); void vector_Point3d_to_Mat(std::vector<cv::Point3d>& v_point, cv::Mat& mat);
void vector_Vec4i_to_Mat(std::vector<cv::Vec4i>& v_vec, cv::Mat& mat);
void vector_Vec4f_to_Mat(std::vector<cv::Vec4f>& v_vec, cv::Mat& mat); void vector_Vec4f_to_Mat(std::vector<cv::Vec4f>& v_vec, cv::Mat& mat);
void vector_Vec6f_to_Mat(std::vector<cv::Vec6f>& v_vec, cv::Mat& mat); void vector_Vec6f_to_Mat(std::vector<cv::Vec6f>& v_vec, cv::Mat& mat);
...@@ -63,6 +64,10 @@ void Mat_to_vector_vector_char(cv::Mat& mat, std::vector< std::vector< char > >& ...@@ -63,6 +64,10 @@ void Mat_to_vector_vector_char(cv::Mat& mat, std::vector< std::vector< char > >&
void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Mat& mat); void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Mat& mat);
void Mat_to_vector_vector_Point(cv::Mat& mat, std::vector< std::vector< cv::Point > >& vv_pt); void Mat_to_vector_vector_Point(cv::Mat& mat, std::vector< std::vector< cv::Point > >& vv_pt);
void vector_vector_Point2f_to_Mat(std::vector< std::vector< cv::Point2f > >& vv_pt, cv::Mat& mat);
void vector_vector_Point_to_Mat(std::vector< std::vector< cv::Point > >& vv_pt, cv::Mat& mat); void vector_vector_Point_to_Mat(std::vector< std::vector< cv::Point > >& vv_pt, cv::Mat& mat);
void Mat_to_vector_vector_Point2f(cv::Mat& mat, std::vector< std::vector< cv::Point2f > >& vv_pt);
void vector_vector_Point2f_to_Mat(std::vector< std::vector< cv::Point2f > >& vv_pt, cv::Mat& mat);
void Mat_to_vector_vector_Point3f(cv::Mat& mat, std::vector< std::vector< cv::Point3f > >& vv_pt);
void vector_vector_Point3f_to_Mat(std::vector< std::vector< cv::Point3f > >& vv_pt, cv::Mat& mat);
...@@ -6,36 +6,32 @@ import java.util.List; ...@@ -6,36 +6,32 @@ import java.util.List;
public class MatOfByte extends Mat { public class MatOfByte extends Mat {
// 8UC(x) // 8UC(x)
private static final int _depth = CvType.CV_8U; private static final int _depth = CvType.CV_8U;
private final int _channels; private static final int _channels = 1;
public MatOfByte(int channels) {
super();
_channels = channels;
}
public MatOfByte() { public MatOfByte() {
this(1); super();
} }
public MatOfByte(int channels, long addr) { protected MatOfByte(long addr) {
super(addr); super(addr);
_channels = channels;
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public MatOfByte(int channels, Mat m) { public static MatOfByte fromNativeAddr(long addr) {
return new MatOfByte(addr);
}
public MatOfByte(Mat m) {
super(m, Range.all()); super(m, Range.all());
_channels = channels;
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public MatOfByte(int channels, byte...a) { public MatOfByte(byte...a) {
super(); super();
_channels = channels;
fromArray(a); fromArray(a);
} }
...@@ -53,7 +49,9 @@ public class MatOfByte extends Mat { ...@@ -53,7 +49,9 @@ public class MatOfByte extends Mat {
} }
public byte[] toArray() { public byte[] toArray() {
int num = (int) total(); int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
byte[] a = new byte[num * _channels]; byte[] a = new byte[num * _channels];
if(num == 0) if(num == 0)
return a; return a;
...@@ -64,7 +62,7 @@ public class MatOfByte extends Mat { ...@@ -64,7 +62,7 @@ public class MatOfByte extends Mat {
public void fromList(List<Byte> lb) { public void fromList(List<Byte> lb) {
if(lb==null || lb.size()==0) if(lb==null || lb.size()==0)
return; return;
Byte ab[] = lb.toArray(null); Byte ab[] = lb.toArray(new Byte[0]);
byte a[] = new byte[ab.length]; byte a[] = new byte[ab.length];
for(int i=0; i<ab.length; i++) for(int i=0; i<ab.length; i++)
a[i] = ab[i]; a[i] = ab[i];
......
...@@ -14,13 +14,17 @@ public class MatOfDMatch extends Mat { ...@@ -14,13 +14,17 @@ public class MatOfDMatch extends Mat {
super(); super();
} }
public MatOfDMatch(long addr) { protected MatOfDMatch(long addr) {
super(addr); super(addr);
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public static MatOfDMatch fromNativeAddr(long addr) {
return new MatOfDMatch(addr);
}
public MatOfDMatch(Mat m) { public MatOfDMatch(Mat m) {
super(m, Range.all()); super(m, Range.all());
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
...@@ -68,7 +72,7 @@ public class MatOfDMatch extends Mat { ...@@ -68,7 +72,7 @@ public class MatOfDMatch extends Mat {
} }
public void fromList(List<DMatch> ldm) { public void fromList(List<DMatch> ldm) {
DMatch adm[] = ldm.toArray(null); DMatch adm[] = ldm.toArray(new DMatch[0]);
fromArray(adm); fromArray(adm);
} }
......
...@@ -6,36 +6,32 @@ import java.util.List; ...@@ -6,36 +6,32 @@ import java.util.List;
public class MatOfDouble extends Mat { public class MatOfDouble extends Mat {
// 64FC(x) // 64FC(x)
private static final int _depth = CvType.CV_64F; private static final int _depth = CvType.CV_64F;
private final int _channels; private static final int _channels = 1;
public MatOfDouble(int channels) {
super();
_channels = channels;
}
public MatOfDouble() { public MatOfDouble() {
this(1); super();
} }
public MatOfDouble(int channels, long addr) { protected MatOfDouble(long addr) {
super(addr); super(addr);
_channels = channels;
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public MatOfDouble(int channels, Mat m) { public static MatOfDouble fromNativeAddr(long addr) {
return new MatOfDouble(addr);
}
public MatOfDouble(Mat m) {
super(m, Range.all()); super(m, Range.all());
_channels = channels;
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public MatOfDouble(int channels, double...a) { public MatOfDouble(double...a) {
super(); super();
_channels = channels;
fromArray(a); fromArray(a);
} }
...@@ -53,7 +49,9 @@ public class MatOfDouble extends Mat { ...@@ -53,7 +49,9 @@ public class MatOfDouble extends Mat {
} }
public double[] toArray() { public double[] toArray() {
int num = (int) total(); int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
double[] a = new double[num * _channels]; double[] a = new double[num * _channels];
if(num == 0) if(num == 0)
return a; return a;
...@@ -64,7 +62,7 @@ public class MatOfDouble extends Mat { ...@@ -64,7 +62,7 @@ public class MatOfDouble extends Mat {
public void fromList(List<Double> lb) { public void fromList(List<Double> lb) {
if(lb==null || lb.size()==0) if(lb==null || lb.size()==0)
return; return;
Double ab[] = lb.toArray(null); Double ab[] = lb.toArray(new Double[0]);
double a[] = new double[ab.length]; double a[] = new double[ab.length];
for(int i=0; i<ab.length; i++) for(int i=0; i<ab.length; i++)
a[i] = ab[i]; a[i] = ab[i];
......
...@@ -4,38 +4,34 @@ import java.util.Arrays; ...@@ -4,38 +4,34 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
public class MatOfFloat extends Mat { public class MatOfFloat extends Mat {
// 32FC(x) // 32FC1
private static final int _depth = CvType.CV_32F; private static final int _depth = CvType.CV_32F;
private final int _channels; private static final int _channels = 1;
public MatOfFloat(int channels) {
super();
_channels = channels;
}
public MatOfFloat() { public MatOfFloat() {
this(1); super();
} }
public MatOfFloat(int channels, long addr) { protected MatOfFloat(long addr) {
super(addr); super(addr);
_channels = channels;
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public MatOfFloat(int channels, Mat m) { public static MatOfFloat fromNativeAddr(long addr) {
return new MatOfFloat(addr);
}
public MatOfFloat(Mat m) {
super(m, Range.all()); super(m, Range.all());
_channels = channels;
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public MatOfFloat(int channels, float...a) { public MatOfFloat(float...a) {
super(); super();
_channels = channels;
fromArray(a); fromArray(a);
} }
...@@ -53,7 +49,9 @@ public class MatOfFloat extends Mat { ...@@ -53,7 +49,9 @@ public class MatOfFloat extends Mat {
} }
public float[] toArray() { public float[] toArray() {
int num = (int) total(); int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
float[] a = new float[num * _channels]; float[] a = new float[num * _channels];
if(num == 0) if(num == 0)
return a; return a;
...@@ -64,7 +62,7 @@ public class MatOfFloat extends Mat { ...@@ -64,7 +62,7 @@ public class MatOfFloat extends Mat {
public void fromList(List<Float> lb) { public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0) if(lb==null || lb.size()==0)
return; return;
Float ab[] = lb.toArray(null); Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length]; float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++) for(int i=0; i<ab.length; i++)
a[i] = ab[i]; a[i] = ab[i];
......
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfFloat4 extends Mat {
// 32FC4
private static final int _depth = CvType.CV_32F;
private static final int _channels = 4;
public MatOfFloat4() {
super();
}
protected MatOfFloat4(long addr) {
super(addr);
if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here?
}
public static MatOfFloat4 fromNativeAddr(long addr) {
return new MatOfFloat4(addr);
}
public MatOfFloat4(Mat m) {
super(m, Range.all());
if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here?
}
public MatOfFloat4(float...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(float...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public float[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
float[] a = new float[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0)
return;
Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Float> toList() {
float[] a = toArray();
Float ab[] = new Float[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfFloat6 extends Mat {
// 32FC6
private static final int _depth = CvType.CV_32F;
private static final int _channels = 6;
public MatOfFloat6() {
super();
}
protected MatOfFloat6(long addr) {
super(addr);
if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here?
}
public static MatOfFloat6 fromNativeAddr(long addr) {
return new MatOfFloat6(addr);
}
public MatOfFloat6(Mat m) {
super(m, Range.all());
if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here?
}
public MatOfFloat6(float...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(float...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public float[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
float[] a = new float[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Float> lb) {
if(lb==null || lb.size()==0)
return;
Float ab[] = lb.toArray(new Float[0]);
float a[] = new float[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Float> toList() {
float[] a = toArray();
Float ab[] = new Float[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}
...@@ -5,38 +5,34 @@ import java.util.List; ...@@ -5,38 +5,34 @@ import java.util.List;
public class MatOfInt extends Mat { public class MatOfInt extends Mat {
// 32SC(x) // 32SC1
private static final int _depth = CvType.CV_32S; private static final int _depth = CvType.CV_32S;
private final int _channels; private static final int _channels = 1;
public MatOfInt(int channels) {
super();
_channels = channels;
}
public MatOfInt() { public MatOfInt() {
this(1); super();
} }
public MatOfInt(int channels, long addr) { protected MatOfInt(long addr) {
super(addr); super(addr);
_channels = channels;
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public MatOfInt(int channels, Mat m) { public static MatOfInt fromNativeAddr(long addr) {
return new MatOfInt(addr);
}
public MatOfInt(Mat m) {
super(m, Range.all()); super(m, Range.all());
_channels = channels;
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public MatOfInt(int channels, int...a) { public MatOfInt(int...a) {
super(); super();
_channels = channels;
fromArray(a); fromArray(a);
} }
...@@ -54,7 +50,9 @@ public class MatOfInt extends Mat { ...@@ -54,7 +50,9 @@ public class MatOfInt extends Mat {
} }
public int[] toArray() { public int[] toArray() {
int num = (int) total(); int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
int[] a = new int[num * _channels]; int[] a = new int[num * _channels];
if(num == 0) if(num == 0)
return a; return a;
...@@ -65,7 +63,7 @@ public class MatOfInt extends Mat { ...@@ -65,7 +63,7 @@ public class MatOfInt extends Mat {
public void fromList(List<Integer> lb) { public void fromList(List<Integer> lb) {
if(lb==null || lb.size()==0) if(lb==null || lb.size()==0)
return; return;
Integer ab[] = lb.toArray(null); Integer ab[] = lb.toArray(new Integer[0]);
int a[] = new int[ab.length]; int a[] = new int[ab.length];
for(int i=0; i<ab.length; i++) for(int i=0; i<ab.length; i++)
a[i] = ab[i]; a[i] = ab[i];
......
package org.opencv.core;
import java.util.Arrays;
import java.util.List;
public class MatOfInt4 extends Mat {
// 32SC4
private static final int _depth = CvType.CV_32S;
private static final int _channels = 4;
public MatOfInt4() {
super();
}
protected MatOfInt4(long addr) {
super(addr);
if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here?
}
public static MatOfInt4 fromNativeAddr(long addr) {
return new MatOfInt4(addr);
}
public MatOfInt4(Mat m) {
super(m, Range.all());
if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here?
}
public MatOfInt4(int...a) {
super();
fromArray(a);
}
public void alloc(int elemNumber) {
if(elemNumber>0)
super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
}
public void fromArray(int...a) {
if(a==null || a.length==0)
return;
int num = a.length / _channels;
alloc(num);
put(0, 0, a); //TODO: check ret val!
}
public int[] toArray() {
int num = checkVector(_channels, _depth);
if(num < 0)
throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
int[] a = new int[num * _channels];
if(num == 0)
return a;
get(0, 0, a); //TODO: check ret val!
return a;
}
public void fromList(List<Integer> lb) {
if(lb==null || lb.size()==0)
return;
Integer ab[] = lb.toArray(new Integer[0]);
int a[] = new int[ab.length];
for(int i=0; i<ab.length; i++)
a[i] = ab[i];
fromArray(a);
}
public List<Integer> toList() {
int[] a = toArray();
Integer ab[] = new Integer[a.length];
for(int i=0; i<a.length; i++)
ab[i] = a[i];
return Arrays.asList(ab);
}
}
...@@ -14,13 +14,17 @@ public class MatOfKeyPoint extends Mat { ...@@ -14,13 +14,17 @@ public class MatOfKeyPoint extends Mat {
super(); super();
} }
public MatOfKeyPoint(long addr) { protected MatOfKeyPoint(long addr) {
super(addr); super(addr);
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public static MatOfKeyPoint fromNativeAddr(long addr) {
return new MatOfKeyPoint(addr);
}
public MatOfKeyPoint(Mat m) { public MatOfKeyPoint(Mat m) {
super(m, Range.all()); super(m, Range.all());
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
...@@ -71,7 +75,7 @@ public class MatOfKeyPoint extends Mat { ...@@ -71,7 +75,7 @@ public class MatOfKeyPoint extends Mat {
} }
public void fromList(List<KeyPoint> lkp) { public void fromList(List<KeyPoint> lkp) {
KeyPoint akp[] = lkp.toArray(null); KeyPoint akp[] = lkp.toArray(new KeyPoint[0]);
fromArray(akp); fromArray(akp);
} }
......
...@@ -12,13 +12,17 @@ public class MatOfPoint extends Mat { ...@@ -12,13 +12,17 @@ public class MatOfPoint extends Mat {
super(); super();
} }
public MatOfPoint(long addr) { protected MatOfPoint(long addr) {
super(addr); super(addr);
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public static MatOfPoint fromNativeAddr(long addr) {
return new MatOfPoint(addr);
}
public MatOfPoint(Mat m) { public MatOfPoint(Mat m) {
super(m, Range.all()); super(m, Range.all());
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
...@@ -63,7 +67,7 @@ public class MatOfPoint extends Mat { ...@@ -63,7 +67,7 @@ public class MatOfPoint extends Mat {
} }
public void fromList(List<Point> lp) { public void fromList(List<Point> lp) {
Point ap[] = lp.toArray(null); Point ap[] = lp.toArray(new Point[0]);
fromArray(ap); fromArray(ap);
} }
......
...@@ -12,13 +12,17 @@ public class MatOfPoint2f extends Mat { ...@@ -12,13 +12,17 @@ public class MatOfPoint2f extends Mat {
super(); super();
} }
public MatOfPoint2f(long addr) { protected MatOfPoint2f(long addr) {
super(addr); super(addr);
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public static MatOfPoint2f fromNativeAddr(long addr) {
return new MatOfPoint2f(addr);
}
public MatOfPoint2f(Mat m) { public MatOfPoint2f(Mat m) {
super(m, Range.all()); super(m, Range.all());
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
...@@ -63,7 +67,7 @@ public class MatOfPoint2f extends Mat { ...@@ -63,7 +67,7 @@ public class MatOfPoint2f extends Mat {
} }
public void fromList(List<Point> lp) { public void fromList(List<Point> lp) {
Point ap[] = lp.toArray(null); Point ap[] = lp.toArray(new Point[0]);
fromArray(ap); fromArray(ap);
} }
......
...@@ -12,13 +12,17 @@ public class MatOfPoint3 extends Mat { ...@@ -12,13 +12,17 @@ public class MatOfPoint3 extends Mat {
super(); super();
} }
public MatOfPoint3(long addr) { protected MatOfPoint3(long addr) {
super(addr); super(addr);
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public static MatOfPoint3 fromNativeAddr(long addr) {
return new MatOfPoint3(addr);
}
public MatOfPoint3(Mat m) { public MatOfPoint3(Mat m) {
super(m, Range.all()); super(m, Range.all());
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
...@@ -64,7 +68,7 @@ public class MatOfPoint3 extends Mat { ...@@ -64,7 +68,7 @@ public class MatOfPoint3 extends Mat {
} }
public void fromList(List<Point3> lp) { public void fromList(List<Point3> lp) {
Point3 ap[] = lp.toArray(null); Point3 ap[] = lp.toArray(new Point3[0]);
fromArray(ap); fromArray(ap);
} }
......
...@@ -12,13 +12,17 @@ public class MatOfPoint3f extends Mat { ...@@ -12,13 +12,17 @@ public class MatOfPoint3f extends Mat {
super(); super();
} }
public MatOfPoint3f(long addr) { protected MatOfPoint3f(long addr) {
super(addr); super(addr);
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public static MatOfPoint3f fromNativeAddr(long addr) {
return new MatOfPoint3f(addr);
}
public MatOfPoint3f(Mat m) { public MatOfPoint3f(Mat m) {
super(m, Range.all()); super(m, Range.all());
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
...@@ -64,7 +68,7 @@ public class MatOfPoint3f extends Mat { ...@@ -64,7 +68,7 @@ public class MatOfPoint3f extends Mat {
} }
public void fromList(List<Point3> lp) { public void fromList(List<Point3> lp) {
Point3 ap[] = lp.toArray(null); Point3 ap[] = lp.toArray(new Point3[0]);
fromArray(ap); fromArray(ap);
} }
......
...@@ -13,13 +13,17 @@ public class MatOfRect extends Mat { ...@@ -13,13 +13,17 @@ public class MatOfRect extends Mat {
super(); super();
} }
public MatOfRect(long addr) { protected MatOfRect(long addr) {
super(addr); super(addr);
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
throw new IllegalArgumentException("Incomatible Mat"); throw new IllegalArgumentException("Incomatible Mat");
//FIXME: do we need release() here? //FIXME: do we need release() here?
} }
public static MatOfRect fromNativeAddr(long addr) {
return new MatOfRect(addr);
}
public MatOfRect(Mat m) { public MatOfRect(Mat m) {
super(m, Range.all()); super(m, Range.all());
if(checkVector(_channels, _depth) < 0 ) if(checkVector(_channels, _depth) < 0 )
...@@ -66,7 +70,7 @@ public class MatOfRect extends Mat { ...@@ -66,7 +70,7 @@ public class MatOfRect extends Mat {
return a; return a;
} }
public void fromList(List<Rect> lr) { public void fromList(List<Rect> lr) {
Rect ap[] = lr.toArray(null); Rect ap[] = lr.toArray(new Rect[0]);
fromArray(ap); fromArray(ap);
} }
......
...@@ -10,6 +10,7 @@ import org.opencv.core.MatOfDMatch; ...@@ -10,6 +10,7 @@ import org.opencv.core.MatOfDMatch;
import org.opencv.core.MatOfKeyPoint; import org.opencv.core.MatOfKeyPoint;
import org.opencv.core.MatOfPoint; import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfPoint2f; import org.opencv.core.MatOfPoint2f;
import org.opencv.core.MatOfPoint3f;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Point3; import org.opencv.core.Point3;
import org.opencv.core.Rect; import org.opencv.core.Rect;
...@@ -519,6 +520,50 @@ public class Converters { ...@@ -519,6 +520,50 @@ public class Converters {
} }
} }
// vector_vector_Point2f
public static Mat vector_vector_Point2f_to_Mat(List<MatOfPoint2f> pts, List<Mat> mats) {
Mat res;
int lCount = (pts != null) ? pts.size() : 0;
if (lCount > 0) {
for (MatOfPoint2f vpt : pts)
mats.add(vpt);
res = vector_Mat_to_Mat(mats);
} else {
res = new Mat();
}
return res;
}
// vector_vector_Point3f
public static void Mat_to_vector_vector_Point3f(Mat m, List<MatOfPoint3f> pts) {
if (pts == null)
throw new java.lang.IllegalArgumentException("Output List can't be null");
if (m == null)
throw new java.lang.IllegalArgumentException("Input Mat can't be null");
List<Mat> mats = new ArrayList<Mat>(m.rows());
Mat_to_vector_Mat(m, mats);
for (Mat mi : mats) {
MatOfPoint3f pt = new MatOfPoint3f(mi);
pts.add(pt);
}
}
// vector_vector_Point3f
public static Mat vector_vector_Point3f_to_Mat(List<MatOfPoint3f> pts, List<Mat> mats) {
Mat res;
int lCount = (pts != null) ? pts.size() : 0;
if (lCount > 0) {
for (MatOfPoint3f vpt : pts)
mats.add(vpt);
res = vector_Mat_to_Mat(mats);
} else {
res = new Mat();
}
return res;
}
// vector_vector_KeyPoint // vector_vector_KeyPoint
public static Mat vector_vector_KeyPoint_to_Mat(List<MatOfKeyPoint> kps, List<Mat> mats) { public static Mat vector_vector_KeyPoint_to_Mat(List<MatOfKeyPoint> kps, List<Mat> mats) {
Mat res; Mat res;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment