1
0
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:
Alexander Smorkalov
2025-08-27 15:50:00 +03:00
69 changed files with 7807 additions and 768 deletions
@@ -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();
}
}