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