parent
9ac0d4323d
commit
78d92584c3
20 changed files with 736 additions and 78 deletions
@ -0,0 +1,35 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVector extends Mat { |
||||
protected int depth; |
||||
protected int channels; |
||||
|
||||
protected CvVector(int d, int ch) { |
||||
super(); |
||||
depth = d; |
||||
channels = ch; |
||||
} |
||||
|
||||
protected CvVector(int d, int ch, long addr) { |
||||
super(addr); |
||||
depth = d; |
||||
channels = ch; |
||||
if( !empty() && checkVector(channels, depth) < 0 ) |
||||
throw new IllegalArgumentException("Incomatible Mat"); |
||||
//FIXME: do we need release() here?
|
||||
} |
||||
|
||||
protected CvVector(int d, int ch, Mat m) { |
||||
super(m, Range.all()); |
||||
depth = d; |
||||
channels = ch; |
||||
if( !empty() && checkVector(channels, depth) < 0 ) |
||||
throw new IllegalArgumentException("Incomatible Mat"); |
||||
//FIXME: do we need release() here?
|
||||
} |
||||
|
||||
protected void create(int cnt) { |
||||
if(cnt>0) |
||||
super.create(cnt, 1, CvType.makeType(depth, channels)); |
||||
} |
||||
} |
@ -0,0 +1,42 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVectorByte extends CvVector { |
||||
private static final int _d = CvType.CV_8U; |
||||
|
||||
public CvVectorByte(int ch) { |
||||
super(_d, ch); |
||||
} |
||||
|
||||
public CvVectorByte(int ch, long addr) { |
||||
super(_d, ch, addr); |
||||
} |
||||
|
||||
public CvVectorByte(long addr) { |
||||
super(_d, 1, addr); |
||||
} |
||||
|
||||
public CvVectorByte(int ch, Mat m) { |
||||
super(_d, ch, m); |
||||
} |
||||
|
||||
public CvVectorByte(int ch, byte[] a) { |
||||
super(_d, ch); |
||||
if(a!=null) { |
||||
int cnt = a.length / ch; |
||||
create(cnt); |
||||
put(0, 0, a); |
||||
} |
||||
} |
||||
|
||||
public byte[] toArray(byte[] a) { |
||||
int cnt = (int) total() * channels; |
||||
if(cnt == 0) |
||||
return new byte[0];//null;
|
||||
byte[] res = a; |
||||
if(res==null || res.length<cnt) |
||||
res = new byte[cnt]; |
||||
get(0, 0, res); //TODO: check ret val!
|
||||
return res; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,49 @@ |
||||
package org.opencv.core; |
||||
|
||||
import org.opencv.features2d.DMatch; |
||||
|
||||
public class CvVectorDMatch extends CvVectorFloat { |
||||
private static final int _ch = 4; //xxxC4
|
||||
|
||||
public CvVectorDMatch() { |
||||
super(_ch); |
||||
} |
||||
|
||||
public CvVectorDMatch(long addr) { |
||||
super(_ch, addr); |
||||
} |
||||
|
||||
public CvVectorDMatch(Mat m) { |
||||
super(_ch, m); |
||||
} |
||||
|
||||
public CvVectorDMatch(DMatch[] a) { |
||||
super(_ch); |
||||
if(a==null) |
||||
return; |
||||
int cnt = a.length; |
||||
create(cnt); |
||||
float buff[] = new float[_ch * cnt]; |
||||
for(int i=0; i<cnt; i++) { |
||||
DMatch m = a[i]; |
||||
buff[_ch*i+0] = m.queryIdx; |
||||
buff[_ch*i+1] = m.trainIdx; |
||||
buff[_ch*i+2] = m.imgIdx; |
||||
buff[_ch*i+3] = m.distance; |
||||
} |
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
} |
||||
|
||||
public DMatch[] toArray(DMatch[] a) { |
||||
float buff[] = super.toArray(null); |
||||
if(buff.length == 0) |
||||
return new DMatch[0]; //null;
|
||||
int cnt = buff.length / _ch; |
||||
DMatch[] res = a; |
||||
if(a==null || a.length<cnt) |
||||
res = new DMatch[cnt]; |
||||
for(int i=0; i<cnt; i++) |
||||
res[i] = new DMatch((int) buff[_ch*i+0], (int) buff[_ch*i+1], (int) buff[_ch*i+2], buff[_ch*i+3]); |
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVectorDouble extends CvVector { |
||||
private static final int _d = CvType.CV_64F; |
||||
|
||||
public CvVectorDouble(int ch) { |
||||
super(_d, ch); |
||||
} |
||||
|
||||
public CvVectorDouble(int ch, long addr) { |
||||
super(_d, ch, addr); |
||||
} |
||||
|
||||
public CvVectorDouble(int ch, Mat m) { |
||||
super(_d, ch, m); |
||||
} |
||||
|
||||
public CvVectorDouble(int ch, double[] a) { |
||||
super(_d, ch); |
||||
if(a!=null) { |
||||
int cnt = a.length / ch; |
||||
create(cnt); |
||||
put(0, 0, a); |
||||
} |
||||
} |
||||
|
||||
public double[] toArray(double[] a) { |
||||
int cnt = (int) total() * channels; |
||||
if(cnt == 0) |
||||
return new double[0];//null;
|
||||
double[] res = a; |
||||
if(res==null || res.length<cnt) |
||||
res = new double[cnt]; |
||||
get(0, 0, res); //TODO: check ret val!
|
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVectorFloat extends CvVector { |
||||
private static final int _d = CvType.CV_32F; |
||||
|
||||
public CvVectorFloat(int ch) { |
||||
super(_d, ch); |
||||
} |
||||
|
||||
public CvVectorFloat(int ch, long addr) { |
||||
super(_d, ch, addr); |
||||
} |
||||
|
||||
public CvVectorFloat(long addr) { |
||||
super(_d, 1, addr); |
||||
} |
||||
|
||||
public CvVectorFloat(int ch, Mat m) { |
||||
super(_d, ch, m); |
||||
} |
||||
|
||||
public CvVectorFloat(int ch, float[] a) { |
||||
super(_d, ch); |
||||
if(a!=null) { |
||||
int cnt = a.length / ch; |
||||
create(cnt); |
||||
put(0, 0, a); |
||||
} |
||||
} |
||||
|
||||
public float[] toArray(float[] a) { |
||||
int cnt = (int) total() * channels; |
||||
if(cnt == 0) |
||||
return new float[0];//null;
|
||||
float[] res = a; |
||||
if(res==null || res.length<cnt) |
||||
res = new float[cnt]; |
||||
get(0, 0, res); //TODO: check ret val!
|
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVectorFloat4 extends CvVectorFloat { |
||||
private static final int _ch = 4; //xxxC4
|
||||
|
||||
public CvVectorFloat4() { |
||||
super(_ch); |
||||
} |
||||
|
||||
public CvVectorFloat4(long addr) { |
||||
super(_ch, addr); |
||||
} |
||||
|
||||
public CvVectorFloat4(Mat m) { |
||||
super(_ch, m); |
||||
} |
||||
|
||||
public CvVectorFloat4(float[] a) { |
||||
super(_ch, a); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVectorFloat6 extends CvVectorFloat { |
||||
private static final int _ch = 6; //xxxC6
|
||||
|
||||
public CvVectorFloat6() { |
||||
super(_ch); |
||||
} |
||||
|
||||
public CvVectorFloat6(long addr) { |
||||
super(_ch, addr); |
||||
} |
||||
|
||||
public CvVectorFloat6(Mat m) { |
||||
super(_ch, m); |
||||
} |
||||
|
||||
public CvVectorFloat6(float[] a) { |
||||
super(_ch, a); |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
package org.opencv.core; |
||||
|
||||
|
||||
public class CvVectorInt extends CvVector { |
||||
private static final int _d = CvType.CV_32S; |
||||
|
||||
public CvVectorInt(int ch) { |
||||
super(_d, ch); |
||||
} |
||||
|
||||
public CvVectorInt(int ch, long addr) { |
||||
super(_d, ch, addr); |
||||
} |
||||
|
||||
public CvVectorInt(int ch, Mat m) { |
||||
super(_d, ch, m); |
||||
} |
||||
|
||||
public CvVectorInt(int ch, int[] a) { |
||||
super(_d, ch); |
||||
if(a!=null) { |
||||
int cnt = a.length / ch; |
||||
create(cnt); |
||||
put(0, 0, a); |
||||
} |
||||
} |
||||
|
||||
public int[] toArray(int[] a) { |
||||
int cnt = (int) total() * channels; |
||||
if(cnt == 0) |
||||
return new int[0];//null;
|
||||
int[] res = a; |
||||
if(res==null || res.length<cnt) |
||||
res = new int[cnt]; |
||||
get(0, 0, res); //TODO: check ret val!
|
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,53 @@ |
||||
package org.opencv.core; |
||||
|
||||
import org.opencv.features2d.KeyPoint; |
||||
|
||||
public class CvVectorKeyPoint extends CvVectorFloat { |
||||
private static final int _ch = 7; //xxxC7
|
||||
|
||||
public CvVectorKeyPoint() { |
||||
super(_ch); |
||||
} |
||||
|
||||
public CvVectorKeyPoint(long addr) { |
||||
super(_ch, addr); |
||||
} |
||||
|
||||
public CvVectorKeyPoint(Mat m) { |
||||
super(_ch, m); |
||||
} |
||||
|
||||
public CvVectorKeyPoint(KeyPoint[] a) { |
||||
super(_ch); |
||||
if(a==null) |
||||
return; |
||||
int cnt = a.length; |
||||
create(cnt); |
||||
float buff[] = new float[_ch * cnt]; |
||||
for(int i=0; i<cnt; i++) { |
||||
KeyPoint kp = a[i]; |
||||
buff[_ch*i+0] = (float) kp.pt.x; |
||||
buff[_ch*i+1] = (float) kp.pt.y; |
||||
buff[_ch*i+2] = kp.size; |
||||
buff[_ch*i+3] = kp.angle; |
||||
buff[_ch*i+4] = kp.response; |
||||
buff[_ch*i+5] = kp.octave; |
||||
buff[_ch*i+6] = kp.class_id; |
||||
} |
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
} |
||||
|
||||
public KeyPoint[] toArray(KeyPoint[] a) { |
||||
float buff[] = super.toArray(null); |
||||
if(buff.length == 0) |
||||
return new KeyPoint[0]; //null;
|
||||
int cnt = buff.length / _ch; |
||||
KeyPoint[] res = a; |
||||
if(a==null || a.length<cnt) |
||||
res = new KeyPoint[cnt]; |
||||
for(int i=0; i<cnt; i++) |
||||
res[i] = new KeyPoint( buff[_ch*i+0], buff[_ch*i+1], buff[_ch*i+2], buff[_ch*i+3], |
||||
buff[_ch*i+4], (int) buff[_ch*i+5], (int) buff[_ch*i+6] ); |
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,45 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVectorPoint extends CvVectorInt { |
||||
private static final int _ch = 2; //xxxC2
|
||||
|
||||
public CvVectorPoint() { |
||||
super(_ch); |
||||
} |
||||
|
||||
public CvVectorPoint(long addr) { |
||||
super(_ch, addr); |
||||
} |
||||
|
||||
public CvVectorPoint(Mat m) { |
||||
super(_ch, m); |
||||
} |
||||
|
||||
public CvVectorPoint(Point[] a) { |
||||
super(_ch); |
||||
if(a==null) |
||||
return; |
||||
int cnt = a.length; |
||||
create(cnt); |
||||
int buff[] = new int[_ch * cnt]; |
||||
for(int i=0; i<cnt; i++) { |
||||
Point p = a[i]; |
||||
buff[_ch*i+0] = (int) p.x; |
||||
buff[_ch*i+1] = (int) p.y; |
||||
} |
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
} |
||||
|
||||
public Point[] toArray(Point[] a) { |
||||
int buff[] = super.toArray(null); |
||||
if(buff.length == 0) |
||||
return new Point[0]; //null;
|
||||
int cnt = buff.length / _ch; |
||||
Point[] res = a; |
||||
if(a==null || a.length<cnt) |
||||
res = new Point[cnt]; |
||||
for(int i=0; i<cnt; i++) |
||||
res[i] = new Point(buff[i*_ch], buff[i*_ch+1]); |
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,45 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVectorPoint2f extends CvVectorFloat { |
||||
private static final int _ch = 2; //xxxC2
|
||||
|
||||
public CvVectorPoint2f() { |
||||
super(_ch); |
||||
} |
||||
|
||||
public CvVectorPoint2f(long addr) { |
||||
super(_ch, addr); |
||||
} |
||||
|
||||
public CvVectorPoint2f(Mat m) { |
||||
super(_ch, m); |
||||
} |
||||
|
||||
public CvVectorPoint2f(Point[] a) { |
||||
super(_ch); |
||||
if(a==null) |
||||
return; |
||||
int cnt = a.length; |
||||
create(cnt); |
||||
float buff[] = new float[_ch * cnt]; |
||||
for(int i=0; i<cnt; i++) { |
||||
Point p = a[i]; |
||||
buff[_ch*i+0] = (float) p.x; |
||||
buff[_ch*i+1] = (float) p.y; |
||||
} |
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
} |
||||
|
||||
public Point[] toArray(Point[] a) { |
||||
float buff[] = super.toArray(null); |
||||
if(buff.length == 0) |
||||
return new Point[0]; //null;
|
||||
int cnt = buff.length / _ch; |
||||
Point[] res = a; |
||||
if(a==null || a.length<cnt) |
||||
res = new Point[cnt]; |
||||
for(int i=0; i<cnt; i++) |
||||
res[i] = new Point(buff[i*_ch], buff[i*_ch+1]); |
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVectorPoint3 extends CvVectorInt { |
||||
private static final int _ch = 3; //xxxC2
|
||||
|
||||
public CvVectorPoint3() { |
||||
super(_ch); |
||||
} |
||||
|
||||
public CvVectorPoint3(long addr) { |
||||
super(_ch, addr); |
||||
} |
||||
|
||||
public CvVectorPoint3(Mat m) { |
||||
super(_ch, m); |
||||
} |
||||
|
||||
public CvVectorPoint3(Point3[] a) { |
||||
super(_ch); |
||||
if(a==null) |
||||
return; |
||||
int cnt = a.length; |
||||
create(cnt); |
||||
int buff[] = new int[_ch * cnt]; |
||||
for(int i=0; i<cnt; i++) { |
||||
Point3 p = a[i]; |
||||
buff[_ch*i] = (int) p.x; |
||||
buff[_ch*i+1] = (int) p.y; |
||||
buff[_ch*i+2] = (int) p.z; |
||||
} |
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
} |
||||
|
||||
public Point3[] toArray(Point3[] a) { |
||||
int buff[] = super.toArray(null); |
||||
if(buff.length == 0) |
||||
return new Point3[0]; //null;
|
||||
int cnt = buff.length / _ch; |
||||
Point3[] res = a; |
||||
if(a==null || a.length<cnt) |
||||
res = new Point3[cnt]; |
||||
for(int i=0; i<cnt; i++) |
||||
res[i] = new Point3(buff[i*_ch], buff[i*_ch+1], buff[i*_ch+2]); |
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
package org.opencv.core; |
||||
|
||||
public class CvVectorPoint3f extends CvVectorFloat { |
||||
private static final int _ch = 3; //xxxC2
|
||||
|
||||
public CvVectorPoint3f() { |
||||
super(_ch); |
||||
} |
||||
|
||||
public CvVectorPoint3f(long addr) { |
||||
super(_ch, addr); |
||||
} |
||||
|
||||
public CvVectorPoint3f(Mat m) { |
||||
super(_ch, m); |
||||
} |
||||
|
||||
public CvVectorPoint3f(Point3[] a) { |
||||
super(_ch); |
||||
if(a==null) |
||||
return; |
||||
int cnt = a.length; |
||||
create(cnt); |
||||
float buff[] = new float[_ch * cnt]; |
||||
for(int i=0; i<cnt; i++) { |
||||
Point3 p = a[i]; |
||||
buff[_ch*i] = (float) p.x; |
||||
buff[_ch*i+1] = (float) p.y; |
||||
buff[_ch*i+2] = (float) p.z; |
||||
} |
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
} |
||||
|
||||
public Point3[] toArray(Point3[] a) { |
||||
float buff[] = super.toArray(null); |
||||
if(buff.length == 0) |
||||
return new Point3[0]; //null;
|
||||
int cnt = buff.length / _ch; |
||||
Point3[] res = a; |
||||
if(a==null || a.length<cnt) |
||||
res = new Point3[cnt]; |
||||
for(int i=0; i<cnt; i++) |
||||
res[i] = new Point3(buff[i*_ch], buff[i*_ch+1], buff[i*_ch+2]); |
||||
return res; |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
package org.opencv.core; |
||||
|
||||
|
||||
public class CvVectorRect extends CvVectorInt { |
||||
private static final int _ch = 4; //xxxC4
|
||||
|
||||
public CvVectorRect() { |
||||
super(_ch); |
||||
} |
||||
|
||||
public CvVectorRect(long addr) { |
||||
super(_ch, addr); |
||||
} |
||||
|
||||
public CvVectorRect(Mat m) { |
||||
super(_ch, m); |
||||
} |
||||
|
||||
public CvVectorRect(Rect[] a) { |
||||
super(_ch); |
||||
if(a==null) |
||||
return; |
||||
int cnt = a.length; |
||||
create(cnt); |
||||
int buff[] = new int[_ch * cnt]; |
||||
for(int i=0; i<cnt; i++) { |
||||
Rect r = a[i]; |
||||
buff[_ch*i] = r.x; |
||||
buff[_ch*i+1] = r.y; |
||||
buff[_ch*i+2] = r.width; |
||||
buff[_ch*i+3] = r.height; |
||||
} |
||||
put(0, 0, buff); //TODO: check ret val!
|
||||
} |
||||
|
||||
public Rect[] toArray(Rect[] a) { |
||||
int buff[] = super.toArray(null); |
||||
if(buff.length == 0) |
||||
return new Rect[0]; //null;
|
||||
int cnt = buff.length / _ch; |
||||
Rect[] res = a; |
||||
if(a==null || a.length<cnt) |
||||
res = new Rect[cnt]; |
||||
for(int i=0; i<cnt; i++) |
||||
res[i] = new Rect(buff[i*_ch], buff[i*_ch+1], buff[i*_ch+2], buff[i*_ch+3]); |
||||
return res; |
||||
} |
||||
} |
Loading…
Reference in new issue