Java API generator: pointers handling fixed, KeyPoint manual port added
authorAndrey Pavlenko <no@email>
Wed, 27 Jul 2011 14:09:49 +0000 (14:09 +0000)
committerAndrey Pavlenko <no@email>
Wed, 27 Jul 2011 14:09:49 +0000 (14:09 +0000)
modules/java/gen_java.py
modules/java/src/cpp/converters.cpp
modules/java/src/java/features2d+KeyPoint.java [new file with mode: 0644]

index ff344d6..5640102 100644 (file)
@@ -11,6 +11,8 @@ class_ignore_list = (
     "FileNode", "FileStorage",\r
     #highgui\r
     "VideoWriter", "VideoCapture",\r
+    #feature2d\r
+    "KeyPoint",\r
 )\r
 \r
 const_ignore_list = (\r
@@ -207,6 +209,11 @@ type_dict = {
     "Point3d" : { "j_type" : "Point", "jn_args" : (("double", ".x"), ("double", ".y"), ("double", ".z")),\r
                   "jni_var" : "Point3d %(n)s(%(n)s_x, %(n)s_y, %(n)s_z)", "jni_type" : "jdoubleArray",\r
                   "suffix" : "DDD"},\r
+    "KeyPoint": { "j_type" : "KeyPoint", "jn_args" : (("float", ".x"), ("float", ".y"), ("float", ".size"),\r
+                    ("float", ".angle"), ("float", ".response"), ("int", ".octave"), ("int", ".class_id")),\r
+                  "jni_var" : "KeyPoint %(n)s(%(n)s_x, %(n)s_y, %(n)s_size, %(n)s_angle, %(n)s_response, %(n)s_octave, %(n)s_class_id)",\r
+                  "jni_type" : "jdoubleArray",\r
+                  "suffix" : "FFFFFII"},\r
     "Rect"    : { "j_type" : "Rect",  "jn_args" : (("int", ".x"), ("int", ".y"), ("int", ".width"), ("int", ".height")),\r
                   "jni_var" : "Rect %(n)s(%(n)s_x, %(n)s_y, %(n)s_width, %(n)s_height)", "jni_type" : "jdoubleArray",\r
                   "suffix" : "IIII"},\r
@@ -859,7 +866,10 @@ extern "C" {
             self.get_imports(fi.classname, fi.ctype)\r
             for a in args:\r
                 self.get_imports(fi.classname, a.ctype)\r
-                suffix += type_dict[a.ctype].get("suffix") or ""\r
+                if a.pointer:\r
+                    suffix += "_3D"\r
+                else:\r
+                    suffix += type_dict[a.ctype].get("suffix") or ""\r
 \r
                 if "vector" in a.ctype: # pass as Mat\r
                     jn_args.append  ( ArgInfo([ "__int64", "%s_mat.nativeObj" % a.name, "", [], "" ]) )\r
index 370b7b1..bc768d4 100644 (file)
 \r
 using namespace cv;\r
 \r
+#define CHECK_MAT(cond) if(cond){ LOGD(#cond); return; }\r
+\r
+\r
 // vector_int\r
 \r
 void Mat_to_vector_int(Mat& mat, vector<int>& v_int)\r
 {\r
        v_int.clear();\r
-\r
-       if(mat.type()!= CV_32SC1 || mat.rows!=1)\r
-               return;\r
-\r
-       /*\r
-       for(int i=0; i<mat.cols; i++)\r
-               v_int.push_back( mat.at< int >(0, i) );\r
-       */\r
+       CHECK_MAT(mat.type()!= CV_32SC1 || mat.rows!=1);\r
        v_int = (vector<int>) mat;\r
 }\r
 \r
 void vector_int_to_Mat(vector<int>& v_int, Mat& mat)\r
 {\r
-       /*\r
-       mat.create(1, v_int.size(), CV_32SC1);\r
-       for(size_t i=0; i<v_int.size(); i++)\r
-               mat.at< int >(0, i) = v_int[i];\r
-       */\r
        mat = Mat(v_int);\r
 }\r
 \r
@@ -42,24 +33,12 @@ void vector_int_to_Mat(vector<int>& v_int, Mat& mat)
 void Mat_to_vector_double(Mat& mat, vector<double>& v_double)\r
 {\r
        v_double.clear();\r
-\r
-       if(mat.type()!= CV_64FC1 || mat.rows!=1)\r
-               return;\r
-\r
-       /*\r
-       for(int i=0; i<mat.cols; i++)\r
-               v_double.push_back( mat.at< double >(0, i) );\r
-       */\r
+       CHECK_MAT(mat.type()!= CV_64FC1 || mat.rows!=1);\r
        v_double = (vector<double>) mat;\r
 }\r
 \r
 void vector_double_to_Mat(vector<double>& v_double, Mat& mat)\r
 {\r
-       /*\r
-       mat.create(1, v_double.size(), CV_64FC1);\r
-       for(size_t i=0; i<v_double.size(); i++)\r
-               mat.at< double >(0, i) = v_double[i];\r
-       */\r
        mat = Mat(v_double);\r
 }\r
 \r
@@ -69,24 +48,12 @@ void vector_double_to_Mat(vector<double>& v_double, Mat& mat)
 void Mat_to_vector_float(Mat& mat, vector<float>& v_float)\r
 {\r
        v_float.clear();\r
-\r
-       if(mat.type()!= CV_32FC1 || mat.rows!=1)\r
-               return;\r
-\r
-       /*\r
-       for(int i=0; i<mat.cols; i++)\r
-               v_float.push_back( mat.at< float >(0, i) );\r
-       */\r
+       CHECK_MAT(mat.type()!= CV_32FC1 || mat.rows!=1);\r
        v_float = (vector<float>) mat;\r
 }\r
 \r
 void vector_float_to_Mat(vector<float>& v_float, Mat& mat)\r
 {\r
-       /*\r
-       mat.create(1, v_float.size(), CV_32FC1);\r
-       for(size_t i=0; i<v_float.size(); i++)\r
-               mat.at< float >(0, i) = v_float[i];\r
-       */\r
        mat = Mat(v_float);\r
 }\r
 \r
@@ -96,14 +63,7 @@ void vector_float_to_Mat(vector<float>& v_float, Mat& mat)
 void Mat_to_vector_uchar(Mat& mat, vector<uchar>& v_uchar)\r
 {\r
        v_uchar.clear();\r
-\r
-       if(mat.type()!= CV_8UC1 || mat.rows!=1)\r
-               return;\r
-\r
-       /*\r
-       for(int i=0; i<mat.cols; i++)\r
-               v_uchar.push_back( mat.at< uchar >(0, i) );\r
-       */\r
+       CHECK_MAT(mat.type()!= CV_8UC1 || mat.rows!=1);\r
        v_uchar = (vector<uchar>) mat;\r
 }\r
 \r
@@ -113,24 +73,21 @@ void Mat_to_vector_uchar(Mat& mat, vector<uchar>& v_uchar)
 void Mat_to_vector_Rect(Mat& mat, vector<Rect>& v_rect)\r
 {\r
        v_rect.clear();\r
-\r
-       if(mat.type()!= CV_32SC4 || mat.rows!=1) {\r
-               LOGD("ERROR mat.type()!= CV_32SC4 || mat.rows!=1");\r
-               return;\r
-       }\r
-\r
-       for(int i=0; i<mat.cols; i++) {\r
+       CHECK_MAT(mat.type()!= CV_32SC4 || mat.rows!=1);\r
+       v_rect = (vector<Rect>) mat;\r
+       /*for(int i=0; i<mat.cols; i++) {\r
                Vec<int, 4> v=mat.at< Vec<int, 4> >(0, i);\r
                v_rect.push_back( Rect(v[0], v[1], v[2], v[3]) );\r
-       }\r
+       }*/\r
 }\r
 \r
 void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)\r
 {\r
-       mat.create(1, v_rect.size(), CV_32SC4);\r
+       mat = Mat(v_rect);\r
+       /*mat.create(1, v_rect.size(), CV_32SC4);\r
        for(size_t i=0; i<v_rect.size(); i++) {\r
                mat.at< Vec<int, 4> >(0, i) = Vec<int, 4>(v_rect[i].x, v_rect[i].y, v_rect[i].width, v_rect[i].height);\r
-       }\r
+       }*/\r
 }\r
 \r
 \r
@@ -138,32 +95,35 @@ void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
 void Mat_to_vector_Point(Mat& mat, vector<Point>& v_point)\r
 {\r
        v_point.clear();\r
-\r
-       if(mat.type()!= CV_32SC2 || mat.rows!=1)\r
-               return;\r
-\r
-       for(int i=0; i<mat.cols; i++)\r
-               v_point.push_back( Point( mat.at< Vec<int, 2> >(0, i) ) );\r
+       CHECK_MAT(mat.type()!= CV_32SC2 || mat.rows!=1);\r
+       v_point = (vector<Point>) mat;\r
+       /*for(int i=0; i<mat.cols; i++)\r
+               v_point.push_back( Point( mat.at< Vec<int, 2> >(0, i) ) );*/\r
 }\r
 \r
 \r
 void vector_Point_to_Mat(vector<Point>& v_point, Mat& mat)\r
 {\r
-       mat.create(1, v_point.size(), CV_32SC2);\r
+       mat = Mat(v_point);\r
+       /*mat.create(1, v_point.size(), CV_32SC2);\r
        for(size_t i=0; i<v_point.size(); i++)\r
-               mat.at< Vec<int, 2> >(0, i) = Vec<int, 2>(v_point[i].x, v_point[i].y);\r
+               mat.at< Vec<int, 2> >(0, i) = Vec<int, 2>(v_point[i].x, v_point[i].y);*/\r
 }\r
 \r
 \r
 //vector_KeyPoint\r
 void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)\r
 {\r
+       v_kp.clear();\r
+       //CHECK_MAT(mat.type()!= ??? || mat.rows!=1);\r
+       v_kp = (vector<KeyPoint>) mat;\r
     return;\r
 }\r
 \r
 \r
 void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat)\r
 {\r
+       mat = Mat(v_kp);\r
     return;\r
 }\r
 \r
diff --git a/modules/java/src/java/features2d+KeyPoint.java b/modules/java/src/java/features2d+KeyPoint.java
new file mode 100644 (file)
index 0000000..0b59812
--- /dev/null
@@ -0,0 +1,61 @@
+package org.opencv.features2d;\r
+\r
+import org.opencv.core.Point;\r
+\r
+//javadoc: KeyPoint\r
+public class KeyPoint {\r
+       \r
+       //javadoc: KeyPoint::pt\r
+    Point pt;\r
+       //javadoc: KeyPoint::size\r
+    float size;\r
+       //javadoc: KeyPoint::angle\r
+    float angle;\r
+       //javadoc: KeyPoint::response\r
+    float response;\r
+       //javadoc: KeyPoint::octave\r
+    int octave;\r
+       //javadoc: KeyPoint::class_id\r
+    int class_id; \r
+\r
+    //javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave, _class_id)\r
+    public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)\r
+    {\r
+        pt       = new Point(x, y);\r
+        size     = _size;\r
+        angle    = _angle;\r
+        response = _response;\r
+        octave   = _octave;\r
+        class_id = _class_id;\r
+    }\r
+\r
+    //javadoc: KeyPoint::KeyPoint()\r
+    public KeyPoint()\r
+    {\r
+       this(0, 0, 0, -1, 0, 0, -1);\r
+    }\r
+\r
+    //javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave)\r
+    public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave)\r
+    {\r
+       this(x, y, _size, _angle, _response, _octave, -1);\r
+    }\r
+\r
+    //javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response)\r
+    public KeyPoint(float x, float y, float _size, float _angle, float _response)\r
+    {\r
+       this(x, y, _size, _angle, _response, 0, -1);\r
+    }\r
+\r
+    //javadoc: KeyPoint::KeyPoint(x, y, _size, _angle)\r
+    public KeyPoint(float x, float y, float _size, float _angle)\r
+    {\r
+       this(x, y, _size, _angle, 0, 0, -1);\r
+    }\r
+\r
+    //javadoc: KeyPoint::KeyPoint(x, y, _size)\r
+    public KeyPoint(float x, float y, float _size)\r
+    {\r
+       this(x, y, _size, -1, 0, 0, -1);\r
+    }\r
+}\r