Added vector_Point2f_to_Mat converter
This commit is contained in:
parent
c966d077c0
commit
20b4d0fae9
@ -166,7 +166,6 @@ public class OpenCVTestCase extends TestCase {
|
|||||||
}
|
}
|
||||||
Mat diff = new Mat();
|
Mat diff = new Mat();
|
||||||
Core.absdiff(expected, actual, diff);
|
Core.absdiff(expected, actual, diff);
|
||||||
OpenCVTestRunner.Log(diff + " \n " + diff.dump());
|
|
||||||
if(isEqualityMeasured)
|
if(isEqualityMeasured)
|
||||||
assertTrue("Max difference between expected and actiual values is bigger than " + eps,
|
assertTrue("Max difference between expected and actiual values is bigger than " + eps,
|
||||||
Core.checkRange(diff, true, new Point(), 0.0, eps));
|
Core.checkRange(diff, true, new Point(), 0.0, eps));
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package org.opencv.test.calib3d;
|
package org.opencv.test.calib3d;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.opencv.Converters;
|
||||||
import org.opencv.core.CvType;
|
import org.opencv.core.CvType;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.core.Point;
|
import org.opencv.core.Point;
|
||||||
@ -8,6 +11,10 @@ import org.opencv.core.Size;
|
|||||||
import org.opencv.calib3d.Calib3d;
|
import org.opencv.calib3d.Calib3d;
|
||||||
import org.opencv.core.Core;
|
import org.opencv.core.Core;
|
||||||
import org.opencv.test.OpenCVTestCase;
|
import org.opencv.test.OpenCVTestCase;
|
||||||
|
import org.opencv.test.OpenCVTestRunner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class calib3dTest extends OpenCVTestCase {
|
public class calib3dTest extends OpenCVTestCase {
|
||||||
|
|
||||||
@ -265,7 +272,23 @@ public class calib3dTest extends OpenCVTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testFindHomographyMatMat() {
|
public void testFindHomographyMatMat() {
|
||||||
fail("Not yet implemented");
|
|
||||||
|
List<Point> originalPoints = new ArrayList<Point>();
|
||||||
|
List<Point> transformedPoints = new ArrayList<Point>();
|
||||||
|
|
||||||
|
for (int i = 0; i < 20; i++){
|
||||||
|
double x = Math.random() * 100 - 50;
|
||||||
|
double y = Math.random() * 100 - 50;
|
||||||
|
originalPoints.add(new Point(x,y));
|
||||||
|
transformedPoints.add(new Point(y,x));
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat hmg = Calib3d.findHomography(Converters.vector_Point2f_to_Mat(originalPoints), Converters.vector_Point2f_to_Mat(transformedPoints));
|
||||||
|
|
||||||
|
truth = new Mat(3,3, CvType.CV_64F);
|
||||||
|
truth.put(0, 0, 0,1,0,1,0,0,0,0,1);
|
||||||
|
|
||||||
|
assertMatEqual(truth, hmg, EPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFindHomographyMatMatInt() {
|
public void testFindHomographyMatMatInt() {
|
||||||
|
@ -1086,8 +1086,39 @@ public class coreTest extends OpenCVTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPerspectiveTransform() {
|
public void testPerspectiveTransform() {
|
||||||
// nice example
|
Mat src = new Mat(matSize, matSize, CvType.CV_32FC2);
|
||||||
fail("Not yet implemented");
|
|
||||||
|
Mat low = new Mat(1, 1, CvType.CV_32F, new Scalar(0));
|
||||||
|
Mat high = new Mat(1, 1, CvType.CV_32F, new Scalar(256));
|
||||||
|
Core.randu(src, low, high);
|
||||||
|
|
||||||
|
//FIXME: use Mat.diag
|
||||||
|
Mat transformMatrix = new Mat(3, 3, CvType.CV_32F);
|
||||||
|
transformMatrix.put(0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
|
||||||
|
|
||||||
|
Core.perspectiveTransform(src, dst, transformMatrix);
|
||||||
|
|
||||||
|
assertMatEqual(src, dst, EPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPerspectiveTransform3D() {
|
||||||
|
Mat src = new Mat(matSize, matSize, CvType.CV_32FC3);
|
||||||
|
|
||||||
|
Mat low = new Mat(1, 1, CvType.CV_32F, new Scalar(0));
|
||||||
|
Mat high = new Mat(1, 1, CvType.CV_32F, new Scalar(256));
|
||||||
|
Core.randu(src, low, high);
|
||||||
|
|
||||||
|
//FIXME: use Mat.diag
|
||||||
|
Mat transformMatrix = new Mat(4, 4, CvType.CV_32F);
|
||||||
|
transformMatrix.put(0, 0,
|
||||||
|
1, 0, 0, 0,
|
||||||
|
0, 1, 0, 0,
|
||||||
|
0, 0, 1, 0,
|
||||||
|
0, 0, 0, 1);
|
||||||
|
|
||||||
|
Core.perspectiveTransform(src, dst, transformMatrix);
|
||||||
|
|
||||||
|
assertMatEqual(src, dst, EPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPhaseMatMatMat() {
|
public void testPhaseMatMatMat() {
|
||||||
|
@ -10,208 +10,226 @@ 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++) {
|
||||||
|
Point p = pts.get(i);
|
||||||
|
buff[i*2] = (float)p.x;
|
||||||
|
buff[i*2+1] = (float)p.y;
|
||||||
|
}
|
||||||
|
res.put(0, 0, buff);
|
||||||
|
} else {
|
||||||
|
res = new Mat();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
pts.clear();
|
public static void Mat_to_vector_Point(Mat m, List<Point> pts) {
|
||||||
int[] buff = new int[2*cols];
|
if(pts == null)
|
||||||
m.get(0, 0, buff);
|
throw new java.lang.IllegalArgumentException();
|
||||||
for(int i=0; i<cols; i++) {
|
int cols = m.cols();
|
||||||
pts.add( new Point(buff[i*2], buff[i*2+1]) );
|
if(CvType.CV_32SC2 != m.type() || m.rows()!=1 )
|
||||||
}
|
throw new java.lang.IllegalArgumentException();
|
||||||
}
|
|
||||||
|
|
||||||
public static Mat vector_Mat_to_Mat(List<Mat> mats) {
|
pts.clear();
|
||||||
Mat res;
|
int[] buff = new int[2*cols];
|
||||||
int count = (mats!=null) ? mats.size() : 0;
|
m.get(0, 0, buff);
|
||||||
if(count>0){
|
for(int i=0; i<cols; i++) {
|
||||||
res = new Mat(1, count, CvType.CV_32SC2);
|
pts.add( new Point(buff[i*2], buff[i*2+1]) );
|
||||||
int[] buff = new int[count*2];
|
}
|
||||||
for(int i=0; i<count; i++) {
|
}
|
||||||
long addr = mats.get(i).nativeObj;
|
|
||||||
buff[i*2] = (int)(addr >> 32);
|
|
||||||
buff[i*2+1] = (int)(addr & 0xffffffff);
|
|
||||||
}
|
|
||||||
res.put(0, 0, buff);
|
|
||||||
} else {
|
|
||||||
res = new Mat();
|
|
||||||
}
|
|
||||||
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++) {
|
||||||
|
long addr = mats.get(i).nativeObj;
|
||||||
|
buff[i*2] = (int)(addr >> 32);
|
||||||
|
buff[i*2+1] = (int)(addr & 0xffffffff);
|
||||||
|
}
|
||||||
|
res.put(0, 0, buff);
|
||||||
|
} else {
|
||||||
|
res = new Mat();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
mats.clear();
|
public static void Mat_to_vector_Mat(Mat m, List<Mat> mats) {
|
||||||
int[] buff = new int[cols*2];
|
if(mats == null)
|
||||||
m.get(0, 0, buff);
|
throw new java.lang.IllegalArgumentException();
|
||||||
for(int i=0; i<cols; i++) {
|
int cols = m.cols();
|
||||||
long addr = (((long)buff[i*2])<<32) | ((long)buff[i*2+1]);
|
if(CvType.CV_32SC2 != m.type() || m.rows()!=1 )
|
||||||
mats.add( new Mat(addr) );
|
throw new java.lang.IllegalArgumentException();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Mat_to_vector_KeyPoint(Mat kp_mat, List<KeyPoint> kps) {
|
mats.clear();
|
||||||
// TODO Auto-generated method stub
|
int[] buff = new int[cols*2];
|
||||||
}
|
m.get(0, 0, buff);
|
||||||
|
for(int i=0; i<cols; i++) {
|
||||||
|
long addr = (((long)buff[i*2])<<32) | ((long)buff[i*2+1]);
|
||||||
|
mats.add( new Mat(addr) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Mat vector_float_to_Mat(List<Float> fs) {
|
public static void Mat_to_vector_KeyPoint(Mat kp_mat, List<KeyPoint> kps) {
|
||||||
Mat res;
|
// TODO Auto-generated method stub
|
||||||
int count = (fs!=null) ? fs.size() : 0;
|
}
|
||||||
if(count>0){
|
|
||||||
res = new Mat(1, count, CvType.CV_32FC1); //Point can be saved into double[2]
|
|
||||||
float[] buff = new float[count];
|
|
||||||
for(int i=0; i<count; i++) {
|
|
||||||
float f = fs.get(i);
|
|
||||||
buff[i] = f;
|
|
||||||
}
|
|
||||||
res.put(0, 0, buff);
|
|
||||||
} else {
|
|
||||||
res = new Mat();
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
|
public static Mat vector_float_to_Mat(List<Float> fs) {
|
||||||
if(fs == null)
|
Mat res;
|
||||||
throw new java.lang.IllegalArgumentException();
|
int count = (fs!=null) ? fs.size() : 0;
|
||||||
int cols = m.cols();
|
if(count>0){
|
||||||
if(CvType.CV_32FC1 != m.type() || m.rows()!=1 )
|
res = new Mat(1, count, CvType.CV_32FC1); //Point can be saved into double[2]
|
||||||
throw new java.lang.IllegalArgumentException();
|
float[] buff = new float[count];
|
||||||
|
for(int i=0; i<count; i++) {
|
||||||
|
float f = fs.get(i);
|
||||||
|
buff[i] = f;
|
||||||
|
}
|
||||||
|
res.put(0, 0, buff);
|
||||||
|
} else {
|
||||||
|
res = new Mat();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
fs.clear();
|
public static void Mat_to_vector_float(Mat m, List<Float> fs) {
|
||||||
float[] buff = new float[cols];
|
if(fs == null)
|
||||||
m.get(0, 0, buff);
|
throw new java.lang.IllegalArgumentException();
|
||||||
for(int i=0; i<cols; i++) {
|
int cols = m.cols();
|
||||||
fs.add( new Float(buff[i]) );
|
if(CvType.CV_32FC1 != m.type() || m.rows()!=1 )
|
||||||
}
|
throw new java.lang.IllegalArgumentException();
|
||||||
}
|
|
||||||
|
|
||||||
public static Mat vector_uchar_to_Mat(List<Byte> bs) {
|
fs.clear();
|
||||||
Mat res;
|
float[] buff = new float[cols];
|
||||||
int count = (bs!=null) ? bs.size() : 0;
|
m.get(0, 0, buff);
|
||||||
if(count>0){
|
for(int i=0; i<cols; i++) {
|
||||||
res = new Mat(1, count, CvType.CV_8UC1); //Point can be saved into double[2]
|
fs.add( new Float(buff[i]) );
|
||||||
byte[] buff = new byte[count];
|
}
|
||||||
for(int i=0; i<count; i++) {
|
}
|
||||||
byte b = bs.get(i);
|
|
||||||
buff[i] = b;
|
|
||||||
}
|
|
||||||
res.put(0, 0, buff);
|
|
||||||
} else {
|
|
||||||
res = new Mat();
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Mat vector_int_to_Mat(List<Integer> is) {
|
public static Mat vector_uchar_to_Mat(List<Byte> bs) {
|
||||||
Mat res;
|
Mat res;
|
||||||
int count = (is!=null) ? is.size() : 0;
|
int count = (bs!=null) ? bs.size() : 0;
|
||||||
if(count>0){
|
if(count>0){
|
||||||
res = new Mat(1, count, CvType.CV_32SC1); //Point can be saved into double[2]
|
res = new Mat(1, count, CvType.CV_8UC1); //Point can be saved into double[2]
|
||||||
int[] buff = new int[count];
|
byte[] buff = new byte[count];
|
||||||
for(int i=0; i<count; i++) {
|
for(int i=0; i<count; i++) {
|
||||||
int v = is.get(i);
|
byte b = bs.get(i);
|
||||||
buff[i] = v;
|
buff[i] = b;
|
||||||
}
|
}
|
||||||
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_int(Mat m, List<Integer> is) {
|
public static Mat vector_int_to_Mat(List<Integer> is) {
|
||||||
if(is == null)
|
Mat res;
|
||||||
throw new java.lang.IllegalArgumentException();
|
int count = (is!=null) ? is.size() : 0;
|
||||||
int cols = m.cols();
|
if(count>0){
|
||||||
if(CvType.CV_32SC1 != m.type() || m.rows()!=1 )
|
res = new Mat(1, count, CvType.CV_32SC1); //Point can be saved into double[2]
|
||||||
throw new java.lang.IllegalArgumentException();
|
int[] buff = new int[count];
|
||||||
|
for(int i=0; i<count; i++) {
|
||||||
|
int v = is.get(i);
|
||||||
|
buff[i] = v;
|
||||||
|
}
|
||||||
|
res.put(0, 0, buff);
|
||||||
|
} else {
|
||||||
|
res = new Mat();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
is.clear();
|
public static void Mat_to_vector_int(Mat m, List<Integer> is) {
|
||||||
int[] buff = new int[cols];
|
if(is == null)
|
||||||
m.get(0, 0, buff);
|
throw new java.lang.IllegalArgumentException();
|
||||||
for(int i=0; i<cols; i++) {
|
int cols = m.cols();
|
||||||
is.add( new Integer(buff[i]) );
|
if(CvType.CV_32SC1 != m.type() || m.rows()!=1 )
|
||||||
}
|
throw new java.lang.IllegalArgumentException();
|
||||||
}
|
|
||||||
|
|
||||||
public static Mat vector_Rect_to_Mat(List<Rect> rs) {
|
is.clear();
|
||||||
Mat res;
|
int[] buff = new int[cols];
|
||||||
int count = (rs!=null) ? rs.size() : 0;
|
m.get(0, 0, buff);
|
||||||
if(count>0){
|
for(int i=0; i<cols; i++) {
|
||||||
res = new Mat(1, count, CvType.CV_32SC4); //Point can be saved into double[2]
|
is.add( new Integer(buff[i]) );
|
||||||
int[] buff = new int[4*count];
|
}
|
||||||
for(int i=0; i<count; i++) {
|
}
|
||||||
Rect r = rs.get(i);
|
|
||||||
buff[4*i ] = r.x;
|
|
||||||
buff[4*i+1] = r.y;
|
|
||||||
buff[4*i+2] = r.width;
|
|
||||||
buff[4*i+3] = r.height;
|
|
||||||
}
|
|
||||||
res.put(0, 0, buff);
|
|
||||||
} else {
|
|
||||||
res = new Mat();
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Mat_to_vector_Rect(Mat m, List<Rect> rs) {
|
public static Mat vector_Rect_to_Mat(List<Rect> rs) {
|
||||||
if(rs == null)
|
Mat res;
|
||||||
throw new java.lang.IllegalArgumentException();
|
int count = (rs!=null) ? rs.size() : 0;
|
||||||
int cols = m.cols();
|
if(count>0){
|
||||||
if(CvType.CV_32SC4 != m.type() || m.rows()!=1 )
|
res = new Mat(1, count, CvType.CV_32SC4); //Point can be saved into double[2]
|
||||||
throw new java.lang.IllegalArgumentException();
|
int[] buff = new int[4*count];
|
||||||
|
for(int i=0; i<count; i++) {
|
||||||
|
Rect r = rs.get(i);
|
||||||
|
buff[4*i ] = r.x;
|
||||||
|
buff[4*i+1] = r.y;
|
||||||
|
buff[4*i+2] = r.width;
|
||||||
|
buff[4*i+3] = r.height;
|
||||||
|
}
|
||||||
|
res.put(0, 0, buff);
|
||||||
|
} else {
|
||||||
|
res = new Mat();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
rs.clear();
|
public static void Mat_to_vector_Rect(Mat m, List<Rect> rs) {
|
||||||
int[] buff = new int[4*cols];
|
if(rs == null)
|
||||||
m.get(0, 0, buff);
|
throw new java.lang.IllegalArgumentException();
|
||||||
for(int i=0; i<cols; i++) {
|
int cols = m.cols();
|
||||||
rs.add( new Rect(buff[4*i], buff[4*i+1], buff[4*i+2], buff[4*i+3]) );
|
if(CvType.CV_32SC4 != m.type() || m.rows()!=1 )
|
||||||
}
|
throw new java.lang.IllegalArgumentException();
|
||||||
}
|
|
||||||
|
|
||||||
public static Mat vector_double_to_Mat(List<Double> ds) {
|
rs.clear();
|
||||||
Mat res;
|
int[] buff = new int[4*cols];
|
||||||
int count = (ds!=null) ? ds.size() : 0;
|
m.get(0, 0, buff);
|
||||||
if(count>0){
|
for(int i=0; i<cols; i++) {
|
||||||
res = new Mat(1, count, CvType.CV_64FC1); //Point can be saved into double[2]
|
rs.add( new Rect(buff[4*i], buff[4*i+1], buff[4*i+2], buff[4*i+3]) );
|
||||||
double[] buff = new double[count];
|
}
|
||||||
for(int i=0; i<count; i++) {
|
}
|
||||||
double v = ds.get(i);
|
|
||||||
buff[i] = v;
|
public static Mat vector_double_to_Mat(List<Double> ds) {
|
||||||
}
|
Mat res;
|
||||||
res.put(0, 0, buff);
|
int count = (ds!=null) ? ds.size() : 0;
|
||||||
} else {
|
if(count>0){
|
||||||
res = new Mat();
|
res = new Mat(1, count, CvType.CV_64FC1); //Point can be saved into double[2]
|
||||||
}
|
double[] buff = new double[count];
|
||||||
return res;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user