Path: blob/master/modules/imgproc/misc/java/test/ImgprocTest.java
16363 views
package org.opencv.test.imgproc;12import java.util.ArrayList;3import java.util.Arrays;4import java.util.List;56import org.opencv.core.Core;7import org.opencv.core.CvType;8import org.opencv.core.Mat;9import org.opencv.core.MatOfFloat;10import org.opencv.core.MatOfInt;11import org.opencv.core.MatOfInt4;12import org.opencv.core.MatOfPoint;13import org.opencv.core.MatOfPoint2f;14import org.opencv.core.Point;15import org.opencv.core.Rect;16import org.opencv.core.RotatedRect;17import org.opencv.core.Scalar;18import org.opencv.core.Size;19import org.opencv.core.TermCriteria;20import org.opencv.imgproc.Imgproc;21import org.opencv.test.OpenCVTestCase;2223public class ImgprocTest extends OpenCVTestCase {2425Point anchorPoint;26private int imgprocSz;27Size size;2829@Override30protected void setUp() throws Exception {31super.setUp();3233imgprocSz = 2;34anchorPoint = new Point(2, 2);35size = new Size(3, 3);36}3738public void testAccumulateMatMat() {39Mat src = getMat(CvType.CV_64F, 2);40Mat dst = getMat(CvType.CV_64F, 0);41Mat dst2 = src.clone();4243Imgproc.accumulate(src, dst);44Imgproc.accumulate(src, dst2);4546assertMatEqual(src, dst, EPS);47assertMatEqual(getMat(CvType.CV_64F, 4), dst2, EPS);48}4950public void testAccumulateMatMatMat() {51Mat src = getMat(CvType.CV_64F, 2);52Mat mask = makeMask(getMat(CvType.CV_8U, 1));53Mat dst = getMat(CvType.CV_64F, 0);54Mat dst2 = src.clone();5556Imgproc.accumulate(src, dst, mask);57Imgproc.accumulate(src, dst2, mask);5859assertMatEqual(makeMask(getMat(CvType.CV_64F, 2)), dst, EPS);60assertMatEqual(makeMask(getMat(CvType.CV_64F, 4), 2), dst2, EPS);61}6263public void testAccumulateProductMatMatMat() {64Mat src = getMat(CvType.CV_64F, 2);65Mat dst = getMat(CvType.CV_64F, 0);66Mat dst2 = src.clone();6768Imgproc.accumulateProduct(src, src, dst);69Imgproc.accumulateProduct(src, dst, dst2);7071assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);72assertMatEqual(getMat(CvType.CV_64F, 10), dst2, EPS);73}7475public void testAccumulateProductMatMatMatMat() {76Mat src = getMat(CvType.CV_64F, 2);77Mat mask = makeMask(getMat(CvType.CV_8U, 1));78Mat dst = getMat(CvType.CV_64F, 0);79Mat dst2 = src.clone();8081Imgproc.accumulateProduct(src, src, dst, mask);82Imgproc.accumulateProduct(src, dst, dst2, mask);8384assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);85assertMatEqual(makeMask(getMat(CvType.CV_64F, 10), 2), dst2, EPS);86}8788public void testAccumulateSquareMatMat() {89Mat src = getMat(CvType.CV_64F, 2);90Mat dst = getMat(CvType.CV_64F, 0);91Mat dst2 = src.clone();9293Imgproc.accumulateSquare(src, dst);94Imgproc.accumulateSquare(src, dst2);9596assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);97assertMatEqual(getMat(CvType.CV_64F, 6), dst2, EPS);98}99100public void testAccumulateSquareMatMatMat() {101Mat src = getMat(CvType.CV_64F, 2);102Mat mask = makeMask(getMat(CvType.CV_8U, 1));103Mat dst = getMat(CvType.CV_64F, 0);104Mat dst2 = src.clone();105106Imgproc.accumulateSquare(src, dst, mask);107Imgproc.accumulateSquare(src, dst2, mask);108109assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);110assertMatEqual(makeMask(getMat(CvType.CV_64F, 6), 2), dst2, EPS);111}112113public void testAccumulateWeightedMatMatDouble() {114Mat src = getMat(CvType.CV_64F, 2);115Mat dst = getMat(CvType.CV_64F, 4);116Mat dst2 = src.clone();117118Imgproc.accumulateWeighted(src, dst, 0.5);119Imgproc.accumulateWeighted(src, dst2, 2);120121assertMatEqual(getMat(CvType.CV_64F, 3), dst, EPS);122assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);123}124125public void testAccumulateWeightedMatMatDoubleMat() {126Mat src = getMat(CvType.CV_64F, 2);127Mat mask = makeMask(getMat(CvType.CV_8U, 1));128Mat dst = getMat(CvType.CV_64F, 4);129Mat dst2 = src.clone();130131Imgproc.accumulateWeighted(src, dst, 0.5, mask);132Imgproc.accumulateWeighted(src, dst2, 2, mask);133134assertMatEqual(makeMask(getMat(CvType.CV_64F, 3), 4), dst, EPS);135assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);136}137138public void testAdaptiveThreshold() {139Mat src = makeMask(getMat(CvType.CV_8U, 50), 20);140Mat dst = new Mat();141142Imgproc.adaptiveThreshold(src, dst, 1, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 3, 0);143144assertEquals(src.rows(), Core.countNonZero(dst));145}146147public void testApproxPolyDP() {148MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));149150MatOfPoint2f approxCurve = new MatOfPoint2f();151152Imgproc.approxPolyDP(curve, approxCurve, EPS, true);153154List<Point> approxCurveGold = new ArrayList<Point>(3);155approxCurveGold.add(new Point(1, 3));156approxCurveGold.add(new Point(3, 5));157approxCurveGold.add(new Point(5, 3));158159assertListPointEquals(approxCurve.toList(), approxCurveGold, EPS);160}161162public void testArcLength() {163MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));164165double arcLength = Imgproc.arcLength(curve, false);166167assertEquals(5.656854249, arcLength, 0.000001);168}169170public void testBilateralFilterMatMatIntDoubleDouble() {171Imgproc.bilateralFilter(gray255, dst, 5, 10, 5);172173assertMatEqual(gray255, dst);174// TODO_: write better test175}176177public void testBilateralFilterMatMatIntDoubleDoubleInt() {178Imgproc.bilateralFilter(gray255, dst, 5, 10, 5, Core.BORDER_REFLECT);179180assertMatEqual(gray255, dst);181// TODO_: write better test182}183184public void testBlurMatMatSize() {185Imgproc.blur(gray0, dst, size);186assertMatEqual(gray0, dst);187188Imgproc.blur(gray255, dst, size);189assertMatEqual(gray255, dst);190// TODO_: write better test191}192193public void testBlurMatMatSizePoint() {194Imgproc.blur(gray0, dst, size, anchorPoint);195assertMatEqual(gray0, dst);196// TODO_: write better test197}198199public void testBlurMatMatSizePointInt() {200Imgproc.blur(gray0, dst, size, anchorPoint, Core.BORDER_REFLECT);201assertMatEqual(gray0, dst);202// TODO_: write better test203}204205public void testBoundingRect() {206MatOfPoint points = new MatOfPoint(new Point(0, 0), new Point(0, 4), new Point(4, 0), new Point(4, 4));207Point p1 = new Point(1, 1);208Point p2 = new Point(-5, -2);209210Rect bbox = Imgproc.boundingRect(points);211212assertTrue(bbox.contains(p1));213assertFalse(bbox.contains(p2));214}215216public void testBoxFilterMatMatIntSize() {217Size size = new Size(3, 3);218Imgproc.boxFilter(gray0, dst, 8, size);219assertMatEqual(gray0, dst);220// TODO_: write better test221}222223public void testBoxFilterMatMatIntSizePointBoolean() {224Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false);225assertMatEqual(gray255, dst);226// TODO_: write better test227}228229public void testBoxFilterMatMatIntSizePointBooleanInt() {230Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false, Core.BORDER_REFLECT);231assertMatEqual(gray255, dst);232// TODO_: write better test233}234235public void testCalcBackProject() {236List<Mat> images = Arrays.asList(grayChess);237MatOfInt channels = new MatOfInt(0);238MatOfInt histSize = new MatOfInt(10);239MatOfFloat ranges = new MatOfFloat(0f, 256f);240241Mat hist = new Mat();242Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);243Core.normalize(hist, hist);244245Imgproc.calcBackProject(images, channels, hist, dst, ranges, 255);246247assertEquals(grayChess.size(), dst.size());248assertEquals(grayChess.depth(), dst.depth());249assertFalse(0 == Core.countNonZero(dst));250}251252public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat() {253List<Mat> images = Arrays.asList(gray128);254MatOfInt channels = new MatOfInt(0);255MatOfInt histSize = new MatOfInt(10);256MatOfFloat ranges = new MatOfFloat(0f, 256f);257Mat hist = new Mat();258259Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);260261truth = new Mat(10, 1, CvType.CV_32F, Scalar.all(0)) {262{263put(5, 0, 100);264}265};266assertMatEqual(truth, hist, EPS);267}268269public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2D() {270List<Mat> images = Arrays.asList(gray255, gray128);271MatOfInt channels = new MatOfInt(0, 1);272MatOfInt histSize = new MatOfInt(10, 10);273MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);274Mat hist = new Mat();275276Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);277278truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {279{280put(9, 5, 100);281}282};283assertMatEqual(truth, hist, EPS);284}285286public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat3D() {287List<Mat> images = Arrays.asList(rgbLena);288289Mat hist3D = new Mat();290List<Mat> histList = Arrays.asList( new Mat[] {new Mat(), new Mat(), new Mat()} );291292MatOfInt histSize = new MatOfInt(10);293MatOfFloat ranges = new MatOfFloat(0f, 256f);294295for(int i=0; i<rgbLena.channels(); i++)296{297Imgproc.calcHist(images, new MatOfInt(i), new Mat(), histList.get(i), histSize, ranges);298299assertEquals(10, histList.get(i).checkVector(1));300}301302Core.merge(histList, hist3D);303304assertEquals(CvType.CV_32FC3, hist3D.type());305assertEquals(10, hist3D.checkVector(3));306307Mat truth = new Mat(10, 1, CvType.CV_32FC3);308truth.put(0, 0,3090, 24870, 0,3101863, 31926, 1,31156682, 37677, 2260,31277278, 44751, 32436,31369397, 41343, 18526,31427180, 40407, 18658,31521101, 15993, 32042,3168343, 18585, 47786,317300, 6567, 80988,3180, 25, 29447319);320321assertMatEqual(truth, hist3D, EPS);322}323324public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean() {325List<Mat> images = Arrays.asList(gray255, gray128);326MatOfInt channels = new MatOfInt(0, 1);327MatOfInt histSize = new MatOfInt(10, 10);328MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);329Mat hist = new Mat();330331Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges, true);332333truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {334{335put(9, 5, 100);336}337};338assertMatEqual(truth, hist, EPS);339}340341public void testCannyMatMatDoubleDouble() {342Imgproc.Canny(gray255, dst, 5, 10);343assertMatEqual(gray0, dst);344// TODO_: write better test345}346347public void testCannyMatMatDoubleDoubleIntBoolean() {348Imgproc.Canny(gray0, dst, 5, 10, 5, true);349assertMatEqual(gray0, dst);350// TODO_: write better test351}352353public void testCompareHist() {354Mat H1 = new Mat(3, 1, CvType.CV_32F);355Mat H2 = new Mat(3, 1, CvType.CV_32F);356H1.put(0, 0, 1, 2, 3);357H2.put(0, 0, 4, 5, 6);358359double distance = Imgproc.compareHist(H1, H2, Imgproc.CV_COMP_CORREL);360361assertEquals(1., distance, EPS);362}363364public void testContourAreaMat() {365Mat contour = new Mat(1, 4, CvType.CV_32FC2);366contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);367368double area = Imgproc.contourArea(contour);369370assertEquals(45., area, EPS);371}372373public void testContourAreaMatBoolean() {374Mat contour = new Mat(1, 4, CvType.CV_32FC2);375contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);376377double area = Imgproc.contourArea(contour, true);378379assertEquals(45., area, EPS);380// TODO_: write better test381}382383public void testConvertMapsMatMatMatMatInt() {384Mat map1 = new Mat(1, 4, CvType.CV_32FC1, new Scalar(1));385Mat map2 = new Mat(1, 4, CvType.CV_32FC1, new Scalar(2));386Mat dstmap1 = new Mat(1, 4, CvType.CV_16SC2);387Mat dstmap2 = new Mat(1, 4, CvType.CV_16UC1);388389Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2);390391Mat truthMap1 = new Mat(1, 4, CvType.CV_16SC2);392truthMap1.put(0, 0, 1, 2, 1, 2, 1, 2, 1, 2);393assertMatEqual(truthMap1, dstmap1);394Mat truthMap2 = new Mat(1, 4, CvType.CV_16UC1, new Scalar(0));395assertMatEqual(truthMap2, dstmap2);396}397398public void testConvertMapsMatMatMatMatIntBoolean() {399Mat map1 = new Mat(1, 3, CvType.CV_32FC1, new Scalar(2));400Mat map2 = new Mat(1, 3, CvType.CV_32FC1, new Scalar(4));401Mat dstmap1 = new Mat(1, 3, CvType.CV_16SC2);402Mat dstmap2 = new Mat(1, 3, CvType.CV_16UC1);403404Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2, false);405// TODO_: write better test (last param == true)406407Mat truthMap1 = new Mat(1, 3, CvType.CV_16SC2);408truthMap1.put(0, 0, 2, 4, 2, 4, 2, 4);409assertMatEqual(truthMap1, dstmap1);410Mat truthMap2 = new Mat(1, 3, CvType.CV_16UC1, new Scalar(0));411assertMatEqual(truthMap2, dstmap2);412}413414public void testConvexHullMatMat() {415MatOfPoint points = new MatOfPoint(416new Point(20, 0),417new Point(40, 0),418new Point(30, 20),419new Point(0, 20),420new Point(20, 10),421new Point(30, 10)422);423424MatOfInt hull = new MatOfInt();425426Imgproc.convexHull(points, hull);427428MatOfInt expHull = new MatOfInt(4291, 2, 3, 0430);431assertMatEqual(expHull, hull, EPS);432}433434public void testConvexHullMatMatBooleanBoolean() {435MatOfPoint points = new MatOfPoint(436new Point(2, 0),437new Point(4, 0),438new Point(3, 2),439new Point(0, 2),440new Point(2, 1),441new Point(3, 1)442);443444MatOfInt hull = new MatOfInt();445446Imgproc.convexHull(points, hull, true);447448MatOfInt expHull = new MatOfInt(4493, 2, 1, 0450);451assertMatEqual(expHull, hull, EPS);452}453454public void testConvexityDefects() {455MatOfPoint points = new MatOfPoint(456new Point(20, 0),457new Point(40, 0),458new Point(30, 20),459new Point(0, 20),460new Point(20, 10),461new Point(30, 10)462);463464MatOfInt hull = new MatOfInt();465Imgproc.convexHull(points, hull);466467MatOfInt4 convexityDefects = new MatOfInt4();468Imgproc.convexityDefects(points, hull, convexityDefects);469470assertMatEqual(new MatOfInt4(3, 0, 5, 3620), convexityDefects);471}472473public void testCornerEigenValsAndVecsMatMatIntInt() {474fail("Not yet implemented");475// TODO: write better test476Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);477src.put(0, 0, 1, 2);478src.put(1, 0, 4, 2);479480int blockSize = 3;481int ksize = 5;482483// TODO: eigen vals and vectors returned = 0 for most src matrices484Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize);485truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC(6), new Scalar(0));486assertMatEqual(truth, dst, EPS);487}488489public void testCornerEigenValsAndVecsMatMatIntIntInt() {490fail("Not yet implemented");491// TODO: write better test492Mat src = new Mat(4, 4, CvType.CV_32FC1, new Scalar(128));493494int blockSize = 3;495int ksize = 5;496497truth = new Mat(4, 4, CvType.CV_32FC(6), new Scalar(0));498499Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize, Core.BORDER_REFLECT);500assertMatEqual(truth, dst, EPS);501}502503public void testCornerHarrisMatMatIntIntDouble() {504fail("Not yet implemented");505// TODO: write better test506507truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));508int blockSize = 5;509int ksize = 7;510double k = 0.1;511Imgproc.cornerHarris(gray128, dst, blockSize, ksize, k);512assertMatEqual(truth, dst, EPS);513}514515public void testCornerHarrisMatMatIntIntDoubleInt() {516fail("Not yet implemented");517// TODO: write better test518519truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));520int blockSize = 5;521int ksize = 7;522double k = 0.1;523Imgproc.cornerHarris(gray255, dst, blockSize, ksize, k, Core.BORDER_REFLECT);524assertMatEqual(truth, dst, EPS);525}526527public void testCornerMinEigenValMatMatInt() {528fail("Not yet implemented");529// TODO: write better test530531Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);532src.put(0, 0, 1, 2);533src.put(1, 0, 2, 1);534int blockSize = 5;535536Imgproc.cornerMinEigenVal(src, dst, blockSize);537538truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(0));539assertMatEqual(truth, dst, EPS);540541Imgproc.cornerMinEigenVal(gray255, dst, blockSize);542543truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));544assertMatEqual(truth, dst, EPS);545}546547public void testCornerMinEigenValMatMatIntInt() {548Mat src = Mat.eye(3, 3, CvType.CV_32FC1);549int blockSize = 3;550int ksize = 5;551552Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize);553554truth = new Mat(3, 3, CvType.CV_32FC1) {555{556put(0, 0, 1. / 18, 1. / 36, 1. / 18);557put(1, 0, 1. / 36, 1. / 18, 1. / 36);558put(2, 0, 1. / 18, 1. / 36, 1. / 18);559}560};561assertMatEqual(truth, dst, EPS);562}563564public void testCornerMinEigenValMatMatIntIntInt() {565Mat src = Mat.eye(3, 3, CvType.CV_32FC1);566int blockSize = 3;567int ksize = 5;568569Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize, Core.BORDER_REFLECT);570571truth = new Mat(3, 3, CvType.CV_32FC1) {572{573put(0, 0, 0.68055558, 0.92708349, 0.5868057);574put(1, 0, 0.92708343, 0.92708343, 0.92708343);575put(2, 0, 0.58680564, 0.92708343, 0.68055564);576}577};578assertMatEqual(truth, dst, EPS);579}580581public void testCornerSubPix() {582Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(128));583Point truthPosition = new Point(img.cols() / 2, img.rows() / 2);584585Rect r = new Rect(new Point(0, 0), truthPosition);586Imgproc.rectangle(img, r.tl(), r.br(), new Scalar(0), Imgproc.FILLED);587MatOfPoint2f corners = new MatOfPoint2f(new Point(truthPosition.x + 1, truthPosition.y + 1));588Size winSize = new Size(2, 2);589Size zeroZone = new Size(-1, -1);590TermCriteria criteria = new TermCriteria(TermCriteria.EPS, 0, 0.01);591592Imgproc.cornerSubPix(img, corners, winSize, zeroZone, criteria);593594assertPointEquals(truthPosition, corners.toList().get(0), weakEPS);595}596597public void testCvtColorMatMatInt() {598fail("Not yet implemented");599}600601public void testCvtColorMatMatIntInt() {602fail("Not yet implemented");603}604605public void testDilateMatMatMat() {606Mat kernel = new Mat();607608Imgproc.dilate(gray255, dst, kernel);609610assertMatEqual(gray255, dst);611612Imgproc.dilate(gray1, dst, kernel);613614assertMatEqual(gray1, dst);615// TODO_: write better test616}617618public void testDilateMatMatMatPoint() {619fail("Not yet implemented");620}621622public void testDilateMatMatMatPointInt() {623fail("Not yet implemented");624}625626public void testDilateMatMatMatPointIntInt() {627fail("Not yet implemented");628}629630public void testDilateMatMatMatPointIntIntScalar() {631fail("Not yet implemented");632}633634public void testDistanceTransformWithLabels() {635Mat dstLables = getMat(CvType.CV_32SC1, 0);636Mat labels = new Mat();637638Imgproc.distanceTransformWithLabels(gray128, dst, labels, Imgproc.CV_DIST_L2, 3);639640assertMatEqual(dstLables, labels);641assertMatEqual(getMat(CvType.CV_32FC1, 8192), dst, EPS);642}643644public void testDrawContoursMatListOfMatIntScalar() {645Imgproc.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100));646List<MatOfPoint> contours = new ArrayList<MatOfPoint>();647Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);648649Imgproc.drawContours(gray0, contours, -1, new Scalar(0));650651assertEquals(0, Core.countNonZero(gray0));652}653654public void testDrawContoursMatListOfMatIntScalarInt() {655Imgproc.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100));656List<MatOfPoint> contours = new ArrayList<MatOfPoint>();657Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);658659Imgproc.drawContours(gray0, contours, -1, new Scalar(0), Imgproc.FILLED);660661assertEquals(0, Core.countNonZero(gray0));662}663664665public void testDrawContoursMatListOfMatIntScalarIntIntMatIntPoint() {666fail("Not yet implemented");667}668669public void testEqualizeHist() {670Imgproc.equalizeHist(gray0, dst);671assertMatEqual(gray0, dst);672673Imgproc.equalizeHist(gray255, dst);674assertMatEqual(gray255, dst);675// TODO_: write better test676}677678public void testErodeMatMatMat() {679Mat kernel = new Mat();680681Imgproc.erode(gray128, dst, kernel);682683assertMatEqual(gray128, dst);684}685686public void testErodeMatMatMatPointInt() {687Mat src = new Mat(3, 3, CvType.CV_8U) {688{689put(0, 0, 15, 9, 10);690put(1, 0, 10, 8, 12);691put(2, 0, 12, 20, 25);692}693};694Mat kernel = new Mat();695696Imgproc.erode(src, dst, kernel, anchorPoint, 10);697698truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));699assertMatEqual(truth, dst);700}701702public void testErodeMatMatMatPointIntIntScalar() {703Mat src = new Mat(3, 3, CvType.CV_8U) {704{705put(0, 0, 15, 9, 10);706put(1, 0, 10, 8, 12);707put(2, 0, 12, 20, 25);708}709};710Mat kernel = new Mat();711Scalar sc = new Scalar(3, 3);712713Imgproc.erode(src, dst, kernel, anchorPoint, 10, Core.BORDER_REFLECT, sc);714715truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));716assertMatEqual(truth, dst);717}718719public void testFilter2DMatMatIntMat() {720Mat src = Mat.eye(4, 4, CvType.CV_32F);721Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1));722723Imgproc.filter2D(src, dst, -1, kernel);724725truth = new Mat(4, 4, CvType.CV_32F) {726{727put(0, 0, 2, 2, 1, 0);728put(1, 0, 2, 2, 1, 0);729put(2, 0, 1, 1, 2, 1);730put(3, 0, 0, 0, 1, 2);731}732};733assertMatEqual(truth, dst, EPS);734}735736public void testFilter2DMatMatIntMatPointDouble() {737fail("Not yet implemented");738}739740public void testFilter2DMatMatIntMatPointDoubleInt() {741Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));742Point point = new Point(0, 0);743744Imgproc.filter2D(gray128, dst, -1, kernel, point, 2, Core.BORDER_CONSTANT);745746assertMatEqual(gray2, dst);747}748749public void testFindContoursMatListOfMatMatIntInt() {750Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0));751List<MatOfPoint> contours = new ArrayList<MatOfPoint>(5);752Mat hierarchy = new Mat();753754Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);755756// no contours on empty image757assertEquals(contours.size(), 0);758assertEquals(contours.size(), hierarchy.total());759760Imgproc.rectangle(img, new Point(10, 20), new Point(20, 30), new Scalar(100), 3, Imgproc.LINE_AA, 0);761Imgproc.rectangle(img, new Point(30, 35), new Point(40, 45), new Scalar(200));762763Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);764765// two contours of two rectangles766assertEquals(contours.size(), 2);767assertEquals(contours.size(), hierarchy.total());768}769770public void testFindContoursMatListOfMatMatIntIntPoint() {771Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0));772Mat img2 = img.submat(5, 50, 3, 50);773List<MatOfPoint> contours = new ArrayList<MatOfPoint>();774List<MatOfPoint> contours2 = new ArrayList<MatOfPoint>();775Mat hierarchy = new Mat();776777Imgproc.rectangle(img, new Point(10, 20), new Point(20, 30), new Scalar(100), 3, Imgproc.LINE_AA, 0);778Imgproc.rectangle(img, new Point(30, 35), new Point(40, 45), new Scalar(200));779780Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);781Imgproc.findContours(img2, contours2, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE, new Point(3, 5));782783assertEquals(contours.size(), contours2.size());784assertMatEqual(contours.get(0), contours2.get(0));785/*786Log.d("findContours", "hierarchy=" + hierarchy);787int iBuff[] = new int[ (int) (hierarchy.total() * hierarchy.channels()) ]; // [ Contour0 (next sibling num, previous sibling num, 1st child num, parent num), Contour1(...), ...788hierarchy.get(0, 0, iBuff);789Log.d("findContours", Arrays.toString(iBuff));790*/791}792793public void testFitEllipse() {794MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-1, 1), new Point(1, 1), new Point(1, -1), new Point(-1, -1));795RotatedRect rrect = new RotatedRect();796797rrect = Imgproc.fitEllipse(points);798799assertPointEquals(new Point(0, 0), rrect.center, EPS);800assertEquals(2.828, rrect.size.width, EPS);801assertEquals(2.828, rrect.size.height, EPS);802}803804public void testFitLine() {805Mat points = new Mat(1, 4, CvType.CV_32FC2);806points.put(0, 0, 0, 0, 2, 3, 3, 4, 5, 8);807808Mat linePoints = new Mat(4, 1, CvType.CV_32FC1);809linePoints.put(0, 0, 0.53196341, 0.84676737, 2.496531, 3.7467217);810811Imgproc.fitLine(points, dst, Imgproc.CV_DIST_L12, 0, 0.01, 0.01);812813assertMatEqual(linePoints, dst, EPS);814}815816public void testFloodFillMatMatPointScalar() {817Mat mask = new Mat(matSize + 2, matSize + 2, CvType.CV_8U, new Scalar(0));818Mat img = gray0;819Imgproc.circle(mask, new Point(matSize / 2 + 1, matSize / 2 + 1), 3, new Scalar(2));820821int retval = Imgproc.floodFill(img, mask, new Point(matSize / 2, matSize / 2), new Scalar(1));822823assertEquals(Core.countNonZero(img), retval);824Imgproc.circle(mask, new Point(matSize / 2 + 1, matSize / 2 + 1), 3, new Scalar(0));825assertEquals(retval + 4 * (matSize + 1), Core.countNonZero(mask));826assertMatEqual(mask.submat(1, matSize + 1, 1, matSize + 1), img);827}828829public void testFloodFillMatMatPointScalar_WithoutMask() {830Mat img = gray0;831Imgproc.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(2));832833// TODO: ideally we should pass null instead of "new Mat()"834int retval = Imgproc.floodFill(img, new Mat(), new Point(matSize / 2, matSize / 2), new Scalar(1));835836Imgproc.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(0));837assertEquals(Core.countNonZero(img), retval);838}839840public void testFloodFillMatMatPointScalarRect() {841fail("Not yet implemented");842}843844public void testFloodFillMatMatPointScalarRectScalar() {845fail("Not yet implemented");846}847848public void testFloodFillMatMatPointScalarRectScalarScalar() {849fail("Not yet implemented");850}851852public void testFloodFillMatMatPointScalarRectScalarScalarInt() {853fail("Not yet implemented");854}855856public void testGaussianBlurMatMatSizeDouble() {857Imgproc.GaussianBlur(gray0, dst, size, 1);858assertMatEqual(gray0, dst);859860Imgproc.GaussianBlur(gray2, dst, size, 1);861assertMatEqual(gray2, dst);862}863864public void testGaussianBlurMatMatSizeDoubleDouble() {865Imgproc.GaussianBlur(gray2, dst, size, 0, 0);866867assertMatEqual(gray2, dst);868// TODO_: write better test869}870871public void testGaussianBlurMatMatSizeDoubleDoubleInt() {872Imgproc.GaussianBlur(gray2, dst, size, 1, 3, Core.BORDER_REFLECT);873874assertMatEqual(gray2, dst);875// TODO_: write better test876}877878public void testGetAffineTransform() {879MatOfPoint2f src = new MatOfPoint2f(new Point(2, 3), new Point(3, 1), new Point(1, 4));880MatOfPoint2f dst = new MatOfPoint2f(new Point(3, 3), new Point(7, 4), new Point(5, 6));881882Mat transform = Imgproc.getAffineTransform(src, dst);883884Mat truth = new Mat(2, 3, CvType.CV_64FC1) {885{886put(0, 0, -8, -6, 37);887put(1, 0, -7, -4, 29);888}889};890assertMatEqual(truth, transform, EPS);891}892893public void testGetDerivKernelsMatMatIntIntInt() {894Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);895Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);896Mat expKx = new Mat(3, 1, CvType.CV_32F);897Mat expKy = new Mat(3, 1, CvType.CV_32F);898kx.put(0, 0, 1, 1);899kx.put(1, 0, 1, 1);900ky.put(0, 0, 2, 2);901ky.put(1, 0, 2, 2);902expKx.put(0, 0, 1, -2, 1);903expKy.put(0, 0, 1, -2, 1);904905Imgproc.getDerivKernels(kx, ky, 2, 2, 3);906907assertMatEqual(expKx, kx, EPS);908assertMatEqual(expKy, ky, EPS);909}910911public void testGetDerivKernelsMatMatIntIntIntBooleanInt() {912Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);913Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);914Mat expKx = new Mat(3, 1, CvType.CV_32F);915Mat expKy = new Mat(3, 1, CvType.CV_32F);916kx.put(0, 0, 1, 1);917kx.put(1, 0, 1, 1);918ky.put(0, 0, 2, 2);919ky.put(1, 0, 2, 2);920expKx.put(0, 0, 1, -2, 1);921expKy.put(0, 0, 1, -2, 1);922923Imgproc.getDerivKernels(kx, ky, 2, 2, 3, true, CvType.CV_32F);924925assertMatEqual(expKx, kx, EPS);926assertMatEqual(expKy, ky, EPS);927// TODO_: write better test928}929930public void testGetGaussianKernelIntDouble() {931dst = Imgproc.getGaussianKernel(1, 0.5);932933truth = new Mat(1, 1, CvType.CV_64FC1, new Scalar(1));934assertMatEqual(truth, dst, EPS);935}936937public void testGetGaussianKernelIntDoubleInt() {938dst = Imgproc.getGaussianKernel(3, 0.8, CvType.CV_32F);939940truth = new Mat(3, 1, CvType.CV_32F);941truth.put(0, 0, 0.23899426, 0.52201146, 0.23899426);942assertMatEqual(truth, dst, EPS);943}944945public void testGetPerspectiveTransform() {946fail("Not yet implemented");947}948949public void testGetRectSubPixMatSizePointMat() {950Size size = new Size(3, 3);951Point center = new Point(gray255.cols() / 2, gray255.rows() / 2);952953Imgproc.getRectSubPix(gray255, size, center, dst);954955truth = new Mat(3, 3, CvType.CV_8U, new Scalar(255));956assertMatEqual(truth, dst);957}958959public void testGetRectSubPixMatSizePointMatInt() {960Mat src = new Mat(10, 10, CvType.CV_32F, new Scalar(2));961Size patchSize = new Size(5, 5);962Point center = new Point(src.cols() / 2, src.rows() / 2);963964Imgproc.getRectSubPix(src, patchSize, center, dst);965966truth = new Mat(5, 5, CvType.CV_32F, new Scalar(2));967assertMatEqual(truth, dst, EPS);968}969970public void testGetRotationMatrix2D() {971Point center = new Point(0, 0);972973dst = Imgproc.getRotationMatrix2D(center, 0, 1);974975truth = new Mat(2, 3, CvType.CV_64F) {976{977put(0, 0, 1, 0, 0);978put(1, 0, 0, 1, 0);979}980};981982assertMatEqual(truth, dst, EPS);983}984985public void testGetStructuringElementIntSize() {986dst = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, size);987988truth = new Mat(3, 3, CvType.CV_8UC1, new Scalar(1));989assertMatEqual(truth, dst);990}991992public void testGetStructuringElementIntSizePoint() {993dst = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, size, anchorPoint);994995truth = new Mat(3, 3, CvType.CV_8UC1) {996{997put(0, 0, 0, 0, 1);998put(1, 0, 0, 0, 1);999put(2, 0, 1, 1, 1);1000}1001};1002assertMatEqual(truth, dst);1003}10041005public void testGoodFeaturesToTrackMatListOfPointIntDoubleDouble() {1006Mat src = gray0;1007Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);1008MatOfPoint lp = new MatOfPoint();10091010Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3);10111012assertEquals(4, lp.total());1013}10141015public void testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDouble() {1016Mat src = gray0;1017Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);1018MatOfPoint lp = new MatOfPoint();10191020Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3, gray1, 4, 3, true, 0);10211022assertEquals(4, lp.total());1023}10241025public void testGrabCutMatMatRectMatMatInt() {1026fail("Not yet implemented");1027}10281029public void testGrabCutMatMatRectMatMatIntInt() {1030fail("Not yet implemented");1031}10321033public void testHoughCirclesMatMatIntDoubleDouble() {1034int sz = 512;1035Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));1036Mat circles = new Mat();10371038Imgproc.HoughCircles(img, circles, Imgproc.CV_HOUGH_GRADIENT, 2, img.rows() / 4);10391040assertEquals(0, circles.cols());1041}10421043public void testHoughCirclesMatMatIntDoubleDouble1() {1044int sz = 512;1045Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));1046Mat circles = new Mat();10471048Point center = new Point(img.cols() / 2, img.rows() / 2);1049int radius = Math.min(img.cols() / 4, img.rows() / 4);1050Imgproc.circle(img, center, radius, colorBlack, 3);10511052Imgproc.HoughCircles(img, circles, Imgproc.CV_HOUGH_GRADIENT, 2, img.rows() / 4);10531054assertEquals(1, circles.cols());1055}10561057public void testHoughCirclesMatMatIntDoubleDoubleDoubleDoubleIntInt() {1058fail("Not yet implemented");1059}10601061public void testHoughLinesMatMatDoubleDoubleInt() {1062int sz = 512;1063Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));1064Point point1 = new Point(50, 50);1065Point point2 = new Point(img.cols() / 2, img.rows() / 2);1066Imgproc.line(img, point1, point2, colorWhite, 1);1067Mat lines = new Mat();10681069Imgproc.HoughLines(img, lines, 1, 3.1415926/180, 100);10701071assertEquals(1, lines.cols());10721073/*1074Log.d("HoughLines", "lines=" + lines);1075int num = (int)lines.total();1076int buff[] = new int[num*4]; //[ (x1, y1, x2, y2), (...), ...]1077lines.get(0, 0, buff);1078Log.d("HoughLines", "lines=" + Arrays.toString(buff));1079*/1080}10811082public void testHoughLinesMatMatDoubleDoubleIntDouble() {1083fail("Not yet implemented");1084}10851086public void testHoughLinesMatMatDoubleDoubleIntDoubleDouble() {1087fail("Not yet implemented");1088}10891090public void testHoughLinesPMatMatDoubleDoubleInt() {1091int sz = 512;1092Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));1093Point point1 = new Point(0, 0);1094Point point2 = new Point(sz, sz);1095Point point3 = new Point(sz, 0);1096Point point4 = new Point(2*sz/3, sz/3);1097Imgproc.line(img, point1, point2, Scalar.all(255), 1);1098Imgproc.line(img, point3, point4, Scalar.all(255), 1);1099Mat lines = new Mat();11001101Imgproc.HoughLinesP(img, lines, 1, 3.1415926/180, 100);11021103assertEquals(2, lines.rows());11041105/*1106Log.d("HoughLinesP", "lines=" + lines);1107int num = (int)lines.cols();1108int buff[] = new int[num*4]; // CV_32SC4 as [ (x1, y1, x2, y2), (...), ...]1109lines.get(0, 0, buff);1110Log.d("HoughLinesP", "lines=" + Arrays.toString(buff));1111*/1112}11131114public void testHoughLinesPMatMatDoubleDoubleIntDouble() {1115fail("Not yet implemented");1116}11171118public void testHoughLinesPMatMatDoubleDoubleIntDoubleDouble() {1119fail("Not yet implemented");1120}11211122public void testHuMoments() {1123fail("Not yet implemented");1124}11251126public void testIntegral2MatMatMat() {1127Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));1128Mat expSum = new Mat(4, 4, CvType.CV_64F);1129Mat expSqsum = new Mat(4, 4, CvType.CV_64F);1130Mat sum = new Mat();1131Mat sqsum = new Mat();11321133expSum.put(0, 0, 0, 0, 0, 0);1134expSum.put(1, 0, 0, 3, 6, 9);1135expSum.put(2, 0, 0, 6, 12, 18);1136expSum.put(3, 0, 0, 9, 18, 27);11371138expSqsum.put(0, 0, 0, 0, 0, 0);1139expSqsum.put(1, 0, 0, 9, 18, 27);1140expSqsum.put(2, 0, 0, 18, 36, 54);1141expSqsum.put(3, 0, 0, 27, 54, 81);11421143Imgproc.integral2(src, sum, sqsum);11441145assertMatEqual(expSum, sum, EPS);1146assertMatEqual(expSqsum, sqsum, EPS);1147}11481149public void testIntegral2MatMatMatInt() {1150Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));1151Mat expSum = new Mat(4, 4, CvType.CV_64F);1152Mat expSqsum = new Mat(4, 4, CvType.CV_64F);1153Mat sum = new Mat();1154Mat sqsum = new Mat();11551156expSum.put(0, 0, 0, 0, 0, 0);1157expSum.put(1, 0, 0, 3, 6, 9);1158expSum.put(2, 0, 0, 6, 12, 18);1159expSum.put(3, 0, 0, 9, 18, 27);11601161expSqsum.put(0, 0, 0, 0, 0, 0);1162expSqsum.put(1, 0, 0, 9, 18, 27);1163expSqsum.put(2, 0, 0, 18, 36, 54);1164expSqsum.put(3, 0, 0, 27, 54, 81);11651166Imgproc.integral2(src, sum, sqsum, CvType.CV_64F, CvType.CV_64F);11671168assertMatEqual(expSum, sum, EPS);1169assertMatEqual(expSqsum, sqsum, EPS);1170}11711172public void testIntegral3MatMatMatMat() {1173Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));1174Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);1175Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);1176Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);1177Mat sum = new Mat();1178Mat sqsum = new Mat();1179Mat tilted = new Mat();11801181expSum.put(0, 0, 0, 0);1182expSum.put(1, 0, 0, 1);11831184expSqsum.put(0, 0, 0, 0);1185expSqsum.put(1, 0, 0, 1);11861187expTilted.put(0, 0, 0, 0);1188expTilted.put(1, 0, 0, 1);11891190Imgproc.integral3(src, sum, sqsum, tilted);11911192assertMatEqual(expSum, sum, EPS);1193assertMatEqual(expSqsum, sqsum, EPS);1194assertMatEqual(expTilted, tilted, EPS);1195}11961197public void testIntegral3MatMatMatMatInt() {1198Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));1199Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);1200Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);1201Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);1202Mat sum = new Mat();1203Mat sqsum = new Mat();1204Mat tilted = new Mat();12051206expSum.put(0, 0, 0, 0);1207expSum.put(1, 0, 0, 1);12081209expSqsum.put(0, 0, 0, 0);1210expSqsum.put(1, 0, 0, 1);12111212expTilted.put(0, 0, 0, 0);1213expTilted.put(1, 0, 0, 1);12141215Imgproc.integral3(src, sum, sqsum, tilted, CvType.CV_64F, CvType.CV_64F);12161217assertMatEqual(expSum, sum, EPS);1218assertMatEqual(expSqsum, sqsum, EPS);1219assertMatEqual(expTilted, tilted, EPS);1220}12211222public void testIntegralMatMat() {1223Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));12241225Imgproc.integral(src, dst);12261227truth = new Mat(3, 3, CvType.CV_64F) {1228{1229put(0, 0, 0, 0, 0);1230put(1, 0, 0, 2, 4);1231put(2, 0, 0, 4, 8);1232}1233};1234assertMatEqual(truth, dst, EPS);1235}12361237public void testIntegralMatMatInt() {1238Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));12391240Imgproc.integral(src, dst, CvType.CV_64F);12411242truth = new Mat(3, 3, CvType.CV_64F) {1243{1244put(0, 0, 0, 0, 0);1245put(1, 0, 0, 2, 4);1246put(2, 0, 0, 4, 8);1247}1248};1249assertMatEqual(truth, dst, EPS);1250}12511252public void testInvertAffineTransform() {1253Mat src = new Mat(2, 3, CvType.CV_64F, new Scalar(1));12541255Imgproc.invertAffineTransform(src, dst);12561257truth = new Mat(2, 3, CvType.CV_64F, new Scalar(0));1258assertMatEqual(truth, dst, EPS);1259}12601261public void testIsContourConvex() {1262MatOfPoint contour1 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4));12631264assertFalse(Imgproc.isContourConvex(contour1));12651266MatOfPoint contour2 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6));12671268assertTrue(Imgproc.isContourConvex(contour2));1269}12701271public void testLaplacianMatMatInt() {1272Imgproc.Laplacian(gray0, dst, CvType.CV_8U);12731274assertMatEqual(gray0, dst);1275}12761277public void testLaplacianMatMatIntIntDoubleDouble() {1278Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);12791280Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS);12811282truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {1283{1284put(0, 0, -7.9990001, 8.0009995);1285put(1, 0, 8.0009995, -7.9990001);1286}1287};1288assertMatEqual(truth, dst, EPS);1289}12901291public void testLaplacianMatMatIntIntDoubleDoubleInt() {1292Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(2));12931294Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS, Core.BORDER_REFLECT);12951296truth = new Mat(3, 3, CvType.CV_32F, new Scalar(0.00099945068));1297assertMatEqual(truth, dst, EPS);1298}12991300public void testMatchShapes() {1301Mat contour1 = new Mat(1, 4, CvType.CV_32FC2);1302Mat contour2 = new Mat(1, 4, CvType.CV_32FC2);1303contour1.put(0, 0, 1, 1, 5, 1, 4, 3, 6, 2);1304contour2.put(0, 0, 1, 1, 6, 1, 4, 1, 2, 5);13051306double distance = Imgproc.matchShapes(contour1, contour2, Imgproc.CV_CONTOURS_MATCH_I1, 1);13071308assertEquals(2.81109697365334, distance, EPS);1309}13101311public void testMatchTemplate() {1312Mat image = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);1313Mat templ = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);1314image.put(0, 0, 1, 2, 3, 4);1315templ.put(0, 0, 5, 6, 7, 8);13161317Imgproc.matchTemplate(image, templ, dst, Imgproc.TM_CCORR);13181319truth = new Mat(1, 1, CvType.CV_32F, new Scalar(70));1320assertMatEqual(truth, dst, EPS);13211322Imgproc.matchTemplate(gray255, gray0, dst, Imgproc.TM_CCORR);13231324truth = new Mat(1, 1, CvType.CV_32F, new Scalar(0));1325assertMatEqual(truth, dst, EPS);1326}13271328public void testMedianBlur() {1329Imgproc.medianBlur(gray255, dst, 5);1330assertMatEqual(gray255, dst);13311332Imgproc.medianBlur(gray2, dst, 3);1333assertMatEqual(gray2, dst);1334// TODO_: write better test1335}13361337public void testMinAreaRect() {1338MatOfPoint2f points = new MatOfPoint2f(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2));13391340RotatedRect rrect = Imgproc.minAreaRect(points);13411342assertEquals(new Size(2, 5), rrect.size);1343assertEquals(-90., rrect.angle);1344assertEquals(new Point(3.5, 2), rrect.center);1345}13461347public void testMinEnclosingCircle() {1348MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-100, 0), new Point(0, -100), new Point(100, 0), new Point(0, 100));1349Point actualCenter = new Point();1350float[] radius = new float[1];13511352Imgproc.minEnclosingCircle(points, actualCenter, radius);13531354assertEquals(new Point(0, 0), actualCenter);1355assertEquals(100.0f, radius[0], 1.0);1356}13571358public void testMomentsMat() {1359fail("Not yet implemented");1360}13611362public void testMomentsMatBoolean() {1363fail("Not yet implemented");1364}13651366public void testMorphologyExMatMatIntMat() {1367Imgproc.morphologyEx(gray255, dst, Imgproc.MORPH_GRADIENT, gray0);13681369assertMatEqual(gray0, dst);1370// TODO_: write better test1371}13721373public void testMorphologyExMatMatIntMatPointInt() {1374Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);13751376Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(0));1377Point point = new Point(0, 0);13781379Imgproc.morphologyEx(src, dst, Imgproc.MORPH_CLOSE, kernel, point, 10);13801381truth = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);1382assertMatEqual(truth, dst);1383// TODO_: write better test1384}138513861387public void testMorphologyExMatMatIntMatPointIntIntScalar() {1388Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);1389src.put(0, 0, 2, 1);1390src.put(1, 0, 2, 1);13911392Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(1));1393Point point = new Point(1, 1);1394Scalar sc = new Scalar(3, 3);13951396Imgproc.morphologyEx(src, dst, Imgproc.MORPH_TOPHAT, kernel, point, 10, Core.BORDER_REFLECT, sc);1397truth = new Mat(imgprocSz, imgprocSz, CvType.CV_8U) {1398{1399put(0, 0, 1, 0);1400put(1, 0, 1, 0);1401}1402};1403assertMatEqual(truth, dst);1404// TODO_: write better test1405}14061407public void testPointPolygonTest() {1408MatOfPoint2f contour = new MatOfPoint2f(new Point(0, 0), new Point(1, 3), new Point(3, 4), new Point(4, 3), new Point(2, 1));1409double sign1 = Imgproc.pointPolygonTest(contour, new Point(2, 2), false);1410assertEquals(1.0, sign1);14111412double sign2 = Imgproc.pointPolygonTest(contour, new Point(4, 4), true);1413assertEquals(-Math.sqrt(0.5), sign2);1414}14151416public void testPreCornerDetectMatMatInt() {1417Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));1418int ksize = 3;14191420Imgproc.preCornerDetect(src, dst, ksize);14211422truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));1423assertMatEqual(truth, dst, EPS);1424}14251426public void testPreCornerDetectMatMatIntInt() {1427Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));1428int ksize = 3;14291430Imgproc.preCornerDetect(src, dst, ksize, Core.BORDER_REFLECT);14311432truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));1433assertMatEqual(truth, dst, EPS);1434// TODO_: write better test1435}14361437public void testPyrDownMatMat() {1438Mat src = new Mat(4, 4, CvType.CV_32F) {1439{1440put(0, 0, 2, 1, 4, 2);1441put(1, 0, 3, 2, 6, 8);1442put(2, 0, 4, 6, 8, 10);1443put(3, 0, 12, 32, 6, 18);1444}1445};14461447Imgproc.pyrDown(src, dst);14481449truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {1450{1451put(0, 0, 2.78125, 4.609375);1452put(1, 0, 8.546875, 8.8515625);1453}1454};1455assertMatEqual(truth, dst, EPS);1456}14571458public void testPyrDownMatMatSize() {1459Mat src = new Mat(4, 4, CvType.CV_32F) {1460{1461put(0, 0, 2, 1, 4, 2);1462put(1, 0, 3, 2, 6, 8);1463put(2, 0, 4, 6, 8, 10);1464put(3, 0, 12, 32, 6, 18);1465}1466};1467Size dstSize = new Size(2, 2);14681469Imgproc.pyrDown(src, dst, dstSize);14701471truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {1472{1473put(0, 0, 2.78125, 4.609375);1474put(1, 0, 8.546875, 8.8515625);1475}1476};1477assertMatEqual(truth, dst, EPS);1478// TODO_: write better test1479}14801481public void testPyrMeanShiftFilteringMatMatDoubleDouble() {1482Mat src = new Mat(matSize, matSize, CvType.CV_8UC3, new Scalar(0));14831484Imgproc.pyrMeanShiftFiltering(src, dst, 10, 50);14851486assertMatEqual(src, dst);1487// TODO_: write better test1488}14891490public void testPyrMeanShiftFilteringMatMatDoubleDoubleInt() {1491fail("Not yet implemented");1492}14931494public void testPyrMeanShiftFilteringMatMatDoubleDoubleIntTermCriteria() {1495fail("Not yet implemented");1496}14971498public void testPyrUpMatMat() {1499Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);1500src.put(0, 0, 2, 1);1501src.put(1, 0, 3, 2);15021503Imgproc.pyrUp(src, dst);15041505truth = new Mat(4, 4, CvType.CV_32F) {1506{1507put(0, 0, 2, 1.75, 1.375, 1.25);1508put(1, 0, 2.25, 2, 1.625, 1.5);1509put(2, 0, 2.625, 2.375, 2, 1.875);1510put(3, 0, 2.75, 2.5, 2.125, 2);1511}1512};1513assertMatEqual(truth, dst, EPS);1514}15151516public void testPyrUpMatMatSize() {1517fail("Not yet implemented");1518}15191520public void testRemapMatMatMatMatInt() {1521fail("Not yet implemented");1522// this test does something weird1523Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));1524Mat map1 = new Mat(1, 3, CvType.CV_32FC1);1525Mat map2 = new Mat(1, 3, CvType.CV_32FC1);15261527map1.put(0, 0, 3, 6, 5);1528map2.put(0, 0, 4, 8, 12);15291530Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR);15311532truth = new Mat(1, 3, CvType.CV_32F, new Scalar(0));1533assertMatEqual(truth, dst, EPS);1534}15351536public void testRemapMatMatMatMatIntIntScalar() {1537fail("Not yet implemented");1538// this test does something weird1539Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));1540Mat map1 = new Mat(1, 3, CvType.CV_32FC1);1541Mat map2 = new Mat(1, 3, CvType.CV_32FC1);15421543Scalar sc = new Scalar(0);15441545map1.put(0, 0, 3, 6, 5, 0);1546map2.put(0, 0, 4, 8, 12);15471548truth = new Mat(1, 3, CvType.CV_32F, new Scalar(2));15491550Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR, Core.BORDER_REFLECT, sc);1551assertMatEqual(truth, dst, EPS);1552}15531554public void testResizeMatMatSize() {1555Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8UC1, new Scalar(1));1556Size dsize = new Size(1, 1);15571558Imgproc.resize(src, dst, dsize, 0, 0, Imgproc.INTER_LINEAR_EXACT);15591560truth = new Mat(1, 1, CvType.CV_8UC1, new Scalar(1));1561assertMatEqual(truth, dst);1562}15631564public void testResizeMatMatSizeDoubleDoubleInt() {1565Imgproc.resize(gray255, dst, new Size(2, 2), 0, 0, Imgproc.INTER_AREA);15661567truth = new Mat(2, 2, CvType.CV_8UC1, new Scalar(255));1568assertMatEqual(truth, dst);1569// TODO_: write better test1570}15711572public void testScharrMatMatIntIntInt() {1573Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);15741575Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0);15761577truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));1578assertMatEqual(truth, dst, EPS);1579}15801581public void testScharrMatMatIntIntIntDoubleDouble() {1582Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);15831584Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0.001);15851586truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0.001));1587assertMatEqual(truth, dst, EPS);1588}15891590public void testScharrMatMatIntIntIntDoubleDoubleInt() {1591Mat src = Mat.eye(3, 3, CvType.CV_32F);15921593Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0, Core.BORDER_REFLECT);15941595truth = new Mat(3, 3, CvType.CV_32F) {1596{1597put(0, 0, -15, -19.5, -4.5);1598put(1, 0, 10.5, 0, -10.5);1599put(2, 0, 4.5, 19.5, 15);1600}1601};1602assertMatEqual(truth, dst, EPS);1603}16041605public void testSepFilter2DMatMatIntMatMat() {1606Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));1607Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);1608Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);1609kernelX.put(0, 0, 4, 3, 7);1610kernelY.put(0, 0, 9, 4, 2);16111612Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY);16131614truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(420));1615assertMatEqual(truth, dst, EPS);1616}16171618public void testSepFilter2DMatMatIntMatMatPointDouble() {1619Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(2));1620Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);1621kernelX.put(0, 0, 2, 2, 2);1622Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);1623kernelY.put(0, 0, 1, 1, 1);16241625Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS);16261627truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(36 + weakEPS));1628assertMatEqual(truth, dst, EPS);1629}16301631public void testSepFilter2DMatMatIntMatMatPointDoubleInt() {1632Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);1633kernelX.put(0, 0, 2, 2, 2);16341635Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);1636kernelY.put(0, 0, 1, 1, 1);16371638Imgproc.sepFilter2D(gray0, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS, Core.BORDER_REFLECT);16391640truth = new Mat(10, 10, CvType.CV_32F, new Scalar(weakEPS));1641assertMatEqual(truth, dst, EPS);1642// TODO_: write better test1643}16441645public void testSobelMatMatIntIntInt() {1646Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0);16471648assertMatEqual(gray0, dst);1649}16501651public void testSobelMatMatIntIntIntIntDoubleDouble() {1652Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0, 3, 2, 0.001);1653assertMatEqual(gray0, dst);1654// TODO_: write better test1655}16561657public void testSobelMatMatIntIntIntIntDoubleDoubleInt() {1658Mat src = new Mat(3, 3, CvType.CV_32F) {1659{1660put(0, 0, 2, 0, 1);1661put(1, 0, 6, 4, 3);1662put(2, 0, 1, 0, 2);1663}1664};16651666Imgproc.Sobel(src, dst, CvType.CV_32F, 1, 0, 3, 2, 0, Core.BORDER_REPLICATE);16671668truth = new Mat(3, 3, CvType.CV_32F) {1669{1670put(0, 0, -16, -12, 4);1671put(1, 0, -14, -12, 2);1672put(2, 0, -10, 0, 10);1673}1674};1675assertMatEqual(truth, dst, EPS);1676}16771678public void testThreshold() {1679Imgproc.threshold(makeMask(gray0.clone(), 10), dst, 5, 255, Imgproc.THRESH_TRUNC);1680assertMatEqual(makeMask(gray0.clone(), 5), dst);16811682Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 1, 255, Imgproc.THRESH_BINARY);1683assertMatEqual(gray255, dst);16841685Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 3, 255, Imgproc.THRESH_BINARY_INV);1686assertMatEqual(makeMask(gray255.clone(), 0), dst);1687}16881689public void testWarpAffineMatMatMatSize() {1690Mat src = new Mat(3, 3, CvType.CV_32F) {1691{1692put(0, 0, 2, 0, 1);1693put(1, 0, 6, 4, 3);1694put(2, 0, 1, 0, 2);1695}1696};1697Mat M = new Mat(2, 3, CvType.CV_32F) {1698{1699put(0, 0, 1, 0, 1);1700put(1, 0, 0, 1, 1);1701}1702};17031704Imgproc.warpAffine(src, dst, M, new Size(3, 3));17051706truth = new Mat(3, 3, CvType.CV_32F) {1707{1708put(0, 0, 0, 0, 0);1709put(1, 0, 0, 2, 0);1710put(2, 0, 0, 6, 4);1711}1712};1713assertMatEqual(truth, dst, EPS);1714}17151716public void testWarpAffineMatMatMatSizeInt() {1717Mat src = new Mat(3, 3, CvType.CV_32F) {1718{1719put(0, 0, 2, 4, 1);1720put(1, 0, 6, 4, 3);1721put(2, 0, 0, 2, 2);1722}1723};1724Mat M = new Mat(2, 3, CvType.CV_32F) {1725{1726put(0, 0, 1, 0, 0);1727put(1, 0, 0, 0, 1);1728}1729};17301731Imgproc.warpAffine(src, dst, M, new Size(2, 2), Imgproc.WARP_INVERSE_MAP);17321733truth = new Mat(2, 2, CvType.CV_32F) {1734{1735put(0, 0, 6, 4);1736put(1, 0, 6, 4);1737}1738};1739assertMatEqual(truth, dst, EPS);1740}17411742public void testWarpAffineMatMatMatSizeIntInt() {1743fail("Not yet implemented");1744}17451746public void testWarpAffineMatMatMatSizeIntIntScalar() {1747fail("Not yet implemented");1748}17491750public void testWarpPerspectiveMatMatMatSize() {1751Mat src = new Mat(3, 3, CvType.CV_32F) {1752{1753put(0, 0, 2, 4, 1);1754put(1, 0, 0, 4, 5);1755put(2, 0, 1, 2, 2);1756}1757};1758Mat M = new Mat(3, 3, CvType.CV_32F) {1759{1760put(0, 0, 1, 0, 1);1761put(1, 0, 0, 1, 1);1762put(2, 0, 0, 0, 1);1763}1764};17651766Imgproc.warpPerspective(src, dst, M, new Size(3, 3));17671768truth = new Mat(3, 3, CvType.CV_32F) {1769{1770put(0, 0, 0, 0, 0);1771put(1, 0, 0, 2, 4);1772put(2, 0, 0, 0, 4);1773}1774};1775assertMatEqual(truth, dst, EPS);1776}17771778public void testWarpPerspectiveMatMatMatSizeInt() {1779fail("Not yet implemented");1780}17811782public void testWarpPerspectiveMatMatMatSizeIntInt() {1783fail("Not yet implemented");1784}17851786public void testWarpPerspectiveMatMatMatSizeIntIntScalar() {1787fail("Not yet implemented");1788}17891790public void testWatershed() {1791Mat image = Mat.eye(4, 4, CvType.CV_8UC(3));1792Mat markers = new Mat(4, 4, CvType.CV_32SC1, new Scalar(0));17931794Imgproc.watershed(image, markers);17951796truth = new Mat(4, 4, CvType.CV_32SC1) {1797{1798put(0, 0, -1, -1, -1, -1);1799put(1, 0, -1, 0, 0, -1);1800put(2, 0, -1, 0, 0, -1);1801put(3, 0, -1, -1, -1, -1);1802}1803};1804assertMatEqual(truth, markers);1805}18061807public void testGetTextSize() {1808String text = "Android all the way";1809double fontScale = 2;1810int thickness = 3;1811int baseLine[] = new int[1];18121813Imgproc.getTextSize(text, Imgproc.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, null);1814Size res = Imgproc.getTextSize(text, Imgproc.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, baseLine);18151816assertEquals(543.0, res.width);1817assertEquals(44.0, res.height);1818assertEquals(20, baseLine[0]);1819}18201821public void testCircleMatPointIntScalar() {1822Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);1823int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);1824Scalar color = new Scalar(128);18251826Imgproc.circle(gray0, center, radius, color);18271828assertTrue(0 != Core.countNonZero(gray0));1829}18301831public void testCircleMatPointIntScalarInt() {1832Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);1833int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);1834Scalar color = new Scalar(128);18351836Imgproc.circle(gray0, center, radius, color, Imgproc.FILLED);18371838assertTrue(0 != Core.countNonZero(gray0));1839}18401841public void testCircleMatPointIntScalarIntIntInt() {1842Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);1843Point center2 = new Point(gray0.cols(), gray0.rows());1844int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);1845Scalar color128 = new Scalar(128);1846Scalar color0 = new Scalar(0);18471848Imgproc.circle(gray0, center2, radius * 2, color128, 2, Imgproc.LINE_4, 1/*1849* Number1850* of1851* fractional1852* bits1853*/);1854assertFalse(0 == Core.countNonZero(gray0));18551856Imgproc.circle(gray0, center, radius, color0, 2, Imgproc.LINE_4, 0);18571858assertTrue(0 == Core.countNonZero(gray0));1859}18601861public void testClipLine() {1862Rect r = new Rect(10, 10, 10, 10);1863Point pt1 = new Point(5.0, 15.0);1864Point pt2 = new Point(25.0, 15.0);18651866assertTrue(Imgproc.clipLine(r, pt1, pt2));18671868Point pt1Clipped = new Point(10.0, 15.0);1869Point pt2Clipped = new Point(19.0, 15.0);1870assertEquals(pt1Clipped, pt1);1871assertEquals(pt2Clipped, pt2);18721873pt1 = new Point(5.0, 5.0);1874pt2 = new Point(25.0, 5.0);1875pt1Clipped = new Point(5.0, 5.0);1876pt2Clipped = new Point(25.0, 5.0);18771878assertFalse(Imgproc.clipLine(r, pt1, pt2));18791880assertEquals(pt1Clipped, pt1);1881assertEquals(pt2Clipped, pt2);1882}18831884public void testEllipse2Poly() {1885Point center = new Point(4, 4);1886Size axes = new Size(2, 2);1887int angle = 30;1888int arcStart = 30;1889int arcEnd = 60;1890int delta = 2;1891MatOfPoint pts = new MatOfPoint();18921893Imgproc.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts);18941895Point truth[] = {1896new Point(5, 6),1897new Point(4, 6)1898};1899assertArrayPointsEquals(truth, pts.toArray(), EPS);1900}19011902public void testEllipseMatPointSizeDoubleDoubleDoubleScalar() {1903Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);1904Size axes = new Size(2, 2);1905double angle = 30, startAngle = 60, endAngle = 90;19061907Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite);19081909assertTrue(0 != Core.countNonZero(gray0));1910}19111912public void testEllipseMatPointSizeDoubleDoubleDoubleScalarInt() {1913Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);1914Size axes = new Size(2, 2);1915double angle = 30, startAngle = 60, endAngle = 90;19161917Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Imgproc.FILLED);19181919assertTrue(0 != Core.countNonZero(gray0));1920}19211922public void testEllipseMatPointSizeDoubleDoubleDoubleScalarIntIntInt() {1923Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);1924Size axes = new Size(2, 2);1925Point center2 = new Point(gray0.cols(), gray0.rows());1926Size axes2 = new Size(4, 4);1927double angle = 30, startAngle = 0, endAngle = 30;19281929Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Imgproc.FILLED, Imgproc.LINE_4, 0);19301931assertTrue(0 != Core.countNonZero(gray0));19321933Imgproc.ellipse(gray0, center2, axes2, angle, startAngle, endAngle, colorBlack, Imgproc.FILLED, Imgproc.LINE_4, 1);19341935assertEquals(0, Core.countNonZero(gray0));1936}19371938public void testEllipseMatRotatedRectScalar() {1939int matSize = 10;1940Mat gray0 = Mat.zeros(matSize, matSize, CvType.CV_8U);1941Point center = new Point(matSize / 2, matSize / 2);1942Size size = new Size(matSize / 4, matSize / 2);1943RotatedRect box = new RotatedRect(center, size, 45);19441945Imgproc.ellipse(gray0, box, new Scalar(1));19461947final byte[] truth = new byte[] {19480, 0, 0, 0, 0, 0, 0, 0, 0, 0,19490, 0, 0, 0, 0, 0, 0, 0, 0, 0,19500, 0, 0, 0, 0, 0, 0, 0, 0, 0,19510, 0, 0, 0, 0, 0, 1, 1, 0, 0,19520, 0, 0, 0, 1, 1, 0, 1, 0, 0,19530, 0, 0, 0, 1, 0, 1, 0, 0, 0,19540, 0, 0, 1, 0, 1, 1, 0, 0, 0,19550, 0, 0, 1, 1, 0, 0, 0, 0, 0,19560, 0, 0, 0, 0, 0, 0, 0, 0, 0,19570, 0, 0, 0, 0, 0, 0, 0, 0, 0 };19581959assertMatEqual(new Mat(matSize, matSize, CvType.CV_8U) {1960{1961put(0, 0, truth);1962}1963}, gray0);1964}19651966public void testEllipseMatRotatedRectScalarInt() {1967Point center = new Point(matSize / 2, matSize / 2);1968Size size = new Size(matSize / 4, matSize / 2);1969RotatedRect box = new RotatedRect(center, size, 45);19701971Imgproc.ellipse(gray0, box, new Scalar(1), Imgproc.FILLED);1972Imgproc.ellipse(gray0, box, new Scalar(0));19731974assertTrue(0 < Core.countNonZero(gray0));1975}19761977public void testEllipseMatRotatedRectScalarIntInt() {1978Point center = new Point(matSize / 2, matSize / 2);1979Size size = new Size(2, matSize * 2 / 3);1980RotatedRect box = new RotatedRect(center, size, 20);19811982Imgproc.ellipse(gray0, box, new Scalar(9), 1, Imgproc.LINE_AA);1983Imgproc.ellipse(gray0, box, new Scalar(0), 1, Imgproc.LINE_4);19841985assertTrue(0 < Core.countNonZero(gray0));1986}19871988public void testPolylinesMatListOfListOfPointBooleanScalar() {1989Mat img = gray0;1990List<MatOfPoint> polyline = new ArrayList<MatOfPoint>();1991polyline.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));19921993Imgproc.polylines(img, polyline, true, new Scalar(100));19941995assertEquals(22, Core.countNonZero(img));19961997Imgproc.polylines(img, polyline, false, new Scalar(0));19981999assertEquals(4, Core.countNonZero(img));2000}20012002public void testPolylinesMatListOfListOfPointBooleanScalarInt() {2003Mat img = gray0;2004List<MatOfPoint> polyline = new ArrayList<MatOfPoint>();2005polyline.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));20062007Imgproc.polylines(img, polyline, true, new Scalar(100), 2);20082009assertEquals(62, Core.countNonZero(img));2010}20112012public void testPolylinesMatListOfListOfPointBooleanScalarIntIntInt() {2013Mat img = gray0;2014List<MatOfPoint> polyline1 = new ArrayList<MatOfPoint>();2015polyline1.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));2016List<MatOfPoint> polyline2 = new ArrayList<MatOfPoint>();2017polyline2.add(new MatOfPoint(new Point(2, 2), new Point(14, 2), new Point(14, 12), new Point(2, 12)));20182019Imgproc.polylines(img, polyline1, true, new Scalar(100), 2, Imgproc.LINE_8, 0);20202021assertTrue(Core.countNonZero(img) > 0);20222023Imgproc.polylines(img, polyline2, true, new Scalar(0), 2, Imgproc.LINE_8, 1);20242025assertEquals(0, Core.countNonZero(img));2026}20272028public void testPutTextMatStringPointIntDoubleScalar() {2029String text = "Hello World";2030Size labelSize = new Size(175, 22);2031Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);2032Point origin = new Point(10, labelSize.height + 10);20332034Imgproc.putText(img, text, origin, Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite);20352036assertTrue(Core.countNonZero(img) > 0);2037// check that border is not corrupted2038Imgproc.rectangle(img, new Point(11, 11), new Point(labelSize.width + 10, labelSize.height + 10), colorBlack, Imgproc.FILLED);2039assertEquals(0, Core.countNonZero(img));2040}20412042public void testPutTextMatStringPointIntDoubleScalarInt() {2043String text = "Hello World";2044Size labelSize = new Size(176, 22);2045Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);2046Point origin = new Point(10, labelSize.height + 10);20472048Imgproc.putText(img, text, origin, Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite, 2);20492050assertTrue(Core.countNonZero(img) > 0);2051// check that border is not corrupted2052Imgproc.rectangle(img, new Point(10, 10), new Point(labelSize.width + 10 + 1, labelSize.height + 10 + 1), colorBlack, Imgproc.FILLED);2053assertEquals(0, Core.countNonZero(img));2054}20552056public void testPutTextMatStringPointIntDoubleScalarIntIntBoolean() {2057String text = "Hello World";2058Size labelSize = new Size(175, 22);20592060Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);2061Point origin = new Point(10, 10);20622063Imgproc.putText(img, text, origin, Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite, 1, Imgproc.LINE_8, true);20642065assertTrue(Core.countNonZero(img) > 0);2066// check that border is not corrupted2067Imgproc.rectangle(img, new Point(10, 10), new Point(labelSize.width + 9, labelSize.height + 9), colorBlack, Imgproc.FILLED);2068assertEquals(0, Core.countNonZero(img));2069}2070}207120722073