/modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java

https://bitbucket.org/manctl/opencv-old · Java · 1966 lines · 1450 code · 449 blank · 67 comment · 4 complexity · 749bcb2b54bea6986448a2b50deed428 MD5 · raw file

  1. package org.opencv.test.imgproc;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import org.opencv.core.Core;
  6. import org.opencv.core.CvType;
  7. import org.opencv.core.Mat;
  8. import org.opencv.core.MatOfFloat;
  9. import org.opencv.core.MatOfInt;
  10. import org.opencv.core.MatOfInt4;
  11. import org.opencv.core.MatOfPoint;
  12. import org.opencv.core.MatOfPoint2f;
  13. import org.opencv.core.Point;
  14. import org.opencv.core.Rect;
  15. import org.opencv.core.RotatedRect;
  16. import org.opencv.core.Scalar;
  17. import org.opencv.core.Size;
  18. import org.opencv.core.TermCriteria;
  19. import org.opencv.imgproc.Imgproc;
  20. import org.opencv.test.OpenCVTestCase;
  21. public class ImgprocTest extends OpenCVTestCase {
  22. Point anchorPoint;
  23. private int imgprocSz;
  24. Size size;
  25. @Override
  26. protected void setUp() throws Exception {
  27. super.setUp();
  28. imgprocSz = 2;
  29. anchorPoint = new Point(2, 2);
  30. size = new Size(3, 3);
  31. }
  32. public void testAccumulateMatMat() {
  33. Mat src = getMat(CvType.CV_64F, 2);
  34. Mat dst = getMat(CvType.CV_64F, 0);
  35. Mat dst2 = src.clone();
  36. Imgproc.accumulate(src, dst);
  37. Imgproc.accumulate(src, dst2);
  38. assertMatEqual(src, dst, EPS);
  39. assertMatEqual(getMat(CvType.CV_64F, 4), dst2, EPS);
  40. }
  41. public void testAccumulateMatMatMat() {
  42. Mat src = getMat(CvType.CV_64F, 2);
  43. Mat mask = makeMask(getMat(CvType.CV_8U, 1));
  44. Mat dst = getMat(CvType.CV_64F, 0);
  45. Mat dst2 = src.clone();
  46. Imgproc.accumulate(src, dst, mask);
  47. Imgproc.accumulate(src, dst2, mask);
  48. assertMatEqual(makeMask(getMat(CvType.CV_64F, 2)), dst, EPS);
  49. assertMatEqual(makeMask(getMat(CvType.CV_64F, 4), 2), dst2, EPS);
  50. }
  51. public void testAccumulateProductMatMatMat() {
  52. Mat src = getMat(CvType.CV_64F, 2);
  53. Mat dst = getMat(CvType.CV_64F, 0);
  54. Mat dst2 = src.clone();
  55. Imgproc.accumulateProduct(src, src, dst);
  56. Imgproc.accumulateProduct(src, dst, dst2);
  57. assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);
  58. assertMatEqual(getMat(CvType.CV_64F, 10), dst2, EPS);
  59. }
  60. public void testAccumulateProductMatMatMatMat() {
  61. Mat src = getMat(CvType.CV_64F, 2);
  62. Mat mask = makeMask(getMat(CvType.CV_8U, 1));
  63. Mat dst = getMat(CvType.CV_64F, 0);
  64. Mat dst2 = src.clone();
  65. Imgproc.accumulateProduct(src, src, dst, mask);
  66. Imgproc.accumulateProduct(src, dst, dst2, mask);
  67. assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);
  68. assertMatEqual(makeMask(getMat(CvType.CV_64F, 10), 2), dst2, EPS);
  69. }
  70. public void testAccumulateSquareMatMat() {
  71. Mat src = getMat(CvType.CV_64F, 2);
  72. Mat dst = getMat(CvType.CV_64F, 0);
  73. Mat dst2 = src.clone();
  74. Imgproc.accumulateSquare(src, dst);
  75. Imgproc.accumulateSquare(src, dst2);
  76. assertMatEqual(getMat(CvType.CV_64F, 4), dst, EPS);
  77. assertMatEqual(getMat(CvType.CV_64F, 6), dst2, EPS);
  78. }
  79. public void testAccumulateSquareMatMatMat() {
  80. Mat src = getMat(CvType.CV_64F, 2);
  81. Mat mask = makeMask(getMat(CvType.CV_8U, 1));
  82. Mat dst = getMat(CvType.CV_64F, 0);
  83. Mat dst2 = src.clone();
  84. Imgproc.accumulateSquare(src, dst, mask);
  85. Imgproc.accumulateSquare(src, dst2, mask);
  86. assertMatEqual(makeMask(getMat(CvType.CV_64F, 4)), dst, EPS);
  87. assertMatEqual(makeMask(getMat(CvType.CV_64F, 6), 2), dst2, EPS);
  88. }
  89. public void testAccumulateWeightedMatMatDouble() {
  90. Mat src = getMat(CvType.CV_64F, 2);
  91. Mat dst = getMat(CvType.CV_64F, 4);
  92. Mat dst2 = src.clone();
  93. Imgproc.accumulateWeighted(src, dst, 0.5);
  94. Imgproc.accumulateWeighted(src, dst2, 2);
  95. assertMatEqual(getMat(CvType.CV_64F, 3), dst, EPS);
  96. assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);
  97. }
  98. public void testAccumulateWeightedMatMatDoubleMat() {
  99. Mat src = getMat(CvType.CV_64F, 2);
  100. Mat mask = makeMask(getMat(CvType.CV_8U, 1));
  101. Mat dst = getMat(CvType.CV_64F, 4);
  102. Mat dst2 = src.clone();
  103. Imgproc.accumulateWeighted(src, dst, 0.5, mask);
  104. Imgproc.accumulateWeighted(src, dst2, 2, mask);
  105. assertMatEqual(makeMask(getMat(CvType.CV_64F, 3), 4), dst, EPS);
  106. assertMatEqual(getMat(CvType.CV_64F, 2), dst2, EPS);
  107. }
  108. public void testAdaptiveThreshold() {
  109. Mat src = makeMask(getMat(CvType.CV_8U, 50), 20);
  110. Mat dst = new Mat();
  111. Imgproc.adaptiveThreshold(src, dst, 1, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 3, 0);
  112. assertEquals(src.rows(), Core.countNonZero(dst));
  113. }
  114. public void testApproxPolyDP() {
  115. MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));
  116. MatOfPoint2f approxCurve = new MatOfPoint2f();
  117. Imgproc.approxPolyDP(curve, approxCurve, EPS, true);
  118. List<Point> approxCurveGold = new ArrayList<Point>(3);
  119. approxCurveGold.add(new Point(1, 3));
  120. approxCurveGold.add(new Point(3, 5));
  121. approxCurveGold.add(new Point(5, 3));
  122. assertListPointEquals(approxCurve.toList(), approxCurveGold, EPS);
  123. }
  124. public void testArcLength() {
  125. MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));
  126. double arcLength = Imgproc.arcLength(curve, false);
  127. assertEquals(5.656854152679443, arcLength);
  128. }
  129. public void testBilateralFilterMatMatIntDoubleDouble() {
  130. Imgproc.bilateralFilter(gray255, dst, 5, 10, 5);
  131. assertMatEqual(gray255, dst);
  132. // TODO_: write better test
  133. }
  134. public void testBilateralFilterMatMatIntDoubleDoubleInt() {
  135. Imgproc.bilateralFilter(gray255, dst, 5, 10, 5, Imgproc.BORDER_REFLECT);
  136. assertMatEqual(gray255, dst);
  137. // TODO_: write better test
  138. }
  139. public void testBlurMatMatSize() {
  140. Imgproc.blur(gray0, dst, size);
  141. assertMatEqual(gray0, dst);
  142. Imgproc.blur(gray255, dst, size);
  143. assertMatEqual(gray255, dst);
  144. // TODO_: write better test
  145. }
  146. public void testBlurMatMatSizePoint() {
  147. Imgproc.blur(gray0, dst, size, anchorPoint);
  148. assertMatEqual(gray0, dst);
  149. // TODO_: write better test
  150. }
  151. public void testBlurMatMatSizePointInt() {
  152. Imgproc.blur(gray0, dst, size, anchorPoint, Imgproc.BORDER_REFLECT);
  153. assertMatEqual(gray0, dst);
  154. // TODO_: write better test
  155. }
  156. public void testBorderInterpolate() {
  157. float val1 = Imgproc.borderInterpolate(100, 150, Imgproc.BORDER_REFLECT_101);
  158. assertEquals(100f, val1);
  159. float val2 = Imgproc.borderInterpolate(-5, 10, Imgproc.BORDER_WRAP);
  160. assertEquals(5f, val2);
  161. }
  162. public void testBoundingRect() {
  163. MatOfPoint points = new MatOfPoint(new Point(0, 0), new Point(0, 4), new Point(4, 0), new Point(4, 4));
  164. Point p1 = new Point(1, 1);
  165. Point p2 = new Point(-5, -2);
  166. Rect bbox = Imgproc.boundingRect(points);
  167. assertTrue(bbox.contains(p1));
  168. assertFalse(bbox.contains(p2));
  169. }
  170. public void testBoxFilterMatMatIntSize() {
  171. Size size = new Size(3, 3);
  172. Imgproc.boxFilter(gray0, dst, 8, size);
  173. assertMatEqual(gray0, dst);
  174. // TODO_: write better test
  175. }
  176. public void testBoxFilterMatMatIntSizePointBoolean() {
  177. Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false);
  178. assertMatEqual(gray255, dst);
  179. // TODO_: write better test
  180. }
  181. public void testBoxFilterMatMatIntSizePointBooleanInt() {
  182. Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false, Imgproc.BORDER_REFLECT);
  183. assertMatEqual(gray255, dst);
  184. // TODO_: write better test
  185. }
  186. public void testCalcBackProject() {
  187. List<Mat> images = Arrays.asList(grayChess);
  188. MatOfInt channels = new MatOfInt(0);
  189. MatOfInt histSize = new MatOfInt(10);
  190. MatOfFloat ranges = new MatOfFloat(0f, 256f);
  191. Mat hist = new Mat();
  192. Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
  193. Core.normalize(hist, hist);
  194. Imgproc.calcBackProject(images, channels, hist, dst, ranges, 255);
  195. assertEquals(grayChess.size(), dst.size());
  196. assertEquals(grayChess.depth(), dst.depth());
  197. assertFalse(0 == Core.countNonZero(dst));
  198. }
  199. public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat() {
  200. List<Mat> images = Arrays.asList(gray128);
  201. MatOfInt channels = new MatOfInt(0);
  202. MatOfInt histSize = new MatOfInt(10);
  203. MatOfFloat ranges = new MatOfFloat(0f, 256f);
  204. Mat hist = new Mat();
  205. Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
  206. truth = new Mat(10, 1, CvType.CV_32F, Scalar.all(0)) {
  207. {
  208. put(5, 0, 100);
  209. }
  210. };
  211. assertMatEqual(truth, hist, EPS);
  212. }
  213. public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2D() {
  214. List<Mat> images = Arrays.asList(gray255, gray128);
  215. MatOfInt channels = new MatOfInt(0, 1);
  216. MatOfInt histSize = new MatOfInt(10, 10);
  217. MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
  218. Mat hist = new Mat();
  219. Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges);
  220. truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {
  221. {
  222. put(9, 5, 100);
  223. }
  224. };
  225. assertMatEqual(truth, hist, EPS);
  226. }
  227. public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat3D() {
  228. List<Mat> images = Arrays.asList(rgbLena);
  229. Mat hist3D = new Mat();
  230. List<Mat> histList = Arrays.asList( new Mat[] {new Mat(), new Mat(), new Mat()} );
  231. MatOfInt histSize = new MatOfInt(10);
  232. MatOfFloat ranges = new MatOfFloat(0f, 256f);
  233. for(int i=0; i<rgbLena.channels(); i++)
  234. {
  235. Imgproc.calcHist(images, new MatOfInt(i), new Mat(), histList.get(i), histSize, ranges);
  236. assertEquals(10, histList.get(i).checkVector(1));
  237. }
  238. Core.merge(histList, hist3D);
  239. assertEquals(CvType.CV_32FC3, hist3D.type());
  240. assertEquals(10, hist3D.checkVector(3));
  241. Mat truth = new Mat(10, 1, CvType.CV_32FC3);
  242. truth.put(0, 0,
  243. 0, 24870, 0,
  244. 1863, 31926, 1,
  245. 56682, 37677, 2260,
  246. 77278, 44751, 32436,
  247. 69397, 41343, 18526,
  248. 27180, 40407, 18658,
  249. 21101, 15993, 32042,
  250. 8343, 18585, 47786,
  251. 300, 6567, 80988,
  252. 0, 25, 29447
  253. );
  254. assertMatEqual(truth, hist3D, EPS);
  255. }
  256. public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean() {
  257. List<Mat> images = Arrays.asList(gray255, gray128);
  258. MatOfInt channels = new MatOfInt(0, 1);
  259. MatOfInt histSize = new MatOfInt(10, 10);
  260. MatOfFloat ranges = new MatOfFloat(0f, 256f, 0f, 256f);
  261. Mat hist = new Mat();
  262. Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges, true);
  263. truth = new Mat(10, 10, CvType.CV_32F, Scalar.all(0)) {
  264. {
  265. put(9, 5, 100);
  266. }
  267. };
  268. assertMatEqual(truth, hist, EPS);
  269. }
  270. public void testCannyMatMatDoubleDouble() {
  271. Imgproc.Canny(gray255, dst, 5, 10);
  272. assertMatEqual(gray0, dst);
  273. // TODO_: write better test
  274. }
  275. public void testCannyMatMatDoubleDoubleIntBoolean() {
  276. Imgproc.Canny(gray0, dst, 5, 10, 5, true);
  277. assertMatEqual(gray0, dst);
  278. // TODO_: write better test
  279. }
  280. public void testCompareHist() {
  281. Mat H1 = new Mat(3, 1, CvType.CV_32F);
  282. Mat H2 = new Mat(3, 1, CvType.CV_32F);
  283. H1.put(0, 0, 1, 2, 3);
  284. H2.put(0, 0, 4, 5, 6);
  285. double distance = Imgproc.compareHist(H1, H2, Imgproc.CV_COMP_CORREL);
  286. assertEquals(1., distance);
  287. }
  288. public void testContourAreaMat() {
  289. Mat contour = new Mat(1, 4, CvType.CV_32FC2);
  290. contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);
  291. double area = Imgproc.contourArea(contour);
  292. assertEquals(45., area);
  293. }
  294. public void testContourAreaMatBoolean() {
  295. Mat contour = new Mat(1, 4, CvType.CV_32FC2);
  296. contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);
  297. double area = Imgproc.contourArea(contour, true);
  298. assertEquals(45., area);
  299. // TODO_: write better test
  300. }
  301. public void testConvertMapsMatMatMatMatInt() {
  302. Mat map1 = new Mat(1, 4, CvType.CV_32FC1, new Scalar(1));
  303. Mat map2 = new Mat(1, 4, CvType.CV_32FC1, new Scalar(2));
  304. Mat dstmap1 = new Mat(1, 4, CvType.CV_16SC2);
  305. Mat dstmap2 = new Mat(1, 4, CvType.CV_16UC1);
  306. Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2);
  307. Mat truthMap1 = new Mat(1, 4, CvType.CV_16SC2);
  308. truthMap1.put(0, 0, 1, 2, 1, 2, 1, 2, 1, 2);
  309. assertMatEqual(truthMap1, dstmap1);
  310. Mat truthMap2 = new Mat(1, 4, CvType.CV_16UC1, new Scalar(0));
  311. assertMatEqual(truthMap2, dstmap2);
  312. }
  313. public void testConvertMapsMatMatMatMatIntBoolean() {
  314. Mat map1 = new Mat(1, 3, CvType.CV_32FC1, new Scalar(2));
  315. Mat map2 = new Mat(1, 3, CvType.CV_32FC1, new Scalar(4));
  316. Mat dstmap1 = new Mat(1, 3, CvType.CV_16SC2);
  317. Mat dstmap2 = new Mat(1, 3, CvType.CV_16UC1);
  318. Imgproc.convertMaps(map1, map2, dstmap1, dstmap2, CvType.CV_16SC2, false);
  319. // TODO_: write better test (last param == true)
  320. Mat truthMap1 = new Mat(1, 3, CvType.CV_16SC2);
  321. truthMap1.put(0, 0, 2, 4, 2, 4, 2, 4);
  322. assertMatEqual(truthMap1, dstmap1);
  323. Mat truthMap2 = new Mat(1, 3, CvType.CV_16UC1, new Scalar(0));
  324. assertMatEqual(truthMap2, dstmap2);
  325. }
  326. public void testConvexHullMatMat() {
  327. MatOfPoint points = new MatOfPoint(
  328. new Point(20, 0),
  329. new Point(40, 0),
  330. new Point(30, 20),
  331. new Point(0, 20),
  332. new Point(20, 10),
  333. new Point(30, 10)
  334. );
  335. MatOfInt hull = new MatOfInt();
  336. Imgproc.convexHull(points, hull);
  337. MatOfInt expHull = new MatOfInt(
  338. 1, 2, 3, 0
  339. );
  340. assertMatEqual(expHull, hull, EPS);
  341. }
  342. public void testConvexHullMatMatBooleanBoolean() {
  343. MatOfPoint points = new MatOfPoint(
  344. new Point(2, 0),
  345. new Point(4, 0),
  346. new Point(3, 2),
  347. new Point(0, 2),
  348. new Point(2, 1),
  349. new Point(3, 1)
  350. );
  351. MatOfInt hull = new MatOfInt();
  352. Imgproc.convexHull(points, hull, true);
  353. MatOfInt expHull = new MatOfInt(
  354. 3, 2, 1, 0
  355. );
  356. assertMatEqual(expHull, hull, EPS);
  357. }
  358. public void testConvexityDefects() {
  359. MatOfPoint points = new MatOfPoint(
  360. new Point(20, 0),
  361. new Point(40, 0),
  362. new Point(30, 20),
  363. new Point(0, 20),
  364. new Point(20, 10),
  365. new Point(30, 10)
  366. );
  367. MatOfInt hull = new MatOfInt();
  368. Imgproc.convexHull(points, hull);
  369. MatOfInt4 convexityDefects = new MatOfInt4();
  370. Imgproc.convexityDefects(points, hull, convexityDefects);
  371. assertMatEqual(new MatOfInt4(3, 0, 5, 3620), convexityDefects);
  372. }
  373. public void testCopyMakeBorderMatMatIntIntIntIntInt() {
  374. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1));
  375. int border = 2;
  376. Imgproc.copyMakeBorder(src, dst, border, border, border, border, Imgproc.BORDER_REPLICATE);
  377. truth = new Mat(6, 6, CvType.CV_32F, new Scalar(1));
  378. assertMatEqual(truth, dst, EPS);
  379. }
  380. public void testCopyMakeBorderMatMatIntIntIntIntIntScalar() {
  381. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1));
  382. Scalar value = new Scalar(0);
  383. int border = 2;
  384. Imgproc.copyMakeBorder(src, dst, border, border, border, border, Imgproc.BORDER_REPLICATE, value);
  385. // TODO_: write better test (use Imgproc.BORDER_CONSTANT)
  386. truth = new Mat(6, 6, CvType.CV_32F, new Scalar(1));
  387. assertMatEqual(truth, dst, EPS);
  388. }
  389. public void testCornerEigenValsAndVecsMatMatIntInt() {
  390. fail("Not yet implemented");
  391. // TODO: write better test
  392. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);
  393. src.put(0, 0, 1, 2);
  394. src.put(1, 0, 4, 2);
  395. int blockSize = 3;
  396. int ksize = 5;
  397. // TODO: eigen vals and vectors returned = 0 for most src matrices
  398. Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize);
  399. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC(6), new Scalar(0));
  400. assertMatEqual(truth, dst, EPS);
  401. }
  402. public void testCornerEigenValsAndVecsMatMatIntIntInt() {
  403. fail("Not yet implemented");
  404. // TODO: write better test
  405. Mat src = new Mat(4, 4, CvType.CV_32FC1, new Scalar(128));
  406. int blockSize = 3;
  407. int ksize = 5;
  408. truth = new Mat(4, 4, CvType.CV_32FC(6), new Scalar(0));
  409. Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize, Imgproc.BORDER_REFLECT);
  410. assertMatEqual(truth, dst, EPS);
  411. }
  412. public void testCornerHarrisMatMatIntIntDouble() {
  413. fail("Not yet implemented");
  414. // TODO: write better test
  415. truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
  416. int blockSize = 5;
  417. int ksize = 7;
  418. double k = 0.1;
  419. Imgproc.cornerHarris(gray128, dst, blockSize, ksize, k);
  420. assertMatEqual(truth, dst, EPS);
  421. }
  422. public void testCornerHarrisMatMatIntIntDoubleInt() {
  423. fail("Not yet implemented");
  424. // TODO: write better test
  425. truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
  426. int blockSize = 5;
  427. int ksize = 7;
  428. double k = 0.1;
  429. Imgproc.cornerHarris(gray255, dst, blockSize, ksize, k, Imgproc.BORDER_REFLECT);
  430. assertMatEqual(truth, dst, EPS);
  431. }
  432. public void testCornerMinEigenValMatMatInt() {
  433. fail("Not yet implemented");
  434. // TODO: write better test
  435. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1);
  436. src.put(0, 0, 1, 2);
  437. src.put(1, 0, 2, 1);
  438. int blockSize = 5;
  439. Imgproc.cornerMinEigenVal(src, dst, blockSize);
  440. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(0));
  441. assertMatEqual(truth, dst, EPS);
  442. Imgproc.cornerMinEigenVal(gray255, dst, blockSize);
  443. truth = new Mat(matSize, matSize, CvType.CV_32FC1, new Scalar(0));
  444. assertMatEqual(truth, dst, EPS);
  445. }
  446. public void testCornerMinEigenValMatMatIntInt() {
  447. Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
  448. int blockSize = 3;
  449. int ksize = 5;
  450. Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize);
  451. truth = new Mat(3, 3, CvType.CV_32FC1) {
  452. {
  453. put(0, 0, 1. / 18, 1. / 36, 1. / 18);
  454. put(1, 0, 1. / 36, 1. / 18, 1. / 36);
  455. put(2, 0, 1. / 18, 1. / 36, 1. / 18);
  456. }
  457. };
  458. assertMatEqual(truth, dst, EPS);
  459. }
  460. public void testCornerMinEigenValMatMatIntIntInt() {
  461. Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
  462. int blockSize = 3;
  463. int ksize = 5;
  464. Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize, Imgproc.BORDER_REFLECT);
  465. truth = new Mat(3, 3, CvType.CV_32FC1) {
  466. {
  467. put(0, 0, 0.68055558, 0.92708349, 0.5868057);
  468. put(1, 0, 0.92708343, 0.92708343, 0.92708343);
  469. put(2, 0, 0.58680564, 0.92708343, 0.68055564);
  470. }
  471. };
  472. assertMatEqual(truth, dst, EPS);
  473. }
  474. public void testCornerSubPix() {
  475. Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(128));
  476. Point truthPosition = new Point(img.cols() / 2, img.rows() / 2);
  477. Rect r = new Rect(new Point(0, 0), truthPosition);
  478. Core.rectangle(img, r.tl(), r.br(), new Scalar(0), Core.FILLED);
  479. MatOfPoint2f corners = new MatOfPoint2f(new Point(truthPosition.x + 1, truthPosition.y + 1));
  480. Size winSize = new Size(2, 2);
  481. Size zeroZone = new Size(-1, -1);
  482. TermCriteria criteria = new TermCriteria(TermCriteria.EPS, 0, 0.01);
  483. Imgproc.cornerSubPix(img, corners, winSize, zeroZone, criteria);
  484. assertPointEquals(truthPosition, corners.toList().get(0), weakEPS);
  485. }
  486. public void testCvtColorMatMatInt() {
  487. fail("Not yet implemented");
  488. }
  489. public void testCvtColorMatMatIntInt() {
  490. fail("Not yet implemented");
  491. }
  492. public void testDilateMatMatMat() {
  493. Mat kernel = new Mat();
  494. Imgproc.dilate(gray255, dst, kernel);
  495. assertMatEqual(gray255, dst);
  496. Imgproc.dilate(gray1, dst, kernel);
  497. assertMatEqual(gray1, dst);
  498. // TODO_: write better test
  499. }
  500. public void testDilateMatMatMatPoint() {
  501. fail("Not yet implemented");
  502. }
  503. public void testDilateMatMatMatPointInt() {
  504. fail("Not yet implemented");
  505. }
  506. public void testDilateMatMatMatPointIntInt() {
  507. fail("Not yet implemented");
  508. }
  509. public void testDilateMatMatMatPointIntIntScalar() {
  510. fail("Not yet implemented");
  511. }
  512. public void testDistanceTransformWithLabels() {
  513. Mat dstLables = getMat(CvType.CV_32SC1, 0);
  514. Mat labels = new Mat();
  515. Imgproc.distanceTransformWithLabels(gray128, dst, labels, Imgproc.CV_DIST_L2, 3);
  516. assertMatEqual(dstLables, labels);
  517. assertMatEqual(getMat(CvType.CV_32FC1, 8192), dst, EPS);
  518. }
  519. public void testDrawContoursMatListOfMatIntScalar() {
  520. Core.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100));
  521. List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
  522. Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
  523. Core.drawContours(gray0, contours, -1, new Scalar(0));
  524. assertEquals(0, Core.countNonZero(gray0));
  525. }
  526. public void testDrawContoursMatListOfMatIntScalarInt() {
  527. Core.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100));
  528. List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
  529. Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
  530. Core.drawContours(gray0, contours, -1, new Scalar(0), Core.FILLED);
  531. assertEquals(0, Core.countNonZero(gray0));
  532. }
  533. public void testDrawContoursMatListOfMatIntScalarIntIntMatIntPoint() {
  534. fail("Not yet implemented");
  535. }
  536. public void testEqualizeHist() {
  537. Imgproc.equalizeHist(gray0, dst);
  538. assertMatEqual(gray0, dst);
  539. Imgproc.equalizeHist(gray255, dst);
  540. assertMatEqual(gray255, dst);
  541. // TODO_: write better test
  542. }
  543. public void testErodeMatMatMat() {
  544. Mat kernel = new Mat();
  545. Imgproc.erode(gray128, dst, kernel);
  546. assertMatEqual(gray128, dst);
  547. }
  548. public void testErodeMatMatMatPointInt() {
  549. Mat src = new Mat(3, 3, CvType.CV_8U) {
  550. {
  551. put(0, 0, 15, 9, 10);
  552. put(1, 0, 10, 8, 12);
  553. put(2, 0, 12, 20, 25);
  554. }
  555. };
  556. Mat kernel = new Mat();
  557. Imgproc.erode(src, dst, kernel, anchorPoint, 10);
  558. truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));
  559. assertMatEqual(truth, dst);
  560. }
  561. public void testErodeMatMatMatPointIntIntScalar() {
  562. Mat src = new Mat(3, 3, CvType.CV_8U) {
  563. {
  564. put(0, 0, 15, 9, 10);
  565. put(1, 0, 10, 8, 12);
  566. put(2, 0, 12, 20, 25);
  567. }
  568. };
  569. Mat kernel = new Mat();
  570. Scalar sc = new Scalar(3, 3);
  571. Imgproc.erode(src, dst, kernel, anchorPoint, 10, Imgproc.BORDER_REFLECT, sc);
  572. truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8));
  573. assertMatEqual(truth, dst);
  574. }
  575. public void testFilter2DMatMatIntMat() {
  576. Mat src = Mat.eye(4, 4, CvType.CV_32F);
  577. Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1));
  578. Imgproc.filter2D(src, dst, -1, kernel);
  579. truth = new Mat(4, 4, CvType.CV_32F) {
  580. {
  581. put(0, 0, 2, 2, 1, 0);
  582. put(1, 0, 2, 2, 1, 0);
  583. put(2, 0, 1, 1, 2, 1);
  584. put(3, 0, 0, 0, 1, 2);
  585. }
  586. };
  587. assertMatEqual(truth, dst, EPS);
  588. }
  589. public void testFilter2DMatMatIntMatPointDouble() {
  590. fail("Not yet implemented");
  591. }
  592. public void testFilter2DMatMatIntMatPointDoubleInt() {
  593. Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));
  594. Point point = new Point(0, 0);
  595. Imgproc.filter2D(gray128, dst, -1, kernel, point, 2, Imgproc.BORDER_CONSTANT);
  596. assertMatEqual(gray2, dst);
  597. }
  598. public void testFindContoursMatListOfMatMatIntInt() {
  599. Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0));
  600. List<MatOfPoint> contours = new ArrayList<MatOfPoint>(5);
  601. Mat hierarchy = new Mat();
  602. Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
  603. // no contours on empty image
  604. assertEquals(contours.size(), 0);
  605. assertEquals(contours.size(), hierarchy.total());
  606. Core.rectangle(img, new Point(10, 20), new Point(20, 30), new Scalar(100), 3, Core.LINE_AA, 0);
  607. Core.rectangle(img, new Point(30, 35), new Point(40, 45), new Scalar(200));
  608. Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
  609. // two contours of two rectangles
  610. assertEquals(contours.size(), 2);
  611. assertEquals(contours.size(), hierarchy.total());
  612. }
  613. public void testFindContoursMatListOfMatMatIntIntPoint() {
  614. Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0));
  615. Mat img2 = img.submat(5, 50, 3, 50);
  616. List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
  617. List<MatOfPoint> contours2 = new ArrayList<MatOfPoint>();
  618. Mat hierarchy = new Mat();
  619. Core.rectangle(img, new Point(10, 20), new Point(20, 30), new Scalar(100), 3, Core.LINE_AA, 0);
  620. Core.rectangle(img, new Point(30, 35), new Point(40, 45), new Scalar(200));
  621. Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
  622. Imgproc.findContours(img2, contours2, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE, new Point(3, 5));
  623. assertEquals(contours.size(), contours2.size());
  624. assertMatEqual(contours.get(0), contours2.get(0));
  625. /*
  626. Log.d("findContours", "hierarchy=" + hierarchy);
  627. int iBuff[] = new int[ (int) (hierarchy.total() * hierarchy.channels()) ]; // [ Contour0 (next sibling num, previous sibling num, 1st child num, parent num), Contour1(...), ...
  628. hierarchy.get(0, 0, iBuff);
  629. Log.d("findContours", Arrays.toString(iBuff));
  630. */
  631. }
  632. public void testFitEllipse() {
  633. MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-1, 1), new Point(1, 1), new Point(1, -1), new Point(-1, -1));
  634. RotatedRect rrect = new RotatedRect();
  635. rrect = Imgproc.fitEllipse(points);
  636. assertPointEquals(new Point(0, 0), rrect.center, EPS);
  637. assertEquals(2.828, rrect.size.width, EPS);
  638. assertEquals(2.828, rrect.size.height, EPS);
  639. }
  640. public void testFitLine() {
  641. Mat points = new Mat(1, 4, CvType.CV_32FC2);
  642. points.put(0, 0, 0, 0, 2, 3, 3, 4, 5, 8);
  643. Mat linePoints = new Mat(4, 1, CvType.CV_32FC1);
  644. linePoints.put(0, 0, 0.53196341, 0.84676737, 2.496531, 3.7467217);
  645. Imgproc.fitLine(points, dst, Imgproc.CV_DIST_L12, 0, 0.01, 0.01);
  646. assertMatEqual(linePoints, dst, EPS);
  647. }
  648. public void testFloodFillMatMatPointScalar() {
  649. Mat mask = new Mat(matSize + 2, matSize + 2, CvType.CV_8U, new Scalar(0));
  650. Mat img = gray0;
  651. Core.circle(mask, new Point(matSize / 2 + 1, matSize / 2 + 1), 3, new Scalar(2));
  652. int retval = Imgproc.floodFill(img, mask, new Point(matSize / 2, matSize / 2), new Scalar(1));
  653. assertEquals(Core.countNonZero(img), retval);
  654. Core.circle(mask, new Point(matSize / 2 + 1, matSize / 2 + 1), 3, new Scalar(0));
  655. assertEquals(retval + 4 * (matSize + 1), Core.countNonZero(mask));
  656. assertMatEqual(mask.submat(1, matSize + 1, 1, matSize + 1), img);
  657. }
  658. public void testFloodFillMatMatPointScalar_WithoutMask() {
  659. Mat img = gray0;
  660. Core.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(2));
  661. // TODO: ideally we should pass null instead of "new Mat()"
  662. int retval = Imgproc.floodFill(img, new Mat(), new Point(matSize / 2, matSize / 2), new Scalar(1));
  663. Core.circle(img, new Point(matSize / 2, matSize / 2), 3, new Scalar(0));
  664. assertEquals(Core.countNonZero(img), retval);
  665. }
  666. public void testFloodFillMatMatPointScalarRect() {
  667. fail("Not yet implemented");
  668. }
  669. public void testFloodFillMatMatPointScalarRectScalar() {
  670. fail("Not yet implemented");
  671. }
  672. public void testFloodFillMatMatPointScalarRectScalarScalar() {
  673. fail("Not yet implemented");
  674. }
  675. public void testFloodFillMatMatPointScalarRectScalarScalarInt() {
  676. fail("Not yet implemented");
  677. }
  678. public void testGaussianBlurMatMatSizeDouble() {
  679. Imgproc.GaussianBlur(gray0, dst, size, 1);
  680. assertMatEqual(gray0, dst);
  681. Imgproc.GaussianBlur(gray2, dst, size, 1);
  682. assertMatEqual(gray2, dst);
  683. }
  684. public void testGaussianBlurMatMatSizeDoubleDouble() {
  685. Imgproc.GaussianBlur(gray2, dst, size, 0, 0);
  686. assertMatEqual(gray2, dst);
  687. // TODO_: write better test
  688. }
  689. public void testGaussianBlurMatMatSizeDoubleDoubleInt() {
  690. Imgproc.GaussianBlur(gray2, dst, size, 1, 3, Imgproc.BORDER_REFLECT);
  691. assertMatEqual(gray2, dst);
  692. // TODO_: write better test
  693. }
  694. public void testGetAffineTransform() {
  695. MatOfPoint2f src = new MatOfPoint2f(new Point(2, 3), new Point(3, 1), new Point(1, 4));
  696. MatOfPoint2f dst = new MatOfPoint2f(new Point(3, 3), new Point(7, 4), new Point(5, 6));
  697. Mat transform = Imgproc.getAffineTransform(src, dst);
  698. Mat truth = new Mat(2, 3, CvType.CV_64FC1) {
  699. {
  700. put(0, 0, -8, -6, 37);
  701. put(1, 0, -7, -4, 29);
  702. }
  703. };
  704. assertMatEqual(truth, transform, EPS);
  705. }
  706. public void testGetDefaultNewCameraMatrixMat() {
  707. Mat mtx = Imgproc.getDefaultNewCameraMatrix(gray0);
  708. assertFalse(mtx.empty());
  709. assertEquals(0, Core.countNonZero(mtx));
  710. }
  711. public void testGetDefaultNewCameraMatrixMatSizeBoolean() {
  712. Mat mtx = Imgproc.getDefaultNewCameraMatrix(gray0, size, true);
  713. assertFalse(mtx.empty());
  714. assertFalse(0 == Core.countNonZero(mtx));
  715. // TODO_: write better test
  716. }
  717. public void testGetDerivKernelsMatMatIntIntInt() {
  718. Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
  719. Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
  720. Mat expKx = new Mat(3, 1, CvType.CV_32F);
  721. Mat expKy = new Mat(3, 1, CvType.CV_32F);
  722. kx.put(0, 0, 1, 1);
  723. kx.put(1, 0, 1, 1);
  724. ky.put(0, 0, 2, 2);
  725. ky.put(1, 0, 2, 2);
  726. expKx.put(0, 0, 1, -2, 1);
  727. expKy.put(0, 0, 1, -2, 1);
  728. Imgproc.getDerivKernels(kx, ky, 2, 2, 3);
  729. assertMatEqual(expKx, kx, EPS);
  730. assertMatEqual(expKy, ky, EPS);
  731. }
  732. public void testGetDerivKernelsMatMatIntIntIntBooleanInt() {
  733. Mat kx = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
  734. Mat ky = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
  735. Mat expKx = new Mat(3, 1, CvType.CV_32F);
  736. Mat expKy = new Mat(3, 1, CvType.CV_32F);
  737. kx.put(0, 0, 1, 1);
  738. kx.put(1, 0, 1, 1);
  739. ky.put(0, 0, 2, 2);
  740. ky.put(1, 0, 2, 2);
  741. expKx.put(0, 0, 1, -2, 1);
  742. expKy.put(0, 0, 1, -2, 1);
  743. Imgproc.getDerivKernels(kx, ky, 2, 2, 3, true, CvType.CV_32F);
  744. assertMatEqual(expKx, kx, EPS);
  745. assertMatEqual(expKy, ky, EPS);
  746. // TODO_: write better test
  747. }
  748. public void testGetGaussianKernelIntDouble() {
  749. dst = Imgproc.getGaussianKernel(1, 0.5);
  750. truth = new Mat(1, 1, CvType.CV_64FC1, new Scalar(1));
  751. assertMatEqual(truth, dst, EPS);
  752. }
  753. public void testGetGaussianKernelIntDoubleInt() {
  754. dst = Imgproc.getGaussianKernel(3, 0.8, CvType.CV_32F);
  755. truth = new Mat(3, 1, CvType.CV_32F);
  756. truth.put(0, 0, 0.23899426, 0.52201146, 0.23899426);
  757. assertMatEqual(truth, dst, EPS);
  758. }
  759. public void testGetPerspectiveTransform() {
  760. fail("Not yet implemented");
  761. }
  762. public void testGetRectSubPixMatSizePointMat() {
  763. Size size = new Size(3, 3);
  764. Point center = new Point(gray255.cols() / 2, gray255.rows() / 2);
  765. Imgproc.getRectSubPix(gray255, size, center, dst);
  766. truth = new Mat(3, 3, CvType.CV_8U, new Scalar(255));
  767. assertMatEqual(truth, dst);
  768. }
  769. public void testGetRectSubPixMatSizePointMatInt() {
  770. Mat src = new Mat(10, 10, CvType.CV_32F, new Scalar(2));
  771. Size patchSize = new Size(5, 5);
  772. Point center = new Point(src.cols() / 2, src.rows() / 2);
  773. Imgproc.getRectSubPix(src, patchSize, center, dst);
  774. truth = new Mat(5, 5, CvType.CV_32F, new Scalar(2));
  775. assertMatEqual(truth, dst, EPS);
  776. }
  777. public void testGetRotationMatrix2D() {
  778. Point center = new Point(0, 0);
  779. dst = Imgproc.getRotationMatrix2D(center, 0, 1);
  780. truth = new Mat(2, 3, CvType.CV_64F) {
  781. {
  782. put(0, 0, 1, 0, 0);
  783. put(1, 0, 0, 1, 0);
  784. }
  785. };
  786. assertMatEqual(truth, dst, EPS);
  787. }
  788. public void testGetStructuringElementIntSize() {
  789. dst = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, size);
  790. truth = new Mat(3, 3, CvType.CV_8UC1, new Scalar(1));
  791. assertMatEqual(truth, dst);
  792. }
  793. public void testGetStructuringElementIntSizePoint() {
  794. dst = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, size, anchorPoint);
  795. truth = new Mat(3, 3, CvType.CV_8UC1) {
  796. {
  797. put(0, 0, 0, 0, 1);
  798. put(1, 0, 0, 0, 1);
  799. put(2, 0, 1, 1, 1);
  800. }
  801. };
  802. assertMatEqual(truth, dst);
  803. }
  804. public void testGoodFeaturesToTrackMatListOfPointIntDoubleDouble() {
  805. Mat src = gray0;
  806. Core.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
  807. MatOfPoint lp = new MatOfPoint();
  808. Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3);
  809. assertEquals(4, lp.total());
  810. }
  811. public void testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDouble() {
  812. Mat src = gray0;
  813. Core.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
  814. MatOfPoint lp = new MatOfPoint();
  815. Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3, gray1, 4, true, 0);
  816. assertEquals(4, lp.total());
  817. }
  818. public void testGrabCutMatMatRectMatMatInt() {
  819. fail("Not yet implemented");
  820. }
  821. public void testGrabCutMatMatRectMatMatIntInt() {
  822. fail("Not yet implemented");
  823. }
  824. public void testHoughCirclesMatMatIntDoubleDouble() {
  825. int sz = 512;
  826. Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));
  827. Mat circles = new Mat();
  828. Imgproc.HoughCircles(img, circles, Imgproc.CV_HOUGH_GRADIENT, 2, img.rows() / 4);
  829. assertEquals(0, circles.cols());
  830. }
  831. public void testHoughCirclesMatMatIntDoubleDouble1() {
  832. int sz = 512;
  833. Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(128));
  834. Mat circles = new Mat();
  835. Point center = new Point(img.cols() / 2, img.rows() / 2);
  836. int radius = Math.min(img.cols() / 4, img.rows() / 4);
  837. Core.circle(img, center, radius, colorBlack, 3);
  838. Imgproc.HoughCircles(img, circles, Imgproc.CV_HOUGH_GRADIENT, 2, img.rows() / 4);
  839. assertEquals(1, circles.cols());
  840. }
  841. public void testHoughCirclesMatMatIntDoubleDoubleDoubleDoubleIntInt() {
  842. fail("Not yet implemented");
  843. }
  844. public void testHoughLinesMatMatDoubleDoubleInt() {
  845. int sz = 512;
  846. Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));
  847. Point point1 = new Point(50, 50);
  848. Point point2 = new Point(img.cols() / 2, img.rows() / 2);
  849. Core.line(img, point1, point2, colorWhite, 1);
  850. Mat lines = new Mat();
  851. Imgproc.HoughLines(img, lines, 1, 3.1415926/180, 100);
  852. assertEquals(1, lines.cols());
  853. /*
  854. Log.d("HoughLines", "lines=" + lines);
  855. int num = (int)lines.total();
  856. int buff[] = new int[num*4]; //[ (x1, y1, x2, y2), (...), ...]
  857. lines.get(0, 0, buff);
  858. Log.d("HoughLines", "lines=" + Arrays.toString(buff));
  859. */
  860. }
  861. public void testHoughLinesMatMatDoubleDoubleIntDouble() {
  862. fail("Not yet implemented");
  863. }
  864. public void testHoughLinesMatMatDoubleDoubleIntDoubleDouble() {
  865. fail("Not yet implemented");
  866. }
  867. public void testHoughLinesPMatMatDoubleDoubleInt() {
  868. int sz = 512;
  869. Mat img = new Mat(sz, sz, CvType.CV_8U, new Scalar(0));
  870. Point point1 = new Point(0, 0);
  871. Point point2 = new Point(sz, sz);
  872. Point point3 = new Point(sz, 0);
  873. Point point4 = new Point(2*sz/3, sz/3);
  874. Core.line(img, point1, point2, Scalar.all(255), 1);
  875. Core.line(img, point3, point4, Scalar.all(255), 1);
  876. Mat lines = new Mat();
  877. Imgproc.HoughLinesP(img, lines, 1, 3.1415926/180, 100);
  878. assertEquals(2, lines.cols());
  879. /*
  880. Log.d("HoughLinesP", "lines=" + lines);
  881. int num = (int)lines.cols();
  882. int buff[] = new int[num*4]; // CV_32SC4 as [ (x1, y1, x2, y2), (...), ...]
  883. lines.get(0, 0, buff);
  884. Log.d("HoughLinesP", "lines=" + Arrays.toString(buff));
  885. */
  886. }
  887. public void testHoughLinesPMatMatDoubleDoubleIntDouble() {
  888. fail("Not yet implemented");
  889. }
  890. public void testHoughLinesPMatMatDoubleDoubleIntDoubleDouble() {
  891. fail("Not yet implemented");
  892. }
  893. public void testHuMoments() {
  894. fail("Not yet implemented");
  895. }
  896. public void testInitUndistortRectifyMap() {
  897. fail("Not yet implemented");
  898. Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
  899. cameraMatrix.put(0, 0, 1, 0, 1);
  900. cameraMatrix.put(1, 0, 0, 1, 1);
  901. cameraMatrix.put(2, 0, 0, 0, 1);
  902. Mat R = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
  903. Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  904. Mat distCoeffs = new Mat();
  905. Mat map1 = new Mat();
  906. Mat map2 = new Mat();
  907. // TODO: complete this test
  908. Imgproc.initUndistortRectifyMap(cameraMatrix, distCoeffs, R, newCameraMatrix, size, CvType.CV_32F, map1, map2);
  909. }
  910. public void testInitWideAngleProjMapMatMatSizeIntIntMatMat() {
  911. fail("Not yet implemented");
  912. Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
  913. Mat distCoeffs = new Mat(1, 4, CvType.CV_32F);
  914. // Size imageSize = new Size(2, 2);
  915. cameraMatrix.put(0, 0, 1, 0, 1);
  916. cameraMatrix.put(1, 0, 0, 1, 2);
  917. cameraMatrix.put(2, 0, 0, 0, 1);
  918. distCoeffs.put(0, 0, 1, 3, 2, 4);
  919. truth = new Mat(3, 3, CvType.CV_32F);
  920. truth.put(0, 0, 0, 0, 0);
  921. truth.put(1, 0, 0, 0, 0);
  922. truth.put(2, 0, 0, 3, 0);
  923. // TODO: No documentation for this function
  924. // Imgproc.initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize,
  925. // 5, m1type, truthput1, truthput2);
  926. }
  927. public void testInitWideAngleProjMapMatMatSizeIntIntMatMatInt() {
  928. fail("Not yet implemented");
  929. }
  930. public void testInitWideAngleProjMapMatMatSizeIntIntMatMatIntDouble() {
  931. fail("Not yet implemented");
  932. }
  933. public void testIntegral2MatMatMat() {
  934. Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  935. Mat expSum = new Mat(4, 4, CvType.CV_64F);
  936. Mat expSqsum = new Mat(4, 4, CvType.CV_64F);
  937. Mat sum = new Mat();
  938. Mat sqsum = new Mat();
  939. expSum.put(0, 0, 0, 0, 0, 0);
  940. expSum.put(1, 0, 0, 3, 6, 9);
  941. expSum.put(2, 0, 0, 6, 12, 18);
  942. expSum.put(3, 0, 0, 9, 18, 27);
  943. expSqsum.put(0, 0, 0, 0, 0, 0);
  944. expSqsum.put(1, 0, 0, 9, 18, 27);
  945. expSqsum.put(2, 0, 0, 18, 36, 54);
  946. expSqsum.put(3, 0, 0, 27, 54, 81);
  947. Imgproc.integral2(src, sum, sqsum);
  948. assertMatEqual(expSum, sum, EPS);
  949. assertMatEqual(expSqsum, sqsum, EPS);
  950. }
  951. public void testIntegral2MatMatMatInt() {
  952. Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  953. Mat expSum = new Mat(4, 4, CvType.CV_64F);
  954. Mat expSqsum = new Mat(4, 4, CvType.CV_64F);
  955. Mat sum = new Mat();
  956. Mat sqsum = new Mat();
  957. expSum.put(0, 0, 0, 0, 0, 0);
  958. expSum.put(1, 0, 0, 3, 6, 9);
  959. expSum.put(2, 0, 0, 6, 12, 18);
  960. expSum.put(3, 0, 0, 9, 18, 27);
  961. expSqsum.put(0, 0, 0, 0, 0, 0);
  962. expSqsum.put(1, 0, 0, 9, 18, 27);
  963. expSqsum.put(2, 0, 0, 18, 36, 54);
  964. expSqsum.put(3, 0, 0, 27, 54, 81);
  965. Imgproc.integral2(src, sum, sqsum, CvType.CV_64F);
  966. assertMatEqual(expSum, sum, EPS);
  967. assertMatEqual(expSqsum, sqsum, EPS);
  968. }
  969. public void testIntegral3MatMatMatMat() {
  970. Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));
  971. Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
  972. Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
  973. Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
  974. Mat sum = new Mat();
  975. Mat sqsum = new Mat();
  976. Mat tilted = new Mat();
  977. expSum.put(0, 0, 0, 0);
  978. expSum.put(1, 0, 0, 1);
  979. expSqsum.put(0, 0, 0, 0);
  980. expSqsum.put(1, 0, 0, 1);
  981. expTilted.put(0, 0, 0, 0);
  982. expTilted.put(1, 0, 0, 1);
  983. Imgproc.integral3(src, sum, sqsum, tilted);
  984. assertMatEqual(expSum, sum, EPS);
  985. assertMatEqual(expSqsum, sqsum, EPS);
  986. assertMatEqual(expTilted, tilted, EPS);
  987. }
  988. public void testIntegral3MatMatMatMatInt() {
  989. Mat src = new Mat(1, 1, CvType.CV_32F, new Scalar(1));
  990. Mat expSum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
  991. Mat expSqsum = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
  992. Mat expTilted = new Mat(imgprocSz, imgprocSz, CvType.CV_64F);
  993. Mat sum = new Mat();
  994. Mat sqsum = new Mat();
  995. Mat tilted = new Mat();
  996. expSum.put(0, 0, 0, 0);
  997. expSum.put(1, 0, 0, 1);
  998. expSqsum.put(0, 0, 0, 0);
  999. expSqsum.put(1, 0, 0, 1);
  1000. expTilted.put(0, 0, 0, 0);
  1001. expTilted.put(1, 0, 0, 1);
  1002. Imgproc.integral3(src, sum, sqsum, tilted, CvType.CV_64F);
  1003. assertMatEqual(expSum, sum, EPS);
  1004. assertMatEqual(expSqsum, sqsum, EPS);
  1005. assertMatEqual(expTilted, tilted, EPS);
  1006. }
  1007. public void testIntegralMatMat() {
  1008. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
  1009. Imgproc.integral(src, dst);
  1010. truth = new Mat(3, 3, CvType.CV_64F) {
  1011. {
  1012. put(0, 0, 0, 0, 0);
  1013. put(1, 0, 0, 2, 4);
  1014. put(2, 0, 0, 4, 8);
  1015. }
  1016. };
  1017. assertMatEqual(truth, dst, EPS);
  1018. }
  1019. public void testIntegralMatMatInt() {
  1020. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
  1021. Imgproc.integral(src, dst, CvType.CV_64F);
  1022. truth = new Mat(3, 3, CvType.CV_64F) {
  1023. {
  1024. put(0, 0, 0, 0, 0);
  1025. put(1, 0, 0, 2, 4);
  1026. put(2, 0, 0, 4, 8);
  1027. }
  1028. };
  1029. assertMatEqual(truth, dst, EPS);
  1030. }
  1031. public void testInvertAffineTransform() {
  1032. Mat src = new Mat(2, 3, CvType.CV_64F, new Scalar(1));
  1033. Imgproc.invertAffineTransform(src, dst);
  1034. truth = new Mat(2, 3, CvType.CV_64F, new Scalar(0));
  1035. assertMatEqual(truth, dst, EPS);
  1036. }
  1037. public void testIsContourConvex() {
  1038. MatOfPoint contour1 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4));
  1039. assertFalse(Imgproc.isContourConvex(contour1));
  1040. MatOfPoint contour2 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6));
  1041. assertTrue(Imgproc.isContourConvex(contour2));
  1042. }
  1043. public void testLaplacianMatMatInt() {
  1044. Imgproc.Laplacian(gray0, dst, CvType.CV_8U);
  1045. assertMatEqual(gray0, dst);
  1046. }
  1047. public void testLaplacianMatMatIntIntDoubleDouble() {
  1048. Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
  1049. Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS);
  1050. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
  1051. {
  1052. put(0, 0, -7.9990001, 8.0009995);
  1053. put(1, 0, 8.0009995, -7.9990001);
  1054. }
  1055. };
  1056. assertMatEqual(truth, dst, EPS);
  1057. }
  1058. public void testLaplacianMatMatIntIntDoubleDoubleInt() {
  1059. Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
  1060. Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS, Imgproc.BORDER_REFLECT);
  1061. truth = new Mat(3, 3, CvType.CV_32F, new Scalar(0.00099945068));
  1062. assertMatEqual(truth, dst, EPS);
  1063. }
  1064. public void testMatchShapes() {
  1065. Mat contour1 = new Mat(1, 4, CvType.CV_32FC2);
  1066. Mat contour2 = new Mat(1, 4, CvType.CV_32FC2);
  1067. contour1.put(0, 0, 1, 1, 5, 1, 4, 3, 6, 2);
  1068. contour2.put(0, 0, 1, 1, 6, 1, 4, 1, 2, 5);
  1069. double distance = Imgproc.matchShapes(contour1, contour2, Imgproc.CV_CONTOURS_MATCH_I1, 1);
  1070. assertEquals(2.81109697365334, distance, EPS);
  1071. }
  1072. public void testMatchTemplate() {
  1073. Mat image = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
  1074. Mat templ = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
  1075. image.put(0, 0, 1, 2, 3, 4);
  1076. templ.put(0, 0, 5, 6, 7, 8);
  1077. Imgproc.matchTemplate(image, templ, dst, Imgproc.TM_CCORR);
  1078. truth = new Mat(1, 1, CvType.CV_32F, new Scalar(70));
  1079. assertMatEqual(truth, dst, EPS);
  1080. Imgproc.matchTemplate(gray255, gray0, dst, Imgproc.TM_CCORR);
  1081. truth = new Mat(1, 1, CvType.CV_32F, new Scalar(0));
  1082. assertMatEqual(truth, dst, EPS);
  1083. }
  1084. public void testMedianBlur() {
  1085. Imgproc.medianBlur(gray255, dst, 5);
  1086. assertMatEqual(gray255, dst);
  1087. Imgproc.medianBlur(gray2, dst, 3);
  1088. assertMatEqual(gray2, dst);
  1089. // TODO_: write better test
  1090. }
  1091. public void testMinAreaRect() {
  1092. MatOfPoint2f points = new MatOfPoint2f(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2));
  1093. RotatedRect rrect = Imgproc.minAreaRect(points);
  1094. assertEquals(new Size(2, 5), rrect.size);
  1095. assertEquals(-90., rrect.angle);
  1096. assertEquals(new Point(3.5, 2), rrect.center);
  1097. }
  1098. public void testMinEnclosingCircle() {
  1099. MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-1, 0), new Point(0, -1), new Point(1, 0), new Point(0, 1));
  1100. Point actualCenter = new Point();
  1101. float[] radius = new float[1];
  1102. Imgproc.minEnclosingCircle(points, actualCenter, radius);
  1103. assertEquals(new Point(0, 0), actualCenter);
  1104. assertEquals(1.03f, radius[0], EPS);
  1105. }
  1106. public void testMomentsMat() {
  1107. fail("Not yet implemented");
  1108. }
  1109. public void testMomentsMatBoolean() {
  1110. fail("Not yet implemented");
  1111. }
  1112. public void testMorphologyExMatMatIntMat() {
  1113. Imgproc.morphologyEx(gray255, dst, Imgproc.MORPH_GRADIENT, gray0);
  1114. assertMatEqual(gray0, dst);
  1115. // TODO_: write better test
  1116. }
  1117. public void testMorphologyExMatMatIntMatPointInt() {
  1118. Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);
  1119. Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(0));
  1120. Point point = new Point(0, 0);
  1121. Imgproc.morphologyEx(src, dst, Imgproc.MORPH_CLOSE, kernel, point, 10);
  1122. truth = Mat.eye(imgprocSz, imgprocSz, CvType.CV_8U);
  1123. assertMatEqual(truth, dst);
  1124. // TODO_: write better test
  1125. }
  1126. public void testMorphologyExMatMatIntMatPointIntIntScalar() {
  1127. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8U);
  1128. src.put(0, 0, 2, 1);
  1129. src.put(1, 0, 2, 1);
  1130. Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_8U, new Scalar(1));
  1131. Point point = new Point(1, 1);
  1132. Scalar sc = new Scalar(3, 3);
  1133. Imgproc.morphologyEx(src, dst, Imgproc.MORPH_TOPHAT, kernel, point, 10, Imgproc.BORDER_REFLECT, sc);
  1134. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_8U) {
  1135. {
  1136. put(0, 0, 1, 0);
  1137. put(1, 0, 1, 0);
  1138. }
  1139. };
  1140. assertMatEqual(truth, dst);
  1141. // TODO_: write better test
  1142. }
  1143. public void testPointPolygonTest() {
  1144. MatOfPoint2f contour = new MatOfPoint2f(new Point(0, 0), new Point(1, 3), new Point(3, 4), new Point(4, 3), new Point(2, 1));
  1145. double sign1 = Imgproc.pointPolygonTest(contour, new Point(2, 2), false);
  1146. assertEquals(1.0, sign1);
  1147. double sign2 = Imgproc.pointPolygonTest(contour, new Point(4, 4), true);
  1148. assertEquals(-Math.sqrt(0.5), sign2);
  1149. }
  1150. public void testPreCornerDetectMatMatInt() {
  1151. Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));
  1152. int ksize = 3;
  1153. Imgproc.preCornerDetect(src, dst, ksize);
  1154. truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
  1155. assertMatEqual(truth, dst, EPS);
  1156. }
  1157. public void testPreCornerDetectMatMatIntInt() {
  1158. Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1));
  1159. int ksize = 3;
  1160. Imgproc.preCornerDetect(src, dst, ksize, Imgproc.BORDER_REFLECT);
  1161. truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
  1162. assertMatEqual(truth, dst, EPS);
  1163. // TODO_: write better test
  1164. }
  1165. public void testPyrDownMatMat() {
  1166. Mat src = new Mat(4, 4, CvType.CV_32F) {
  1167. {
  1168. put(0, 0, 2, 1, 4, 2);
  1169. put(1, 0, 3, 2, 6, 8);
  1170. put(2, 0, 4, 6, 8, 10);
  1171. put(3, 0, 12, 32, 6, 18);
  1172. }
  1173. };
  1174. Imgproc.pyrDown(src, dst);
  1175. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
  1176. {
  1177. put(0, 0, 2.78125, 4.609375);
  1178. put(1, 0, 8.546875, 8.8515625);
  1179. }
  1180. };
  1181. assertMatEqual(truth, dst, EPS);
  1182. }
  1183. public void testPyrDownMatMatSize() {
  1184. Mat src = new Mat(4, 4, CvType.CV_32F) {
  1185. {
  1186. put(0, 0, 2, 1, 4, 2);
  1187. put(1, 0, 3, 2, 6, 8);
  1188. put(2, 0, 4, 6, 8, 10);
  1189. put(3, 0, 12, 32, 6, 18);
  1190. }
  1191. };
  1192. Size dstSize = new Size(2, 2);
  1193. Imgproc.pyrDown(src, dst, dstSize);
  1194. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F) {
  1195. {
  1196. put(0, 0, 2.78125, 4.609375);
  1197. put(1, 0, 8.546875, 8.8515625);
  1198. }
  1199. };
  1200. assertMatEqual(truth, dst, EPS);
  1201. // TODO_: write better test
  1202. }
  1203. public void testPyrMeanShiftFilteringMatMatDoubleDouble() {
  1204. Mat src = new Mat(matSize, matSize, CvType.CV_8UC3, new Scalar(0));
  1205. Imgproc.pyrMeanShiftFiltering(src, dst, 10, 50);
  1206. assertMatEqual(src, dst);
  1207. // TODO_: write better test
  1208. }
  1209. public void testPyrMeanShiftFilteringMatMatDoubleDoubleInt() {
  1210. fail("Not yet implemented");
  1211. }
  1212. public void testPyrMeanShiftFilteringMatMatDoubleDoubleIntTermCriteria() {
  1213. fail("Not yet implemented");
  1214. }
  1215. public void testPyrUpMatMat() {
  1216. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F);
  1217. src.put(0, 0, 2, 1);
  1218. src.put(1, 0, 3, 2);
  1219. Imgproc.pyrUp(src, dst);
  1220. truth = new Mat(4, 4, CvType.CV_32F) {
  1221. {
  1222. put(0, 0, 2, 1.75, 1.375, 1.25);
  1223. put(1, 0, 2.25, 2, 1.625, 1.5);
  1224. put(2, 0, 2.625, 2.375, 2, 1.875);
  1225. put(3, 0, 2.75, 2.5, 2.125, 2);
  1226. }
  1227. };
  1228. assertMatEqual(truth, dst, EPS);
  1229. }
  1230. public void testPyrUpMatMatSize() {
  1231. fail("Not yet implemented");
  1232. }
  1233. public void testRemapMatMatMatMatInt() {
  1234. fail("Not yet implemented");
  1235. // this test does something weird
  1236. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
  1237. Mat map1 = new Mat(1, 3, CvType.CV_32FC1);
  1238. Mat map2 = new Mat(1, 3, CvType.CV_32FC1);
  1239. map1.put(0, 0, 3, 6, 5);
  1240. map2.put(0, 0, 4, 8, 12);
  1241. Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR);
  1242. truth = new Mat(1, 3, CvType.CV_32F, new Scalar(0));
  1243. assertMatEqual(truth, dst, EPS);
  1244. }
  1245. public void testRemapMatMatMatMatIntIntScalar() {
  1246. fail("Not yet implemented");
  1247. // this test does something weird
  1248. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
  1249. Mat map1 = new Mat(1, 3, CvType.CV_32FC1);
  1250. Mat map2 = new Mat(1, 3, CvType.CV_32FC1);
  1251. Scalar sc = new Scalar(0);
  1252. map1.put(0, 0, 3, 6, 5, 0);
  1253. map2.put(0, 0, 4, 8, 12);
  1254. truth = new Mat(1, 3, CvType.CV_32F, new Scalar(2));
  1255. Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR, Imgproc.BORDER_REFLECT, sc);
  1256. assertMatEqual(truth, dst, EPS);
  1257. }
  1258. public void testResizeMatMatSize() {
  1259. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_8UC1, new Scalar(1));
  1260. Size dsize = new Size(1, 1);
  1261. Imgproc.resize(src, dst, dsize);
  1262. truth = new Mat(1, 1, CvType.CV_8UC1, new Scalar(1));
  1263. assertMatEqual(truth, dst);
  1264. }
  1265. public void testResizeMatMatSizeDoubleDoubleInt() {
  1266. Imgproc.resize(gray255, dst, new Size(2, 2), 0, 0, Imgproc.INTER_AREA);
  1267. truth = new Mat(2, 2, CvType.CV_8UC1, new Scalar(255));
  1268. assertMatEqual(truth, dst);
  1269. // TODO_: write better test
  1270. }
  1271. public void testScharrMatMatIntIntInt() {
  1272. Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
  1273. Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0);
  1274. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0));
  1275. assertMatEqual(truth, dst, EPS);
  1276. }
  1277. public void testScharrMatMatIntIntIntDoubleDouble() {
  1278. Mat src = Mat.eye(imgprocSz, imgprocSz, CvType.CV_32F);
  1279. Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0.001);
  1280. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0.001));
  1281. assertMatEqual(truth, dst, EPS);
  1282. }
  1283. public void testScharrMatMatIntIntIntDoubleDoubleInt() {
  1284. Mat src = Mat.eye(3, 3, CvType.CV_32F);
  1285. Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0, Imgproc.BORDER_REFLECT);
  1286. truth = new Mat(3, 3, CvType.CV_32F) {
  1287. {
  1288. put(0, 0, -15, -19.5, -4.5);
  1289. put(1, 0, 10.5, 0, -10.5);
  1290. put(2, 0, 4.5, 19.5, 15);
  1291. }
  1292. };
  1293. assertMatEqual(truth, dst, EPS);
  1294. }
  1295. public void testSepFilter2DMatMatIntMatMat() {
  1296. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(2));
  1297. Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
  1298. Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
  1299. kernelX.put(0, 0, 4, 3, 7);
  1300. kernelY.put(0, 0, 9, 4, 2);
  1301. Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY);
  1302. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(420));
  1303. assertMatEqual(truth, dst, EPS);
  1304. }
  1305. public void testSepFilter2DMatMatIntMatMatPointDouble() {
  1306. Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32FC1, new Scalar(2));
  1307. Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
  1308. kernelX.put(0, 0, 2, 2, 2);
  1309. Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
  1310. kernelY.put(0, 0, 1, 1, 1);
  1311. Imgproc.sepFilter2D(src, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS);
  1312. truth = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(36 + weakEPS));
  1313. assertMatEqual(truth, dst, EPS);
  1314. }
  1315. public void testSepFilter2DMatMatIntMatMatPointDoubleInt() {
  1316. Mat kernelX = new Mat(1, 3, CvType.CV_32FC1);
  1317. kernelX.put(0, 0, 2, 2, 2);
  1318. Mat kernelY = new Mat(1, 3, CvType.CV_32FC1);
  1319. kernelY.put(0, 0, 1, 1, 1);
  1320. Imgproc.sepFilter2D(gray0, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS, Imgproc.BORDER_REFLECT);
  1321. truth = new Mat(10, 10, CvType.CV_32F, new Scalar(weakEPS));
  1322. assertMatEqual(truth, dst, EPS);
  1323. // TODO_: write better test
  1324. }
  1325. public void testSobelMatMatIntIntInt() {
  1326. Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0);
  1327. assertMatEqual(gray0, dst);
  1328. }
  1329. public void testSobelMatMatIntIntIntIntDoubleDouble() {
  1330. Imgproc.Sobel(gray255, dst, CvType.CV_8U, 1, 0, 3, 2, 0.001);
  1331. assertMatEqual(gray0, dst);
  1332. // TODO_: write better test
  1333. }
  1334. public void testSobelMatMatIntIntIntIntDoubleDoubleInt() {
  1335. Mat src = new Mat(3, 3, CvType.CV_32F) {
  1336. {
  1337. put(0, 0, 2, 0, 1);
  1338. put(1, 0, 6, 4, 3);
  1339. put(2, 0, 1, 0, 2);
  1340. }
  1341. };
  1342. Imgproc.Sobel(src, dst, CvType.CV_32F, 1, 0, 3, 2, 0, Imgproc.BORDER_REPLICATE);
  1343. truth = new Mat(3, 3, CvType.CV_32F) {
  1344. {
  1345. put(0, 0, -16, -12, 4);
  1346. put(1, 0, -14, -12, 2);
  1347. put(2, 0, -10, 0, 10);
  1348. }
  1349. };
  1350. assertMatEqual(truth, dst, EPS);
  1351. }
  1352. public void testThreshold() {
  1353. Imgproc.threshold(makeMask(gray0.clone(), 10), dst, 5, 255, Imgproc.THRESH_TRUNC);
  1354. assertMatEqual(makeMask(gray0.clone(), 5), dst);
  1355. Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 1, 255, Imgproc.THRESH_BINARY);
  1356. assertMatEqual(gray255, dst);
  1357. Imgproc.threshold(makeMask(gray2.clone(), 10), dst, 3, 255, Imgproc.THRESH_BINARY_INV);
  1358. assertMatEqual(makeMask(gray255.clone(), 0), dst);
  1359. }
  1360. public void testUndistortMatMatMatMat() {
  1361. Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  1362. Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
  1363. {
  1364. put(0, 0, 1, 0, 1);
  1365. put(1, 0, 0, 1, 2);
  1366. put(2, 0, 0, 0, 1);
  1367. }
  1368. };
  1369. Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
  1370. {
  1371. put(0, 0, 1, 3, 2, 4);
  1372. }
  1373. };
  1374. Imgproc.undistort(src, dst, cameraMatrix, distCoeffs);
  1375. truth = new Mat(3, 3, CvType.CV_32F) {
  1376. {
  1377. put(0, 0, 0, 0, 0);
  1378. put(1, 0, 0, 0, 0);
  1379. put(2, 0, 0, 3, 0);
  1380. }
  1381. };
  1382. assertMatEqual(truth, dst, EPS);
  1383. }
  1384. public void testUndistortMatMatMatMatMat() {
  1385. Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  1386. Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
  1387. {
  1388. put(0, 0, 1, 0, 1);
  1389. put(1, 0, 0, 1, 2);
  1390. put(2, 0, 0, 0, 1);
  1391. }
  1392. };
  1393. Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
  1394. {
  1395. put(0, 0, 2, 1, 4, 5);
  1396. }
  1397. };
  1398. Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(1));
  1399. Imgproc.undistort(src, dst, cameraMatrix, distCoeffs, newCameraMatrix);
  1400. truth = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  1401. assertMatEqual(truth, dst, EPS);
  1402. }
  1403. //undistortPoints(List<Point> src, List<Point> dst, Mat cameraMatrix, Mat distCoeffs)
  1404. public void testUndistortPointsListOfPointListOfPointMatMat() {
  1405. MatOfPoint2f src = new MatOfPoint2f(new Point(1, 2), new Point(3, 4), new Point(-1, -1));
  1406. MatOfPoint2f dst = new MatOfPoint2f();
  1407. Mat cameraMatrix = Mat.eye(3, 3, CvType.CV_64FC1);
  1408. Mat distCoeffs = new Mat(8, 1, CvType.CV_64FC1, new Scalar(0));
  1409. Imgproc.undistortPoints(src, dst, cameraMatrix, distCoeffs);
  1410. assertEquals(src.size(), dst.size());
  1411. for(int i=0; i<src.toList().size(); i++) {
  1412. //Log.d("UndistortPoints", "s="+src.get(i)+", d="+dst.get(i));
  1413. assertTrue(src.toList().get(i).equals(dst.toList().get(i)));
  1414. }
  1415. }
  1416. public void testWarpAffineMatMatMatSize() {
  1417. Mat src = new Mat(3, 3, CvType.CV_32F) {
  1418. {
  1419. put(0, 0, 2, 0, 1);
  1420. put(1, 0, 6, 4, 3);
  1421. put(2, 0, 1, 0, 2);
  1422. }
  1423. };
  1424. Mat M = new Mat(2, 3, CvType.CV_32F) {
  1425. {
  1426. put(0, 0, 1, 0, 1);
  1427. put(1, 0, 0, 1, 1);
  1428. }
  1429. };
  1430. Imgproc.warpAffine(src, dst, M, new Size(3, 3));
  1431. truth = new Mat(3, 3, CvType.CV_32F) {
  1432. {
  1433. put(0, 0, 0, 0, 0);
  1434. put(1, 0, 0, 2, 0);
  1435. put(2, 0, 0, 6, 4);
  1436. }
  1437. };
  1438. assertMatEqual(truth, dst, EPS);
  1439. }
  1440. public void testWarpAffineMatMatMatSizeInt() {
  1441. Mat src = new Mat(3, 3, CvType.CV_32F) {
  1442. {
  1443. put(0, 0, 2, 4, 1);
  1444. put(1, 0, 6, 4, 3);
  1445. put(2, 0, 0, 2, 2);
  1446. }
  1447. };
  1448. Mat M = new Mat(2, 3, CvType.CV_32F) {
  1449. {
  1450. put(0, 0, 1, 0, 0);
  1451. put(1, 0, 0, 0, 1);
  1452. }
  1453. };
  1454. Imgproc.warpAffine(src, dst, M, new Size(2, 2), Imgproc.WARP_INVERSE_MAP);
  1455. truth = new Mat(2, 2, CvType.CV_32F) {
  1456. {
  1457. put(0, 0, 6, 4);
  1458. put(1, 0, 6, 4);
  1459. }
  1460. };
  1461. assertMatEqual(truth, dst, EPS);
  1462. }
  1463. public void testWarpAffineMatMatMatSizeIntInt() {
  1464. fail("Not yet implemented");
  1465. }
  1466. public void testWarpAffineMatMatMatSizeIntIntScalar() {
  1467. fail("Not yet implemented");
  1468. }
  1469. public void testWarpPerspectiveMatMatMatSize() {
  1470. Mat src = new Mat(3, 3, CvType.CV_32F) {
  1471. {
  1472. put(0, 0, 2, 4, 1);
  1473. put(1, 0, 0, 4, 5);
  1474. put(2, 0, 1, 2, 2);
  1475. }
  1476. };
  1477. Mat M = new Mat(3, 3, CvType.CV_32F) {
  1478. {
  1479. put(0, 0, 1, 0, 1);
  1480. put(1, 0, 0, 1, 1);
  1481. put(2, 0, 0, 0, 1);
  1482. }
  1483. };
  1484. Imgproc.warpPerspective(src, dst, M, new Size(3, 3));
  1485. truth = new Mat(3, 3, CvType.CV_32F) {
  1486. {
  1487. put(0, 0, 0, 0, 0);
  1488. put(1, 0, 0, 2, 4);
  1489. put(2, 0, 0, 0, 4);
  1490. }
  1491. };
  1492. assertMatEqual(truth, dst, EPS);
  1493. }
  1494. public void testWarpPerspectiveMatMatMatSizeInt() {
  1495. fail("Not yet implemented");
  1496. }
  1497. public void testWarpPerspectiveMatMatMatSizeIntInt() {
  1498. fail("Not yet implemented");
  1499. }
  1500. public void testWarpPerspectiveMatMatMatSizeIntIntScalar() {
  1501. fail("Not yet implemented");
  1502. }
  1503. public void testWatershed() {
  1504. Mat image = Mat.eye(4, 4, CvType.CV_8UC(3));
  1505. Mat markers = new Mat(4, 4, CvType.CV_32SC1, new Scalar(0));
  1506. Imgproc.watershed(image, markers);
  1507. truth = new Mat(4, 4, CvType.CV_32SC1) {
  1508. {
  1509. put(0, 0, -1, -1, -1, -1);
  1510. put(1, 0, -1, 0, 0, -1);
  1511. put(2, 0, -1, 0, 0, -1);
  1512. put(3, 0, -1, -1, -1, -1);
  1513. }
  1514. };
  1515. assertMatEqual(truth, markers);
  1516. }
  1517. }