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