Fixed java tests build
[profile/ivi/opencv.git] / modules / java / android_test / src / org / opencv / test / core / CoreTest.java
1 package org.opencv.test.core;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.List;
6
7 import org.opencv.core.Core;
8 import org.opencv.core.Core.MinMaxLocResult;
9 import org.opencv.core.CvException;
10 import org.opencv.core.CvType;
11 import org.opencv.core.Mat;
12 import org.opencv.core.MatOfDouble;
13 import org.opencv.core.MatOfInt;
14 import org.opencv.core.MatOfPoint;
15 import org.opencv.core.Point;
16 import org.opencv.core.Rect;
17 import org.opencv.core.RotatedRect;
18 import org.opencv.core.Scalar;
19 import org.opencv.core.Size;
20 import org.opencv.core.TermCriteria;
21 import org.opencv.test.OpenCVTestCase;
22 import org.opencv.imgproc.Imgproc;
23
24 public class CoreTest extends OpenCVTestCase {
25
26     public void testAbsdiff() {
27         Core.absdiff(gray128, gray255, dst);
28
29         assertMatEqual(gray127, dst);
30     }
31
32     public void testAddMatMatMat() {
33         Core.add(gray128, gray128, dst);
34
35         assertMatEqual(gray255, dst);
36     }
37
38     public void testAddMatMatMatMatInt() {
39         Core.add(gray0, gray1, dst, gray1, CvType.CV_32F);
40
41         assertEquals(CvType.CV_32F, dst.depth());
42         assertMatEqual(gray1_32f, dst, EPS);
43     }
44
45     public void testAddWeightedMatDoubleMatDoubleDoubleMat() {
46         Core.addWeighted(gray1, 120.0, gray127, 1.0, 10.0, dst);
47
48         assertMatEqual(gray255, dst);
49     }
50
51     public void testAddWeightedMatDoubleMatDoubleDoubleMatInt() {
52         Core.addWeighted(gray1, 126.0, gray127, 1.0, 2.0, dst, CvType.CV_32F);
53
54         assertEquals(CvType.CV_32F, dst.depth());
55         assertMatEqual(gray255_32f, dst, EPS);
56     }
57
58     public void testBitwise_andMatMatMat() {
59         Core.bitwise_and(gray127, gray3, dst);
60
61         assertMatEqual(gray3, dst);
62     }
63
64     public void testBitwise_andMatMatMatMat() {
65         Core.bitwise_and(gray3, gray1, dst, gray255);
66
67         assertMatEqual(gray1, dst);
68     }
69
70     public void testBitwise_notMatMat() {
71         Core.bitwise_not(gray255, dst);
72
73         assertMatEqual(gray0, dst);
74     }
75
76     public void testBitwise_notMatMatMat() {
77         Core.bitwise_not(gray0, dst, gray1);
78
79         assertMatEqual(gray255, dst);
80     }
81
82     public void testBitwise_orMatMatMat() {
83         Core.bitwise_or(gray1, gray2, dst);
84
85         assertMatEqual(gray3, dst);
86     }
87
88     public void testBitwise_orMatMatMatMat() {
89         Core.bitwise_or(gray127, gray3, dst, gray255);
90
91         assertMatEqual(gray127, dst);
92     }
93
94     public void testBitwise_xorMatMatMat() {
95         Core.bitwise_xor(gray3, gray2, dst);
96
97         assertMatEqual(gray1, dst);
98     }
99
100     public void testBitwise_xorMatMatMatMat() {
101         Core.bitwise_or(gray127, gray128, dst, gray255);
102
103         assertMatEqual(gray255, dst);
104     }
105
106     public void testCalcCovarMatrixMatMatMatInt() {
107         Mat covar = new Mat(matSize, matSize, CvType.CV_64FC1);
108         Mat mean = new Mat(1, matSize, CvType.CV_64FC1);
109
110         Core.calcCovarMatrix(gray0_32f, covar, mean, Core.COVAR_ROWS | Core.COVAR_NORMAL);
111
112         assertMatEqual(gray0_64f, covar, EPS);
113         assertMatEqual(gray0_64f_1d, mean, EPS);
114     }
115
116     public void testCalcCovarMatrixMatMatMatIntInt() {
117         Mat covar = new Mat(matSize, matSize, CvType.CV_32F);
118         Mat mean = new Mat(1, matSize, CvType.CV_32F);
119
120         Core.calcCovarMatrix(gray0_32f, covar, mean, Core.COVAR_ROWS | Core.COVAR_NORMAL, CvType.CV_32F);
121
122         assertMatEqual(gray0_32f, covar, EPS);
123         assertMatEqual(gray0_32f_1d, mean, EPS);
124     }
125
126     public void testCartToPolarMatMatMatMat() {
127         Mat x = new Mat(1, 3, CvType.CV_32F) {
128             {
129                 put(0, 0, 3.0, 6.0, 5, 0);
130             }
131         };
132         Mat y = new Mat(1, 3, CvType.CV_32F) {
133             {
134                 put(0, 0, 4.0, 8.0, 12.0);
135             }
136         };
137         Mat dst_angle = new Mat();
138
139         Core.cartToPolar(x, y, dst, dst_angle);
140
141         Mat expected_magnitude = new Mat(1, 3, CvType.CV_32F) {
142             {
143                 put(0, 0, 5.0, 10.0, 13.0);
144             }
145         };
146         Mat expected_angle = new Mat(1, 3, CvType.CV_32F) {
147             {
148                 put(0, 0, atan2rad(4,3), atan2rad(8,6), atan2rad(12,5));
149             }
150         };
151         assertMatEqual(expected_magnitude, dst, EPS);
152         assertMatEqual(expected_angle, dst_angle, EPS);
153     }
154
155     public void testCartToPolarMatMatMatMatBoolean() {
156         Mat x = new Mat(1, 3, CvType.CV_32F) {
157             {
158                 put(0, 0, 3.0, 6.0, 5, 0);
159             }
160         };
161         Mat y = new Mat(1, 3, CvType.CV_32F) {
162             {
163                 put(0, 0, 4.0, 8.0, 12.0);
164             }
165         };
166         Mat dst_angle = new Mat();
167
168         Core.cartToPolar(x, y, dst, dst_angle, true);
169
170         Mat expected_magnitude = new Mat(1, 3, CvType.CV_32F) {
171             {
172                 put(0, 0, 5.0, 10.0, 13.0);
173             }
174         };
175         Mat expected_angle = new Mat(1, 3, CvType.CV_32F) {
176             {
177                 put(0, 0, atan2deg(4,3), atan2deg(8,6), atan2deg(12,5));
178             }
179         };
180         assertMatEqual(expected_magnitude, dst, EPS);
181         assertMatEqual(expected_angle, dst_angle, EPS * 180/Math.PI);
182     }
183
184
185     public void testCheckRangeMat() {
186         Mat outOfRange = new Mat(2, 2, CvType.CV_64F);
187         outOfRange.put(0, 0, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 0);
188
189         assertTrue(Core.checkRange(grayRnd_32f));
190         assertTrue(Core.checkRange(new Mat()));
191         assertFalse(Core.checkRange(outOfRange));
192     }
193
194
195     public void testCheckRangeMatBooleanPointDoubleDouble() {
196         Mat inRange = new Mat(2, 3, CvType.CV_64F) {
197             {
198                 put(0, 0, 14, 48, 76, 33, 5, 99);
199             }
200         };
201
202         assertTrue(Core.checkRange(inRange, true, 5, 100));
203
204         Mat outOfRange = new Mat(2, 3, CvType.CV_64F) {
205             {
206                 put(0, 0, -4, 0, 6, 33, 4, 109);
207             }
208         };
209
210         assertFalse(Core.checkRange(outOfRange, true, 5, 100));
211     }
212
213     public void testCompare() {
214         Core.compare(gray0, gray0, dst, Core.CMP_EQ);
215
216         assertMatEqual(dst, gray255);
217
218         Core.compare(gray0, gray1, dst, Core.CMP_EQ);
219
220         assertMatEqual(dst, gray0);
221
222         grayRnd.put(0, 0, 0, 0);
223
224         Core.compare(gray0, grayRnd, dst, Core.CMP_GE);
225
226         int expected = (int) (grayRnd.total() - Core.countNonZero(grayRnd));
227         assertEquals(expected, Core.countNonZero(dst));
228     }
229
230     public void testCompleteSymmMat() {
231         Core.completeSymm(grayRnd_32f);
232
233         assertMatEqual(grayRnd_32f, grayRnd_32f.t(), EPS);
234     }
235
236     public void testCompleteSymmMatBoolean() {
237         Mat grayRnd_32f2 = grayRnd_32f.clone();
238
239         Core.completeSymm(grayRnd_32f, true);
240
241         assertMatEqual(grayRnd_32f, grayRnd_32f.t(), EPS);
242         Core.completeSymm(grayRnd_32f2, false);
243         assertMatNotEqual(grayRnd_32f2, grayRnd_32f, EPS);
244     }
245
246     public void testConvertScaleAbsMatMat() {
247         Core.convertScaleAbs(gray0, dst);
248
249         assertMatEqual(gray0, dst, EPS);
250
251         Core.convertScaleAbs(gray_16u_256, dst);
252
253         assertMatEqual(gray255, dst, EPS);
254     }
255
256     public void testConvertScaleAbsMatMatDoubleDouble() {
257         Core.convertScaleAbs(gray_16u_256, dst, 2, -513);
258
259         assertMatEqual(gray1, dst);
260     }
261
262     public void testCountNonZero() {
263         assertEquals(0, Core.countNonZero(gray0));
264
265         gray0.put(0, 0, 255);
266         gray0.put(gray0.rows() - 1, gray0.cols() - 1, 255);
267
268         assertEquals(2, Core.countNonZero(gray0));
269     }
270
271     public void testCubeRoot() {
272         float res = Core.cubeRoot(-27.0f);
273
274         assertEquals(-3.0f, res);
275     }
276
277     public void testDctMatMat() {
278         Mat in = new Mat(1, 4, CvType.CV_32F) {
279             {
280                 put(0, 0, 135.22211, 50.811096, 102.27016, 207.6682);
281             }
282         };
283         Mat dst1 = new Mat();
284         Mat dst2 = new Mat();
285
286         Core.dct(gray0_32f_1d, dst1);
287         Core.dct(in, dst2);
288
289         truth = new Mat(1, 4, CvType.CV_32F) {
290             {
291                 put(0, 0, 247.98576, -61.252407, 94.904533, 14.013477);
292             }
293         };
294         assertMatEqual(gray0_32f_1d, dst1, EPS);
295         assertMatEqual(truth, dst2, EPS);
296     }
297
298     public void testDctMatMatInt() {
299         Mat in = new Mat(1, 4, CvType.CV_32F) {
300             {
301                 put(0, 0, 247.98576, -61.252407, 94.904533, 14.013477);
302             }
303         };
304         Mat dst1 = new Mat();
305         Mat dst2 = new Mat();
306
307         Core.dct(gray0_32f_1d, dst1, Core.DCT_INVERSE);
308         Core.dct(in, dst2, Core.DCT_INVERSE);
309
310         truth = new Mat(1, 4, CvType.CV_32F) {
311             {
312                 put(0, 0, 135.22211, 50.811096, 102.27016, 207.6682);
313             }
314         };
315         assertMatEqual(gray0_32f_1d, dst1, EPS);
316         assertMatEqual(truth, dst2, EPS);
317     }
318
319     public void testDeterminant() {
320         Mat mat = new Mat(2, 2, CvType.CV_32F) {
321             {
322                 put(0, 0, 4.0);
323                 put(0, 1, 2.0);
324                 put(1, 0, 4.0);
325                 put(1, 1, 4.0);
326             }
327         };
328
329         double det = Core.determinant(mat);
330
331         assertEquals(8.0, det);
332     }
333
334     public void testDftMatMat() {
335         Core.dft(gray0_32f_1d, dst);
336
337         assertMatEqual(gray0_32f_1d, dst, EPS);
338     }
339
340     public void testDftMatMatIntInt() {
341         Mat src1 = new Mat(2, 4, CvType.CV_32F) {
342             {
343                 put(0, 0, 1, 2, 3, 4);
344                 put(1, 0, 1, 1, 1, 1);
345             }
346         };
347         Mat src2 = new Mat(2, 4, CvType.CV_32F) {
348             {
349                 put(0, 0, 1, 2, 3, 4);
350                 put(1, 0, 0, 0, 0, 0);
351             }
352         };
353         Mat dst1 = new Mat();
354         Mat dst2 = new Mat();
355
356         Core.dft(src1, dst1, Core.DFT_REAL_OUTPUT, 1);
357         Core.dft(src2, dst2, Core.DFT_REAL_OUTPUT, 0);
358
359         assertMatEqual(dst2, dst1, EPS);
360     }
361
362     public void testDivideDoubleMatMat() {
363         Core.divide(4.0, gray2, dst);
364
365         assertMatEqual(gray2, dst);
366
367         Core.divide(4.0, gray0, dst);
368
369         assertMatEqual(gray0, dst);
370     }
371
372     public void testDivideDoubleMatMatInt() {
373         Core.divide(9.0, gray3, dst, CvType.CV_32F);
374
375         assertMatEqual(gray3_32f, dst, EPS);
376     }
377
378     public void testDivideMatMatMat() {
379         Core.divide(gray9, gray3, dst);
380
381         assertMatEqual(gray3, dst);
382     }
383
384     public void testDivideMatMatMatDouble() {
385         Core.divide(gray1, gray2, dst, 6.0);
386
387         assertMatEqual(gray3, dst);
388     }
389
390     public void testDivideMatMatMatDoubleInt() {
391         Core.divide(gray1, gray2, dst, 6.0, CvType.CV_32F);
392
393         assertMatEqual(gray3_32f, dst, EPS);
394     }
395
396     public void testEigen() {
397         Mat src = new Mat(3, 3, CvType.CV_32FC1, new Scalar(2.0));
398         Mat eigenVals = new Mat();
399         Mat eigenVecs = new Mat();
400
401         Core.eigen(src, eigenVals, eigenVecs);
402
403         Mat expectedEigenVals = new Mat(3, 1, CvType.CV_32FC1) {
404             {
405                 put(0, 0, 6, 0, 0);
406             }
407         };
408         Mat expectedEigenVecs = new Mat(3, 3, CvType.CV_32FC1) {
409             {
410                 put(0, 0, 0.57735026, 0.57735026, 0.57735032);
411                 put(1, 0, 0.70710677, -0.70710677, 0);
412                 put(2, 0, -0.40824831, -0.40824831, 0.81649661);
413             }
414         };
415         assertMatEqual(eigenVals, expectedEigenVals, EPS);
416         assertMatEqual(eigenVecs, expectedEigenVecs, EPS);
417     }
418
419     public void testExp() {
420         Core.exp(gray0_32f, dst);
421
422         assertMatEqual(gray1_32f, dst, EPS);
423     }
424
425     public void testExtractChannel() {
426         Core.extractChannel(rgba128, dst, 0);
427
428         assertMatEqual(gray128, dst);
429     }
430
431     public void testFastAtan2() {
432         double eps = 0.3;
433
434         float res = Core.fastAtan2(50, 50);
435
436         assertEquals(45, res, eps);
437
438         float res2 = Core.fastAtan2(80, 20);
439
440         assertEquals(Math.atan2(80, 20) * 180 / Math.PI, res2, eps);
441     }
442
443     public void testFillConvexPolyMatListOfPointScalar() {
444         MatOfPoint polyline = new MatOfPoint(new Point[]{new Point(1, 1), new Point(5, 0), new Point(6, 8), new Point(0, 9)});
445
446         Imgproc.fillConvexPoly(gray0, polyline, new Scalar(150));
447
448         assertTrue(0 < Core.countNonZero(gray0));
449         assertTrue(gray0.total() > Core.countNonZero(gray0));
450     }
451
452     public void testFillConvexPolyMatListOfPointScalarIntInt() {
453         MatOfPoint polyline1 = new MatOfPoint(new Point(2, 1), new Point(5, 1), new Point(5, 7), new Point(2, 7));
454         MatOfPoint polyline2 = new MatOfPoint(new Point(4, 2), new Point(10, 2), new Point(10, 14), new Point(4, 14));
455
456         // current implementation of fixed-point version of fillConvexPoly
457         // requires image to be at least 2-pixel wider in each direction than
458         // contour
459         Imgproc.fillConvexPoly(gray0, polyline1, colorWhite, Imgproc.LINE_8, 0);
460
461         assertTrue(0 < Core.countNonZero(gray0));
462         assertTrue(gray0.total() > Core.countNonZero(gray0));
463
464         Imgproc.fillConvexPoly(gray0, polyline2, colorBlack, Imgproc.LINE_8, 1);
465
466         assertEquals("see http://code.opencv.org/issues/1284", 0, Core.countNonZero(gray0));
467     }
468
469     public void testFillPolyMatListOfListOfPointScalar() {
470         int matSize = 10;
471         Mat gray0 = Mat.zeros(matSize, matSize, CvType.CV_8U);
472         MatOfPoint polyline = new MatOfPoint(new Point(1, 4), new Point(1, 8), new Point(4, 1), new Point(7, 8), new Point(7, 4));
473         List<MatOfPoint> polylines = new ArrayList<MatOfPoint>();
474         polylines.add(polyline);
475
476         Imgproc.fillPoly(gray0, polylines, new Scalar(1));
477
478         final byte[] truth = new byte[] {
479                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
480                 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
481                 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
482                 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
483                 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,
484                 0, 1, 1, 0, 0, 0, 1, 1, 0, 0,
485                 0, 1, 1, 0, 0, 0, 1, 1, 0, 0,
486                 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
487                 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
488                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
489
490         assertMatEqual(new Mat(gray0.size(), CvType.CV_8U) {
491             {
492                 put(0, 0, truth);
493             }
494         }, gray0);
495     }
496
497     public void testFillPolyMatListOfListOfPointScalarIntIntPoint() {
498         MatOfPoint polyline1 = new MatOfPoint(new Point(1, 4), new Point(1, 8), new Point(4, 1), new Point(7, 8), new Point(7, 4));
499         MatOfPoint polyline2 = new MatOfPoint(new Point(0, 3), new Point(0, 7), new Point(3, 0), new Point(6, 7), new Point(6, 3));
500
501         List<MatOfPoint> polylines1 = new ArrayList<MatOfPoint>();
502         polylines1.add(polyline1);
503
504         List<MatOfPoint> polylines2 = new ArrayList<MatOfPoint>();
505         polylines2.add(polyline2);
506
507         Imgproc.fillPoly(gray0, polylines1, new Scalar(1), Imgproc.LINE_8, 0, new Point(0, 0));
508
509         assertTrue(0 < Core.countNonZero(gray0));
510
511         Imgproc.fillPoly(gray0, polylines2, new Scalar(0), Imgproc.LINE_8, 0, new Point(1, 1));
512
513         assertEquals(0, Core.countNonZero(gray0));
514     }
515
516     public void testFlip() {
517         Mat src = new Mat(2, 2, CvType.CV_32F) {
518             {
519                 put(0, 0, 1.0);
520                 put(0, 1, 2.0);
521                 put(1, 0, 3.0);
522                 put(1, 1, 4.0);
523             }
524         };
525         Mat dst1 = new Mat();
526         Mat dst2 = new Mat();
527
528         Core.flip(src, dst1, 0);
529         Core.flip(src, dst2, 1);
530
531         Mat dst_f1 = new Mat(2, 2, CvType.CV_32F) {
532             {
533                 put(0, 0, 3.0);
534                 put(0, 1, 4.0);
535                 put(1, 0, 1.0);
536                 put(1, 1, 2.0);
537             }
538         };
539         Mat dst_f2 = new Mat(2, 2, CvType.CV_32F) {
540             {
541                 put(0, 0, 2.0);
542                 put(0, 1, 1.0);
543                 put(1, 0, 4.0);
544                 put(1, 1, 3.0);
545             }
546         };
547         assertMatEqual(dst_f1, dst1, EPS);
548         assertMatEqual(dst_f2, dst2, EPS);
549     }
550
551     public void testGemmMatMatDoubleMatDoubleMat() {
552         Mat m1 = new Mat(2, 2, CvType.CV_32FC1) {
553             {
554                 put(0, 0, 1.0, 0.0);
555                 put(1, 0, 1.0, 0.0);
556             }
557         };
558         Mat m2 = new Mat(2, 2, CvType.CV_32FC1) {
559             {
560                 put(0, 0, 1.0, 0.0);
561                 put(1, 0, 1.0, 0.0);
562             }
563         };
564         Mat dmatrix = new Mat(2, 2, CvType.CV_32FC1) {
565             {
566                 put(0, 0, 0.001, 0.001);
567                 put(1, 0, 0.001, 0.001);
568             }
569         };
570
571         Core.gemm(m1, m2, 1.0, dmatrix, 1.0, dst);
572
573         Mat expected = new Mat(2, 2, CvType.CV_32FC1) {
574             {
575                 put(0, 0, 1.001, 0.001);
576                 put(1, 0, 1.001, 0.001);
577             }
578         };
579         assertMatEqual(expected, dst, EPS);
580     }
581
582     public void testGemmMatMatDoubleMatDoubleMatInt() {
583         Mat m1 = new Mat(2, 2, CvType.CV_32FC1) {
584             {
585                 put(0, 0, 1.0, 0.0);
586                 put(1, 0, 1.0, 0.0);
587             }
588         };
589         Mat m2 = new Mat(2, 2, CvType.CV_32FC1) {
590             {
591                 put(0, 0, 1.0, 0.0);
592                 put(1, 0, 1.0, 0.0);
593             }
594         };
595         Mat dmatrix = new Mat(2, 2, CvType.CV_32FC1) {
596             {
597                 put(0, 0, 0.001, 0.001);
598                 put(1, 0, 0.001, 0.001);
599             }
600         };
601
602         Core.gemm(m1, m2, 1.0, dmatrix, 1.0, dst, Core.GEMM_1_T);
603
604         Mat expected = new Mat(2, 2, CvType.CV_32FC1) {
605             {
606                 put(0, 0, 2.001, 0.001);
607                 put(1, 0, 0.001, 0.001);
608             }
609         };
610         assertMatEqual(expected, dst, EPS);
611     }
612
613     public void testGetCPUTickCount() {
614         long cpuCountStart = 0, actualTickCount;
615
616         cpuCountStart = Core.getCPUTickCount();
617         Core.sumElems(gray255);
618         actualTickCount = Core.getCPUTickCount();
619
620         long expectedTickCount = actualTickCount - cpuCountStart;
621         assertTrue(expectedTickCount > 0);
622     }
623
624     public void testGetNumberOfCPUs() {
625         int cpus = Core.getNumberOfCPUs();
626
627         assertTrue(Runtime.getRuntime().availableProcessors() <= cpus);
628     }
629
630     public void testGetOptimalDFTSize() {
631         assertEquals(1, Core.getOptimalDFTSize(0));
632         assertEquals(135, Core.getOptimalDFTSize(133));
633         assertEquals(15, Core.getOptimalDFTSize(13));
634     }
635
636     public void testGetTickCount() {
637         long startCount, endCount, count;
638
639         startCount = Core.getTickCount();
640         Core.divide(gray2, gray1, dst);
641         endCount = Core.getTickCount();
642
643         count = endCount - startCount;
644         assertTrue(count > 0);
645     }
646
647     public void testGetTickFrequency() {
648         double freq1 = Core.getTickFrequency();
649         Core.divide(gray2, gray1, dst);
650         double freq2 = Core.getTickFrequency();
651
652         assertTrue(0 < freq1);
653         assertEquals(freq1, freq2);
654     }
655
656     public void testHconcat() {
657         List<Mat> mats = Arrays.asList(Mat.eye(3, 3, CvType.CV_8U), Mat.zeros(3, 2, CvType.CV_8U));
658
659         Core.hconcat(mats, dst);
660
661         assertMatEqual(Mat.eye(3, 5, CvType.CV_8U), dst);
662     }
663
664     public void testIdctMatMat() {
665         Mat in = new Mat(1, 8, CvType.CV_32F) {
666             {
667                 put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0);
668             }
669         };
670
671         Core.idct(in, dst);
672
673         truth = new Mat(1, 8, CvType.CV_32F) {
674             {
675                 put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
676             }
677         };
678         assertMatEqual(truth, dst, EPS);
679     }
680
681     public void testIdctMatMatInt() {
682         Mat in = new Mat(2, 8, CvType.CV_32F) {
683             {
684                 put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0);
685                 put(1, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0);
686             }
687         };
688
689         Core.idct(in, dst, Core.DCT_ROWS);
690
691         truth = new Mat(2, 8, CvType.CV_32F) {
692             {
693                 put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
694                 put(1, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
695             }
696         };
697         assertMatEqual(truth, dst, EPS);
698     }
699
700     public void testIdftMatMat() {
701         Mat in = new Mat(1, 4, CvType.CV_32F) {
702             {
703                 put(0, 0, 1.0, 2.0, 3.0, 4.0);
704             }
705         };
706
707         Core.idft(in, dst);
708
709         truth = new Mat(1, 4, CvType.CV_32F) {
710             {
711                 put(0, 0, 9, -9, 1, 3);
712             }
713         };
714         assertMatEqual(truth, dst, EPS);
715     }
716
717     public void testIdftMatMatIntInt() {
718         Mat in = new Mat(2, 4, CvType.CV_32F) {
719             {
720                 put(0, 0, 1.0, 2.0, 3.0, 4.0);
721                 put(1, 0, 1.0, 2.0, 3.0, 4.0);
722             }
723         };
724         Mat dst = new Mat();
725
726         Core.idft(in, dst, Core.DFT_REAL_OUTPUT, 1);
727
728         truth = new Mat(2, 4, CvType.CV_32F) {
729             {
730                 put(0, 0, 18, -18, 2, 6);
731                 put(1, 0, 0, 0, 0, 0);
732             }
733         };
734         assertMatEqual(truth, dst, EPS);
735     }
736
737     public void testInRange() {
738         gray0.put(1, 1, 100, 150, 200);
739
740         Core.inRange(gray0, new Scalar(120), new Scalar(160), dst);
741
742         byte vals[] = new byte[3];
743         dst.get(1, 1, vals);
744
745         assertEquals(0, vals[0]);
746         assertEquals(-1, vals[1]);
747         assertEquals(0, vals[2]);
748         assertEquals(1, Core.countNonZero(dst));
749     }
750
751     public void testInsertChannel() {
752         Core.insertChannel(gray0, rgba128, 0);
753         Core.insertChannel(gray0, rgba128, 1);
754         Core.insertChannel(gray0, rgba128, 2);
755         Core.insertChannel(gray0, rgba128, 3);
756
757         assertMatEqual(rgba0, rgba128);
758     }
759
760     public void testInvertMatMat() {
761         Mat src = new Mat(2, 2, CvType.CV_32F) {
762             {
763                 put(0, 0, 1.0);
764                 put(0, 1, 2.0);
765                 put(1, 0, 1.5);
766                 put(1, 1, 4.0);
767             }
768         };
769
770         Core.invert(src, dst);
771
772         truth = new Mat(2, 2, CvType.CV_32F) {
773             {
774                 put(0, 0, 4.0);
775                 put(0, 1, -2.0);
776                 put(1, 0, -1.5);
777                 put(1, 1, 1.0);
778             }
779         };
780         assertMatEqual(truth, dst, EPS);
781     }
782
783     public void testInvertMatMatInt() {
784         Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
785         src.put(0, 2, 1);
786
787         double cond = Core.invert(src, dst, Core.DECOMP_SVD);
788
789         truth = Mat.eye(3, 3, CvType.CV_32FC1);
790         truth.put(0, 2, -1);
791         assertMatEqual(truth, dst, EPS);
792         assertEquals(0.3819660544395447, cond, EPS);
793     }
794
795     public void testKmeansMatIntMatTermCriteriaIntInt() {
796         Mat data = new Mat(4, 5, CvType.CV_32FC1) {
797             {
798                 put(0, 0, 1, 2, 3, 4, 5);
799                 put(1, 0, 2, 3, 4, 5, 6);
800                 put(2, 0, 5, 4, 3, 2, 1);
801                 put(3, 0, 6, 5, 4, 3, 2);
802             }
803         };
804         TermCriteria criteria = new TermCriteria(TermCriteria.EPS, 0, EPS);
805         Mat labels = new Mat();
806
807         Core.kmeans(data, 2, labels, criteria, 1, Core.KMEANS_PP_CENTERS);
808
809         int[] first_center = new int[1];
810         labels.get(0, 0, first_center);
811         final int c1 = first_center[0];
812         Mat expected_labels = new Mat(4, 1, CvType.CV_32S) {
813             {
814                 put(0, 0, c1, c1, 1 - c1, 1 - c1);
815             }
816         };
817         assertMatEqual(expected_labels, labels);
818     }
819
820     public void testKmeansMatIntMatTermCriteriaIntIntMat() {
821         Mat data = new Mat(4, 5, CvType.CV_32FC1) {
822             {
823                 put(0, 0, 1, 2, 3, 4, 5);
824                 put(1, 0, 2, 3, 4, 5, 6);
825                 put(2, 0, 5, 4, 3, 2, 1);
826                 put(3, 0, 6, 5, 4, 3, 2);
827             }
828         };
829         TermCriteria criteria = new TermCriteria(TermCriteria.EPS, 0, EPS);
830         Mat labels = new Mat();
831         Mat centers = new Mat();
832
833         Core.kmeans(data, 2, labels, criteria, 6, Core.KMEANS_RANDOM_CENTERS, centers);
834
835         int[] first_center = new int[1];
836         labels.get(0, 0, first_center);
837         final int c1 = first_center[0];
838         Mat expected_labels = new Mat(4, 1, CvType.CV_32S) {
839             {
840                 put(0, 0, c1, c1, 1 - c1, 1 - c1);
841             }
842         };
843         Mat expected_centers = new Mat(2, 5, CvType.CV_32FC1) {
844             {
845                 put(c1, 0, 1.5, 2.5, 3.5, 4.5, 5.5);
846                 put(1 - c1, 0, 5.5, 4.5, 3.5, 2.5, 1.5);
847             }
848         };
849         assertMatEqual(expected_labels, labels);
850         assertMatEqual(expected_centers, centers, EPS);
851     }
852
853     public void testLineMatPointPointScalar() {
854         int nPoints = Math.min(gray0.cols(), gray0.rows());
855         Point point1 = new Point(0, 0);
856         Point point2 = new Point(nPoints, nPoints);
857         Scalar color = new Scalar(255);
858
859         Imgproc.line(gray0, point1, point2, color);
860
861         assertTrue(nPoints == Core.countNonZero(gray0));
862     }
863
864     public void testLineMatPointPointScalarInt() {
865         int nPoints = Math.min(gray0.cols(), gray0.rows());
866         Point point1 = new Point(0, 0);
867         Point point2 = new Point(nPoints, nPoints);
868
869         Imgproc.line(gray0, point1, point2, colorWhite, 0);
870
871         assertTrue(nPoints == Core.countNonZero(gray0));
872     }
873
874     public void testLineMatPointPointScalarIntIntInt() {
875         int nPoints = Math.min(gray0.cols(), gray0.rows());
876         Point point1 = new Point(3, 4);
877         Point point2 = new Point(nPoints, nPoints);
878         Point point1_4 = new Point(3 * 4, 4 * 4);
879         Point point2_4 = new Point(nPoints * 4, nPoints * 4);
880
881         Imgproc.line(gray0, point2, point1, colorWhite, 2, Imgproc.LINE_8, 0);
882
883         assertFalse(0 == Core.countNonZero(gray0));
884
885         Imgproc.line(gray0, point2_4, point1_4, colorBlack, 2, Imgproc.LINE_8, 2);
886
887         assertEquals(0, Core.countNonZero(gray0));
888     }
889
890     public void testLog() {
891         Mat in = new Mat(1, 4, CvType.CV_32FC1) {
892             {
893                 put(0, 0, 1.0, 10.0, 100.0, 1000.0);
894             }
895         };
896
897         Core.log(in, dst);
898
899         Mat expected = new Mat(1, 4, CvType.CV_32FC1) {
900             {
901                 put(0, 0, 0, 2.3025851, 4.6051702, 6.9077554);
902             }
903         };
904         assertMatEqual(expected, dst, EPS);
905     }
906
907     public void testLUTMatMatMat() {
908         Mat lut = new Mat(1, 256, CvType.CV_8UC1);
909         lut.setTo(new Scalar(0));
910
911         Core.LUT(grayRnd, lut, dst);
912
913         assertMatEqual(gray0, dst);
914
915         lut.setTo(new Scalar(255));
916
917         Core.LUT(grayRnd, lut, dst);
918
919         assertMatEqual(gray255, dst);
920     }
921
922     public void testMagnitude() {
923         Mat x = new Mat(1, 4, CvType.CV_32F);
924         Mat y = new Mat(1, 4, CvType.CV_32F);
925         x.put(0, 0, 3.0, 5.0, 9.0, 6.0);
926         y.put(0, 0, 4.0, 12.0, 40.0, 8.0);
927
928         Core.magnitude(x, y, dst);
929
930         Mat out = new Mat(1, 4, CvType.CV_32F);
931         out.put(0, 0, 5.0, 13.0, 41.0, 10.0);
932         assertMatEqual(out, dst, EPS);
933
934         Core.magnitude(gray0_32f, gray255_32f, dst);
935
936         assertMatEqual(gray255_32f, dst, EPS);
937     }
938
939     public void testMahalanobis() {
940         Mat covar = new Mat(matSize, matSize, CvType.CV_32F);
941         Mat mean = new Mat(1, matSize, CvType.CV_32F);
942         Core.calcCovarMatrix(grayRnd_32f, covar, mean, Core.COVAR_ROWS | Core.COVAR_NORMAL, CvType.CV_32F);
943         covar = covar.inv();
944         Mat line1 = grayRnd_32f.row(0);
945         Mat line2 = grayRnd_32f.row(1);
946
947         double d = Core.Mahalanobis(line1, line1, covar);
948
949         assertEquals(0.0, d);
950
951         d = Core.Mahalanobis(line1, line2, covar);
952
953         assertTrue(d > 0.0);
954     }
955
956     public void testMax() {
957         Core.max(gray0, gray255, dst);
958
959         assertMatEqual(gray255, dst);
960
961         Mat x = new Mat(1, 1, CvType.CV_32F);
962         Mat y = new Mat(1, 1, CvType.CV_32F);
963         x.put(0, 0, 23.0);
964         y.put(0, 0, 4.0);
965
966         Core.max(x, y, dst);
967
968         Mat truth = new Mat(1, 1, CvType.CV_32F);
969         truth.put(0, 0, 23.0);
970         assertMatEqual(truth, dst, EPS);
971     }
972
973     public void testMeanMat() {
974         Scalar mean = Core.mean(makeMask(gray128));
975
976         assertScalarEqual(new Scalar(64), mean, EPS);
977     }
978
979     public void testMeanMatMat() {
980         Mat mask1 = makeMask(gray1.clone());
981         Mat mask2 = makeMask(gray0, 1);
982
983         Scalar mean1 = Core.mean(grayRnd, mask1);
984         Scalar mean2 = Core.mean(grayRnd, mask2);
985         Scalar mean = Core.mean(grayRnd, gray1);
986
987         assertScalarEqual(mean, new Scalar(0.5 * (mean1.val[0] + mean2.val[0])), EPS);
988     }
989
990     public void testMeanStdDevMatMatMat() {
991         MatOfDouble mean   = new MatOfDouble();
992         MatOfDouble stddev = new MatOfDouble();
993
994         Core.meanStdDev(rgbLena, mean, stddev);
995
996         double expectedMean[] = new double[]
997             {105.3989906311035, 99.56269836425781, 179.7303047180176};
998         double expectedDev[] = new double[]
999             {33.74205485167219, 52.8734582803278, 49.01569488056406};
1000
1001         assertArrayEquals(expectedMean, mean.toArray(), EPS);
1002         assertArrayEquals(expectedDev, stddev.toArray(), EPS);
1003     }
1004
1005     public void testMeanStdDevMatMatMatMat() {
1006         Mat submat = grayRnd.submat(0, grayRnd.rows() / 2, 0, grayRnd.cols() / 2);
1007         submat.setTo(new Scalar(33));
1008         Mat mask = gray0.clone();
1009         submat = mask.submat(0, mask.rows() / 2, 0, mask.cols() / 2);
1010         submat.setTo(new Scalar(1));
1011         MatOfDouble mean   = new MatOfDouble();
1012         MatOfDouble stddev = new MatOfDouble();
1013
1014         Core.meanStdDev(grayRnd, mean, stddev, mask);
1015
1016         double expectedMean[] = new double[] {33d};
1017         double expectedDev[]  = new double[] {0d};
1018
1019         assertArrayEquals(expectedMean, mean.toArray(), EPS);
1020         assertArrayEquals(expectedDev, stddev.toArray(), EPS);
1021     }
1022
1023     public void testMerge() {
1024         Mat src1 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(1));
1025         Mat src2 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(2));
1026         Mat src3 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(3));
1027         List<Mat> listMat = Arrays.asList(src1, src2, src3);
1028
1029         Core.merge(listMat, dst);
1030
1031         truth = new Mat(2, 2, CvType.CV_32FC3, new Scalar(1, 2, 3));
1032         assertMatEqual(truth, dst, EPS);
1033     }
1034
1035     public void testMin() {
1036         Core.min(gray0, gray255, dst);
1037
1038         assertMatEqual(gray0, dst);
1039     }
1040
1041     public void testMinMaxLocMat() {
1042         double minVal = 1;
1043         double maxVal = 10;
1044         Point minLoc = new Point(gray3.cols() / 4, gray3.rows() / 2);
1045         Point maxLoc = new Point(gray3.cols() / 2, gray3.rows() / 4);
1046         gray3.put((int) minLoc.y, (int) minLoc.x, minVal);
1047         gray3.put((int) maxLoc.y, (int) maxLoc.x, maxVal);
1048
1049         Core.MinMaxLocResult mmres = Core.minMaxLoc(gray3);
1050
1051         assertEquals(minVal, mmres.minVal);
1052         assertEquals(maxVal, mmres.maxVal);
1053         assertPointEquals(minLoc, mmres.minLoc, EPS);
1054         assertPointEquals(maxLoc, mmres.maxLoc, EPS);
1055     }
1056
1057     public void testMinMaxLocMatMat() {
1058         Mat src = new Mat(4, 4, CvType.CV_8U) {
1059             {
1060                 put(0, 0, 2, 4, 27, 3);
1061                 put(1, 0, 0, 8, 7, 130);
1062                 put(2, 0, 13, 4, 13, 4);
1063                 put(3, 0, 6, 4, 2, 13);
1064             }
1065         };
1066         Mat mask = new Mat(4, 4, CvType.CV_8U, new Scalar(0));
1067         mask.submat(1, 3, 1, 4).setTo(new Scalar(1));
1068
1069         MinMaxLocResult res = Core.minMaxLoc(src, mask);
1070
1071         assertEquals(4.0, res.minVal);
1072         assertEquals(130.0, res.maxVal);
1073         assertPointEquals(new Point(1, 2), res.minLoc, EPS);
1074         assertPointEquals(new Point(3, 1), res.maxLoc, EPS);
1075     }
1076
1077     public void testMixChannels() {
1078         rgba0.setTo(new Scalar(10, 20, 30, 40));
1079         List<Mat> src = Arrays.asList(rgba0);
1080         List<Mat> dst = Arrays.asList(gray3, gray2, gray1, gray0, getMat(CvType.CV_8UC3, 0, 0, 0));
1081         MatOfInt fromTo = new MatOfInt(
1082                 3, 0,
1083                 3, 1,
1084                 2, 2,
1085                 0, 3,
1086                 2, 4,
1087                 1, 5,
1088                 0, 6
1089         );
1090
1091         Core.mixChannels(src, dst, fromTo);
1092
1093         assertMatEqual(getMat(CvType.CV_8U, 40), dst.get(0));
1094         assertMatEqual(getMat(CvType.CV_8U, 40), dst.get(1));
1095         assertMatEqual(getMat(CvType.CV_8U, 30), dst.get(2));
1096         assertMatEqual(getMat(CvType.CV_8U, 10), dst.get(3));
1097         assertMatEqual(getMat(CvType.CV_8UC3, 30, 20, 10), dst.get(4));
1098     }
1099
1100     public void testMulSpectrumsMatMatMatInt() {
1101         Mat src1 = new Mat(1, 4, CvType.CV_32F) {
1102             {
1103                 put(0, 0, 1.0, 2.0, 3.0, 4.0);
1104             }
1105         };
1106         Mat src2 = new Mat(1, 4, CvType.CV_32F) {
1107             {
1108                 put(0, 0, 1.0, 2.0, 3.0, 4.0);
1109             }
1110         };
1111
1112         Core.mulSpectrums(src1, src2, dst, Core.DFT_ROWS);
1113
1114         Mat expected = new Mat(1, 4, CvType.CV_32F) {
1115             {
1116                 put(0, 0, 1, -5, 12, 16);
1117             }
1118         };
1119         assertMatEqual(expected, dst, EPS);
1120     }
1121
1122     public void testMulSpectrumsMatMatMatIntBoolean() {
1123         Mat src1 = new Mat(1, 4, CvType.CV_32F) {
1124             {
1125                 put(0, 0, 1.0, 2.0, 3.0, 4.0);
1126             }
1127         };
1128         Mat src2 = new Mat(1, 4, CvType.CV_32F) {
1129             {
1130                 put(0, 0, 1.0, 2.0, 3.0, 4.0);
1131             }
1132         };
1133
1134         Core.mulSpectrums(src1, src2, dst, Core.DFT_ROWS, true);
1135
1136         Mat expected = new Mat(1, 4, CvType.CV_32F) {
1137             {
1138                 put(0, 0, 1, 13, 0, 16);
1139             }
1140         };
1141         assertMatEqual(expected, dst, EPS);
1142     }
1143
1144     public void testMultiplyMatMatMat() {
1145         Core.multiply(gray0, gray255, dst);
1146
1147         assertMatEqual(gray0, dst);
1148     }
1149
1150     public void testMultiplyMatMatMatDouble() {
1151         Core.multiply(gray1, gray1, dst, 2.0);
1152
1153         assertMatEqual(gray2, dst);
1154
1155     }
1156
1157     public void testMultiplyMatMatMatDoubleInt() {
1158         Core.multiply(gray1, gray2, dst, 1.5, CvType.CV_32F);
1159
1160         assertMatEqual(gray3_32f, dst, EPS);
1161     }
1162
1163     public void testMulTransposedMatMatBoolean() {
1164         Core.mulTransposed(grayE_32f, dst, true);
1165
1166         assertMatEqual(grayE_32f, dst, EPS);
1167     }
1168
1169     public void testMulTransposedMatMatBooleanMatDouble() {
1170         Core.mulTransposed(grayE_32f, dst, true, gray0_32f, 2);
1171
1172         truth = gray0_32f;
1173         truth.diag().setTo(new Scalar(2));
1174         assertMatEqual(truth, dst, EPS);
1175     }
1176
1177     public void testMulTransposedMatMatBooleanMatDoubleInt() {
1178         Mat a = getMat(CvType.CV_32F, 1);
1179
1180         Core.mulTransposed(a, dst, true, gray0_32f, 3, CvType.CV_64F);
1181
1182         assertMatEqual(getMat(CvType.CV_64F, 3 * a.rows()), dst, EPS);
1183     }
1184
1185     public void testNormalizeMatMat() {
1186         Mat m = gray0.clone();
1187         m.diag().setTo(new Scalar(2));
1188
1189         Core.normalize(m, dst);
1190
1191         assertMatEqual(gray0, dst);
1192     }
1193
1194     public void testNormalizeMatMatDoubleDoubleInt() {
1195         Mat src = new Mat(1, 4, CvType.CV_32F) {
1196             {
1197                 put(0, 0, 1.0, 2.0, 3.0, 4.0);
1198             }
1199         };
1200
1201         Core.normalize(src, dst, 1.0, 2.0, Core.NORM_INF);
1202
1203         Mat expected = new Mat(1, 4, CvType.CV_32F) {
1204             {
1205                 put(0, 0, 0.25, 0.5, 0.75, 1);
1206             }
1207         };
1208         assertMatEqual(expected, dst, EPS);
1209     }
1210
1211     public void testNormalizeMatMatDoubleDoubleIntInt() {
1212         Mat src = new Mat(1, 5, CvType.CV_32F) {
1213             {
1214                 put(0, 0, 0, 1, 2, 3, 4);
1215             }
1216         };
1217
1218         Core.normalize(src, dst, 1, 2, Core.NORM_MINMAX, CvType.CV_64F);
1219
1220         Mat expected = new Mat(1, 5, CvType.CV_64F) {
1221             {
1222                 put(0, 0, 1, 1.25, 1.5, 1.75, 2);
1223             }
1224         };
1225         assertMatEqual(expected, dst, EPS);
1226     }
1227
1228     public void testNormalizeMatMatDoubleDoubleIntIntMat() {
1229         Mat src = new Mat(1, 5, CvType.CV_32F) {
1230             {
1231                 put(0, 0, 0, 1, 2, 3, 4);
1232             }
1233         };
1234         Mat mask = new Mat(1, 5, CvType.CV_8U) {
1235             {
1236                 put(0, 0, 1, 0, 0, 0, 1);
1237             }
1238         };
1239         dst = src.clone();
1240
1241         Core.normalize(src, dst, 1, 2, Core.NORM_MINMAX, CvType.CV_32F, mask);
1242
1243         Mat expected = new Mat(1, 5, CvType.CV_32F) {
1244             {
1245                 put(0, 0, 1, 1, 2, 3, 2);
1246             }
1247         };
1248         assertMatEqual(expected, dst, EPS);
1249     }
1250
1251     public void testNormMat() {
1252         double n = Core.norm(gray1);
1253
1254         assertEquals(10., n);
1255     }
1256
1257     public void testNormMatInt() {
1258         double n = Core.norm(gray127, Core.NORM_INF);
1259
1260         assertEquals(127., n);
1261     }
1262
1263     public void testNormMatIntMat() {
1264         double n = Core.norm(gray3, Core.NORM_L1, gray0);
1265
1266         assertEquals(0.0, n);
1267     }
1268
1269     public void testNormMatMat() {
1270         double n = Core.norm(gray0, gray1);
1271
1272         assertEquals(10.0, n);
1273     }
1274
1275     public void testNormMatMatInt() {
1276         double n = Core.norm(gray127, gray1, Core.NORM_INF);
1277
1278         assertEquals(126.0, n);
1279     }
1280
1281     public void testNormMatMatIntMat() {
1282         double n = Core.norm(gray3, gray0, Core.NORM_L1, makeMask(gray0.clone(), 1));
1283
1284         assertEquals(150.0, n);
1285     }
1286
1287     public void testPCABackProject() {
1288         Mat mean = new Mat(1, 4, CvType.CV_32F) {
1289             {
1290                 put(0, 0, 2, 4, 4, 8);
1291             }
1292         };
1293         Mat vectors = new Mat(1, 4, CvType.CV_32F, new Scalar(0)) {
1294             {
1295                 put(0, 0, 0.2, 0.4, 0.4, 0.8);
1296             }
1297         };
1298         Mat data = new Mat(3, 1, CvType.CV_32F) {
1299             {
1300                 put(0, 0, -5, 0, -10);
1301             }
1302         };
1303         Mat result = new Mat();
1304
1305         Core.PCABackProject(data, mean, vectors, result);
1306
1307         Mat truth = new Mat(3, 4, CvType.CV_32F) {
1308             {
1309                 put(0, 0, 1, 2, 2, 4);
1310                 put(1, 0, 2, 4, 4, 8);
1311                 put(2, 0, 0, 0, 0, 0);
1312             }
1313         };
1314         assertMatEqual(truth, result, EPS);
1315     }
1316
1317     public void testPCAComputeMatMatMat() {
1318         Mat data = new Mat(3, 4, CvType.CV_32F) {
1319             {
1320                 put(0, 0, 1, 2, 2, 4);
1321                 put(1, 0, 2, 4, 4, 8);
1322                 put(2, 0, 3, 6, 6, 12);
1323             }
1324         };
1325         Mat mean = new Mat();
1326         Mat vectors = new Mat();
1327
1328         Core.PCACompute(data, mean, vectors);
1329
1330         Mat mean_truth = new Mat(1, 4, CvType.CV_32F) {
1331             {
1332                 put(0, 0, 2, 4, 4, 8);
1333             }
1334         };
1335         Mat vectors_truth = new Mat(3, 4, CvType.CV_32F, new Scalar(0)) {
1336             {
1337                 put(0, 0, 0.2, 0.4, 0.4, 0.8);
1338             }
1339         };
1340         assertMatEqual(mean_truth, mean, EPS);
1341         assertMatEqual(vectors_truth, vectors, EPS);
1342     }
1343
1344     public void testPCAComputeMatMatMatInt() {
1345         Mat data = new Mat(3, 4, CvType.CV_32F) {
1346             {
1347                 put(0, 0, 1, 2, 2, 4);
1348                 put(1, 0, 2, 4, 4, 8);
1349                 put(2, 0, 3, 6, 6, 12);
1350             }
1351         };
1352         Mat mean = new Mat();
1353         Mat vectors = new Mat();
1354
1355         Core.PCACompute(data, mean, vectors, 1);
1356
1357         Mat mean_truth = new Mat(1, 4, CvType.CV_32F) {
1358             {
1359                 put(0, 0, 2, 4, 4, 8);
1360             }
1361         };
1362         Mat vectors_truth = new Mat(1, 4, CvType.CV_32F, new Scalar(0)) {
1363             {
1364                 put(0, 0, 0.2, 0.4, 0.4, 0.8);
1365             }
1366         };
1367         assertMatEqual(mean_truth, mean, EPS);
1368         assertMatEqual(vectors_truth, vectors, EPS);
1369     }
1370
1371     public void testPCAProject() {
1372         Mat mean = new Mat(1, 4, CvType.CV_32F) {
1373             {
1374                 put(0, 0, 2, 4, 4, 8);
1375             }
1376         };
1377         Mat vectors = new Mat(1, 4, CvType.CV_32F, new Scalar(0)) {
1378             {
1379                 put(0, 0, 0.2, 0.4, 0.4, 0.8);
1380             }
1381         };
1382         Mat data = new Mat(3, 4, CvType.CV_32F) {
1383             {
1384                 put(0, 0, 1, 2, 2, 4);
1385                 put(1, 0, 2, 4, 4, 8);
1386                 put(2, 0, 0, 0, 0, 0);
1387             }
1388         };
1389         Mat result = new Mat();
1390
1391         Core.PCAProject(data, mean, vectors, result);
1392
1393         Mat truth = new Mat(3, 1, CvType.CV_32F) {
1394             {
1395                 put(0, 0, -5, 0, -10);
1396             }
1397         };
1398         assertMatEqual(truth, result, EPS);
1399     }
1400
1401     public void testPerspectiveTransform() {
1402         Mat src = new Mat(matSize, matSize, CvType.CV_32FC2);
1403         Core.randu(src, 0, 256);
1404         Mat transformMatrix = Mat.eye(3, 3, CvType.CV_32F);
1405
1406         Core.perspectiveTransform(src, dst, transformMatrix);
1407         assertMatEqual(src, dst, EPS);
1408     }
1409
1410     public void testPerspectiveTransform3D() {
1411         Mat src = new Mat(matSize, matSize, CvType.CV_32FC3);
1412         Core.randu(src, 0, 256);
1413         Mat transformMatrix = Mat.eye(4, 4, CvType.CV_32F);
1414
1415         Core.perspectiveTransform(src, dst, transformMatrix);
1416
1417         assertMatEqual(src, dst, EPS);
1418     }
1419
1420     private static double atan2deg(double y, double x)
1421     {
1422         double res = Math.atan2(y, x);
1423         if (res < 0)
1424             res = Math.PI * 2 + res;
1425         return res * 180 / Math.PI;
1426     }
1427
1428     private static double atan2rad(double y, double x)
1429     {
1430         double res = Math.atan2(y, x);
1431         if (res < 0)
1432             res = Math.PI * 2 + res;
1433         return res;
1434     }
1435
1436     public void testPhaseMatMatMat() {
1437         Mat x = new Mat(1, 4, CvType.CV_32F) {
1438             {
1439                 put(0, 0, 10.0, 10.0, 20.0, 5.0);
1440             }
1441         };
1442         Mat y = new Mat(1, 4, CvType.CV_32F) {
1443             {
1444                 put(0, 0, 20.0, 15.0, 20.0, 20.0);
1445             }
1446         };
1447         Mat gold = new Mat(1, 4, CvType.CV_32F) {
1448             {
1449                 put(0, 0, atan2rad(20, 10), atan2rad(15, 10), atan2rad(20, 20), atan2rad(20, 5));
1450             }
1451         };
1452
1453         Core.phase(x, y, dst);
1454
1455         assertMatEqual(gold, dst, EPS);
1456     }
1457
1458     public void testPhaseMatMatMatBoolean() {
1459         Mat x = new Mat(1, 4, CvType.CV_32F) {
1460             {
1461                 put(0, 0, 10.0, 10.0, 20.0, 5.0);
1462             }
1463         };
1464         Mat y = new Mat(1, 4, CvType.CV_32F) {
1465             {
1466                 put(0, 0, 20.0, 15.0, 20.0, 20.0);
1467             }
1468         };
1469         Mat gold = new Mat(1, 4, CvType.CV_32F) {
1470             {
1471                 put(0, 0, atan2deg(20, 10), atan2deg(15, 10), atan2deg(20, 20), atan2deg(20, 5));
1472             }
1473         };
1474
1475         Core.phase(x, y, dst, true);
1476
1477         assertMatEqual(gold, dst, EPS * 180 / Math.PI);
1478     }
1479
1480     public void testPolarToCartMatMatMatMat() {
1481         Mat magnitude = new Mat(1, 3, CvType.CV_32F) {
1482             {
1483                 put(0, 0, 5.0, 10.0, 13.0);
1484             }
1485         };
1486         Mat angle = new Mat(1, 3, CvType.CV_32F) {
1487             {
1488                 put(0, 0, 0.92729962, 0.92729962, 1.1759995);
1489             }
1490         };
1491         Mat xCoordinate = new Mat();
1492         Mat yCoordinate = new Mat();
1493
1494         Core.polarToCart(magnitude, angle, xCoordinate, yCoordinate);
1495
1496         Mat x = new Mat(1, 3, CvType.CV_32F) {
1497             {
1498                 put(0, 0, 3.0, 6.0, 5, 0);
1499             }
1500         };
1501         Mat y = new Mat(1, 3, CvType.CV_32F) {
1502             {
1503                 put(0, 0, 4.0, 8.0, 12.0);
1504             }
1505         };
1506         assertMatEqual(x, xCoordinate, EPS);
1507         assertMatEqual(y, yCoordinate, EPS);
1508     }
1509
1510     public void testPolarToCartMatMatMatMatBoolean() {
1511         Mat magnitude = new Mat(1, 3, CvType.CV_32F) {
1512             {
1513                 put(0, 0, 5.0, 10.0, 13.0);
1514             }
1515         };
1516         Mat angle = new Mat(1, 3, CvType.CV_32F) {
1517             {
1518                 put(0, 0, 0.92729962, 0.92729962, 1.1759995);
1519             }
1520         };
1521         Mat xCoordinate = new Mat();
1522         Mat yCoordinate = new Mat();
1523
1524         Core.polarToCart(magnitude, angle, xCoordinate, yCoordinate, true);
1525
1526         Mat x = new Mat(1, 3, CvType.CV_32F) {
1527             {
1528                 put(0, 0, 4.9993458, 9.9986916, 12.997262);
1529             }
1530         };
1531         Mat y = new Mat(1, 3, CvType.CV_32F) {
1532             {
1533                 put(0, 0, 0.080918625, 0.16183725, 0.26680708);
1534             }
1535         };
1536         assertMatEqual(x, xCoordinate, EPS);
1537         assertMatEqual(y, yCoordinate, EPS);
1538     }
1539
1540     public void testPow() {
1541         Core.pow(gray2, 7, dst);
1542
1543         assertMatEqual(gray128, dst);
1544     }
1545
1546     public void testRandn() {
1547         Core.randn(gray0, 100, 23);
1548
1549         assertEquals(100., Core.mean(gray0).val[0], 23 / 2);
1550     }
1551
1552     public void testRandShuffleMat() {
1553         Mat original = new Mat(1, 10, CvType.CV_32F) {
1554             {
1555                 put(0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
1556             }
1557         };
1558         Mat shuffled = original.clone();
1559
1560         Core.randShuffle(shuffled);
1561
1562         assertMatNotEqual(original, shuffled, EPS);
1563         Mat dst1 = new Mat();
1564         Mat dst2 = new Mat();
1565         Core.sort(original, dst1, Core.SORT_ASCENDING);
1566         Core.sort(shuffled, dst2, Core.SORT_ASCENDING);
1567         assertMatEqual(dst1, dst2, EPS);
1568     }
1569
1570     public void testRandShuffleMatDouble() {
1571         Mat original = new Mat(1, 10, CvType.CV_32F) {
1572             {
1573                 put(0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
1574             }
1575         };
1576         Mat shuffled = original.clone();
1577
1578         Core.randShuffle(shuffled, 10);
1579
1580         assertMatNotEqual(original, shuffled, EPS);
1581         Mat dst1 = new Mat();
1582         Mat dst2 = new Mat();
1583         Core.sort(original, dst1, Core.SORT_ASCENDING);
1584         Core.sort(shuffled, dst2, Core.SORT_ASCENDING);
1585         assertMatEqual(dst1, dst2, EPS);
1586     }
1587
1588     public void testRandu() {
1589         Core.randu(gray0, 3, 23);
1590         fail("Not yet implemented");
1591         //assertTrue(Core.checkRange(gray0, true, null, 3, 23));
1592     }
1593
1594     public void testRectangleMatPointPointScalar() {
1595         Point bottomRight = new Point(gray0.cols() / 2, gray0.rows() / 2);
1596         Point topLeft = new Point(0, 0);
1597         Scalar color = new Scalar(128);
1598
1599         Imgproc.rectangle(gray0, bottomRight, topLeft, color);
1600
1601         assertTrue(0 != Core.countNonZero(gray0));
1602     }
1603
1604     public void testRectangleMatPointPointScalarInt() {
1605         Point bottomRight = new Point(gray0.cols(), gray0.rows());
1606         Point topLeft = new Point(0, 0);
1607         Scalar color = new Scalar(128);
1608
1609         Imgproc.rectangle(gray0, bottomRight, topLeft, color, 2);
1610         Imgproc.rectangle(gray0, bottomRight, topLeft, colorBlack);
1611
1612         assertTrue(0 != Core.countNonZero(gray0));
1613     }
1614
1615     public void testRectangleMatPointPointScalarIntInt() {
1616         Point bottomRight = new Point(gray0.cols() / 2, gray0.rows() / 2);
1617         Point topLeft = new Point(0, 0);
1618         Scalar color = new Scalar(128);
1619
1620         Imgproc.rectangle(gray0, bottomRight, topLeft, color, 2, Imgproc.LINE_AA, 0);
1621         Imgproc.rectangle(gray0, bottomRight, topLeft, colorBlack, 2, Imgproc.LINE_4, 0);
1622
1623         assertTrue(0 != Core.countNonZero(gray0));
1624     }
1625
1626     public void testRectangleMatPointPointScalarIntIntInt() {
1627         Point bottomRight1 = new Point(gray0.cols(), gray0.rows());
1628         Point bottomRight2 = new Point(gray0.cols() / 2, gray0.rows() / 2);
1629         Point topLeft = new Point(0, 0);
1630         Scalar color = new Scalar(128);
1631
1632         Imgproc.rectangle(gray0, bottomRight1, topLeft, color, 2, Imgproc.LINE_8, 1);
1633
1634         assertTrue(0 != Core.countNonZero(gray0));
1635
1636         Imgproc.rectangle(gray0, bottomRight2, topLeft, colorBlack, 2, Imgproc.LINE_8, 0);
1637
1638         assertEquals(0, Core.countNonZero(gray0));
1639     }
1640
1641     public void testReduceMatMatIntInt() {
1642         Mat src = new Mat(2, 2, CvType.CV_32F) {
1643             {
1644                 put(0, 0, 1, 0);
1645                 put(1, 0, 3, 0);
1646             }
1647         };
1648
1649         Core.reduce(src, dst, 0, Core.REDUCE_AVG);
1650
1651         Mat out = new Mat(1, 2, CvType.CV_32F) {
1652             {
1653                 put(0, 0, 2, 0);
1654             }
1655         };
1656         assertMatEqual(out, dst, EPS);
1657     }
1658
1659     public void testReduceMatMatIntIntInt() {
1660         Mat src = new Mat(2, 2, CvType.CV_32F) {
1661             {
1662                 put(0, 0, 1, 0);
1663                 put(1, 0, 2, 3);
1664             }
1665         };
1666
1667         Core.reduce(src, dst, 1, Core.REDUCE_SUM, CvType.CV_64F);
1668
1669         Mat out = new Mat(2, 1, CvType.CV_64F) {
1670             {
1671                 put(0, 0, 1, 5);
1672             }
1673         };
1674         assertMatEqual(out, dst, EPS);
1675     }
1676
1677     public void testRepeat() {
1678         Mat src = new Mat(1, 2, CvType.CV_32F, new Scalar(0));
1679
1680         Core.repeat(src, matSize, matSize / 2, dst);
1681
1682         assertMatEqual(gray0_32f, dst, EPS);
1683     }
1684
1685     public void testScaleAdd() {
1686         Core.scaleAdd(gray3, 2.0, gray3, dst);
1687
1688         assertMatEqual(gray9, dst);
1689     }
1690
1691     public void testSetIdentityMat() {
1692         Core.setIdentity(gray0_32f);
1693
1694         assertMatEqual(grayE_32f, gray0_32f, EPS);
1695     }
1696
1697     public void testSetIdentityMatScalar() {
1698         Mat m = gray0_32f;
1699
1700         Core.setIdentity(m, new Scalar(5));
1701
1702         truth = new Mat(m.size(), m.type(), new Scalar(0));
1703         truth.diag().setTo(new Scalar(5));
1704         assertMatEqual(truth, m, EPS);
1705     }
1706
1707     public void testSolveCubic() {
1708         Mat coeffs = new Mat(1, 4, CvType.CV_32F) {
1709             {
1710                 put(0, 0, 1, 6, 11, 6);
1711             }
1712         };
1713
1714         assertEquals(3, Core.solveCubic(coeffs, dst));
1715
1716         Mat roots = new Mat(3, 1, CvType.CV_32F) {
1717             {
1718                 put(0, 0, -3, -1, -2);
1719             }
1720         };
1721         assertMatEqual(roots, dst, EPS);
1722     }
1723
1724     public void testSolveMatMatMat() {
1725         Mat a = new Mat(3, 3, CvType.CV_32F) {
1726             {
1727                 put(0, 0, 1, 1, 1);
1728                 put(1, 0, 1, -2, 2);
1729                 put(2, 0, 1, 2, 1);
1730             }
1731         };
1732         Mat b = new Mat(3, 1, CvType.CV_32F) {
1733             {
1734                 put(0, 0, 0, 4, 2);
1735             }
1736         };
1737
1738         assertTrue(Core.solve(a, b, dst));
1739
1740         Mat res = new Mat(3, 1, CvType.CV_32F) {
1741             {
1742                 put(0, 0, -12, 2, 10);
1743             }
1744         };
1745         assertMatEqual(res, dst, EPS);
1746     }
1747
1748     public void testSolveMatMatMatInt() {
1749         Mat a = new Mat(3, 3, CvType.CV_32F) {
1750             {
1751                 put(0, 0, 1, 1, 1);
1752                 put(1, 0, 1, -2, 2);
1753                 put(2, 0, 1, 2, 1);
1754             }
1755         };
1756         Mat b = new Mat(3, 1, CvType.CV_32F) {
1757             {
1758                 put(0, 0, 0, 4, 2);
1759             }
1760         };
1761
1762         assertTrue(Core.solve(a, b, dst, Core.DECOMP_QR | Core.DECOMP_NORMAL));
1763
1764         Mat res = new Mat(3, 1, CvType.CV_32F) {
1765             {
1766                 put(0, 0, -12, 2, 10);
1767             }
1768         };
1769         assertMatEqual(res, dst, EPS);
1770     }
1771
1772     public void testSolvePolyMatMat() {
1773         Mat coeffs = new Mat(4, 1, CvType.CV_32F) {
1774             {
1775                 put(0, 0, -6, 11, -6, 1);
1776             }
1777         };
1778         Mat roots = new Mat();
1779
1780         assertEquals(0.0, Core.solvePoly(coeffs, roots));
1781
1782         truth = new Mat(3, 1, CvType.CV_32FC2) {
1783             {
1784                 put(0, 0, 1, 0, 2, 0, 3, 0);
1785             }
1786         };
1787         assertMatEqual(truth, roots, EPS);
1788     }
1789
1790     public void testSolvePolyMatMatInt() {
1791         Mat coeffs = new Mat(4, 1, CvType.CV_32F) {
1792             {
1793                 put(0, 0, -6, 11, -6, 1);
1794             }
1795         };
1796         Mat roots = new Mat();
1797
1798         assertEquals(10.198039027185569, Core.solvePoly(coeffs, roots, 1));
1799
1800         truth = new Mat(3, 1, CvType.CV_32FC2) {
1801             {
1802                 put(0, 0, 1, 0, -1, 2, -2, 12);
1803             }
1804         };
1805         assertMatEqual(truth, roots, EPS);
1806     }
1807
1808     public void testSort() {
1809         Mat submat = gray0.submat(0, gray0.rows() / 2, 0, gray0.cols() / 2);
1810         submat.setTo(new Scalar(1.0));
1811
1812         Core.sort(gray0, dst, Core.SORT_EVERY_ROW);
1813
1814         submat = dst.submat(0, dst.rows() / 2, dst.cols() / 2, dst.cols());
1815         assertTrue(submat.total() == Core.countNonZero(submat));
1816
1817         Core.sort(gray0, dst, Core.SORT_EVERY_COLUMN);
1818
1819         submat = dst.submat(dst.rows() / 2, dst.rows(), 0, dst.cols() / 2);
1820
1821         assertTrue(submat.total() == Core.countNonZero(submat));
1822     }
1823
1824     public void testSortIdx() {
1825         Mat a = Mat.eye(3, 3, CvType.CV_8UC1);
1826         Mat b = new Mat();
1827
1828         Core.sortIdx(a, b, Core.SORT_EVERY_ROW | Core.SORT_ASCENDING);
1829
1830         truth = new Mat(3, 3, CvType.CV_32SC1) {
1831             {
1832                 put(0, 0, 1, 2, 0);
1833                 put(1, 0, 0, 2, 1);
1834                 put(2, 0, 0, 1, 2);
1835             }
1836         };
1837         assertMatEqual(truth, b);
1838     }
1839
1840     public void testSplit() {
1841         Mat m = getMat(CvType.CV_8UC3, 1, 2, 3);
1842         ArrayList<Mat> cois = new ArrayList<Mat>();
1843
1844         Core.split(m, cois);
1845
1846         assertMatEqual(gray1, cois.get(0));
1847         assertMatEqual(gray2, cois.get(1));
1848         assertMatEqual(gray3, cois.get(2));
1849     }
1850
1851     public void testSqrt() {
1852         Core.sqrt(gray9_32f, dst);
1853
1854         assertMatEqual(gray3_32f, dst, EPS);
1855
1856         Mat rgba144 = new Mat(matSize, matSize, CvType.CV_32FC4, Scalar.all(144));
1857         Mat rgba12 = new Mat(matSize, matSize, CvType.CV_32FC4, Scalar.all(12));
1858
1859         Core.sqrt(rgba144, dst);
1860
1861         assertMatEqual(rgba12, dst, EPS);
1862     }
1863
1864     public void testSubtractMatMatMat() {
1865         Core.subtract(gray128, gray1, dst);
1866
1867         assertMatEqual(gray127, dst);
1868     }
1869
1870     public void testSubtractMatMatMatMat() {
1871         Mat mask = makeMask(gray1.clone());
1872         dst = gray128.clone();
1873
1874         Core.subtract(gray128, gray1, dst, mask);
1875
1876         assertMatEqual(makeMask(gray127, 128), dst);
1877     }
1878
1879     public void testSubtractMatMatMatMatInt() {
1880         Core.subtract(gray3, gray2, dst, gray1, CvType.CV_32F);
1881
1882         assertMatEqual(gray1_32f, dst, EPS);
1883     }
1884
1885     public void testSumElems() {
1886         Mat src = new Mat(4, 4, CvType.CV_8U, new Scalar(10));
1887
1888         Scalar res1 = Core.sumElems(src);
1889
1890         assertScalarEqual(new Scalar(160), res1, EPS);
1891     }
1892
1893     public void testSVBackSubst() {
1894         Mat w = new Mat(2, 2, CvType.CV_32FC1, new Scalar(2));
1895         Mat u = new Mat(2, 2, CvType.CV_32FC1, new Scalar(4));
1896         Mat vt = new Mat(2, 2, CvType.CV_32FC1, new Scalar(2));
1897         Mat rhs = new Mat(2, 2, CvType.CV_32FC1, new Scalar(1));
1898
1899         Core.SVBackSubst(w, u, vt, rhs, dst);
1900
1901         Mat truth = new Mat(2, 2, CvType.CV_32FC1, new Scalar(16));
1902         assertMatEqual(truth, dst, EPS);
1903     }
1904
1905     public void testSVDecompMatMatMatMat() {
1906         Mat src = new Mat(1, 4, CvType.CV_32FC1) {
1907             {
1908                 put(0, 0, 1, 4, 8, 6);
1909             }
1910         };
1911         Mat w = new Mat();
1912         Mat u = new Mat();
1913         Mat vt = new Mat();
1914
1915         Core.SVDecomp(src, w, u, vt);
1916
1917         Mat truthW = new Mat(1, 1, CvType.CV_32FC1, new Scalar(10.816654));
1918         Mat truthU = new Mat(1, 1, CvType.CV_32FC1, new Scalar(1));
1919         Mat truthVT = new Mat(1, 4, CvType.CV_32FC1) {
1920             {
1921                 put(0, 0, 0.09245003, 0.36980012, 0.73960024, 0.5547002);
1922             }
1923         };
1924         assertMatEqual(truthW, w, EPS);
1925         assertMatEqual(truthU, u, EPS);
1926         assertMatEqual(truthVT, vt, EPS);
1927     }
1928
1929     public void testSVDecompMatMatMatMatInt() {
1930         Mat src = new Mat(1, 4, CvType.CV_32FC1) {
1931             {
1932                 put(0, 0, 1, 4, 8, 6);
1933             }
1934         };
1935         Mat w = new Mat();
1936         Mat u = new Mat();
1937         Mat vt = new Mat();
1938
1939         Core.SVDecomp(src, w, u, vt, Core.SVD_NO_UV);
1940
1941         Mat truthW = new Mat(1, 1, CvType.CV_32FC1, new Scalar(10.816654));
1942         assertMatEqual(truthW, w, EPS);
1943         assertTrue(u.empty());
1944         assertTrue(vt.empty());
1945     }
1946
1947     public void testTrace() {
1948         Scalar s = Core.trace(gray1);
1949
1950         assertEquals(new Scalar(matSize), s);
1951     }
1952
1953     public void testTransform() {
1954         Mat src = new Mat(2, 2, CvType.CV_32F, new Scalar(55));
1955         Mat m = Mat.eye(2, 2, CvType.CV_32FC1);
1956
1957         Core.transform(src, dst, m);
1958
1959         truth = new Mat(2, 2, CvType.CV_32FC2, new Scalar(55, 1));
1960         assertMatEqual(truth, dst, EPS);
1961     }
1962
1963     public void testTranspose() {
1964         gray0.submat(0, gray0.rows() / 2, 0, gray0.cols()).setTo(new Scalar(1));
1965         Mat destination = getMat(CvType.CV_8U, 0);
1966
1967         Core.transpose(gray0, destination);
1968
1969         Mat subdst = destination.submat(0, destination.rows(), 0, destination.cols() / 2);
1970         assertTrue(subdst.total() == Core.countNonZero(subdst));
1971     }
1972
1973     public void testVconcat() {
1974         List<Mat> mats = Arrays.asList(Mat.eye(3, 3, CvType.CV_8U), Mat.zeros(2, 3, CvType.CV_8U));
1975
1976         Core.vconcat(mats, dst);
1977
1978         assertMatEqual(Mat.eye(5, 3, CvType.CV_8U), dst);
1979
1980     }
1981
1982     public void testCopyMakeBorderMatMatIntIntIntIntInt() {
1983         Mat src = new Mat(2, 2, CvType.CV_32F, new Scalar(1));
1984         int border = 2;
1985
1986         Core.copyMakeBorder(src, dst, border, border, border, border, Core.BORDER_REPLICATE);
1987
1988         truth = new Mat(6, 6, CvType.CV_32F, new Scalar(1));
1989         assertMatEqual(truth, dst, EPS);
1990     }
1991
1992     public void testCopyMakeBorderMatMatIntIntIntIntIntScalar() {
1993         Mat src = new Mat(2, 2, CvType.CV_32F, new Scalar(1));
1994
1995         Scalar value = new Scalar(0);
1996         int border = 2;
1997
1998         Core.copyMakeBorder(src, dst, border, border, border, border, Core.BORDER_REPLICATE, value);
1999         // TODO_: write better test (use Core.BORDER_CONSTANT)
2000
2001         truth = new Mat(6, 6, CvType.CV_32F, new Scalar(1));
2002         assertMatEqual(truth, dst, EPS);
2003     }
2004
2005     public void testBorderInterpolate() {
2006         float val1 = Core.borderInterpolate(100, 150, Core.BORDER_REFLECT_101);
2007         assertEquals(100f, val1);
2008
2009         float val2 = Core.borderInterpolate(-5, 10, Core.BORDER_WRAP);
2010         assertEquals(5f, val2);
2011     }
2012
2013 }