From 9235a8010988a94d9afaeb7b94ff006c48027e14 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Wed, 27 Jul 2011 15:16:24 +0000 Subject: [PATCH] Java API generator: KeyPoint converters from/to Mat --- modules/java/gen_java.py | 2 +- modules/java/src/cpp/converters.cpp | 21 +++++-- modules/java/src/java/Converters.java | 59 +++++++++++++++---- .../java/src/java/features2d+KeyPoint.java | 24 ++++---- 4 files changed, 76 insertions(+), 30 deletions(-) diff --git a/modules/java/gen_java.py b/modules/java/gen_java.py index 5640102c14..dae412ee16 100644 --- a/modules/java/gen_java.py +++ b/modules/java/gen_java.py @@ -11,7 +11,7 @@ class_ignore_list = ( "FileNode", "FileStorage", #highgui "VideoWriter", "VideoCapture", - #feature2d + #features2d "KeyPoint", ) diff --git a/modules/java/src/cpp/converters.cpp b/modules/java/src/cpp/converters.cpp index bc768d43d7..94716e5ecf 100644 --- a/modules/java/src/cpp/converters.cpp +++ b/modules/java/src/cpp/converters.cpp @@ -114,17 +114,27 @@ void vector_Point_to_Mat(vector& v_point, Mat& mat) //vector_KeyPoint void Mat_to_vector_KeyPoint(Mat& mat, vector& v_kp) { - v_kp.clear(); - //CHECK_MAT(mat.type()!= ??? || mat.rows!=1); - v_kp = (vector) mat; + v_kp.clear(); + CHECK_MAT(mat.type()!= CV_64FC(7) || mat.rows!=1); + for(int i=0; i v = mat.at< Vec >(0, i); + KeyPoint kp((float)v[0], (float)v[1], (float)v[2], (float)v[3], (float)v[4], (int)v[5], (int)v[6]); + v_kp.push_back(kp); + } return; } void vector_KeyPoint_to_Mat(vector& v_kp, Mat& mat) { - mat = Mat(v_kp); - return; + int count = v_kp.size(); + mat.create(1, count, CV_64FC(7)); + for(int i=0; i >(0, i) = Vec(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id); + } } @@ -154,5 +164,4 @@ void vector_Mat_to_Mat(std::vector& v_mat, cv::Mat& mat) long long addr = (long long) new Mat(v_mat[i]); mat.at< Vec >(0, i) = Vec(addr>>32, addr&0xffffffff); } - return; } diff --git a/modules/java/src/java/Converters.java b/modules/java/src/java/Converters.java index 177fb99a57..d8e081cc61 100644 --- a/modules/java/src/java/Converters.java +++ b/modules/java/src/java/Converters.java @@ -9,7 +9,7 @@ import org.opencv.core.Rect; import org.opencv.features2d.KeyPoint; public class Converters { - + public static Mat vector_Point_to_Mat(List pts) { Mat res; int count = (pts!=null) ? pts.size() : 0; @@ -52,7 +52,7 @@ public class Converters { int cols = m.cols(); if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) throw new java.lang.IllegalArgumentException(); - + pts.clear(); int[] buff = new int[2*cols]; m.get(0, 0, buff); @@ -85,7 +85,7 @@ public class Converters { int cols = m.cols(); if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) throw new java.lang.IllegalArgumentException(); - + mats.clear(); int[] buff = new int[cols*2]; m.get(0, 0, buff); @@ -95,10 +95,6 @@ public class Converters { } } - public static void Mat_to_vector_KeyPoint(Mat kp_mat, List kps) { - // TODO Auto-generated method stub - } - public static Mat vector_float_to_Mat(List fs) { Mat res; int count = (fs!=null) ? fs.size() : 0; @@ -122,7 +118,7 @@ public class Converters { int cols = m.cols(); if(CvType.CV_32FC1 != m.type() || m.rows()!=1 ) throw new java.lang.IllegalArgumentException(); - + fs.clear(); float[] buff = new float[cols]; m.get(0, 0, buff); @@ -171,7 +167,7 @@ public class Converters { int cols = m.cols(); if(CvType.CV_32SC1 != m.type() || m.rows()!=1 ) throw new java.lang.IllegalArgumentException(); - + is.clear(); int[] buff = new int[cols]; m.get(0, 0, buff); @@ -184,7 +180,7 @@ public class Converters { Mat res; int count = (rs!=null) ? rs.size() : 0; if(count>0){ - res = new Mat(1, count, CvType.CV_32SC4); //Point can be saved into double[2] + res = new Mat(1, count, CvType.CV_32SC4); int[] buff = new int[4*count]; for(int i=0; i kps) { + Mat res; + int count = (kps!=null) ? kps.size() : 0; + if(count>0){ + res = new Mat(1, count, CvType.CV_64FC(7)); + double[] buff = new double[count * 7]; + for(int i=0; i kps) { + if(kps == null) + throw new java.lang.IllegalArgumentException(); + int cols = m.cols(); + if(CvType.CV_64FC(7) != m.type() || m.rows()!=1 ) + throw new java.lang.IllegalArgumentException(); + + kps.clear(); + double[] buff = new double[7*cols]; + m.get(0, 0, buff); + for(int i=0; i ds) { Mat res; int count = (ds!=null) ? ds.size() : 0; diff --git a/modules/java/src/java/features2d+KeyPoint.java b/modules/java/src/java/features2d+KeyPoint.java index 0b59812d37..9f3da1afd2 100644 --- a/modules/java/src/java/features2d+KeyPoint.java +++ b/modules/java/src/java/features2d+KeyPoint.java @@ -5,18 +5,18 @@ import org.opencv.core.Point; //javadoc: KeyPoint public class KeyPoint { - //javadoc: KeyPoint::pt - Point pt; - //javadoc: KeyPoint::size - float size; - //javadoc: KeyPoint::angle - float angle; - //javadoc: KeyPoint::response - float response; - //javadoc: KeyPoint::octave - int octave; - //javadoc: KeyPoint::class_id - int class_id; + //javadoc: KeyPoint::pt + public Point pt; + //javadoc: KeyPoint::size + public float size; + //javadoc: KeyPoint::angle + public float angle; + //javadoc: KeyPoint::response + public float response; + //javadoc: KeyPoint::octave + public int octave; + //javadoc: KeyPoint::class_id + public int class_id; //javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave, _class_id) public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id) -- GitLab