mirror of
https://github.com/opencv/opencv.git
synced 2025-06-13 13:13:26 +08:00
Added vector_Point3f_to_Mat converter and some java API tests
This commit is contained in:
parent
9235a80109
commit
e3ede92db6
@ -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() {
|
||||
@ -276,17 +290,19 @@ public class calib3dTest extends OpenCVTestCase {
|
||||
List<Point> originalPoints = 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 y = Math.random() * 100 - 50;
|
||||
originalPoints.add(new Point(x,y));
|
||||
transformedPoints.add(new Point(y,x));
|
||||
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));
|
||||
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);
|
||||
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);
|
||||
}
|
||||
@ -364,15 +380,15 @@ public class calib3dTest extends OpenCVTestCase {
|
||||
}
|
||||
|
||||
public void testRodriguesMatMat() {
|
||||
Mat r = new Mat(3,1,CvType.CV_32F);
|
||||
Mat R = new Mat(3,3,CvType.CV_32F);
|
||||
Mat r = new Mat(3, 1, CvType.CV_32F);
|
||||
Mat R = new Mat(3, 3, CvType.CV_32F);
|
||||
|
||||
r.put(0, 0, Math.PI, 0, 0);
|
||||
|
||||
Calib3d.Rodrigues(r, R);
|
||||
|
||||
truth = new Mat(3,3,CvType.CV_32F);
|
||||
truth.put(0, 0, 1, 0 ,0, 0, -1, 0, 0, 0, -1);
|
||||
truth = new Mat(3, 3, CvType.CV_32F);
|
||||
truth.put(0, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1);
|
||||
assertMatEqual(truth, R, EPS);
|
||||
|
||||
Mat r2 = new Mat();
|
||||
@ -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…
Reference in New Issue
Block a user