2011-07-07 22:35:12 +08:00
|
|
|
package org.opencv.test.imgproc;
|
2011-06-30 20:07:31 +08:00
|
|
|
|
2011-07-19 19:44:30 +08:00
|
|
|
import java.util.ArrayList;
|
2011-08-07 05:19:23 +08:00
|
|
|
import java.util.Arrays;
|
2011-07-19 19:44:30 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
2011-07-28 19:28:33 +08:00
|
|
|
import org.opencv.core.Core;
|
2011-07-20 00:08:26 +08:00
|
|
|
import org.opencv.core.CvType;
|
|
|
|
import org.opencv.core.Mat;
|
2012-04-14 05:50:59 +08:00
|
|
|
import org.opencv.core.MatOfFloat;
|
|
|
|
import org.opencv.core.MatOfInt;
|
2012-04-30 22:33:52 +08:00
|
|
|
import org.opencv.core.MatOfInt4;
|
2012-04-14 05:50:59 +08:00
|
|
|
import org.opencv.core.MatOfPoint;
|
|
|
|
import org.opencv.core.MatOfPoint2f;
|
2011-07-22 20:47:11 +08:00
|
|
|
import org.opencv.core.Point;
|
|
|
|
import org.opencv.core.Rect;
|
|
|
|
import org.opencv.core.RotatedRect;
|
2011-07-20 00:08:26 +08:00
|
|
|
import org.opencv.core.Scalar;
|
|
|
|
import org.opencv.core.Size;
|
2011-07-30 20:01:00 +08:00
|
|
|
import org.opencv.core.TermCriteria;
|
2011-07-20 00:08:26 +08:00
|
|
|
import org.opencv.imgproc.Imgproc;
|
2011-07-07 22:35:12 +08:00
|
|
|
import org.opencv.test.OpenCVTestCase;
|
2011-06-30 20:07:31 +08:00
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public class ImgprocTest extends OpenCVTestCase {
|
2011-08-03 19:57:00 +08:00
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
Point anchorPoint;
|
2011-07-28 01:06:33 +08:00
|
|
|
private int imgprocSz;
|
|
|
|
Size size;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
|
|
|
|
imgprocSz = 2;
|
|
|
|
anchorPoint = new Point(2, 2);
|
|
|
|
size = new Size(3, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testAccumulateMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = getMat(CvType.CV_64F, 2);
|
|
|
|
Mat dst = getMat(CvType.CV_64F, 0);
|
|
|
|
Mat dst2 = src.clone();
|
|
|
|
|
|
|
|
Imgproc.accumulate(src, dst);
|
|
|
|
Imgproc.accumulate(src, dst2);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
assertMatEqual(src, dst, EPS);
|
|
|
|
assertMatEqual(getMat(CvType.CV_64F, 4), dst2, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAccumulateMatMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = getMat(CvType.CV_64F, 2);
|
|
|
|
Mat mask = makeMask(getMat(CvType.CV_8U, 1));
|
|
|
|
Mat dst = getMat(CvType.CV_64F, 0);
|
|
|
|
Mat dst2 = src.clone();
|
|
|
|
|
|
|
|
Imgproc.accumulate(src, dst, mask);
|
|
|
|
Imgproc.accumulate(src, dst2, mask);
|
|
|
|
|
|
|
|
assertMatEqual(makeMask(getMat(CvType.CV_64F, 2)), dst, EPS);
|
|
|
|
assertMatEqual(makeMask(getMat(CvType.CV_64F, 4), 2), dst2, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAccumulateProductMatMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = getMat(CvType.CV_64F, 2);
|
|
|
|
Mat dst = getMat(CvType.CV_64F, 0);
|
|
|
|
Mat dst2 = src.clone();
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.accumulateProduct(src, src, dst);
|
|
|
|
Imgproc.accumulateProduct(src, dst, dst2);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);
|
|
|
|
assertMatEqual(getMat(CvType.CV_64F, 10), dst2, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAccumulateProductMatMatMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = getMat(CvType.CV_64F, 2);
|
|
|
|
Mat mask = makeMask(getMat(CvType.CV_8U, 1));
|
|
|
|
Mat dst = getMat(CvType.CV_64F, 0);
|
|
|
|
Mat dst2 = src.clone();
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.accumulateProduct(src, src, dst, mask);
|
|
|
|
Imgproc.accumulateProduct(src, dst, dst2, mask);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);
|
|
|
|
assertMatEqual(makeMask(getMat(CvType.CV_64F, 10), 2), dst2, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAccumulateSquareMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = getMat(CvType.CV_64F, 2);
|
|
|
|
Mat dst = getMat(CvType.CV_64F, 0);
|
|
|
|
Mat dst2 = src.clone();
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.accumulateSquare(src, dst);
|
|
|
|
Imgproc.accumulateSquare(src, dst2);
|
|
|
|
|
|
|
|
assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);
|
|
|
|
assertMatEqual(getMat(CvType.CV_64F, 6), dst2, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAccumulateSquareMatMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = getMat(CvType.CV_64F, 2);
|
|
|
|
Mat mask = makeMask(getMat(CvType.CV_8U, 1));
|
|
|
|
Mat dst = getMat(CvType.CV_64F, 0);
|
|
|
|
Mat dst2 = src.clone();
|
|
|
|
|
|
|
|
Imgproc.accumulateSquare(src, dst, mask);
|
|
|
|
Imgproc.accumulateSquare(src, dst2, mask);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);
|
|
|
|
assertMatEqual(makeMask(getMat(CvType.CV_64F, 6), 2), dst2, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAccumulateWeightedMatMatDouble() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = getMat(CvType.CV_64F, 2);
|
|
|
|
Mat dst = getMat(CvType.CV_64F, 4);
|
|
|
|
Mat dst2 = src.clone();
|
|
|
|
|
|
|
|
Imgproc.accumulateWeighted(src, dst, 0.5);
|
|
|
|
Imgproc.accumulateWeighted(src, dst2, 2);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
assertMatEqual(getMat(CvType.CV_64F, 3), dst, EPS);
|
|
|
|
assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAccumulateWeightedMatMatDoubleMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = getMat(CvType.CV_64F, 2);
|
|
|
|
Mat mask = makeMask(getMat(CvType.CV_8U, 1));
|
|
|
|
Mat dst = getMat(CvType.CV_64F, 4);
|
|
|
|
Mat dst2 = src.clone();
|
|
|
|
|
|
|
|
Imgproc.accumulateWeighted(src, dst, 0.5, mask);
|
|
|
|
Imgproc.accumulateWeighted(src, dst2, 2, mask);
|
|
|
|
|
|
|
|
assertMatEqual(makeMask(getMat(CvType.CV_64F, 3), 4), dst, EPS);
|
|
|
|
assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testAdaptiveThreshold() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = makeMask(getMat(CvType.CV_8U, 50), 20);
|
|
|
|
Mat dst = new Mat();
|
|
|
|
|
|
|
|
Imgproc.adaptiveThreshold(src, dst, 1, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 3, 0);
|
|
|
|
|
|
|
|
assertEquals(src.rows(), Core.countNonZero(dst));
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testApproxPolyDP() {
|
2012-10-17 15:12:04 +08:00
|
|
|
MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));
|
|
|
|
|
|
|
|
MatOfPoint2f approxCurve = new MatOfPoint2f();
|
2012-03-23 23:18:05 +08:00
|
|
|
|
|
|
|
Imgproc.approxPolyDP(curve, approxCurve, EPS, true);
|
|
|
|
|
|
|
|
List<Point> approxCurveGold = new ArrayList<Point>(3);
|
|
|
|
approxCurveGold.add(new Point(1, 3));
|
|
|
|
approxCurveGold.add(new Point(3, 5));
|
|
|
|
approxCurveGold.add(new Point(5, 3));
|
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
assertListPointEquals(approxCurve.toList(), approxCurveGold, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testArcLength() {
|
2012-04-14 05:50:59 +08:00
|
|
|
MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
double arcLength = Imgproc.arcLength(curve, false);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2015-02-19 21:17:19 +08:00
|
|
|
assertEquals(5.656854249, arcLength, 0.000001);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testBilateralFilterMatMatIntDoubleDouble() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.bilateralFilter(gray255, dst, 5, 10, 5);
|
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray255, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testBilateralFilterMatMatIntDoubleDoubleInt() {
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.bilateralFilter(gray255, dst, 5, 10, 5, Core.BORDER_REFLECT);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray255, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testBlurMatMatSize() {
|
|
|
|
Imgproc.blur(gray0, dst, size);
|
|
|
|
assertMatEqual(gray0, dst);
|
|
|
|
|
|
|
|
Imgproc.blur(gray255, dst, size);
|
|
|
|
assertMatEqual(gray255, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testBlurMatMatSizePoint() {
|
|
|
|
Imgproc.blur(gray0, dst, size, anchorPoint);
|
|
|
|
assertMatEqual(gray0, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testBlurMatMatSizePointInt() {
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.blur(gray0, dst, size, anchorPoint, Core.BORDER_REFLECT);
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray0, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testBoundingRect() {
|
2012-04-14 05:50:59 +08:00
|
|
|
MatOfPoint points = new MatOfPoint(new Point(0, 0), new Point(0, 4), new Point(4, 0), new Point(4, 4));
|
2011-07-28 01:06:33 +08:00
|
|
|
Point p1 = new Point(1, 1);
|
|
|
|
Point p2 = new Point(-5, -2);
|
|
|
|
|
|
|
|
Rect bbox = Imgproc.boundingRect(points);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertTrue(bbox.contains(p1));
|
|
|
|
assertFalse(bbox.contains(p2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testBoxFilterMatMatIntSize() {
|
|
|
|
Size size = new Size(3, 3);
|
|
|
|
Imgproc.boxFilter(gray0, dst, 8, size);
|
|
|
|
assertMatEqual(gray0, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testBoxFilterMatMatIntSizePointBoolean() {
|
|
|
|
Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false);
|
|
|
|
assertMatEqual(gray255, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testBoxFilterMatMatIntSizePointBooleanInt() {
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false, Core.BORDER_REFLECT);
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray255, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCalcBackProject() {
|
2011-08-07 05:19:23 +08:00
|
|
|
List<Mat> images = Arrays.asList(grayChess);
|
2012-04-30 22:33:52 +08:00
|
|
|
MatOfInt channels = new MatOfInt(0);
|
|
|
|
MatOfInt histSize = new MatOfInt(10);
|
|
|
|
MatOfFloat ranges = new MatOfFloat(0f, 256f);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Mat hist = new Mat();
|
|
|
|
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
|
|
|
|
Core.normalize(hist, hist);
|
|
|
|
|
|
|
|
Imgproc.calcBackProject(images, channels, hist, dst, ranges, 255);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
assertEquals(grayChess.size(), dst.size());
|
2011-07-28 01:06:33 +08:00
|
|
|
assertEquals(grayChess.depth(), dst.depth());
|
2011-08-07 05:19:23 +08:00
|
|
|
assertFalse(0 == Core.countNonZero(dst));
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
List<Mat> images = Arrays.asList(gray128);
|
2012-04-30 22:33:52 +08:00
|
|
|
MatOfInt channels = new MatOfInt(0);
|
|
|
|
MatOfInt histSize = new MatOfInt(10);
|
|
|
|
MatOfFloat ranges = new MatOfFloat(0f, 256f);
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat hist = new Mat();
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(10, 1, CvType.CV_32F, Scalar.all(0)) {
|
|
|
|
{
|
|
|
|
put(5, 0, 100);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, hist, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2D() {
|
2011-08-07 05:19:23 +08:00
|
|
|
List<Mat> images = Arrays.asList(gray255, gray128);
|
2012-04-30 22:33:52 +08:00
|
|
|
MatOfInt channels = new MatOfInt(0, 1);
|
|
|
|
MatOfInt histSize = new MatOfInt(10, 10);
|
|
|
|
MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat hist = new Mat();
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {
|
|
|
|
{
|
|
|
|
put(9, 5, 100);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, hist, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat3D() {
|
|
|
|
List<Mat> images = Arrays.asList(rgbLena);
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
Mat hist3D = new Mat();
|
|
|
|
List<Mat> histList = Arrays.asList( new Mat[] {new Mat(), new Mat(), new Mat()} );
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
MatOfInt histSize = new MatOfInt(10);
|
|
|
|
MatOfFloat ranges = new MatOfFloat(0f, 256f);
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
for(int i=0; i<rgbLena.channels(); i++)
|
|
|
|
{
|
|
|
|
Imgproc.calcHist(images, new MatOfInt(i), new Mat(), histList.get(i), histSize, ranges);
|
|
|
|
|
|
|
|
assertEquals(10, histList.get(i).checkVector(1));
|
|
|
|
}
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
Core.merge(histList, hist3D);
|
|
|
|
|
|
|
|
assertEquals(CvType.CV_32FC3, hist3D.type());
|
|
|
|
assertEquals(10, hist3D.checkVector(3));
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
Mat truth = new Mat(10, 1, CvType.CV_32FC3);
|
|
|
|
truth.put(0, 0,
|
2012-10-17 15:12:04 +08:00
|
|
|
0, 24870, 0,
|
|
|
|
1863, 31926, 1,
|
|
|
|
56682, 37677, 2260,
|
|
|
|
77278, 44751, 32436,
|
|
|
|
69397, 41343, 18526,
|
|
|
|
27180, 40407, 18658,
|
|
|
|
21101, 15993, 32042,
|
|
|
|
8343, 18585, 47786,
|
|
|
|
300, 6567, 80988,
|
|
|
|
0, 25, 29447
|
|
|
|
);
|
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
assertMatEqual(truth, hist3D, EPS);
|
|
|
|
}
|
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean() {
|
2011-08-07 05:19:23 +08:00
|
|
|
List<Mat> images = Arrays.asList(gray255, gray128);
|
2012-04-30 22:33:52 +08:00
|
|
|
MatOfInt channels = new MatOfInt(0, 1);
|
|
|
|
MatOfInt histSize = new MatOfInt(10, 10);
|
|
|
|
MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat hist = new Mat();
|
|
|
|
|
2011-08-02 21:47:40 +08:00
|
|
|
Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges, true);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {
|
|
|
|
{
|
|
|
|
put(9, 5, 100);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, hist, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCannyMatMatDoubleDouble() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.Canny(gray255, dst, 5, 10);
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray0, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCannyMatMatDoubleDoubleIntBoolean() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.Canny(gray0, dst, 5, 10, 5, true);
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray0, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCompareHist() {
|
|
|
|
Mat H1 = new Mat(3, 1, CvType.CV_32F);
|
|
|
|
Mat H2 = new Mat(3, 1, CvType.CV_32F);
|
|
|
|
H1.put(0, 0, 1, 2, 3);
|
|
|
|
H2.put(0, 0, 4, 5, 6);
|
|
|
|
|
2022-12-15 02:57:08 +08:00
|
|
|
double distance = Imgproc.compareHist(H1, H2, Imgproc.HISTCMP_CORREL);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2016-11-23 01:08:27 +08:00
|
|
|
assertEquals(1., distance, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testContourAreaMat() {
|
|
|
|
Mat contour = new Mat(1, 4, CvType.CV_32FC2);
|
2011-08-07 05:19:23 +08:00
|
|
|
contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
double area = Imgproc.contourArea(contour);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2016-11-23 01:08:27 +08:00
|
|
|
assertEquals(45., area, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testContourAreaMatBoolean() {
|
|
|
|
Mat contour = new Mat(1, 4, CvType.CV_32FC2);
|
2011-08-07 05:19:23 +08:00
|
|
|
contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
double area = Imgproc.contourArea(contour, true);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2016-11-23 01:08:27 +08:00
|
|
|
assertEquals(45., area, EPS);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testConvertMapsMatMatMatMatInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat map1 = new Mat(1, 4, CvType.CV_32FC1, new Scalar(1));
|
|
|
|
Mat map2 = new Mat(1, 4, CvType.CV_32FC1, new Scalar(2));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat dstmap1 = new Mat(1, 4, CvType.CV_16SC2);
|
|
|
|
Mat dstmap2 = new Mat(1, 4, CvType.CV_16UC1);
|
|
|
|
|
2011-07-30 20:01:00 +08:00
|
|
|
Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-30 20:01:00 +08:00
|
|
|
Mat truthMap1 = new Mat(1, 4, CvType.CV_16SC2);
|
|
|
|
truthMap1.put(0, 0, 1, 2, 1, 2, 1, 2, 1, 2);
|
|
|
|
assertMatEqual(truthMap1, dstmap1);
|
2011-08-02 21:47:40 +08:00
|
|
|
Mat truthMap2 = new Mat(1, 4, CvType.CV_16UC1, new Scalar(0));
|
2011-07-30 20:01:00 +08:00
|
|
|
assertMatEqual(truthMap2, dstmap2);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testConvertMapsMatMatMatMatIntBoolean() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat map1 = new Mat(1, 3, CvType.CV_32FC1, new Scalar(2));
|
|
|
|
Mat map2 = new Mat(1, 3, CvType.CV_32FC1, new Scalar(4));
|
2011-08-02 21:47:40 +08:00
|
|
|
Mat dstmap1 = new Mat(1, 3, CvType.CV_16SC2);
|
|
|
|
Mat dstmap2 = new Mat(1, 3, CvType.CV_16UC1);
|
|
|
|
|
|
|
|
Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2, false);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test (last param == true)
|
|
|
|
|
2011-08-02 21:47:40 +08:00
|
|
|
Mat truthMap1 = new Mat(1, 3, CvType.CV_16SC2);
|
|
|
|
truthMap1.put(0, 0, 2, 4, 2, 4, 2, 4);
|
|
|
|
assertMatEqual(truthMap1, dstmap1);
|
|
|
|
Mat truthMap2 = new Mat(1, 3, CvType.CV_16UC1, new Scalar(0));
|
|
|
|
assertMatEqual(truthMap2, dstmap2);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testConvexHullMatMat() {
|
2012-10-17 15:12:04 +08:00
|
|
|
MatOfPoint points = new MatOfPoint(
|
|
|
|
new Point(20, 0),
|
|
|
|
new Point(40, 0),
|
|
|
|
new Point(30, 20),
|
|
|
|
new Point(0, 20),
|
|
|
|
new Point(20, 10),
|
|
|
|
new Point(30, 10)
|
|
|
|
);
|
|
|
|
|
|
|
|
MatOfInt hull = new MatOfInt();
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
Imgproc.convexHull(points, hull);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
MatOfInt expHull = new MatOfInt(
|
2020-02-21 23:18:24 +08:00
|
|
|
0, 1, 2, 3
|
2012-04-30 22:33:52 +08:00
|
|
|
);
|
|
|
|
assertMatEqual(expHull, hull, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testConvexHullMatMatBooleanBoolean() {
|
2012-10-17 15:12:04 +08:00
|
|
|
MatOfPoint points = new MatOfPoint(
|
|
|
|
new Point(2, 0),
|
|
|
|
new Point(4, 0),
|
|
|
|
new Point(3, 2),
|
|
|
|
new Point(0, 2),
|
|
|
|
new Point(2, 1),
|
|
|
|
new Point(3, 1)
|
|
|
|
);
|
|
|
|
|
|
|
|
MatOfInt hull = new MatOfInt();
|
2012-04-30 22:33:52 +08:00
|
|
|
|
|
|
|
Imgproc.convexHull(points, hull, true);
|
|
|
|
|
|
|
|
MatOfInt expHull = new MatOfInt(
|
2012-10-17 15:12:04 +08:00
|
|
|
3, 2, 1, 0
|
2012-04-30 22:33:52 +08:00
|
|
|
);
|
|
|
|
assertMatEqual(expHull, hull, EPS);
|
|
|
|
}
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
public void testConvexityDefects() {
|
2012-10-17 15:12:04 +08:00
|
|
|
MatOfPoint points = new MatOfPoint(
|
|
|
|
new Point(20, 0),
|
|
|
|
new Point(40, 0),
|
|
|
|
new Point(30, 20),
|
|
|
|
new Point(0, 20),
|
|
|
|
new Point(20, 10),
|
|
|
|
new Point(30, 10)
|
|
|
|
);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
|
|
|
MatOfInt hull = new MatOfInt();
|
|
|
|
Imgproc.convexHull(points, hull);
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
MatOfInt4 convexityDefects = new MatOfInt4();
|
|
|
|
Imgproc.convexityDefects(points, hull, convexityDefects);
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
assertMatEqual(new MatOfInt4(3, 0, 5, 3620), convexityDefects);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCornerEigenValsAndVecsMatMatIntInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
|
|
|
// TODO: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);
|
|
|
|
src.put(0, 0, 1, 2);
|
|
|
|
src.put(1, 0, 4, 2);
|
|
|
|
|
|
|
|
int blockSize = 3;
|
|
|
|
int ksize = 5;
|
|
|
|
|
|
|
|
// TODO: eigen vals and vectors returned = 0 for most src matrices
|
|
|
|
Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize);
|
2011-08-03 22:18:26 +08:00
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC(6), new Scalar(0));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCornerEigenValsAndVecsMatMatIntIntInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
|
|
|
// TODO: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat src = new Mat(4, 4, CvType.CV_32FC1, new Scalar(128));
|
|
|
|
|
|
|
|
int blockSize = 3;
|
|
|
|
int ksize = 5;
|
|
|
|
|
|
|
|
truth = new Mat(4, 4, CvType.CV_32FC(6), new Scalar(0));
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize, Core.BORDER_REFLECT);
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCornerHarrisMatMatIntIntDouble() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
|
|
|
// TODO: write better test
|
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
|
|
|
|
int blockSize = 5;
|
|
|
|
int ksize = 7;
|
|
|
|
double k = 0.1;
|
|
|
|
Imgproc.cornerHarris(gray128, dst, blockSize, ksize, k);
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCornerHarrisMatMatIntIntDoubleInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
|
|
|
// TODO: write better test
|
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
|
|
|
|
int blockSize = 5;
|
|
|
|
int ksize = 7;
|
|
|
|
double k = 0.1;
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.cornerHarris(gray255, dst, blockSize, ksize, k, Core.BORDER_REFLECT);
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCornerMinEigenValMatMatInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
|
|
|
// TODO: write better test
|
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);
|
|
|
|
src.put(0, 0, 1, 2);
|
|
|
|
src.put(1, 0, 2, 1);
|
|
|
|
int blockSize = 5;
|
|
|
|
|
|
|
|
Imgproc.cornerMinEigenVal(src, dst, blockSize);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(0));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Imgproc.cornerMinEigenVal(gray255, dst, blockSize);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
|
|
|
truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
|
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCornerMinEigenValMatMatIntInt() {
|
|
|
|
Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
|
|
|
|
int blockSize = 3;
|
|
|
|
int ksize = 5;
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize);
|
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(3, 3, CvType.CV_32FC1) {
|
|
|
|
{
|
|
|
|
put(0, 0, 1. / 18, 1. / 36, 1. / 18);
|
|
|
|
put(1, 0, 1. / 36, 1. / 18, 1. / 36);
|
|
|
|
put(2, 0, 1. / 18, 1. / 36, 1. / 18);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCornerMinEigenValMatMatIntIntInt() {
|
|
|
|
Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
|
|
|
|
int blockSize = 3;
|
|
|
|
int ksize = 5;
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize, Core.BORDER_REFLECT);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(3, 3, CvType.CV_32FC1) {
|
|
|
|
{
|
|
|
|
put(0, 0, 0.68055558, 0.92708349, 0.5868057);
|
|
|
|
put(1, 0, 0.92708343, 0.92708343, 0.92708343);
|
|
|
|
put(2, 0, 0.58680564, 0.92708343, 0.68055564);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCornerSubPix() {
|
2011-08-03 17:43:36 +08:00
|
|
|
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(128));
|
|
|
|
Point truthPosition = new Point(img.cols() / 2, img.rows() / 2);
|
|
|
|
|
|
|
|
Rect r = new Rect(new Point(0, 0), truthPosition);
|
2018-08-26 02:50:50 +08:00
|
|
|
Imgproc.rectangle(img, r.tl(), r.br(), new Scalar(0), Imgproc.FILLED);
|
2012-04-14 05:50:59 +08:00
|
|
|
MatOfPoint2f corners = new MatOfPoint2f(new Point(truthPosition.x + 1, truthPosition.y + 1));
|
2011-08-03 17:43:36 +08:00
|
|
|
Size winSize = new Size(2, 2);
|
|
|
|
Size zeroZone = new Size(-1, -1);
|
2011-08-07 05:19:23 +08:00
|
|
|
TermCriteria criteria = new TermCriteria(TermCriteria.EPS, 0, 0.01);
|
2011-08-03 17:43:36 +08:00
|
|
|
|
|
|
|
Imgproc.cornerSubPix(img, corners, winSize, zeroZone, criteria);
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
assertPointEquals(truthPosition, corners.toList().get(0), weakEPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCvtColorMatMatInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testCvtColorMatMatIntInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testDilateMatMatMat() {
|
|
|
|
Mat kernel = new Mat();
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
Imgproc.dilate(gray255, dst, kernel);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray255, dst);
|
|
|
|
|
|
|
|
Imgproc.dilate(gray1, dst, kernel);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray1, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testDilateMatMatMatPoint() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testDilateMatMatMatPointInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testDilateMatMatMatPointIntInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testDilateMatMatMatPointIntIntScalar() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
2012-01-26 16:51:16 +08:00
|
|
|
public void testDistanceTransformWithLabels() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat dstLables = getMat(CvType.CV_32SC1, 0);
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat labels = new Mat();
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2022-12-15 02:57:08 +08:00
|
|
|
Imgproc.distanceTransformWithLabels(gray128, dst, labels, Imgproc.DIST_L2, 3);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(dstLables, labels);
|
2011-08-07 05:19:23 +08:00
|
|
|
assertMatEqual(getMat(CvType.CV_32FC1, 8192), dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testDrawContoursMatListOfMatIntScalar() {
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100));
|
2012-04-14 05:50:59 +08:00
|
|
|
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.drawContours(gray0, contours, -1, new Scalar(0));
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
assertEquals(0, Core.countNonZero(gray0));
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testDrawContoursMatListOfMatIntScalarInt() {
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100));
|
2012-04-14 05:50:59 +08:00
|
|
|
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
|
|
|
|
|
2018-08-26 02:50:50 +08:00
|
|
|
Imgproc.drawContours(gray0, contours, -1, new Scalar(0), Imgproc.FILLED);
|
2011-08-05 19:59:45 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
assertEquals(0, Core.countNonZero(gray0));
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void testDrawContoursMatListOfMatIntScalarIntIntMatIntPoint() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testEqualizeHist() {
|
|
|
|
Imgproc.equalizeHist(gray0, dst);
|
|
|
|
assertMatEqual(gray0, dst);
|
|
|
|
|
|
|
|
Imgproc.equalizeHist(gray255, dst);
|
|
|
|
assertMatEqual(gray255, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testErodeMatMatMat() {
|
|
|
|
Mat kernel = new Mat();
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
Imgproc.erode(gray128, dst, kernel);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray128, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testErodeMatMatMatPointInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(3, 3, CvType.CV_8U) {
|
|
|
|
{
|
|
|
|
put(0, 0, 15, 9, 10);
|
|
|
|
put(1, 0, 10, 8, 12);
|
|
|
|
put(2, 0, 12, 20, 25);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat kernel = new Mat();
|
|
|
|
|
|
|
|
Imgproc.erode(src, dst, kernel, anchorPoint, 10);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(truth, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testErodeMatMatMatPointIntIntScalar() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(3, 3, CvType.CV_8U) {
|
|
|
|
{
|
|
|
|
put(0, 0, 15, 9, 10);
|
|
|
|
put(1, 0, 10, 8, 12);
|
|
|
|
put(2, 0, 12, 20, 25);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat kernel = new Mat();
|
|
|
|
Scalar sc = new Scalar(3, 3);
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.erode(src, dst, kernel, anchorPoint, 10, Core.BORDER_REFLECT, sc);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(truth, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFilter2DMatMatIntMat() {
|
|
|
|
Mat src = Mat.eye(4, 4, CvType.CV_32F);
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1));
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
Imgproc.filter2D(src, dst, -1, kernel);
|
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(4, 4, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 2, 2, 1, 0);
|
|
|
|
put(1, 0, 2, 2, 1, 0);
|
|
|
|
put(2, 0, 1, 1, 2, 1);
|
|
|
|
put(3, 0, 0, 0, 1, 2);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testFilter2DMatMatIntMatPointDouble() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
public void testFilter2DMatMatIntMatPointDoubleInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));
|
2011-07-28 01:06:33 +08:00
|
|
|
Point point = new Point(0, 0);
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.filter2D(gray128, dst, -1, kernel, point, 2, Core.BORDER_CONSTANT);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray2, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFindContoursMatListOfMatMatIntInt() {
|
2011-07-28 19:28:33 +08:00
|
|
|
Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0));
|
2012-04-14 05:50:59 +08:00
|
|
|
List<MatOfPoint> contours = new ArrayList<MatOfPoint>(5);
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat hierarchy = new Mat();
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2011-07-28 19:28:33 +08:00
|
|
|
Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 19:28:33 +08:00
|
|
|
// no contours on empty image
|
|
|
|
assertEquals(contours.size(), 0);
|
|
|
|
assertEquals(contours.size(), hierarchy.total());
|
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.rectangle(img, new Point(10, 20), new Point(20, 30), new Scalar(100), 3, Imgproc.LINE_AA, 0);
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.rectangle(img, new Point(30, 35), new Point(40, 45), new Scalar(200));
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2011-07-28 19:28:33 +08:00
|
|
|
Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 19:28:33 +08:00
|
|
|
// two contours of two rectangles
|
|
|
|
assertEquals(contours.size(), 2);
|
|
|
|
assertEquals(contours.size(), hierarchy.total());
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testFindContoursMatListOfMatMatIntIntPoint() {
|
2011-08-02 21:47:40 +08:00
|
|
|
Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0));
|
|
|
|
Mat img2 = img.submat(5, 50, 3, 50);
|
2012-04-14 05:50:59 +08:00
|
|
|
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
|
|
|
|
List<MatOfPoint> contours2 = new ArrayList<MatOfPoint>();
|
2012-01-26 16:51:16 +08:00
|
|
|
Mat hierarchy = new Mat();
|
2011-07-28 19:28:33 +08:00
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.rectangle(img, new Point(10, 20), new Point(20, 30), new Scalar(100), 3, Imgproc.LINE_AA, 0);
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.rectangle(img, new Point(30, 35), new Point(40, 45), new Scalar(200));
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2012-01-26 16:51:16 +08:00
|
|
|
Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
|
|
|
|
Imgproc.findContours(img2, contours2, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE, new Point(3, 5));
|
2011-07-28 19:28:33 +08:00
|
|
|
|
|
|
|
assertEquals(contours.size(), contours2.size());
|
|
|
|
assertMatEqual(contours.get(0), contours2.get(0));
|
2012-01-26 16:51:16 +08:00
|
|
|
/*
|
|
|
|
Log.d("findContours", "hierarchy=" + hierarchy);
|
|
|
|
int iBuff[] = new int[ (int) (hierarchy.total() * hierarchy.channels()) ]; // [ Contour0 (next sibling num, previous sibling num, 1st child num, parent num), Contour1(...), ...
|
|
|
|
hierarchy.get(0, 0, iBuff);
|
|
|
|
Log.d("findContours", Arrays.toString(iBuff));
|
2012-10-17 15:12:04 +08:00
|
|
|
*/
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testFitEllipse() {
|
2012-04-14 05:50:59 +08:00
|
|
|
MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-1, 1), new Point(1, 1), new Point(1, -1), new Point(-1, -1));
|
2011-07-28 01:06:33 +08:00
|
|
|
RotatedRect rrect = new RotatedRect();
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
rrect = Imgproc.fitEllipse(points);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2020-06-02 02:01:20 +08:00
|
|
|
double FIT_ELLIPSE_CENTER_EPS = 0.01;
|
|
|
|
double FIT_ELLIPSE_SIZE_EPS = 0.4;
|
|
|
|
|
|
|
|
assertEquals(0.0, rrect.center.x, FIT_ELLIPSE_CENTER_EPS);
|
|
|
|
assertEquals(0.0, rrect.center.y, FIT_ELLIPSE_CENTER_EPS);
|
|
|
|
assertEquals(2.828, rrect.size.width, FIT_ELLIPSE_SIZE_EPS);
|
|
|
|
assertEquals(2.828, rrect.size.height, FIT_ELLIPSE_SIZE_EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testFitLine() {
|
|
|
|
Mat points = new Mat(1, 4, CvType.CV_32FC2);
|
2011-08-07 05:19:23 +08:00
|
|
|
points.put(0, 0, 0, 0, 2, 3, 3, 4, 5, 8);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Mat linePoints = new Mat(4, 1, CvType.CV_32FC1);
|
2019-10-04 04:45:43 +08:00
|
|
|
linePoints.put(0, 0, 0.53198653, 0.84675282, 2.5, 3.75);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2022-12-15 02:57:08 +08:00
|
|
|
Imgproc.fitLine(points, dst, Imgproc.DIST_L12, 0, 0.01, 0.01);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(linePoints, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testFloodFillMatMatPointScalar() {
|
2011-08-05 16:39:28 +08:00
|
|
|
Mat mask = new Mat(matSize + 2, matSize + 2, CvType.CV_8U, new Scalar(0));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat img = gray0;
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.circle(mask, new Point(matSize / 2 + 1, matSize / 2 + 1), 3, new Scalar(2));
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
int retval = Imgproc.floodFill(img, mask, new Point(matSize / 2, matSize / 2), new Scalar(1));
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertEquals(Core.countNonZero(img), retval);
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.circle(mask, new Point(matSize / 2 + 1, matSize / 2 + 1), 3, new Scalar(0));
|
2011-07-28 01:06:33 +08:00
|
|
|
assertEquals(retval + 4 * (matSize + 1), Core.countNonZero(mask));
|
2011-08-02 21:47:40 +08:00
|
|
|
assertMatEqual(mask.submat(1, matSize + 1, 1, matSize + 1), img);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2011-07-29 00:03:16 +08:00
|
|
|
public void testFloodFillMatMatPointScalar_WithoutMask() {
|
|
|
|
Mat img = gray0;
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(2));
|
2011-08-02 21:47:40 +08:00
|
|
|
|
|
|
|
// TODO: ideally we should pass null instead of "new Mat()"
|
2011-07-29 00:03:16 +08:00
|
|
|
int retval = Imgproc.floodFill(img, new Mat(), new Point(matSize / 2, matSize / 2), new Scalar(1));
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(0));
|
2011-07-29 00:03:16 +08:00
|
|
|
assertEquals(Core.countNonZero(img), retval);
|
|
|
|
}
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
public void testFloodFillMatMatPointScalarRect() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFloodFillMatMatPointScalarRectScalar() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFloodFillMatMatPointScalarRectScalarScalar() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testFloodFillMatMatPointScalarRectScalarScalarInt() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGaussianBlurMatMatSizeDouble() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.GaussianBlur(gray0, dst, size, 1);
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray0, dst);
|
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.GaussianBlur(gray2, dst, size, 1);
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray2, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGaussianBlurMatMatSizeDoubleDouble() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.GaussianBlur(gray2, dst, size, 0, 0);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray2, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGaussianBlurMatMatSizeDoubleDoubleInt() {
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.GaussianBlur(gray2, dst, size, 1, 3, Core.BORDER_REFLECT);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray2, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetAffineTransform() {
|
2012-10-17 15:12:04 +08:00
|
|
|
MatOfPoint2f src = new MatOfPoint2f(new Point(2, 3), new Point(3, 1), new Point(1, 4));
|
|
|
|
MatOfPoint2f dst = new MatOfPoint2f(new Point(3, 3), new Point(7, 4), new Point(5, 6));
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
Mat transform = Imgproc.getAffineTransform(src, dst);
|
|
|
|
|
|
|
|
Mat truth = new Mat(2, 3, CvType.CV_64FC1) {
|
|
|
|
{
|
|
|
|
put(0, 0, -8, -6, 37);
|
|
|
|
put(1, 0, -7, -4, 29);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
assertMatEqual(truth, transform, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetDerivKernelsMatMatIntIntInt() {
|
|
|
|
Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
|
|
|
|
Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
|
|
|
|
Mat expKx = new Mat(3, 1, CvType.CV_32F);
|
|
|
|
Mat expKy = new Mat(3, 1, CvType.CV_32F);
|
|
|
|
kx.put(0, 0, 1, 1);
|
|
|
|
kx.put(1, 0, 1, 1);
|
|
|
|
ky.put(0, 0, 2, 2);
|
|
|
|
ky.put(1, 0, 2, 2);
|
|
|
|
expKx.put(0, 0, 1, -2, 1);
|
|
|
|
expKy.put(0, 0, 1, -2, 1);
|
|
|
|
|
|
|
|
Imgproc.getDerivKernels(kx, ky, 2, 2, 3);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(expKx, kx, EPS);
|
|
|
|
assertMatEqual(expKy, ky, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetDerivKernelsMatMatIntIntIntBooleanInt() {
|
|
|
|
Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
|
|
|
|
Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
|
|
|
|
Mat expKx = new Mat(3, 1, CvType.CV_32F);
|
|
|
|
Mat expKy = new Mat(3, 1, CvType.CV_32F);
|
|
|
|
kx.put(0, 0, 1, 1);
|
|
|
|
kx.put(1, 0, 1, 1);
|
|
|
|
ky.put(0, 0, 2, 2);
|
|
|
|
ky.put(1, 0, 2, 2);
|
|
|
|
expKx.put(0, 0, 1, -2, 1);
|
|
|
|
expKy.put(0, 0, 1, -2, 1);
|
|
|
|
|
|
|
|
Imgproc.getDerivKernels(kx, ky, 2, 2, 3, true, CvType.CV_32F);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(expKx, kx, EPS);
|
|
|
|
assertMatEqual(expKy, ky, EPS);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetGaussianKernelIntDouble() {
|
|
|
|
dst = Imgproc.getGaussianKernel(1, 0.5);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(1, 1, CvType.CV_64FC1, new Scalar(1));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetGaussianKernelIntDoubleInt() {
|
|
|
|
dst = Imgproc.getGaussianKernel(3, 0.8, CvType.CV_32F);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(3, 1, CvType.CV_32F);
|
|
|
|
truth.put(0, 0, 0.23899426, 0.52201146, 0.23899426);
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testGetPerspectiveTransform() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
public void testGetRectSubPixMatSizePointMat() {
|
|
|
|
Size size = new Size(3, 3);
|
|
|
|
Point center = new Point(gray255.cols() / 2, gray255.rows() / 2);
|
|
|
|
|
|
|
|
Imgproc.getRectSubPix(gray255, size, center, dst);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(3, 3, CvType.CV_8U, new Scalar(255));
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(truth, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetRectSubPixMatSizePointMatInt() {
|
|
|
|
Mat src = new Mat(10, 10, CvType.CV_32F, new Scalar(2));
|
|
|
|
Size patchSize = new Size(5, 5);
|
|
|
|
Point center = new Point(src.cols() / 2, src.rows() / 2);
|
|
|
|
|
|
|
|
Imgproc.getRectSubPix(src, patchSize, center, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(5, 5, CvType.CV_32F, new Scalar(2));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetRotationMatrix2D() {
|
|
|
|
Point center = new Point(0, 0);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
dst = Imgproc.getRotationMatrix2D(center, 0, 1);
|
|
|
|
|
|
|
|
truth = new Mat(2, 3, CvType.CV_64F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 1, 0, 0);
|
|
|
|
put(1, 0, 0, 1, 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetStructuringElementIntSize() {
|
|
|
|
dst = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, size);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(3, 3, CvType.CV_8UC1, new Scalar(1));
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(truth, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetStructuringElementIntSizePoint() {
|
2011-08-02 21:47:40 +08:00
|
|
|
dst = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, size, anchorPoint);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(3, 3, CvType.CV_8UC1) {
|
|
|
|
{
|
|
|
|
put(0, 0, 0, 0, 1);
|
|
|
|
put(1, 0, 0, 0, 1);
|
|
|
|
put(2, 0, 1, 1, 1);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(truth, dst);
|
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testGoodFeaturesToTrackMatListOfPointIntDoubleDouble() {
|
2011-08-02 21:47:40 +08:00
|
|
|
Mat src = gray0;
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
|
2012-04-14 05:50:59 +08:00
|
|
|
MatOfPoint lp = new MatOfPoint();
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-07-29 23:18:04 +08:00
|
|
|
Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3);
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
assertEquals(4, lp.total());
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
2011-08-05 16:39:28 +08:00
|
|
|
public void testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDouble() {
|
2011-08-02 21:47:40 +08:00
|
|
|
Mat src = gray0;
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
|
2012-04-14 05:50:59 +08:00
|
|
|
MatOfPoint lp = new MatOfPoint();
|
2011-07-29 23:18:04 +08:00
|
|
|
|
2017-09-22 22:04:43 +08:00
|
|
|
Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3, gray1, 4, 3, true, 0);
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
assertEquals(4, lp.total());
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGrabCutMatMatRectMatMatInt() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGrabCutMatMatRectMatMatIntInt() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testHoughCirclesMatMatIntDoubleDouble() {
|
2011-08-02 21:47:40 +08:00
|
|
|
int sz = 512;
|
|
|
|
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));
|
|
|
|
Mat circles = new Mat();
|
|
|
|
|
2022-12-15 02:57:08 +08:00
|
|
|
Imgproc.HoughCircles(img, circles, Imgproc.HOUGH_GRADIENT, 2, img.rows() / 4);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-08-02 21:47:40 +08:00
|
|
|
assertEquals(0, circles.cols());
|
2011-08-07 05:19:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testHoughCirclesMatMatIntDoubleDouble1() {
|
|
|
|
int sz = 512;
|
|
|
|
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));
|
|
|
|
Mat circles = new Mat();
|
2011-08-02 21:47:40 +08:00
|
|
|
|
|
|
|
Point center = new Point(img.cols() / 2, img.rows() / 2);
|
|
|
|
int radius = Math.min(img.cols() / 4, img.rows() / 4);
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.circle(img, center, radius, colorBlack, 3);
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2022-12-15 02:57:08 +08:00
|
|
|
Imgproc.HoughCircles(img, circles, Imgproc.HOUGH_GRADIENT, 2, img.rows() / 4);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-08-02 21:47:40 +08:00
|
|
|
assertEquals(1, circles.cols());
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testHoughCirclesMatMatIntDoubleDoubleDoubleDoubleIntInt() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testHoughLinesMatMatDoubleDoubleInt() {
|
2011-08-05 19:59:45 +08:00
|
|
|
int sz = 512;
|
2011-11-16 16:36:57 +08:00
|
|
|
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));
|
2011-08-05 19:59:45 +08:00
|
|
|
Point point1 = new Point(50, 50);
|
|
|
|
Point point2 = new Point(img.cols() / 2, img.rows() / 2);
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.line(img, point1, point2, colorWhite, 1);
|
2011-11-16 16:36:57 +08:00
|
|
|
Mat lines = new Mat();
|
2011-08-05 19:59:45 +08:00
|
|
|
|
2011-11-16 16:36:57 +08:00
|
|
|
Imgproc.HoughLines(img, lines, 1, 3.1415926/180, 100);
|
2011-08-05 19:59:45 +08:00
|
|
|
|
2011-11-16 16:36:57 +08:00
|
|
|
assertEquals(1, lines.cols());
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2011-11-16 16:36:57 +08:00
|
|
|
/*
|
|
|
|
Log.d("HoughLines", "lines=" + lines);
|
|
|
|
int num = (int)lines.total();
|
|
|
|
int buff[] = new int[num*4]; //[ (x1, y1, x2, y2), (...), ...]
|
|
|
|
lines.get(0, 0, buff);
|
|
|
|
Log.d("HoughLines", "lines=" + Arrays.toString(buff));
|
|
|
|
*/
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testHoughLinesMatMatDoubleDoubleIntDouble() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testHoughLinesMatMatDoubleDoubleIntDoubleDouble() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testHoughLinesPMatMatDoubleDoubleInt() {
|
2011-11-16 16:36:57 +08:00
|
|
|
int sz = 512;
|
|
|
|
Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));
|
|
|
|
Point point1 = new Point(0, 0);
|
|
|
|
Point point2 = new Point(sz, sz);
|
|
|
|
Point point3 = new Point(sz, 0);
|
|
|
|
Point point4 = new Point(2*sz/3, sz/3);
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.line(img, point1, point2, Scalar.all(255), 1);
|
|
|
|
Imgproc.line(img, point3, point4, Scalar.all(255), 1);
|
2011-11-16 16:36:57 +08:00
|
|
|
Mat lines = new Mat();
|
|
|
|
|
|
|
|
Imgproc.HoughLinesP(img, lines, 1, 3.1415926/180, 100);
|
|
|
|
|
2016-10-19 02:22:18 +08:00
|
|
|
assertEquals(2, lines.rows());
|
2012-10-17 15:12:04 +08:00
|
|
|
|
2011-11-16 16:36:57 +08:00
|
|
|
/*
|
|
|
|
Log.d("HoughLinesP", "lines=" + lines);
|
|
|
|
int num = (int)lines.cols();
|
|
|
|
int buff[] = new int[num*4]; // CV_32SC4 as [ (x1, y1, x2, y2), (...), ...]
|
|
|
|
lines.get(0, 0, buff);
|
|
|
|
Log.d("HoughLinesP", "lines=" + Arrays.toString(buff));
|
|
|
|
*/
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testHoughLinesPMatMatDoubleDoubleIntDouble() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testHoughLinesPMatMatDoubleDoubleIntDoubleDouble() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testHuMoments() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testIntegral2MatMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat expSum = new Mat(4, 4, CvType.CV_64F);
|
|
|
|
Mat expSqsum = new Mat(4, 4, CvType.CV_64F);
|
|
|
|
Mat sum = new Mat();
|
|
|
|
Mat sqsum = new Mat();
|
|
|
|
|
|
|
|
expSum.put(0, 0, 0, 0, 0, 0);
|
|
|
|
expSum.put(1, 0, 0, 3, 6, 9);
|
|
|
|
expSum.put(2, 0, 0, 6, 12, 18);
|
|
|
|
expSum.put(3, 0, 0, 9, 18, 27);
|
|
|
|
|
|
|
|
expSqsum.put(0, 0, 0, 0, 0, 0);
|
|
|
|
expSqsum.put(1, 0, 0, 9, 18, 27);
|
|
|
|
expSqsum.put(2, 0, 0, 18, 36, 54);
|
|
|
|
expSqsum.put(3, 0, 0, 27, 54, 81);
|
|
|
|
|
|
|
|
Imgproc.integral2(src, sum, sqsum);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(expSum, sum, EPS);
|
|
|
|
assertMatEqual(expSqsum, sqsum, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testIntegral2MatMatMatInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat expSum = new Mat(4, 4, CvType.CV_64F);
|
|
|
|
Mat expSqsum = new Mat(4, 4, CvType.CV_64F);
|
|
|
|
Mat sum = new Mat();
|
|
|
|
Mat sqsum = new Mat();
|
|
|
|
|
|
|
|
expSum.put(0, 0, 0, 0, 0, 0);
|
|
|
|
expSum.put(1, 0, 0, 3, 6, 9);
|
|
|
|
expSum.put(2, 0, 0, 6, 12, 18);
|
|
|
|
expSum.put(3, 0, 0, 9, 18, 27);
|
|
|
|
|
|
|
|
expSqsum.put(0, 0, 0, 0, 0, 0);
|
|
|
|
expSqsum.put(1, 0, 0, 9, 18, 27);
|
|
|
|
expSqsum.put(2, 0, 0, 18, 36, 54);
|
|
|
|
expSqsum.put(3, 0, 0, 27, 54, 81);
|
|
|
|
|
2013-12-05 23:43:50 +08:00
|
|
|
Imgproc.integral2(src, sum, sqsum, CvType.CV_64F, CvType.CV_64F);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(expSum, sum, EPS);
|
|
|
|
assertMatEqual(expSqsum, sqsum, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testIntegral3MatMatMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
|
|
|
|
Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
|
|
|
|
Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
|
|
|
|
Mat sum = new Mat();
|
|
|
|
Mat sqsum = new Mat();
|
|
|
|
Mat tilted = new Mat();
|
|
|
|
|
|
|
|
expSum.put(0, 0, 0, 0);
|
|
|
|
expSum.put(1, 0, 0, 1);
|
|
|
|
|
|
|
|
expSqsum.put(0, 0, 0, 0);
|
|
|
|
expSqsum.put(1, 0, 0, 1);
|
|
|
|
|
|
|
|
expTilted.put(0, 0, 0, 0);
|
|
|
|
expTilted.put(1, 0, 0, 1);
|
|
|
|
|
|
|
|
Imgproc.integral3(src, sum, sqsum, tilted);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(expSum, sum, EPS);
|
|
|
|
assertMatEqual(expSqsum, sqsum, EPS);
|
|
|
|
assertMatEqual(expTilted, tilted, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testIntegral3MatMatMatMatInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
|
|
|
|
Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
|
|
|
|
Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
|
|
|
|
Mat sum = new Mat();
|
|
|
|
Mat sqsum = new Mat();
|
|
|
|
Mat tilted = new Mat();
|
|
|
|
|
|
|
|
expSum.put(0, 0, 0, 0);
|
|
|
|
expSum.put(1, 0, 0, 1);
|
|
|
|
|
|
|
|
expSqsum.put(0, 0, 0, 0);
|
|
|
|
expSqsum.put(1, 0, 0, 1);
|
|
|
|
|
|
|
|
expTilted.put(0, 0, 0, 0);
|
|
|
|
expTilted.put(1, 0, 0, 1);
|
|
|
|
|
2013-12-05 23:43:50 +08:00
|
|
|
Imgproc.integral3(src, sum, sqsum, tilted, CvType.CV_64F, CvType.CV_64F);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(expSum, sum, EPS);
|
|
|
|
assertMatEqual(expSqsum, sqsum, EPS);
|
|
|
|
assertMatEqual(expTilted, tilted, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testIntegralMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Imgproc.integral(src, dst);
|
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(3, 3, CvType.CV_64F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 0, 0, 0);
|
|
|
|
put(1, 0, 0, 2, 4);
|
|
|
|
put(2, 0, 0, 4, 8);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testIntegralMatMatInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Imgproc.integral(src, dst, CvType.CV_64F);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(3, 3, CvType.CV_64F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 0, 0, 0);
|
|
|
|
put(1, 0, 0, 2, 4);
|
|
|
|
put(2, 0, 0, 4, 8);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testInvertAffineTransform() {
|
|
|
|
Mat src = new Mat(2, 3, CvType.CV_64F, new Scalar(1));
|
|
|
|
|
|
|
|
Imgproc.invertAffineTransform(src, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(2, 3, CvType.CV_64F, new Scalar(0));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testIsContourConvex() {
|
2012-04-30 22:33:52 +08:00
|
|
|
MatOfPoint contour1 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4));
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertFalse(Imgproc.isContourConvex(contour1));
|
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
MatOfPoint contour2 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6));
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
assertTrue(Imgproc.isContourConvex(contour2));
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testLaplacianMatMatInt() {
|
|
|
|
Imgproc.Laplacian(gray0, dst, CvType.CV_8U);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray0, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testLaplacianMatMatIntIntDoubleDouble() {
|
|
|
|
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
|
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, -7.9990001, 8.0009995);
|
|
|
|
put(1, 0, 8.0009995, -7.9990001);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testLaplacianMatMatIntIntDoubleDoubleInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS, Core.BORDER_REFLECT);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(3, 3, CvType.CV_32F, new Scalar(0.00099945068));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testMatchShapes() {
|
|
|
|
Mat contour1 = new Mat(1, 4, CvType.CV_32FC2);
|
|
|
|
Mat contour2 = new Mat(1, 4, CvType.CV_32FC2);
|
2011-08-07 05:19:23 +08:00
|
|
|
contour1.put(0, 0, 1, 1, 5, 1, 4, 3, 6, 2);
|
|
|
|
contour2.put(0, 0, 1, 1, 6, 1, 4, 1, 2, 5);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2022-12-15 02:57:08 +08:00
|
|
|
double distance = Imgproc.matchShapes(contour1, contour2, Imgproc.CONTOURS_MATCH_I1, 1);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
assertEquals(2.81109697365334, distance, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testMatchTemplate() {
|
|
|
|
Mat image = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
|
|
|
|
Mat templ = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
|
|
|
|
image.put(0, 0, 1, 2, 3, 4);
|
|
|
|
templ.put(0, 0, 5, 6, 7, 8);
|
|
|
|
|
|
|
|
Imgproc.matchTemplate(image, templ, dst, Imgproc.TM_CCORR);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(1, 1, CvType.CV_32F, new Scalar(70));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Imgproc.matchTemplate(gray255, gray0, dst, Imgproc.TM_CCORR);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(1, 1, CvType.CV_32F, new Scalar(0));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testMedianBlur() {
|
|
|
|
Imgproc.medianBlur(gray255, dst, 5);
|
|
|
|
assertMatEqual(gray255, dst);
|
|
|
|
|
|
|
|
Imgproc.medianBlur(gray2, dst, 3);
|
|
|
|
assertMatEqual(gray2, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testMinAreaRect() {
|
2012-04-14 05:50:59 +08:00
|
|
|
MatOfPoint2f points = new MatOfPoint2f(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2));
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
RotatedRect rrect = Imgproc.minAreaRect(points);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2020-12-10 16:07:50 +08:00
|
|
|
assertEquals(new Size(5, 2), rrect.size);
|
|
|
|
assertEquals(0., rrect.angle);
|
2011-07-30 20:01:00 +08:00
|
|
|
assertEquals(new Point(3.5, 2), rrect.center);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testMinEnclosingCircle() {
|
2016-10-19 02:22:18 +08:00
|
|
|
MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-100, 0), new Point(0, -100), new Point(100, 0), new Point(0, 100));
|
2011-07-30 20:01:00 +08:00
|
|
|
Point actualCenter = new Point();
|
2011-08-07 05:19:23 +08:00
|
|
|
float[] radius = new float[1];
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.minEnclosingCircle(points, actualCenter, radius);
|
2011-08-02 21:47:40 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
assertEquals(new Point(0, 0), actualCenter);
|
2016-10-19 02:22:18 +08:00
|
|
|
assertEquals(100.0f, radius[0], 1.0);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testMomentsMat() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testMomentsMatBoolean() {
|
|
|
|
fail("Not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testMorphologyExMatMatIntMat() {
|
|
|
|
Imgproc.morphologyEx(gray255, dst, Imgproc.MORPH_GRADIENT, gray0);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray0, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testMorphologyExMatMatIntMatPointInt() {
|
|
|
|
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);
|
|
|
|
|
|
|
|
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(0));
|
|
|
|
Point point = new Point(0, 0);
|
|
|
|
|
|
|
|
Imgproc.morphologyEx(src, dst, Imgproc.MORPH_CLOSE, kernel, point, 10);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
truth = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);
|
|
|
|
assertMatEqual(truth, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void testMorphologyExMatMatIntMatPointIntIntScalar() {
|
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
|
|
|
|
src.put(0, 0, 2, 1);
|
|
|
|
src.put(1, 0, 2, 1);
|
|
|
|
|
|
|
|
Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(1));
|
|
|
|
Point point = new Point(1, 1);
|
|
|
|
Scalar sc = new Scalar(3, 3);
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.morphologyEx(src, dst, Imgproc.MORPH_TOPHAT, kernel, point, 10, Core.BORDER_REFLECT, sc);
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_8U) {
|
|
|
|
{
|
|
|
|
put(0, 0, 1, 0);
|
|
|
|
put(1, 0, 1, 0);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(truth, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPointPolygonTest() {
|
2012-10-17 15:12:04 +08:00
|
|
|
MatOfPoint2f contour = new MatOfPoint2f(new Point(0, 0), new Point(1, 3), new Point(3, 4), new Point(4, 3), new Point(2, 1));
|
2011-08-07 05:19:23 +08:00
|
|
|
double sign1 = Imgproc.pointPolygonTest(contour, new Point(2, 2), false);
|
2011-08-08 15:08:58 +08:00
|
|
|
assertEquals(1.0, sign1);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
double sign2 = Imgproc.pointPolygonTest(contour, new Point(4, 4), true);
|
|
|
|
assertEquals(-Math.sqrt(0.5), sign2);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPreCornerDetectMatMatInt() {
|
|
|
|
Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));
|
|
|
|
int ksize = 3;
|
|
|
|
|
|
|
|
Imgproc.preCornerDetect(src, dst, ksize);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPreCornerDetectMatMatIntInt() {
|
|
|
|
Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));
|
|
|
|
int ksize = 3;
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.preCornerDetect(src, dst, ksize, Core.BORDER_REFLECT);
|
2011-08-05 16:39:28 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPyrDownMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(4, 4, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 2, 1, 4, 2);
|
|
|
|
put(1, 0, 3, 2, 6, 8);
|
|
|
|
put(2, 0, 4, 6, 8, 10);
|
|
|
|
put(3, 0, 12, 32, 6, 18);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Imgproc.pyrDown(src, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 2.78125, 4.609375);
|
|
|
|
put(1, 0, 8.546875, 8.8515625);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPyrDownMatMatSize() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(4, 4, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 2, 1, 4, 2);
|
|
|
|
put(1, 0, 3, 2, 6, 8);
|
|
|
|
put(2, 0, 4, 6, 8, 10);
|
|
|
|
put(3, 0, 12, 32, 6, 18);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 01:06:33 +08:00
|
|
|
Size dstSize = new Size(2, 2);
|
|
|
|
|
|
|
|
Imgproc.pyrDown(src, dst, dstSize);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 2.78125, 4.609375);
|
|
|
|
put(1, 0, 8.546875, 8.8515625);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPyrMeanShiftFilteringMatMatDoubleDouble() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(matSize, matSize, CvType.CV_8UC3, new Scalar(0));
|
2011-07-30 20:01:00 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.pyrMeanShiftFiltering(src, dst, 10, 50);
|
|
|
|
|
|
|
|
assertMatEqual(src, dst);
|
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPyrMeanShiftFilteringMatMatDoubleDoubleInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPyrMeanShiftFilteringMatMatDoubleDoubleIntTermCriteria() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPyrUpMatMat() {
|
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
|
|
|
|
src.put(0, 0, 2, 1);
|
|
|
|
src.put(1, 0, 3, 2);
|
|
|
|
|
|
|
|
Imgproc.pyrUp(src, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(4, 4, CvType.CV_32F) {
|
|
|
|
{
|
2011-12-21 20:12:58 +08:00
|
|
|
put(0, 0, 2, 1.75, 1.375, 1.25);
|
|
|
|
put(1, 0, 2.25, 2, 1.625, 1.5);
|
|
|
|
put(2, 0, 2.625, 2.375, 2, 1.875);
|
|
|
|
put(3, 0, 2.75, 2.5, 2.125, 2);
|
2011-08-07 05:19:23 +08:00
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testPyrUpMatMatSize() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testRemapMatMatMatMatInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
|
|
|
// this test does something weird
|
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat map1 = new Mat(1, 3, CvType.CV_32FC1);
|
|
|
|
Mat map2 = new Mat(1, 3, CvType.CV_32FC1);
|
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
map1.put(0, 0, 3, 6, 5);
|
|
|
|
map2.put(0, 0, 4, 8, 12);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(1, 3, CvType.CV_32F, new Scalar(0));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testRemapMatMatMatMatIntIntScalar() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
|
|
|
// this test does something weird
|
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat map1 = new Mat(1, 3, CvType.CV_32FC1);
|
|
|
|
Mat map2 = new Mat(1, 3, CvType.CV_32FC1);
|
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Scalar sc = new Scalar(0);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
map1.put(0, 0, 3, 6, 5, 0);
|
|
|
|
map2.put(0, 0, 4, 8, 12);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
truth = new Mat(1, 3, CvType.CV_32F, new Scalar(2));
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR, Core.BORDER_REFLECT, sc);
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testResizeMatMatSize() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8UC1, new Scalar(1));
|
2011-07-28 01:06:33 +08:00
|
|
|
Size dsize = new Size(1, 1);
|
|
|
|
|
2017-12-13 20:00:38 +08:00
|
|
|
Imgproc.resize(src, dst, dsize, 0, 0, Imgproc.INTER_LINEAR_EXACT);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(1, 1, CvType.CV_8UC1, new Scalar(1));
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(truth, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testResizeMatMatSizeDoubleDoubleInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.resize(gray255, dst, new Size(2, 2), 0, 0, Imgproc.INTER_AREA);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(2, 2, CvType.CV_8UC1, new Scalar(255));
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(truth, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testScharrMatMatIntIntInt() {
|
|
|
|
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
|
|
|
|
|
|
|
|
Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testScharrMatMatIntIntIntDoubleDouble() {
|
|
|
|
Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
|
|
|
|
|
|
|
|
Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0.001);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0.001));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testScharrMatMatIntIntIntDoubleDoubleInt() {
|
|
|
|
Mat src = Mat.eye(3, 3, CvType.CV_32F);
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0, Core.BORDER_REFLECT);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(3, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, -15, -19.5, -4.5);
|
|
|
|
put(1, 0, 10.5, 0, -10.5);
|
|
|
|
put(2, 0, 4.5, 19.5, 15);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testSepFilter2DMatMatIntMatMat() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
|
|
|
|
Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
|
2011-08-07 05:19:23 +08:00
|
|
|
kernelX.put(0, 0, 4, 3, 7);
|
|
|
|
kernelY.put(0, 0, 9, 4, 2);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(420));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testSepFilter2DMatMatIntMatMatPointDouble() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(2));
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
|
2011-08-07 05:19:23 +08:00
|
|
|
kernelX.put(0, 0, 2, 2, 2);
|
2011-07-28 01:06:33 +08:00
|
|
|
Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
|
2011-08-07 05:19:23 +08:00
|
|
|
kernelY.put(0, 0, 1, 1, 1);
|
|
|
|
|
|
|
|
Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(36 + weakEPS));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testSepFilter2DMatMatIntMatMatPointDoubleInt() {
|
|
|
|
Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
|
2011-08-07 05:19:23 +08:00
|
|
|
kernelX.put(0, 0, 2, 2, 2);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
|
|
|
Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
|
2011-08-07 05:19:23 +08:00
|
|
|
kernelY.put(0, 0, 1, 1, 1);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.sepFilter2D(gray0, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS, Core.BORDER_REFLECT);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(10, 10, CvType.CV_32F, new Scalar(weakEPS));
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testSobelMatMatIntIntInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0);
|
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray0, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testSobelMatMatIntIntIntIntDoubleDouble() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0, 3, 2, 0.001);
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray0, dst);
|
2011-08-07 05:19:23 +08:00
|
|
|
// TODO_: write better test
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testSobelMatMatIntIntIntIntDoubleDoubleInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(3, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 2, 0, 1);
|
|
|
|
put(1, 0, 6, 4, 3);
|
|
|
|
put(2, 0, 1, 0, 2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-10 19:54:14 +08:00
|
|
|
Imgproc.Sobel(src, dst, CvType.CV_32F, 1, 0, 3, 2, 0, Core.BORDER_REPLICATE);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(3, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, -16, -12, 4);
|
|
|
|
put(1, 0, -14, -12, 2);
|
|
|
|
put(2, 0, -10, 0, 10);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testThreshold() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.threshold(makeMask(gray0.clone(), 10), dst, 5, 255, Imgproc.THRESH_TRUNC);
|
|
|
|
assertMatEqual(makeMask(gray0.clone(), 5), dst);
|
2011-07-28 01:06:33 +08:00
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 1, 255, Imgproc.THRESH_BINARY);
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(gray255, dst);
|
|
|
|
|
2011-08-07 05:19:23 +08:00
|
|
|
Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 3, 255, Imgproc.THRESH_BINARY_INV);
|
|
|
|
assertMatEqual(makeMask(gray255.clone(), 0), dst);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWarpAffineMatMatMatSize() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(3, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 2, 0, 1);
|
|
|
|
put(1, 0, 6, 4, 3);
|
|
|
|
put(2, 0, 1, 0, 2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Mat M = new Mat(2, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 1, 0, 1);
|
|
|
|
put(1, 0, 0, 1, 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Imgproc.warpAffine(src, dst, M, new Size(3, 3));
|
|
|
|
|
|
|
|
truth = new Mat(3, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 0, 0, 0);
|
|
|
|
put(1, 0, 0, 2, 0);
|
|
|
|
put(2, 0, 0, 6, 4);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
2011-06-30 20:07:31 +08:00
|
|
|
|
2011-07-28 01:06:33 +08:00
|
|
|
public void testWarpAffineMatMatMatSizeInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(3, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 2, 4, 1);
|
|
|
|
put(1, 0, 6, 4, 3);
|
|
|
|
put(2, 0, 0, 2, 2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Mat M = new Mat(2, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 1, 0, 0);
|
|
|
|
put(1, 0, 0, 0, 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Imgproc.warpAffine(src, dst, M, new Size(2, 2), Imgproc.WARP_INVERSE_MAP);
|
|
|
|
|
|
|
|
truth = new Mat(2, 2, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 6, 4);
|
|
|
|
put(1, 0, 6, 4);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWarpAffineMatMatMatSizeIntInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWarpAffineMatMatMatSizeIntIntScalar() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWarpPerspectiveMatMatMatSize() {
|
2011-08-07 05:19:23 +08:00
|
|
|
Mat src = new Mat(3, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 2, 4, 1);
|
|
|
|
put(1, 0, 0, 4, 5);
|
|
|
|
put(2, 0, 1, 2, 2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Mat M = new Mat(3, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 1, 0, 1);
|
|
|
|
put(1, 0, 0, 1, 1);
|
|
|
|
put(2, 0, 0, 0, 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Imgproc.warpPerspective(src, dst, M, new Size(3, 3));
|
|
|
|
|
|
|
|
truth = new Mat(3, 3, CvType.CV_32F) {
|
|
|
|
{
|
|
|
|
put(0, 0, 0, 0, 0);
|
|
|
|
put(1, 0, 0, 2, 4);
|
|
|
|
put(2, 0, 0, 0, 4);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 20:13:11 +08:00
|
|
|
assertMatEqual(truth, dst, EPS);
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWarpPerspectiveMatMatMatSizeInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWarpPerspectiveMatMatMatSizeIntInt() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWarpPerspectiveMatMatMatSizeIntIntScalar() {
|
2011-08-07 05:19:23 +08:00
|
|
|
fail("Not yet implemented");
|
2011-07-28 01:06:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testWatershed() {
|
|
|
|
Mat image = Mat.eye(4, 4, CvType.CV_8UC(3));
|
|
|
|
Mat markers = new Mat(4, 4, CvType.CV_32SC1, new Scalar(0));
|
|
|
|
|
|
|
|
Imgproc.watershed(image, markers);
|
2011-08-07 05:19:23 +08:00
|
|
|
|
|
|
|
truth = new Mat(4, 4, CvType.CV_32SC1) {
|
|
|
|
{
|
|
|
|
put(0, 0, -1, -1, -1, -1);
|
|
|
|
put(1, 0, -1, 0, 0, -1);
|
|
|
|
put(2, 0, -1, 0, 0, -1);
|
|
|
|
put(3, 0, -1, -1, -1, -1);
|
|
|
|
}
|
|
|
|
};
|
2011-07-28 01:06:33 +08:00
|
|
|
assertMatEqual(truth, markers);
|
|
|
|
}
|
2014-08-14 18:53:02 +08:00
|
|
|
|
2014-08-14 17:48:52 +08:00
|
|
|
public void testGetTextSize() {
|
|
|
|
String text = "Android all the way";
|
|
|
|
double fontScale = 2;
|
|
|
|
int thickness = 3;
|
|
|
|
int baseLine[] = new int[1];
|
2020-11-12 03:17:05 +08:00
|
|
|
double EPS=5.0;
|
2011-06-30 20:07:31 +08:00
|
|
|
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.getTextSize(text, Imgproc.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, null);
|
|
|
|
Size res = Imgproc.getTextSize(text, Imgproc.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, baseLine);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
2020-11-12 03:17:05 +08:00
|
|
|
assertEquals(494.0, res.width, EPS);
|
|
|
|
assertEquals(51.0, res.height, EPS);
|
|
|
|
assertEquals(10, baseLine[0], 2.0);
|
2014-08-14 17:48:52 +08:00
|
|
|
}
|
2014-08-14 18:53:02 +08:00
|
|
|
|
2014-08-14 17:48:52 +08:00
|
|
|
public void testCircleMatPointIntScalar() {
|
|
|
|
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
|
|
|
|
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
|
|
|
|
Scalar color = new Scalar(128);
|
|
|
|
|
|
|
|
Imgproc.circle(gray0, center, radius, color);
|
|
|
|
|
|
|
|
assertTrue(0 != Core.countNonZero(gray0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testCircleMatPointIntScalarInt() {
|
|
|
|
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
|
|
|
|
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
|
|
|
|
Scalar color = new Scalar(128);
|
|
|
|
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.circle(gray0, center, radius, color, Imgproc.FILLED);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertTrue(0 != Core.countNonZero(gray0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testCircleMatPointIntScalarIntIntInt() {
|
|
|
|
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
|
|
|
|
Point center2 = new Point(gray0.cols(), gray0.rows());
|
|
|
|
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
|
|
|
|
Scalar color128 = new Scalar(128);
|
|
|
|
Scalar color0 = new Scalar(0);
|
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.circle(gray0, center2, radius * 2, color128, 2, Imgproc.LINE_4, 1/*
|
2014-08-14 17:48:52 +08:00
|
|
|
* Number
|
|
|
|
* of
|
|
|
|
* fractional
|
|
|
|
* bits
|
|
|
|
*/);
|
|
|
|
assertFalse(0 == Core.countNonZero(gray0));
|
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.circle(gray0, center, radius, color0, 2, Imgproc.LINE_4, 0);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertTrue(0 == Core.countNonZero(gray0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testClipLine() {
|
|
|
|
Rect r = new Rect(10, 10, 10, 10);
|
|
|
|
Point pt1 = new Point(5.0, 15.0);
|
|
|
|
Point pt2 = new Point(25.0, 15.0);
|
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
assertTrue(Imgproc.clipLine(r, pt1, pt2));
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
Point pt1Clipped = new Point(10.0, 15.0);
|
|
|
|
Point pt2Clipped = new Point(19.0, 15.0);
|
|
|
|
assertEquals(pt1Clipped, pt1);
|
|
|
|
assertEquals(pt2Clipped, pt2);
|
|
|
|
|
|
|
|
pt1 = new Point(5.0, 5.0);
|
|
|
|
pt2 = new Point(25.0, 5.0);
|
|
|
|
pt1Clipped = new Point(5.0, 5.0);
|
|
|
|
pt2Clipped = new Point(25.0, 5.0);
|
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
assertFalse(Imgproc.clipLine(r, pt1, pt2));
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertEquals(pt1Clipped, pt1);
|
|
|
|
assertEquals(pt2Clipped, pt2);
|
|
|
|
}
|
2014-08-14 18:53:02 +08:00
|
|
|
|
2014-08-14 17:48:52 +08:00
|
|
|
public void testEllipse2Poly() {
|
|
|
|
Point center = new Point(4, 4);
|
|
|
|
Size axes = new Size(2, 2);
|
|
|
|
int angle = 30;
|
|
|
|
int arcStart = 30;
|
|
|
|
int arcEnd = 60;
|
|
|
|
int delta = 2;
|
|
|
|
MatOfPoint pts = new MatOfPoint();
|
|
|
|
|
|
|
|
Imgproc.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts);
|
|
|
|
|
|
|
|
Point truth[] = {
|
|
|
|
new Point(5, 6),
|
|
|
|
new Point(4, 6)
|
|
|
|
};
|
|
|
|
assertArrayPointsEquals(truth, pts.toArray(), EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testEllipseMatPointSizeDoubleDoubleDoubleScalar() {
|
|
|
|
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
|
|
|
|
Size axes = new Size(2, 2);
|
|
|
|
double angle = 30, startAngle = 60, endAngle = 90;
|
|
|
|
|
|
|
|
Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite);
|
|
|
|
|
|
|
|
assertTrue(0 != Core.countNonZero(gray0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testEllipseMatPointSizeDoubleDoubleDoubleScalarInt() {
|
|
|
|
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
|
|
|
|
Size axes = new Size(2, 2);
|
|
|
|
double angle = 30, startAngle = 60, endAngle = 90;
|
|
|
|
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Imgproc.FILLED);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertTrue(0 != Core.countNonZero(gray0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testEllipseMatPointSizeDoubleDoubleDoubleScalarIntIntInt() {
|
|
|
|
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
|
|
|
|
Size axes = new Size(2, 2);
|
|
|
|
Point center2 = new Point(gray0.cols(), gray0.rows());
|
|
|
|
Size axes2 = new Size(4, 4);
|
|
|
|
double angle = 30, startAngle = 0, endAngle = 30;
|
|
|
|
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Imgproc.FILLED, Imgproc.LINE_4, 0);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertTrue(0 != Core.countNonZero(gray0));
|
|
|
|
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.ellipse(gray0, center2, axes2, angle, startAngle, endAngle, colorBlack, Imgproc.FILLED, Imgproc.LINE_4, 1);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertEquals(0, Core.countNonZero(gray0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testEllipseMatRotatedRectScalar() {
|
|
|
|
int matSize = 10;
|
|
|
|
Mat gray0 = Mat.zeros(matSize, matSize, CvType.CV_8U);
|
|
|
|
Point center = new Point(matSize / 2, matSize / 2);
|
|
|
|
Size size = new Size(matSize / 4, matSize / 2);
|
|
|
|
RotatedRect box = new RotatedRect(center, size, 45);
|
|
|
|
|
|
|
|
Imgproc.ellipse(gray0, box, new Scalar(1));
|
|
|
|
|
|
|
|
final byte[] truth = new byte[] {
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
|
|
|
|
0, 0, 0, 0, 1, 1, 0, 1, 0, 0,
|
|
|
|
0, 0, 0, 0, 1, 0, 1, 0, 0, 0,
|
|
|
|
0, 0, 0, 1, 0, 1, 1, 0, 0, 0,
|
|
|
|
0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
assertMatEqual(new Mat(matSize, matSize, CvType.CV_8U) {
|
|
|
|
{
|
|
|
|
put(0, 0, truth);
|
|
|
|
}
|
|
|
|
}, gray0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testEllipseMatRotatedRectScalarInt() {
|
|
|
|
Point center = new Point(matSize / 2, matSize / 2);
|
|
|
|
Size size = new Size(matSize / 4, matSize / 2);
|
|
|
|
RotatedRect box = new RotatedRect(center, size, 45);
|
|
|
|
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.ellipse(gray0, box, new Scalar(1), Imgproc.FILLED);
|
2014-08-14 17:48:52 +08:00
|
|
|
Imgproc.ellipse(gray0, box, new Scalar(0));
|
|
|
|
|
|
|
|
assertTrue(0 < Core.countNonZero(gray0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testEllipseMatRotatedRectScalarIntInt() {
|
|
|
|
Point center = new Point(matSize / 2, matSize / 2);
|
|
|
|
Size size = new Size(2, matSize * 2 / 3);
|
|
|
|
RotatedRect box = new RotatedRect(center, size, 20);
|
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.ellipse(gray0, box, new Scalar(9), 1, Imgproc.LINE_AA);
|
|
|
|
Imgproc.ellipse(gray0, box, new Scalar(0), 1, Imgproc.LINE_4);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertTrue(0 < Core.countNonZero(gray0));
|
|
|
|
}
|
2014-08-14 18:53:02 +08:00
|
|
|
|
2014-08-14 17:48:52 +08:00
|
|
|
public void testPolylinesMatListOfListOfPointBooleanScalar() {
|
|
|
|
Mat img = gray0;
|
|
|
|
List<MatOfPoint> polyline = new ArrayList<MatOfPoint>();
|
|
|
|
polyline.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
|
|
|
|
|
|
|
|
Imgproc.polylines(img, polyline, true, new Scalar(100));
|
|
|
|
|
|
|
|
assertEquals(22, Core.countNonZero(img));
|
|
|
|
|
|
|
|
Imgproc.polylines(img, polyline, false, new Scalar(0));
|
|
|
|
|
|
|
|
assertEquals(4, Core.countNonZero(img));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testPolylinesMatListOfListOfPointBooleanScalarInt() {
|
|
|
|
Mat img = gray0;
|
|
|
|
List<MatOfPoint> polyline = new ArrayList<MatOfPoint>();
|
|
|
|
polyline.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
|
|
|
|
|
|
|
|
Imgproc.polylines(img, polyline, true, new Scalar(100), 2);
|
|
|
|
|
|
|
|
assertEquals(62, Core.countNonZero(img));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testPolylinesMatListOfListOfPointBooleanScalarIntIntInt() {
|
|
|
|
Mat img = gray0;
|
|
|
|
List<MatOfPoint> polyline1 = new ArrayList<MatOfPoint>();
|
|
|
|
polyline1.add(new MatOfPoint(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
|
|
|
|
List<MatOfPoint> polyline2 = new ArrayList<MatOfPoint>();
|
|
|
|
polyline2.add(new MatOfPoint(new Point(2, 2), new Point(14, 2), new Point(14, 12), new Point(2, 12)));
|
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.polylines(img, polyline1, true, new Scalar(100), 2, Imgproc.LINE_8, 0);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertTrue(Core.countNonZero(img) > 0);
|
|
|
|
|
2014-09-08 21:35:55 +08:00
|
|
|
Imgproc.polylines(img, polyline2, true, new Scalar(0), 2, Imgproc.LINE_8, 1);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertEquals(0, Core.countNonZero(img));
|
|
|
|
}
|
2014-08-14 18:53:02 +08:00
|
|
|
|
2014-08-14 17:48:52 +08:00
|
|
|
public void testPutTextMatStringPointIntDoubleScalar() {
|
|
|
|
String text = "Hello World";
|
2020-11-12 03:17:05 +08:00
|
|
|
Size labelSize = new Size(170, 23);
|
2014-08-14 17:48:52 +08:00
|
|
|
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
|
|
|
|
Point origin = new Point(10, labelSize.height + 10);
|
|
|
|
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.putText(img, text, origin, Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertTrue(Core.countNonZero(img) > 0);
|
|
|
|
// check that border is not corrupted
|
2020-11-12 03:17:05 +08:00
|
|
|
Imgproc.rectangle(img, new Point(10, 10), new Point(labelSize.width + 10, labelSize.height + 10), colorBlack, Imgproc.FILLED);
|
2014-08-14 17:48:52 +08:00
|
|
|
assertEquals(0, Core.countNonZero(img));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testPutTextMatStringPointIntDoubleScalarInt() {
|
|
|
|
String text = "Hello World";
|
2020-11-12 03:17:05 +08:00
|
|
|
Size labelSize = new Size(170, 23);
|
2014-08-14 17:48:52 +08:00
|
|
|
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
|
|
|
|
Point origin = new Point(10, labelSize.height + 10);
|
|
|
|
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.putText(img, text, origin, Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite, 2);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertTrue(Core.countNonZero(img) > 0);
|
|
|
|
// check that border is not corrupted
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.rectangle(img, new Point(10, 10), new Point(labelSize.width + 10 + 1, labelSize.height + 10 + 1), colorBlack, Imgproc.FILLED);
|
2014-08-14 17:48:52 +08:00
|
|
|
assertEquals(0, Core.countNonZero(img));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testPutTextMatStringPointIntDoubleScalarIntIntBoolean() {
|
|
|
|
String text = "Hello World";
|
2020-11-12 03:17:05 +08:00
|
|
|
Size labelSize = new Size(170, 23);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
|
|
|
|
Point origin = new Point(10, 10);
|
|
|
|
|
2018-08-24 16:11:34 +08:00
|
|
|
Imgproc.putText(img, text, origin, Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, colorWhite, 1, Imgproc.LINE_8, true);
|
2014-08-14 17:48:52 +08:00
|
|
|
|
|
|
|
assertTrue(Core.countNonZero(img) > 0);
|
|
|
|
// check that border is not corrupted
|
2020-11-12 03:17:05 +08:00
|
|
|
Imgproc.rectangle(img, new Point(10, 10), new Point(labelSize.width + 10, labelSize.height + 10), colorBlack, Imgproc.FILLED);
|
2014-08-14 17:48:52 +08:00
|
|
|
assertEquals(0, Core.countNonZero(img));
|
|
|
|
}
|
2013-08-21 21:26:54 +08:00
|
|
|
}
|