Java API generator: KeyPoint converters from/to Mat
This commit is contained in:
parent
20b4d0fae9
commit
9235a80109
@ -11,7 +11,7 @@ class_ignore_list = (
|
|||||||
"FileNode", "FileStorage",
|
"FileNode", "FileStorage",
|
||||||
#highgui
|
#highgui
|
||||||
"VideoWriter", "VideoCapture",
|
"VideoWriter", "VideoCapture",
|
||||||
#feature2d
|
#features2d
|
||||||
"KeyPoint",
|
"KeyPoint",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -115,16 +115,26 @@ void vector_Point_to_Mat(vector<Point>& v_point, Mat& mat)
|
|||||||
void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
|
void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
|
||||||
{
|
{
|
||||||
v_kp.clear();
|
v_kp.clear();
|
||||||
//CHECK_MAT(mat.type()!= ??? || mat.rows!=1);
|
CHECK_MAT(mat.type()!= CV_64FC(7) || mat.rows!=1);
|
||||||
v_kp = (vector<KeyPoint>) mat;
|
for(int i=0; i<mat.cols; i++)
|
||||||
|
{
|
||||||
|
Vec<double, 7> v = mat.at< Vec<double, 7> >(0, i);
|
||||||
|
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);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat)
|
void vector_KeyPoint_to_Mat(vector<KeyPoint>& v_kp, Mat& mat)
|
||||||
{
|
{
|
||||||
mat = Mat(v_kp);
|
int count = v_kp.size();
|
||||||
return;
|
mat.create(1, count, CV_64FC(7));
|
||||||
|
for(int i=0; i<count; i++)
|
||||||
|
{
|
||||||
|
KeyPoint kp = v_kp[i];
|
||||||
|
mat.at< Vec<double, 7> >(0, i) = Vec<double, 7>(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -154,5 +164,4 @@ void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
|
|||||||
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> >(0, i) = Vec<int, 2>(addr>>32, addr&0xffffffff);
|
mat.at< Vec<int, 2> >(0, i) = Vec<int, 2>(addr>>32, addr&0xffffffff);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
@ -95,10 +95,6 @@ public class Converters {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Mat_to_vector_KeyPoint(Mat kp_mat, List<KeyPoint> kps) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Mat vector_float_to_Mat(List<Float> fs) {
|
public static Mat vector_float_to_Mat(List<Float> fs) {
|
||||||
Mat res;
|
Mat res;
|
||||||
int count = (fs!=null) ? fs.size() : 0;
|
int count = (fs!=null) ? fs.size() : 0;
|
||||||
@ -184,7 +180,7 @@ public class Converters {
|
|||||||
Mat res;
|
Mat res;
|
||||||
int count = (rs!=null) ? rs.size() : 0;
|
int count = (rs!=null) ? rs.size() : 0;
|
||||||
if(count>0){
|
if(count>0){
|
||||||
res = new Mat(1, count, CvType.CV_32SC4); //Point can be saved into double[2]
|
res = new Mat(1, count, CvType.CV_32SC4);
|
||||||
int[] buff = new int[4*count];
|
int[] buff = new int[4*count];
|
||||||
for(int i=0; i<count; i++) {
|
for(int i=0; i<count; i++) {
|
||||||
Rect r = rs.get(i);
|
Rect r = rs.get(i);
|
||||||
@ -215,6 +211,47 @@ public class Converters {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Mat vector_KeyPoint_to_Mat(List<KeyPoint> kps) {
|
||||||
|
Mat res;
|
||||||
|
int count = (kps!=null) ? kps.size() : 0;
|
||||||
|
if(count>0){
|
||||||
|
res = new Mat(1, count, CvType.CV_64FC(7));
|
||||||
|
double[] buff = new double[count * 7];
|
||||||
|
for(int i=0; i<count; i++) {
|
||||||
|
KeyPoint kp = kps.get(i);
|
||||||
|
buff[7*i ] = kp.pt.x;
|
||||||
|
buff[7*i+1] = kp.pt.y;
|
||||||
|
buff[7*i+2] = kp.size;
|
||||||
|
buff[7*i+3] = kp.angle;
|
||||||
|
buff[7*i+4] = kp.response;
|
||||||
|
buff[7*i+5] = kp.octave;
|
||||||
|
buff[7*i+6] = kp.class_id;
|
||||||
|
}
|
||||||
|
res.put(0, 0, buff);
|
||||||
|
} else {
|
||||||
|
res = new Mat();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Mat_to_vector_KeyPoint(Mat m, List<KeyPoint> kps) {
|
||||||
|
if(kps == null)
|
||||||
|
throw new java.lang.IllegalArgumentException();
|
||||||
|
int cols = m.cols();
|
||||||
|
if(CvType.CV_64FC(7) != m.type() || m.rows()!=1 )
|
||||||
|
throw new java.lang.IllegalArgumentException();
|
||||||
|
|
||||||
|
kps.clear();
|
||||||
|
double[] buff = new double[7*cols];
|
||||||
|
m.get(0, 0, buff);
|
||||||
|
for(int i=0; i<cols; i++) {
|
||||||
|
kps.add( new KeyPoint( (float)buff[4*i], (float)buff[4*i+1], (float)buff[4*i+2], (float)buff[4*i+3],
|
||||||
|
(float)buff[4*i+4], (int)buff[4*i+5], (int)buff[4*i+6] ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Mat vector_double_to_Mat(List<Double> ds) {
|
public static Mat vector_double_to_Mat(List<Double> ds) {
|
||||||
Mat res;
|
Mat res;
|
||||||
int count = (ds!=null) ? ds.size() : 0;
|
int count = (ds!=null) ? ds.size() : 0;
|
||||||
|
@ -6,17 +6,17 @@ import org.opencv.core.Point;
|
|||||||
public class KeyPoint {
|
public class KeyPoint {
|
||||||
|
|
||||||
//javadoc: KeyPoint::pt
|
//javadoc: KeyPoint::pt
|
||||||
Point pt;
|
public Point pt;
|
||||||
//javadoc: KeyPoint::size
|
//javadoc: KeyPoint::size
|
||||||
float size;
|
public float size;
|
||||||
//javadoc: KeyPoint::angle
|
//javadoc: KeyPoint::angle
|
||||||
float angle;
|
public float angle;
|
||||||
//javadoc: KeyPoint::response
|
//javadoc: KeyPoint::response
|
||||||
float response;
|
public float response;
|
||||||
//javadoc: KeyPoint::octave
|
//javadoc: KeyPoint::octave
|
||||||
int octave;
|
public int octave;
|
||||||
//javadoc: KeyPoint::class_id
|
//javadoc: KeyPoint::class_id
|
||||||
int class_id;
|
public int class_id;
|
||||||
|
|
||||||
//javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave, _class_id)
|
//javadoc: KeyPoint::KeyPoint(x, y, _size, _angle, _response, _octave, _class_id)
|
||||||
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)
|
public KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user