|
|
@ -9,209 +9,227 @@ import org.opencv.core.Rect; |
|
|
|
import org.opencv.features2d.KeyPoint; |
|
|
|
import org.opencv.features2d.KeyPoint; |
|
|
|
|
|
|
|
|
|
|
|
public class Converters { |
|
|
|
public class Converters { |
|
|
|
|
|
|
|
|
|
|
|
public static Mat vector_Point_to_Mat(List<Point> pts) { |
|
|
|
public static Mat vector_Point_to_Mat(List<Point> pts) { |
|
|
|
Mat res; |
|
|
|
Mat res; |
|
|
|
int count = (pts!=null) ? pts.size() : 0; |
|
|
|
int count = (pts!=null) ? pts.size() : 0; |
|
|
|
if(count>0){ |
|
|
|
if(count>0){ |
|
|
|
res = new Mat(1, count, CvType.CV_32SC2); |
|
|
|
res = new Mat(1, count, CvType.CV_32SC2); |
|
|
|
int[] buff = new int[count*2]; |
|
|
|
int[] buff = new int[count*2]; |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
Point p = pts.get(i); |
|
|
|
Point p = pts.get(i); |
|
|
|
buff[i*2] = (int)p.x; |
|
|
|
buff[i*2] = (int)p.x; |
|
|
|
buff[i*2+1] = (int)p.y; |
|
|
|
buff[i*2+1] = (int)p.y; |
|
|
|
} |
|
|
|
} |
|
|
|
res.put(0, 0, buff); |
|
|
|
res.put(0, 0, buff); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
res = new Mat(); |
|
|
|
res = new Mat(); |
|
|
|
} |
|
|
|
} |
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void Mat_to_vector_Point(Mat m, List<Point> pts) { |
|
|
|
public static Mat vector_Point2f_to_Mat(List<Point> pts) { |
|
|
|
if(pts == null) |
|
|
|
Mat res; |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
int count = (pts!=null) ? pts.size() : 0; |
|
|
|
int cols = m.cols(); |
|
|
|
if(count>0){ |
|
|
|
if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) |
|
|
|
res = new Mat(1, count, CvType.CV_32FC2); |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
float[] buff = new float[count*2]; |
|
|
|
|
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
pts.clear(); |
|
|
|
Point p = pts.get(i); |
|
|
|
int[] buff = new int[2*cols]; |
|
|
|
buff[i*2] = (float)p.x; |
|
|
|
m.get(0, 0, buff); |
|
|
|
buff[i*2+1] = (float)p.y; |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
} |
|
|
|
pts.add( new Point(buff[i*2], buff[i*2+1]) ); |
|
|
|
res.put(0, 0, buff); |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
res = new Mat(); |
|
|
|
|
|
|
|
} |
|
|
|
public static Mat vector_Mat_to_Mat(List<Mat> mats) { |
|
|
|
return res; |
|
|
|
Mat res; |
|
|
|
} |
|
|
|
int count = (mats!=null) ? mats.size() : 0; |
|
|
|
|
|
|
|
if(count>0){ |
|
|
|
public static void Mat_to_vector_Point(Mat m, List<Point> pts) { |
|
|
|
res = new Mat(1, count, CvType.CV_32SC2); |
|
|
|
if(pts == null) |
|
|
|
int[] buff = new int[count*2]; |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
int cols = m.cols(); |
|
|
|
long addr = mats.get(i).nativeObj; |
|
|
|
if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) |
|
|
|
buff[i*2] = (int)(addr >> 32); |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
buff[i*2+1] = (int)(addr & 0xffffffff); |
|
|
|
|
|
|
|
} |
|
|
|
pts.clear(); |
|
|
|
res.put(0, 0, buff); |
|
|
|
int[] buff = new int[2*cols]; |
|
|
|
} else { |
|
|
|
m.get(0, 0, buff); |
|
|
|
res = new Mat(); |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
} |
|
|
|
pts.add( new Point(buff[i*2], buff[i*2+1]) ); |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void Mat_to_vector_Mat(Mat m, List<Mat> mats) { |
|
|
|
public static Mat vector_Mat_to_Mat(List<Mat> mats) { |
|
|
|
if(mats == null) |
|
|
|
Mat res; |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
int count = (mats!=null) ? mats.size() : 0; |
|
|
|
int cols = m.cols(); |
|
|
|
if(count>0){ |
|
|
|
if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) |
|
|
|
res = new Mat(1, count, CvType.CV_32SC2); |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
int[] buff = new int[count*2]; |
|
|
|
|
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
mats.clear(); |
|
|
|
long addr = mats.get(i).nativeObj; |
|
|
|
int[] buff = new int[cols*2]; |
|
|
|
buff[i*2] = (int)(addr >> 32); |
|
|
|
m.get(0, 0, buff); |
|
|
|
buff[i*2+1] = (int)(addr & 0xffffffff); |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
} |
|
|
|
long addr = (((long)buff[i*2])<<32) | ((long)buff[i*2+1]); |
|
|
|
res.put(0, 0, buff); |
|
|
|
mats.add( new Mat(addr) ); |
|
|
|
} else { |
|
|
|
} |
|
|
|
res = new Mat(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return res; |
|
|
|
public static void Mat_to_vector_KeyPoint(Mat kp_mat, List<KeyPoint> kps) { |
|
|
|
} |
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
} |
|
|
|
public static void Mat_to_vector_Mat(Mat m, List<Mat> mats) { |
|
|
|
|
|
|
|
if(mats == null) |
|
|
|
public static Mat vector_float_to_Mat(List<Float> fs) { |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
Mat res; |
|
|
|
int cols = m.cols(); |
|
|
|
int count = (fs!=null) ? fs.size() : 0; |
|
|
|
if(CvType.CV_32SC2 != m.type() || m.rows()!=1 ) |
|
|
|
if(count>0){ |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
res = new Mat(1, count, CvType.CV_32FC1); //Point can be saved into double[2]
|
|
|
|
|
|
|
|
float[] buff = new float[count]; |
|
|
|
mats.clear(); |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
int[] buff = new int[cols*2]; |
|
|
|
float f = fs.get(i); |
|
|
|
m.get(0, 0, buff); |
|
|
|
buff[i] = f; |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
} |
|
|
|
long addr = (((long)buff[i*2])<<32) | ((long)buff[i*2+1]); |
|
|
|
res.put(0, 0, buff); |
|
|
|
mats.add( new Mat(addr) ); |
|
|
|
} else { |
|
|
|
} |
|
|
|
res = new Mat(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return res; |
|
|
|
public static void Mat_to_vector_KeyPoint(Mat kp_mat, List<KeyPoint> kps) { |
|
|
|
} |
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
} |
|
|
|
public static void Mat_to_vector_float(Mat m, List<Float> fs) { |
|
|
|
|
|
|
|
if(fs == null) |
|
|
|
public static Mat vector_float_to_Mat(List<Float> fs) { |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
Mat res; |
|
|
|
int cols = m.cols(); |
|
|
|
int count = (fs!=null) ? fs.size() : 0; |
|
|
|
if(CvType.CV_32FC1 != m.type() || m.rows()!=1 ) |
|
|
|
if(count>0){ |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
res = new Mat(1, count, CvType.CV_32FC1); //Point can be saved into double[2]
|
|
|
|
|
|
|
|
float[] buff = new float[count]; |
|
|
|
fs.clear(); |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
float[] buff = new float[cols]; |
|
|
|
float f = fs.get(i); |
|
|
|
m.get(0, 0, buff); |
|
|
|
buff[i] = f; |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
} |
|
|
|
fs.add( new Float(buff[i]) ); |
|
|
|
res.put(0, 0, buff); |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
res = new Mat(); |
|
|
|
|
|
|
|
} |
|
|
|
public static Mat vector_uchar_to_Mat(List<Byte> bs) { |
|
|
|
return res; |
|
|
|
Mat res; |
|
|
|
} |
|
|
|
int count = (bs!=null) ? bs.size() : 0; |
|
|
|
|
|
|
|
if(count>0){ |
|
|
|
public static void Mat_to_vector_float(Mat m, List<Float> fs) { |
|
|
|
res = new Mat(1, count, CvType.CV_8UC1); //Point can be saved into double[2]
|
|
|
|
if(fs == null) |
|
|
|
byte[] buff = new byte[count]; |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
int cols = m.cols(); |
|
|
|
byte b = bs.get(i); |
|
|
|
if(CvType.CV_32FC1 != m.type() || m.rows()!=1 ) |
|
|
|
buff[i] = b; |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
} |
|
|
|
|
|
|
|
res.put(0, 0, buff); |
|
|
|
fs.clear(); |
|
|
|
} else { |
|
|
|
float[] buff = new float[cols]; |
|
|
|
res = new Mat(); |
|
|
|
m.get(0, 0, buff); |
|
|
|
} |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
return res; |
|
|
|
fs.add( new Float(buff[i]) ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
public static Mat vector_int_to_Mat(List<Integer> is) { |
|
|
|
|
|
|
|
Mat res; |
|
|
|
public static Mat vector_uchar_to_Mat(List<Byte> bs) { |
|
|
|
int count = (is!=null) ? is.size() : 0; |
|
|
|
Mat res; |
|
|
|
if(count>0){ |
|
|
|
int count = (bs!=null) ? bs.size() : 0; |
|
|
|
res = new Mat(1, count, CvType.CV_32SC1); //Point can be saved into double[2]
|
|
|
|
if(count>0){ |
|
|
|
int[] buff = new int[count]; |
|
|
|
res = new Mat(1, count, CvType.CV_8UC1); //Point can be saved into double[2]
|
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
byte[] buff = new byte[count]; |
|
|
|
int v = is.get(i); |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
buff[i] = v; |
|
|
|
byte b = bs.get(i); |
|
|
|
} |
|
|
|
buff[i] = b; |
|
|
|
res.put(0, 0, buff); |
|
|
|
} |
|
|
|
} else { |
|
|
|
res.put(0, 0, buff); |
|
|
|
res = new Mat(); |
|
|
|
} else { |
|
|
|
} |
|
|
|
res = new Mat(); |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
public static void Mat_to_vector_int(Mat m, List<Integer> is) { |
|
|
|
|
|
|
|
if(is == null) |
|
|
|
public static Mat vector_int_to_Mat(List<Integer> is) { |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
Mat res; |
|
|
|
int cols = m.cols(); |
|
|
|
int count = (is!=null) ? is.size() : 0; |
|
|
|
if(CvType.CV_32SC1 != m.type() || m.rows()!=1 ) |
|
|
|
if(count>0){ |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
res = new Mat(1, count, CvType.CV_32SC1); //Point can be saved into double[2]
|
|
|
|
|
|
|
|
int[] buff = new int[count]; |
|
|
|
is.clear(); |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
int[] buff = new int[cols]; |
|
|
|
int v = is.get(i); |
|
|
|
m.get(0, 0, buff); |
|
|
|
buff[i] = v; |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
} |
|
|
|
is.add( new Integer(buff[i]) ); |
|
|
|
res.put(0, 0, buff); |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
res = new Mat(); |
|
|
|
|
|
|
|
} |
|
|
|
public static Mat vector_Rect_to_Mat(List<Rect> rs) { |
|
|
|
return res; |
|
|
|
Mat res; |
|
|
|
} |
|
|
|
int count = (rs!=null) ? rs.size() : 0; |
|
|
|
|
|
|
|
if(count>0){ |
|
|
|
public static void Mat_to_vector_int(Mat m, List<Integer> is) { |
|
|
|
res = new Mat(1, count, CvType.CV_32SC4); //Point can be saved into double[2]
|
|
|
|
if(is == null) |
|
|
|
int[] buff = new int[4*count]; |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
int cols = m.cols(); |
|
|
|
Rect r = rs.get(i); |
|
|
|
if(CvType.CV_32SC1 != m.type() || m.rows()!=1 ) |
|
|
|
buff[4*i ] = r.x; |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
buff[4*i+1] = r.y; |
|
|
|
|
|
|
|
buff[4*i+2] = r.width; |
|
|
|
is.clear(); |
|
|
|
buff[4*i+3] = r.height; |
|
|
|
int[] buff = new int[cols]; |
|
|
|
} |
|
|
|
m.get(0, 0, buff); |
|
|
|
res.put(0, 0, buff); |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
} else { |
|
|
|
is.add( new Integer(buff[i]) ); |
|
|
|
res = new Mat(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
public static Mat vector_Rect_to_Mat(List<Rect> rs) { |
|
|
|
|
|
|
|
Mat res; |
|
|
|
public static void Mat_to_vector_Rect(Mat m, List<Rect> rs) { |
|
|
|
int count = (rs!=null) ? rs.size() : 0; |
|
|
|
if(rs == null) |
|
|
|
if(count>0){ |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
res = new Mat(1, count, CvType.CV_32SC4); //Point can be saved into double[2]
|
|
|
|
int cols = m.cols(); |
|
|
|
int[] buff = new int[4*count]; |
|
|
|
if(CvType.CV_32SC4 != m.type() || m.rows()!=1 ) |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
Rect r = rs.get(i); |
|
|
|
|
|
|
|
buff[4*i ] = r.x; |
|
|
|
rs.clear(); |
|
|
|
buff[4*i+1] = r.y; |
|
|
|
int[] buff = new int[4*cols]; |
|
|
|
buff[4*i+2] = r.width; |
|
|
|
m.get(0, 0, buff); |
|
|
|
buff[4*i+3] = r.height; |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
} |
|
|
|
rs.add( new Rect(buff[4*i], buff[4*i+1], buff[4*i+2], buff[4*i+3]) ); |
|
|
|
res.put(0, 0, buff); |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
res = new Mat(); |
|
|
|
|
|
|
|
} |
|
|
|
public static Mat vector_double_to_Mat(List<Double> ds) { |
|
|
|
return res; |
|
|
|
Mat res; |
|
|
|
} |
|
|
|
int count = (ds!=null) ? ds.size() : 0; |
|
|
|
|
|
|
|
if(count>0){ |
|
|
|
public static void Mat_to_vector_Rect(Mat m, List<Rect> rs) { |
|
|
|
res = new Mat(1, count, CvType.CV_64FC1); //Point can be saved into double[2]
|
|
|
|
if(rs == null) |
|
|
|
double[] buff = new double[count]; |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
int cols = m.cols(); |
|
|
|
double v = ds.get(i); |
|
|
|
if(CvType.CV_32SC4 != m.type() || m.rows()!=1 ) |
|
|
|
buff[i] = v; |
|
|
|
throw new java.lang.IllegalArgumentException(); |
|
|
|
} |
|
|
|
|
|
|
|
res.put(0, 0, buff); |
|
|
|
rs.clear(); |
|
|
|
} else { |
|
|
|
int[] buff = new int[4*cols]; |
|
|
|
res = new Mat(); |
|
|
|
m.get(0, 0, buff); |
|
|
|
} |
|
|
|
for(int i=0; i<cols; i++) { |
|
|
|
return res; |
|
|
|
rs.add( new Rect(buff[4*i], buff[4*i+1], buff[4*i+2], buff[4*i+3]) ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Mat vector_double_to_Mat(List<Double> ds) { |
|
|
|
|
|
|
|
Mat res; |
|
|
|
|
|
|
|
int count = (ds!=null) ? ds.size() : 0; |
|
|
|
|
|
|
|
if(count>0){ |
|
|
|
|
|
|
|
res = new Mat(1, count, CvType.CV_64FC1); //Point can be saved into double[2]
|
|
|
|
|
|
|
|
double[] buff = new double[count]; |
|
|
|
|
|
|
|
for(int i=0; i<count; i++) { |
|
|
|
|
|
|
|
double v = ds.get(i); |
|
|
|
|
|
|
|
buff[i] = v; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
res.put(0, 0, buff); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
res = new Mat(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|