Java API: changing C++ vector<T> handling;
Java tests fixes are expected shortly
This commit is contained in:
parent
9ac0d4323d
commit
78d92584c3
@ -193,34 +193,36 @@ type_dict = {
|
||||
|
||||
# "complex" : { j_type : "?", jn_args : (("", ""),), jn_name : "", jni_var : "", jni_name : "", "suffix" : "?" },
|
||||
|
||||
"vector_Point" : { "j_type" : "List<Point>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point> %(n)s", "suffix" : "J" },
|
||||
"vector_Point2f" : { "j_type" : "List<Point>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point2f> %(n)s", "suffix" : "J" },
|
||||
"vector_Point2d" : { "j_type" : "List<Point>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point2d> %(n)s", "suffix" : "J" },
|
||||
"vector_Point3i" : { "j_type" : "List<Point3>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3i> %(n)s", "suffix" : "J" },
|
||||
"vector_Point3f" : { "j_type" : "List<Point3>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3f> %(n)s", "suffix" : "J" },
|
||||
"vector_Point3d" : { "j_type" : "List<Point3>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3d> %(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_KeyPoint" : { "j_type" : "List<KeyPoint>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<KeyPoint> %(n)s", "suffix" : "J" },
|
||||
"vector_DMatch" : { "j_type" : "List<DMatch>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<DMatch> %(n)s", "suffix" : "J" },
|
||||
"vector_Rect" : { "j_type" : "List<Rect>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Rect> %(n)s", "suffix" : "J" },
|
||||
"vector_uchar" : { "j_type" : "List<Byte>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<uchar> %(n)s", "suffix" : "J" },
|
||||
"vector_char" : { "j_type" : "List<Byte>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<char> %(n)s", "suffix" : "J" },
|
||||
"vector_int" : { "j_type" : "List<Integer>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<int> %(n)s", "suffix" : "J" },
|
||||
"vector_float" : { "j_type" : "List<Float>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<float> %(n)s", "suffix" : "J" },
|
||||
"vector_double" : { "j_type" : "List<Double>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<double> %(n)s", "suffix" : "J" },
|
||||
"vector_Vec4f" : { "j_type" : "Mat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec4f> %(n)s", "suffix" : "J" },
|
||||
"vector_Vec6f" : { "j_type" : "Mat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec6f> %(n)s", "suffix" : "J" },
|
||||
"vector_Point" : { "j_type" : "CvVectorPoint", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point> %(n)s", "suffix" : "J" },
|
||||
"vector_Point2f" : { "j_type" : "CvVectorPoint2f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point2f> %(n)s", "suffix" : "J" },
|
||||
"vector_Point2d" : { "j_type" : "CvVectorPoint2f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point2d> %(n)s", "suffix" : "J" },
|
||||
"vector_Point3i" : { "j_type" : "CvVectorPoint3", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3i> %(n)s", "suffix" : "J" },
|
||||
"vector_Point3f" : { "j_type" : "CvVectorPoint3f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3f> %(n)s", "suffix" : "J" },
|
||||
"vector_Point3d" : { "j_type" : "CvVectorPoint3f", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Point3d> %(n)s", "suffix" : "J" },
|
||||
"vector_KeyPoint" : { "j_type" : "CvVectorKeyPoint", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<KeyPoint> %(n)s", "suffix" : "J" },
|
||||
"vector_DMatch" : { "j_type" : "CvVectorDMatch", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<DMatch> %(n)s", "suffix" : "J" },
|
||||
"vector_Rect" : { "j_type" : "CvVectorRect", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Rect> %(n)s", "suffix" : "J" },
|
||||
"vector_uchar" : { "j_type" : "CvVectorByte", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<uchar> %(n)s", "suffix" : "J" },
|
||||
"vector_char" : { "j_type" : "CvVectorByte", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<char> %(n)s", "suffix" : "J" },
|
||||
"vector_int" : { "j_type" : "CvVectorInt", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<int> %(n)s", "suffix" : "J" },
|
||||
"vector_float" : { "j_type" : "CvVectorFloat", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<float> %(n)s", "suffix" : "J" },
|
||||
"vector_double" : { "j_type" : "CvVectorDouble", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<double> %(n)s", "suffix" : "J" },
|
||||
"vector_Vec4f" : { "j_type" : "CvVectorFloat4", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec4f> %(n)s", "suffix" : "J" },
|
||||
"vector_Vec6f" : { "j_type" : "CvVectorFloat6", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Vec6f> %(n)s", "suffix" : "J" },
|
||||
|
||||
"vector_vector_KeyPoint": { "j_type" : "List<List<KeyPoint>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<KeyPoint> > %(n)s" },
|
||||
"vector_vector_DMatch" : { "j_type" : "List<List<DMatch>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<DMatch> > %(n)s" },
|
||||
"vector_vector_char" : { "j_type" : "List<List<Byte>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<char> > %(n)s" },
|
||||
"vector_vector_Point" : { "j_type" : "List<List<Point>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point> > %(n)s" },
|
||||
"vector_vector_Point2f" : { "j_type" : "List<List<Point>>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point2f> > %(n)s" },
|
||||
"vector_Mat" : { "j_type" : "List<Mat>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector<Mat> %(n)s", "suffix" : "J" },
|
||||
|
||||
"vector_vector_KeyPoint": { "j_type" : "List<CvVectorKeyPoint>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<KeyPoint> > %(n)s" },
|
||||
"vector_vector_DMatch" : { "j_type" : "List<CvVectorDMatch>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<DMatch> > %(n)s" },
|
||||
"vector_vector_char" : { "j_type" : "List<CvVectorByte>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<char> > %(n)s" },
|
||||
"vector_vector_Point" : { "j_type" : "List<CvVectorPoint>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point> > %(n)s" },
|
||||
"vector_vector_Point2f" : { "j_type" : "List<CvVectorPoint2f>", "jn_type" : "long", "jni_type" : "jlong", "jni_var" : "vector< vector<Point2f> > %(n)s" },
|
||||
|
||||
"Mat" : { "j_type" : "Mat", "jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
|
||||
"jni_var" : "Mat& %(n)s = *((Mat*)%(n)s_nativeObj)",
|
||||
"jni_type" : "jlong", #"jni_name" : "*%(n)s",
|
||||
"suffix" : "J" },
|
||||
|
||||
"Point" : { "j_type" : "Point", "jn_args" : (("double", ".x"), ("double", ".y")),
|
||||
"jni_var" : "Point %(n)s((int)%(n)s_x, (int)%(n)s_y)", "jni_type" : "jdoubleArray",
|
||||
"suffix" : "DD"},
|
||||
@ -510,7 +512,6 @@ func_arg_fix = {
|
||||
'boundingRect' : { 'points' : 'vector_Point', },
|
||||
'approxPolyDP' : { 'curve' : 'vector_Point2f', 'approxCurve' : 'vector_Point2f', },
|
||||
'arcLength' : { 'curve' : 'vector_Point2f', },
|
||||
'isContourConvex' : { 'contour' : 'vector_Point2f', },
|
||||
'pointPolygonTest' : { 'contour' : 'vector_Point2f', },
|
||||
'minAreaRect' : { 'points' : 'vector_Point2f', },
|
||||
'getAffineTransform' : { 'src' : 'vector_Point2f', 'dst' : 'vector_Point2f', },
|
||||
@ -519,6 +520,10 @@ func_arg_fix = {
|
||||
'undistortPoints' : { 'src' : 'vector_Point2d', 'dst' : 'vector_Point2d' },
|
||||
'checkRange' : {'pos' : '*'},
|
||||
'meanStdDev' : {'mean' : 'vector_double', 'stddev' : 'vector_double'},
|
||||
'drawContours' : {'contours' : 'vector_vector_Point'},
|
||||
'findContours' : {'contours' : 'vector_vector_Point'},
|
||||
'convexityDefects' : {'contour' : 'vector_Point'},
|
||||
'isContourConvex' : { 'contour' : 'vector_Point2f', },
|
||||
}, # '', i.e. no class
|
||||
} # func_arg_fix
|
||||
|
||||
@ -891,9 +896,13 @@ extern "C" {
|
||||
def get_imports(self, scope_classname, ctype):
|
||||
imports = self.classes[scope_classname or self.Module].imports
|
||||
if ctype.startswith('vector'):
|
||||
imports.add("java.util.List")
|
||||
imports.add("org.opencv.core.Mat")
|
||||
imports.add("org.opencv.utils.Converters")
|
||||
if type_dict[ctype]['j_type'].startswith('CvVector'):
|
||||
imports.add("org.opencv.core." + type_dict[ctype]['j_type'])
|
||||
return #TMP
|
||||
else:
|
||||
imports.add("java.util.List")
|
||||
imports.add("org.opencv.utils.Converters")
|
||||
ctype = ctype.replace('vector_', '')
|
||||
j_type = ''
|
||||
if ctype in type_dict:
|
||||
@ -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 } )
|
||||
j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s, %(n)s_tmplm);" % {"n" : a.name, "t" : a.ctype} )
|
||||
else:
|
||||
j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s);" % {"n" : a.name, "t" : a.ctype} )
|
||||
if not type_dict[a.ctype]["j_type"].startswith("CvVector"):
|
||||
j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s);" % {"n" : a.name, "t" : a.ctype} )
|
||||
else:
|
||||
j_prologue.append( "Mat %s_mat = %s;" % (a.name, a.name) )
|
||||
c_prologue.append( "Mat_to_%(t)s( %(n)s_mat, %(n)s );" % {"n" : a.name, "t" : a.ctype} )
|
||||
else:
|
||||
if type_dict[a.ctype]["j_type"] != "Mat":
|
||||
if not type_dict[a.ctype]["j_type"].startswith("CvVector"):
|
||||
j_prologue.append( "Mat %s_mat = new Mat();" % a.name )
|
||||
else:
|
||||
j_prologue.append( "Mat %s_mat = %s;" % (a.name, a.name) )
|
||||
if "O" in a.out:
|
||||
if type_dict[a.ctype]["j_type"] != "Mat":
|
||||
if not type_dict[a.ctype]["j_type"].startswith("CvVector"):
|
||||
j_epilogue.append("Converters.Mat_to_%(t)s(%(n)s_mat, %(n)s);" % {"t" : a.ctype, "n" : a.name})
|
||||
c_epilogue.append( "%(t)s_to_Mat( %(n)s, %(n)s_mat );" % {"n" : a.name, "t" : a.ctype} )
|
||||
else:
|
||||
@ -1060,12 +1072,15 @@ extern "C" {
|
||||
tail = ""
|
||||
ret = "return retVal;"
|
||||
if ret_type.startswith('vector'):
|
||||
ret_val = "Mat retValMat = new Mat("
|
||||
tail = ")"
|
||||
j_type = type_dict[ret_type]["j_type"]
|
||||
j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')
|
||||
self.classes[fi.classname or self.Module].imports.add('java.util.ArrayList')
|
||||
j_epilogue.append('Converters.Mat_to_' + ret_type + '(retValMat, retVal);')
|
||||
if j_type.startswith('CvVector'):
|
||||
ret_val += "new " + j_type + "("
|
||||
else:
|
||||
ret_val = "Mat retValMat = new Mat("
|
||||
j_prologue.append( j_type + ' retVal = new Array' + j_type+'();')
|
||||
self.classes[fi.classname or self.Module].imports.add('java.util.ArrayList')
|
||||
j_epilogue.append('Converters.Mat_to_' + ret_type + '(retValMat, retVal);')
|
||||
elif ret_type == "void":
|
||||
ret_val = ""
|
||||
ret = "return;"
|
||||
|
@ -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)
|
||||
{
|
||||
v_kp.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC(7) && mat.cols==1);
|
||||
CHECK_MAT(mat.type()==CV_32FC(7) && mat.cols==1);
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<double, 7> v = mat.at< Vec<double, 7> >(i, 0);
|
||||
KeyPoint kp((float)v[0], (float)v[1], (float)v[2], (float)v[3], (float)v[4], (int)v[5], (int)v[6]);
|
||||
Vec<float, 7> v = mat.at< Vec<float, 7> >(i, 0);
|
||||
KeyPoint kp(v[0], v[1], v[2], v[3], v[4], (int)v[5], (int)v[6]);
|
||||
v_kp.push_back(kp);
|
||||
}
|
||||
return;
|
||||
@ -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)
|
||||
{
|
||||
int count = v_kp.size();
|
||||
mat.create(count, 1, CV_64FC(7));
|
||||
mat.create(count, 1, CV_32FC(7));
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
KeyPoint kp = v_kp[i];
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -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)
|
||||
{
|
||||
v_dm.clear();
|
||||
CHECK_MAT(mat.type()==CV_64FC4 && mat.cols==1);
|
||||
CHECK_MAT(mat.type()==CV_32FC4 && mat.cols==1);
|
||||
for(int i=0; i<mat.rows; i++)
|
||||
{
|
||||
Vec<double, 4> v = mat.at< Vec<double, 4> >(i, 0);
|
||||
DMatch dm((int)v[0], (int)v[1], (int)v[2], (float)v[3]);
|
||||
Vec<float, 4> v = mat.at< Vec<float, 4> >(i, 0);
|
||||
DMatch dm((int)v[0], (int)v[1], (int)v[2], v[3]);
|
||||
v_dm.push_back(dm);
|
||||
}
|
||||
return;
|
||||
@ -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)
|
||||
{
|
||||
int count = v_dm.size();
|
||||
mat.create(count, 1, CV_64FC4);
|
||||
mat.create(count, 1, CV_32FC4);
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
DMatch dm = v_dm[i];
|
||||
mat.at< Vec<double, 4> >(i, 0) = Vec<double, 4>(dm.queryIdx, dm.trainIdx, dm.imgIdx, dm.distance);
|
||||
mat.at< Vec<float, 4> >(i, 0) = Vec<float, 4>(dm.queryIdx, dm.trainIdx, dm.imgIdx, dm.distance);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -374,6 +374,19 @@ void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& 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_Vec4f_to_Mat(vector<Vec4f>& v_vec, Mat& mat)
|
||||
{
|
||||
mat = Mat(v_vec, true);
|
||||
|
@ -64,4 +64,5 @@ void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Ma
|
||||
|
||||
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);
|
||||
|
||||
|
35
modules/java/src/java/core+CvVector.java
Normal file
35
modules/java/src/java/core+CvVector.java
Normal file
@ -0,0 +1,35 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVector extends Mat {
|
||||
protected int depth;
|
||||
protected int channels;
|
||||
|
||||
protected CvVector(int d, int ch) {
|
||||
super();
|
||||
depth = d;
|
||||
channels = ch;
|
||||
}
|
||||
|
||||
protected CvVector(int d, int ch, long addr) {
|
||||
super(addr);
|
||||
depth = d;
|
||||
channels = ch;
|
||||
if( !empty() && checkVector(channels, depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
protected CvVector(int d, int ch, Mat m) {
|
||||
super(m, Range.all());
|
||||
depth = d;
|
||||
channels = ch;
|
||||
if( !empty() && checkVector(channels, depth) < 0 )
|
||||
throw new IllegalArgumentException("Incomatible Mat");
|
||||
//FIXME: do we need release() here?
|
||||
}
|
||||
|
||||
protected void create(int cnt) {
|
||||
if(cnt>0)
|
||||
super.create(cnt, 1, CvType.makeType(depth, channels));
|
||||
}
|
||||
}
|
42
modules/java/src/java/core+CvVectorByte.java
Normal file
42
modules/java/src/java/core+CvVectorByte.java
Normal file
@ -0,0 +1,42 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVectorByte extends CvVector {
|
||||
private static final int _d = CvType.CV_8U;
|
||||
|
||||
public CvVectorByte(int ch) {
|
||||
super(_d, ch);
|
||||
}
|
||||
|
||||
public CvVectorByte(int ch, long addr) {
|
||||
super(_d, ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorByte(long addr) {
|
||||
super(_d, 1, addr);
|
||||
}
|
||||
|
||||
public CvVectorByte(int ch, Mat m) {
|
||||
super(_d, ch, m);
|
||||
}
|
||||
|
||||
public CvVectorByte(int ch, byte[] a) {
|
||||
super(_d, ch);
|
||||
if(a!=null) {
|
||||
int cnt = a.length / ch;
|
||||
create(cnt);
|
||||
put(0, 0, a);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] toArray(byte[] a) {
|
||||
int cnt = (int) total() * channels;
|
||||
if(cnt == 0)
|
||||
return new byte[0];//null;
|
||||
byte[] res = a;
|
||||
if(res==null || res.length<cnt)
|
||||
res = new byte[cnt];
|
||||
get(0, 0, res); //TODO: check ret val!
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
49
modules/java/src/java/core+CvVectorDMatch.java
Normal file
49
modules/java/src/java/core+CvVectorDMatch.java
Normal file
@ -0,0 +1,49 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import org.opencv.features2d.DMatch;
|
||||
|
||||
public class CvVectorDMatch extends CvVectorFloat {
|
||||
private static final int _ch = 4; //xxxC4
|
||||
|
||||
public CvVectorDMatch() {
|
||||
super(_ch);
|
||||
}
|
||||
|
||||
public CvVectorDMatch(long addr) {
|
||||
super(_ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorDMatch(Mat m) {
|
||||
super(_ch, m);
|
||||
}
|
||||
|
||||
public CvVectorDMatch(DMatch[] a) {
|
||||
super(_ch);
|
||||
if(a==null)
|
||||
return;
|
||||
int cnt = a.length;
|
||||
create(cnt);
|
||||
float buff[] = new float[_ch * cnt];
|
||||
for(int i=0; i<cnt; i++) {
|
||||
DMatch m = a[i];
|
||||
buff[_ch*i+0] = m.queryIdx;
|
||||
buff[_ch*i+1] = m.trainIdx;
|
||||
buff[_ch*i+2] = m.imgIdx;
|
||||
buff[_ch*i+3] = m.distance;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public DMatch[] toArray(DMatch[] a) {
|
||||
float buff[] = super.toArray(null);
|
||||
if(buff.length == 0)
|
||||
return new DMatch[0]; //null;
|
||||
int cnt = buff.length / _ch;
|
||||
DMatch[] res = a;
|
||||
if(a==null || a.length<cnt)
|
||||
res = new DMatch[cnt];
|
||||
for(int i=0; i<cnt; i++)
|
||||
res[i] = new DMatch((int) buff[_ch*i+0], (int) buff[_ch*i+1], (int) buff[_ch*i+2], buff[_ch*i+3]);
|
||||
return res;
|
||||
}
|
||||
}
|
37
modules/java/src/java/core+CvVectorDouble.java
Normal file
37
modules/java/src/java/core+CvVectorDouble.java
Normal file
@ -0,0 +1,37 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVectorDouble extends CvVector {
|
||||
private static final int _d = CvType.CV_64F;
|
||||
|
||||
public CvVectorDouble(int ch) {
|
||||
super(_d, ch);
|
||||
}
|
||||
|
||||
public CvVectorDouble(int ch, long addr) {
|
||||
super(_d, ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorDouble(int ch, Mat m) {
|
||||
super(_d, ch, m);
|
||||
}
|
||||
|
||||
public CvVectorDouble(int ch, double[] a) {
|
||||
super(_d, ch);
|
||||
if(a!=null) {
|
||||
int cnt = a.length / ch;
|
||||
create(cnt);
|
||||
put(0, 0, a);
|
||||
}
|
||||
}
|
||||
|
||||
public double[] toArray(double[] a) {
|
||||
int cnt = (int) total() * channels;
|
||||
if(cnt == 0)
|
||||
return new double[0];//null;
|
||||
double[] res = a;
|
||||
if(res==null || res.length<cnt)
|
||||
res = new double[cnt];
|
||||
get(0, 0, res); //TODO: check ret val!
|
||||
return res;
|
||||
}
|
||||
}
|
41
modules/java/src/java/core+CvVectorFloat.java
Normal file
41
modules/java/src/java/core+CvVectorFloat.java
Normal file
@ -0,0 +1,41 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVectorFloat extends CvVector {
|
||||
private static final int _d = CvType.CV_32F;
|
||||
|
||||
public CvVectorFloat(int ch) {
|
||||
super(_d, ch);
|
||||
}
|
||||
|
||||
public CvVectorFloat(int ch, long addr) {
|
||||
super(_d, ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorFloat(long addr) {
|
||||
super(_d, 1, addr);
|
||||
}
|
||||
|
||||
public CvVectorFloat(int ch, Mat m) {
|
||||
super(_d, ch, m);
|
||||
}
|
||||
|
||||
public CvVectorFloat(int ch, float[] a) {
|
||||
super(_d, ch);
|
||||
if(a!=null) {
|
||||
int cnt = a.length / ch;
|
||||
create(cnt);
|
||||
put(0, 0, a);
|
||||
}
|
||||
}
|
||||
|
||||
public float[] toArray(float[] a) {
|
||||
int cnt = (int) total() * channels;
|
||||
if(cnt == 0)
|
||||
return new float[0];//null;
|
||||
float[] res = a;
|
||||
if(res==null || res.length<cnt)
|
||||
res = new float[cnt];
|
||||
get(0, 0, res); //TODO: check ret val!
|
||||
return res;
|
||||
}
|
||||
}
|
22
modules/java/src/java/core+CvVectorFloat4.java
Normal file
22
modules/java/src/java/core+CvVectorFloat4.java
Normal file
@ -0,0 +1,22 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVectorFloat4 extends CvVectorFloat {
|
||||
private static final int _ch = 4; //xxxC4
|
||||
|
||||
public CvVectorFloat4() {
|
||||
super(_ch);
|
||||
}
|
||||
|
||||
public CvVectorFloat4(long addr) {
|
||||
super(_ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorFloat4(Mat m) {
|
||||
super(_ch, m);
|
||||
}
|
||||
|
||||
public CvVectorFloat4(float[] a) {
|
||||
super(_ch, a);
|
||||
}
|
||||
|
||||
}
|
21
modules/java/src/java/core+CvVectorFloat6.java
Normal file
21
modules/java/src/java/core+CvVectorFloat6.java
Normal file
@ -0,0 +1,21 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVectorFloat6 extends CvVectorFloat {
|
||||
private static final int _ch = 6; //xxxC6
|
||||
|
||||
public CvVectorFloat6() {
|
||||
super(_ch);
|
||||
}
|
||||
|
||||
public CvVectorFloat6(long addr) {
|
||||
super(_ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorFloat6(Mat m) {
|
||||
super(_ch, m);
|
||||
}
|
||||
|
||||
public CvVectorFloat6(float[] a) {
|
||||
super(_ch, a);
|
||||
}
|
||||
}
|
38
modules/java/src/java/core+CvVectorInt.java
Normal file
38
modules/java/src/java/core+CvVectorInt.java
Normal file
@ -0,0 +1,38 @@
|
||||
package org.opencv.core;
|
||||
|
||||
|
||||
public class CvVectorInt extends CvVector {
|
||||
private static final int _d = CvType.CV_32S;
|
||||
|
||||
public CvVectorInt(int ch) {
|
||||
super(_d, ch);
|
||||
}
|
||||
|
||||
public CvVectorInt(int ch, long addr) {
|
||||
super(_d, ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorInt(int ch, Mat m) {
|
||||
super(_d, ch, m);
|
||||
}
|
||||
|
||||
public CvVectorInt(int ch, int[] a) {
|
||||
super(_d, ch);
|
||||
if(a!=null) {
|
||||
int cnt = a.length / ch;
|
||||
create(cnt);
|
||||
put(0, 0, a);
|
||||
}
|
||||
}
|
||||
|
||||
public int[] toArray(int[] a) {
|
||||
int cnt = (int) total() * channels;
|
||||
if(cnt == 0)
|
||||
return new int[0];//null;
|
||||
int[] res = a;
|
||||
if(res==null || res.length<cnt)
|
||||
res = new int[cnt];
|
||||
get(0, 0, res); //TODO: check ret val!
|
||||
return res;
|
||||
}
|
||||
}
|
53
modules/java/src/java/core+CvVectorKeyPoint.java
Normal file
53
modules/java/src/java/core+CvVectorKeyPoint.java
Normal file
@ -0,0 +1,53 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import org.opencv.features2d.KeyPoint;
|
||||
|
||||
public class CvVectorKeyPoint extends CvVectorFloat {
|
||||
private static final int _ch = 7; //xxxC7
|
||||
|
||||
public CvVectorKeyPoint() {
|
||||
super(_ch);
|
||||
}
|
||||
|
||||
public CvVectorKeyPoint(long addr) {
|
||||
super(_ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorKeyPoint(Mat m) {
|
||||
super(_ch, m);
|
||||
}
|
||||
|
||||
public CvVectorKeyPoint(KeyPoint[] a) {
|
||||
super(_ch);
|
||||
if(a==null)
|
||||
return;
|
||||
int cnt = a.length;
|
||||
create(cnt);
|
||||
float buff[] = new float[_ch * cnt];
|
||||
for(int i=0; i<cnt; i++) {
|
||||
KeyPoint kp = a[i];
|
||||
buff[_ch*i+0] = (float) kp.pt.x;
|
||||
buff[_ch*i+1] = (float) kp.pt.y;
|
||||
buff[_ch*i+2] = kp.size;
|
||||
buff[_ch*i+3] = kp.angle;
|
||||
buff[_ch*i+4] = kp.response;
|
||||
buff[_ch*i+5] = kp.octave;
|
||||
buff[_ch*i+6] = kp.class_id;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public KeyPoint[] toArray(KeyPoint[] a) {
|
||||
float buff[] = super.toArray(null);
|
||||
if(buff.length == 0)
|
||||
return new KeyPoint[0]; //null;
|
||||
int cnt = buff.length / _ch;
|
||||
KeyPoint[] res = a;
|
||||
if(a==null || a.length<cnt)
|
||||
res = new KeyPoint[cnt];
|
||||
for(int i=0; i<cnt; i++)
|
||||
res[i] = new KeyPoint( buff[_ch*i+0], buff[_ch*i+1], buff[_ch*i+2], buff[_ch*i+3],
|
||||
buff[_ch*i+4], (int) buff[_ch*i+5], (int) buff[_ch*i+6] );
|
||||
return res;
|
||||
}
|
||||
}
|
45
modules/java/src/java/core+CvVectorPoint.java
Normal file
45
modules/java/src/java/core+CvVectorPoint.java
Normal file
@ -0,0 +1,45 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVectorPoint extends CvVectorInt {
|
||||
private static final int _ch = 2; //xxxC2
|
||||
|
||||
public CvVectorPoint() {
|
||||
super(_ch);
|
||||
}
|
||||
|
||||
public CvVectorPoint(long addr) {
|
||||
super(_ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorPoint(Mat m) {
|
||||
super(_ch, m);
|
||||
}
|
||||
|
||||
public CvVectorPoint(Point[] a) {
|
||||
super(_ch);
|
||||
if(a==null)
|
||||
return;
|
||||
int cnt = a.length;
|
||||
create(cnt);
|
||||
int buff[] = new int[_ch * cnt];
|
||||
for(int i=0; i<cnt; i++) {
|
||||
Point p = a[i];
|
||||
buff[_ch*i+0] = (int) p.x;
|
||||
buff[_ch*i+1] = (int) p.y;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public Point[] toArray(Point[] a) {
|
||||
int buff[] = super.toArray(null);
|
||||
if(buff.length == 0)
|
||||
return new Point[0]; //null;
|
||||
int cnt = buff.length / _ch;
|
||||
Point[] res = a;
|
||||
if(a==null || a.length<cnt)
|
||||
res = new Point[cnt];
|
||||
for(int i=0; i<cnt; i++)
|
||||
res[i] = new Point(buff[i*_ch], buff[i*_ch+1]);
|
||||
return res;
|
||||
}
|
||||
}
|
45
modules/java/src/java/core+CvVectorPoint2f.java
Normal file
45
modules/java/src/java/core+CvVectorPoint2f.java
Normal file
@ -0,0 +1,45 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVectorPoint2f extends CvVectorFloat {
|
||||
private static final int _ch = 2; //xxxC2
|
||||
|
||||
public CvVectorPoint2f() {
|
||||
super(_ch);
|
||||
}
|
||||
|
||||
public CvVectorPoint2f(long addr) {
|
||||
super(_ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorPoint2f(Mat m) {
|
||||
super(_ch, m);
|
||||
}
|
||||
|
||||
public CvVectorPoint2f(Point[] a) {
|
||||
super(_ch);
|
||||
if(a==null)
|
||||
return;
|
||||
int cnt = a.length;
|
||||
create(cnt);
|
||||
float buff[] = new float[_ch * cnt];
|
||||
for(int i=0; i<cnt; i++) {
|
||||
Point p = a[i];
|
||||
buff[_ch*i+0] = (float) p.x;
|
||||
buff[_ch*i+1] = (float) p.y;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public Point[] toArray(Point[] a) {
|
||||
float buff[] = super.toArray(null);
|
||||
if(buff.length == 0)
|
||||
return new Point[0]; //null;
|
||||
int cnt = buff.length / _ch;
|
||||
Point[] res = a;
|
||||
if(a==null || a.length<cnt)
|
||||
res = new Point[cnt];
|
||||
for(int i=0; i<cnt; i++)
|
||||
res[i] = new Point(buff[i*_ch], buff[i*_ch+1]);
|
||||
return res;
|
||||
}
|
||||
}
|
46
modules/java/src/java/core+CvVectorPoint3.java
Normal file
46
modules/java/src/java/core+CvVectorPoint3.java
Normal file
@ -0,0 +1,46 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVectorPoint3 extends CvVectorInt {
|
||||
private static final int _ch = 3; //xxxC2
|
||||
|
||||
public CvVectorPoint3() {
|
||||
super(_ch);
|
||||
}
|
||||
|
||||
public CvVectorPoint3(long addr) {
|
||||
super(_ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorPoint3(Mat m) {
|
||||
super(_ch, m);
|
||||
}
|
||||
|
||||
public CvVectorPoint3(Point3[] a) {
|
||||
super(_ch);
|
||||
if(a==null)
|
||||
return;
|
||||
int cnt = a.length;
|
||||
create(cnt);
|
||||
int buff[] = new int[_ch * cnt];
|
||||
for(int i=0; i<cnt; i++) {
|
||||
Point3 p = a[i];
|
||||
buff[_ch*i] = (int) p.x;
|
||||
buff[_ch*i+1] = (int) p.y;
|
||||
buff[_ch*i+2] = (int) p.z;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public Point3[] toArray(Point3[] a) {
|
||||
int buff[] = super.toArray(null);
|
||||
if(buff.length == 0)
|
||||
return new Point3[0]; //null;
|
||||
int cnt = buff.length / _ch;
|
||||
Point3[] res = a;
|
||||
if(a==null || a.length<cnt)
|
||||
res = new Point3[cnt];
|
||||
for(int i=0; i<cnt; i++)
|
||||
res[i] = new Point3(buff[i*_ch], buff[i*_ch+1], buff[i*_ch+2]);
|
||||
return res;
|
||||
}
|
||||
}
|
46
modules/java/src/java/core+CvVectorPoint3f.java
Normal file
46
modules/java/src/java/core+CvVectorPoint3f.java
Normal file
@ -0,0 +1,46 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public class CvVectorPoint3f extends CvVectorFloat {
|
||||
private static final int _ch = 3; //xxxC2
|
||||
|
||||
public CvVectorPoint3f() {
|
||||
super(_ch);
|
||||
}
|
||||
|
||||
public CvVectorPoint3f(long addr) {
|
||||
super(_ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorPoint3f(Mat m) {
|
||||
super(_ch, m);
|
||||
}
|
||||
|
||||
public CvVectorPoint3f(Point3[] a) {
|
||||
super(_ch);
|
||||
if(a==null)
|
||||
return;
|
||||
int cnt = a.length;
|
||||
create(cnt);
|
||||
float buff[] = new float[_ch * cnt];
|
||||
for(int i=0; i<cnt; i++) {
|
||||
Point3 p = a[i];
|
||||
buff[_ch*i] = (float) p.x;
|
||||
buff[_ch*i+1] = (float) p.y;
|
||||
buff[_ch*i+2] = (float) p.z;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public Point3[] toArray(Point3[] a) {
|
||||
float buff[] = super.toArray(null);
|
||||
if(buff.length == 0)
|
||||
return new Point3[0]; //null;
|
||||
int cnt = buff.length / _ch;
|
||||
Point3[] res = a;
|
||||
if(a==null || a.length<cnt)
|
||||
res = new Point3[cnt];
|
||||
for(int i=0; i<cnt; i++)
|
||||
res[i] = new Point3(buff[i*_ch], buff[i*_ch+1], buff[i*_ch+2]);
|
||||
return res;
|
||||
}
|
||||
}
|
48
modules/java/src/java/core+CvVectorRect.java
Normal file
48
modules/java/src/java/core+CvVectorRect.java
Normal file
@ -0,0 +1,48 @@
|
||||
package org.opencv.core;
|
||||
|
||||
|
||||
public class CvVectorRect extends CvVectorInt {
|
||||
private static final int _ch = 4; //xxxC4
|
||||
|
||||
public CvVectorRect() {
|
||||
super(_ch);
|
||||
}
|
||||
|
||||
public CvVectorRect(long addr) {
|
||||
super(_ch, addr);
|
||||
}
|
||||
|
||||
public CvVectorRect(Mat m) {
|
||||
super(_ch, m);
|
||||
}
|
||||
|
||||
public CvVectorRect(Rect[] a) {
|
||||
super(_ch);
|
||||
if(a==null)
|
||||
return;
|
||||
int cnt = a.length;
|
||||
create(cnt);
|
||||
int buff[] = new int[_ch * cnt];
|
||||
for(int i=0; i<cnt; i++) {
|
||||
Rect r = a[i];
|
||||
buff[_ch*i] = r.x;
|
||||
buff[_ch*i+1] = r.y;
|
||||
buff[_ch*i+2] = r.width;
|
||||
buff[_ch*i+3] = r.height;
|
||||
}
|
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
}
|
||||
|
||||
public Rect[] toArray(Rect[] a) {
|
||||
int buff[] = super.toArray(null);
|
||||
if(buff.length == 0)
|
||||
return new Rect[0]; //null;
|
||||
int cnt = buff.length / _ch;
|
||||
Rect[] res = a;
|
||||
if(a==null || a.length<cnt)
|
||||
res = new Rect[cnt];
|
||||
for(int i=0; i<cnt; i++)
|
||||
res[i] = new Rect(buff[i*_ch], buff[i*_ch+1], buff[i*_ch+2], buff[i*_ch+3]);
|
||||
return res;
|
||||
}
|
||||
}
|
@ -3,11 +3,16 @@ package org.opencv.utils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.CvVectorPoint2f;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Point3;
|
||||
import org.opencv.core.Rect;
|
||||
import org.opencv.core.CvVectorByte;
|
||||
import org.opencv.core.CvVectorDMatch;
|
||||
import org.opencv.core.CvVectorKeyPoint;
|
||||
import org.opencv.core.CvVectorPoint;
|
||||
import org.opencv.features2d.DMatch;
|
||||
import org.opencv.features2d.KeyPoint;
|
||||
|
||||
@ -468,14 +473,14 @@ public class Converters {
|
||||
(float) buff[7 * i + 4], (int) buff[7 * i + 5], (int) buff[7 * i + 6]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// vector_vector_Point
|
||||
public static Mat vector_vector_Point_to_Mat(List<List<Point>> pts, List<Mat> mats) {
|
||||
public static Mat vector_vector_Point_to_Mat(List<CvVectorPoint> pts, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (pts != null) ? pts.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (List<Point> lpt : pts)
|
||||
mats.add(vector_Point_to_Mat(lpt));
|
||||
for (CvVectorPoint vpt : pts)
|
||||
mats.add(vpt);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
@ -483,8 +488,7 @@ public class Converters {
|
||||
return res;
|
||||
}
|
||||
|
||||
// vector_vector_Point2f
|
||||
public static void Mat_to_vector_vector_Point2f(Mat m, List<List<Point>> pts) {
|
||||
public static void Mat_to_vector_vector_Point(Mat m, List<CvVectorPoint> pts) {
|
||||
if (pts == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
@ -494,19 +498,34 @@ public class Converters {
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
for (Mat mi : mats) {
|
||||
List<Point> pt = new ArrayList<Point>();
|
||||
Mat_to_vector_Point2f(mi, pt);
|
||||
CvVectorPoint pt = new CvVectorPoint(mi);
|
||||
pts.add(pt);
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_Point2f
|
||||
public static void Mat_to_vector_vector_Point2f(Mat m, List<CvVectorPoint2f> 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) {
|
||||
CvVectorPoint2f pt = new CvVectorPoint2f(mi);
|
||||
pts.add(pt);
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_KeyPoint
|
||||
public static Mat vector_vector_KeyPoint_to_Mat(List<List<KeyPoint>> kps, List<Mat> mats) {
|
||||
public static Mat vector_vector_KeyPoint_to_Mat(List<CvVectorKeyPoint> kps, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (kps != null) ? kps.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (List<KeyPoint> lkp : kps)
|
||||
mats.add(vector_KeyPoint_to_Mat(lkp));
|
||||
for (CvVectorKeyPoint vkp : kps)
|
||||
mats.add(vkp);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
@ -514,7 +533,7 @@ public class Converters {
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_KeyPoint(Mat m, List<List<KeyPoint>> kps) {
|
||||
public static void Mat_to_vector_vector_KeyPoint(Mat m, List<CvVectorKeyPoint> kps) {
|
||||
if (kps == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
@ -524,9 +543,8 @@ public class Converters {
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
for (Mat mi : mats) {
|
||||
List<KeyPoint> lkp = new ArrayList<KeyPoint>();
|
||||
Mat_to_vector_KeyPoint(mi, lkp);
|
||||
kps.add(lkp);
|
||||
CvVectorKeyPoint vkp = new CvVectorKeyPoint(mi);
|
||||
kps.add(vkp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -600,12 +618,12 @@ public class Converters {
|
||||
}
|
||||
|
||||
// vector_vector_DMatch
|
||||
public static Mat vector_vector_DMatch_to_Mat(List<List<DMatch>> lldm, List<Mat> mats) {
|
||||
public static Mat vector_vector_DMatch_to_Mat(List<CvVectorDMatch> lvdm, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (lldm != null) ? lldm.size() : 0;
|
||||
int lCount = (lvdm != null) ? lvdm.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (List<DMatch> ldm : lldm)
|
||||
mats.add(vector_DMatch_to_Mat(ldm));
|
||||
for (CvVectorDMatch vdm : lvdm)
|
||||
mats.add(vdm);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
@ -613,8 +631,8 @@ public class Converters {
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_DMatch(Mat m, List<List<DMatch>> lldm) {
|
||||
if (lldm == null)
|
||||
public static void Mat_to_vector_vector_DMatch(Mat m, List<CvVectorDMatch> lvdm) {
|
||||
if (lvdm == null)
|
||||
throw new java.lang.IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if (m == null)
|
||||
@ -622,20 +640,20 @@ public class Converters {
|
||||
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
lvdm.clear();
|
||||
for (Mat mi : mats) {
|
||||
List<DMatch> ldm = new ArrayList<DMatch>();
|
||||
Mat_to_vector_DMatch(mi, ldm);
|
||||
lldm.add(ldm);
|
||||
CvVectorDMatch vdm = new CvVectorDMatch(mi);
|
||||
lvdm.add(vdm);
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_char
|
||||
public static Mat vector_vector_char_to_Mat(List<List<Byte>> llb, List<Mat> mats) {
|
||||
public static Mat vector_vector_char_to_Mat(List<CvVectorByte> lvb, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (llb != null) ? llb.size() : 0;
|
||||
int lCount = (lvb != null) ? lvb.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (List<Byte> lb : llb)
|
||||
mats.add(vector_char_to_Mat(lb));
|
||||
for (CvVectorByte vb : lvb)
|
||||
mats.add(vb);
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user