mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 07:13:02 +04:00
Merge branch 4.x
This commit is contained in:
@@ -756,6 +756,13 @@ class JavaWrapperGenerator(object):
|
||||
"jdouble _tmp_retval_[%(cnt)i] = {%(args)s}; " +
|
||||
"env->SetDoubleArrayRegion(_da_retval_, 0, %(cnt)i, _tmp_retval_);") %
|
||||
{ "cnt" : len(fields), "args" : ", ".join(["(jdouble)_retval_" + f[1] for f in fields]) } )
|
||||
elif type_dict[fi.ctype]["jni_type"] == "jintArray":
|
||||
fields = type_dict[fi.ctype]["jn_args"]
|
||||
c_epilogue.append(
|
||||
("jintArray _ia_retval_ = env->NewIntArray(%(cnt)i); " +
|
||||
"jint _tmp_retval_[%(cnt)i] = {%(args)s}; " +
|
||||
"env->SetIntArrayRegion(_ia_retval_, 0, %(cnt)i, _tmp_retval_);") %
|
||||
{ "cnt" : len(fields), "args" : ", ".join(["(jint)_retval_" + f[1] for f in fields]) } )
|
||||
if fi.classname and fi.ctype and not fi.static: # non-static class method except c-tor
|
||||
# adding 'self'
|
||||
jn_args.append ( ArgInfo([ "__int64", "nativeObj", "", [], "" ]) )
|
||||
@@ -803,7 +810,14 @@ class JavaWrapperGenerator(object):
|
||||
fields = type_dict[a.ctype].get("jn_args", ((a.ctype, ""),))
|
||||
if "I" in a.out or not a.out or self.isWrapped(a.ctype): # input arg, pass by primitive fields
|
||||
for f in fields:
|
||||
jn_args.append ( ArgInfo([ f[0], a.name + f[1], "", [], "" ]) )
|
||||
# Use array access format for Java code when jn_type is array type
|
||||
if type_dict[a.ctype].get("jn_type", "").endswith("[]"):
|
||||
# For Java code: convert .val[0] format to [0] format
|
||||
jn_args.append ( ArgInfo([ f[0], a.name + f[1].replace(".val[", "["), "", [], "" ]) )
|
||||
else:
|
||||
# For non-array types, use conventional format
|
||||
jn_args.append ( ArgInfo([ f[0], a.name + f[1], "", [], "" ]) )
|
||||
# For C++ code: use conventional format as is
|
||||
jni_args.append( ArgInfo([ f[0], a.name + normalize_field_name(f[1]), "", [], "" ]) )
|
||||
if "O" in a.out and not self.isWrapped(a.ctype): # out arg, pass as double[]
|
||||
jn_args.append ( ArgInfo([ "double[]", "%s_out" % a.name, "", [], "" ]) )
|
||||
@@ -818,9 +832,16 @@ class JavaWrapperGenerator(object):
|
||||
set_vals = []
|
||||
i = 0
|
||||
for f in fields:
|
||||
set_vals.append( "%(n)s%(f)s = %(t)s%(n)s_out[%(i)i]" %
|
||||
{"n" : a.name, "t": ("("+type_dict[f[0]]["j_type"]+")", "")[f[0]=="double"], "f" : f[1], "i" : i}
|
||||
)
|
||||
# Use array access format for Java code when jn_type is array type
|
||||
if type_dict[a.ctype].get("jn_type", "").endswith("[]"):
|
||||
# For Java code: convert .val[0] format to [0] format
|
||||
set_vals.append( "%(n)s%(f)s = %(t)s%(n)s_out[%(i)i]" %
|
||||
{"n" : a.name, "t": ("("+type_dict[f[0]]["j_type"]+")", "")[f[0]=="double"], "f" : f[1].replace(".val[", "["), "i" : i}
|
||||
)
|
||||
else:
|
||||
set_vals.append( "%(n)s%(f)s = %(t)s%(n)s_out[%(i)i]" %
|
||||
{"n" : a.name, "t": ("("+type_dict[f[0]]["j_type"]+")", "")[f[0]=="double"], "f" : f[1], "i" : i}
|
||||
)
|
||||
i += 1
|
||||
j_epilogue.append( "if("+a.name+"!=null){ " + "; ".join(set_vals) + "; } ")
|
||||
|
||||
@@ -1015,6 +1036,8 @@ class JavaWrapperGenerator(object):
|
||||
ret = "return (jlong) _retval_;"
|
||||
elif type_dict[fi.ctype]["jni_type"] == "jdoubleArray":
|
||||
ret = "return _da_retval_;"
|
||||
elif type_dict[fi.ctype]["jni_type"] == "jintArray":
|
||||
ret = "return _ia_retval_;"
|
||||
elif "jni_var" in type_dict[ret_type]:
|
||||
c_epilogue.append(type_dict[ret_type]["jni_var"] % {"n" : '_retval_'})
|
||||
ret = f"return {type_dict[ret_type]['jni_name'] % {'n' : '_retval_'}};"
|
||||
|
||||
@@ -219,6 +219,32 @@ void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
|
||||
}
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_Mat(Mat& mat, std::vector< std::vector< Mat > >& vv_mat)
|
||||
{
|
||||
std::vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
std::vector<Mat> vmat;
|
||||
Mat_to_vector_Mat(vm[i], vmat);
|
||||
vv_mat.push_back(vmat);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_Mat_to_Mat(std::vector< std::vector< Mat > >& vv_mat, Mat& mat)
|
||||
{
|
||||
std::vector<Mat> vm;
|
||||
vm.reserve( vv_mat.size() );
|
||||
for(size_t i=0; i<vv_mat.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_Mat_to_Mat(vv_mat[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_Point(Mat& mat, std::vector< std::vector< Point > >& vv_pt)
|
||||
{
|
||||
std::vector<Mat> vm;
|
||||
|
||||
@@ -50,6 +50,9 @@ void vector_Vec6f_to_Mat(std::vector<cv::Vec6f>& v_vec, cv::Mat& mat);
|
||||
void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat);
|
||||
void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_Mat(cv::Mat& mat, std::vector< std::vector< cv::Mat > >& vv_mat);
|
||||
void vector_vector_Mat_to_Mat(std::vector< std::vector< cv::Mat > >& vv_mat, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_char(cv::Mat& mat, std::vector< std::vector< char > >& vv_ch);
|
||||
void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Mat& mat);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfByte;
|
||||
import org.opencv.core.MatOfDMatch;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.core.MatOfKeyPoint;
|
||||
import org.opencv.core.MatOfPoint;
|
||||
import org.opencv.core.MatOfPoint2f;
|
||||
@@ -514,6 +515,41 @@ public class Converters {
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_Mat
|
||||
public static Mat vector_vector_Mat_to_Mat(List<List<Mat>> vecMats, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (vecMats != null) ? vecMats.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (List<Mat> matList : vecMats) {
|
||||
Mat mat = vector_Mat_to_Mat(matList);
|
||||
mats.add(mat);
|
||||
}
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_Mat(Mat m, List<List<Mat>> vecMats) {
|
||||
if (vecMats == null)
|
||||
throw new IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if (m == null)
|
||||
throw new IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
vecMats.clear();
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
for (Mat mi : mats) {
|
||||
List<Mat> rowList = new ArrayList<Mat>(mi.rows());
|
||||
Mat_to_vector_Mat(mi, rowList);
|
||||
vecMats.add(rowList);
|
||||
mi.release();
|
||||
}
|
||||
mats.clear();
|
||||
}
|
||||
|
||||
// vector_vector_Point
|
||||
public static Mat vector_vector_Point_to_Mat(List<MatOfPoint> pts, List<Mat> mats) {
|
||||
Mat res;
|
||||
@@ -803,4 +839,75 @@ public class Converters {
|
||||
rs.add(new RotatedRect(new Point(buff[5 * i], buff[5 * i + 1]), new Size(buff[5 * i + 2], buff[5 * i + 3]), buff[5 * i + 4]));
|
||||
}
|
||||
}
|
||||
|
||||
// vector_MatShape
|
||||
public static Mat vector_MatShape_to_Mat(List<MatOfInt> matOfInts) {
|
||||
Mat res;
|
||||
int count = (matOfInts != null) ? matOfInts.size() : 0;
|
||||
if (count > 0) {
|
||||
res = new Mat(count, 1, CvType.CV_32SC2);
|
||||
int[] buff = new int[count * 2];
|
||||
for (int i = 0; i < count; i++) {
|
||||
long addr = matOfInts.get(i).nativeObj;
|
||||
buff[i * 2] = (int) (addr >> 32);
|
||||
buff[i * 2 + 1] = (int) (addr & 0xffffffff);
|
||||
}
|
||||
res.put(0, 0, buff);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_MatShape(Mat m, List<MatOfInt> matOfInts) {
|
||||
if (matOfInts == null)
|
||||
throw new IllegalArgumentException("matOfInts == null");
|
||||
int count = m.rows();
|
||||
if (CvType.CV_32SC2 != m.type() || m.cols() != 1)
|
||||
throw new IllegalArgumentException(
|
||||
"CvType.CV_32SC2 != m.type() || m.cols()!=1\n" + m);
|
||||
|
||||
matOfInts.clear();
|
||||
int[] buff = new int[count * 2];
|
||||
m.get(0, 0, buff);
|
||||
for (int i = 0; i < count; i++) {
|
||||
long addr = (((long) buff[i * 2]) << 32) | (((long) buff[i * 2 + 1]) & 0xffffffffL);
|
||||
matOfInts.add(MatOfInt.fromNativeAddr(addr));
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_MatShape
|
||||
public static Mat vector_vector_MatShape_to_Mat(List<List<MatOfInt>> vecMatOfInts, List<Mat> mats) {
|
||||
Mat res;
|
||||
int lCount = (vecMatOfInts != null) ? vecMatOfInts.size() : 0;
|
||||
if (lCount > 0) {
|
||||
for (List<MatOfInt> matList : vecMatOfInts) {
|
||||
Mat mat = vector_MatShape_to_Mat(matList);
|
||||
mats.add(mat);
|
||||
}
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_MatShape(Mat m, List<List<MatOfInt>> vecMatOfInts) {
|
||||
if (vecMatOfInts == null)
|
||||
throw new IllegalArgumentException("Output List can't be null");
|
||||
|
||||
if (m == null)
|
||||
throw new IllegalArgumentException("Input Mat can't be null");
|
||||
|
||||
vecMatOfInts.clear();
|
||||
List<Mat> mats = new ArrayList<Mat>(m.rows());
|
||||
Mat_to_vector_Mat(m, mats);
|
||||
for (Mat mi : mats) {
|
||||
List<MatOfInt> rowList = new ArrayList<MatOfInt>(mi.rows());
|
||||
Mat_to_vector_MatShape(mi, rowList);
|
||||
vecMatOfInts.add(rowList);
|
||||
mi.release();
|
||||
}
|
||||
mats.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user