Calib3dTest.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. package org.opencv.test.calib3d;
  2. import java.util.ArrayList;
  3. import org.opencv.calib3d.Calib3d;
  4. import org.opencv.core.Core;
  5. import org.opencv.core.CvType;
  6. import org.opencv.core.Mat;
  7. import org.opencv.core.MatOfDouble;
  8. import org.opencv.core.MatOfPoint2f;
  9. import org.opencv.core.MatOfPoint3f;
  10. import org.opencv.core.Point;
  11. import org.opencv.core.Scalar;
  12. import org.opencv.core.Size;
  13. import org.opencv.test.OpenCVTestCase;
  14. import org.opencv.imgproc.Imgproc;
  15. public class Calib3dTest extends OpenCVTestCase {
  16. Size size;
  17. @Override
  18. protected void setUp() throws Exception {
  19. super.setUp();
  20. size = new Size(3, 3);
  21. }
  22. public void testCalibrateCameraListOfMatListOfMatSizeMatMatListOfMatListOfMat() {
  23. fail("Not yet implemented");
  24. }
  25. public void testCalibrateCameraListOfMatListOfMatSizeMatMatListOfMatListOfMatInt() {
  26. fail("Not yet implemented");
  27. }
  28. public void testCalibrationMatrixValues() {
  29. fail("Not yet implemented");
  30. }
  31. public void testComposeRTMatMatMatMatMatMat() {
  32. Mat rvec1 = new Mat(3, 1, CvType.CV_32F);
  33. rvec1.put(0, 0, 0.5302828, 0.19925919, 0.40105945);
  34. Mat tvec1 = new Mat(3, 1, CvType.CV_32F);
  35. tvec1.put(0, 0, 0.81438506, 0.43713298, 0.2487897);
  36. Mat rvec2 = new Mat(3, 1, CvType.CV_32F);
  37. rvec2.put(0, 0, 0.77310503, 0.76209372, 0.30779448);
  38. Mat tvec2 = new Mat(3, 1, CvType.CV_32F);
  39. tvec2.put(0, 0, 0.70243168, 0.4784472, 0.79219002);
  40. Mat rvec3 = new Mat();
  41. Mat tvec3 = new Mat();
  42. Mat outRvec = new Mat(3, 1, CvType.CV_32F);
  43. outRvec.put(0, 0, 1.418641, 0.88665926, 0.56020796);
  44. Mat outTvec = new Mat(3, 1, CvType.CV_32F);
  45. outTvec.put(0, 0, 1.4560841, 1.0680628, 0.81598103);
  46. Calib3d.composeRT(rvec1, tvec1, rvec2, tvec2, rvec3, tvec3);
  47. assertMatEqual(outRvec, rvec3, EPS);
  48. assertMatEqual(outTvec, tvec3, EPS);
  49. }
  50. public void testComposeRTMatMatMatMatMatMatMat() {
  51. fail("Not yet implemented");
  52. }
  53. public void testComposeRTMatMatMatMatMatMatMatMat() {
  54. fail("Not yet implemented");
  55. }
  56. public void testComposeRTMatMatMatMatMatMatMatMatMat() {
  57. fail("Not yet implemented");
  58. }
  59. public void testComposeRTMatMatMatMatMatMatMatMatMatMat() {
  60. fail("Not yet implemented");
  61. }
  62. public void testComposeRTMatMatMatMatMatMatMatMatMatMatMat() {
  63. fail("Not yet implemented");
  64. }
  65. public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMat() {
  66. fail("Not yet implemented");
  67. }
  68. public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMatMat() {
  69. fail("Not yet implemented");
  70. }
  71. public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMatMatMat() {
  72. fail("Not yet implemented");
  73. // Mat dr3dr1;
  74. // Mat dr3dt1;
  75. // Mat dr3dr2;
  76. // Mat dr3dt2;
  77. // Mat dt3dr1;
  78. // Mat dt3dt1;
  79. // Mat dt3dr2;
  80. // Mat dt3dt2;
  81. // , dr3dr1, dr3dt1, dr3dr2, dr3dt2, dt3dr1, dt3dt1, dt3dr2, dt3dt2);
  82. // [0.97031879, -0.091774099, 0.38594806;
  83. // 0.15181915, 0.98091727, -0.44186208;
  84. // -0.39509675, 0.43839464, 0.93872648]
  85. // [0, 0, 0;
  86. // 0, 0, 0;
  87. // 0, 0, 0]
  88. // [1.0117353, 0.16348237, -0.083180845;
  89. // -0.1980398, 1.006078, 0.30299222;
  90. // 0.075766489, -0.32784501, 1.0163091]
  91. // [0, 0, 0;
  92. // 0, 0, 0;
  93. // 0, 0, 0]
  94. // [0, 0, 0;
  95. // 0, 0, 0;
  96. // 0, 0, 0]
  97. // [0.69658804, 0.018115902, 0.7172426;
  98. // 0.51114357, 0.68899536, -0.51382649;
  99. // -0.50348526, 0.72453934, 0.47068608]
  100. // [0.18536358, -0.20515044, -0.48834875;
  101. // -0.25120571, 0.29043972, 0.60573936;
  102. // 0.35370794, -0.69923931, 0.45781645]
  103. // [1, 0, 0;
  104. // 0, 1, 0;
  105. // 0, 0, 1]
  106. }
  107. public void testConvertPointsFromHomogeneous() {
  108. fail("Not yet implemented");
  109. }
  110. public void testConvertPointsToHomogeneous() {
  111. fail("Not yet implemented");
  112. }
  113. public void testDecomposeProjectionMatrixMatMatMatMat() {
  114. fail("Not yet implemented");
  115. }
  116. public void testDecomposeProjectionMatrixMatMatMatMatMat() {
  117. fail("Not yet implemented");
  118. }
  119. public void testDecomposeProjectionMatrixMatMatMatMatMatMat() {
  120. fail("Not yet implemented");
  121. }
  122. public void testDecomposeProjectionMatrixMatMatMatMatMatMatMat() {
  123. fail("Not yet implemented");
  124. }
  125. public void testDecomposeProjectionMatrixMatMatMatMatMatMatMatMat() {
  126. fail("Not yet implemented");
  127. }
  128. public void testDrawChessboardCorners() {
  129. fail("Not yet implemented");
  130. }
  131. public void testEstimateAffine3DMatMatMatMat() {
  132. fail("Not yet implemented");
  133. }
  134. public void testEstimateAffine3DMatMatMatMatDouble() {
  135. fail("Not yet implemented");
  136. }
  137. public void testEstimateAffine3DMatMatMatMatDoubleDouble() {
  138. fail("Not yet implemented");
  139. }
  140. public void testFilterSpecklesMatDoubleIntDouble() {
  141. gray_16s_1024.copyTo(dst);
  142. Point center = new Point(gray_16s_1024.rows() / 2., gray_16s_1024.cols() / 2.);
  143. Imgproc.circle(dst, center, 1, Scalar.all(4096));
  144. assertMatNotEqual(gray_16s_1024, dst);
  145. Calib3d.filterSpeckles(dst, 1024.0, 100, 0.);
  146. assertMatEqual(gray_16s_1024, dst);
  147. }
  148. public void testFilterSpecklesMatDoubleIntDoubleMat() {
  149. fail("Not yet implemented");
  150. }
  151. public void testFindChessboardCornersMatSizeMat() {
  152. Size patternSize = new Size(9, 6);
  153. MatOfPoint2f corners = new MatOfPoint2f();
  154. Calib3d.findChessboardCorners(grayChess, patternSize, corners);
  155. assertFalse(corners.empty());
  156. }
  157. public void testFindChessboardCornersMatSizeMatInt() {
  158. Size patternSize = new Size(9, 6);
  159. MatOfPoint2f corners = new MatOfPoint2f();
  160. Calib3d.findChessboardCorners(grayChess, patternSize, corners, Calib3d.CALIB_CB_ADAPTIVE_THRESH + Calib3d.CALIB_CB_NORMALIZE_IMAGE
  161. + Calib3d.CALIB_CB_FAST_CHECK);
  162. assertFalse(corners.empty());
  163. }
  164. public void testFind4QuadCornerSubpix() {
  165. Size patternSize = new Size(9, 6);
  166. MatOfPoint2f corners = new MatOfPoint2f();
  167. Size region_size = new Size(5, 5);
  168. Calib3d.findChessboardCorners(grayChess, patternSize, corners);
  169. Calib3d.find4QuadCornerSubpix(grayChess, corners, region_size);
  170. assertFalse(corners.empty());
  171. }
  172. public void testFindCirclesGridMatSizeMat() {
  173. int size = 300;
  174. Mat img = new Mat(size, size, CvType.CV_8U);
  175. img.setTo(new Scalar(255));
  176. Mat centers = new Mat();
  177. assertFalse(Calib3d.findCirclesGrid(img, new Size(5, 5), centers));
  178. for (int i = 0; i < 5; i++)
  179. for (int j = 0; j < 5; j++) {
  180. Point pt = new Point(size * (2 * i + 1) / 10, size * (2 * j + 1) / 10);
  181. Imgproc.circle(img, pt, 10, new Scalar(0), -1);
  182. }
  183. assertTrue(Calib3d.findCirclesGrid(img, new Size(5, 5), centers));
  184. assertEquals(25, centers.rows());
  185. assertEquals(1, centers.cols());
  186. assertEquals(CvType.CV_32FC2, centers.type());
  187. }
  188. public void testFindCirclesGridMatSizeMatInt() {
  189. int size = 300;
  190. Mat img = new Mat(size, size, CvType.CV_8U);
  191. img.setTo(new Scalar(255));
  192. Mat centers = new Mat();
  193. assertFalse(Calib3d.findCirclesGrid(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING
  194. | Calib3d.CALIB_CB_ASYMMETRIC_GRID));
  195. int step = size * 2 / 15;
  196. int offsetx = size / 6;
  197. int offsety = (size - 4 * step) / 2;
  198. for (int i = 0; i < 3; i++)
  199. for (int j = 0; j < 5; j++) {
  200. Point pt = new Point(offsetx + (2 * i + j % 2) * step, offsety + step * j);
  201. Imgproc.circle(img, pt, 10, new Scalar(0), -1);
  202. }
  203. assertTrue(Calib3d.findCirclesGrid(img, new Size(3, 5), centers, Calib3d.CALIB_CB_CLUSTERING
  204. | Calib3d.CALIB_CB_ASYMMETRIC_GRID));
  205. assertEquals(15, centers.rows());
  206. assertEquals(1, centers.cols());
  207. assertEquals(CvType.CV_32FC2, centers.type());
  208. }
  209. public void testFindFundamentalMatListOfPointListOfPoint() {
  210. fail("Not yet implemented");
  211. /*
  212. int minFundamentalMatPoints = 8;
  213. MatOfPoint2f pts = new MatOfPoint2f();
  214. pts.alloc(minFundamentalMatPoints);
  215. for (int i = 0; i < minFundamentalMatPoints; i++) {
  216. double x = Math.random() * 100 - 50;
  217. double y = Math.random() * 100 - 50;
  218. pts.put(i, 0, x, y); //add(new Point(x, y));
  219. }
  220. Mat fm = Calib3d.findFundamentalMat(pts, pts);
  221. truth = new Mat(3, 3, CvType.CV_64F);
  222. truth.put(0, 0, 0, -0.577, 0.288, 0.577, 0, 0.288, -0.288, -0.288, 0);
  223. assertMatEqual(truth, fm, EPS);
  224. */
  225. }
  226. public void testFindFundamentalMatListOfPointListOfPointInt() {
  227. fail("Not yet implemented");
  228. }
  229. public void testFindFundamentalMatListOfPointListOfPointIntDouble() {
  230. fail("Not yet implemented");
  231. }
  232. public void testFindFundamentalMatListOfPointListOfPointIntDoubleDouble() {
  233. fail("Not yet implemented");
  234. }
  235. public void testFindFundamentalMatListOfPointListOfPointIntDoubleDoubleMat() {
  236. fail("Not yet implemented");
  237. }
  238. public void testFindHomographyListOfPointListOfPoint() {
  239. final int NUM = 20;
  240. MatOfPoint2f originalPoints = new MatOfPoint2f();
  241. originalPoints.alloc(NUM);
  242. MatOfPoint2f transformedPoints = new MatOfPoint2f();
  243. transformedPoints.alloc(NUM);
  244. for (int i = 0; i < NUM; i++) {
  245. double x = Math.random() * 100 - 50;
  246. double y = Math.random() * 100 - 50;
  247. originalPoints.put(i, 0, x, y);
  248. transformedPoints.put(i, 0, y, x);
  249. }
  250. Mat hmg = Calib3d.findHomography(originalPoints, transformedPoints);
  251. truth = new Mat(3, 3, CvType.CV_64F);
  252. truth.put(0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1);
  253. assertMatEqual(truth, hmg, EPS);
  254. }
  255. public void testFindHomographyListOfPointListOfPointInt() {
  256. fail("Not yet implemented");
  257. }
  258. public void testFindHomographyListOfPointListOfPointIntDouble() {
  259. fail("Not yet implemented");
  260. }
  261. public void testFindHomographyListOfPointListOfPointIntDoubleMat() {
  262. fail("Not yet implemented");
  263. }
  264. public void testGetOptimalNewCameraMatrixMatMatSizeDouble() {
  265. fail("Not yet implemented");
  266. }
  267. public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSize() {
  268. fail("Not yet implemented");
  269. }
  270. public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSizeRect() {
  271. fail("Not yet implemented");
  272. }
  273. public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSizeRectBoolean() {
  274. fail("Not yet implemented");
  275. }
  276. public void testGetValidDisparityROI() {
  277. fail("Not yet implemented");
  278. }
  279. public void testInitCameraMatrix2DListOfMatListOfMatSize() {
  280. fail("Not yet implemented");
  281. }
  282. public void testInitCameraMatrix2DListOfMatListOfMatSizeDouble() {
  283. fail("Not yet implemented");
  284. }
  285. public void testMatMulDeriv() {
  286. fail("Not yet implemented");
  287. }
  288. public void testProjectPointsMatMatMatMatMatMat() {
  289. fail("Not yet implemented");
  290. }
  291. public void testProjectPointsMatMatMatMatMatMatMat() {
  292. fail("Not yet implemented");
  293. }
  294. public void testProjectPointsMatMatMatMatMatMatMatDouble() {
  295. fail("Not yet implemented");
  296. }
  297. public void testRectify3Collinear() {
  298. fail("Not yet implemented");
  299. }
  300. public void testReprojectImageTo3DMatMatMat() {
  301. Mat transformMatrix = new Mat(4, 4, CvType.CV_64F);
  302. transformMatrix.put(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  303. Mat disparity = new Mat(matSize, matSize, CvType.CV_32F);
  304. float[] disp = new float[matSize * matSize];
  305. for (int i = 0; i < matSize; i++)
  306. for (int j = 0; j < matSize; j++)
  307. disp[i * matSize + j] = i - j;
  308. disparity.put(0, 0, disp);
  309. Mat _3dPoints = new Mat();
  310. Calib3d.reprojectImageTo3D(disparity, _3dPoints, transformMatrix);
  311. assertEquals(CvType.CV_32FC3, _3dPoints.type());
  312. assertEquals(matSize, _3dPoints.rows());
  313. assertEquals(matSize, _3dPoints.cols());
  314. truth = new Mat(matSize, matSize, CvType.CV_32FC3);
  315. float[] _truth = new float[matSize * matSize * 3];
  316. for (int i = 0; i < matSize; i++)
  317. for (int j = 0; j < matSize; j++) {
  318. _truth[(i * matSize + j) * 3 + 0] = i;
  319. _truth[(i * matSize + j) * 3 + 1] = j;
  320. _truth[(i * matSize + j) * 3 + 2] = i - j;
  321. }
  322. truth.put(0, 0, _truth);
  323. assertMatEqual(truth, _3dPoints, EPS);
  324. }
  325. public void testReprojectImageTo3DMatMatMatBoolean() {
  326. Mat transformMatrix = new Mat(4, 4, CvType.CV_64F);
  327. transformMatrix.put(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  328. Mat disparity = new Mat(matSize, matSize, CvType.CV_32F);
  329. float[] disp = new float[matSize * matSize];
  330. for (int i = 0; i < matSize; i++)
  331. for (int j = 0; j < matSize; j++)
  332. disp[i * matSize + j] = i - j;
  333. disp[0] = -Float.MAX_VALUE;
  334. disparity.put(0, 0, disp);
  335. Mat _3dPoints = new Mat();
  336. Calib3d.reprojectImageTo3D(disparity, _3dPoints, transformMatrix, true);
  337. assertEquals(CvType.CV_32FC3, _3dPoints.type());
  338. assertEquals(matSize, _3dPoints.rows());
  339. assertEquals(matSize, _3dPoints.cols());
  340. truth = new Mat(matSize, matSize, CvType.CV_32FC3);
  341. float[] _truth = new float[matSize * matSize * 3];
  342. for (int i = 0; i < matSize; i++)
  343. for (int j = 0; j < matSize; j++) {
  344. _truth[(i * matSize + j) * 3 + 0] = i;
  345. _truth[(i * matSize + j) * 3 + 1] = j;
  346. _truth[(i * matSize + j) * 3 + 2] = i - j;
  347. }
  348. _truth[2] = 10000;
  349. truth.put(0, 0, _truth);
  350. assertMatEqual(truth, _3dPoints, EPS);
  351. }
  352. public void testReprojectImageTo3DMatMatMatBooleanInt() {
  353. Mat transformMatrix = new Mat(4, 4, CvType.CV_64F);
  354. transformMatrix.put(0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  355. Mat disparity = new Mat(matSize, matSize, CvType.CV_32F);
  356. float[] disp = new float[matSize * matSize];
  357. for (int i = 0; i < matSize; i++)
  358. for (int j = 0; j < matSize; j++)
  359. disp[i * matSize + j] = i - j;
  360. disparity.put(0, 0, disp);
  361. Mat _3dPoints = new Mat();
  362. Calib3d.reprojectImageTo3D(disparity, _3dPoints, transformMatrix, false, CvType.CV_16S);
  363. assertEquals(CvType.CV_16SC3, _3dPoints.type());
  364. assertEquals(matSize, _3dPoints.rows());
  365. assertEquals(matSize, _3dPoints.cols());
  366. truth = new Mat(matSize, matSize, CvType.CV_16SC3);
  367. short[] _truth = new short[matSize * matSize * 3];
  368. for (short i = 0; i < matSize; i++)
  369. for (short j = 0; j < matSize; j++) {
  370. _truth[(i * matSize + j) * 3 + 0] = i;
  371. _truth[(i * matSize + j) * 3 + 1] = j;
  372. _truth[(i * matSize + j) * 3 + 2] = (short) (i - j);
  373. }
  374. truth.put(0, 0, _truth);
  375. assertMatEqual(truth, _3dPoints, EPS);
  376. }
  377. public void testRodriguesMatMat() {
  378. Mat r = new Mat(3, 1, CvType.CV_32F);
  379. Mat R = new Mat(3, 3, CvType.CV_32F);
  380. r.put(0, 0, Math.PI, 0, 0);
  381. Calib3d.Rodrigues(r, R);
  382. truth = new Mat(3, 3, CvType.CV_32F);
  383. truth.put(0, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1);
  384. assertMatEqual(truth, R, EPS);
  385. Mat r2 = new Mat();
  386. Calib3d.Rodrigues(R, r2);
  387. assertMatEqual(r, r2, EPS);
  388. }
  389. public void testRodriguesMatMatMat() {
  390. fail("Not yet implemented");
  391. }
  392. public void testRQDecomp3x3MatMatMat() {
  393. fail("Not yet implemented");
  394. }
  395. public void testRQDecomp3x3MatMatMatMat() {
  396. fail("Not yet implemented");
  397. }
  398. public void testRQDecomp3x3MatMatMatMatMat() {
  399. fail("Not yet implemented");
  400. }
  401. public void testRQDecomp3x3MatMatMatMatMatMat() {
  402. fail("Not yet implemented");
  403. }
  404. public void testSolvePnPListOfPoint3ListOfPointMatMatMatMat() {
  405. Mat intrinsics = Mat.eye(3, 3, CvType.CV_64F);
  406. intrinsics.put(0, 0, 400);
  407. intrinsics.put(1, 1, 400);
  408. intrinsics.put(0, 2, 640 / 2);
  409. intrinsics.put(1, 2, 480 / 2);
  410. final int minPnpPointsNum = 4;
  411. MatOfPoint3f points3d = new MatOfPoint3f();
  412. points3d.alloc(minPnpPointsNum);
  413. MatOfPoint2f points2d = new MatOfPoint2f();
  414. points2d.alloc(minPnpPointsNum);
  415. for (int i = 0; i < minPnpPointsNum; i++) {
  416. double x = Math.random() * 100 - 50;
  417. double y = Math.random() * 100 - 50;
  418. points2d.put(i, 0, x, y); //add(new Point(x, y));
  419. points3d.put(i, 0, 0, y, x); // add(new Point3(0, y, x));
  420. }
  421. Mat rvec = new Mat();
  422. Mat tvec = new Mat();
  423. Calib3d.solvePnP(points3d, points2d, intrinsics, new MatOfDouble(), rvec, tvec);
  424. Mat truth_rvec = new Mat(3, 1, CvType.CV_64F);
  425. truth_rvec.put(0, 0, 0, Math.PI / 2, 0);
  426. Mat truth_tvec = new Mat(3, 1, CvType.CV_64F);
  427. truth_tvec.put(0, 0, -320, -240, 400);
  428. assertMatEqual(truth_rvec, rvec, EPS);
  429. assertMatEqual(truth_tvec, tvec, EPS);
  430. }
  431. public void testSolvePnPListOfPoint3ListOfPointMatMatMatMatBoolean() {
  432. fail("Not yet implemented");
  433. }
  434. public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMat() {
  435. fail("Not yet implemented");
  436. }
  437. public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBoolean() {
  438. fail("Not yet implemented");
  439. }
  440. public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanInt() {
  441. fail("Not yet implemented");
  442. }
  443. public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloat() {
  444. fail("Not yet implemented");
  445. }
  446. public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloatInt() {
  447. fail("Not yet implemented");
  448. }
  449. public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloatIntMat() {
  450. fail("Not yet implemented");
  451. }
  452. public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMat() {
  453. fail("Not yet implemented");
  454. }
  455. public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMatTermCriteria() {
  456. fail("Not yet implemented");
  457. }
  458. public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMatTermCriteriaInt() {
  459. fail("Not yet implemented");
  460. }
  461. public void testStereoRectifyUncalibratedMatMatMatSizeMatMat() {
  462. fail("Not yet implemented");
  463. }
  464. public void testStereoRectifyUncalibratedMatMatMatSizeMatMatDouble() {
  465. fail("Not yet implemented");
  466. }
  467. public void testValidateDisparityMatMatIntInt() {
  468. fail("Not yet implemented");
  469. }
  470. public void testValidateDisparityMatMatIntIntInt() {
  471. fail("Not yet implemented");
  472. }
  473. public void testComputeCorrespondEpilines()
  474. {
  475. Mat fundamental = new Mat(3, 3, CvType.CV_64F);
  476. fundamental.put(0, 0, 0, -0.577, 0.288, 0.577, 0, 0.288, -0.288, -0.288, 0);
  477. MatOfPoint2f left = new MatOfPoint2f();
  478. left.alloc(1);
  479. left.put(0, 0, 2, 3); //add(new Point(x, y));
  480. Mat lines = new Mat();
  481. Mat truth = new Mat(1, 1, CvType.CV_32FC3);
  482. truth.put(0, 0, -0.70735186, 0.70686162, -0.70588124);
  483. Calib3d.computeCorrespondEpilines(left, 1, fundamental, lines);
  484. assertMatEqual(truth, lines, EPS);
  485. }
  486. public void testConstants()
  487. {
  488. // calib3d.hpp: some constants have conflict with constants from 'fisheye' namespace
  489. assertEquals(1, Calib3d.CALIB_USE_INTRINSIC_GUESS);
  490. assertEquals(2, Calib3d.CALIB_FIX_ASPECT_RATIO);
  491. assertEquals(4, Calib3d.CALIB_FIX_PRINCIPAL_POINT);
  492. assertEquals(8, Calib3d.CALIB_ZERO_TANGENT_DIST);
  493. assertEquals(16, Calib3d.CALIB_FIX_FOCAL_LENGTH);
  494. assertEquals(32, Calib3d.CALIB_FIX_K1);
  495. assertEquals(64, Calib3d.CALIB_FIX_K2);
  496. assertEquals(128, Calib3d.CALIB_FIX_K3);
  497. assertEquals(0x0800, Calib3d.CALIB_FIX_K4);
  498. assertEquals(0x1000, Calib3d.CALIB_FIX_K5);
  499. assertEquals(0x2000, Calib3d.CALIB_FIX_K6);
  500. assertEquals(0x4000, Calib3d.CALIB_RATIONAL_MODEL);
  501. assertEquals(0x8000, Calib3d.CALIB_THIN_PRISM_MODEL);
  502. assertEquals(0x10000, Calib3d.CALIB_FIX_S1_S2_S3_S4);
  503. assertEquals(0x40000, Calib3d.CALIB_TILTED_MODEL);
  504. assertEquals(0x80000, Calib3d.CALIB_FIX_TAUX_TAUY);
  505. assertEquals(0x100000, Calib3d.CALIB_USE_QR);
  506. assertEquals(0x200000, Calib3d.CALIB_FIX_TANGENT_DIST);
  507. assertEquals(0x100, Calib3d.CALIB_FIX_INTRINSIC);
  508. assertEquals(0x200, Calib3d.CALIB_SAME_FOCAL_LENGTH);
  509. assertEquals(0x400, Calib3d.CALIB_ZERO_DISPARITY);
  510. assertEquals((1 << 17), Calib3d.CALIB_USE_LU);
  511. assertEquals((1 << 22), Calib3d.CALIB_USE_EXTRINSIC_GUESS);
  512. }
  513. public void testSolvePnPGeneric_regression_16040() {
  514. Mat intrinsics = Mat.eye(3, 3, CvType.CV_64F);
  515. intrinsics.put(0, 0, 400);
  516. intrinsics.put(1, 1, 400);
  517. intrinsics.put(0, 2, 640 / 2);
  518. intrinsics.put(1, 2, 480 / 2);
  519. final int minPnpPointsNum = 4;
  520. MatOfPoint3f points3d = new MatOfPoint3f();
  521. points3d.alloc(minPnpPointsNum);
  522. MatOfPoint2f points2d = new MatOfPoint2f();
  523. points2d.alloc(minPnpPointsNum);
  524. for (int i = 0; i < minPnpPointsNum; i++) {
  525. double x = Math.random() * 100 - 50;
  526. double y = Math.random() * 100 - 50;
  527. points2d.put(i, 0, x, y); //add(new Point(x, y));
  528. points3d.put(i, 0, 0, y, x); // add(new Point3(0, y, x));
  529. }
  530. ArrayList<Mat> rvecs = new ArrayList<Mat>();
  531. ArrayList<Mat> tvecs = new ArrayList<Mat>();
  532. Mat rvec = new Mat();
  533. Mat tvec = new Mat();
  534. Mat reprojectionError = new Mat(2, 1, CvType.CV_64FC1);
  535. Calib3d.solvePnPGeneric(points3d, points2d, intrinsics, new MatOfDouble(), rvecs, tvecs, false, Calib3d.SOLVEPNP_IPPE, rvec, tvec, reprojectionError);
  536. Mat truth_rvec = new Mat(3, 1, CvType.CV_64F);
  537. truth_rvec.put(0, 0, 0, Math.PI / 2, 0);
  538. Mat truth_tvec = new Mat(3, 1, CvType.CV_64F);
  539. truth_tvec.put(0, 0, -320, -240, 400);
  540. assertMatEqual(truth_rvec, rvecs.get(0), 10 * EPS);
  541. assertMatEqual(truth_tvec, tvecs.get(0), 1000 * EPS);
  542. }
  543. public void testGetDefaultNewCameraMatrixMat() {
  544. Mat mtx = Calib3d.getDefaultNewCameraMatrix(gray0);
  545. assertFalse(mtx.empty());
  546. assertEquals(0, Core.countNonZero(mtx));
  547. }
  548. public void testGetDefaultNewCameraMatrixMatSizeBoolean() {
  549. Mat mtx = Calib3d.getDefaultNewCameraMatrix(gray0, size, true);
  550. assertFalse(mtx.empty());
  551. assertFalse(0 == Core.countNonZero(mtx));
  552. // TODO_: write better test
  553. }
  554. public void testInitUndistortRectifyMap() {
  555. fail("Not yet implemented");
  556. Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
  557. cameraMatrix.put(0, 0, 1, 0, 1);
  558. cameraMatrix.put(1, 0, 0, 1, 1);
  559. cameraMatrix.put(2, 0, 0, 0, 1);
  560. Mat R = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
  561. Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  562. Mat distCoeffs = new Mat();
  563. Mat map1 = new Mat();
  564. Mat map2 = new Mat();
  565. // TODO: complete this test
  566. Calib3d.initUndistortRectifyMap(cameraMatrix, distCoeffs, R, newCameraMatrix, size, CvType.CV_32F, map1, map2);
  567. }
  568. public void testInitWideAngleProjMapMatMatSizeIntIntMatMat() {
  569. fail("Not yet implemented");
  570. Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
  571. Mat distCoeffs = new Mat(1, 4, CvType.CV_32F);
  572. // Size imageSize = new Size(2, 2);
  573. cameraMatrix.put(0, 0, 1, 0, 1);
  574. cameraMatrix.put(1, 0, 0, 1, 2);
  575. cameraMatrix.put(2, 0, 0, 0, 1);
  576. distCoeffs.put(0, 0, 1, 3, 2, 4);
  577. truth = new Mat(3, 3, CvType.CV_32F);
  578. truth.put(0, 0, 0, 0, 0);
  579. truth.put(1, 0, 0, 0, 0);
  580. truth.put(2, 0, 0, 3, 0);
  581. // TODO: No documentation for this function
  582. // Calib3d.initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize,
  583. // 5, m1type, truthput1, truthput2);
  584. }
  585. public void testInitWideAngleProjMapMatMatSizeIntIntMatMatInt() {
  586. fail("Not yet implemented");
  587. }
  588. public void testInitWideAngleProjMapMatMatSizeIntIntMatMatIntDouble() {
  589. fail("Not yet implemented");
  590. }
  591. public void testUndistortMatMatMatMat() {
  592. Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  593. Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
  594. {
  595. put(0, 0, 1, 0, 1);
  596. put(1, 0, 0, 1, 2);
  597. put(2, 0, 0, 0, 1);
  598. }
  599. };
  600. Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
  601. {
  602. put(0, 0, 1, 3, 2, 4);
  603. }
  604. };
  605. Calib3d.undistort(src, dst, cameraMatrix, distCoeffs);
  606. truth = new Mat(3, 3, CvType.CV_32F) {
  607. {
  608. put(0, 0, 0, 0, 0);
  609. put(1, 0, 0, 0, 0);
  610. put(2, 0, 0, 3, 0);
  611. }
  612. };
  613. assertMatEqual(truth, dst, EPS);
  614. }
  615. public void testUndistortMatMatMatMatMat() {
  616. Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  617. Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
  618. {
  619. put(0, 0, 1, 0, 1);
  620. put(1, 0, 0, 1, 2);
  621. put(2, 0, 0, 0, 1);
  622. }
  623. };
  624. Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
  625. {
  626. put(0, 0, 2, 1, 4, 5);
  627. }
  628. };
  629. Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(1));
  630. Calib3d.undistort(src, dst, cameraMatrix, distCoeffs, newCameraMatrix);
  631. truth = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
  632. assertMatEqual(truth, dst, EPS);
  633. }
  634. //undistortPoints(List<Point> src, List<Point> dst, Mat cameraMatrix, Mat distCoeffs)
  635. public void testUndistortPointsListOfPointListOfPointMatMat() {
  636. MatOfPoint2f src = new MatOfPoint2f(new Point(1, 2), new Point(3, 4), new Point(-1, -1));
  637. MatOfPoint2f dst = new MatOfPoint2f();
  638. Mat cameraMatrix = Mat.eye(3, 3, CvType.CV_64FC1);
  639. Mat distCoeffs = new Mat(8, 1, CvType.CV_64FC1, new Scalar(0));
  640. Calib3d.undistortPoints(src, dst, cameraMatrix, distCoeffs);
  641. assertEquals(src.size(), dst.size());
  642. for(int i=0; i<src.toList().size(); i++) {
  643. //Log.d("UndistortPoints", "s="+src.get(i)+", d="+dst.get(i));
  644. assertTrue(src.toList().get(i).equals(dst.toList().get(i)));
  645. }
  646. }
  647. public void testEstimateNewCameraMatrixForUndistortRectify() {
  648. Mat K = new Mat().eye(3, 3, CvType.CV_64FC1);
  649. Mat K_new = new Mat().eye(3, 3, CvType.CV_64FC1);
  650. Mat K_new_truth = new Mat().eye(3, 3, CvType.CV_64FC1);
  651. Mat D = new Mat().zeros(4, 1, CvType.CV_64FC1);
  652. K.put(0,0,600.4447738238429);
  653. K.put(1,1,578.9929805505851);
  654. K.put(0,2,992.0642578801213);
  655. K.put(1,2,549.2682624212172);
  656. D.put(0,0,-0.05090103223466704);
  657. D.put(1,0,0.030944413642173308);
  658. D.put(2,0,-0.021509225493198905);
  659. D.put(3,0,0.0043378096628297145);
  660. K_new_truth.put(0,0, 387.4809086880343);
  661. K_new_truth.put(0,2, 1036.669802754649);
  662. K_new_truth.put(1,1, 373.6375700303157);
  663. K_new_truth.put(1,2, 538.8373261247601);
  664. Calib3d.fisheye_estimateNewCameraMatrixForUndistortRectify(K,D,new Size(1920,1080),
  665. new Mat().eye(3, 3, CvType.CV_64F), K_new, 0.0, new Size(1920,1080));
  666. assertMatEqual(K_new, K_new_truth, EPS);
  667. }
  668. }