Added vector_Point3f_to_Mat converter and some java API tests

pull/13383/head
Andrey Kamaev 14 years ago
parent 9235a80109
commit e3ede92db6
  1. 60
      modules/java/android_test/src/org/opencv/test/calib3d/calib3dTest.java
  2. 11
      modules/java/android_test/src/org/opencv/test/core/coreTest.java
  3. 6
      modules/java/android_test/src/org/opencv/test/objdetect/HOGDescriptorTest.java
  4. 19
      modules/java/src/java/Converters.java

@ -1,15 +1,14 @@
package org.opencv.test.calib3d;
import android.util.Log;
import org.opencv.Converters;
import org.opencv.calib3d.Calib3d;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Point3;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.calib3d.Calib3d;
import org.opencv.core.Core;
import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner;
@ -252,7 +251,22 @@ public class calib3dTest extends OpenCVTestCase {
}
public void testFindFundamentalMatMatMat() {
fail("Not yet implemented");
List<Point> pts1 = new ArrayList<Point>();
List<Point> pts2 = new ArrayList<Point>();
int minFundamentalMatPoints = 9; //FIXME: probably should be 8 (see ticket #1262)
for (int i = 0; i < minFundamentalMatPoints; i++) {
double x = Math.random() * 100 - 50;
double y = Math.random() * 100 - 50;
pts1.add(new Point(x, y));
pts2.add(new Point(x, y));
}
Mat fm = Calib3d.findFundamentalMat(Converters.vector_Point2f_to_Mat(pts1), Converters.vector_Point2f_to_Mat(pts2));
truth = new Mat(3,3,CvType.CV_64F);
truth.put(0, 0, 0, -0.5, -0.5, 0.5, 0, 0, 0.5, 0, 0);
assertMatEqual(truth, fm, EPS);
}
public void testFindFundamentalMatMatMatInt() {
@ -283,7 +297,9 @@ public class calib3dTest extends OpenCVTestCase {
transformedPoints.add(new Point(y, x));
}
Mat hmg = Calib3d.findHomography(Converters.vector_Point2f_to_Mat(originalPoints), Converters.vector_Point2f_to_Mat(transformedPoints));
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);
@ -402,7 +418,37 @@ public class calib3dTest extends OpenCVTestCase {
}
public void testSolvePnPMatMatMatMatMatMat() {
fail("Not yet implemented");
Mat intrinsics = Mat.eye(3, 3, CvType.CV_32F);
intrinsics.put(0, 0, 400);
intrinsics.put(1, 1, 400);
intrinsics.put(0, 2, 640 / 2);
intrinsics.put(1, 2, 480 / 2);
List<Point3> points3d = new ArrayList<Point3>();
List<Point> points2d = new ArrayList<Point>();
int minPnpPointsNum = 4;
for (int i = 0; i < minPnpPointsNum; i++) {
double x = Math.random() * 100 - 50;
double y = Math.random() * 100 - 50;
points2d.add(new Point(x, y));
points3d.add(new Point3(0, y, x));
}
Mat rvec = new Mat();
Mat tvec = new Mat();
Calib3d.solvePnP(Converters.vector_Point3f_to_Mat(points3d),
Converters.vector_Point2f_to_Mat(points2d), intrinsics,
new Mat(), rvec, tvec);
Mat truth_rvec = new Mat(3, 1, CvType.CV_64F);
truth_rvec.put(0, 0, 0, Math.PI / 2, 0);
Mat truth_tvec = new Mat(3, 1, CvType.CV_64F);
truth_tvec.put(0, 0, -320, -240, 400);
assertMatEqual(truth_rvec, rvec, EPS);
assertMatEqual(truth_tvec, tvec, EPS);
}
public void testSolvePnPMatMatMatMatMatMatBoolean() {

@ -1093,8 +1093,7 @@ public class coreTest extends OpenCVTestCase {
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);
Mat transformMatrix = Mat.eye(3, 3, CvType.CV_32F);
Core.perspectiveTransform(src, dst, transformMatrix);
@ -1108,13 +1107,7 @@ public class coreTest extends OpenCVTestCase {
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);
Mat transformMatrix = Mat.eye(4, 4, CvType.CV_32F);
Core.perspectiveTransform(src, dst, transformMatrix);

@ -1,5 +1,6 @@
package org.opencv.test.objdetect;
import org.opencv.objdetect.HOGDescriptor;
import org.opencv.test.OpenCVTestCase;
public class HOGDescriptorTest extends OpenCVTestCase {
@ -189,7 +190,10 @@ public class HOGDescriptorTest extends OpenCVTestCase {
}
public void testHOGDescriptor() {
fail("Not yet implemented");
HOGDescriptor hog = new HOGDescriptor();
assertTrue(null != hog);
assertEquals(HOGDescriptor.DEFAULT_NLEVELS, hog.get_nlevels());
}
public void testHOGDescriptorSizeSizeSizeSizeInt() {

@ -46,6 +46,25 @@ public class Converters {
return res;
}
public static Mat vector_Point3f_to_Mat(List<Point3> pts) {
Mat res;
int count = (pts!=null) ? pts.size() : 0;
if(count>0){
res = new Mat(1, count, CvType.CV_32FC3);
float[] buff = new float[count*3];
for(int i=0; i<count; i++) {
Point3 p = pts.get(i);
buff[i*3] = (float)p.x;
buff[i*3+1] = (float)p.y;
buff[i*3+2] = (float)p.z;
}
res.put(0, 0, buff);
} else {
res = new Mat();
}
return res;
}
public static void Mat_to_vector_Point(Mat m, List<Point> pts) {
if(pts == null)
throw new java.lang.IllegalArgumentException();

Loading…
Cancel
Save