提交 10444f4e 编写于 作者: A Andrey Pavlenko

Java API: vector_vector support for KeyPoint/DMatch/char

Testing: 1178/4/576
上级 874196e3
......@@ -96,6 +96,28 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase {
assertListKeyPointEquals(Arrays.asList(truth), keypoints, EPS);
}
public void testDetectListOfMatListOfListOfKeyPoint() {
String filename = OpenCVTestRunner.getTempFileName("yml");
writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n");
detector.read(filename);
List<List<KeyPoint>> keypoints = new ArrayList<List<KeyPoint>>();
Mat cross = getTestImg();
List<Mat> crosses = new ArrayList<Mat>(3);
crosses.add(cross);
crosses.add(cross);
crosses.add(cross);
detector.detect(crosses, keypoints);
assertEquals(3, keypoints.size());
for(List<KeyPoint> lkp : keypoints) {
order(lkp);
assertListKeyPointEquals(Arrays.asList(truth), lkp, EPS);
}
}
public void testEmpty() {
assertFalse(detector.empty());
}
......
......@@ -200,6 +200,10 @@ type_dict = {
"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_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" },
"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",
......@@ -668,7 +672,7 @@ public class %(jc)s {
# class props
for p in decl[3]:
if "vector" not in p[0]:
if True: #"vector" not in p[0]:
classinfo.props.append( ClassPropInfo(p) )
else:
print "Skipped property: [%s]" % name, p
......
......@@ -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);
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);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册