Java API: fixed input List<List<smth>> arguments

This commit is contained in:
Andrey Kamaev 2011-08-10 14:09:22 +00:00
parent f9ef92d45a
commit 92afe9e40a
6 changed files with 215 additions and 207 deletions

View File

@ -1,6 +1,7 @@
package org.opencv.test.core; package org.opencv.test.core;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.core.CvException;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.Range; import org.opencv.core.Range;
@ -175,11 +176,19 @@ public class MatTest extends OpenCVTestCase {
} }
public void testDiagMat() { public void testDiagMat() {
dst = Mat.diag(gray255); Mat diagVector = new Mat(matSize, 1, CvType.CV_32F, new Scalar(1));
truth = new Mat(1, matSize, CvType.CV_8U, new Scalar(255)); dst = Mat.diag(diagVector);
assertMatEqual(truth, dst); assertMatEqual(grayE_32f, dst, EPS);
}
public void testDiagMat_sqrMatrix() {
try {
dst = Mat.diag(gray255);
} catch (CvException e) {
// expected
}
} }
public void testDot() { public void testDot() {

View File

@ -1,9 +1,5 @@
package org.opencv.test.utils; package org.opencv.test.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.Point; import org.opencv.core.Point;
@ -12,9 +8,11 @@ import org.opencv.core.Rect;
import org.opencv.features2d.DMatch; import org.opencv.features2d.DMatch;
import org.opencv.features2d.KeyPoint; import org.opencv.features2d.KeyPoint;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner;
import org.opencv.utils.Converters; import org.opencv.utils.Converters;
import java.util.ArrayList;
import java.util.List;
public class ConvertersTest extends OpenCVTestCase { public class ConvertersTest extends OpenCVTestCase {
public void testMat_to_vector_char() { public void testMat_to_vector_char() {
@ -481,17 +479,6 @@ public class ConvertersTest extends OpenCVTestCase {
public void testVector_vector_char_to_Mat() { public void testVector_vector_char_to_Mat() {
fail("Not yet implemented"); fail("Not yet implemented");
List<List<Byte>> llb = new ArrayList<List<Byte>>();
byte value1 = 1;
byte value2 = 2;
byte value3 = 3;
byte value4 = 4;
llb.add(Arrays.asList(new Byte(value1), new Byte(value2), new Byte(value3), new Byte(value4)));
dst = Converters.vector_vector_char_to_Mat(llb);
OpenCVTestRunner.Log(dst.toString());
OpenCVTestRunner.Log(dst.dump());
} }
public void testVector_vector_DMatch_to_Mat() { public void testVector_vector_DMatch_to_Mat() {
@ -503,13 +490,6 @@ public class ConvertersTest extends OpenCVTestCase {
} }
public void testVector_vector_Point_to_Mat() { public void testVector_vector_Point_to_Mat() {
List<List<Point>> points = new ArrayList<List<Point>>();
points.add(Arrays.asList(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6),
new Point(5, 5), new Point(8, 9)));
dst = Converters.vector_vector_Point_to_Mat(points);
// TODO: returns random dst matrix
// assertMatEqual();
fail("Not yet implemented"); fail("Not yet implemented");
} }

View File

@ -1137,7 +1137,12 @@ extern "C" {
c_prologue.append( type_dict[a.ctype]["jni_var"] % {"n" : a.name} + ";" ) c_prologue.append( type_dict[a.ctype]["jni_var"] % {"n" : a.name} + ";" )
c_prologue.append( "Mat& %(n)s_mat = *((Mat*)%(n)s_mat_nativeObj)" % {"n" : a.name} + ";" ) c_prologue.append( "Mat& %(n)s_mat = *((Mat*)%(n)s_mat_nativeObj)" % {"n" : a.name} + ";" )
if "I" in a.out or not a.out: if "I" in a.out or not a.out:
j_prologue.append( "Mat %(n)s_mat = Converters.%(t)s_to_Mat(%(n)s);" % {"n" : a.name, "t" : a.ctype} ) if a.ctype.startswith("vector_vector_"):
self.classes[fi.classname or self.Module].imports.add("java.util.ArrayList")
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} )
c_prologue.append( "Mat_to_%(t)s( %(n)s_mat, %(n)s );" % {"n" : a.name, "t" : a.ctype} ) c_prologue.append( "Mat_to_%(t)s( %(n)s_mat, %(n)s );" % {"n" : a.name, "t" : a.ctype} )
else: else:
j_prologue.append( "Mat %s_mat = new Mat();" % a.name ) j_prologue.append( "Mat %s_mat = new Mat();" % a.name )
@ -1246,8 +1251,8 @@ extern "C" {
ret = ret, \ ret = ret, \
ret_val = ret_val, \ ret_val = ret_val, \
tail = tail, \ tail = tail, \
prologue = " ".join(j_prologue), \ prologue = "\n ".join(j_prologue), \
epilogue = " ".join(j_epilogue), \ epilogue = "\n ".join(j_epilogue), \
static=static, \ static=static, \
j_type=type_dict[fi.ctype]["j_type"], \ j_type=type_dict[fi.ctype]["j_type"], \
j_name=fi.jname, \ j_name=fi.jname, \

View File

@ -17,14 +17,14 @@ using namespace cv;
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.cols==1); CHECK_MAT(mat.type()==CV_32SC1 && mat.cols==1);
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 = Mat(v_int, true); mat = Mat(v_int, true);
} }
@ -32,14 +32,14 @@ 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.cols==1); CHECK_MAT(mat.type()==CV_64FC1 && mat.cols==1);
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 = Mat(v_double, true); mat = Mat(v_double, true);
} }
@ -47,14 +47,14 @@ 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.cols==1); CHECK_MAT(mat.type()==CV_32FC1 && mat.cols==1);
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 = Mat(v_float, true); mat = Mat(v_float, true);
} }
@ -62,26 +62,26 @@ 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.cols==1); CHECK_MAT(mat.type()==CV_8UC1 && mat.cols==1);
v_uchar = (vector<uchar>) mat; v_uchar = (vector<uchar>) mat;
} }
void vector_uchar_to_Mat(vector<uchar>& v_uchar, Mat& mat) void vector_uchar_to_Mat(vector<uchar>& v_uchar, Mat& mat)
{ {
mat = Mat(v_uchar, true); mat = Mat(v_uchar, true);
} }
void Mat_to_vector_char(Mat& mat, vector<char>& v_char) void Mat_to_vector_char(Mat& mat, vector<char>& v_char)
{ {
v_char.clear(); v_char.clear();
CHECK_MAT(mat.type()==CV_8SC1 && mat.cols==1); CHECK_MAT(mat.type()==CV_8SC1 && mat.cols==1);
v_char = (vector<char>) mat; v_char = (vector<char>) mat;
} }
void vector_char_to_Mat(vector<char>& v_char, Mat& mat) void vector_char_to_Mat(vector<char>& v_char, Mat& mat)
{ {
mat = Mat(v_char, true); mat = Mat(v_char, true);
} }
@ -89,95 +89,95 @@ void vector_char_to_Mat(vector<char>& v_char, Mat& mat)
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.cols==1); CHECK_MAT(mat.type()==CV_32SC4 && mat.cols==1);
v_rect = (vector<Rect>) mat; v_rect = (vector<Rect>) mat;
} }
void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat) void vector_Rect_to_Mat(vector<Rect>& v_rect, Mat& mat)
{ {
mat = Mat(v_rect, true); mat = Mat(v_rect, true);
} }
//vector_Point //vector_Point
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.cols==1); CHECK_MAT(mat.type()==CV_32SC2 && mat.cols==1);
v_point = (vector<Point>) mat; v_point = (vector<Point>) mat;
} }
//vector_Point2f //vector_Point2f
void Mat_to_vector_Point2f(Mat& mat, vector<Point2f>& v_point) void Mat_to_vector_Point2f(Mat& mat, vector<Point2f>& v_point)
{ {
v_point.clear(); v_point.clear();
CHECK_MAT(mat.type()==CV_32FC2 && mat.cols==1); CHECK_MAT(mat.type()==CV_32FC2 && mat.cols==1);
v_point = (vector<Point2f>) mat; v_point = (vector<Point2f>) mat;
} }
//vector_Point2d //vector_Point2d
void Mat_to_vector_Point2d(Mat& mat, vector<Point2d>& v_point) void Mat_to_vector_Point2d(Mat& mat, vector<Point2d>& v_point)
{ {
v_point.clear(); v_point.clear();
CHECK_MAT(mat.type()==CV_64FC2 && mat.cols==1); CHECK_MAT(mat.type()==CV_64FC2 && mat.cols==1);
v_point = (vector<Point2d>) mat; v_point = (vector<Point2d>) mat;
} }
//vector_Point3i //vector_Point3i
void Mat_to_vector_Point3i(Mat& mat, vector<Point3i>& v_point) void Mat_to_vector_Point3i(Mat& mat, vector<Point3i>& v_point)
{ {
v_point.clear(); v_point.clear();
CHECK_MAT(mat.type()==CV_32SC3 && mat.cols==1); CHECK_MAT(mat.type()==CV_32SC3 && mat.cols==1);
v_point = (vector<Point3i>) mat; v_point = (vector<Point3i>) mat;
} }
//vector_Point3f //vector_Point3f
void Mat_to_vector_Point3f(Mat& mat, vector<Point3f>& v_point) void Mat_to_vector_Point3f(Mat& mat, vector<Point3f>& v_point)
{ {
v_point.clear(); v_point.clear();
CHECK_MAT(mat.type()==CV_32FC3 && mat.cols==1); CHECK_MAT(mat.type()==CV_32FC3 && mat.cols==1);
v_point = (vector<Point3f>) mat; v_point = (vector<Point3f>) mat;
} }
//vector_Point3d //vector_Point3d
void Mat_to_vector_Point3d(Mat& mat, vector<Point3d>& v_point) void Mat_to_vector_Point3d(Mat& mat, vector<Point3d>& v_point)
{ {
v_point.clear(); v_point.clear();
CHECK_MAT(mat.type()==CV_64FC3 && mat.cols==1); CHECK_MAT(mat.type()==CV_64FC3 && mat.cols==1);
v_point = (vector<Point3d>) mat; v_point = (vector<Point3d>) mat;
} }
void vector_Point_to_Mat(vector<Point>& v_point, Mat& mat) void vector_Point_to_Mat(vector<Point>& v_point, Mat& mat)
{ {
mat = Mat(v_point, true); mat = Mat(v_point, true);
} }
void vector_Point2f_to_Mat(vector<Point2f>& v_point, Mat& mat) void vector_Point2f_to_Mat(vector<Point2f>& v_point, Mat& mat)
{ {
mat = Mat(v_point, true); mat = Mat(v_point, true);
} }
void vector_Point2d_to_Mat(vector<Point2d>& v_point, Mat& mat) void vector_Point2d_to_Mat(vector<Point2d>& v_point, Mat& mat)
{ {
mat = Mat(v_point, true); mat = Mat(v_point, true);
} }
void vector_Point3i_to_Mat(vector<Point3i>& v_point, Mat& mat) void vector_Point3i_to_Mat(vector<Point3i>& v_point, Mat& mat)
{ {
mat = Mat(v_point, true); mat = Mat(v_point, true);
} }
void vector_Point3f_to_Mat(vector<Point3f>& v_point, Mat& mat) void vector_Point3f_to_Mat(vector<Point3f>& v_point, Mat& mat)
{ {
mat = Mat(v_point, true); mat = Mat(v_point, true);
} }
void vector_Point3d_to_Mat(vector<Point3d>& v_point, Mat& mat) void vector_Point3d_to_Mat(vector<Point3d>& v_point, Mat& mat)
{ {
mat = Mat(v_point, true); mat = Mat(v_point, true);
} }
@ -186,56 +186,57 @@ void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
{ {
v_kp.clear(); v_kp.clear();
CHECK_MAT(mat.type()==CV_64FC(7) && mat.cols==1); CHECK_MAT(mat.type()==CV_64FC(7) && mat.cols==1);
for(int i=0; i<mat.rows; i++) for(int i=0; i<mat.rows; i++)
{ {
Vec<double, 7> v = mat.at< Vec<double, 7> >(i, 0); 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]); 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); v_kp.push_back(kp);
} }
return; return;
} }
void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat) void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat)
{ {
int count = v_kp.size(); int count = v_kp.size();
mat.create(count, 1, CV_64FC(7)); mat.create(count, 1, CV_64FC(7));
for(int i=0; i<count; i++) for(int i=0; i<count; i++)
{ {
KeyPoint kp = v_kp[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<double, 7> >(i, 0) = Vec<double, 7>(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id);
} }
} }
//vector_Mat //vector_Mat
void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat) void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat)
{ {
v_mat.clear(); v_mat.clear();
if(mat.type() == CV_32SC2 && mat.cols == 1) if(mat.type() == CV_32SC2 && mat.cols == 1)
{ {
for(int i=0; i<mat.rows; i++) v_mat.reserve(mat.rows);
{ for(int i=0; i<mat.rows; i++)
Vec<int, 2> a = mat.at< Vec<int, 2> >(i, 0); {
long long addr = (((long long)a[0])<<32) | a[1]; Vec<int, 2> a = mat.at< Vec<int, 2> >(i, 0);
Mat& m = *( (Mat*) addr ); long long addr = (((long long)a[0])<<32) | a[1];
v_mat.push_back(m); Mat& m = *( (Mat*) addr );
} v_mat.push_back(m);
} else { }
LOGD("Mat_to_vector_Mat() FAILED: mat.type() == CV_32SC2 && mat.cols == 1"); } else {
} LOGD("Mat_to_vector_Mat() FAILED: mat.type() == CV_32SC2 && mat.cols == 1");
}
} }
void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat) void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
{ {
int count = v_mat.size(); int count = v_mat.size();
mat.create(count, 1, CV_32SC2); mat.create(count, 1, CV_32SC2);
for(int i=0; i<count; i++) for(int i=0; i<count; i++)
{ {
long long addr = (long long) new Mat(v_mat[i]); long long addr = (long long) new Mat(v_mat[i]);
mat.at< Vec<int, 2> >(i, 0) = Vec<int, 2>(addr>>32, addr&0xffffffff); mat.at< Vec<int, 2> >(i, 0) = Vec<int, 2>(addr>>32, addr&0xffffffff);
} }
} }
//vector_DMatch //vector_DMatch
@ -243,137 +244,137 @@ void Mat_to_vector_DMatch(Mat& mat, vector<DMatch>& v_dm)
{ {
v_dm.clear(); v_dm.clear();
CHECK_MAT(mat.type()==CV_64FC4 && mat.cols==1); CHECK_MAT(mat.type()==CV_64FC4 && mat.cols==1);
for(int i=0; i<mat.rows; i++) for(int i=0; i<mat.rows; i++)
{ {
Vec<double, 4> v = mat.at< Vec<double, 4> >(i, 0); 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]); DMatch dm((int)v[0], (int)v[1], (int)v[2], (float)v[3]);
v_dm.push_back(dm); v_dm.push_back(dm);
} }
return; return;
} }
void vector_DMatch_to_Mat(vector<DMatch>& v_dm, Mat& mat) void vector_DMatch_to_Mat(vector<DMatch>& v_dm, Mat& mat)
{ {
int count = v_dm.size(); int count = v_dm.size();
mat.create(count, 1, CV_64FC4); mat.create(count, 1, CV_64FC4);
for(int i=0; i<count; i++) for(int i=0; i<count; i++)
{ {
DMatch dm = v_dm[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<double, 4> >(i, 0) = Vec<double, 4>(dm.queryIdx, dm.trainIdx, dm.imgIdx, dm.distance);
} }
} }
void Mat_to_vector_vector_Point(Mat& mat, vector< vector< Point > >& vv_pt) void Mat_to_vector_vector_Point(Mat& mat, vector< vector< Point > >& vv_pt)
{ {
vector<Mat> vm; vector<Mat> vm;
vm.reserve( mat.rows ); vm.reserve( mat.rows );
Mat_to_vector_Mat(mat, vm); Mat_to_vector_Mat(mat, vm);
for(size_t i=0; i<vm.size(); i++) for(size_t i=0; i<vm.size(); i++)
{ {
vector<Point> vpt; vector<Point> vpt;
Mat_to_vector_Point(vm[i], vpt); Mat_to_vector_Point(vm[i], vpt);
vv_pt.push_back(vpt); vv_pt.push_back(vpt);
} }
} }
void Mat_to_vector_vector_KeyPoint(Mat& mat, vector< vector< KeyPoint > >& vv_kp) void Mat_to_vector_vector_KeyPoint(Mat& mat, vector< vector< KeyPoint > >& vv_kp)
{ {
vector<Mat> vm; vector<Mat> vm;
vm.reserve( mat.rows ); vm.reserve( mat.rows );
Mat_to_vector_Mat(mat, vm); Mat_to_vector_Mat(mat, vm);
for(size_t i=0; i<vm.size(); i++) for(size_t i=0; i<vm.size(); i++)
{ {
vector<KeyPoint> vkp; vector<KeyPoint> vkp;
Mat_to_vector_KeyPoint(vm[i], vkp); Mat_to_vector_KeyPoint(vm[i], vkp);
vv_kp.push_back(vkp); vv_kp.push_back(vkp);
} }
} }
void vector_vector_KeyPoint_to_Mat(vector< vector< KeyPoint > >& vv_kp, Mat& mat) void vector_vector_KeyPoint_to_Mat(vector< vector< KeyPoint > >& vv_kp, Mat& mat)
{ {
vector<Mat> vm; vector<Mat> vm;
vm.reserve( vv_kp.size() ); vm.reserve( vv_kp.size() );
for(size_t i=0; i<vv_kp.size(); i++) for(size_t i=0; i<vv_kp.size(); i++)
{ {
Mat m; Mat m;
vector_KeyPoint_to_Mat(vv_kp[i], m); vector_KeyPoint_to_Mat(vv_kp[i], m);
vm.push_back(m); vm.push_back(m);
} }
vector_Mat_to_Mat(vm, mat); vector_Mat_to_Mat(vm, mat);
} }
void Mat_to_vector_vector_DMatch(Mat& mat, vector< vector< DMatch > >& vv_dm) void Mat_to_vector_vector_DMatch(Mat& mat, vector< vector< DMatch > >& vv_dm)
{ {
vector<Mat> vm; vector<Mat> vm;
vm.reserve( mat.rows ); vm.reserve( mat.rows );
Mat_to_vector_Mat(mat, vm); Mat_to_vector_Mat(mat, vm);
for(size_t i=0; i<vm.size(); i++) for(size_t i=0; i<vm.size(); i++)
{ {
vector<DMatch> vdm; vector<DMatch> vdm;
Mat_to_vector_DMatch(vm[i], vdm); Mat_to_vector_DMatch(vm[i], vdm);
vv_dm.push_back(vdm); vv_dm.push_back(vdm);
} }
} }
void vector_vector_DMatch_to_Mat(vector< vector< DMatch > >& vv_dm, Mat& mat) void vector_vector_DMatch_to_Mat(vector< vector< DMatch > >& vv_dm, Mat& mat)
{ {
vector<Mat> vm; vector<Mat> vm;
vm.reserve( vv_dm.size() ); vm.reserve( vv_dm.size() );
for(size_t i=0; i<vv_dm.size(); i++) for(size_t i=0; i<vv_dm.size(); i++)
{ {
Mat m; Mat m;
vector_DMatch_to_Mat(vv_dm[i], m); vector_DMatch_to_Mat(vv_dm[i], m);
vm.push_back(m); vm.push_back(m);
} }
vector_Mat_to_Mat(vm, mat); vector_Mat_to_Mat(vm, mat);
} }
void Mat_to_vector_vector_char(Mat& mat, vector< vector< char > >& vv_ch) void Mat_to_vector_vector_char(Mat& mat, vector< vector< char > >& vv_ch)
{ {
vector<Mat> vm; vector<Mat> vm;
vm.reserve( mat.rows ); vm.reserve( mat.rows );
Mat_to_vector_Mat(mat, vm); Mat_to_vector_Mat(mat, vm);
for(size_t i=0; i<vm.size(); i++) for(size_t i=0; i<vm.size(); i++)
{ {
vector<char> vch; vector<char> vch;
Mat_to_vector_char(vm[i], vch); Mat_to_vector_char(vm[i], vch);
vv_ch.push_back(vch); vv_ch.push_back(vch);
} }
} }
void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& mat) void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& mat)
{ {
vector<Mat> vm; vector<Mat> vm;
vm.reserve( vv_ch.size() ); vm.reserve( vv_ch.size() );
for(size_t i=0; i<vv_ch.size(); i++) for(size_t i=0; i<vv_ch.size(); i++)
{ {
Mat m; Mat m;
vector_char_to_Mat(vv_ch[i], m); vector_char_to_Mat(vv_ch[i], m);
vm.push_back(m); vm.push_back(m);
} }
vector_Mat_to_Mat(vm, mat); vector_Mat_to_Mat(vm, mat);
} }
void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat) void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat)
{ {
vector<Mat> vm; vector<Mat> vm;
vm.reserve( vv_pt.size() ); vm.reserve( vv_pt.size() );
for(size_t i=0; i<vv_pt.size(); i++) for(size_t i=0; i<vv_pt.size(); i++)
{ {
Mat m; Mat m;
vector_Point2f_to_Mat(vv_pt[i], m); vector_Point2f_to_Mat(vv_pt[i], m);
vm.push_back(m); vm.push_back(m);
} }
vector_Mat_to_Mat(vm, mat); vector_Mat_to_Mat(vm, mat);
} }
void vector_Vec4f_to_Mat(vector<Vec4f>& v_vec, Mat& mat) void vector_Vec4f_to_Mat(vector<Vec4f>& v_vec, Mat& mat)
{ {
mat = Mat(v_vec, true); mat = Mat(v_vec, true);
} }
void vector_Vec6f_to_Mat(vector<Vec6f>& v_vec, Mat& mat) void vector_Vec6f_to_Mat(vector<Vec6f>& v_vec, Mat& mat)
{ {
mat = Mat(v_vec, true); mat = Mat(v_vec, true);
} }

View File

@ -108,7 +108,7 @@ public class Mat {
public Mat(Mat m, Rect roi) public Mat(Mat m, Rect roi)
{ {
nativeObj = n_Mat(m.nativeObj, roi.x, roi.y, roi.width, roi.height); nativeObj = n_Mat(m.nativeObj, roi.x, roi.x + roi.width, roi.y, roi.y + roi.height);
return; return;
} }

View File

@ -469,12 +469,11 @@ public class Converters {
} }
} }
// vector_vector_Point // vector_vector_Point
public static Mat vector_vector_Point_to_Mat(List<List<Point>> pts) { public static Mat vector_vector_Point_to_Mat(List<List<Point>> pts, List<Mat> mats) {
Mat res; Mat res;
int lCount = (pts != null) ? pts.size() : 0; int lCount = (pts != null) ? pts.size() : 0;
if (lCount > 0) { if (lCount > 0) {
List<Mat> mats = new ArrayList<Mat>(lCount);
for (List<Point> lpt : pts) for (List<Point> lpt : pts)
mats.add(vector_Point_to_Mat(lpt)); mats.add(vector_Point_to_Mat(lpt));
res = vector_Mat_to_Mat(mats); res = vector_Mat_to_Mat(mats);
@ -484,12 +483,28 @@ public class Converters {
return res; return res;
} }
// vector_vector_Point2f
public static void Mat_to_vector_vector_Point2f(Mat m, List<List<Point>> 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);
List<Point> pt = new ArrayList<Point>();
for (Mat mi : mats) {
Mat_to_vector_Point2f(mi, pt);
pts.add(pt);
}
}
// vector_vector_KeyPoint // vector_vector_KeyPoint
public static Mat vector_vector_KeyPoint_to_Mat(List<List<KeyPoint>> kps) { public static Mat vector_vector_KeyPoint_to_Mat(List<List<KeyPoint>> kps, List<Mat> mats) {
Mat res; Mat res;
int lCount = (kps != null) ? kps.size() : 0; int lCount = (kps != null) ? kps.size() : 0;
if (lCount > 0) { if (lCount > 0) {
List<Mat> mats = new ArrayList<Mat>(lCount);
for (List<KeyPoint> lkp : kps) for (List<KeyPoint> lkp : kps)
mats.add(vector_KeyPoint_to_Mat(lkp)); mats.add(vector_KeyPoint_to_Mat(lkp));
res = vector_Mat_to_Mat(mats); res = vector_Mat_to_Mat(mats);
@ -569,11 +584,10 @@ public class Converters {
} }
// vector_vector_DMatch // vector_vector_DMatch
public static Mat vector_vector_DMatch_to_Mat(List<List<DMatch>> lldm) { public static Mat vector_vector_DMatch_to_Mat(List<List<DMatch>> lldm, List<Mat> mats) {
Mat res; Mat res;
int lCount = (lldm != null) ? lldm.size() : 0; int lCount = (lldm != null) ? lldm.size() : 0;
if (lCount > 0) { if (lCount > 0) {
List<Mat> mats = new ArrayList<Mat>(lCount);
for (List<DMatch> ldm : lldm) for (List<DMatch> ldm : lldm)
mats.add(vector_DMatch_to_Mat(ldm)); mats.add(vector_DMatch_to_Mat(ldm));
res = vector_Mat_to_Mat(mats); res = vector_Mat_to_Mat(mats);
@ -600,11 +614,10 @@ public class Converters {
} }
// vector_vector_char // vector_vector_char
public static Mat vector_vector_char_to_Mat(List<List<Byte>> llb) { public static Mat vector_vector_char_to_Mat(List<List<Byte>> llb, List<Mat> mats) {
Mat res; Mat res;
int lCount = (llb != null) ? llb.size() : 0; int lCount = (llb != null) ? llb.size() : 0;
if (lCount > 0) { if (lCount > 0) {
List<Mat> mats = new ArrayList<Mat>(lCount);
for (List<Byte> lb : llb) for (List<Byte> lb : llb)
mats.add(vector_char_to_Mat(lb)); mats.add(vector_char_to_Mat(lb));
res = vector_Mat_to_Mat(mats); res = vector_Mat_to_Mat(mats);