Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/misc/java/test/ImgprocTest.java
16363 views
1
package org.opencv.test.imgproc;
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.CvType;
9
import org.opencv.core.Mat;
10
import org.opencv.core.MatOfFloat;
11
import org.opencv.core.MatOfInt;
12
import org.opencv.core.MatOfInt4;
13
import org.opencv.core.MatOfPoint;
14
import org.opencv.core.MatOfPoint2f;
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.imgproc.Imgproc;
22
import org.opencv.test.OpenCVTestCase;
23
24
public class ImgprocTest extends OpenCVTestCase {
25
26
Point anchorPoint;
27
private int imgprocSz;
28
Size size;
29
30
@Override
31
protected void setUp() throws Exception {
32
super.setUp();
33
34
imgprocSz = 2;
35
anchorPoint = new Point(2, 2);
36
size = new Size(3, 3);
37
}
38
39
public void testAccumulateMatMat() {
40
Mat src = getMat(CvType.CV_64F, 2);
41
Mat dst = getMat(CvType.CV_64F, 0);
42
Mat dst2 = src.clone();
43
44
Imgproc.accumulate(src, dst);
45
Imgproc.accumulate(src, dst2);
46
47
assertMatEqual(src, dst, EPS);
48
assertMatEqual(getMat(CvType.CV_64F, 4), dst2, EPS);
49
}
50
51
public void testAccumulateMatMatMat() {
52
Mat src = getMat(CvType.CV_64F, 2);
53
Mat mask = makeMask(getMat(CvType.CV_8U, 1));
54
Mat dst = getMat(CvType.CV_64F, 0);
55
Mat dst2 = src.clone();
56
57
Imgproc.accumulate(src, dst, mask);
58
Imgproc.accumulate(src, dst2, mask);
59
60
assertMatEqual(makeMask(getMat(CvType.CV_64F, 2)), dst, EPS);
61
assertMatEqual(makeMask(getMat(CvType.CV_64F, 4), 2), dst2, EPS);
62
}
63
64
public void testAccumulateProductMatMatMat() {
65
Mat src = getMat(CvType.CV_64F, 2);
66
Mat dst = getMat(CvType.CV_64F, 0);
67
Mat dst2 = src.clone();
68
69
Imgproc.accumulateProduct(src, src, dst);
70
Imgproc.accumulateProduct(src, dst, dst2);
71
72
assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);
73
assertMatEqual(getMat(CvType.CV_64F, 10), dst2, EPS);
74
}
75
76
public void testAccumulateProductMatMatMatMat() {
77
Mat src = getMat(CvType.CV_64F, 2);
78
Mat mask = makeMask(getMat(CvType.CV_8U, 1));
79
Mat dst = getMat(CvType.CV_64F, 0);
80
Mat dst2 = src.clone();
81
82
Imgproc.accumulateProduct(src, src, dst, mask);
83
Imgproc.accumulateProduct(src, dst, dst2, mask);
84
85
assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);
86
assertMatEqual(makeMask(getMat(CvType.CV_64F, 10), 2), dst2, EPS);
87
}
88
89
public void testAccumulateSquareMatMat() {
90
Mat src = getMat(CvType.CV_64F, 2);
91
Mat dst = getMat(CvType.CV_64F, 0);
92
Mat dst2 = src.clone();
93
94
Imgproc.accumulateSquare(src, dst);
95
Imgproc.accumulateSquare(src, dst2);
96
97
assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);
98
assertMatEqual(getMat(CvType.CV_64F, 6), dst2, EPS);
99
}
100
101
public void testAccumulateSquareMatMatMat() {
102
Mat src = getMat(CvType.CV_64F, 2);
103
Mat mask = makeMask(getMat(CvType.CV_8U, 1));
104
Mat dst = getMat(CvType.CV_64F, 0);
105
Mat dst2 = src.clone();
106
107
Imgproc.accumulateSquare(src, dst, mask);
108
Imgproc.accumulateSquare(src, dst2, mask);
109
110
assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);
111
assertMatEqual(makeMask(getMat(CvType.CV_64F, 6), 2), dst2, EPS);
112
}
113
114
public void testAccumulateWeightedMatMatDouble() {
115
Mat src = getMat(CvType.CV_64F, 2);
116
Mat dst = getMat(CvType.CV_64F, 4);
117
Mat dst2 = src.clone();
118
119
Imgproc.accumulateWeighted(src, dst, 0.5);
120
Imgproc.accumulateWeighted(src, dst2, 2);
121
122
assertMatEqual(getMat(CvType.CV_64F, 3), dst, EPS);
123
assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);
124
}
125
126
public void testAccumulateWeightedMatMatDoubleMat() {
127
Mat src = getMat(CvType.CV_64F, 2);
128
Mat mask = makeMask(getMat(CvType.CV_8U, 1));
129
Mat dst = getMat(CvType.CV_64F, 4);
130
Mat dst2 = src.clone();
131
132
Imgproc.accumulateWeighted(src, dst, 0.5, mask);
133
Imgproc.accumulateWeighted(src, dst2, 2, mask);
134
135
assertMatEqual(makeMask(getMat(CvType.CV_64F, 3), 4), dst, EPS);
136
assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);
137
}
138
139
public void testAdaptiveThreshold() {
140
Mat src = makeMask(getMat(CvType.CV_8U, 50), 20);
141
Mat dst = new Mat();
142
143
Imgproc.adaptiveThreshold(src, dst, 1, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 3, 0);
144
145
assertEquals(src.rows(), Core.countNonZero(dst));
146
}
147
148
public void testApproxPolyDP() {
149
MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));
150
151
MatOfPoint2f approxCurve = new MatOfPoint2f();
152
153
Imgproc.approxPolyDP(curve, approxCurve, EPS, true);
154
155
List<Point> approxCurveGold = new ArrayList<Point>(3);
156
approxCurveGold.add(new Point(1, 3));
157
approxCurveGold.add(new Point(3, 5));
158
approxCurveGold.add(new Point(5, 3));
159
160
assertListPointEquals(approxCurve.toList(), approxCurveGold, EPS);
161
}
162
163
public void testArcLength() {
164
MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));
165
166
double arcLength = Imgproc.arcLength(curve, false);
167
168
assertEquals(5.656854249, arcLength, 0.000001);
169
}
170
171
public void testBilateralFilterMatMatIntDoubleDouble() {
172
Imgproc.bilateralFilter(gray255, dst, 5, 10, 5);
173
174
assertMatEqual(gray255, dst);
175
// TODO_: write better test
176
}
177
178
public void testBilateralFilterMatMatIntDoubleDoubleInt() {
179
Imgproc.bilateralFilter(gray255, dst, 5, 10, 5, Core.BORDER_REFLECT);
180
181
assertMatEqual(gray255, dst);
182
// TODO_: write better test
183
}
184
185
public void testBlurMatMatSize() {
186
Imgproc.blur(gray0, dst, size);
187
assertMatEqual(gray0, dst);
188
189
Imgproc.blur(gray255, dst, size);
190
assertMatEqual(gray255, dst);
191
// TODO_: write better test
192
}
193
194
public void testBlurMatMatSizePoint() {
195
Imgproc.blur(gray0, dst, size, anchorPoint);
196
assertMatEqual(gray0, dst);
197
// TODO_: write better test
198
}
199
200
public void testBlurMatMatSizePointInt() {
201
Imgproc.blur(gray0, dst, size, anchorPoint, Core.BORDER_REFLECT);
202
assertMatEqual(gray0, dst);
203
// TODO_: write better test
204
}
205
206
public void testBoundingRect() {
207
MatOfPoint points = new MatOfPoint(new Point(0, 0), new Point(0, 4), new Point(4, 0), new Point(4, 4));
208
Point p1 = new Point(1, 1);
209
Point p2 = new Point(-5, -2);
210
211
Rect bbox = Imgproc.boundingRect(points);
212
213
assertTrue(bbox.contains(p1));
214
assertFalse(bbox.contains(p2));
215
}
216
217
public void testBoxFilterMatMatIntSize() {
218
Size size = new Size(3, 3);
219
Imgproc.boxFilter(gray0, dst, 8, size);
220
assertMatEqual(gray0, dst);
221
// TODO_: write better test
222
}
223
224
public void testBoxFilterMatMatIntSizePointBoolean() {
225
Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false);
226
assertMatEqual(gray255, dst);
227
// TODO_: write better test
228
}
229
230
public void testBoxFilterMatMatIntSizePointBooleanInt() {
231
Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false, Core.BORDER_REFLECT);
232
assertMatEqual(gray255, dst);
233
// TODO_: write better test
234
}
235
236
public void testCalcBackProject() {
237
List<Mat> images = Arrays.asList(grayChess);
238
MatOfInt channels = new MatOfInt(0);
239
MatOfInt histSize = new MatOfInt(10);
240
MatOfFloat ranges = new MatOfFloat(0f, 256f);
241
242
Mat hist = new Mat();
243
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
244
Core.normalize(hist, hist);
245
246
Imgproc.calcBackProject(images, channels, hist, dst, ranges, 255);
247
248
assertEquals(grayChess.size(), dst.size());
249
assertEquals(grayChess.depth(), dst.depth());
250
assertFalse(0 == Core.countNonZero(dst));
251
}
252
253
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat() {
254
List<Mat> images = Arrays.asList(gray128);
255
MatOfInt channels = new MatOfInt(0);
256
MatOfInt histSize = new MatOfInt(10);
257
MatOfFloat ranges = new MatOfFloat(0f, 256f);
258
Mat hist = new Mat();
259
260
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
261
262
truth = new Mat(10, 1, CvType.CV_32F, Scalar.all(0)) {
263
{
264
put(5, 0, 100);
265
}
266
};
267
assertMatEqual(truth, hist, EPS);
268
}
269
270
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2D() {
271
List<Mat> images = Arrays.asList(gray255, gray128);
272
MatOfInt channels = new MatOfInt(0, 1);
273
MatOfInt histSize = new MatOfInt(10, 10);
274
MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
275
Mat hist = new Mat();
276
277
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
278
279
truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {
280
{
281
put(9, 5, 100);
282
}
283
};
284
assertMatEqual(truth, hist, EPS);
285
}
286
287
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat3D() {
288
List<Mat> images = Arrays.asList(rgbLena);
289
290
Mat hist3D = new Mat();
291
List<Mat> histList = Arrays.asList( new Mat[] {new Mat(), new Mat(), new Mat()} );
292
293
MatOfInt histSize = new MatOfInt(10);
294
MatOfFloat ranges = new MatOfFloat(0f, 256f);
295
296
for(int i=0; i<rgbLena.channels(); i++)
297
{
298
Imgproc.calcHist(images, new MatOfInt(i), new Mat(), histList.get(i), histSize, ranges);
299
300
assertEquals(10, histList.get(i).checkVector(1));
301
}
302
303
Core.merge(histList, hist3D);
304
305
assertEquals(CvType.CV_32FC3, hist3D.type());
306
assertEquals(10, hist3D.checkVector(3));
307
308
Mat truth = new Mat(10, 1, CvType.CV_32FC3);
309
truth.put(0, 0,
310
0, 24870, 0,
311
1863, 31926, 1,
312
56682, 37677, 2260,
313
77278, 44751, 32436,
314
69397, 41343, 18526,
315
27180, 40407, 18658,
316
21101, 15993, 32042,
317
8343, 18585, 47786,
318
300, 6567, 80988,
319
0, 25, 29447
320
);
321
322
assertMatEqual(truth, hist3D, EPS);
323
}
324
325
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean() {
326
List<Mat> images = Arrays.asList(gray255, gray128);
327
MatOfInt channels = new MatOfInt(0, 1);
328
MatOfInt histSize = new MatOfInt(10, 10);
329
MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
330
Mat hist = new Mat();
331
332
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges, true);
333
334
truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {
335
{
336
put(9, 5, 100);
337
}
338
};
339
assertMatEqual(truth, hist, EPS);
340
}
341
342
public void testCannyMatMatDoubleDouble() {
343
Imgproc.Canny(gray255, dst, 5, 10);
344
assertMatEqual(gray0, dst);
345
// TODO_: write better test
346
}
347
348
public void testCannyMatMatDoubleDoubleIntBoolean() {
349
Imgproc.Canny(gray0, dst, 5, 10, 5, true);
350
assertMatEqual(gray0, dst);
351
// TODO_: write better test
352
}
353
354
public void testCompareHist() {
355
Mat H1 = new Mat(3, 1, CvType.CV_32F);
356
Mat H2 = new Mat(3, 1, CvType.CV_32F);
357
H1.put(0, 0, 1, 2, 3);
358
H2.put(0, 0, 4, 5, 6);
359
360
double distance = Imgproc.compareHist(H1, H2, Imgproc.CV_COMP_CORREL);
361
362
assertEquals(1., distance, EPS);
363
}
364
365
public void testContourAreaMat() {
366
Mat contour = new Mat(1, 4, CvType.CV_32FC2);
367
contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);
368
369
double area = Imgproc.contourArea(contour);
370
371
assertEquals(45., area, EPS);
372
}
373
374
public void testContourAreaMatBoolean() {
375
Mat contour = new Mat(1, 4, CvType.CV_32FC2);
376
contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);
377
378
double area = Imgproc.contourArea(contour, true);
379
380
assertEquals(45., area, EPS);
381
// TODO_: write better test
382
}
383
384
public void testConvertMapsMatMatMatMatInt() {
385
Mat map1 = new Mat(1, 4, CvType.CV_32FC1, new Scalar(1));
386
Mat map2 = new Mat(1, 4, CvType.CV_32FC1, new Scalar(2));
387
Mat dstmap1 = new Mat(1, 4, CvType.CV_16SC2);
388
Mat dstmap2 = new Mat(1, 4, CvType.CV_16UC1);
389
390
Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2);
391
392
Mat truthMap1 = new Mat(1, 4, CvType.CV_16SC2);
393
truthMap1.put(0, 0, 1, 2, 1, 2, 1, 2, 1, 2);
394
assertMatEqual(truthMap1, dstmap1);
395
Mat truthMap2 = new Mat(1, 4, CvType.CV_16UC1, new Scalar(0));
396
assertMatEqual(truthMap2, dstmap2);
397
}
398
399
public void testConvertMapsMatMatMatMatIntBoolean() {
400
Mat map1 = new Mat(1, 3, CvType.CV_32FC1, new Scalar(2));
401
Mat map2 = new Mat(1, 3, CvType.CV_32FC1, new Scalar(4));
402
Mat dstmap1 = new Mat(1, 3, CvType.CV_16SC2);
403
Mat dstmap2 = new Mat(1, 3, CvType.CV_16UC1);
404
405
Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2, false);
406
// TODO_: write better test (last param == true)
407
408
Mat truthMap1 = new Mat(1, 3, CvType.CV_16SC2);
409
truthMap1.put(0, 0, 2, 4, 2, 4, 2, 4);
410
assertMatEqual(truthMap1, dstmap1);
411
Mat truthMap2 = new Mat(1, 3, CvType.CV_16UC1, new Scalar(0));
412
assertMatEqual(truthMap2, dstmap2);
413
}
414
415
public void testConvexHullMatMat() {
416
MatOfPoint points = new MatOfPoint(
417
new Point(20, 0),
418
new Point(40, 0),
419
new Point(30, 20),
420
new Point(0, 20),
421
new Point(20, 10),
422
new Point(30, 10)
423
);
424
425
MatOfInt hull = new MatOfInt();
426
427
Imgproc.convexHull(points, hull);
428
429
MatOfInt expHull = new MatOfInt(
430
1, 2, 3, 0
431
);
432
assertMatEqual(expHull, hull, EPS);
433
}
434
435
public void testConvexHullMatMatBooleanBoolean() {
436
MatOfPoint points = new MatOfPoint(
437
new Point(2, 0),
438
new Point(4, 0),
439
new Point(3, 2),
440
new Point(0, 2),
441
new Point(2, 1),
442
new Point(3, 1)
443
);
444
445
MatOfInt hull = new MatOfInt();
446
447
Imgproc.convexHull(points, hull, true);
448
449
MatOfInt expHull = new MatOfInt(
450
3, 2, 1, 0
451
);
452
assertMatEqual(expHull, hull, EPS);
453
}
454
455
public void testConvexityDefects() {
456
MatOfPoint points = new MatOfPoint(
457
new Point(20, 0),
458
new Point(40, 0),
459
new Point(30, 20),
460
new Point(0, 20),
461
new Point(20, 10),
462
new Point(30, 10)
463
);
464
465
MatOfInt hull = new MatOfInt();
466
Imgproc.convexHull(points, hull);
467
468
MatOfInt4 convexityDefects = new MatOfInt4();
469
Imgproc.convexityDefects(points, hull, convexityDefects);
470
471
assertMatEqual(new MatOfInt4(3, 0, 5, 3620), convexityDefects);
472
}
473
474
public void testCornerEigenValsAndVecsMatMatIntInt() {
475
fail("Not yet implemented");
476
// TODO: write better test
477
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);
478
src.put(0, 0, 1, 2);
479
src.put(1, 0, 4, 2);
480
481
int blockSize = 3;
482
int ksize = 5;
483
484
// TODO: eigen vals and vectors returned = 0 for most src matrices
485
Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize);
486
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC(6), new Scalar(0));
487
assertMatEqual(truth, dst, EPS);
488
}
489
490
public void testCornerEigenValsAndVecsMatMatIntIntInt() {
491
fail("Not yet implemented");
492
// TODO: write better test
493
Mat src = new Mat(4, 4, CvType.CV_32FC1, new Scalar(128));
494
495
int blockSize = 3;
496
int ksize = 5;
497
498
truth = new Mat(4, 4, CvType.CV_32FC(6), new Scalar(0));
499
500
Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize, Core.BORDER_REFLECT);
501
assertMatEqual(truth, dst, EPS);
502
}
503
504
public void testCornerHarrisMatMatIntIntDouble() {
505
fail("Not yet implemented");
506
// TODO: write better test
507
508
truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
509
int blockSize = 5;
510
int ksize = 7;
511
double k = 0.1;
512
Imgproc.cornerHarris(gray128, dst, blockSize, ksize, k);
513
assertMatEqual(truth, dst, EPS);
514
}
515
516
public void testCornerHarrisMatMatIntIntDoubleInt() {
517
fail("Not yet implemented");
518
// TODO: write better test
519
520
truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
521
int blockSize = 5;
522
int ksize = 7;
523
double k = 0.1;
524
Imgproc.cornerHarris(gray255, dst, blockSize, ksize, k, Core.BORDER_REFLECT);
525
assertMatEqual(truth, dst, EPS);
526
}
527
528
public void testCornerMinEigenValMatMatInt() {
529
fail("Not yet implemented");
530
// TODO: write better test
531
532
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);
533
src.put(0, 0, 1, 2);
534
src.put(1, 0, 2, 1);
535
int blockSize = 5;
536
537
Imgproc.cornerMinEigenVal(src, dst, blockSize);
538
539
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(0));
540
assertMatEqual(truth, dst, EPS);
541
542
Imgproc.cornerMinEigenVal(gray255, dst, blockSize);
543
544
truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
545
assertMatEqual(truth, dst, EPS);
546
}
547
548
public void testCornerMinEigenValMatMatIntInt() {
549
Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
550
int blockSize = 3;
551
int ksize = 5;
552
553
Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize);
554
555
truth = new Mat(3, 3, CvType.CV_32FC1) {
556
{
557
put(0, 0, 1. / 18, 1. / 36, 1. / 18);
558
put(1, 0, 1. / 36, 1. / 18, 1. / 36);
559
put(2, 0, 1. / 18, 1. / 36, 1. / 18);
560
}
561
};
562
assertMatEqual(truth, dst, EPS);
563
}
564
565
public void testCornerMinEigenValMatMatIntIntInt() {
566
Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
567
int blockSize = 3;
568
int ksize = 5;
569
570
Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize, Core.BORDER_REFLECT);
571
572
truth = new Mat(3, 3, CvType.CV_32FC1) {
573
{
574
put(0, 0, 0.68055558, 0.92708349, 0.5868057);
575
put(1, 0, 0.92708343, 0.92708343, 0.92708343);
576
put(2, 0, 0.58680564, 0.92708343, 0.68055564);
577
}
578
};
579
assertMatEqual(truth, dst, EPS);
580
}
581
582
public void testCornerSubPix() {
583
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(128));
584
Point truthPosition = new Point(img.cols() / 2, img.rows() / 2);
585
586
Rect r = new Rect(new Point(0, 0), truthPosition);
587
Imgproc.rectangle(img, r.tl(), r.br(), new Scalar(0), Imgproc.FILLED);
588
MatOfPoint2f corners = new MatOfPoint2f(new Point(truthPosition.x + 1, truthPosition.y + 1));
589
Size winSize = new Size(2, 2);
590
Size zeroZone = new Size(-1, -1);
591
TermCriteria criteria = new TermCriteria(TermCriteria.EPS, 0, 0.01);
592
593
Imgproc.cornerSubPix(img, corners, winSize, zeroZone, criteria);
594
595
assertPointEquals(truthPosition, corners.toList().get(0), weakEPS);
596
}
597
598
public void testCvtColorMatMatInt() {
599
fail("Not yet implemented");
600
}
601
602
public void testCvtColorMatMatIntInt() {
603
fail("Not yet implemented");
604
}
605
606
public void testDilateMatMatMat() {
607
Mat kernel = new Mat();
608
609
Imgproc.dilate(gray255, dst, kernel);
610
611
assertMatEqual(gray255, dst);
612
613
Imgproc.dilate(gray1, dst, kernel);
614
615
assertMatEqual(gray1, dst);
616
// TODO_: write better test
617
}
618
619
public void testDilateMatMatMatPoint() {
620
fail("Not yet implemented");
621
}
622
623
public void testDilateMatMatMatPointInt() {
624
fail("Not yet implemented");
625
}
626
627
public void testDilateMatMatMatPointIntInt() {
628
fail("Not yet implemented");
629
}
630
631
public void testDilateMatMatMatPointIntIntScalar() {
632
fail("Not yet implemented");
633
}
634
635
public void testDistanceTransformWithLabels() {
636
Mat dstLables = getMat(CvType.CV_32SC1, 0);
637
Mat labels = new Mat();
638
639
Imgproc.distanceTransformWithLabels(gray128, dst, labels, Imgproc.CV_DIST_L2, 3);
640
641
assertMatEqual(dstLables, labels);
642
assertMatEqual(getMat(CvType.CV_32FC1, 8192), dst, EPS);
643
}
644
645
public void testDrawContoursMatListOfMatIntScalar() {
646
Imgproc.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100));
647
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
648
Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
649
650
Imgproc.drawContours(gray0, contours, -1, new Scalar(0));
651
652
assertEquals(0, Core.countNonZero(gray0));
653
}
654
655
public void testDrawContoursMatListOfMatIntScalarInt() {
656
Imgproc.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100));
657
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
658
Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
659
660
Imgproc.drawContours(gray0, contours, -1, new Scalar(0), Imgproc.FILLED);
661
662
assertEquals(0, Core.countNonZero(gray0));
663
}
664
665
666
public void testDrawContoursMatListOfMatIntScalarIntIntMatIntPoint() {
667
fail("Not yet implemented");
668
}
669
670
public void testEqualizeHist() {
671
Imgproc.equalizeHist(gray0, dst);
672
assertMatEqual(gray0, dst);
673
674
Imgproc.equalizeHist(gray255, dst);
675
assertMatEqual(gray255, dst);
676
// TODO_: write better test
677
}
678
679
public void testErodeMatMatMat() {
680
Mat kernel = new Mat();
681
682
Imgproc.erode(gray128, dst, kernel);
683
684
assertMatEqual(gray128, dst);
685
}
686
687
public void testErodeMatMatMatPointInt() {
688
Mat src = new Mat(3, 3, CvType.CV_8U) {
689
{
690
put(0, 0, 15, 9, 10);
691
put(1, 0, 10, 8, 12);
692
put(2, 0, 12, 20, 25);
693
}
694
};
695
Mat kernel = new Mat();
696
697
Imgproc.erode(src, dst, kernel, anchorPoint, 10);
698
699
truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));
700
assertMatEqual(truth, dst);
701
}
702
703
public void testErodeMatMatMatPointIntIntScalar() {
704
Mat src = new Mat(3, 3, CvType.CV_8U) {
705
{
706
put(0, 0, 15, 9, 10);
707
put(1, 0, 10, 8, 12);
708
put(2, 0, 12, 20, 25);
709
}
710
};
711
Mat kernel = new Mat();
712
Scalar sc = new Scalar(3, 3);
713
714
Imgproc.erode(src, dst, kernel, anchorPoint, 10, Core.BORDER_REFLECT, sc);
715
716
truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));
717
assertMatEqual(truth, dst);
718
}
719
720
public void testFilter2DMatMatIntMat() {
721
Mat src = Mat.eye(4, 4, CvType.CV_32F);
722
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1));
723
724
Imgproc.filter2D(src, dst, -1, kernel);
725
726
truth = new Mat(4, 4, CvType.CV_32F) {
727
{
728
put(0, 0, 2, 2, 1, 0);
729
put(1, 0, 2, 2, 1, 0);
730
put(2, 0, 1, 1, 2, 1);
731
put(3, 0, 0, 0, 1, 2);
732
}
733
};
734
assertMatEqual(truth, dst, EPS);
735
}
736
737
public void testFilter2DMatMatIntMatPointDouble() {
738
fail("Not yet implemented");
739
}
740
741
public void testFilter2DMatMatIntMatPointDoubleInt() {
742
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));
743
Point point = new Point(0, 0);
744
745
Imgproc.filter2D(gray128, dst, -1, kernel, point, 2, Core.BORDER_CONSTANT);
746
747
assertMatEqual(gray2, dst);
748
}
749
750
public void testFindContoursMatListOfMatMatIntInt() {
751
Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0));
752
List<MatOfPoint> contours = new ArrayList<MatOfPoint>(5);
753
Mat hierarchy = new Mat();
754
755
Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
756
757
// no contours on empty image
758
assertEquals(contours.size(), 0);
759
assertEquals(contours.size(), hierarchy.total());
760
761
Imgproc.rectangle(img, new Point(10, 20), new Point(20, 30), new Scalar(100), 3, Imgproc.LINE_AA, 0);
762
Imgproc.rectangle(img, new Point(30, 35), new Point(40, 45), new Scalar(200));
763
764
Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
765
766
// two contours of two rectangles
767
assertEquals(contours.size(), 2);
768
assertEquals(contours.size(), hierarchy.total());
769
}
770
771
public void testFindContoursMatListOfMatMatIntIntPoint() {
772
Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0));
773
Mat img2 = img.submat(5, 50, 3, 50);
774
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
775
List<MatOfPoint> contours2 = new ArrayList<MatOfPoint>();
776
Mat hierarchy = new Mat();
777
778
Imgproc.rectangle(img, new Point(10, 20), new Point(20, 30), new Scalar(100), 3, Imgproc.LINE_AA, 0);
779
Imgproc.rectangle(img, new Point(30, 35), new Point(40, 45), new Scalar(200));
780
781
Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
782
Imgproc.findContours(img2, contours2, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE, new Point(3, 5));
783
784
assertEquals(contours.size(), contours2.size());
785
assertMatEqual(contours.get(0), contours2.get(0));
786
/*
787
Log.d("findContours", "hierarchy=" + hierarchy);
788
int iBuff[] = new int[ (int) (hierarchy.total() * hierarchy.channels()) ]; // [ Contour0 (next sibling num, previous sibling num, 1st child num, parent num), Contour1(...), ...
789
hierarchy.get(0, 0, iBuff);
790
Log.d("findContours", Arrays.toString(iBuff));
791
*/
792
}
793
794
public void testFitEllipse() {
795
MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-1, 1), new Point(1, 1), new Point(1, -1), new Point(-1, -1));
796
RotatedRect rrect = new RotatedRect();
797
798
rrect = Imgproc.fitEllipse(points);
799
800
assertPointEquals(new Point(0, 0), rrect.center, EPS);
801
assertEquals(2.828, rrect.size.width, EPS);
802
assertEquals(2.828, rrect.size.height, EPS);
803
}
804
805
public void testFitLine() {
806
Mat points = new Mat(1, 4, CvType.CV_32FC2);
807
points.put(0, 0, 0, 0, 2, 3, 3, 4, 5, 8);
808
809
Mat linePoints = new Mat(4, 1, CvType.CV_32FC1);
810
linePoints.put(0, 0, 0.53196341, 0.84676737, 2.496531, 3.7467217);
811
812
Imgproc.fitLine(points, dst, Imgproc.CV_DIST_L12, 0, 0.01, 0.01);
813
814
assertMatEqual(linePoints, dst, EPS);
815
}
816
817
public void testFloodFillMatMatPointScalar() {
818
Mat mask = new Mat(matSize + 2, matSize + 2, CvType.CV_8U, new Scalar(0));
819
Mat img = gray0;
820
Imgproc.circle(mask, new Point(matSize / 2 + 1, matSize / 2 + 1), 3, new Scalar(2));
821
822
int retval = Imgproc.floodFill(img, mask, new Point(matSize / 2, matSize / 2), new Scalar(1));
823
824
assertEquals(Core.countNonZero(img), retval);
825
Imgproc.circle(mask, new Point(matSize / 2 + 1, matSize / 2 + 1), 3, new Scalar(0));
826
assertEquals(retval + 4 * (matSize + 1), Core.countNonZero(mask));
827
assertMatEqual(mask.submat(1, matSize + 1, 1, matSize + 1), img);
828
}
829
830
public void testFloodFillMatMatPointScalar_WithoutMask() {
831
Mat img = gray0;
832
Imgproc.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(2));
833
834
// TODO: ideally we should pass null instead of "new Mat()"
835
int retval = Imgproc.floodFill(img, new Mat(), new Point(matSize / 2, matSize / 2), new Scalar(1));
836
837
Imgproc.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(0));
838
assertEquals(Core.countNonZero(img), retval);
839
}
840
841
public void testFloodFillMatMatPointScalarRect() {
842
fail("Not yet implemented");
843
}
844
845
public void testFloodFillMatMatPointScalarRectScalar() {
846
fail("Not yet implemented");
847
}
848
849
public void testFloodFillMatMatPointScalarRectScalarScalar() {
850
fail("Not yet implemented");
851
}
852
853
public void testFloodFillMatMatPointScalarRectScalarScalarInt() {
854
fail("Not yet implemented");
855
}
856
857
public void testGaussianBlurMatMatSizeDouble() {
858
Imgproc.GaussianBlur(gray0, dst, size, 1);
859
assertMatEqual(gray0, dst);
860
861
Imgproc.GaussianBlur(gray2, dst, size, 1);
862
assertMatEqual(gray2, dst);
863
}
864
865
public void testGaussianBlurMatMatSizeDoubleDouble() {
866
Imgproc.GaussianBlur(gray2, dst, size, 0, 0);
867
868
assertMatEqual(gray2, dst);
869
// TODO_: write better test
870
}
871
872
public void testGaussianBlurMatMatSizeDoubleDoubleInt() {
873
Imgproc.GaussianBlur(gray2, dst, size, 1, 3, Core.BORDER_REFLECT);
874
875
assertMatEqual(gray2, dst);
876
// TODO_: write better test
877
}
878
879
public void testGetAffineTransform() {
880
MatOfPoint2f src = new MatOfPoint2f(new Point(2, 3), new Point(3, 1), new Point(1, 4));
881
MatOfPoint2f dst = new MatOfPoint2f(new Point(3, 3), new Point(7, 4), new Point(5, 6));
882
883
Mat transform = Imgproc.getAffineTransform(src, dst);
884
885
Mat truth = new Mat(2, 3, CvType.CV_64FC1) {
886
{
887
put(0, 0, -8, -6, 37);
888
put(1, 0, -7, -4, 29);
889
}
890
};
891
assertMatEqual(truth, transform, EPS);
892
}
893
894
public void testGetDerivKernelsMatMatIntIntInt() {
895
Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
896
Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
897
Mat expKx = new Mat(3, 1, CvType.CV_32F);
898
Mat expKy = new Mat(3, 1, CvType.CV_32F);
899
kx.put(0, 0, 1, 1);
900
kx.put(1, 0, 1, 1);
901
ky.put(0, 0, 2, 2);
902
ky.put(1, 0, 2, 2);
903
expKx.put(0, 0, 1, -2, 1);
904
expKy.put(0, 0, 1, -2, 1);
905
906
Imgproc.getDerivKernels(kx, ky, 2, 2, 3);
907
908
assertMatEqual(expKx, kx, EPS);
909
assertMatEqual(expKy, ky, EPS);
910
}
911
912
public void testGetDerivKernelsMatMatIntIntIntBooleanInt() {
913
Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
914
Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
915
Mat expKx = new Mat(3, 1, CvType.CV_32F);
916
Mat expKy = new Mat(3, 1, CvType.CV_32F);
917
kx.put(0, 0, 1, 1);
918
kx.put(1, 0, 1, 1);
919
ky.put(0, 0, 2, 2);
920
ky.put(1, 0, 2, 2);
921
expKx.put(0, 0, 1, -2, 1);
922
expKy.put(0, 0, 1, -2, 1);
923
924
Imgproc.getDerivKernels(kx, ky, 2, 2, 3, true, CvType.CV_32F);
925
926
assertMatEqual(expKx, kx, EPS);
927
assertMatEqual(expKy, ky, EPS);
928
// TODO_: write better test
929
}
930
931
public void testGetGaussianKernelIntDouble() {
932
dst = Imgproc.getGaussianKernel(1, 0.5);
933
934
truth = new Mat(1, 1, CvType.CV_64FC1, new Scalar(1));
935
assertMatEqual(truth, dst, EPS);
936
}
937
938
public void testGetGaussianKernelIntDoubleInt() {
939
dst = Imgproc.getGaussianKernel(3, 0.8, CvType.CV_32F);
940
941
truth = new Mat(3, 1, CvType.CV_32F);
942
truth.put(0, 0, 0.23899426, 0.52201146, 0.23899426);
943
assertMatEqual(truth, dst, EPS);
944
}
945
946
public void testGetPerspectiveTransform() {
947
fail("Not yet implemented");
948
}
949
950
public void testGetRectSubPixMatSizePointMat() {
951
Size size = new Size(3, 3);
952
Point center = new Point(gray255.cols() / 2, gray255.rows() / 2);
953
954
Imgproc.getRectSubPix(gray255, size, center, dst);
955
956
truth = new Mat(3, 3, CvType.CV_8U, new Scalar(255));
957
assertMatEqual(truth, dst);
958
}
959
960
public void testGetRectSubPixMatSizePointMatInt() {
961
Mat src = new Mat(10, 10, CvType.CV_32F, new Scalar(2));
962
Size patchSize = new Size(5, 5);
963
Point center = new Point(src.cols() / 2, src.rows() / 2);
964
965
Imgproc.getRectSubPix(src, patchSize, center, dst);
966
967
truth = new Mat(5, 5, CvType.CV_32F, new Scalar(2));
968
assertMatEqual(truth, dst, EPS);
969
}
970
971
public void testGetRotationMatrix2D() {
972
Point center = new Point(0, 0);
973
974
dst = Imgproc.getRotationMatrix2D(center, 0, 1);
975
976
truth = new Mat(2, 3, CvType.CV_64F) {
977
{
978
put(0, 0, 1, 0, 0);
979
put(1, 0, 0, 1, 0);
980
}
981
};
982
983
assertMatEqual(truth, dst, EPS);
984
}
985
986
public void testGetStructuringElementIntSize() {
987
dst = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, size);
988
989
truth = new Mat(3, 3, CvType.CV_8UC1, new Scalar(1));
990
assertMatEqual(truth, dst);
991
}
992
993
public void testGetStructuringElementIntSizePoint() {
994
dst = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, size, anchorPoint);
995
996
truth = new Mat(3, 3, CvType.CV_8UC1) {
997
{
998
put(0, 0, 0, 0, 1);
999
put(1, 0, 0, 0, 1);
1000
put(2, 0, 1, 1, 1);
1001
}
1002
};
1003
assertMatEqual(truth, dst);
1004
}
1005
1006
public void testGoodFeaturesToTrackMatListOfPointIntDoubleDouble() {
1007
Mat src = gray0;
1008
Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
1009
MatOfPoint lp = new MatOfPoint();
1010
1011
Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3);
1012
1013
assertEquals(4, lp.total());
1014
}
1015
1016
public void testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDouble() {
1017
Mat src = gray0;
1018
Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
1019
MatOfPoint lp = new MatOfPoint();
1020
1021
Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3, gray1, 4, 3, true, 0);
1022
1023
assertEquals(4, lp.total());
1024
}
1025
1026
public void testGrabCutMatMatRectMatMatInt() {
1027
fail("Not yet implemented");
1028
}
1029
1030
public void testGrabCutMatMatRectMatMatIntInt() {
1031
fail("Not yet implemented");
1032
}
1033
1034
public void testHoughCirclesMatMatIntDoubleDouble() {
1035
int sz = 512;
1036
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));
1037
Mat circles = new Mat();
1038
1039
Imgproc.HoughCircles(img, circles, Imgproc.CV_HOUGH_GRADIENT, 2, img.rows() / 4);
1040
1041
assertEquals(0, circles.cols());
1042
}
1043
1044
public void testHoughCirclesMatMatIntDoubleDouble1() {
1045
int sz = 512;
1046
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));
1047
Mat circles = new Mat();
1048
1049
Point center = new Point(img.cols() / 2, img.rows() / 2);
1050
int radius = Math.min(img.cols() / 4, img.rows() / 4);
1051
Imgproc.circle(img, center, radius, colorBlack, 3);
1052
1053
Imgproc.HoughCircles(img, circles, Imgproc.CV_HOUGH_GRADIENT, 2, img.rows() / 4);
1054
1055
assertEquals(1, circles.cols());
1056
}
1057
1058
public void testHoughCirclesMatMatIntDoubleDoubleDoubleDoubleIntInt() {
1059
fail("Not yet implemented");
1060
}
1061
1062
public void testHoughLinesMatMatDoubleDoubleInt() {
1063
int sz = 512;
1064
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));
1065
Point point1 = new Point(50, 50);
1066
Point point2 = new Point(img.cols() / 2, img.rows() / 2);
1067
Imgproc.line(img, point1, point2, colorWhite, 1);
1068
Mat lines = new Mat();
1069
1070
Imgproc.HoughLines(img, lines, 1, 3.1415926/180, 100);
1071
1072
assertEquals(1, lines.cols());
1073
1074
/*
1075
Log.d("HoughLines", "lines=" + lines);
1076
int num = (int)lines.total();
1077
int buff[] = new int[num*4]; //[ (x1, y1, x2, y2), (...), ...]
1078
lines.get(0, 0, buff);
1079
Log.d("HoughLines", "lines=" + Arrays.toString(buff));
1080
*/
1081
}
1082
1083
public void testHoughLinesMatMatDoubleDoubleIntDouble() {
1084
fail("Not yet implemented");
1085
}
1086
1087
public void testHoughLinesMatMatDoubleDoubleIntDoubleDouble() {
1088
fail("Not yet implemented");
1089
}
1090
1091
public void testHoughLinesPMatMatDoubleDoubleInt() {
1092
int sz = 512;
1093
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));
1094
Point point1 = new Point(0, 0);
1095
Point point2 = new Point(sz, sz);
1096
Point point3 = new Point(sz, 0);
1097
Point point4 = new Point(2*sz/3, sz/3);
1098
Imgproc.line(img, point1, point2, Scalar.all(255), 1);
1099
Imgproc.line(img, point3, point4, Scalar.all(255), 1);
1100
Mat lines = new Mat();
1101
1102
Imgproc.HoughLinesP(img, lines, 1, 3.1415926/180, 100);
1103
1104
assertEquals(2, lines.rows());
1105
1106
/*
1107
Log.d("HoughLinesP", "lines=" + lines);
1108
int num = (int)lines.cols();
1109
int buff[] = new int[num*4]; // CV_32SC4 as [ (x1, y1, x2, y2), (...), ...]
1110
lines.get(0, 0, buff);
1111
Log.d("HoughLinesP", "lines=" + Arrays.toString(buff));
1112
*/
1113
}
1114
1115
public void testHoughLinesPMatMatDoubleDoubleIntDouble() {
1116
fail("Not yet implemented");
1117
}
1118
1119
public void testHoughLinesPMatMatDoubleDoubleIntDoubleDouble() {
1120
fail("Not yet implemented");
1121
}
1122
1123
public void testHuMoments() {
1124
fail("Not yet implemented");
1125
}
1126
1127
public void testIntegral2MatMatMat() {
1128
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
1129
Mat expSum = new Mat(4, 4, CvType.CV_64F);
1130
Mat expSqsum = new Mat(4, 4, CvType.CV_64F);
1131
Mat sum = new Mat();
1132
Mat sqsum = new Mat();
1133
1134
expSum.put(0, 0, 0, 0, 0, 0);
1135
expSum.put(1, 0, 0, 3, 6, 9);
1136
expSum.put(2, 0, 0, 6, 12, 18);
1137
expSum.put(3, 0, 0, 9, 18, 27);
1138
1139
expSqsum.put(0, 0, 0, 0, 0, 0);
1140
expSqsum.put(1, 0, 0, 9, 18, 27);
1141
expSqsum.put(2, 0, 0, 18, 36, 54);
1142
expSqsum.put(3, 0, 0, 27, 54, 81);
1143
1144
Imgproc.integral2(src, sum, sqsum);
1145
1146
assertMatEqual(expSum, sum, EPS);
1147
assertMatEqual(expSqsum, sqsum, EPS);
1148
}
1149
1150
public void testIntegral2MatMatMatInt() {
1151
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
1152
Mat expSum = new Mat(4, 4, CvType.CV_64F);
1153
Mat expSqsum = new Mat(4, 4, CvType.CV_64F);
1154
Mat sum = new Mat();
1155
Mat sqsum = new Mat();
1156
1157
expSum.put(0, 0, 0, 0, 0, 0);
1158
expSum.put(1, 0, 0, 3, 6, 9);
1159
expSum.put(2, 0, 0, 6, 12, 18);
1160
expSum.put(3, 0, 0, 9, 18, 27);
1161
1162
expSqsum.put(0, 0, 0, 0, 0, 0);
1163
expSqsum.put(1, 0, 0, 9, 18, 27);
1164
expSqsum.put(2, 0, 0, 18, 36, 54);
1165
expSqsum.put(3, 0, 0, 27, 54, 81);
1166
1167
Imgproc.integral2(src, sum, sqsum, CvType.CV_64F, CvType.CV_64F);
1168
1169
assertMatEqual(expSum, sum, EPS);
1170
assertMatEqual(expSqsum, sqsum, EPS);
1171
}
1172
1173
public void testIntegral3MatMatMatMat() {
1174
Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));
1175
Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1176
Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1177
Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1178
Mat sum = new Mat();
1179
Mat sqsum = new Mat();
1180
Mat tilted = new Mat();
1181
1182
expSum.put(0, 0, 0, 0);
1183
expSum.put(1, 0, 0, 1);
1184
1185
expSqsum.put(0, 0, 0, 0);
1186
expSqsum.put(1, 0, 0, 1);
1187
1188
expTilted.put(0, 0, 0, 0);
1189
expTilted.put(1, 0, 0, 1);
1190
1191
Imgproc.integral3(src, sum, sqsum, tilted);
1192
1193
assertMatEqual(expSum, sum, EPS);
1194
assertMatEqual(expSqsum, sqsum, EPS);
1195
assertMatEqual(expTilted, tilted, EPS);
1196
}
1197
1198
public void testIntegral3MatMatMatMatInt() {
1199
Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));
1200
Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1201
Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1202
Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1203
Mat sum = new Mat();
1204
Mat sqsum = new Mat();
1205
Mat tilted = new Mat();
1206
1207
expSum.put(0, 0, 0, 0);
1208
expSum.put(1, 0, 0, 1);
1209
1210
expSqsum.put(0, 0, 0, 0);
1211
expSqsum.put(1, 0, 0, 1);
1212
1213
expTilted.put(0, 0, 0, 0);
1214
expTilted.put(1, 0, 0, 1);
1215
1216
Imgproc.integral3(src, sum, sqsum, tilted, CvType.CV_64F, CvType.CV_64F);
1217
1218
assertMatEqual(expSum, sum, EPS);
1219
assertMatEqual(expSqsum, sqsum, EPS);
1220
assertMatEqual(expTilted, tilted, EPS);
1221
}
1222
1223
public void testIntegralMatMat() {
1224
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1225
1226
Imgproc.integral(src, dst);
1227
1228
truth = new Mat(3, 3, CvType.CV_64F) {
1229
{
1230
put(0, 0, 0, 0, 0);
1231
put(1, 0, 0, 2, 4);
1232
put(2, 0, 0, 4, 8);
1233
}
1234
};
1235
assertMatEqual(truth, dst, EPS);
1236
}
1237
1238
public void testIntegralMatMatInt() {
1239
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1240
1241
Imgproc.integral(src, dst, CvType.CV_64F);
1242
1243
truth = new Mat(3, 3, CvType.CV_64F) {
1244
{
1245
put(0, 0, 0, 0, 0);
1246
put(1, 0, 0, 2, 4);
1247
put(2, 0, 0, 4, 8);
1248
}
1249
};
1250
assertMatEqual(truth, dst, EPS);
1251
}
1252
1253
public void testInvertAffineTransform() {
1254
Mat src = new Mat(2, 3, CvType.CV_64F, new Scalar(1));
1255
1256
Imgproc.invertAffineTransform(src, dst);
1257
1258
truth = new Mat(2, 3, CvType.CV_64F, new Scalar(0));
1259
assertMatEqual(truth, dst, EPS);
1260
}
1261
1262
public void testIsContourConvex() {
1263
MatOfPoint contour1 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4));
1264
1265
assertFalse(Imgproc.isContourConvex(contour1));
1266
1267
MatOfPoint contour2 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6));
1268
1269
assertTrue(Imgproc.isContourConvex(contour2));
1270
}
1271
1272
public void testLaplacianMatMatInt() {
1273
Imgproc.Laplacian(gray0, dst, CvType.CV_8U);
1274
1275
assertMatEqual(gray0, dst);
1276
}
1277
1278
public void testLaplacianMatMatIntIntDoubleDouble() {
1279
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
1280
1281
Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS);
1282
1283
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
1284
{
1285
put(0, 0, -7.9990001, 8.0009995);
1286
put(1, 0, 8.0009995, -7.9990001);
1287
}
1288
};
1289
assertMatEqual(truth, dst, EPS);
1290
}
1291
1292
public void testLaplacianMatMatIntIntDoubleDoubleInt() {
1293
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
1294
1295
Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS, Core.BORDER_REFLECT);
1296
1297
truth = new Mat(3, 3, CvType.CV_32F, new Scalar(0.00099945068));
1298
assertMatEqual(truth, dst, EPS);
1299
}
1300
1301
public void testMatchShapes() {
1302
Mat contour1 = new Mat(1, 4, CvType.CV_32FC2);
1303
Mat contour2 = new Mat(1, 4, CvType.CV_32FC2);
1304
contour1.put(0, 0, 1, 1, 5, 1, 4, 3, 6, 2);
1305
contour2.put(0, 0, 1, 1, 6, 1, 4, 1, 2, 5);
1306
1307
double distance = Imgproc.matchShapes(contour1, contour2, Imgproc.CV_CONTOURS_MATCH_I1, 1);
1308
1309
assertEquals(2.81109697365334, distance, EPS);
1310
}
1311
1312
public void testMatchTemplate() {
1313
Mat image = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
1314
Mat templ = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
1315
image.put(0, 0, 1, 2, 3, 4);
1316
templ.put(0, 0, 5, 6, 7, 8);
1317
1318
Imgproc.matchTemplate(image, templ, dst, Imgproc.TM_CCORR);
1319
1320
truth = new Mat(1, 1, CvType.CV_32F, new Scalar(70));
1321
assertMatEqual(truth, dst, EPS);
1322
1323
Imgproc.matchTemplate(gray255, gray0, dst, Imgproc.TM_CCORR);
1324
1325
truth = new Mat(1, 1, CvType.CV_32F, new Scalar(0));
1326
assertMatEqual(truth, dst, EPS);
1327
}
1328
1329
public void testMedianBlur() {
1330
Imgproc.medianBlur(gray255, dst, 5);
1331
assertMatEqual(gray255, dst);
1332
1333
Imgproc.medianBlur(gray2, dst, 3);
1334
assertMatEqual(gray2, dst);
1335
// TODO_: write better test
1336
}
1337
1338
public void testMinAreaRect() {
1339
MatOfPoint2f points = new MatOfPoint2f(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2));
1340
1341
RotatedRect rrect = Imgproc.minAreaRect(points);
1342
1343
assertEquals(new Size(2, 5), rrect.size);
1344
assertEquals(-90., rrect.angle);
1345
assertEquals(new Point(3.5, 2), rrect.center);
1346
}
1347
1348
public void testMinEnclosingCircle() {
1349
MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-100, 0), new Point(0, -100), new Point(100, 0), new Point(0, 100));
1350
Point actualCenter = new Point();
1351
float[] radius = new float[1];
1352
1353
Imgproc.minEnclosingCircle(points, actualCenter, radius);
1354
1355
assertEquals(new Point(0, 0), actualCenter);
1356
assertEquals(100.0f, radius[0], 1.0);
1357
}
1358
1359
public void testMomentsMat() {
1360
fail("Not yet implemented");
1361
}
1362
1363
public void testMomentsMatBoolean() {
1364
fail("Not yet implemented");
1365
}
1366
1367
public void testMorphologyExMatMatIntMat() {
1368
Imgproc.morphologyEx(gray255, dst, Imgproc.MORPH_GRADIENT, gray0);
1369
1370
assertMatEqual(gray0, dst);
1371
// TODO_: write better test
1372
}
1373
1374
public void testMorphologyExMatMatIntMatPointInt() {
1375
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);
1376
1377
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(0));
1378
Point point = new Point(0, 0);
1379
1380
Imgproc.morphologyEx(src, dst, Imgproc.MORPH_CLOSE, kernel, point, 10);
1381
1382
truth = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);
1383
assertMatEqual(truth, dst);
1384
// TODO_: write better test
1385
}
1386
1387
1388
public void testMorphologyExMatMatIntMatPointIntIntScalar() {
1389
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
1390
src.put(0, 0, 2, 1);
1391
src.put(1, 0, 2, 1);
1392
1393
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(1));
1394
Point point = new Point(1, 1);
1395
Scalar sc = new Scalar(3, 3);
1396
1397
Imgproc.morphologyEx(src, dst, Imgproc.MORPH_TOPHAT, kernel, point, 10, Core.BORDER_REFLECT, sc);
1398
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_8U) {
1399
{
1400
put(0, 0, 1, 0);
1401
put(1, 0, 1, 0);
1402
}
1403
};
1404
assertMatEqual(truth, dst);
1405
// TODO_: write better test
1406
}
1407
1408
public void testPointPolygonTest() {
1409
MatOfPoint2f contour = new MatOfPoint2f(new Point(0, 0), new Point(1, 3), new Point(3, 4), new Point(4, 3), new Point(2, 1));
1410
double sign1 = Imgproc.pointPolygonTest(contour, new Point(2, 2), false);
1411
assertEquals(1.0, sign1);
1412
1413
double sign2 = Imgproc.pointPolygonTest(contour, new Point(4, 4), true);
1414
assertEquals(-Math.sqrt(0.5), sign2);
1415
}
1416
1417
public void testPreCornerDetectMatMatInt() {
1418
Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));
1419
int ksize = 3;
1420
1421
Imgproc.preCornerDetect(src, dst, ksize);
1422
1423
truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
1424
assertMatEqual(truth, dst, EPS);
1425
}
1426
1427
public void testPreCornerDetectMatMatIntInt() {
1428
Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));
1429
int ksize = 3;
1430
1431
Imgproc.preCornerDetect(src, dst, ksize, Core.BORDER_REFLECT);
1432
1433
truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
1434
assertMatEqual(truth, dst, EPS);
1435
// TODO_: write better test
1436
}
1437
1438
public void testPyrDownMatMat() {
1439
Mat src = new Mat(4, 4, CvType.CV_32F) {
1440
{
1441
put(0, 0, 2, 1, 4, 2);
1442
put(1, 0, 3, 2, 6, 8);
1443
put(2, 0, 4, 6, 8, 10);
1444
put(3, 0, 12, 32, 6, 18);
1445
}
1446
};
1447
1448
Imgproc.pyrDown(src, dst);
1449
1450
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
1451
{
1452
put(0, 0, 2.78125, 4.609375);
1453
put(1, 0, 8.546875, 8.8515625);
1454
}
1455
};
1456
assertMatEqual(truth, dst, EPS);
1457
}
1458
1459
public void testPyrDownMatMatSize() {
1460
Mat src = new Mat(4, 4, CvType.CV_32F) {
1461
{
1462
put(0, 0, 2, 1, 4, 2);
1463
put(1, 0, 3, 2, 6, 8);
1464
put(2, 0, 4, 6, 8, 10);
1465
put(3, 0, 12, 32, 6, 18);
1466
}
1467
};
1468
Size dstSize = new Size(2, 2);
1469
1470
Imgproc.pyrDown(src, dst, dstSize);
1471
1472
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
1473
{
1474
put(0, 0, 2.78125, 4.609375);
1475
put(1, 0, 8.546875, 8.8515625);
1476
}
1477
};
1478
assertMatEqual(truth, dst, EPS);
1479
// TODO_: write better test
1480
}
1481
1482
public void testPyrMeanShiftFilteringMatMatDoubleDouble() {
1483
Mat src = new Mat(matSize, matSize, CvType.CV_8UC3, new Scalar(0));
1484
1485
Imgproc.pyrMeanShiftFiltering(src, dst, 10, 50);
1486
1487
assertMatEqual(src, dst);
1488
// TODO_: write better test
1489
}
1490
1491
public void testPyrMeanShiftFilteringMatMatDoubleDoubleInt() {
1492
fail("Not yet implemented");
1493
}
1494
1495
public void testPyrMeanShiftFilteringMatMatDoubleDoubleIntTermCriteria() {
1496
fail("Not yet implemented");
1497
}
1498
1499
public void testPyrUpMatMat() {
1500
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
1501
src.put(0, 0, 2, 1);
1502
src.put(1, 0, 3, 2);
1503
1504
Imgproc.pyrUp(src, dst);
1505
1506
truth = new Mat(4, 4, CvType.CV_32F) {
1507
{
1508
put(0, 0, 2, 1.75, 1.375, 1.25);
1509
put(1, 0, 2.25, 2, 1.625, 1.5);
1510
put(2, 0, 2.625, 2.375, 2, 1.875);
1511
put(3, 0, 2.75, 2.5, 2.125, 2);
1512
}
1513
};
1514
assertMatEqual(truth, dst, EPS);
1515
}
1516
1517
public void testPyrUpMatMatSize() {
1518
fail("Not yet implemented");
1519
}
1520
1521
public void testRemapMatMatMatMatInt() {
1522
fail("Not yet implemented");
1523
// this test does something weird
1524
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1525
Mat map1 = new Mat(1, 3, CvType.CV_32FC1);
1526
Mat map2 = new Mat(1, 3, CvType.CV_32FC1);
1527
1528
map1.put(0, 0, 3, 6, 5);
1529
map2.put(0, 0, 4, 8, 12);
1530
1531
Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR);
1532
1533
truth = new Mat(1, 3, CvType.CV_32F, new Scalar(0));
1534
assertMatEqual(truth, dst, EPS);
1535
}
1536
1537
public void testRemapMatMatMatMatIntIntScalar() {
1538
fail("Not yet implemented");
1539
// this test does something weird
1540
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1541
Mat map1 = new Mat(1, 3, CvType.CV_32FC1);
1542
Mat map2 = new Mat(1, 3, CvType.CV_32FC1);
1543
1544
Scalar sc = new Scalar(0);
1545
1546
map1.put(0, 0, 3, 6, 5, 0);
1547
map2.put(0, 0, 4, 8, 12);
1548
1549
truth = new Mat(1, 3, CvType.CV_32F, new Scalar(2));
1550
1551
Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR, Core.BORDER_REFLECT, sc);
1552
assertMatEqual(truth, dst, EPS);
1553
}
1554
1555
public void testResizeMatMatSize() {
1556
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8UC1, new Scalar(1));
1557
Size dsize = new Size(1, 1);
1558
1559
Imgproc.resize(src, dst, dsize, 0, 0, Imgproc.INTER_LINEAR_EXACT);
1560
1561
truth = new Mat(1, 1, CvType.CV_8UC1, new Scalar(1));
1562
assertMatEqual(truth, dst);
1563
}
1564
1565
public void testResizeMatMatSizeDoubleDoubleInt() {
1566
Imgproc.resize(gray255, dst, new Size(2, 2), 0, 0, Imgproc.INTER_AREA);
1567
1568
truth = new Mat(2, 2, CvType.CV_8UC1, new Scalar(255));
1569
assertMatEqual(truth, dst);
1570
// TODO_: write better test
1571
}
1572
1573
public void testScharrMatMatIntIntInt() {
1574
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
1575
1576
Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0);
1577
1578
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));
1579
assertMatEqual(truth, dst, EPS);
1580
}
1581
1582
public void testScharrMatMatIntIntIntDoubleDouble() {
1583
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
1584
1585
Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0.001);
1586
1587
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0.001));
1588
assertMatEqual(truth, dst, EPS);
1589
}
1590
1591
public void testScharrMatMatIntIntIntDoubleDoubleInt() {
1592
Mat src = Mat.eye(3, 3, CvType.CV_32F);
1593
1594
Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0, Core.BORDER_REFLECT);
1595
1596
truth = new Mat(3, 3, CvType.CV_32F) {
1597
{
1598
put(0, 0, -15, -19.5, -4.5);
1599
put(1, 0, 10.5, 0, -10.5);
1600
put(2, 0, 4.5, 19.5, 15);
1601
}
1602
};
1603
assertMatEqual(truth, dst, EPS);
1604
}
1605
1606
public void testSepFilter2DMatMatIntMatMat() {
1607
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1608
Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
1609
Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
1610
kernelX.put(0, 0, 4, 3, 7);
1611
kernelY.put(0, 0, 9, 4, 2);
1612
1613
Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY);
1614
1615
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(420));
1616
assertMatEqual(truth, dst, EPS);
1617
}
1618
1619
public void testSepFilter2DMatMatIntMatMatPointDouble() {
1620
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(2));
1621
Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
1622
kernelX.put(0, 0, 2, 2, 2);
1623
Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
1624
kernelY.put(0, 0, 1, 1, 1);
1625
1626
Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS);
1627
1628
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(36 + weakEPS));
1629
assertMatEqual(truth, dst, EPS);
1630
}
1631
1632
public void testSepFilter2DMatMatIntMatMatPointDoubleInt() {
1633
Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
1634
kernelX.put(0, 0, 2, 2, 2);
1635
1636
Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
1637
kernelY.put(0, 0, 1, 1, 1);
1638
1639
Imgproc.sepFilter2D(gray0, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS, Core.BORDER_REFLECT);
1640
1641
truth = new Mat(10, 10, CvType.CV_32F, new Scalar(weakEPS));
1642
assertMatEqual(truth, dst, EPS);
1643
// TODO_: write better test
1644
}
1645
1646
public void testSobelMatMatIntIntInt() {
1647
Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0);
1648
1649
assertMatEqual(gray0, dst);
1650
}
1651
1652
public void testSobelMatMatIntIntIntIntDoubleDouble() {
1653
Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0, 3, 2, 0.001);
1654
assertMatEqual(gray0, dst);
1655
// TODO_: write better test
1656
}
1657
1658
public void testSobelMatMatIntIntIntIntDoubleDoubleInt() {
1659
Mat src = new Mat(3, 3, CvType.CV_32F) {
1660
{
1661
put(0, 0, 2, 0, 1);
1662
put(1, 0, 6, 4, 3);
1663
put(2, 0, 1, 0, 2);
1664
}
1665
};
1666
1667
Imgproc.Sobel(src, dst, CvType.CV_32F, 1, 0, 3, 2, 0, Core.BORDER_REPLICATE);
1668
1669
truth = new Mat(3, 3, CvType.CV_32F) {
1670
{
1671
put(0, 0, -16, -12, 4);
1672
put(1, 0, -14, -12, 2);
1673
put(2, 0, -10, 0, 10);
1674
}
1675
};
1676
assertMatEqual(truth, dst, EPS);
1677
}
1678
1679
public void testThreshold() {
1680
Imgproc.threshold(makeMask(gray0.clone(), 10), dst, 5, 255, Imgproc.THRESH_TRUNC);
1681
assertMatEqual(makeMask(gray0.clone(), 5), dst);
1682
1683
Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 1, 255, Imgproc.THRESH_BINARY);
1684
assertMatEqual(gray255, dst);
1685
1686
Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 3, 255, Imgproc.THRESH_BINARY_INV);
1687
assertMatEqual(makeMask(gray255.clone(), 0), dst);
1688
}
1689
1690
public void testWarpAffineMatMatMatSize() {
1691
Mat src = new Mat(3, 3, CvType.CV_32F) {
1692
{
1693
put(0, 0, 2, 0, 1);
1694
put(1, 0, 6, 4, 3);
1695
put(2, 0, 1, 0, 2);
1696
}
1697
};
1698
Mat M = new Mat(2, 3, CvType.CV_32F) {
1699
{
1700
put(0, 0, 1, 0, 1);
1701
put(1, 0, 0, 1, 1);
1702
}
1703
};
1704
1705
Imgproc.warpAffine(src, dst, M, new Size(3, 3));
1706
1707
truth = new Mat(3, 3, CvType.CV_32F) {
1708
{
1709
put(0, 0, 0, 0, 0);
1710
put(1, 0, 0, 2, 0);
1711
put(2, 0, 0, 6, 4);
1712
}
1713
};
1714
assertMatEqual(truth, dst, EPS);
1715
}
1716
1717
public void testWarpAffineMatMatMatSizeInt() {
1718
Mat src = new Mat(3, 3, CvType.CV_32F) {
1719
{
1720
put(0, 0, 2, 4, 1);
1721
put(1, 0, 6, 4, 3);
1722
put(2, 0, 0, 2, 2);
1723
}
1724
};
1725
Mat M = new Mat(2, 3, CvType.CV_32F) {
1726
{
1727
put(0, 0, 1, 0, 0);
1728
put(1, 0, 0, 0, 1);
1729
}
1730
};
1731
1732
Imgproc.warpAffine(src, dst, M, new Size(2, 2), Imgproc.WARP_INVERSE_MAP);
1733
1734
truth = new Mat(2, 2, CvType.CV_32F) {
1735
{
1736
put(0, 0, 6, 4);
1737
put(1, 0, 6, 4);
1738
}
1739
};
1740
assertMatEqual(truth, dst, EPS);
1741
}
1742
1743
public void testWarpAffineMatMatMatSizeIntInt() {
1744
fail("Not yet implemented");
1745
}
1746
1747
public void testWarpAffineMatMatMatSizeIntIntScalar() {
1748
fail("Not yet implemented");
1749
}
1750
1751
public void testWarpPerspectiveMatMatMatSize() {
1752
Mat src = new Mat(3, 3, CvType.CV_32F) {
1753
{
1754
put(0, 0, 2, 4, 1);
1755
put(1, 0, 0, 4, 5);
1756
put(2, 0, 1, 2, 2);
1757
}
1758
};
1759
Mat M = new Mat(3, 3, CvType.CV_32F) {
1760
{
1761
put(0, 0, 1, 0, 1);
1762
put(1, 0, 0, 1, 1);
1763
put(2, 0, 0, 0, 1);
1764
}
1765
};
1766
1767
Imgproc.warpPerspective(src, dst, M, new Size(3, 3));
1768
1769
truth = new Mat(3, 3, CvType.CV_32F) {
1770
{
1771
put(0, 0, 0, 0, 0);
1772
put(1, 0, 0, 2, 4);
1773
put(2, 0, 0, 0, 4);
1774
}
1775
};
1776
assertMatEqual(truth, dst, EPS);
1777
}
1778
1779
public void testWarpPerspectiveMatMatMatSizeInt() {
1780
fail("Not yet implemented");
1781
}
1782
1783
public void testWarpPerspectiveMatMatMatSizeIntInt() {
1784
fail("Not yet implemented");
1785
}
1786
1787
public void testWarpPerspectiveMatMatMatSizeIntIntScalar() {
1788
fail("Not yet implemented");
1789
}
1790
1791
public void testWatershed() {
1792
Mat image = Mat.eye(4, 4, CvType.CV_8UC(3));
1793
Mat markers = new Mat(4, 4, CvType.CV_32SC1, new Scalar(0));
1794
1795
Imgproc.watershed(image, markers);
1796
1797
truth = new Mat(4, 4, CvType.CV_32SC1) {
1798
{
1799
put(0, 0, -1, -1, -1, -1);
1800
put(1, 0, -1, 0, 0, -1);
1801
put(2, 0, -1, 0, 0, -1);
1802
put(3, 0, -1, -1, -1, -1);
1803
}
1804
};
1805
assertMatEqual(truth, markers);
1806
}
1807
1808
public void testGetTextSize() {
1809
String text = "Android all the way";
1810
double fontScale = 2;
1811
int thickness = 3;
1812
int baseLine[] = new int[1];
1813
1814
Imgproc.getTextSize(text, Imgproc.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, null);
1815
Size res = Imgproc.getTextSize(text, Imgproc.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, baseLine);
1816
1817
assertEquals(543.0, res.width);
1818
assertEquals(44.0, res.height);
1819
assertEquals(20, baseLine[0]);
1820
}
1821
1822
public void testCircleMatPointIntScalar() {
1823
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
1824
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
1825
Scalar color = new Scalar(128);
1826
1827
Imgproc.circle(gray0, center, radius, color);
1828
1829
assertTrue(0 != Core.countNonZero(gray0));
1830
}
1831
1832
public void testCircleMatPointIntScalarInt() {
1833
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
1834
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
1835
Scalar color = new Scalar(128);
1836
1837
Imgproc.circle(gray0, center, radius, color, Imgproc.FILLED);
1838
1839
assertTrue(0 != Core.countNonZero(gray0));
1840
}
1841
1842
public void testCircleMatPointIntScalarIntIntInt() {
1843
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
1844
Point center2 = new Point(gray0.cols(), gray0.rows());
1845
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
1846
Scalar color128 = new Scalar(128);
1847
Scalar color0 = new Scalar(0);
1848
1849
Imgproc.circle(gray0, center2, radius * 2, color128, 2, Imgproc.LINE_4, 1/*
1850
* Number
1851
* of
1852
* fractional
1853
* bits
1854
*/);
1855
assertFalse(0 == Core.countNonZero(gray0));
1856
1857
Imgproc.circle(gray0, center, radius, color0, 2, Imgproc.LINE_4, 0);
1858
1859
assertTrue(0 == Core.countNonZero(gray0));
1860
}
1861
1862
public void testClipLine() {
1863
Rect r = new Rect(10, 10, 10, 10);
1864
Point pt1 = new Point(5.0, 15.0);
1865
Point pt2 = new Point(25.0, 15.0);
1866
1867
assertTrue(Imgproc.clipLine(r, pt1, pt2));
1868
1869
Point pt1Clipped = new Point(10.0, 15.0);
1870
Point pt2Clipped = new Point(19.0, 15.0);
1871
assertEquals(pt1Clipped, pt1);
1872
assertEquals(pt2Clipped, pt2);
1873
1874
pt1 = new Point(5.0, 5.0);
1875
pt2 = new Point(25.0, 5.0);
1876
pt1Clipped = new Point(5.0, 5.0);
1877
pt2Clipped = new Point(25.0, 5.0);
1878
1879
assertFalse(Imgproc.clipLine(r, pt1, pt2));
1880
1881
assertEquals(pt1Clipped, pt1);
1882
assertEquals(pt2Clipped, pt2);
1883
}
1884
1885
public void testEllipse2Poly() {
1886
Point center = new Point(4, 4);
1887
Size axes = new Size(2, 2);
1888
int angle = 30;
1889
int arcStart = 30;
1890
int arcEnd = 60;
1891
int delta = 2;
1892
MatOfPoint pts = new MatOfPoint();
1893
1894
Imgproc.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts);
1895
1896
Point truth[] = {
1897
new Point(5, 6),
1898
new Point(4, 6)
1899
};
1900
assertArrayPointsEquals(truth, pts.toArray(), EPS);
1901
}
1902
1903
public void testEllipseMatPointSizeDoubleDoubleDoubleScalar() {
1904
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
1905
Size axes = new Size(2, 2);
1906
double angle = 30, startAngle = 60, endAngle = 90;
1907
1908
Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite);
1909
1910
assertTrue(0 != Core.countNonZero(gray0));
1911
}
1912
1913
public void testEllipseMatPointSizeDoubleDoubleDoubleScalarInt() {
1914
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
1915
Size axes = new Size(2, 2);
1916
double angle = 30, startAngle = 60, endAngle = 90;
1917
1918
Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Imgproc.FILLED);
1919
1920
assertTrue(0 != Core.countNonZero(gray0));
1921
}
1922
1923
public void testEllipseMatPointSizeDoubleDoubleDoubleScalarIntIntInt() {
1924
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
1925
Size axes = new Size(2, 2);
1926
Point center2 = new Point(gray0.cols(), gray0.rows());
1927
Size axes2 = new Size(4, 4);
1928
double angle = 30, startAngle = 0, endAngle = 30;
1929
1930
Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Imgproc.FILLED, Imgproc.LINE_4, 0);
1931
1932
assertTrue(0 != Core.countNonZero(gray0));
1933
1934
Imgproc.ellipse(gray0, center2, axes2, angle, startAngle, endAngle, colorBlack, Imgproc.FILLED, Imgproc.LINE_4, 1);
1935
1936
assertEquals(0, Core.countNonZero(gray0));
1937
}
1938
1939
public void testEllipseMatRotatedRectScalar() {
1940
int matSize = 10;
1941
Mat gray0 = Mat.zeros(matSize, matSize, CvType.CV_8U);
1942
Point center = new Point(matSize / 2, matSize / 2);
1943
Size size = new Size(matSize / 4, matSize / 2);
1944
RotatedRect box = new RotatedRect(center, size, 45);
1945
1946
Imgproc.ellipse(gray0, box, new Scalar(1));
1947
1948
final byte[] truth = new byte[] {
1949
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1950
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1951
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1952
0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
1953
0, 0, 0, 0, 1, 1, 0, 1, 0, 0,
1954
0, 0, 0, 0, 1, 0, 1, 0, 0, 0,
1955
0, 0, 0, 1, 0, 1, 1, 0, 0, 0,
1956
0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
1957
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1958
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1959
1960
assertMatEqual(new Mat(matSize, matSize, CvType.CV_8U) {
1961
{
1962
put(0, 0, truth);
1963
}
1964
}, gray0);
1965
}
1966
1967
public void testEllipseMatRotatedRectScalarInt() {
1968
Point center = new Point(matSize / 2, matSize / 2);
1969
Size size = new Size(matSize / 4, matSize / 2);
1970
RotatedRect box = new RotatedRect(center, size, 45);
1971
1972
Imgproc.ellipse(gray0, box, new Scalar(1), Imgproc.FILLED);
1973
Imgproc.ellipse(gray0, box, new Scalar(0));
1974
1975
assertTrue(0 < Core.countNonZero(gray0));
1976
}
1977
1978
public void testEllipseMatRotatedRectScalarIntInt() {
1979
Point center = new Point(matSize / 2, matSize / 2);
1980
Size size = new Size(2, matSize * 2 / 3);
1981
RotatedRect box = new RotatedRect(center, size, 20);
1982
1983
Imgproc.ellipse(gray0, box, new Scalar(9), 1, Imgproc.LINE_AA);
1984
Imgproc.ellipse(gray0, box, new Scalar(0), 1, Imgproc.LINE_4);
1985
1986
assertTrue(0 < Core.countNonZero(gray0));
1987
}
1988
1989
public void testPolylinesMatListOfListOfPointBooleanScalar() {
1990
Mat img = gray0;
1991
List<MatOfPoint> polyline = new ArrayList<MatOfPoint>();
1992
polyline.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
1993
1994
Imgproc.polylines(img, polyline, true, new Scalar(100));
1995
1996
assertEquals(22, Core.countNonZero(img));
1997
1998
Imgproc.polylines(img, polyline, false, new Scalar(0));
1999
2000
assertEquals(4, Core.countNonZero(img));
2001
}
2002
2003
public void testPolylinesMatListOfListOfPointBooleanScalarInt() {
2004
Mat img = gray0;
2005
List<MatOfPoint> polyline = new ArrayList<MatOfPoint>();
2006
polyline.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
2007
2008
Imgproc.polylines(img, polyline, true, new Scalar(100), 2);
2009
2010
assertEquals(62, Core.countNonZero(img));
2011
}
2012
2013
public void testPolylinesMatListOfListOfPointBooleanScalarIntIntInt() {
2014
Mat img = gray0;
2015
List<MatOfPoint> polyline1 = new ArrayList<MatOfPoint>();
2016
polyline1.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
2017
List<MatOfPoint> polyline2 = new ArrayList<MatOfPoint>();
2018
polyline2.add(new MatOfPoint(new Point(2, 2), new Point(14, 2), new Point(14, 12), new Point(2, 12)));
2019
2020
Imgproc.polylines(img, polyline1, true, new Scalar(100), 2, Imgproc.LINE_8, 0);
2021
2022
assertTrue(Core.countNonZero(img) > 0);
2023
2024
Imgproc.polylines(img, polyline2, true, new Scalar(0), 2, Imgproc.LINE_8, 1);
2025
2026
assertEquals(0, Core.countNonZero(img));
2027
}
2028
2029
public void testPutTextMatStringPointIntDoubleScalar() {
2030
String text = "Hello World";
2031
Size labelSize = new Size(175, 22);
2032
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
2033
Point origin = new Point(10, labelSize.height + 10);
2034
2035
Imgproc.putText(img, text, origin, Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite);
2036
2037
assertTrue(Core.countNonZero(img) > 0);
2038
// check that border is not corrupted
2039
Imgproc.rectangle(img, new Point(11, 11), new Point(labelSize.width + 10, labelSize.height + 10), colorBlack, Imgproc.FILLED);
2040
assertEquals(0, Core.countNonZero(img));
2041
}
2042
2043
public void testPutTextMatStringPointIntDoubleScalarInt() {
2044
String text = "Hello World";
2045
Size labelSize = new Size(176, 22);
2046
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
2047
Point origin = new Point(10, labelSize.height + 10);
2048
2049
Imgproc.putText(img, text, origin, Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite, 2);
2050
2051
assertTrue(Core.countNonZero(img) > 0);
2052
// check that border is not corrupted
2053
Imgproc.rectangle(img, new Point(10, 10), new Point(labelSize.width + 10 + 1, labelSize.height + 10 + 1), colorBlack, Imgproc.FILLED);
2054
assertEquals(0, Core.countNonZero(img));
2055
}
2056
2057
public void testPutTextMatStringPointIntDoubleScalarIntIntBoolean() {
2058
String text = "Hello World";
2059
Size labelSize = new Size(175, 22);
2060
2061
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
2062
Point origin = new Point(10, 10);
2063
2064
Imgproc.putText(img, text, origin, Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite, 1, Imgproc.LINE_8, true);
2065
2066
assertTrue(Core.countNonZero(img) > 0);
2067
// check that border is not corrupted
2068
Imgproc.rectangle(img, new Point(10, 10), new Point(labelSize.width + 9, labelSize.height + 9), colorBlack, Imgproc.FILLED);
2069
assertEquals(0, Core.countNonZero(img));
2070
}
2071
}
2072
2073