Added vector_Point3f_to_Mat converter and some java API tests

pull/13383/head
Andrey Kamaev 14 years ago
parent 9235a80109
commit e3ede92db6
  1. 102
      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. 364
      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; package org.opencv.test.calib3d;
import android.util.Log;
import org.opencv.Converters; import org.opencv.Converters;
import org.opencv.calib3d.Calib3d;
import org.opencv.core.Core;
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;
import org.opencv.core.Point3;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.core.Size; import org.opencv.core.Size;
import org.opencv.calib3d.Calib3d;
import org.opencv.core.Core;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner; import org.opencv.test.OpenCVTestRunner;
@ -216,7 +215,7 @@ public class calib3dTest extends OpenCVTestCase {
org.opencv.highgui.Highgui.imwrite("/mnt/sdcard/test3.png", img); org.opencv.highgui.Highgui.imwrite("/mnt/sdcard/test3.png", img);
assertTrue(Calib3d.findCirclesGridDefault(img, new Size(5, 5), centers)); assertTrue(Calib3d.findCirclesGridDefault(img, new Size(5, 5), centers));
assertEquals(25, centers.rows()); assertEquals(25, centers.rows());
assertEquals(1, centers.cols()); assertEquals(1, centers.cols());
assertEquals(CvType.CV_32FC2, centers.type()); assertEquals(CvType.CV_32FC2, centers.type());
@ -245,14 +244,29 @@ public class calib3dTest extends OpenCVTestCase {
assertTrue(Calib3d.findCirclesGridDefault(img, new Size(3, 5), centers, assertTrue(Calib3d.findCirclesGridDefault(img, new Size(3, 5), centers,
Calib3d.CALIB_CB_CLUSTERING | Calib3d.CALIB_CB_ASYMMETRIC_GRID)); Calib3d.CALIB_CB_CLUSTERING | Calib3d.CALIB_CB_ASYMMETRIC_GRID));
assertEquals(15, centers.rows()); assertEquals(15, centers.rows());
assertEquals(1, centers.cols()); assertEquals(1, centers.cols());
assertEquals(CvType.CV_32FC2, centers.type()); assertEquals(CvType.CV_32FC2, centers.type());
} }
public void testFindFundamentalMatMatMat() { 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() { public void testFindFundamentalMatMatMatInt() {
@ -272,22 +286,24 @@ public class calib3dTest extends OpenCVTestCase {
} }
public void testFindHomographyMatMat() { public void testFindHomographyMatMat() {
List<Point> originalPoints = new ArrayList<Point>(); List<Point> originalPoints = new ArrayList<Point>();
List<Point> transformedPoints = new ArrayList<Point>(); List<Point> transformedPoints = new ArrayList<Point>();
for (int i = 0; i < 20; i++){ for (int i = 0; i < 20; i++) {
double x = Math.random() * 100 - 50; double x = Math.random() * 100 - 50;
double y = Math.random() * 100 - 50; double y = Math.random() * 100 - 50;
originalPoints.add(new Point(x,y)); originalPoints.add(new Point(x, y));
transformedPoints.add(new Point(y,x)); 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),
truth = new Mat(3,3, CvType.CV_64F); Converters.vector_Point2f_to_Mat(transformedPoints));
truth.put(0, 0, 0,1,0,1,0,0,0,0,1);
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); assertMatEqual(truth, hmg, EPS);
} }
@ -364,20 +380,20 @@ public class calib3dTest extends OpenCVTestCase {
} }
public void testRodriguesMatMat() { public void testRodriguesMatMat() {
Mat r = new Mat(3,1,CvType.CV_32F); Mat r = new Mat(3, 1, CvType.CV_32F);
Mat R = new Mat(3,3,CvType.CV_32F); Mat R = new Mat(3, 3, CvType.CV_32F);
r.put(0, 0, Math.PI, 0, 0); r.put(0, 0, Math.PI, 0, 0);
Calib3d.Rodrigues(r, R); Calib3d.Rodrigues(r, R);
truth = new Mat(3,3,CvType.CV_32F); truth = new Mat(3, 3, CvType.CV_32F);
truth.put(0, 0, 1, 0 ,0, 0, -1, 0, 0, 0, -1); truth.put(0, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1);
assertMatEqual(truth, R, EPS); assertMatEqual(truth, R, EPS);
Mat r2 = new Mat(); Mat r2 = new Mat();
Calib3d.Rodrigues(R, r2); Calib3d.Rodrigues(R, r2);
assertMatEqual(r, r2, EPS); assertMatEqual(r, r2, EPS);
} }
@ -402,7 +418,37 @@ public class calib3dTest extends OpenCVTestCase {
} }
public void testSolvePnPMatMatMatMatMatMat() { 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() { public void testSolvePnPMatMatMatMatMatMatBoolean() {

@ -1093,8 +1093,7 @@ public class coreTest extends OpenCVTestCase {
Core.randu(src, low, high); Core.randu(src, low, high);
//FIXME: use Mat.diag //FIXME: use Mat.diag
Mat transformMatrix = new Mat(3, 3, CvType.CV_32F); Mat transformMatrix = Mat.eye(3, 3, CvType.CV_32F);
transformMatrix.put(0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1);
Core.perspectiveTransform(src, dst, transformMatrix); 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)); Mat high = new Mat(1, 1, CvType.CV_32F, new Scalar(256));
Core.randu(src, low, high); Core.randu(src, low, high);
//FIXME: use Mat.diag Mat transformMatrix = Mat.eye(4, 4, CvType.CV_32F);
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); Core.perspectiveTransform(src, dst, transformMatrix);

@ -1,247 +1,251 @@
package org.opencv.test.objdetect; package org.opencv.test.objdetect;
import org.opencv.objdetect.HOGDescriptor;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
public class HOGDescriptorTest extends OpenCVTestCase { public class HOGDescriptorTest extends OpenCVTestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
} }
public void testCheckDetectorSize() { public void testCheckDetectorSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testComputeGradientMatMatMat() { public void testComputeGradientMatMatMat() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testComputeGradientMatMatMatSize() { public void testComputeGradientMatMatMatSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testComputeGradientMatMatMatSizeSize() { public void testComputeGradientMatMatMatSizeSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testComputeMatListOfFloat() { public void testComputeMatListOfFloat() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testComputeMatListOfFloatSize() { public void testComputeMatListOfFloatSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testComputeMatListOfFloatSizeSize() { public void testComputeMatListOfFloatSizeSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testComputeMatListOfFloatSizeSizeListOfPoint() { public void testComputeMatListOfFloatSizeSizeListOfPoint() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPoint() { public void testDetectMatListOfPoint() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPointDouble() { public void testDetectMatListOfPointDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPointDoubleSize() { public void testDetectMatListOfPointDoubleSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPointDoubleSizeSize() { public void testDetectMatListOfPointDoubleSizeSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPointDoubleSizeSizeListOfPoint() { public void testDetectMatListOfPointDoubleSizeSizeListOfPoint() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPointListOfDouble() { public void testDetectMatListOfPointListOfDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPointListOfDoubleDouble() { public void testDetectMatListOfPointListOfDoubleDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPointListOfDoubleDoubleSize() { public void testDetectMatListOfPointListOfDoubleDoubleSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPointListOfDoubleDoubleSizeSize() { public void testDetectMatListOfPointListOfDoubleDoubleSizeSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMatListOfPointListOfDoubleDoubleSizeSizeListOfPoint() { public void testDetectMatListOfPointListOfDoubleDoubleSizeSizeListOfPoint() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRect() { public void testDetectMultiScaleMatListOfRect() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectDouble() { public void testDetectMultiScaleMatListOfRectDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectDoubleSize() { public void testDetectMultiScaleMatListOfRectDoubleSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectDoubleSizeSize() { public void testDetectMultiScaleMatListOfRectDoubleSizeSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectDoubleSizeSizeDouble() { public void testDetectMultiScaleMatListOfRectDoubleSizeSizeDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectDoubleSizeSizeDoubleDouble() { public void testDetectMultiScaleMatListOfRectDoubleSizeSizeDoubleDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectDoubleSizeSizeDoubleDoubleBoolean() { public void testDetectMultiScaleMatListOfRectDoubleSizeSizeDoubleDoubleBoolean() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectListOfDouble() { public void testDetectMultiScaleMatListOfRectListOfDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectListOfDoubleDouble() { public void testDetectMultiScaleMatListOfRectListOfDoubleDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSize() { public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSize() { public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSizeDouble() { public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSizeDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSizeDoubleDouble() { public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSizeDoubleDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSizeDoubleDoubleBoolean() { public void testDetectMultiScaleMatListOfRectListOfDoubleDoubleSizeSizeDoubleDoubleBoolean() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_blockSize() { public void testGet_blockSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_blockStride() { public void testGet_blockStride() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_cellSize() { public void testGet_cellSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_derivAperture() { public void testGet_derivAperture() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_gammaCorrection() { public void testGet_gammaCorrection() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_histogramNormType() { public void testGet_histogramNormType() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_L2HysThreshold() { public void testGet_L2HysThreshold() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_nbins() { public void testGet_nbins() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_nlevels() { public void testGet_nlevels() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_winSigma() { public void testGet_winSigma() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGet_winSize() { public void testGet_winSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGetDescriptorSize() { public void testGetDescriptorSize() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testGetWinSigma() { public void testGetWinSigma() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testHOGDescriptor() { public void testHOGDescriptor() {
fail("Not yet implemented"); HOGDescriptor hog = new HOGDescriptor();
}
public void testHOGDescriptorSizeSizeSizeSizeInt() { assertTrue(null != hog);
fail("Not yet implemented"); assertEquals(HOGDescriptor.DEFAULT_NLEVELS, hog.get_nlevels());
} }
public void testHOGDescriptorSizeSizeSizeSizeIntInt() { public void testHOGDescriptorSizeSizeSizeSizeInt() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testHOGDescriptorSizeSizeSizeSizeIntIntDouble() { public void testHOGDescriptorSizeSizeSizeSizeIntInt() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleInt() { public void testHOGDescriptorSizeSizeSizeSizeIntIntDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleIntDouble() { public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleInt() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleIntDoubleBoolean() { public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleIntDouble() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleIntDoubleBooleanInt() { public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleIntDoubleBoolean() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testHOGDescriptorString() { public void testHOGDescriptorSizeSizeSizeSizeIntIntDoubleIntDoubleBooleanInt() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testLoadString() { public void testHOGDescriptorString() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testLoadStringString() { public void testLoadString() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testSaveString() { public void testLoadStringString() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testSaveStringString() { public void testSaveString() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testSetSVMDetector() { public void testSaveStringString() {
fail("Not yet implemented"); fail("Not yet implemented");
} }
public void testSetSVMDetector() {
fail("Not yet implemented");
}
} }

@ -46,6 +46,25 @@ public class Converters {
return res; 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) { public static void Mat_to_vector_Point(Mat m, List<Point> pts) {
if(pts == null) if(pts == null)
throw new java.lang.IllegalArgumentException(); throw new java.lang.IllegalArgumentException();

Loading…
Cancel
Save