Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/calib3d/misc/java/test/Calib3dTest.java
16363 views
1
package org.opencv.test.calib3d;
2
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;
15
16
public class Calib3dTest extends OpenCVTestCase {
17
18
Size size;
19
20
@Override
21
protected void setUp() throws Exception {
22
super.setUp();
23
24
size = new Size(3, 3);
25
}
26
27
public void testCalibrateCameraListOfMatListOfMatSizeMatMatListOfMatListOfMat() {
28
fail("Not yet implemented");
29
}
30
31
public void testCalibrateCameraListOfMatListOfMatSizeMatMatListOfMatListOfMatInt() {
32
fail("Not yet implemented");
33
}
34
35
public void testCalibrationMatrixValues() {
36
fail("Not yet implemented");
37
}
38
39
public void testComposeRTMatMatMatMatMatMat() {
40
Mat rvec1 = new Mat(3, 1, CvType.CV_32F);
41
rvec1.put(0, 0, 0.5302828, 0.19925919, 0.40105945);
42
Mat tvec1 = new Mat(3, 1, CvType.CV_32F);
43
tvec1.put(0, 0, 0.81438506, 0.43713298, 0.2487897);
44
Mat rvec2 = new Mat(3, 1, CvType.CV_32F);
45
rvec2.put(0, 0, 0.77310503, 0.76209372, 0.30779448);
46
Mat tvec2 = new Mat(3, 1, CvType.CV_32F);
47
tvec2.put(0, 0, 0.70243168, 0.4784472, 0.79219002);
48
49
Mat rvec3 = new Mat();
50
Mat tvec3 = new Mat();
51
52
Mat outRvec = new Mat(3, 1, CvType.CV_32F);
53
outRvec.put(0, 0, 1.418641, 0.88665926, 0.56020796);
54
Mat outTvec = new Mat(3, 1, CvType.CV_32F);
55
outTvec.put(0, 0, 1.4560841, 1.0680628, 0.81598103);
56
57
Calib3d.composeRT(rvec1, tvec1, rvec2, tvec2, rvec3, tvec3);
58
59
assertMatEqual(outRvec, rvec3, EPS);
60
assertMatEqual(outTvec, tvec3, EPS);
61
}
62
63
public void testComposeRTMatMatMatMatMatMatMat() {
64
fail("Not yet implemented");
65
}
66
67
public void testComposeRTMatMatMatMatMatMatMatMat() {
68
fail("Not yet implemented");
69
}
70
71
public void testComposeRTMatMatMatMatMatMatMatMatMat() {
72
fail("Not yet implemented");
73
}
74
75
public void testComposeRTMatMatMatMatMatMatMatMatMatMat() {
76
fail("Not yet implemented");
77
}
78
79
public void testComposeRTMatMatMatMatMatMatMatMatMatMatMat() {
80
fail("Not yet implemented");
81
}
82
83
public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMat() {
84
fail("Not yet implemented");
85
}
86
87
public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMatMat() {
88
fail("Not yet implemented");
89
}
90
91
public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMatMatMat() {
92
fail("Not yet implemented");
93
// Mat dr3dr1;
94
// Mat dr3dt1;
95
// Mat dr3dr2;
96
// Mat dr3dt2;
97
// Mat dt3dr1;
98
// Mat dt3dt1;
99
// Mat dt3dr2;
100
// Mat dt3dt2;
101
// , dr3dr1, dr3dt1, dr3dr2, dr3dt2, dt3dr1, dt3dt1, dt3dr2, dt3dt2);
102
// [0.97031879, -0.091774099, 0.38594806;
103
// 0.15181915, 0.98091727, -0.44186208;
104
// -0.39509675, 0.43839464, 0.93872648]
105
// [0, 0, 0;
106
// 0, 0, 0;
107
// 0, 0, 0]
108
// [1.0117353, 0.16348237, -0.083180845;
109
// -0.1980398, 1.006078, 0.30299222;
110
// 0.075766489, -0.32784501, 1.0163091]
111
// [0, 0, 0;
112
// 0, 0, 0;
113
// 0, 0, 0]
114
// [0, 0, 0;
115
// 0, 0, 0;
116
// 0, 0, 0]
117
// [0.69658804, 0.018115902, 0.7172426;
118
// 0.51114357, 0.68899536, -0.51382649;
119
// -0.50348526, 0.72453934, 0.47068608]
120
// [0.18536358, -0.20515044, -0.48834875;
121
// -0.25120571, 0.29043972, 0.60573936;
122
// 0.35370794, -0.69923931, 0.45781645]
123
// [1, 0, 0;
124
// 0, 1, 0;
125
// 0, 0, 1]
126
}
127
128
public void testConvertPointsFromHomogeneous() {
129
fail("Not yet implemented");
130
}
131
132
public void testConvertPointsToHomogeneous() {
133
fail("Not yet implemented");
134
}
135
136
public void testDecomposeProjectionMatrixMatMatMatMat() {
137
fail("Not yet implemented");
138
}
139
140
public void testDecomposeProjectionMatrixMatMatMatMatMat() {
141
fail("Not yet implemented");
142
}
143
144
public void testDecomposeProjectionMatrixMatMatMatMatMatMat() {
145
fail("Not yet implemented");
146
}
147
148
public void testDecomposeProjectionMatrixMatMatMatMatMatMatMat() {
149
fail("Not yet implemented");
150
}
151
152
public void testDecomposeProjectionMatrixMatMatMatMatMatMatMatMat() {
153
fail("Not yet implemented");
154
}
155
156
public void testDrawChessboardCorners() {
157
fail("Not yet implemented");
158
}
159
160
public void testEstimateAffine3DMatMatMatMat() {
161
fail("Not yet implemented");
162
}
163
164
public void testEstimateAffine3DMatMatMatMatDouble() {
165
fail("Not yet implemented");
166
}
167
168
public void testEstimateAffine3DMatMatMatMatDoubleDouble() {
169
fail("Not yet implemented");
170
}
171
172
public void testFilterSpecklesMatDoubleIntDouble() {
173
gray_16s_1024.copyTo(dst);
174
Point center = new Point(gray_16s_1024.rows() / 2., gray_16s_1024.cols() / 2.);
175
Imgproc.circle(dst, center, 1, Scalar.all(4096));
176
177
assertMatNotEqual(gray_16s_1024, dst);
178
Calib3d.filterSpeckles(dst, 1024.0, 100, 0.);
179
assertMatEqual(gray_16s_1024, dst);
180
}
181
182
public void testFilterSpecklesMatDoubleIntDoubleMat() {
183
fail("Not yet implemented");
184
}
185
186
public void testFindChessboardCornersMatSizeMat() {
187
Size patternSize = new Size(9, 6);
188
MatOfPoint2f corners = new MatOfPoint2f();
189
Calib3d.findChessboardCorners(grayChess, patternSize, corners);
190
assertTrue(!corners.empty());
191
}
192
193
public void testFindChessboardCornersMatSizeMatInt() {
194
Size patternSize = new Size(9, 6);
195
MatOfPoint2f corners = new MatOfPoint2f();
196
Calib3d.findChessboardCorners(grayChess, patternSize, corners, Calib3d.CALIB_CB_ADAPTIVE_THRESH + Calib3d.CALIB_CB_NORMALIZE_IMAGE
197
+ Calib3d.CALIB_CB_FAST_CHECK);
198
assertTrue(!corners.empty());
199
}
200
201
public void testFindCirclesGridMatSizeMat() {
202
int size = 300;
203
Mat img = new Mat(size, size, CvType.CV_8U);
204
img.setTo(new Scalar(255));
205
Mat centers = new Mat();
206
207
assertFalse(Calib3d.findCirclesGrid(img, new Size(5, 5), centers));
208
209
for (int i = 0; i < 5; i++)
210
for (int j = 0; j < 5; j++) {
211
Point pt = new Point(size * (2 * i + 1) / 10, size * (2 * j + 1) / 10);
212
Imgproc.circle(img, pt, 10, new Scalar(0), -1);
213
}
214
215
assertTrue(Calib3d.findCirclesGrid(img, new Size(5, 5), centers));
216
217
assertEquals(25, centers.rows());
218
assertEquals(1, centers.cols());
219
assertEquals(CvType.CV_32FC2, centers.type());
220
}
221
222
public void testFindCirclesGridMatSizeMatInt() {
223
int size = 300;
224
Mat img = new Mat(size, size, CvType.CV_8U);
225
img.setTo(new Scalar(255));
226
Mat centers = new Mat();
227
228
assertFalse(Calib3d.findCirclesGrid(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING
229
| Calib3d.CALIB_CB_ASYMMETRIC_GRID));
230
231
int step = size * 2 / 15;
232
int offsetx = size / 6;
233
int offsety = (size - 4 * step) / 2;
234
for (int i = 0; i < 3; i++)
235
for (int j = 0; j < 5; j++) {
236
Point pt = new Point(offsetx + (2 * i + j % 2) * step, offsety + step * j);
237
Imgproc.circle(img, pt, 10, new Scalar(0), -1);
238
}
239
240
assertTrue(Calib3d.findCirclesGrid(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING
241
| Calib3d.CALIB_CB_ASYMMETRIC_GRID));
242
243
assertEquals(15, centers.rows());
244
assertEquals(1, centers.cols());
245
assertEquals(CvType.CV_32FC2, centers.type());
246
}
247
248
public void testFindFundamentalMatListOfPointListOfPoint() {
249
fail("Not yet implemented");
250
/*
251
int minFundamentalMatPoints = 8;
252
253
MatOfPoint2f pts = new MatOfPoint2f();
254
pts.alloc(minFundamentalMatPoints);
255
256
for (int i = 0; i < minFundamentalMatPoints; i++) {
257
double x = Math.random() * 100 - 50;
258
double y = Math.random() * 100 - 50;
259
pts.put(i, 0, x, y); //add(new Point(x, y));
260
}
261
262
Mat fm = Calib3d.findFundamentalMat(pts, pts);
263
264
truth = new Mat(3, 3, CvType.CV_64F);
265
truth.put(0, 0, 0, -0.577, 0.288, 0.577, 0, 0.288, -0.288, -0.288, 0);
266
assertMatEqual(truth, fm, EPS);
267
*/
268
}
269
270
public void testFindFundamentalMatListOfPointListOfPointInt() {
271
fail("Not yet implemented");
272
}
273
274
public void testFindFundamentalMatListOfPointListOfPointIntDouble() {
275
fail("Not yet implemented");
276
}
277
278
public void testFindFundamentalMatListOfPointListOfPointIntDoubleDouble() {
279
fail("Not yet implemented");
280
}
281
282
public void testFindFundamentalMatListOfPointListOfPointIntDoubleDoubleMat() {
283
fail("Not yet implemented");
284
}
285
286
public void testFindHomographyListOfPointListOfPoint() {
287
final int NUM = 20;
288
289
MatOfPoint2f originalPoints = new MatOfPoint2f();
290
originalPoints.alloc(NUM);
291
MatOfPoint2f transformedPoints = new MatOfPoint2f();
292
transformedPoints.alloc(NUM);
293
294
for (int i = 0; i < NUM; i++) {
295
double x = Math.random() * 100 - 50;
296
double y = Math.random() * 100 - 50;
297
originalPoints.put(i, 0, x, y);
298
transformedPoints.put(i, 0, y, x);
299
}
300
301
Mat hmg = Calib3d.findHomography(originalPoints, transformedPoints);
302
303
truth = new Mat(3, 3, CvType.CV_64F);
304
truth.put(0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1);
305
306
assertMatEqual(truth, hmg, EPS);
307
}
308
309
public void testFindHomographyListOfPointListOfPointInt() {
310
fail("Not yet implemented");
311
}
312
313
public void testFindHomographyListOfPointListOfPointIntDouble() {
314
fail("Not yet implemented");
315
}
316
317
public void testFindHomographyListOfPointListOfPointIntDoubleMat() {
318
fail("Not yet implemented");
319
}
320
321
public void testGetOptimalNewCameraMatrixMatMatSizeDouble() {
322
fail("Not yet implemented");
323
}
324
325
public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSize() {
326
fail("Not yet implemented");
327
}
328
329
public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSizeRect() {
330
fail("Not yet implemented");
331
}
332
333
public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSizeRectBoolean() {
334
fail("Not yet implemented");
335
}
336
337
public void testGetValidDisparityROI() {
338
fail("Not yet implemented");
339
}
340
341
public void testInitCameraMatrix2DListOfMatListOfMatSize() {
342
fail("Not yet implemented");
343
}
344
345
public void testInitCameraMatrix2DListOfMatListOfMatSizeDouble() {
346
fail("Not yet implemented");
347
}
348
349
public void testMatMulDeriv() {
350
fail("Not yet implemented");
351
}
352
353
public void testProjectPointsMatMatMatMatMatMat() {
354
fail("Not yet implemented");
355
}
356
357
public void testProjectPointsMatMatMatMatMatMatMat() {
358
fail("Not yet implemented");
359
}
360
361
public void testProjectPointsMatMatMatMatMatMatMatDouble() {
362
fail("Not yet implemented");
363
}
364
365
public void testRectify3Collinear() {
366
fail("Not yet implemented");
367
}
368
369
public void testReprojectImageTo3DMatMatMat() {
370
Mat transformMatrix = new Mat(4, 4, CvType.CV_64F);
371
transformMatrix.put(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
372
373
Mat disparity = new Mat(matSize, matSize, CvType.CV_32F);
374
375
float[] disp = new float[matSize * matSize];
376
for (int i = 0; i < matSize; i++)
377
for (int j = 0; j < matSize; j++)
378
disp[i * matSize + j] = i - j;
379
disparity.put(0, 0, disp);
380
381
Mat _3dPoints = new Mat();
382
383
Calib3d.reprojectImageTo3D(disparity, _3dPoints, transformMatrix);
384
385
assertEquals(CvType.CV_32FC3, _3dPoints.type());
386
assertEquals(matSize, _3dPoints.rows());
387
assertEquals(matSize, _3dPoints.cols());
388
389
truth = new Mat(matSize, matSize, CvType.CV_32FC3);
390
391
float[] _truth = new float[matSize * matSize * 3];
392
for (int i = 0; i < matSize; i++)
393
for (int j = 0; j < matSize; j++) {
394
_truth[(i * matSize + j) * 3 + 0] = i;
395
_truth[(i * matSize + j) * 3 + 1] = j;
396
_truth[(i * matSize + j) * 3 + 2] = i - j;
397
}
398
truth.put(0, 0, _truth);
399
400
assertMatEqual(truth, _3dPoints, EPS);
401
}
402
403
public void testReprojectImageTo3DMatMatMatBoolean() {
404
Mat transformMatrix = new Mat(4, 4, CvType.CV_64F);
405
transformMatrix.put(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
406
407
Mat disparity = new Mat(matSize, matSize, CvType.CV_32F);
408
409
float[] disp = new float[matSize * matSize];
410
for (int i = 0; i < matSize; i++)
411
for (int j = 0; j < matSize; j++)
412
disp[i * matSize + j] = i - j;
413
disp[0] = -Float.MAX_VALUE;
414
disparity.put(0, 0, disp);
415
416
Mat _3dPoints = new Mat();
417
418
Calib3d.reprojectImageTo3D(disparity, _3dPoints, transformMatrix, true);
419
420
assertEquals(CvType.CV_32FC3, _3dPoints.type());
421
assertEquals(matSize, _3dPoints.rows());
422
assertEquals(matSize, _3dPoints.cols());
423
424
truth = new Mat(matSize, matSize, CvType.CV_32FC3);
425
426
float[] _truth = new float[matSize * matSize * 3];
427
for (int i = 0; i < matSize; i++)
428
for (int j = 0; j < matSize; j++) {
429
_truth[(i * matSize + j) * 3 + 0] = i;
430
_truth[(i * matSize + j) * 3 + 1] = j;
431
_truth[(i * matSize + j) * 3 + 2] = i - j;
432
}
433
_truth[2] = 10000;
434
truth.put(0, 0, _truth);
435
436
assertMatEqual(truth, _3dPoints, EPS);
437
}
438
439
public void testReprojectImageTo3DMatMatMatBooleanInt() {
440
Mat transformMatrix = new Mat(4, 4, CvType.CV_64F);
441
transformMatrix.put(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
442
443
Mat disparity = new Mat(matSize, matSize, CvType.CV_32F);
444
445
float[] disp = new float[matSize * matSize];
446
for (int i = 0; i < matSize; i++)
447
for (int j = 0; j < matSize; j++)
448
disp[i * matSize + j] = i - j;
449
disparity.put(0, 0, disp);
450
451
Mat _3dPoints = new Mat();
452
453
Calib3d.reprojectImageTo3D(disparity, _3dPoints, transformMatrix, false, CvType.CV_16S);
454
455
assertEquals(CvType.CV_16SC3, _3dPoints.type());
456
assertEquals(matSize, _3dPoints.rows());
457
assertEquals(matSize, _3dPoints.cols());
458
459
truth = new Mat(matSize, matSize, CvType.CV_16SC3);
460
461
short[] _truth = new short[matSize * matSize * 3];
462
for (short i = 0; i < matSize; i++)
463
for (short j = 0; j < matSize; j++) {
464
_truth[(i * matSize + j) * 3 + 0] = i;
465
_truth[(i * matSize + j) * 3 + 1] = j;
466
_truth[(i * matSize + j) * 3 + 2] = (short) (i - j);
467
}
468
truth.put(0, 0, _truth);
469
470
assertMatEqual(truth, _3dPoints, EPS);
471
}
472
473
public void testRodriguesMatMat() {
474
Mat r = new Mat(3, 1, CvType.CV_32F);
475
Mat R = new Mat(3, 3, CvType.CV_32F);
476
477
r.put(0, 0, Math.PI, 0, 0);
478
479
Calib3d.Rodrigues(r, R);
480
481
truth = new Mat(3, 3, CvType.CV_32F);
482
truth.put(0, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1);
483
assertMatEqual(truth, R, EPS);
484
485
Mat r2 = new Mat();
486
Calib3d.Rodrigues(R, r2);
487
488
assertMatEqual(r, r2, EPS);
489
}
490
491
public void testRodriguesMatMatMat() {
492
fail("Not yet implemented");
493
}
494
495
public void testRQDecomp3x3MatMatMat() {
496
fail("Not yet implemented");
497
}
498
499
public void testRQDecomp3x3MatMatMatMat() {
500
fail("Not yet implemented");
501
}
502
503
public void testRQDecomp3x3MatMatMatMatMat() {
504
fail("Not yet implemented");
505
}
506
507
public void testRQDecomp3x3MatMatMatMatMatMat() {
508
fail("Not yet implemented");
509
}
510
511
public void testSolvePnPListOfPoint3ListOfPointMatMatMatMat() {
512
Mat intrinsics = Mat.eye(3, 3, CvType.CV_64F);
513
intrinsics.put(0, 0, 400);
514
intrinsics.put(1, 1, 400);
515
intrinsics.put(0, 2, 640 / 2);
516
intrinsics.put(1, 2, 480 / 2);
517
518
final int minPnpPointsNum = 4;
519
520
MatOfPoint3f points3d = new MatOfPoint3f();
521
points3d.alloc(minPnpPointsNum);
522
MatOfPoint2f points2d = new MatOfPoint2f();
523
points2d.alloc(minPnpPointsNum);
524
525
for (int i = 0; i < minPnpPointsNum; i++) {
526
double x = Math.random() * 100 - 50;
527
double y = Math.random() * 100 - 50;
528
points2d.put(i, 0, x, y); //add(new Point(x, y));
529
points3d.put(i, 0, 0, y, x); // add(new Point3(0, y, x));
530
}
531
532
Mat rvec = new Mat();
533
Mat tvec = new Mat();
534
Calib3d.solvePnP(points3d, points2d, intrinsics, new MatOfDouble(), rvec, tvec);
535
536
Mat truth_rvec = new Mat(3, 1, CvType.CV_64F);
537
truth_rvec.put(0, 0, 0, Math.PI / 2, 0);
538
539
Mat truth_tvec = new Mat(3, 1, CvType.CV_64F);
540
truth_tvec.put(0, 0, -320, -240, 400);
541
542
assertMatEqual(truth_rvec, rvec, EPS);
543
assertMatEqual(truth_tvec, tvec, EPS);
544
}
545
546
public void testSolvePnPListOfPoint3ListOfPointMatMatMatMatBoolean() {
547
fail("Not yet implemented");
548
}
549
550
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMat() {
551
fail("Not yet implemented");
552
}
553
554
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBoolean() {
555
fail("Not yet implemented");
556
}
557
558
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanInt() {
559
fail("Not yet implemented");
560
}
561
562
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloat() {
563
fail("Not yet implemented");
564
}
565
566
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloatInt() {
567
fail("Not yet implemented");
568
}
569
570
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloatIntMat() {
571
fail("Not yet implemented");
572
}
573
574
public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMat() {
575
fail("Not yet implemented");
576
}
577
578
public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMatTermCriteria() {
579
fail("Not yet implemented");
580
}
581
582
public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMatTermCriteriaInt() {
583
fail("Not yet implemented");
584
}
585
586
public void testStereoRectifyUncalibratedMatMatMatSizeMatMat() {
587
fail("Not yet implemented");
588
}
589
590
public void testStereoRectifyUncalibratedMatMatMatSizeMatMatDouble() {
591
fail("Not yet implemented");
592
}
593
594
public void testValidateDisparityMatMatIntInt() {
595
fail("Not yet implemented");
596
}
597
598
public void testValidateDisparityMatMatIntIntInt() {
599
fail("Not yet implemented");
600
}
601
602
public void testComputeCorrespondEpilines()
603
{
604
Mat fundamental = new Mat(3, 3, CvType.CV_64F);
605
fundamental.put(0, 0, 0, -0.577, 0.288, 0.577, 0, 0.288, -0.288, -0.288, 0);
606
MatOfPoint2f left = new MatOfPoint2f();
607
left.alloc(1);
608
left.put(0, 0, 2, 3); //add(new Point(x, y));
609
Mat lines = new Mat();
610
Mat truth = new Mat(1, 1, CvType.CV_32FC3);
611
truth.put(0, 0, -0.70735186, 0.70686162, -0.70588124);
612
Calib3d.computeCorrespondEpilines(left, 1, fundamental, lines);
613
assertMatEqual(truth, lines, EPS);
614
}
615
616
public void testGetDefaultNewCameraMatrixMat() {
617
Mat mtx = Calib3d.getDefaultNewCameraMatrix(gray0);
618
619
assertFalse(mtx.empty());
620
assertEquals(0, Core.countNonZero(mtx));
621
}
622
623
public void testGetDefaultNewCameraMatrixMatSizeBoolean() {
624
Mat mtx = Calib3d.getDefaultNewCameraMatrix(gray0, size, true);
625
626
assertFalse(mtx.empty());
627
assertFalse(0 == Core.countNonZero(mtx));
628
// TODO_: write better test
629
}
630
631
public void testInitUndistortRectifyMap() {
632
fail("Not yet implemented");
633
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
634
cameraMatrix.put(0, 0, 1, 0, 1);
635
cameraMatrix.put(1, 0, 0, 1, 1);
636
cameraMatrix.put(2, 0, 0, 0, 1);
637
638
Mat R = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
639
Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
640
641
Mat distCoeffs = new Mat();
642
Mat map1 = new Mat();
643
Mat map2 = new Mat();
644
645
// TODO: complete this test
646
Calib3d.initUndistortRectifyMap(cameraMatrix, distCoeffs, R, newCameraMatrix, size, CvType.CV_32F, map1, map2);
647
}
648
649
public void testInitWideAngleProjMapMatMatSizeIntIntMatMat() {
650
fail("Not yet implemented");
651
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
652
Mat distCoeffs = new Mat(1, 4, CvType.CV_32F);
653
// Size imageSize = new Size(2, 2);
654
655
cameraMatrix.put(0, 0, 1, 0, 1);
656
cameraMatrix.put(1, 0, 0, 1, 2);
657
cameraMatrix.put(2, 0, 0, 0, 1);
658
659
distCoeffs.put(0, 0, 1, 3, 2, 4);
660
truth = new Mat(3, 3, CvType.CV_32F);
661
truth.put(0, 0, 0, 0, 0);
662
truth.put(1, 0, 0, 0, 0);
663
truth.put(2, 0, 0, 3, 0);
664
// TODO: No documentation for this function
665
// Calib3d.initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize,
666
// 5, m1type, truthput1, truthput2);
667
}
668
669
public void testInitWideAngleProjMapMatMatSizeIntIntMatMatInt() {
670
fail("Not yet implemented");
671
}
672
673
public void testInitWideAngleProjMapMatMatSizeIntIntMatMatIntDouble() {
674
fail("Not yet implemented");
675
}
676
677
public void testUndistortMatMatMatMat() {
678
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
679
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
680
{
681
put(0, 0, 1, 0, 1);
682
put(1, 0, 0, 1, 2);
683
put(2, 0, 0, 0, 1);
684
}
685
};
686
Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
687
{
688
put(0, 0, 1, 3, 2, 4);
689
}
690
};
691
692
Calib3d.undistort(src, dst, cameraMatrix, distCoeffs);
693
694
truth = new Mat(3, 3, CvType.CV_32F) {
695
{
696
put(0, 0, 0, 0, 0);
697
put(1, 0, 0, 0, 0);
698
put(2, 0, 0, 3, 0);
699
}
700
};
701
assertMatEqual(truth, dst, EPS);
702
}
703
704
public void testUndistortMatMatMatMatMat() {
705
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
706
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
707
{
708
put(0, 0, 1, 0, 1);
709
put(1, 0, 0, 1, 2);
710
put(2, 0, 0, 0, 1);
711
}
712
};
713
Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
714
{
715
put(0, 0, 2, 1, 4, 5);
716
}
717
};
718
Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(1));
719
720
Calib3d.undistort(src, dst, cameraMatrix, distCoeffs, newCameraMatrix);
721
722
truth = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
723
assertMatEqual(truth, dst, EPS);
724
}
725
726
//undistortPoints(List<Point> src, List<Point> dst, Mat cameraMatrix, Mat distCoeffs)
727
public void testUndistortPointsListOfPointListOfPointMatMat() {
728
MatOfPoint2f src = new MatOfPoint2f(new Point(1, 2), new Point(3, 4), new Point(-1, -1));
729
MatOfPoint2f dst = new MatOfPoint2f();
730
Mat cameraMatrix = Mat.eye(3, 3, CvType.CV_64FC1);
731
Mat distCoeffs = new Mat(8, 1, CvType.CV_64FC1, new Scalar(0));
732
733
Calib3d.undistortPoints(src, dst, cameraMatrix, distCoeffs);
734
735
assertEquals(src.size(), dst.size());
736
for(int i=0; i<src.toList().size(); i++) {
737
//Log.d("UndistortPoints", "s="+src.get(i)+", d="+dst.get(i));
738
assertTrue(src.toList().get(i).equals(dst.toList().get(i)));
739
}
740
}
741
742
}
743
744