Commit 5ba826d2 authored by Andrey Pavlenko's avatar Andrey Pavlenko

Java API generator: pointers handling fixed, KeyPoint manual port added

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