1 package org.opencv.test.calib3d;
3 import org.opencv.calib3d.Calib3d;
4 import org.opencv.core.Core;
5 import org.opencv.core.CvType;
6 import org.opencv.core.Mat;
7 import org.opencv.core.MatOfDouble;
8 import org.opencv.core.MatOfPoint2f;
9 import org.opencv.core.MatOfPoint3f;
10 import org.opencv.core.Point;
11 import org.opencv.core.Scalar;
12 import org.opencv.core.Size;
13 import org.opencv.test.OpenCVTestCase;
14 import org.opencv.imgproc.Imgproc;
16 public class Calib3dTest extends OpenCVTestCase {
18 public void testCalibrateCameraListOfMatListOfMatSizeMatMatListOfMatListOfMat() {
19 fail("Not yet implemented");
22 public void testCalibrateCameraListOfMatListOfMatSizeMatMatListOfMatListOfMatInt() {
23 fail("Not yet implemented");
26 public void testCalibrationMatrixValues() {
27 fail("Not yet implemented");
30 public void testComposeRTMatMatMatMatMatMat() {
31 Mat rvec1 = new Mat(3, 1, CvType.CV_32F);
32 rvec1.put(0, 0, 0.5302828, 0.19925919, 0.40105945);
33 Mat tvec1 = new Mat(3, 1, CvType.CV_32F);
34 tvec1.put(0, 0, 0.81438506, 0.43713298, 0.2487897);
35 Mat rvec2 = new Mat(3, 1, CvType.CV_32F);
36 rvec2.put(0, 0, 0.77310503, 0.76209372, 0.30779448);
37 Mat tvec2 = new Mat(3, 1, CvType.CV_32F);
38 tvec2.put(0, 0, 0.70243168, 0.4784472, 0.79219002);
40 Mat rvec3 = new Mat();
41 Mat tvec3 = new Mat();
43 Mat outRvec = new Mat(3, 1, CvType.CV_32F);
44 outRvec.put(0, 0, 1.418641, 0.88665926, 0.56020796);
45 Mat outTvec = new Mat(3, 1, CvType.CV_32F);
46 outTvec.put(0, 0, 1.4560841, 1.0680628, 0.81598103);
48 Calib3d.composeRT(rvec1, tvec1, rvec2, tvec2, rvec3, tvec3);
50 assertMatEqual(outRvec, rvec3, EPS);
51 assertMatEqual(outTvec, tvec3, EPS);
54 public void testComposeRTMatMatMatMatMatMatMat() {
55 fail("Not yet implemented");
58 public void testComposeRTMatMatMatMatMatMatMatMat() {
59 fail("Not yet implemented");
62 public void testComposeRTMatMatMatMatMatMatMatMatMat() {
63 fail("Not yet implemented");
66 public void testComposeRTMatMatMatMatMatMatMatMatMatMat() {
67 fail("Not yet implemented");
70 public void testComposeRTMatMatMatMatMatMatMatMatMatMatMat() {
71 fail("Not yet implemented");
74 public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMat() {
75 fail("Not yet implemented");
78 public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMatMat() {
79 fail("Not yet implemented");
82 public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMatMatMat() {
83 fail("Not yet implemented");
92 // , dr3dr1, dr3dt1, dr3dr2, dr3dt2, dt3dr1, dt3dt1, dt3dr2, dt3dt2);
93 // [0.97031879, -0.091774099, 0.38594806;
94 // 0.15181915, 0.98091727, -0.44186208;
95 // -0.39509675, 0.43839464, 0.93872648]
99 // [1.0117353, 0.16348237, -0.083180845;
100 // -0.1980398, 1.006078, 0.30299222;
101 // 0.075766489, -0.32784501, 1.0163091]
108 // [0.69658804, 0.018115902, 0.7172426;
109 // 0.51114357, 0.68899536, -0.51382649;
110 // -0.50348526, 0.72453934, 0.47068608]
111 // [0.18536358, -0.20515044, -0.48834875;
112 // -0.25120571, 0.29043972, 0.60573936;
113 // 0.35370794, -0.69923931, 0.45781645]
119 public void testConvertPointsFromHomogeneous() {
120 fail("Not yet implemented");
123 public void testConvertPointsToHomogeneous() {
124 fail("Not yet implemented");
127 public void testDecomposeProjectionMatrixMatMatMatMat() {
128 fail("Not yet implemented");
131 public void testDecomposeProjectionMatrixMatMatMatMatMat() {
132 fail("Not yet implemented");
135 public void testDecomposeProjectionMatrixMatMatMatMatMatMat() {
136 fail("Not yet implemented");
139 public void testDecomposeProjectionMatrixMatMatMatMatMatMatMat() {
140 fail("Not yet implemented");
143 public void testDecomposeProjectionMatrixMatMatMatMatMatMatMatMat() {
144 fail("Not yet implemented");
147 public void testDrawChessboardCorners() {
148 fail("Not yet implemented");
151 public void testEstimateAffine3DMatMatMatMat() {
152 fail("Not yet implemented");
155 public void testEstimateAffine3DMatMatMatMatDouble() {
156 fail("Not yet implemented");
159 public void testEstimateAffine3DMatMatMatMatDoubleDouble() {
160 fail("Not yet implemented");
163 public void testFilterSpecklesMatDoubleIntDouble() {
164 gray_16s_1024.copyTo(dst);
165 Point center = new Point(gray_16s_1024.rows() / 2., gray_16s_1024.cols() / 2.);
166 Imgproc.circle(dst, center, 1, Scalar.all(4096));
168 assertMatNotEqual(gray_16s_1024, dst);
169 Calib3d.filterSpeckles(dst, 1024.0, 100, 0.);
170 assertMatEqual(gray_16s_1024, dst);
173 public void testFilterSpecklesMatDoubleIntDoubleMat() {
174 fail("Not yet implemented");
177 public void testFindChessboardCornersMatSizeMat() {
178 Size patternSize = new Size(9, 6);
179 MatOfPoint2f corners = new MatOfPoint2f();
180 Calib3d.findChessboardCorners(grayChess, patternSize, corners);
181 assertTrue(!corners.empty());
184 public void testFindChessboardCornersMatSizeMatInt() {
185 Size patternSize = new Size(9, 6);
186 MatOfPoint2f corners = new MatOfPoint2f();
187 Calib3d.findChessboardCorners(grayChess, patternSize, corners, Calib3d.CALIB_CB_ADAPTIVE_THRESH + Calib3d.CALIB_CB_NORMALIZE_IMAGE
188 + Calib3d.CALIB_CB_FAST_CHECK);
189 assertTrue(!corners.empty());
192 public void testFindCirclesGridMatSizeMat() {
194 Mat img = new Mat(size, size, CvType.CV_8U);
195 img.setTo(new Scalar(255));
196 Mat centers = new Mat();
198 assertFalse(Calib3d.findCirclesGrid(img, new Size(5, 5), centers));
200 for (int i = 0; i < 5; i++)
201 for (int j = 0; j < 5; j++) {
202 Point pt = new Point(size * (2 * i + 1) / 10, size * (2 * j + 1) / 10);
203 Imgproc.circle(img, pt, 10, new Scalar(0), -1);
206 assertTrue(Calib3d.findCirclesGrid(img, new Size(5, 5), centers));
208 assertEquals(25, centers.rows());
209 assertEquals(1, centers.cols());
210 assertEquals(CvType.CV_32FC2, centers.type());
213 public void testFindCirclesGridMatSizeMatInt() {
215 Mat img = new Mat(size, size, CvType.CV_8U);
216 img.setTo(new Scalar(255));
217 Mat centers = new Mat();
219 assertFalse(Calib3d.findCirclesGrid(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING
220 | Calib3d.CALIB_CB_ASYMMETRIC_GRID));
222 int step = size * 2 / 15;
223 int offsetx = size / 6;
224 int offsety = (size - 4 * step) / 2;
225 for (int i = 0; i < 3; i++)
226 for (int j = 0; j < 5; j++) {
227 Point pt = new Point(offsetx + (2 * i + j % 2) * step, offsety + step * j);
228 Imgproc.circle(img, pt, 10, new Scalar(0), -1);
231 assertTrue(Calib3d.findCirclesGrid(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING
232 | Calib3d.CALIB_CB_ASYMMETRIC_GRID));
234 assertEquals(15, centers.rows());
235 assertEquals(1, centers.cols());
236 assertEquals(CvType.CV_32FC2, centers.type());
239 public void testFindFundamentalMatListOfPointListOfPoint() {
240 int minFundamentalMatPoints = 8;
242 MatOfPoint2f pts = new MatOfPoint2f();
243 pts.alloc(minFundamentalMatPoints);
245 for (int i = 0; i < minFundamentalMatPoints; i++) {
246 double x = Math.random() * 100 - 50;
247 double y = Math.random() * 100 - 50;
248 pts.put(i, 0, x, y); //add(new Point(x, y));
251 Mat fm = Calib3d.findFundamentalMat(pts, pts);
253 truth = new Mat(3, 3, CvType.CV_64F);
254 truth.put(0, 0, 0, -0.577, 0.288, 0.577, 0, 0.288, -0.288, -0.288, 0);
255 assertMatEqual(truth, fm, EPS);
258 public void testFindFundamentalMatListOfPointListOfPointInt() {
259 fail("Not yet implemented");
262 public void testFindFundamentalMatListOfPointListOfPointIntDouble() {
263 fail("Not yet implemented");
266 public void testFindFundamentalMatListOfPointListOfPointIntDoubleDouble() {
267 fail("Not yet implemented");
270 public void testFindFundamentalMatListOfPointListOfPointIntDoubleDoubleMat() {
271 fail("Not yet implemented");
274 public void testFindHomographyListOfPointListOfPoint() {
277 MatOfPoint2f originalPoints = new MatOfPoint2f();
278 originalPoints.alloc(NUM);
279 MatOfPoint2f transformedPoints = new MatOfPoint2f();
280 transformedPoints.alloc(NUM);
282 for (int i = 0; i < NUM; i++) {
283 double x = Math.random() * 100 - 50;
284 double y = Math.random() * 100 - 50;
285 originalPoints.put(i, 0, x, y);
286 transformedPoints.put(i, 0, y, x);
289 Mat hmg = Calib3d.findHomography(originalPoints, transformedPoints);
291 truth = new Mat(3, 3, CvType.CV_64F);
292 truth.put(0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1);
294 assertMatEqual(truth, hmg, EPS);
297 public void testFindHomographyListOfPointListOfPointInt() {
298 fail("Not yet implemented");
301 public void testFindHomographyListOfPointListOfPointIntDouble() {
302 fail("Not yet implemented");
305 public void testFindHomographyListOfPointListOfPointIntDoubleMat() {
306 fail("Not yet implemented");
309 public void testGetOptimalNewCameraMatrixMatMatSizeDouble() {
310 fail("Not yet implemented");
313 public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSize() {
314 fail("Not yet implemented");
317 public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSizeRect() {
318 fail("Not yet implemented");
321 public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSizeRectBoolean() {
322 fail("Not yet implemented");
325 public void testGetValidDisparityROI() {
326 fail("Not yet implemented");
329 public void testInitCameraMatrix2DListOfMatListOfMatSize() {
330 fail("Not yet implemented");
333 public void testInitCameraMatrix2DListOfMatListOfMatSizeDouble() {
334 fail("Not yet implemented");
337 public void testMatMulDeriv() {
338 fail("Not yet implemented");
341 public void testProjectPointsMatMatMatMatMatMat() {
342 fail("Not yet implemented");
345 public void testProjectPointsMatMatMatMatMatMatMat() {
346 fail("Not yet implemented");
349 public void testProjectPointsMatMatMatMatMatMatMatDouble() {
350 fail("Not yet implemented");
353 public void testRectify3Collinear() {
354 fail("Not yet implemented");
357 public void testReprojectImageTo3DMatMatMat() {
358 Mat transformMatrix = new Mat(4, 4, CvType.CV_64F);
359 transformMatrix.put(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
361 Mat disparity = new Mat(matSize, matSize, CvType.CV_32F);
363 float[] disp = new float[matSize * matSize];
364 for (int i = 0; i < matSize; i++)
365 for (int j = 0; j < matSize; j++)
366 disp[i * matSize + j] = i - j;
367 disparity.put(0, 0, disp);
369 Mat _3dPoints = new Mat();
371 Calib3d.reprojectImageTo3D(disparity, _3dPoints, transformMatrix);
373 assertEquals(CvType.CV_32FC3, _3dPoints.type());
374 assertEquals(matSize, _3dPoints.rows());
375 assertEquals(matSize, _3dPoints.cols());
377 truth = new Mat(matSize, matSize, CvType.CV_32FC3);
379 float[] _truth = new float[matSize * matSize * 3];
380 for (int i = 0; i < matSize; i++)
381 for (int j = 0; j < matSize; j++) {
382 _truth[(i * matSize + j) * 3 + 0] = i;
383 _truth[(i * matSize + j) * 3 + 1] = j;
384 _truth[(i * matSize + j) * 3 + 2] = i - j;
386 truth.put(0, 0, _truth);
388 assertMatEqual(truth, _3dPoints, EPS);
391 public void testReprojectImageTo3DMatMatMatBoolean() {
392 Mat transformMatrix = new Mat(4, 4, CvType.CV_64F);
393 transformMatrix.put(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
395 Mat disparity = new Mat(matSize, matSize, CvType.CV_32F);
397 float[] disp = new float[matSize * matSize];
398 for (int i = 0; i < matSize; i++)
399 for (int j = 0; j < matSize; j++)
400 disp[i * matSize + j] = i - j;
401 disp[0] = -Float.MAX_VALUE;
402 disparity.put(0, 0, disp);
404 Mat _3dPoints = new Mat();
406 Calib3d.reprojectImageTo3D(disparity, _3dPoints, transformMatrix, true);
408 assertEquals(CvType.CV_32FC3, _3dPoints.type());
409 assertEquals(matSize, _3dPoints.rows());
410 assertEquals(matSize, _3dPoints.cols());
412 truth = new Mat(matSize, matSize, CvType.CV_32FC3);
414 float[] _truth = new float[matSize * matSize * 3];
415 for (int i = 0; i < matSize; i++)
416 for (int j = 0; j < matSize; j++) {
417 _truth[(i * matSize + j) * 3 + 0] = i;
418 _truth[(i * matSize + j) * 3 + 1] = j;
419 _truth[(i * matSize + j) * 3 + 2] = i - j;
422 truth.put(0, 0, _truth);
424 assertMatEqual(truth, _3dPoints, EPS);
427 public void testReprojectImageTo3DMatMatMatBooleanInt() {
428 Mat transformMatrix = new Mat(4, 4, CvType.CV_64F);
429 transformMatrix.put(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
431 Mat disparity = new Mat(matSize, matSize, CvType.CV_32F);
433 float[] disp = new float[matSize * matSize];
434 for (int i = 0; i < matSize; i++)
435 for (int j = 0; j < matSize; j++)
436 disp[i * matSize + j] = i - j;
437 disparity.put(0, 0, disp);
439 Mat _3dPoints = new Mat();
441 Calib3d.reprojectImageTo3D(disparity, _3dPoints, transformMatrix, false, CvType.CV_16S);
443 assertEquals(CvType.CV_16SC3, _3dPoints.type());
444 assertEquals(matSize, _3dPoints.rows());
445 assertEquals(matSize, _3dPoints.cols());
447 truth = new Mat(matSize, matSize, CvType.CV_16SC3);
449 short[] _truth = new short[matSize * matSize * 3];
450 for (short i = 0; i < matSize; i++)
451 for (short j = 0; j < matSize; j++) {
452 _truth[(i * matSize + j) * 3 + 0] = i;
453 _truth[(i * matSize + j) * 3 + 1] = j;
454 _truth[(i * matSize + j) * 3 + 2] = (short) (i - j);
456 truth.put(0, 0, _truth);
458 assertMatEqual(truth, _3dPoints, EPS);
461 public void testRodriguesMatMat() {
462 Mat r = new Mat(3, 1, CvType.CV_32F);
463 Mat R = new Mat(3, 3, CvType.CV_32F);
465 r.put(0, 0, Math.PI, 0, 0);
467 Calib3d.Rodrigues(r, R);
469 truth = new Mat(3, 3, CvType.CV_32F);
470 truth.put(0, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1);
471 assertMatEqual(truth, R, EPS);
474 Calib3d.Rodrigues(R, r2);
476 assertMatEqual(r, r2, EPS);
479 public void testRodriguesMatMatMat() {
480 fail("Not yet implemented");
483 public void testRQDecomp3x3MatMatMat() {
484 fail("Not yet implemented");
487 public void testRQDecomp3x3MatMatMatMat() {
488 fail("Not yet implemented");
491 public void testRQDecomp3x3MatMatMatMatMat() {
492 fail("Not yet implemented");
495 public void testRQDecomp3x3MatMatMatMatMatMat() {
496 fail("Not yet implemented");
499 public void testSolvePnPListOfPoint3ListOfPointMatMatMatMat() {
500 Mat intrinsics = Mat.eye(3, 3, CvType.CV_32F);
501 intrinsics.put(0, 0, 400);
502 intrinsics.put(1, 1, 400);
503 intrinsics.put(0, 2, 640 / 2);
504 intrinsics.put(1, 2, 480 / 2);
506 final int minPnpPointsNum = 4;
508 MatOfPoint3f points3d = new MatOfPoint3f();
509 points3d.alloc(minPnpPointsNum);
510 MatOfPoint2f points2d = new MatOfPoint2f();
511 points2d.alloc(minPnpPointsNum);
513 for (int i = 0; i < minPnpPointsNum; i++) {
514 double x = Math.random() * 100 - 50;
515 double y = Math.random() * 100 - 50;
516 points2d.put(i, 0, x, y); //add(new Point(x, y));
517 points3d.put(i, 0, 0, y, x); // add(new Point3(0, y, x));
520 Mat rvec = new Mat();
521 Mat tvec = new Mat();
522 Calib3d.solvePnP(points3d, points2d, intrinsics, new MatOfDouble(), rvec, tvec);
524 Mat truth_rvec = new Mat(3, 1, CvType.CV_64F);
525 truth_rvec.put(0, 0, 0, Math.PI / 2, 0);
527 Mat truth_tvec = new Mat(3, 1, CvType.CV_64F);
528 truth_tvec.put(0, 0, -320, -240, 400);
530 assertMatEqual(truth_rvec, rvec, EPS);
531 assertMatEqual(truth_tvec, tvec, EPS);
534 public void testSolvePnPListOfPoint3ListOfPointMatMatMatMatBoolean() {
535 fail("Not yet implemented");
538 public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMat() {
539 fail("Not yet implemented");
542 public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBoolean() {
543 fail("Not yet implemented");
546 public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanInt() {
547 fail("Not yet implemented");
550 public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloat() {
551 fail("Not yet implemented");
554 public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloatInt() {
555 fail("Not yet implemented");
558 public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloatIntMat() {
559 fail("Not yet implemented");
562 public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMat() {
563 fail("Not yet implemented");
566 public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMatTermCriteria() {
567 fail("Not yet implemented");
570 public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMatTermCriteriaInt() {
571 fail("Not yet implemented");
574 public void testStereoRectifyUncalibratedMatMatMatSizeMatMat() {
575 fail("Not yet implemented");
578 public void testStereoRectifyUncalibratedMatMatMatSizeMatMatDouble() {
579 fail("Not yet implemented");
582 public void testValidateDisparityMatMatIntInt() {
583 fail("Not yet implemented");
586 public void testValidateDisparityMatMatIntIntInt() {
587 fail("Not yet implemented");
590 public void testComputeCorrespondEpilines()
592 Mat fundamental = new Mat(3, 3, CvType.CV_64F);
593 fundamental.put(0, 0, 0, -0.577, 0.288, 0.577, 0, 0.288, -0.288, -0.288, 0);
594 MatOfPoint2f left = new MatOfPoint2f();
596 left.put(0, 0, 2, 3); //add(new Point(x, y));
597 Mat lines = new Mat();
598 Mat truth = new Mat(1, 1, CvType.CV_32FC3);
599 truth.put(0, 0, -0.70735186, 0.70686162, -0.70588124);
600 Calib3d.computeCorrespondEpilines(left, 1, fundamental, lines);
601 assertMatEqual(truth, lines, EPS);