Java API: vector_vector support for KeyPoint/DMatch/char
Testing: 1178/4/576
This commit is contained in:
@@ -263,3 +263,81 @@ void vector_DMatch_to_Mat(vector<DMatch>& v_dm, Mat& mat)
|
||||
mat.at< Vec<double, 4> >(i, 0) = Vec<double, 4>(dm.queryIdx, dm.trainIdx, dm.imgIdx, dm.distance);
|
||||
}
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_KeyPoint(Mat& mat, vector< vector< KeyPoint > >& vv_kp)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<KeyPoint> vkp;
|
||||
Mat_to_vector_KeyPoint(vm[i], vkp);
|
||||
vv_kp.push_back(vkp);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_KeyPoint_to_Mat(vector< vector< KeyPoint > >& vv_kp, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_kp.size() );
|
||||
for(size_t i=0; i<vv_kp.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_KeyPoint_to_Mat(vv_kp[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_DMatch(Mat& mat, vector< vector< DMatch > >& vv_dm)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<DMatch> vdm;
|
||||
Mat_to_vector_DMatch(vm[i], vdm);
|
||||
vv_dm.push_back(vdm);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_DMatch_to_Mat(vector< vector< DMatch > >& vv_dm, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_dm.size() );
|
||||
for(size_t i=0; i<vv_dm.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_DMatch_to_Mat(vv_dm[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
||||
void Mat_to_vector_vector_char(Mat& mat, vector< vector< char > >& vv_ch)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( mat.rows );
|
||||
Mat_to_vector_Mat(mat, vm);
|
||||
for(size_t i=0; i<vm.size(); i++)
|
||||
{
|
||||
vector<char> vch;
|
||||
Mat_to_vector_char(vm[i], vch);
|
||||
vv_ch.push_back(vch);
|
||||
}
|
||||
}
|
||||
|
||||
void vector_vector_char_to_Mat(vector< vector< char > >& vv_ch, Mat& mat)
|
||||
{
|
||||
vector<Mat> vm;
|
||||
vm.reserve( vv_ch.size() );
|
||||
for(size_t i=0; i<vv_ch.size(); i++)
|
||||
{
|
||||
Mat m;
|
||||
vector_char_to_Mat(vv_ch[i], m);
|
||||
vm.push_back(m);
|
||||
}
|
||||
vector_Mat_to_Mat(vm, mat);
|
||||
}
|
||||
|
@@ -46,3 +46,12 @@ void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_DMatch(cv::Mat& mat, std::vector<cv::DMatch>& v_dm);
|
||||
void vector_DMatch_to_Mat(std::vector<cv::DMatch>& v_dm, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_KeyPoint(cv::Mat& mat, std::vector< std::vector< cv::KeyPoint > >& vv_kp);
|
||||
void vector_vector_KeyPoint_to_Mat(std::vector< std::vector< cv::KeyPoint > >& vv_kp, cv::Mat& mat);
|
||||
|
||||
void Mat_to_vector_vector_DMatch(cv::Mat& mat, std::vector< std::vector< cv::DMatch > >& vv_dm);
|
||||
void vector_vector_DMatch_to_Mat(std::vector< std::vector< cv::DMatch > >& vv_dm, 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);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package org.opencv.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.core.Mat;
|
||||
@@ -474,6 +475,36 @@ public class Converters {
|
||||
}
|
||||
}
|
||||
|
||||
// vector_vector_KeyPoint
|
||||
public static Mat vector_vector_KeyPoint_to_Mat(List<List<KeyPoint>> kps) {
|
||||
Mat res;
|
||||
int lCount = (kps!=null) ? kps.size() : 0;
|
||||
if(lCount>0){
|
||||
List<Mat> mats = new ArrayList<Mat>(lCount);
|
||||
for(List<KeyPoint> lkp: kps) mats.add( vector_KeyPoint_to_Mat(lkp) );
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_KeyPoint(Mat m, List<List<KeyPoint>> kps) {
|
||||
if(kps == 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<KeyPoint> lkp = new ArrayList<KeyPoint>();
|
||||
for(Mat mi : mats) {
|
||||
Mat_to_vector_KeyPoint(mi, lkp);
|
||||
kps.add(lkp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Mat vector_double_to_Mat(List<Double> ds) {
|
||||
Mat res;
|
||||
@@ -528,4 +559,65 @@ public class Converters {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// vector_vector_DMatch
|
||||
public static Mat vector_vector_DMatch_to_Mat(List<List<DMatch>> lldm) {
|
||||
Mat res;
|
||||
int lCount = (lldm!=null) ? lldm.size() : 0;
|
||||
if(lCount>0){
|
||||
List<Mat> mats = new ArrayList<Mat>(lCount);
|
||||
for(List<DMatch> ldm: lldm) mats.add( vector_DMatch_to_Mat(ldm) );
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_DMatch(Mat m, List<List<DMatch>> lldm) {
|
||||
if(lldm == 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<DMatch> ldm = new ArrayList<DMatch>();
|
||||
for(Mat mi : mats) {
|
||||
Mat_to_vector_DMatch(mi, ldm);
|
||||
lldm.add(ldm);
|
||||
}
|
||||
}
|
||||
|
||||
//vector_vector_char
|
||||
public static Mat vector_vector_char_to_Mat(List<List<Byte>> llb) {
|
||||
Mat res;
|
||||
int lCount = (llb!=null) ? llb.size() : 0;
|
||||
if(lCount>0){
|
||||
List<Mat> mats = new ArrayList<Mat>(lCount);
|
||||
for(List<Byte> lb: llb) mats.add( vector_char_to_Mat(lb) );
|
||||
res = vector_Mat_to_Mat(mats);
|
||||
} else {
|
||||
res = new Mat();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void Mat_to_vector_vector_char(Mat m, List<List<Byte>> llb) {
|
||||
if(llb == 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<Byte> lb = new ArrayList<Byte>();
|
||||
for(Mat mi : mats) {
|
||||
Mat_to_vector_char(mi, lb);
|
||||
llb.add(lb);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user