Java API: changing C++ vector<T> handling;
authorAndrey Pavlenko <no@email>
Wed, 4 Apr 2012 12:59:53 +0000 (12:59 +0000)
committerAndrey Pavlenko <no@email>
Wed, 4 Apr 2012 12:59:53 +0000 (12:59 +0000)
Java tests fixes are expected shortly

20 files changed:
modules/java/gen_java.py
modules/java/src/cpp/converters.cpp
modules/java/src/cpp/converters.h
modules/java/src/java/core+CvVector.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorByte.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorDMatch.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorDouble.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorFloat.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorFloat4.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorFloat6.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorInt.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorKeyPoint.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorPoint.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorPoint2f.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorPoint3.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorPoint3f.java [new file with mode: 0644]
modules/java/src/java/core+CvVectorRect.java [new file with mode: 0644]
modules/java/src/java/utils+Converters.java
samples/android/face-detection/src/org/opencv/samples/fd/FdView.java
samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java

index 89d4c32..79688aa 100644 (file)
@@ -193,34 +193,36 @@ type_dict = {
 \r
 # "complex" : { j_type : "?", jn_args : (("", ""),), jn_name : "", jni_var : "", jni_name : "", "suffix" : "?" },\r
 \r
-    "vector_Point"    : { "j_type" : "List<Point>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point> %(n)s", "suffix" : "J" },\r
-    "vector_Point2f"  : { "j_type" : "List<Point>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point2f> %(n)s", "suffix" : "J" },\r
-    "vector_Point2d"  : { "j_type" : "List<Point>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point2d> %(n)s", "suffix" : "J" },\r
-    "vector_Point3i"  : { "j_type" : "List<Point3>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3i> %(n)s", "suffix" : "J" },\r
-    "vector_Point3f"  : { "j_type" : "List<Point3>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3f> %(n)s", "suffix" : "J" },\r
-    "vector_Point3d"  : { "j_type" : "List<Point3>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3d> %(n)s", "suffix" : "J" },\r
+    "vector_Point"    : { "j_type" : "CvVectorPoint", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point> %(n)s", "suffix" : "J" },\r
+    "vector_Point2f"  : { "j_type" : "CvVectorPoint2f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point2f> %(n)s", "suffix" : "J" },\r
+    "vector_Point2d"  : { "j_type" : "CvVectorPoint2f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point2d> %(n)s", "suffix" : "J" },\r
+    "vector_Point3i"  : { "j_type" : "CvVectorPoint3", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3i> %(n)s", "suffix" : "J" },\r
+    "vector_Point3f"  : { "j_type" : "CvVectorPoint3f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3f> %(n)s", "suffix" : "J" },\r
+    "vector_Point3d"  : { "j_type" : "CvVectorPoint3f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3d> %(n)s", "suffix" : "J" },\r
+    "vector_KeyPoint" : { "j_type" : "CvVectorKeyPoint", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<KeyPoint> %(n)s", "suffix" : "J" },\r
+    "vector_DMatch"   : { "j_type" : "CvVectorDMatch", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<DMatch> %(n)s", "suffix" : "J" },\r
+    "vector_Rect"     : { "j_type" : "CvVectorRect", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Rect> %(n)s", "suffix" : "J" },\r
+    "vector_uchar"    : { "j_type" : "CvVectorByte", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<uchar> %(n)s", "suffix" : "J" },\r
+    "vector_char"     : { "j_type" : "CvVectorByte", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<char> %(n)s", "suffix" : "J" },\r
+    "vector_int"      : { "j_type" : "CvVectorInt", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<int> %(n)s", "suffix" : "J" },\r
+    "vector_float"    : { "j_type" : "CvVectorFloat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<float> %(n)s", "suffix" : "J" },\r
+    "vector_double"   : { "j_type" : "CvVectorDouble", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<double> %(n)s", "suffix" : "J" },\r
+    "vector_Vec4f"    : { "j_type" : "CvVectorFloat4", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec4f> %(n)s", "suffix" : "J" },\r
+    "vector_Vec6f"    : { "j_type" : "CvVectorFloat6", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec6f> %(n)s", "suffix" : "J" },\r
+\r
     "vector_Mat"      : { "j_type" : "List<Mat>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Mat> %(n)s", "suffix" : "J" },\r
-    "vector_KeyPoint" : { "j_type" : "List<KeyPoint>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<KeyPoint> %(n)s", "suffix" : "J" },\r
-    "vector_DMatch"   : { "j_type" : "List<DMatch>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<DMatch> %(n)s", "suffix" : "J" },\r
-    "vector_Rect"     : { "j_type" : "List<Rect>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Rect> %(n)s", "suffix" : "J" },\r
-    "vector_uchar"    : { "j_type" : "List<Byte>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<uchar> %(n)s", "suffix" : "J" },\r
-    "vector_char"     : { "j_type" : "List<Byte>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<char> %(n)s", "suffix" : "J" },\r
-    "vector_int"      : { "j_type" : "List<Integer>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<int> %(n)s", "suffix" : "J" },\r
-    "vector_float"    : { "j_type" : "List<Float>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<float> %(n)s", "suffix" : "J" },\r
-    "vector_double"   : { "j_type" : "List<Double>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<double> %(n)s", "suffix" : "J" },\r
-    "vector_Vec4f"    : { "j_type" : "Mat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec4f> %(n)s", "suffix" : "J" },\r
-    "vector_Vec6f"    : { "j_type" : "Mat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec6f> %(n)s", "suffix" : "J" },\r
-\r
-    "vector_vector_KeyPoint": { "j_type" : "List<List<KeyPoint>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<KeyPoint> > %(n)s" },\r
-    "vector_vector_DMatch"  : { "j_type" : "List<List<DMatch>>",   "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<DMatch> > %(n)s" },\r
-    "vector_vector_char"    : { "j_type" : "List<List<Byte>>",     "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<char> > %(n)s" },\r
-    "vector_vector_Point"   : { "j_type" : "List<List<Point>>",    "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point> > %(n)s" },\r
-    "vector_vector_Point2f" : { "j_type" : "List<List<Point>>",    "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point2f> > %(n)s" },\r
+\r
+    "vector_vector_KeyPoint": { "j_type" : "List<CvVectorKeyPoint>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<KeyPoint> > %(n)s" },\r
+    "vector_vector_DMatch"  : { "j_type" : "List<CvVectorDMatch>",   "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<DMatch> > %(n)s" },\r
+    "vector_vector_char"    : { "j_type" : "List<CvVectorByte>",     "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<char> > %(n)s" },\r
+    "vector_vector_Point"   : { "j_type" : "List<CvVectorPoint>",    "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point> > %(n)s" },\r
+    "vector_vector_Point2f" : { "j_type" : "List<CvVectorPoint2f>",    "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point2f> > %(n)s" },\r
 \r
     "Mat"     : { "j_type" : "Mat", "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),\r
                   "jni_var" : "Mat& %(n)s = *((Mat*)%(n)s_nativeObj)",\r
                   "jni_type" : "jlong", #"jni_name" : "*%(n)s",\r
                   "suffix" : "J" },\r
+\r
     "Point"   : { "j_type" : "Point", "jn_args" : (("double", ".x"), ("double", ".y")),\r
                   "jni_var" : "Point %(n)s((int)%(n)s_x, (int)%(n)s_y)", "jni_type" : "jdoubleArray",\r
                   "suffix" : "DD"},\r
@@ -510,7 +512,6 @@ func_arg_fix = {
         'boundingRect' : { 'points' : 'vector_Point', },\r
         'approxPolyDP' : { 'curve' : 'vector_Point2f', 'approxCurve' : 'vector_Point2f', },\r
         'arcLength' : { 'curve' : 'vector_Point2f', },\r
-        'isContourConvex' : { 'contour' : 'vector_Point2f', },\r
         'pointPolygonTest' : { 'contour' : 'vector_Point2f', },\r
         'minAreaRect' : { 'points' : 'vector_Point2f', },\r
         'getAffineTransform' : { 'src' : 'vector_Point2f', 'dst' : 'vector_Point2f', },\r
@@ -519,6 +520,10 @@ func_arg_fix = {
         'undistortPoints' : { 'src' : 'vector_Point2d', 'dst' : 'vector_Point2d' },\r
         'checkRange' : {'pos' : '*'},\r
         'meanStdDev' : {'mean' : 'vector_double', 'stddev' : 'vector_double'},\r
+        'drawContours' : {'contours' : 'vector_vector_Point'},\r
+        'findContours' : {'contours' : 'vector_vector_Point'},\r
+        'convexityDefects' : {'contour' : 'vector_Point'},\r
+        'isContourConvex' : { 'contour' : 'vector_Point2f', },\r
     }, # '', i.e. no class\r
 } # func_arg_fix\r
 \r
@@ -891,9 +896,13 @@ extern "C" {
     def get_imports(self, scope_classname, ctype):\r
         imports = self.classes[scope_classname or self.Module].imports\r
         if ctype.startswith('vector'):\r
-            imports.add("java.util.List")\r
             imports.add("org.opencv.core.Mat")\r
-            imports.add("org.opencv.utils.Converters")\r
+            if type_dict[ctype]['j_type'].startswith('CvVector'):\r
+                imports.add("org.opencv.core." + type_dict[ctype]['j_type'])\r
+                return #TMP\r
+            else:\r
+                imports.add("java.util.List")\r
+                imports.add("org.opencv.utils.Converters")\r
             ctype = ctype.replace('vector_', '')\r
         j_type = ''\r
         if ctype in type_dict:\r
@@ -992,15 +1001,18 @@ extern "C" {
                             j_prologue.append( "List<Mat> %(n)s_tmplm = new ArrayList<Mat>((%(n)s != null) ? %(n)s.size() : 0);" % {"n" : a.name } )\r
                             j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s, %(n)s_tmplm);" % {"n" : a.name, "t" : a.ctype} )\r
                         else:\r
-                            j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s);" % {"n" : a.name, "t" : a.ctype} )\r
+                            if not type_dict[a.ctype]["j_type"].startswith("CvVector"):\r
+                                j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s);" % {"n" : a.name, "t" : a.ctype} )\r
+                            else:\r
+                                j_prologue.append( "Mat %s_mat = %s;" % (a.name, a.name) )\r
                         c_prologue.append( "Mat_to_%(t)s( %(n)s_mat, %(n)s );" % {"n" : a.name, "t" : a.ctype} )\r
                     else:\r
-                        if type_dict[a.ctype]["j_type"] != "Mat":\r
+                        if not type_dict[a.ctype]["j_type"].startswith("CvVector"):\r
                             j_prologue.append( "Mat %s_mat = new Mat();" % a.name )\r
                         else:\r
                             j_prologue.append( "Mat %s_mat = %s;" % (a.name, a.name) )\r
                     if "O" in a.out:\r
-                        if type_dict[a.ctype]["j_type"] != "Mat":\r
+                        if not type_dict[a.ctype]["j_type"].startswith("CvVector"):\r
                             j_epilogue.append("Converters.Mat_to_%(t)s(%(n)s_mat, %(n)s);" % {"t" : a.ctype, "n" : a.name})\r
                         c_epilogue.append( "%(t)s_to_Mat( %(n)s, %(n)s_mat );" % {"n" : a.name, "t" : a.ctype} )\r
                 else:\r
@@ -1060,12 +1072,15 @@ extern "C" {
             tail = ""\r
             ret = "return retVal;"\r
             if ret_type.startswith('vector'):\r
-                ret_val = "Mat retValMat = new Mat("\r
                 tail = ")"\r
                 j_type = type_dict[ret_type]["j_type"]\r
-                j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')\r
-                self.classes[fi.classname or self.Module].imports.add('java.util.ArrayList')\r
-                j_epilogue.append('Converters.Mat_to_' + ret_type + '(retValMat, retVal);')\r
+                if j_type.startswith('CvVector'):\r
+                    ret_val += "new " + j_type + "("\r
+                else:\r
+                    ret_val = "Mat retValMat = new Mat("\r
+                    j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')\r
+                    self.classes[fi.classname or self.Module].imports.add('java.util.ArrayList')\r
+                    j_epilogue.append('Converters.Mat_to_' + ret_type + '(retValMat, retVal);')\r
             elif ret_type == "void":\r
                 ret_val = ""\r
                 ret = "return;"\r
index 7e1f4cf..7d7b092 100644 (file)
@@ -185,11 +185,11 @@ void vector_Point3d_to_Mat(vector<Point3d>& v_point, Mat& mat)
 void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)\r
 {\r
     v_kp.clear();\r
-    CHECK_MAT(mat.type()==CV_64FC(7) && mat.cols==1);\r
+    CHECK_MAT(mat.type()==CV_32FC(7) && mat.cols==1);\r
     for(int i=0; i<mat.rows; i++)\r
     {\r
-        Vec<double, 7> v = mat.at< Vec<double, 7> >(i, 0);\r
-        KeyPoint kp((float)v[0], (float)v[1], (float)v[2], (float)v[3], (float)v[4], (int)v[5], (int)v[6]);\r
+        Vec<float, 7> v = mat.at< Vec<float, 7> >(i, 0);\r
+        KeyPoint kp(v[0], v[1], v[2], v[3], v[4], (int)v[5], (int)v[6]);\r
         v_kp.push_back(kp);\r
     }\r
     return;\r
@@ -199,11 +199,11 @@ void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
 void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat)\r
 {\r
     int count = v_kp.size();\r
-    mat.create(count, 1, CV_64FC(7));\r
+    mat.create(count, 1, CV_32FC(7));\r
     for(int i=0; i<count; i++)\r
     {\r
         KeyPoint kp = v_kp[i];\r
-        mat.at< Vec<double, 7> >(i, 0) = Vec<double, 7>(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id);\r
+        mat.at< Vec<float, 7> >(i, 0) = Vec<float, 7>(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id);\r
     }\r
 }\r
 #endif\r
@@ -245,11 +245,11 @@ void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
 void Mat_to_vector_DMatch(Mat& mat, vector<DMatch>& v_dm)\r
 {\r
     v_dm.clear();\r
-    CHECK_MAT(mat.type()==CV_64FC4 && mat.cols==1);\r
+    CHECK_MAT(mat.type()==CV_32FC4 && mat.cols==1);\r
     for(int i=0; i<mat.rows; i++)\r
     {\r
-        Vec<double, 4> v = mat.at< Vec<double, 4> >(i, 0);\r
-        DMatch dm((int)v[0], (int)v[1], (int)v[2], (float)v[3]);\r
+        Vec<float, 4> v = mat.at< Vec<float, 4> >(i, 0);\r
+        DMatch dm((int)v[0], (int)v[1], (int)v[2], v[3]);\r
         v_dm.push_back(dm);\r
     }\r
     return;\r
@@ -259,11 +259,11 @@ void Mat_to_vector_DMatch(Mat& mat, vector<DMatch>& v_dm)
 void vector_DMatch_to_Mat(vector<DMatch>& v_dm, Mat& mat)\r
 {\r
     int count = v_dm.size();\r
-    mat.create(count, 1, CV_64FC4);\r
+    mat.create(count, 1, CV_32FC4);\r
     for(int i=0; i<count; i++)\r
     {\r
         DMatch dm = v_dm[i];\r
-        mat.at< Vec<double, 4> >(i, 0) = Vec<double, 4>(dm.queryIdx, dm.trainIdx, dm.imgIdx, dm.distance);\r
+        mat.at< Vec<float, 4> >(i, 0) = Vec<float, 4>(dm.queryIdx, dm.trainIdx, dm.imgIdx, dm.distance);\r
     }\r
 }\r
 #endif\r
@@ -374,6 +374,19 @@ void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat)
     vector_Mat_to_Mat(vm, mat);\r
 }\r
 \r
+void vector_vector_Point_to_Mat(vector< vector< Point > >& vv_pt, Mat& mat)\r
+{\r
+    vector<Mat> vm;\r
+    vm.reserve( vv_pt.size() );\r
+    for(size_t i=0; i<vv_pt.size(); i++)\r
+    {\r
+        Mat m;\r
+        vector_Point_to_Mat(vv_pt[i], m);\r
+        vm.push_back(m);\r
+    }\r
+    vector_Mat_to_Mat(vm, mat);\r
+}\r
+\r
 void vector_Vec4f_to_Mat(vector<Vec4f>& v_vec, Mat& mat)\r
 {\r
     mat = Mat(v_vec, true);\r
index e1118e9..b1105ca 100644 (file)
@@ -64,4 +64,5 @@ void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Ma
 \r
 void Mat_to_vector_vector_Point(cv::Mat& mat, std::vector< std::vector< cv::Point > >& vv_pt);\r
 void vector_vector_Point2f_to_Mat(std::vector< std::vector< cv::Point2f > >& vv_pt, cv::Mat& mat);\r
+void vector_vector_Point_to_Mat(std::vector< std::vector< cv::Point > >& vv_pt, cv::Mat& mat);\r
 \r
diff --git a/modules/java/src/java/core+CvVector.java b/modules/java/src/java/core+CvVector.java
new file mode 100644 (file)
index 0000000..11fafca
--- /dev/null
@@ -0,0 +1,35 @@
+package org.opencv.core;\r
+\r
+public class CvVector extends Mat {\r
+    protected int depth;\r
+    protected int channels;\r
+\r
+    protected CvVector(int d, int ch) {\r
+        super();\r
+        depth = d;\r
+        channels = ch;\r
+    }\r
+\r
+    protected CvVector(int d, int ch, long addr) {\r
+        super(addr);\r
+        depth = d;\r
+        channels = ch;\r
+        if( !empty() && checkVector(channels, depth) < 0 )\r
+            throw new IllegalArgumentException("Incomatible Mat");\r
+        //FIXME: do we need release() here?\r
+    }\r
+\r
+    protected CvVector(int d, int ch, Mat m) {\r
+        super(m, Range.all());\r
+        depth = d;\r
+        channels = ch;\r
+        if( !empty() && checkVector(channels, depth) < 0 )\r
+            throw new IllegalArgumentException("Incomatible Mat");\r
+        //FIXME: do we need release() here?\r
+    }\r
+\r
+    protected void create(int cnt) {\r
+        if(cnt>0)\r
+            super.create(cnt, 1, CvType.makeType(depth, channels));\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorByte.java b/modules/java/src/java/core+CvVectorByte.java
new file mode 100644 (file)
index 0000000..656eb9f
--- /dev/null
@@ -0,0 +1,42 @@
+package org.opencv.core;\r
+\r
+public class CvVectorByte extends CvVector {\r
+    private static final int _d = CvType.CV_8U;\r
+\r
+    public CvVectorByte(int ch) {\r
+        super(_d, ch);\r
+    }\r
+\r
+    public CvVectorByte(int ch, long addr) {\r
+        super(_d, ch, addr);\r
+    }\r
+\r
+    public CvVectorByte(long addr) {\r
+        super(_d, 1, addr);\r
+    }\r
+\r
+    public CvVectorByte(int ch, Mat m) {\r
+        super(_d, ch, m);\r
+    }\r
+\r
+    public CvVectorByte(int ch, byte[] a) {\r
+        super(_d, ch);\r
+        if(a!=null) {\r
+            int cnt = a.length / ch;\r
+            create(cnt);\r
+            put(0, 0, a);\r
+        }\r
+    }\r
+\r
+    public byte[] toArray(byte[] a) {\r
+        int cnt = (int) total() * channels;\r
+        if(cnt == 0)\r
+            return new byte[0];//null;\r
+        byte[] res = a;\r
+        if(res==null || res.length<cnt)\r
+            res = new byte[cnt];\r
+        get(0, 0, res); //TODO: check ret val!\r
+        return res;\r
+    }\r
+\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorDMatch.java b/modules/java/src/java/core+CvVectorDMatch.java
new file mode 100644 (file)
index 0000000..5e47436
--- /dev/null
@@ -0,0 +1,49 @@
+package org.opencv.core;\r
+\r
+import org.opencv.features2d.DMatch;\r
+\r
+public class CvVectorDMatch extends CvVectorFloat {\r
+    private static final int _ch = 4; //xxxC4\r
+\r
+    public CvVectorDMatch() {\r
+        super(_ch);\r
+    }\r
+\r
+    public CvVectorDMatch(long addr) {\r
+        super(_ch, addr);\r
+    }\r
+\r
+    public CvVectorDMatch(Mat m) {\r
+        super(_ch, m);\r
+    }\r
+\r
+    public CvVectorDMatch(DMatch[] a) {\r
+        super(_ch);\r
+        if(a==null)\r
+            return;\r
+        int cnt = a.length;\r
+        create(cnt);\r
+        float buff[] = new float[_ch * cnt];\r
+        for(int i=0; i<cnt; i++) {\r
+               DMatch m = a[i];\r
+            buff[_ch*i+0] = m.queryIdx;\r
+            buff[_ch*i+1] = m.trainIdx;\r
+            buff[_ch*i+2] = m.imgIdx;\r
+            buff[_ch*i+3] = m.distance;\r
+        }\r
+        put(0, 0, buff); //TODO: check ret val!\r
+    }\r
+\r
+    public DMatch[] toArray(DMatch[] a) {\r
+       float buff[] = super.toArray(null);\r
+        if(buff.length == 0)\r
+            return new DMatch[0]; //null;\r
+        int cnt = buff.length / _ch;\r
+        DMatch[] res = a;\r
+        if(a==null || a.length<cnt)\r
+            res = new DMatch[cnt];\r
+        for(int i=0; i<cnt; i++)\r
+            res[i] = new DMatch((int) buff[_ch*i+0], (int) buff[_ch*i+1], (int) buff[_ch*i+2], buff[_ch*i+3]);\r
+        return res;\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorDouble.java b/modules/java/src/java/core+CvVectorDouble.java
new file mode 100644 (file)
index 0000000..6721359
--- /dev/null
@@ -0,0 +1,37 @@
+package org.opencv.core;\r
+\r
+public class CvVectorDouble extends CvVector {\r
+       private static final int _d = CvType.CV_64F;\r
+       \r
+    public CvVectorDouble(int ch) {\r
+        super(_d, ch);\r
+    }\r
+\r
+    public CvVectorDouble(int ch, long addr) {\r
+        super(_d, ch, addr);\r
+    }\r
+\r
+    public CvVectorDouble(int ch, Mat m) {\r
+        super(_d, ch, m);\r
+    }\r
+\r
+    public CvVectorDouble(int ch, double[] a) {\r
+        super(_d, ch);\r
+        if(a!=null) {\r
+               int cnt = a.length / ch;\r
+               create(cnt);\r
+               put(0, 0, a);\r
+        }\r
+    }\r
+\r
+    public double[] toArray(double[] a) {\r
+        int cnt = (int) total() * channels;\r
+        if(cnt == 0)\r
+            return new double[0];//null;\r
+        double[] res = a;\r
+        if(res==null || res.length<cnt)\r
+            res = new double[cnt];\r
+        get(0, 0, res); //TODO: check ret val!\r
+        return res;\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorFloat.java b/modules/java/src/java/core+CvVectorFloat.java
new file mode 100644 (file)
index 0000000..a0a5091
--- /dev/null
@@ -0,0 +1,41 @@
+package org.opencv.core;\r
+\r
+public class CvVectorFloat extends CvVector {\r
+    private static final int _d = CvType.CV_32F;\r
+\r
+    public CvVectorFloat(int ch) {\r
+        super(_d, ch);\r
+    }\r
+\r
+    public CvVectorFloat(int ch, long addr) {\r
+        super(_d, ch, addr);\r
+    }\r
+\r
+    public CvVectorFloat(long addr) {\r
+        super(_d, 1, addr);\r
+    }\r
+\r
+    public CvVectorFloat(int ch, Mat m) {\r
+        super(_d, ch, m);\r
+    }\r
+\r
+    public CvVectorFloat(int ch, float[] a) {\r
+        super(_d, ch);\r
+        if(a!=null) {\r
+            int cnt = a.length / ch;\r
+            create(cnt);\r
+            put(0, 0, a);\r
+        }\r
+    }\r
+\r
+    public float[] toArray(float[] a) {\r
+        int cnt = (int) total() * channels;\r
+        if(cnt == 0)\r
+            return new float[0];//null;\r
+        float[] res = a;\r
+        if(res==null || res.length<cnt)\r
+            res = new float[cnt];\r
+        get(0, 0, res); //TODO: check ret val!\r
+        return res;\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorFloat4.java b/modules/java/src/java/core+CvVectorFloat4.java
new file mode 100644 (file)
index 0000000..0947ddb
--- /dev/null
@@ -0,0 +1,22 @@
+package org.opencv.core;\r
+\r
+public class CvVectorFloat4 extends CvVectorFloat {\r
+    private static final int _ch = 4; //xxxC4\r
+\r
+    public CvVectorFloat4() {\r
+        super(_ch);\r
+    }\r
+\r
+    public CvVectorFloat4(long addr) {\r
+        super(_ch, addr);\r
+    }\r
+\r
+    public CvVectorFloat4(Mat m) {\r
+        super(_ch, m);\r
+    }\r
+\r
+    public CvVectorFloat4(float[] a) {\r
+        super(_ch, a);\r
+    }\r
+\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorFloat6.java b/modules/java/src/java/core+CvVectorFloat6.java
new file mode 100644 (file)
index 0000000..9294d75
--- /dev/null
@@ -0,0 +1,21 @@
+package org.opencv.core;\r
+\r
+public class CvVectorFloat6 extends CvVectorFloat {\r
+    private static final int _ch = 6; //xxxC6\r
+\r
+    public CvVectorFloat6() {\r
+        super(_ch);\r
+    }\r
+\r
+    public CvVectorFloat6(long addr) {\r
+        super(_ch, addr);\r
+    }\r
+\r
+    public CvVectorFloat6(Mat m) {\r
+        super(_ch, m);\r
+    }\r
+\r
+    public CvVectorFloat6(float[] a) {\r
+        super(_ch, a);\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorInt.java b/modules/java/src/java/core+CvVectorInt.java
new file mode 100644 (file)
index 0000000..5993ae2
--- /dev/null
@@ -0,0 +1,38 @@
+package org.opencv.core;\r
+\r
+\r
+public class CvVectorInt extends CvVector {\r
+       private static final int _d = CvType.CV_32S;\r
+       \r
+    public CvVectorInt(int ch) {\r
+        super(_d, ch);\r
+    }\r
+\r
+    public CvVectorInt(int ch, long addr) {\r
+        super(_d, ch, addr);\r
+    }\r
+\r
+    public CvVectorInt(int ch, Mat m) {\r
+        super(_d, ch, m);\r
+    }\r
+\r
+    public CvVectorInt(int ch, int[] a) {\r
+        super(_d, ch);\r
+        if(a!=null) {\r
+               int cnt = a.length / ch;\r
+               create(cnt);\r
+               put(0, 0, a);\r
+        }\r
+    }\r
+\r
+    public int[] toArray(int[] a) {\r
+        int cnt = (int) total() * channels;\r
+        if(cnt == 0)\r
+            return new int[0];//null;\r
+        int[] res = a;\r
+        if(res==null || res.length<cnt)\r
+            res = new int[cnt];\r
+        get(0, 0, res); //TODO: check ret val!\r
+        return res;\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorKeyPoint.java b/modules/java/src/java/core+CvVectorKeyPoint.java
new file mode 100644 (file)
index 0000000..36b87de
--- /dev/null
@@ -0,0 +1,53 @@
+package org.opencv.core;\r
+\r
+import org.opencv.features2d.KeyPoint;\r
+\r
+public class CvVectorKeyPoint extends CvVectorFloat {\r
+    private static final int _ch = 7; //xxxC7\r
+\r
+    public CvVectorKeyPoint() {\r
+        super(_ch);\r
+    }\r
+\r
+    public CvVectorKeyPoint(long addr) {\r
+        super(_ch, addr);\r
+    }\r
+\r
+    public CvVectorKeyPoint(Mat m) {\r
+        super(_ch, m);\r
+    }\r
+\r
+    public CvVectorKeyPoint(KeyPoint[] a) {\r
+        super(_ch);\r
+        if(a==null)\r
+            return;\r
+        int cnt = a.length;\r
+        create(cnt);\r
+        float buff[] = new float[_ch * cnt];\r
+        for(int i=0; i<cnt; i++) {\r
+               KeyPoint kp = a[i];\r
+            buff[_ch*i+0] = (float) kp.pt.x;\r
+            buff[_ch*i+1] = (float) kp.pt.y;\r
+            buff[_ch*i+2] = kp.size;\r
+            buff[_ch*i+3] = kp.angle;\r
+            buff[_ch*i+4] = kp.response;\r
+            buff[_ch*i+5] = kp.octave;\r
+            buff[_ch*i+6] = kp.class_id;\r
+        }\r
+        put(0, 0, buff); //TODO: check ret val!\r
+    }\r
+\r
+    public KeyPoint[] toArray(KeyPoint[] a) {\r
+       float buff[] = super.toArray(null);\r
+        if(buff.length == 0)\r
+            return new KeyPoint[0]; //null;\r
+        int cnt = buff.length / _ch;\r
+        KeyPoint[] res = a;\r
+        if(a==null || a.length<cnt)\r
+            res = new KeyPoint[cnt];\r
+        for(int i=0; i<cnt; i++)\r
+            res[i] = new KeyPoint( buff[_ch*i+0], buff[_ch*i+1], buff[_ch*i+2], buff[_ch*i+3],\r
+                                          buff[_ch*i+4], (int) buff[_ch*i+5], (int) buff[_ch*i+6] );\r
+        return res;\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorPoint.java b/modules/java/src/java/core+CvVectorPoint.java
new file mode 100644 (file)
index 0000000..b8c9e26
--- /dev/null
@@ -0,0 +1,45 @@
+package org.opencv.core;\r
+\r
+public class CvVectorPoint extends CvVectorInt {\r
+    private static final int _ch = 2; //xxxC2\r
+\r
+    public CvVectorPoint() {\r
+        super(_ch);\r
+    }\r
+\r
+    public CvVectorPoint(long addr) {\r
+        super(_ch, addr);\r
+    }\r
+\r
+    public CvVectorPoint(Mat m) {\r
+        super(_ch, m);\r
+    }\r
+\r
+    public CvVectorPoint(Point[] a) {\r
+        super(_ch);\r
+        if(a==null)\r
+            return;\r
+        int cnt = a.length;\r
+        create(cnt);\r
+        int buff[] = new int[_ch * cnt];\r
+        for(int i=0; i<cnt; i++) {\r
+               Point p = a[i];\r
+            buff[_ch*i+0] = (int) p.x;\r
+            buff[_ch*i+1] = (int) p.y;\r
+        }\r
+        put(0, 0, buff); //TODO: check ret val!\r
+    }\r
+\r
+    public Point[] toArray(Point[] a) {\r
+        int buff[] = super.toArray(null);\r
+        if(buff.length == 0)\r
+            return new Point[0]; //null;\r
+        int cnt = buff.length / _ch;\r
+        Point[] res = a;\r
+        if(a==null || a.length<cnt)\r
+            res = new Point[cnt];\r
+        for(int i=0; i<cnt; i++)\r
+            res[i] = new Point(buff[i*_ch], buff[i*_ch+1]);\r
+        return res;\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorPoint2f.java b/modules/java/src/java/core+CvVectorPoint2f.java
new file mode 100644 (file)
index 0000000..1b1ad11
--- /dev/null
@@ -0,0 +1,45 @@
+package org.opencv.core;\r
+\r
+public class CvVectorPoint2f extends CvVectorFloat {\r
+    private static final int _ch = 2; //xxxC2\r
+\r
+    public CvVectorPoint2f() {\r
+        super(_ch);\r
+    }\r
+\r
+    public CvVectorPoint2f(long addr) {\r
+        super(_ch, addr);\r
+    }\r
+\r
+    public CvVectorPoint2f(Mat m) {\r
+        super(_ch, m);\r
+    }\r
+\r
+    public CvVectorPoint2f(Point[] a) {\r
+        super(_ch);\r
+        if(a==null)\r
+            return;\r
+        int cnt = a.length;\r
+        create(cnt);\r
+        float buff[] = new float[_ch * cnt];\r
+        for(int i=0; i<cnt; i++) {\r
+               Point p = a[i];\r
+            buff[_ch*i+0] = (float) p.x;\r
+            buff[_ch*i+1] = (float) p.y;\r
+        }\r
+        put(0, 0, buff); //TODO: check ret val!\r
+    }\r
+\r
+    public Point[] toArray(Point[] a) {\r
+        float buff[] = super.toArray(null);\r
+        if(buff.length == 0)\r
+            return new Point[0]; //null;\r
+        int cnt = buff.length / _ch;\r
+        Point[] res = a;\r
+        if(a==null || a.length<cnt)\r
+            res = new Point[cnt];\r
+        for(int i=0; i<cnt; i++)\r
+            res[i] = new Point(buff[i*_ch], buff[i*_ch+1]);\r
+        return res;\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorPoint3.java b/modules/java/src/java/core+CvVectorPoint3.java
new file mode 100644 (file)
index 0000000..64cd462
--- /dev/null
@@ -0,0 +1,46 @@
+package org.opencv.core;\r
+\r
+public class CvVectorPoint3 extends CvVectorInt {\r
+    private static final int _ch = 3; //xxxC2\r
+\r
+    public CvVectorPoint3() {\r
+        super(_ch);\r
+    }\r
+\r
+    public CvVectorPoint3(long addr) {\r
+        super(_ch, addr);\r
+    }\r
+\r
+    public CvVectorPoint3(Mat m) {\r
+        super(_ch, m);\r
+    }\r
+\r
+    public CvVectorPoint3(Point3[] a) {\r
+        super(_ch);\r
+        if(a==null)\r
+            return;\r
+        int cnt = a.length;\r
+        create(cnt);\r
+        int buff[] = new int[_ch * cnt];\r
+        for(int i=0; i<cnt; i++) {\r
+               Point3 p = a[i];\r
+            buff[_ch*i]   = (int) p.x;\r
+            buff[_ch*i+1] = (int) p.y;\r
+            buff[_ch*i+2] = (int) p.z;\r
+        }\r
+        put(0, 0, buff); //TODO: check ret val!\r
+    }\r
+\r
+    public Point3[] toArray(Point3[] a) {\r
+        int buff[] = super.toArray(null);\r
+        if(buff.length == 0)\r
+            return new Point3[0]; //null;\r
+        int cnt = buff.length / _ch;\r
+        Point3[] res = a;\r
+        if(a==null || a.length<cnt)\r
+            res = new Point3[cnt];\r
+        for(int i=0; i<cnt; i++)\r
+            res[i] = new Point3(buff[i*_ch], buff[i*_ch+1], buff[i*_ch+2]);\r
+        return res;\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorPoint3f.java b/modules/java/src/java/core+CvVectorPoint3f.java
new file mode 100644 (file)
index 0000000..c3132b6
--- /dev/null
@@ -0,0 +1,46 @@
+package org.opencv.core;\r
+\r
+public class CvVectorPoint3f extends CvVectorFloat {\r
+    private static final int _ch = 3; //xxxC2\r
+\r
+    public CvVectorPoint3f() {\r
+        super(_ch);\r
+    }\r
+\r
+    public CvVectorPoint3f(long addr) {\r
+        super(_ch, addr);\r
+    }\r
+\r
+    public CvVectorPoint3f(Mat m) {\r
+        super(_ch, m);\r
+    }\r
+\r
+    public CvVectorPoint3f(Point3[] a) {\r
+        super(_ch);\r
+        if(a==null)\r
+            return;\r
+        int cnt = a.length;\r
+        create(cnt);\r
+        float buff[] = new float[_ch * cnt];\r
+        for(int i=0; i<cnt; i++) {\r
+               Point3 p = a[i];\r
+            buff[_ch*i]   = (float) p.x;\r
+            buff[_ch*i+1] = (float) p.y;\r
+            buff[_ch*i+2] = (float) p.z;\r
+        }\r
+        put(0, 0, buff); //TODO: check ret val!\r
+    }\r
+\r
+    public Point3[] toArray(Point3[] a) {\r
+        float buff[] = super.toArray(null);\r
+        if(buff.length == 0)\r
+            return new Point3[0]; //null;\r
+        int cnt = buff.length / _ch;\r
+        Point3[] res = a;\r
+        if(a==null || a.length<cnt)\r
+            res = new Point3[cnt];\r
+        for(int i=0; i<cnt; i++)\r
+            res[i] = new Point3(buff[i*_ch], buff[i*_ch+1], buff[i*_ch+2]);\r
+        return res;\r
+    }\r
+}\r
diff --git a/modules/java/src/java/core+CvVectorRect.java b/modules/java/src/java/core+CvVectorRect.java
new file mode 100644 (file)
index 0000000..e6e3688
--- /dev/null
@@ -0,0 +1,48 @@
+package org.opencv.core;\r
+\r
+\r
+public class CvVectorRect extends CvVectorInt {\r
+    private static final int _ch = 4; //xxxC4\r
+\r
+    public CvVectorRect() {\r
+        super(_ch);\r
+    }\r
+\r
+    public CvVectorRect(long addr) {\r
+        super(_ch, addr);\r
+    }\r
+\r
+    public CvVectorRect(Mat m) {\r
+        super(_ch, m);\r
+    }\r
+\r
+    public CvVectorRect(Rect[] a) {\r
+        super(_ch);\r
+        if(a==null)\r
+            return;\r
+        int cnt = a.length;\r
+        create(cnt);\r
+        int buff[] = new int[_ch * cnt];\r
+        for(int i=0; i<cnt; i++) {\r
+               Rect r = a[i];\r
+            buff[_ch*i]   = r.x;\r
+            buff[_ch*i+1] = r.y;\r
+            buff[_ch*i+2] = r.width;\r
+            buff[_ch*i+3] = r.height;\r
+        }\r
+        put(0, 0, buff); //TODO: check ret val!\r
+    }\r
+\r
+    public Rect[] toArray(Rect[] a) {\r
+        int buff[] = super.toArray(null);\r
+        if(buff.length == 0)\r
+            return new Rect[0]; //null;\r
+        int cnt = buff.length / _ch;\r
+        Rect[] res = a;\r
+        if(a==null || a.length<cnt)\r
+            res = new Rect[cnt];\r
+        for(int i=0; i<cnt; i++)\r
+            res[i] = new Rect(buff[i*_ch], buff[i*_ch+1], buff[i*_ch+2], buff[i*_ch+3]);\r
+        return res;\r
+    }\r
+}\r
index 4ebbd1b..1b5555a 100644 (file)
@@ -3,11 +3,16 @@ package org.opencv.utils;
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
-import org.opencv.core.Mat;\r
 import org.opencv.core.CvType;\r
+import org.opencv.core.CvVectorPoint2f;\r
+import org.opencv.core.Mat;\r
 import org.opencv.core.Point;\r
 import org.opencv.core.Point3;\r
 import org.opencv.core.Rect;\r
+import org.opencv.core.CvVectorByte;\r
+import org.opencv.core.CvVectorDMatch;\r
+import org.opencv.core.CvVectorKeyPoint;\r
+import org.opencv.core.CvVectorPoint;\r
 import org.opencv.features2d.DMatch;\r
 import org.opencv.features2d.KeyPoint;\r
 \r
@@ -468,14 +473,14 @@ public class Converters {
                     (float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6]));\r
         }\r
     }\r
-       \r
+\r
     // vector_vector_Point\r
-    public static Mat vector_vector_Point_to_Mat(List<List<Point>> pts, List<Mat> mats) {\r
+    public static Mat vector_vector_Point_to_Mat(List<CvVectorPoint> pts, List<Mat> mats) {\r
         Mat res;\r
         int lCount = (pts != null) ? pts.size() : 0;\r
         if (lCount > 0) {\r
-            for (List<Point> lpt : pts)\r
-                mats.add(vector_Point_to_Mat(lpt));\r
+            for (CvVectorPoint vpt : pts)\r
+                mats.add(vpt);\r
             res = vector_Mat_to_Mat(mats);\r
         } else {\r
             res = new Mat();\r
@@ -483,8 +488,23 @@ public class Converters {
         return res;\r
     }\r
 \r
+    public static void Mat_to_vector_vector_Point(Mat m, List<CvVectorPoint> pts) {\r
+        if (pts == null)\r
+            throw new java.lang.IllegalArgumentException("Output List can't be null");\r
+\r
+        if (m == null)\r
+            throw new java.lang.IllegalArgumentException("Input Mat can't be null");\r
+\r
+        List<Mat> mats = new ArrayList<Mat>(m.rows());\r
+        Mat_to_vector_Mat(m, mats);\r
+        for (Mat mi : mats) {\r
+            CvVectorPoint pt = new CvVectorPoint(mi);\r
+            pts.add(pt);\r
+        }\r
+    }\r
+\r
     // vector_vector_Point2f\r
-    public static void Mat_to_vector_vector_Point2f(Mat m, List<List<Point>> pts) {\r
+    public static void Mat_to_vector_vector_Point2f(Mat m, List<CvVectorPoint2f> pts) {\r
         if (pts == null)\r
             throw new java.lang.IllegalArgumentException("Output List can't be null");\r
 \r
@@ -494,19 +514,18 @@ public class Converters {
         List<Mat> mats = new ArrayList<Mat>(m.rows());\r
         Mat_to_vector_Mat(m, mats);\r
         for (Mat mi : mats) {\r
-            List<Point> pt = new ArrayList<Point>();\r
-            Mat_to_vector_Point2f(mi, pt);\r
+            CvVectorPoint2f pt = new CvVectorPoint2f(mi);\r
             pts.add(pt);\r
         }\r
     }\r
 \r
     // vector_vector_KeyPoint\r
-    public static Mat vector_vector_KeyPoint_to_Mat(List<List<KeyPoint>> kps, List<Mat> mats) {\r
+    public static Mat vector_vector_KeyPoint_to_Mat(List<CvVectorKeyPoint> kps, List<Mat> mats) {\r
         Mat res;\r
         int lCount = (kps != null) ? kps.size() : 0;\r
         if (lCount > 0) {\r
-            for (List<KeyPoint> lkp : kps)\r
-                mats.add(vector_KeyPoint_to_Mat(lkp));\r
+            for (CvVectorKeyPoint vkp : kps)\r
+                mats.add(vkp);\r
             res = vector_Mat_to_Mat(mats);\r
         } else {\r
             res = new Mat();\r
@@ -514,7 +533,7 @@ public class Converters {
         return res;\r
     }\r
 \r
-    public static void Mat_to_vector_vector_KeyPoint(Mat m, List<List<KeyPoint>> kps) {\r
+    public static void Mat_to_vector_vector_KeyPoint(Mat m, List<CvVectorKeyPoint> kps) {\r
         if (kps == null)\r
             throw new java.lang.IllegalArgumentException("Output List can't be null");\r
 \r
@@ -524,9 +543,8 @@ public class Converters {
         List<Mat> mats = new ArrayList<Mat>(m.rows());\r
         Mat_to_vector_Mat(m, mats);\r
         for (Mat mi : mats) {\r
-            List<KeyPoint> lkp = new ArrayList<KeyPoint>();\r
-            Mat_to_vector_KeyPoint(mi, lkp);\r
-            kps.add(lkp);\r
+            CvVectorKeyPoint vkp = new CvVectorKeyPoint(mi);\r
+            kps.add(vkp);\r
         }\r
     }\r
 \r
@@ -600,12 +618,12 @@ public class Converters {
     }\r
 \r
     // vector_vector_DMatch\r
-    public static Mat vector_vector_DMatch_to_Mat(List<List<DMatch>> lldm, List<Mat> mats) {\r
+    public static Mat vector_vector_DMatch_to_Mat(List<CvVectorDMatch> lvdm, List<Mat> mats) {\r
         Mat res;\r
-        int lCount = (lldm != null) ? lldm.size() : 0;\r
+        int lCount = (lvdm != null) ? lvdm.size() : 0;\r
         if (lCount > 0) {\r
-            for (List<DMatch> ldm : lldm)\r
-                mats.add(vector_DMatch_to_Mat(ldm));\r
+            for (CvVectorDMatch vdm : lvdm)\r
+                mats.add(vdm);\r
             res = vector_Mat_to_Mat(mats);\r
         } else {\r
             res = new Mat();\r
@@ -613,8 +631,8 @@ public class Converters {
         return res;\r
     }\r
 \r
-    public static void Mat_to_vector_vector_DMatch(Mat m, List<List<DMatch>> lldm) {\r
-        if (lldm == null)\r
+    public static void Mat_to_vector_vector_DMatch(Mat m, List<CvVectorDMatch> lvdm) {\r
+        if (lvdm == null)\r
             throw new java.lang.IllegalArgumentException("Output List can't be null");\r
 \r
         if (m == null)\r
@@ -622,20 +640,20 @@ public class Converters {
 \r
         List<Mat> mats = new ArrayList<Mat>(m.rows());\r
         Mat_to_vector_Mat(m, mats);\r
+        lvdm.clear();\r
         for (Mat mi : mats) {\r
-            List<DMatch> ldm = new ArrayList<DMatch>();\r
-            Mat_to_vector_DMatch(mi, ldm);\r
-            lldm.add(ldm);\r
+            CvVectorDMatch vdm = new CvVectorDMatch(mi);\r
+            lvdm.add(vdm);\r
         }\r
     }\r
 \r
     // vector_vector_char\r
-    public static Mat vector_vector_char_to_Mat(List<List<Byte>> llb, List<Mat> mats) {\r
+    public static Mat vector_vector_char_to_Mat(List<CvVectorByte> lvb, List<Mat> mats) {\r
         Mat res;\r
-        int lCount = (llb != null) ? llb.size() : 0;\r
+        int lCount = (lvb != null) ? lvb.size() : 0;\r
         if (lCount > 0) {\r
-            for (List<Byte> lb : llb)\r
-                mats.add(vector_char_to_Mat(lb));\r
+            for (CvVectorByte vb : lvb)\r
+                mats.add(vb);\r
             res = vector_Mat_to_Mat(mats);\r
         } else {\r
             res = new Mat();\r
index facad4c..3a74f90 100644 (file)
@@ -4,11 +4,10 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.LinkedList;
-import java.util.List;
 
 import org.opencv.android.Utils;
 import org.opencv.core.Core;
+import org.opencv.core.CvVectorRect;
 import org.opencv.core.Mat;
 import org.opencv.core.Rect;
 import org.opencv.core.Scalar;
@@ -81,11 +80,12 @@ class FdView extends SampleCvViewBase {
         if (mCascade != null) {
             int height = mGray.rows();
             int faceSize = Math.round(height * FdActivity.minFaceSize);
-            List<Rect> faces = new LinkedList<Rect>();
+            CvVectorRect faces = new CvVectorRect();
             mCascade.detectMultiScale(mGray, faces, 1.1, 2, 2 // TODO: objdetect.CV_HAAR_SCALE_IMAGE
                     , new Size(faceSize, faceSize), new Size());
 
-            for (Rect r : faces)
+            Rect ra[] = null;
+            for (Rect r : faces.toArray(ra))
                 Core.rectangle(mRgba, r.tl(), r.br(), new Scalar(0, 255, 0, 255), 3);
         }
 
index 406ffe2..ac7bbfa 100644 (file)
@@ -1,13 +1,17 @@
 package org.opencv.samples.tutorial2;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.opencv.android.Utils;
 import org.opencv.core.Core;
+import org.opencv.core.CvVectorPoint;
 import org.opencv.core.Mat;
 import org.opencv.core.Point;
 import org.opencv.core.Scalar;
-import org.opencv.imgproc.Imgproc;
 import org.opencv.highgui.Highgui;
 import org.opencv.highgui.VideoCapture;
+import org.opencv.imgproc.Imgproc;
 
 import android.content.Context;
 import android.graphics.Bitmap;
@@ -18,6 +22,10 @@ class Sample2View extends SampleCvViewBase {
     private Mat mRgba;
     private Mat mGray;
     private Mat mIntermediateMat;
+    private Mat mIntermediateMat2;
+    private Mat mEmpty;
+    private Scalar lo, hi;
+    private Scalar bl, wh;
 
     public Sample2View(Context context) {
         super(context);
@@ -32,11 +40,18 @@ class Sample2View extends SampleCvViewBase {
             mGray = new Mat();
             mRgba = new Mat();
             mIntermediateMat = new Mat();
+            mIntermediateMat2 = new Mat();
+            mEmpty = new Mat();
+            lo = new Scalar(85, 100, 30);
+            hi = new Scalar(130, 255, 255);
+            bl = new Scalar(0, 0, 0, 255);
+            wh = new Scalar(255, 255, 255, 255);
         }
     }
 
     @Override
     protected Bitmap processFrame(VideoCapture capture) {
+       /**/
         switch (Sample2NativeCamera.viewMode) {
         case Sample2NativeCamera.VIEW_MODE_GRAY:
             capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
@@ -44,14 +59,39 @@ class Sample2View extends SampleCvViewBase {
             break;
         case Sample2NativeCamera.VIEW_MODE_RGBA:
             capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
-            Core.putText(mRgba, "OpenCV + Android", new Point(10, 100), 3/* CV_FONT_HERSHEY_COMPLEX */, 2, new Scalar(255, 0, 0, 255), 3);
+            Core.putText(mRgba, "OpenCV + Android", new Point(10, 100), 3, 2, new Scalar(255, 0, 0, 255), 3);
             break;
         case Sample2NativeCamera.VIEW_MODE_CANNY:
-            capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
+            /*capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
             Imgproc.Canny(mGray, mIntermediateMat, 80, 100);
             Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);
-            break;
+            */
+               capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
+               Imgproc.cvtColor(mRgba, mIntermediateMat, Imgproc.COLOR_RGB2HSV_FULL);
+               Core.inRange(mIntermediateMat, lo, hi, mIntermediateMat2); // green
+               Imgproc.dilate(mIntermediateMat2, mIntermediateMat2, mEmpty);
+               //
+               List<CvVectorPoint> contours = new ArrayList<CvVectorPoint>();
+               Mat hierarchy = new Mat();
+               Imgproc.findContours(mIntermediateMat2, contours, hierarchy,Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
+               Log.d("processFrame", "contours.size()" + contours.size());
+               double maxArea = 0;
+               int indexMaxArea = -1;
+              for (int i = 0; i < contours.size(); i++) {
+                  double s = Imgproc.contourArea(contours.get(i));
+                    if(s > maxArea){
+                           indexMaxArea = i;
+                           maxArea = s;
+                    }
+              } 
+              
+                       mRgba.setTo(bl);
+                       Imgproc.drawContours(mRgba, contours, indexMaxArea, wh);
+                       //
+                       //Imgproc.cvtColor(mIntermediateMat2, mRgba, Imgproc.COLOR_GRAY2RGBA);
+                       break;
         }
+       /**/
 
         Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
 
@@ -78,6 +118,9 @@ class Sample2View extends SampleCvViewBase {
             if (mIntermediateMat != null)
                 mIntermediateMat.release();
 
+            if (mIntermediateMat2 != null)
+                mIntermediateMat2.release();
+            
             mRgba = null;
             mGray = null;
             mIntermediateMat = null;