1
package org.opencv.test.imgproc;
3
import java.util.ArrayList;
4
import java.util.Arrays;
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;
24
public class ImgprocTest extends OpenCVTestCase {
27
private int imgprocSz;
31
protected void setUp() throws Exception {
35
anchorPoint = new Point(2, 2);
36
size = new Size(3, 3);
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();
44
Imgproc.accumulate(src, dst);
45
Imgproc.accumulate(src, dst2);
47
assertMatEqual(src, dst, EPS);
48
assertMatEqual(getMat(CvType.CV_64F, 4), dst2, EPS);
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();
57
Imgproc.accumulate(src, dst, mask);
58
Imgproc.accumulate(src, dst2, mask);
60
assertMatEqual(makeMask(getMat(CvType.CV_64F, 2)), dst, EPS);
61
assertMatEqual(makeMask(getMat(CvType.CV_64F, 4), 2), dst2, EPS);
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();
69
Imgproc.accumulateProduct(src, src, dst);
70
Imgproc.accumulateProduct(src, dst, dst2);
72
assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);
73
assertMatEqual(getMat(CvType.CV_64F, 10), dst2, EPS);
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();
82
Imgproc.accumulateProduct(src, src, dst, mask);
83
Imgproc.accumulateProduct(src, dst, dst2, mask);
85
assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);
86
assertMatEqual(makeMask(getMat(CvType.CV_64F, 10), 2), dst2, EPS);
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();
94
Imgproc.accumulateSquare(src, dst);
95
Imgproc.accumulateSquare(src, dst2);
97
assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);
98
assertMatEqual(getMat(CvType.CV_64F, 6), dst2, EPS);
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();
107
Imgproc.accumulateSquare(src, dst, mask);
108
Imgproc.accumulateSquare(src, dst2, mask);
110
assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);
111
assertMatEqual(makeMask(getMat(CvType.CV_64F, 6), 2), dst2, EPS);
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();
119
Imgproc.accumulateWeighted(src, dst, 0.5);
120
Imgproc.accumulateWeighted(src, dst2, 2);
122
assertMatEqual(getMat(CvType.CV_64F, 3), dst, EPS);
123
assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);
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();
132
Imgproc.accumulateWeighted(src, dst, 0.5, mask);
133
Imgproc.accumulateWeighted(src, dst2, 2, mask);
135
assertMatEqual(makeMask(getMat(CvType.CV_64F, 3), 4), dst, EPS);
136
assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);
139
public void testAdaptiveThreshold() {
140
Mat src = makeMask(getMat(CvType.CV_8U, 50), 20);
143
Imgproc.adaptiveThreshold(src, dst, 1, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 3, 0);
145
assertEquals(src.rows(), Core.countNonZero(dst));
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));
151
MatOfPoint2f approxCurve = new MatOfPoint2f();
153
Imgproc.approxPolyDP(curve, approxCurve, EPS, true);
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));
160
assertListPointEquals(approxCurve.toList(), approxCurveGold, EPS);
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));
166
double arcLength = Imgproc.arcLength(curve, false);
168
assertEquals(5.656854249, arcLength, 0.000001);
171
public void testBilateralFilterMatMatIntDoubleDouble() {
172
Imgproc.bilateralFilter(gray255, dst, 5, 10, 5);
174
assertMatEqual(gray255, dst);
175
// TODO_: write better test
178
public void testBilateralFilterMatMatIntDoubleDoubleInt() {
179
Imgproc.bilateralFilter(gray255, dst, 5, 10, 5, Core.BORDER_REFLECT);
181
assertMatEqual(gray255, dst);
182
// TODO_: write better test
185
public void testBlurMatMatSize() {
186
Imgproc.blur(gray0, dst, size);
187
assertMatEqual(gray0, dst);
189
Imgproc.blur(gray255, dst, size);
190
assertMatEqual(gray255, dst);
191
// TODO_: write better test
194
public void testBlurMatMatSizePoint() {
195
Imgproc.blur(gray0, dst, size, anchorPoint);
196
assertMatEqual(gray0, dst);
197
// TODO_: write better test
200
public void testBlurMatMatSizePointInt() {
201
Imgproc.blur(gray0, dst, size, anchorPoint, Core.BORDER_REFLECT);
202
assertMatEqual(gray0, dst);
203
// TODO_: write better test
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);
211
Rect bbox = Imgproc.boundingRect(points);
213
assertTrue(bbox.contains(p1));
214
assertFalse(bbox.contains(p2));
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
224
public void testBoxFilterMatMatIntSizePointBoolean() {
225
Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false);
226
assertMatEqual(gray255, dst);
227
// TODO_: write better test
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
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);
242
Mat hist = new Mat();
243
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
244
Core.normalize(hist, hist);
246
Imgproc.calcBackProject(images, channels, hist, dst, ranges, 255);
248
assertEquals(grayChess.size(), dst.size());
249
assertEquals(grayChess.depth(), dst.depth());
250
assertFalse(0 == Core.countNonZero(dst));
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();
260
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
262
truth = new Mat(10, 1, CvType.CV_32F, Scalar.all(0)) {
267
assertMatEqual(truth, hist, EPS);
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();
277
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
279
truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {
284
assertMatEqual(truth, hist, EPS);
287
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat3D() {
288
List<Mat> images = Arrays.asList(rgbLena);
290
Mat hist3D = new Mat();
291
List<Mat> histList = Arrays.asList( new Mat[] {new Mat(), new Mat(), new Mat()} );
293
MatOfInt histSize = new MatOfInt(10);
294
MatOfFloat ranges = new MatOfFloat(0f, 256f);
296
for(int i=0; i<rgbLena.channels(); i++)
298
Imgproc.calcHist(images, new MatOfInt(i), new Mat(), histList.get(i), histSize, ranges);
300
assertEquals(10, histList.get(i).checkVector(1));
303
Core.merge(histList, hist3D);
305
assertEquals(CvType.CV_32FC3, hist3D.type());
306
assertEquals(10, hist3D.checkVector(3));
308
Mat truth = new Mat(10, 1, CvType.CV_32FC3);
322
assertMatEqual(truth, hist3D, EPS);
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();
332
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges, true);
334
truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {
339
assertMatEqual(truth, hist, EPS);
342
public void testCannyMatMatDoubleDouble() {
343
Imgproc.Canny(gray255, dst, 5, 10);
344
assertMatEqual(gray0, dst);
345
// TODO_: write better test
348
public void testCannyMatMatDoubleDoubleIntBoolean() {
349
Imgproc.Canny(gray0, dst, 5, 10, 5, true);
350
assertMatEqual(gray0, dst);
351
// TODO_: write better test
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);
360
double distance = Imgproc.compareHist(H1, H2, Imgproc.CV_COMP_CORREL);
362
assertEquals(1., distance);
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);
369
double area = Imgproc.contourArea(contour);
371
assertEquals(45., area);
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);
378
double area = Imgproc.contourArea(contour, true);
380
assertEquals(45., area);
381
// TODO_: write better test
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);
390
Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2);
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);
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);
405
Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2, false);
406
// TODO_: write better test (last param == true)
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);
415
public void testConvexHullMatMat() {
416
MatOfPoint points = new MatOfPoint(
425
MatOfInt hull = new MatOfInt();
427
Imgproc.convexHull(points, hull);
429
MatOfInt expHull = new MatOfInt(
432
assertMatEqual(expHull, hull, EPS);
435
public void testConvexHullMatMatBooleanBoolean() {
436
MatOfPoint points = new MatOfPoint(
445
MatOfInt hull = new MatOfInt();
447
Imgproc.convexHull(points, hull, true);
449
MatOfInt expHull = new MatOfInt(
452
assertMatEqual(expHull, hull, EPS);
455
public void testConvexityDefects() {
456
MatOfPoint points = new MatOfPoint(
465
MatOfInt hull = new MatOfInt();
466
Imgproc.convexHull(points, hull);
468
MatOfInt4 convexityDefects = new MatOfInt4();
469
Imgproc.convexityDefects(points, hull, convexityDefects);
471
assertMatEqual(new MatOfInt4(3, 0, 5, 3620), convexityDefects);
474
public void testCornerEigenValsAndVecsMatMatIntInt() {
475
fail("Not yet implemented");
476
// TODO: write better test
477
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);
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);
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));
498
truth = new Mat(4, 4, CvType.CV_32FC(6), new Scalar(0));
500
Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize, Core.BORDER_REFLECT);
501
assertMatEqual(truth, dst, EPS);
504
public void testCornerHarrisMatMatIntIntDouble() {
505
fail("Not yet implemented");
506
// TODO: write better test
508
truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
512
Imgproc.cornerHarris(gray128, dst, blockSize, ksize, k);
513
assertMatEqual(truth, dst, EPS);
516
public void testCornerHarrisMatMatIntIntDoubleInt() {
517
fail("Not yet implemented");
518
// TODO: write better test
520
truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
524
Imgproc.cornerHarris(gray255, dst, blockSize, ksize, k, Core.BORDER_REFLECT);
525
assertMatEqual(truth, dst, EPS);
528
public void testCornerMinEigenValMatMatInt() {
529
fail("Not yet implemented");
530
// TODO: write better test
532
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);
537
Imgproc.cornerMinEigenVal(src, dst, blockSize);
539
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(0));
540
assertMatEqual(truth, dst, EPS);
542
Imgproc.cornerMinEigenVal(gray255, dst, blockSize);
544
truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
545
assertMatEqual(truth, dst, EPS);
548
public void testCornerMinEigenValMatMatIntInt() {
549
Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
553
Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize);
555
truth = new Mat(3, 3, CvType.CV_32FC1) {
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);
562
assertMatEqual(truth, dst, EPS);
565
public void testCornerMinEigenValMatMatIntIntInt() {
566
Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
570
Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize, Core.BORDER_REFLECT);
572
truth = new Mat(3, 3, CvType.CV_32FC1) {
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);
579
assertMatEqual(truth, dst, EPS);
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);
586
Rect r = new Rect(new Point(0, 0), truthPosition);
587
Imgproc.rectangle(img, r.tl(), r.br(), new Scalar(0), Core.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);
593
Imgproc.cornerSubPix(img, corners, winSize, zeroZone, criteria);
595
assertPointEquals(truthPosition, corners.toList().get(0), weakEPS);
598
public void testCvtColorMatMatInt() {
599
fail("Not yet implemented");
602
public void testCvtColorMatMatIntInt() {
603
fail("Not yet implemented");
606
public void testDilateMatMatMat() {
607
Mat kernel = new Mat();
609
Imgproc.dilate(gray255, dst, kernel);
611
assertMatEqual(gray255, dst);
613
Imgproc.dilate(gray1, dst, kernel);
615
assertMatEqual(gray1, dst);
616
// TODO_: write better test
619
public void testDilateMatMatMatPoint() {
620
fail("Not yet implemented");
623
public void testDilateMatMatMatPointInt() {
624
fail("Not yet implemented");
627
public void testDilateMatMatMatPointIntInt() {
628
fail("Not yet implemented");
631
public void testDilateMatMatMatPointIntIntScalar() {
632
fail("Not yet implemented");
635
public void testDistanceTransformWithLabels() {
636
Mat dstLables = getMat(CvType.CV_32SC1, 0);
637
Mat labels = new Mat();
639
Imgproc.distanceTransformWithLabels(gray128, dst, labels, Imgproc.CV_DIST_L2, 3);
641
assertMatEqual(dstLables, labels);
642
assertMatEqual(getMat(CvType.CV_32FC1, 8192), dst, EPS);
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);
650
Imgproc.drawContours(gray0, contours, -1, new Scalar(0));
652
assertEquals(0, Core.countNonZero(gray0));
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);
660
Imgproc.drawContours(gray0, contours, -1, new Scalar(0), Core.FILLED);
662
assertEquals(0, Core.countNonZero(gray0));
666
public void testDrawContoursMatListOfMatIntScalarIntIntMatIntPoint() {
667
fail("Not yet implemented");
670
public void testEqualizeHist() {
671
Imgproc.equalizeHist(gray0, dst);
672
assertMatEqual(gray0, dst);
674
Imgproc.equalizeHist(gray255, dst);
675
assertMatEqual(gray255, dst);
676
// TODO_: write better test
679
public void testErodeMatMatMat() {
680
Mat kernel = new Mat();
682
Imgproc.erode(gray128, dst, kernel);
684
assertMatEqual(gray128, dst);
687
public void testErodeMatMatMatPointInt() {
688
Mat src = new Mat(3, 3, CvType.CV_8U) {
690
put(0, 0, 15, 9, 10);
691
put(1, 0, 10, 8, 12);
692
put(2, 0, 12, 20, 25);
695
Mat kernel = new Mat();
697
Imgproc.erode(src, dst, kernel, anchorPoint, 10);
699
truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));
700
assertMatEqual(truth, dst);
703
public void testErodeMatMatMatPointIntIntScalar() {
704
Mat src = new Mat(3, 3, CvType.CV_8U) {
706
put(0, 0, 15, 9, 10);
707
put(1, 0, 10, 8, 12);
708
put(2, 0, 12, 20, 25);
711
Mat kernel = new Mat();
712
Scalar sc = new Scalar(3, 3);
714
Imgproc.erode(src, dst, kernel, anchorPoint, 10, Core.BORDER_REFLECT, sc);
716
truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));
717
assertMatEqual(truth, dst);
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));
724
Imgproc.filter2D(src, dst, -1, kernel);
726
truth = new Mat(4, 4, CvType.CV_32F) {
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);
734
assertMatEqual(truth, dst, EPS);
737
public void testFilter2DMatMatIntMatPointDouble() {
738
fail("Not yet implemented");
741
public void testFilter2DMatMatIntMatPointDoubleInt() {
742
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));
743
Point point = new Point(0, 0);
745
Imgproc.filter2D(gray128, dst, -1, kernel, point, 2, Core.BORDER_CONSTANT);
747
assertMatEqual(gray2, dst);
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();
755
Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
757
// no contours on empty image
758
assertEquals(contours.size(), 0);
759
assertEquals(contours.size(), hierarchy.total());
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));
764
Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
766
// two contours of two rectangles
767
assertEquals(contours.size(), 2);
768
assertEquals(contours.size(), hierarchy.total());
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();
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));
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));
784
assertEquals(contours.size(), contours2.size());
785
assertMatEqual(contours.get(0), contours2.get(0));
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));
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();
798
rrect = Imgproc.fitEllipse(points);
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);
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);
809
Mat linePoints = new Mat(4, 1, CvType.CV_32FC1);
810
linePoints.put(0, 0, 0.53196341, 0.84676737, 2.496531, 3.7467217);
812
Imgproc.fitLine(points, dst, Imgproc.CV_DIST_L12, 0, 0.01, 0.01);
814
assertMatEqual(linePoints, dst, EPS);
817
public void testFloodFillMatMatPointScalar() {
818
Mat mask = new Mat(matSize + 2, matSize + 2, CvType.CV_8U, new Scalar(0));
820
Imgproc.circle(mask, new Point(matSize / 2 + 1, matSize / 2 + 1), 3, new Scalar(2));
822
int retval = Imgproc.floodFill(img, mask, new Point(matSize / 2, matSize / 2), new Scalar(1));
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);
830
public void testFloodFillMatMatPointScalar_WithoutMask() {
832
Imgproc.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(2));
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));
837
Imgproc.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(0));
838
assertEquals(Core.countNonZero(img), retval);
841
public void testFloodFillMatMatPointScalarRect() {
842
fail("Not yet implemented");
845
public void testFloodFillMatMatPointScalarRectScalar() {
846
fail("Not yet implemented");
849
public void testFloodFillMatMatPointScalarRectScalarScalar() {
850
fail("Not yet implemented");
853
public void testFloodFillMatMatPointScalarRectScalarScalarInt() {
854
fail("Not yet implemented");
857
public void testGaussianBlurMatMatSizeDouble() {
858
Imgproc.GaussianBlur(gray0, dst, size, 1);
859
assertMatEqual(gray0, dst);
861
Imgproc.GaussianBlur(gray2, dst, size, 1);
862
assertMatEqual(gray2, dst);
865
public void testGaussianBlurMatMatSizeDoubleDouble() {
866
Imgproc.GaussianBlur(gray2, dst, size, 0, 0);
868
assertMatEqual(gray2, dst);
869
// TODO_: write better test
872
public void testGaussianBlurMatMatSizeDoubleDoubleInt() {
873
Imgproc.GaussianBlur(gray2, dst, size, 1, 3, Core.BORDER_REFLECT);
875
assertMatEqual(gray2, dst);
876
// TODO_: write better test
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));
883
Mat transform = Imgproc.getAffineTransform(src, dst);
885
Mat truth = new Mat(2, 3, CvType.CV_64FC1) {
887
put(0, 0, -8, -6, 37);
888
put(1, 0, -7, -4, 29);
891
assertMatEqual(truth, transform, EPS);
894
public void testGetDefaultNewCameraMatrixMat() {
895
Mat mtx = Imgproc.getDefaultNewCameraMatrix(gray0);
897
assertFalse(mtx.empty());
898
assertEquals(0, Core.countNonZero(mtx));
901
public void testGetDefaultNewCameraMatrixMatSizeBoolean() {
902
Mat mtx = Imgproc.getDefaultNewCameraMatrix(gray0, size, true);
904
assertFalse(mtx.empty());
905
assertFalse(0 == Core.countNonZero(mtx));
906
// TODO_: write better test
909
public void testGetDerivKernelsMatMatIntIntInt() {
910
Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
911
Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
912
Mat expKx = new Mat(3, 1, CvType.CV_32F);
913
Mat expKy = new Mat(3, 1, CvType.CV_32F);
918
expKx.put(0, 0, 1, -2, 1);
919
expKy.put(0, 0, 1, -2, 1);
921
Imgproc.getDerivKernels(kx, ky, 2, 2, 3);
923
assertMatEqual(expKx, kx, EPS);
924
assertMatEqual(expKy, ky, EPS);
927
public void testGetDerivKernelsMatMatIntIntIntBooleanInt() {
928
Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
929
Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
930
Mat expKx = new Mat(3, 1, CvType.CV_32F);
931
Mat expKy = new Mat(3, 1, CvType.CV_32F);
936
expKx.put(0, 0, 1, -2, 1);
937
expKy.put(0, 0, 1, -2, 1);
939
Imgproc.getDerivKernels(kx, ky, 2, 2, 3, true, CvType.CV_32F);
941
assertMatEqual(expKx, kx, EPS);
942
assertMatEqual(expKy, ky, EPS);
943
// TODO_: write better test
946
public void testGetGaussianKernelIntDouble() {
947
dst = Imgproc.getGaussianKernel(1, 0.5);
949
truth = new Mat(1, 1, CvType.CV_64FC1, new Scalar(1));
950
assertMatEqual(truth, dst, EPS);
953
public void testGetGaussianKernelIntDoubleInt() {
954
dst = Imgproc.getGaussianKernel(3, 0.8, CvType.CV_32F);
956
truth = new Mat(3, 1, CvType.CV_32F);
957
truth.put(0, 0, 0.23899426, 0.52201146, 0.23899426);
958
assertMatEqual(truth, dst, EPS);
961
public void testGetPerspectiveTransform() {
962
fail("Not yet implemented");
965
public void testGetRectSubPixMatSizePointMat() {
966
Size size = new Size(3, 3);
967
Point center = new Point(gray255.cols() / 2, gray255.rows() / 2);
969
Imgproc.getRectSubPix(gray255, size, center, dst);
971
truth = new Mat(3, 3, CvType.CV_8U, new Scalar(255));
972
assertMatEqual(truth, dst);
975
public void testGetRectSubPixMatSizePointMatInt() {
976
Mat src = new Mat(10, 10, CvType.CV_32F, new Scalar(2));
977
Size patchSize = new Size(5, 5);
978
Point center = new Point(src.cols() / 2, src.rows() / 2);
980
Imgproc.getRectSubPix(src, patchSize, center, dst);
982
truth = new Mat(5, 5, CvType.CV_32F, new Scalar(2));
983
assertMatEqual(truth, dst, EPS);
986
public void testGetRotationMatrix2D() {
987
Point center = new Point(0, 0);
989
dst = Imgproc.getRotationMatrix2D(center, 0, 1);
991
truth = new Mat(2, 3, CvType.CV_64F) {
998
assertMatEqual(truth, dst, EPS);
1001
public void testGetStructuringElementIntSize() {
1002
dst = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, size);
1004
truth = new Mat(3, 3, CvType.CV_8UC1, new Scalar(1));
1005
assertMatEqual(truth, dst);
1008
public void testGetStructuringElementIntSizePoint() {
1009
dst = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, size, anchorPoint);
1011
truth = new Mat(3, 3, CvType.CV_8UC1) {
1018
assertMatEqual(truth, dst);
1021
public void testGoodFeaturesToTrackMatListOfPointIntDoubleDouble() {
1023
Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
1024
MatOfPoint lp = new MatOfPoint();
1026
Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3);
1028
assertEquals(4, lp.total());
1031
public void testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDouble() {
1033
Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
1034
MatOfPoint lp = new MatOfPoint();
1036
Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3, gray1, 4, true, 0);
1038
assertEquals(4, lp.total());
1041
public void testGrabCutMatMatRectMatMatInt() {
1042
fail("Not yet implemented");
1045
public void testGrabCutMatMatRectMatMatIntInt() {
1046
fail("Not yet implemented");
1049
public void testHoughCirclesMatMatIntDoubleDouble() {
1051
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));
1052
Mat circles = new Mat();
1054
Imgproc.HoughCircles(img, circles, Imgproc.CV_HOUGH_GRADIENT, 2, img.rows() / 4);
1056
assertEquals(0, circles.cols());
1059
public void testHoughCirclesMatMatIntDoubleDouble1() {
1061
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));
1062
Mat circles = new Mat();
1064
Point center = new Point(img.cols() / 2, img.rows() / 2);
1065
int radius = Math.min(img.cols() / 4, img.rows() / 4);
1066
Imgproc.circle(img, center, radius, colorBlack, 3);
1068
Imgproc.HoughCircles(img, circles, Imgproc.CV_HOUGH_GRADIENT, 2, img.rows() / 4);
1070
assertEquals(1, circles.cols());
1073
public void testHoughCirclesMatMatIntDoubleDoubleDoubleDoubleIntInt() {
1074
fail("Not yet implemented");
1077
public void testHoughLinesMatMatDoubleDoubleInt() {
1079
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));
1080
Point point1 = new Point(50, 50);
1081
Point point2 = new Point(img.cols() / 2, img.rows() / 2);
1082
Imgproc.line(img, point1, point2, colorWhite, 1);
1083
Mat lines = new Mat();
1085
Imgproc.HoughLines(img, lines, 1, 3.1415926/180, 100);
1087
assertEquals(1, lines.cols());
1090
Log.d("HoughLines", "lines=" + lines);
1091
int num = (int)lines.total();
1092
int buff[] = new int[num*4]; //[ (x1, y1, x2, y2), (...), ...]
1093
lines.get(0, 0, buff);
1094
Log.d("HoughLines", "lines=" + Arrays.toString(buff));
1098
public void testHoughLinesMatMatDoubleDoubleIntDouble() {
1099
fail("Not yet implemented");
1102
public void testHoughLinesMatMatDoubleDoubleIntDoubleDouble() {
1103
fail("Not yet implemented");
1106
public void testHoughLinesPMatMatDoubleDoubleInt() {
1108
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));
1109
Point point1 = new Point(0, 0);
1110
Point point2 = new Point(sz, sz);
1111
Point point3 = new Point(sz, 0);
1112
Point point4 = new Point(2*sz/3, sz/3);
1113
Imgproc.line(img, point1, point2, Scalar.all(255), 1);
1114
Imgproc.line(img, point3, point4, Scalar.all(255), 1);
1115
Mat lines = new Mat();
1117
Imgproc.HoughLinesP(img, lines, 1, 3.1415926/180, 100);
1119
assertEquals(2, lines.cols());
1122
Log.d("HoughLinesP", "lines=" + lines);
1123
int num = (int)lines.cols();
1124
int buff[] = new int[num*4]; // CV_32SC4 as [ (x1, y1, x2, y2), (...), ...]
1125
lines.get(0, 0, buff);
1126
Log.d("HoughLinesP", "lines=" + Arrays.toString(buff));
1130
public void testHoughLinesPMatMatDoubleDoubleIntDouble() {
1131
fail("Not yet implemented");
1134
public void testHoughLinesPMatMatDoubleDoubleIntDoubleDouble() {
1135
fail("Not yet implemented");
1138
public void testHuMoments() {
1139
fail("Not yet implemented");
1142
public void testInitUndistortRectifyMap() {
1143
fail("Not yet implemented");
1144
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
1145
cameraMatrix.put(0, 0, 1, 0, 1);
1146
cameraMatrix.put(1, 0, 0, 1, 1);
1147
cameraMatrix.put(2, 0, 0, 0, 1);
1149
Mat R = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
1150
Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
1152
Mat distCoeffs = new Mat();
1153
Mat map1 = new Mat();
1154
Mat map2 = new Mat();
1156
// TODO: complete this test
1157
Imgproc.initUndistortRectifyMap(cameraMatrix, distCoeffs, R, newCameraMatrix, size, CvType.CV_32F, map1, map2);
1160
public void testInitWideAngleProjMapMatMatSizeIntIntMatMat() {
1161
fail("Not yet implemented");
1162
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
1163
Mat distCoeffs = new Mat(1, 4, CvType.CV_32F);
1164
// Size imageSize = new Size(2, 2);
1166
cameraMatrix.put(0, 0, 1, 0, 1);
1167
cameraMatrix.put(1, 0, 0, 1, 2);
1168
cameraMatrix.put(2, 0, 0, 0, 1);
1170
distCoeffs.put(0, 0, 1, 3, 2, 4);
1171
truth = new Mat(3, 3, CvType.CV_32F);
1172
truth.put(0, 0, 0, 0, 0);
1173
truth.put(1, 0, 0, 0, 0);
1174
truth.put(2, 0, 0, 3, 0);
1175
// TODO: No documentation for this function
1176
// Imgproc.initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize,
1177
// 5, m1type, truthput1, truthput2);
1180
public void testInitWideAngleProjMapMatMatSizeIntIntMatMatInt() {
1181
fail("Not yet implemented");
1184
public void testInitWideAngleProjMapMatMatSizeIntIntMatMatIntDouble() {
1185
fail("Not yet implemented");
1188
public void testIntegral2MatMatMat() {
1189
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
1190
Mat expSum = new Mat(4, 4, CvType.CV_64F);
1191
Mat expSqsum = new Mat(4, 4, CvType.CV_64F);
1192
Mat sum = new Mat();
1193
Mat sqsum = new Mat();
1195
expSum.put(0, 0, 0, 0, 0, 0);
1196
expSum.put(1, 0, 0, 3, 6, 9);
1197
expSum.put(2, 0, 0, 6, 12, 18);
1198
expSum.put(3, 0, 0, 9, 18, 27);
1200
expSqsum.put(0, 0, 0, 0, 0, 0);
1201
expSqsum.put(1, 0, 0, 9, 18, 27);
1202
expSqsum.put(2, 0, 0, 18, 36, 54);
1203
expSqsum.put(3, 0, 0, 27, 54, 81);
1205
Imgproc.integral2(src, sum, sqsum);
1207
assertMatEqual(expSum, sum, EPS);
1208
assertMatEqual(expSqsum, sqsum, EPS);
1211
public void testIntegral2MatMatMatInt() {
1212
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
1213
Mat expSum = new Mat(4, 4, CvType.CV_64F);
1214
Mat expSqsum = new Mat(4, 4, CvType.CV_64F);
1215
Mat sum = new Mat();
1216
Mat sqsum = new Mat();
1218
expSum.put(0, 0, 0, 0, 0, 0);
1219
expSum.put(1, 0, 0, 3, 6, 9);
1220
expSum.put(2, 0, 0, 6, 12, 18);
1221
expSum.put(3, 0, 0, 9, 18, 27);
1223
expSqsum.put(0, 0, 0, 0, 0, 0);
1224
expSqsum.put(1, 0, 0, 9, 18, 27);
1225
expSqsum.put(2, 0, 0, 18, 36, 54);
1226
expSqsum.put(3, 0, 0, 27, 54, 81);
1228
Imgproc.integral2(src, sum, sqsum, CvType.CV_64F, CvType.CV_64F);
1230
assertMatEqual(expSum, sum, EPS);
1231
assertMatEqual(expSqsum, sqsum, EPS);
1234
public void testIntegral3MatMatMatMat() {
1235
Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));
1236
Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1237
Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1238
Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1239
Mat sum = new Mat();
1240
Mat sqsum = new Mat();
1241
Mat tilted = new Mat();
1243
expSum.put(0, 0, 0, 0);
1244
expSum.put(1, 0, 0, 1);
1246
expSqsum.put(0, 0, 0, 0);
1247
expSqsum.put(1, 0, 0, 1);
1249
expTilted.put(0, 0, 0, 0);
1250
expTilted.put(1, 0, 0, 1);
1252
Imgproc.integral3(src, sum, sqsum, tilted);
1254
assertMatEqual(expSum, sum, EPS);
1255
assertMatEqual(expSqsum, sqsum, EPS);
1256
assertMatEqual(expTilted, tilted, EPS);
1259
public void testIntegral3MatMatMatMatInt() {
1260
Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));
1261
Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1262
Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1263
Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
1264
Mat sum = new Mat();
1265
Mat sqsum = new Mat();
1266
Mat tilted = new Mat();
1268
expSum.put(0, 0, 0, 0);
1269
expSum.put(1, 0, 0, 1);
1271
expSqsum.put(0, 0, 0, 0);
1272
expSqsum.put(1, 0, 0, 1);
1274
expTilted.put(0, 0, 0, 0);
1275
expTilted.put(1, 0, 0, 1);
1277
Imgproc.integral3(src, sum, sqsum, tilted, CvType.CV_64F, CvType.CV_64F);
1279
assertMatEqual(expSum, sum, EPS);
1280
assertMatEqual(expSqsum, sqsum, EPS);
1281
assertMatEqual(expTilted, tilted, EPS);
1284
public void testIntegralMatMat() {
1285
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1287
Imgproc.integral(src, dst);
1289
truth = new Mat(3, 3, CvType.CV_64F) {
1296
assertMatEqual(truth, dst, EPS);
1299
public void testIntegralMatMatInt() {
1300
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1302
Imgproc.integral(src, dst, CvType.CV_64F);
1304
truth = new Mat(3, 3, CvType.CV_64F) {
1311
assertMatEqual(truth, dst, EPS);
1314
public void testInvertAffineTransform() {
1315
Mat src = new Mat(2, 3, CvType.CV_64F, new Scalar(1));
1317
Imgproc.invertAffineTransform(src, dst);
1319
truth = new Mat(2, 3, CvType.CV_64F, new Scalar(0));
1320
assertMatEqual(truth, dst, EPS);
1323
public void testIsContourConvex() {
1324
MatOfPoint contour1 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4));
1326
assertFalse(Imgproc.isContourConvex(contour1));
1328
MatOfPoint contour2 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6));
1330
assertTrue(Imgproc.isContourConvex(contour2));
1333
public void testLaplacianMatMatInt() {
1334
Imgproc.Laplacian(gray0, dst, CvType.CV_8U);
1336
assertMatEqual(gray0, dst);
1339
public void testLaplacianMatMatIntIntDoubleDouble() {
1340
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
1342
Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS);
1344
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
1346
put(0, 0, -7.9990001, 8.0009995);
1347
put(1, 0, 8.0009995, -7.9990001);
1350
assertMatEqual(truth, dst, EPS);
1353
public void testLaplacianMatMatIntIntDoubleDoubleInt() {
1354
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
1356
Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS, Core.BORDER_REFLECT);
1358
truth = new Mat(3, 3, CvType.CV_32F, new Scalar(0.00099945068));
1359
assertMatEqual(truth, dst, EPS);
1362
public void testMatchShapes() {
1363
Mat contour1 = new Mat(1, 4, CvType.CV_32FC2);
1364
Mat contour2 = new Mat(1, 4, CvType.CV_32FC2);
1365
contour1.put(0, 0, 1, 1, 5, 1, 4, 3, 6, 2);
1366
contour2.put(0, 0, 1, 1, 6, 1, 4, 1, 2, 5);
1368
double distance = Imgproc.matchShapes(contour1, contour2, Imgproc.CV_CONTOURS_MATCH_I1, 1);
1370
assertEquals(2.81109697365334, distance, EPS);
1373
public void testMatchTemplate() {
1374
Mat image = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
1375
Mat templ = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
1376
image.put(0, 0, 1, 2, 3, 4);
1377
templ.put(0, 0, 5, 6, 7, 8);
1379
Imgproc.matchTemplate(image, templ, dst, Imgproc.TM_CCORR);
1381
truth = new Mat(1, 1, CvType.CV_32F, new Scalar(70));
1382
assertMatEqual(truth, dst, EPS);
1384
Imgproc.matchTemplate(gray255, gray0, dst, Imgproc.TM_CCORR);
1386
truth = new Mat(1, 1, CvType.CV_32F, new Scalar(0));
1387
assertMatEqual(truth, dst, EPS);
1390
public void testMedianBlur() {
1391
Imgproc.medianBlur(gray255, dst, 5);
1392
assertMatEqual(gray255, dst);
1394
Imgproc.medianBlur(gray2, dst, 3);
1395
assertMatEqual(gray2, dst);
1396
// TODO_: write better test
1399
public void testMinAreaRect() {
1400
MatOfPoint2f points = new MatOfPoint2f(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2));
1402
RotatedRect rrect = Imgproc.minAreaRect(points);
1404
assertEquals(new Size(2, 5), rrect.size);
1405
assertEquals(-90., rrect.angle);
1406
assertEquals(new Point(3.5, 2), rrect.center);
1409
public void testMinEnclosingCircle() {
1410
MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-1, 0), new Point(0, -1), new Point(1, 0), new Point(0, 1));
1411
Point actualCenter = new Point();
1412
float[] radius = new float[1];
1414
Imgproc.minEnclosingCircle(points, actualCenter, radius);
1416
assertEquals(new Point(0, 0), actualCenter);
1417
assertEquals(1.03f, radius[0], EPS);
1420
public void testMomentsMat() {
1421
fail("Not yet implemented");
1424
public void testMomentsMatBoolean() {
1425
fail("Not yet implemented");
1428
public void testMorphologyExMatMatIntMat() {
1429
Imgproc.morphologyEx(gray255, dst, Imgproc.MORPH_GRADIENT, gray0);
1431
assertMatEqual(gray0, dst);
1432
// TODO_: write better test
1435
public void testMorphologyExMatMatIntMatPointInt() {
1436
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);
1438
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(0));
1439
Point point = new Point(0, 0);
1441
Imgproc.morphologyEx(src, dst, Imgproc.MORPH_CLOSE, kernel, point, 10);
1443
truth = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);
1444
assertMatEqual(truth, dst);
1445
// TODO_: write better test
1449
public void testMorphologyExMatMatIntMatPointIntIntScalar() {
1450
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
1451
src.put(0, 0, 2, 1);
1452
src.put(1, 0, 2, 1);
1454
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(1));
1455
Point point = new Point(1, 1);
1456
Scalar sc = new Scalar(3, 3);
1458
Imgproc.morphologyEx(src, dst, Imgproc.MORPH_TOPHAT, kernel, point, 10, Core.BORDER_REFLECT, sc);
1459
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_8U) {
1465
assertMatEqual(truth, dst);
1466
// TODO_: write better test
1469
public void testPointPolygonTest() {
1470
MatOfPoint2f contour = new MatOfPoint2f(new Point(0, 0), new Point(1, 3), new Point(3, 4), new Point(4, 3), new Point(2, 1));
1471
double sign1 = Imgproc.pointPolygonTest(contour, new Point(2, 2), false);
1472
assertEquals(1.0, sign1);
1474
double sign2 = Imgproc.pointPolygonTest(contour, new Point(4, 4), true);
1475
assertEquals(-Math.sqrt(0.5), sign2);
1478
public void testPreCornerDetectMatMatInt() {
1479
Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));
1482
Imgproc.preCornerDetect(src, dst, ksize);
1484
truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
1485
assertMatEqual(truth, dst, EPS);
1488
public void testPreCornerDetectMatMatIntInt() {
1489
Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));
1492
Imgproc.preCornerDetect(src, dst, ksize, Core.BORDER_REFLECT);
1494
truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
1495
assertMatEqual(truth, dst, EPS);
1496
// TODO_: write better test
1499
public void testPyrDownMatMat() {
1500
Mat src = new Mat(4, 4, CvType.CV_32F) {
1502
put(0, 0, 2, 1, 4, 2);
1503
put(1, 0, 3, 2, 6, 8);
1504
put(2, 0, 4, 6, 8, 10);
1505
put(3, 0, 12, 32, 6, 18);
1509
Imgproc.pyrDown(src, dst);
1511
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
1513
put(0, 0, 2.78125, 4.609375);
1514
put(1, 0, 8.546875, 8.8515625);
1517
assertMatEqual(truth, dst, EPS);
1520
public void testPyrDownMatMatSize() {
1521
Mat src = new Mat(4, 4, CvType.CV_32F) {
1523
put(0, 0, 2, 1, 4, 2);
1524
put(1, 0, 3, 2, 6, 8);
1525
put(2, 0, 4, 6, 8, 10);
1526
put(3, 0, 12, 32, 6, 18);
1529
Size dstSize = new Size(2, 2);
1531
Imgproc.pyrDown(src, dst, dstSize);
1533
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
1535
put(0, 0, 2.78125, 4.609375);
1536
put(1, 0, 8.546875, 8.8515625);
1539
assertMatEqual(truth, dst, EPS);
1540
// TODO_: write better test
1543
public void testPyrMeanShiftFilteringMatMatDoubleDouble() {
1544
Mat src = new Mat(matSize, matSize, CvType.CV_8UC3, new Scalar(0));
1546
Imgproc.pyrMeanShiftFiltering(src, dst, 10, 50);
1548
assertMatEqual(src, dst);
1549
// TODO_: write better test
1552
public void testPyrMeanShiftFilteringMatMatDoubleDoubleInt() {
1553
fail("Not yet implemented");
1556
public void testPyrMeanShiftFilteringMatMatDoubleDoubleIntTermCriteria() {
1557
fail("Not yet implemented");
1560
public void testPyrUpMatMat() {
1561
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
1562
src.put(0, 0, 2, 1);
1563
src.put(1, 0, 3, 2);
1565
Imgproc.pyrUp(src, dst);
1567
truth = new Mat(4, 4, CvType.CV_32F) {
1569
put(0, 0, 2, 1.75, 1.375, 1.25);
1570
put(1, 0, 2.25, 2, 1.625, 1.5);
1571
put(2, 0, 2.625, 2.375, 2, 1.875);
1572
put(3, 0, 2.75, 2.5, 2.125, 2);
1575
assertMatEqual(truth, dst, EPS);
1578
public void testPyrUpMatMatSize() {
1579
fail("Not yet implemented");
1582
public void testRemapMatMatMatMatInt() {
1583
fail("Not yet implemented");
1584
// this test does something weird
1585
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1586
Mat map1 = new Mat(1, 3, CvType.CV_32FC1);
1587
Mat map2 = new Mat(1, 3, CvType.CV_32FC1);
1589
map1.put(0, 0, 3, 6, 5);
1590
map2.put(0, 0, 4, 8, 12);
1592
Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR);
1594
truth = new Mat(1, 3, CvType.CV_32F, new Scalar(0));
1595
assertMatEqual(truth, dst, EPS);
1598
public void testRemapMatMatMatMatIntIntScalar() {
1599
fail("Not yet implemented");
1600
// this test does something weird
1601
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1602
Mat map1 = new Mat(1, 3, CvType.CV_32FC1);
1603
Mat map2 = new Mat(1, 3, CvType.CV_32FC1);
1605
Scalar sc = new Scalar(0);
1607
map1.put(0, 0, 3, 6, 5, 0);
1608
map2.put(0, 0, 4, 8, 12);
1610
truth = new Mat(1, 3, CvType.CV_32F, new Scalar(2));
1612
Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR, Core.BORDER_REFLECT, sc);
1613
assertMatEqual(truth, dst, EPS);
1616
public void testResizeMatMatSize() {
1617
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8UC1, new Scalar(1));
1618
Size dsize = new Size(1, 1);
1620
Imgproc.resize(src, dst, dsize);
1622
truth = new Mat(1, 1, CvType.CV_8UC1, new Scalar(1));
1623
assertMatEqual(truth, dst);
1626
public void testResizeMatMatSizeDoubleDoubleInt() {
1627
Imgproc.resize(gray255, dst, new Size(2, 2), 0, 0, Imgproc.INTER_AREA);
1629
truth = new Mat(2, 2, CvType.CV_8UC1, new Scalar(255));
1630
assertMatEqual(truth, dst);
1631
// TODO_: write better test
1634
public void testScharrMatMatIntIntInt() {
1635
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
1637
Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0);
1639
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));
1640
assertMatEqual(truth, dst, EPS);
1643
public void testScharrMatMatIntIntIntDoubleDouble() {
1644
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
1646
Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0.001);
1648
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0.001));
1649
assertMatEqual(truth, dst, EPS);
1652
public void testScharrMatMatIntIntIntDoubleDoubleInt() {
1653
Mat src = Mat.eye(3, 3, CvType.CV_32F);
1655
Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0, Core.BORDER_REFLECT);
1657
truth = new Mat(3, 3, CvType.CV_32F) {
1659
put(0, 0, -15, -19.5, -4.5);
1660
put(1, 0, 10.5, 0, -10.5);
1661
put(2, 0, 4.5, 19.5, 15);
1664
assertMatEqual(truth, dst, EPS);
1667
public void testSepFilter2DMatMatIntMatMat() {
1668
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
1669
Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
1670
Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
1671
kernelX.put(0, 0, 4, 3, 7);
1672
kernelY.put(0, 0, 9, 4, 2);
1674
Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY);
1676
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(420));
1677
assertMatEqual(truth, dst, EPS);
1680
public void testSepFilter2DMatMatIntMatMatPointDouble() {
1681
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(2));
1682
Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
1683
kernelX.put(0, 0, 2, 2, 2);
1684
Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
1685
kernelY.put(0, 0, 1, 1, 1);
1687
Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS);
1689
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(36 + weakEPS));
1690
assertMatEqual(truth, dst, EPS);
1693
public void testSepFilter2DMatMatIntMatMatPointDoubleInt() {
1694
Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
1695
kernelX.put(0, 0, 2, 2, 2);
1697
Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
1698
kernelY.put(0, 0, 1, 1, 1);
1700
Imgproc.sepFilter2D(gray0, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS, Core.BORDER_REFLECT);
1702
truth = new Mat(10, 10, CvType.CV_32F, new Scalar(weakEPS));
1703
assertMatEqual(truth, dst, EPS);
1704
// TODO_: write better test
1707
public void testSobelMatMatIntIntInt() {
1708
Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0);
1710
assertMatEqual(gray0, dst);
1713
public void testSobelMatMatIntIntIntIntDoubleDouble() {
1714
Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0, 3, 2, 0.001);
1715
assertMatEqual(gray0, dst);
1716
// TODO_: write better test
1719
public void testSobelMatMatIntIntIntIntDoubleDoubleInt() {
1720
Mat src = new Mat(3, 3, CvType.CV_32F) {
1728
Imgproc.Sobel(src, dst, CvType.CV_32F, 1, 0, 3, 2, 0, Core.BORDER_REPLICATE);
1730
truth = new Mat(3, 3, CvType.CV_32F) {
1732
put(0, 0, -16, -12, 4);
1733
put(1, 0, -14, -12, 2);
1734
put(2, 0, -10, 0, 10);
1737
assertMatEqual(truth, dst, EPS);
1740
public void testThreshold() {
1741
Imgproc.threshold(makeMask(gray0.clone(), 10), dst, 5, 255, Imgproc.THRESH_TRUNC);
1742
assertMatEqual(makeMask(gray0.clone(), 5), dst);
1744
Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 1, 255, Imgproc.THRESH_BINARY);
1745
assertMatEqual(gray255, dst);
1747
Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 3, 255, Imgproc.THRESH_BINARY_INV);
1748
assertMatEqual(makeMask(gray255.clone(), 0), dst);
1751
public void testUndistortMatMatMatMat() {
1752
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
1753
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
1760
Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
1762
put(0, 0, 1, 3, 2, 4);
1766
Imgproc.undistort(src, dst, cameraMatrix, distCoeffs);
1768
truth = new Mat(3, 3, CvType.CV_32F) {
1775
assertMatEqual(truth, dst, EPS);
1778
public void testUndistortMatMatMatMatMat() {
1779
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
1780
Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
1787
Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
1789
put(0, 0, 2, 1, 4, 5);
1792
Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(1));
1794
Imgproc.undistort(src, dst, cameraMatrix, distCoeffs, newCameraMatrix);
1796
truth = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
1797
assertMatEqual(truth, dst, EPS);
1800
//undistortPoints(List<Point> src, List<Point> dst, Mat cameraMatrix, Mat distCoeffs)
1801
public void testUndistortPointsListOfPointListOfPointMatMat() {
1802
MatOfPoint2f src = new MatOfPoint2f(new Point(1, 2), new Point(3, 4), new Point(-1, -1));
1803
MatOfPoint2f dst = new MatOfPoint2f();
1804
Mat cameraMatrix = Mat.eye(3, 3, CvType.CV_64FC1);
1805
Mat distCoeffs = new Mat(8, 1, CvType.CV_64FC1, new Scalar(0));
1807
Imgproc.undistortPoints(src, dst, cameraMatrix, distCoeffs);
1809
assertEquals(src.size(), dst.size());
1810
for(int i=0; i<src.toList().size(); i++) {
1811
//Log.d("UndistortPoints", "s="+src.get(i)+", d="+dst.get(i));
1812
assertTrue(src.toList().get(i).equals(dst.toList().get(i)));
1817
public void testWarpAffineMatMatMatSize() {
1818
Mat src = new Mat(3, 3, CvType.CV_32F) {
1825
Mat M = new Mat(2, 3, CvType.CV_32F) {
1832
Imgproc.warpAffine(src, dst, M, new Size(3, 3));
1834
truth = new Mat(3, 3, CvType.CV_32F) {
1841
assertMatEqual(truth, dst, EPS);
1844
public void testWarpAffineMatMatMatSizeInt() {
1845
Mat src = new Mat(3, 3, CvType.CV_32F) {
1852
Mat M = new Mat(2, 3, CvType.CV_32F) {
1859
Imgproc.warpAffine(src, dst, M, new Size(2, 2), Imgproc.WARP_INVERSE_MAP);
1861
truth = new Mat(2, 2, CvType.CV_32F) {
1867
assertMatEqual(truth, dst, EPS);
1870
public void testWarpAffineMatMatMatSizeIntInt() {
1871
fail("Not yet implemented");
1874
public void testWarpAffineMatMatMatSizeIntIntScalar() {
1875
fail("Not yet implemented");
1878
public void testWarpPerspectiveMatMatMatSize() {
1879
Mat src = new Mat(3, 3, CvType.CV_32F) {
1886
Mat M = new Mat(3, 3, CvType.CV_32F) {
1894
Imgproc.warpPerspective(src, dst, M, new Size(3, 3));
1896
truth = new Mat(3, 3, CvType.CV_32F) {
1903
assertMatEqual(truth, dst, EPS);
1906
public void testWarpPerspectiveMatMatMatSizeInt() {
1907
fail("Not yet implemented");
1910
public void testWarpPerspectiveMatMatMatSizeIntInt() {
1911
fail("Not yet implemented");
1914
public void testWarpPerspectiveMatMatMatSizeIntIntScalar() {
1915
fail("Not yet implemented");
1918
public void testWatershed() {
1919
Mat image = Mat.eye(4, 4, CvType.CV_8UC(3));
1920
Mat markers = new Mat(4, 4, CvType.CV_32SC1, new Scalar(0));
1922
Imgproc.watershed(image, markers);
1924
truth = new Mat(4, 4, CvType.CV_32SC1) {
1926
put(0, 0, -1, -1, -1, -1);
1927
put(1, 0, -1, 0, 0, -1);
1928
put(2, 0, -1, 0, 0, -1);
1929
put(3, 0, -1, -1, -1, -1);
1932
assertMatEqual(truth, markers);
1935
public void testGetTextSize() {
1936
String text = "Android all the way";
1937
double fontScale = 2;
1939
int baseLine[] = new int[1];
1941
Imgproc.getTextSize(text, Core.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, null);
1942
Size res = Imgproc.getTextSize(text, Core.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, baseLine);
1944
assertEquals(543.0, res.width);
1945
assertEquals(44.0, res.height);
1946
assertEquals(20, baseLine[0]);
1949
public void testCircleMatPointIntScalar() {
1950
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
1951
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
1952
Scalar color = new Scalar(128);
1954
Imgproc.circle(gray0, center, radius, color);
1956
assertTrue(0 != Core.countNonZero(gray0));
1959
public void testCircleMatPointIntScalarInt() {
1960
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
1961
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
1962
Scalar color = new Scalar(128);
1964
Imgproc.circle(gray0, center, radius, color, Core.FILLED);
1966
assertTrue(0 != Core.countNonZero(gray0));
1969
public void testCircleMatPointIntScalarIntIntInt() {
1970
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
1971
Point center2 = new Point(gray0.cols(), gray0.rows());
1972
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
1973
Scalar color128 = new Scalar(128);
1974
Scalar color0 = new Scalar(0);
1976
Imgproc.circle(gray0, center2, radius * 2, color128, 2, Imgproc.LINE_4, 1/*
1982
assertFalse(0 == Core.countNonZero(gray0));
1984
Imgproc.circle(gray0, center, radius, color0, 2, Imgproc.LINE_4, 0);
1986
assertTrue(0 == Core.countNonZero(gray0));
1989
public void testClipLine() {
1990
Rect r = new Rect(10, 10, 10, 10);
1991
Point pt1 = new Point(5.0, 15.0);
1992
Point pt2 = new Point(25.0, 15.0);
1994
assertTrue(Imgproc.clipLine(r, pt1, pt2));
1996
Point pt1Clipped = new Point(10.0, 15.0);
1997
Point pt2Clipped = new Point(19.0, 15.0);
1998
assertEquals(pt1Clipped, pt1);
1999
assertEquals(pt2Clipped, pt2);
2001
pt1 = new Point(5.0, 5.0);
2002
pt2 = new Point(25.0, 5.0);
2003
pt1Clipped = new Point(5.0, 5.0);
2004
pt2Clipped = new Point(25.0, 5.0);
2006
assertFalse(Imgproc.clipLine(r, pt1, pt2));
2008
assertEquals(pt1Clipped, pt1);
2009
assertEquals(pt2Clipped, pt2);
2012
public void testEllipse2Poly() {
2013
Point center = new Point(4, 4);
2014
Size axes = new Size(2, 2);
2019
MatOfPoint pts = new MatOfPoint();
2021
Imgproc.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts);
2027
assertArrayPointsEquals(truth, pts.toArray(), EPS);
2030
public void testEllipseMatPointSizeDoubleDoubleDoubleScalar() {
2031
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
2032
Size axes = new Size(2, 2);
2033
double angle = 30, startAngle = 60, endAngle = 90;
2035
Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite);
2037
assertTrue(0 != Core.countNonZero(gray0));
2040
public void testEllipseMatPointSizeDoubleDoubleDoubleScalarInt() {
2041
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
2042
Size axes = new Size(2, 2);
2043
double angle = 30, startAngle = 60, endAngle = 90;
2045
Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Core.FILLED);
2047
assertTrue(0 != Core.countNonZero(gray0));
2050
public void testEllipseMatPointSizeDoubleDoubleDoubleScalarIntIntInt() {
2051
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
2052
Size axes = new Size(2, 2);
2053
Point center2 = new Point(gray0.cols(), gray0.rows());
2054
Size axes2 = new Size(4, 4);
2055
double angle = 30, startAngle = 0, endAngle = 30;
2057
Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Core.FILLED, Imgproc.LINE_4, 0);
2059
assertTrue(0 != Core.countNonZero(gray0));
2061
Imgproc.ellipse(gray0, center2, axes2, angle, startAngle, endAngle, colorBlack, Core.FILLED, Imgproc.LINE_4, 1);
2063
assertEquals(0, Core.countNonZero(gray0));
2066
public void testEllipseMatRotatedRectScalar() {
2068
Mat gray0 = Mat.zeros(matSize, matSize, CvType.CV_8U);
2069
Point center = new Point(matSize / 2, matSize / 2);
2070
Size size = new Size(matSize / 4, matSize / 2);
2071
RotatedRect box = new RotatedRect(center, size, 45);
2073
Imgproc.ellipse(gray0, box, new Scalar(1));
2075
final byte[] truth = new byte[] {
2076
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2077
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2078
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2079
0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
2080
0, 0, 0, 0, 1, 1, 0, 1, 0, 0,
2081
0, 0, 0, 0, 1, 0, 1, 0, 0, 0,
2082
0, 0, 0, 1, 0, 1, 1, 0, 0, 0,
2083
0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
2084
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2085
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2087
assertMatEqual(new Mat(matSize, matSize, CvType.CV_8U) {
2094
public void testEllipseMatRotatedRectScalarInt() {
2095
Point center = new Point(matSize / 2, matSize / 2);
2096
Size size = new Size(matSize / 4, matSize / 2);
2097
RotatedRect box = new RotatedRect(center, size, 45);
2099
Imgproc.ellipse(gray0, box, new Scalar(1), Core.FILLED);
2100
Imgproc.ellipse(gray0, box, new Scalar(0));
2102
assertTrue(0 < Core.countNonZero(gray0));
2105
public void testEllipseMatRotatedRectScalarIntInt() {
2106
Point center = new Point(matSize / 2, matSize / 2);
2107
Size size = new Size(2, matSize * 2 / 3);
2108
RotatedRect box = new RotatedRect(center, size, 20);
2110
Imgproc.ellipse(gray0, box, new Scalar(9), 1, Imgproc.LINE_AA);
2111
Imgproc.ellipse(gray0, box, new Scalar(0), 1, Imgproc.LINE_4);
2113
assertTrue(0 < Core.countNonZero(gray0));
2116
public void testPolylinesMatListOfListOfPointBooleanScalar() {
2118
List<MatOfPoint> polyline = new ArrayList<MatOfPoint>();
2119
polyline.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
2121
Imgproc.polylines(img, polyline, true, new Scalar(100));
2123
assertEquals(22, Core.countNonZero(img));
2125
Imgproc.polylines(img, polyline, false, new Scalar(0));
2127
assertEquals(4, Core.countNonZero(img));
2130
public void testPolylinesMatListOfListOfPointBooleanScalarInt() {
2132
List<MatOfPoint> polyline = new ArrayList<MatOfPoint>();
2133
polyline.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
2135
Imgproc.polylines(img, polyline, true, new Scalar(100), 2);
2137
assertEquals(62, Core.countNonZero(img));
2140
public void testPolylinesMatListOfListOfPointBooleanScalarIntIntInt() {
2142
List<MatOfPoint> polyline1 = new ArrayList<MatOfPoint>();
2143
polyline1.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
2144
List<MatOfPoint> polyline2 = new ArrayList<MatOfPoint>();
2145
polyline2.add(new MatOfPoint(new Point(2, 2), new Point(14, 2), new Point(14, 12), new Point(2, 12)));
2147
Imgproc.polylines(img, polyline1, true, new Scalar(100), 2, Imgproc.LINE_8, 0);
2149
assertTrue(Core.countNonZero(img) > 0);
2151
Imgproc.polylines(img, polyline2, true, new Scalar(0), 2, Imgproc.LINE_8, 1);
2153
assertEquals(0, Core.countNonZero(img));
2156
public void testPutTextMatStringPointIntDoubleScalar() {
2157
String text = "Hello World";
2158
Size labelSize = new Size(175, 22);
2159
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
2160
Point origin = new Point(10, labelSize.height + 10);
2162
Imgproc.putText(img, text, origin, Core.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite);
2164
assertTrue(Core.countNonZero(img) > 0);
2165
// check that border is not corrupted
2166
Imgproc.rectangle(img, new Point(11, 11), new Point(labelSize.width + 10, labelSize.height + 10), colorBlack, Core.FILLED);
2167
assertEquals(0, Core.countNonZero(img));
2170
public void testPutTextMatStringPointIntDoubleScalarInt() {
2171
String text = "Hello World";
2172
Size labelSize = new Size(176, 22);
2173
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
2174
Point origin = new Point(10, labelSize.height + 10);
2176
Imgproc.putText(img, text, origin, Core.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite, 2);
2178
assertTrue(Core.countNonZero(img) > 0);
2179
// check that border is not corrupted
2180
Imgproc.rectangle(img, new Point(10, 10), new Point(labelSize.width + 10 + 1, labelSize.height + 10 + 1), colorBlack, Core.FILLED);
2181
assertEquals(0, Core.countNonZero(img));
2184
public void testPutTextMatStringPointIntDoubleScalarIntIntBoolean() {
2185
String text = "Hello World";
2186
Size labelSize = new Size(175, 22);
2188
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
2189
Point origin = new Point(10, 10);
2191
Imgproc.putText(img, text, origin, Core.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite, 1, Imgproc.LINE_8, true);
2193
assertTrue(Core.countNonZero(img) > 0);
2194
// check that border is not corrupted
2195
Imgproc.rectangle(img, new Point(10, 10), new Point(labelSize.width + 9, labelSize.height + 9), colorBlack, Core.FILLED);
2196
assertEquals(0, Core.countNonZero(img));