test_calib3d.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. QUnit.module('Camera Calibration and 3D Reconstruction', {});
  5. QUnit.test('constants', function(assert) {
  6. assert.strictEqual(typeof cv.LMEDS, 'number');
  7. assert.strictEqual(typeof cv.RANSAC, 'number');
  8. assert.strictEqual(typeof cv.RHO, 'number');
  9. });
  10. QUnit.test('findHomography', function(assert) {
  11. let srcPoints = cv.matFromArray(4, 1, cv.CV_32FC2, [
  12. 56,
  13. 65,
  14. 368,
  15. 52,
  16. 28,
  17. 387,
  18. 389,
  19. 390,
  20. ]);
  21. let dstPoints = cv.matFromArray(4, 1, cv.CV_32FC2, [
  22. 0,
  23. 0,
  24. 300,
  25. 0,
  26. 0,
  27. 300,
  28. 300,
  29. 300,
  30. ]);
  31. const mat = cv.findHomography(srcPoints, dstPoints);
  32. assert.ok(mat instanceof cv.Mat);
  33. });
  34. QUnit.test('Rodrigues', function(assert) {
  35. // Converts a rotation matrix to a rotation vector and vice versa
  36. // data64F is the output array
  37. const rvec0 = cv.matFromArray(1, 3, cv.CV_64F, [1,1,1]);
  38. let rMat0 = new cv.Mat();
  39. let rvec1 = new cv.Mat();
  40. // Args: input Mat, output Mat. The function mutates the output Mat, so the function does not return anything.
  41. // cv.Rodrigues (InputArray=src, OutputArray=dst, jacobian=0)
  42. // https://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#void%20Rodrigues(InputArray%20src,%20OutputArray%20dst,%20OutputArray%20jacobian)
  43. // vec to Mat, starting number is 3 long and each element is 1.
  44. cv.Rodrigues(rvec0, rMat0);
  45. assert.ok(rMat0.data64F.length == 9);
  46. assert.ok(0.23 > rMat0.data64F[0] > 0.22);
  47. // convert Mat to Vec, should be same as what we started with, 3 long and each item should be a 1.
  48. cv.Rodrigues(rMat0, rvec1);
  49. assert.ok(rvec1.data64F.length == 3);
  50. assert.ok(1.01 > rvec1.data64F[0] > 0.9);
  51. // Answer should be around 1: 0.9999999999999999
  52. });
  53. QUnit.test('estimateAffine2D', function(assert) {
  54. const inputs = cv.matFromArray(4, 1, cv.CV_32FC2, [
  55. 1, 1,
  56. 80, 0,
  57. 0, 80,
  58. 80, 80
  59. ]);
  60. const outputs = cv.matFromArray(4, 1, cv.CV_32FC2, [
  61. 21, 51,
  62. 70, 77,
  63. 40, 40,
  64. 10, 70
  65. ]);
  66. const M = cv.estimateAffine2D(inputs, outputs);
  67. assert.ok(M instanceof cv.Mat);
  68. assert.deepEqual(Array.from(M.data), [
  69. 23, 55, 97, 126, 87, 139, 227, 63, 0, 0,
  70. 0, 0, 0, 0, 232, 191, 71, 246, 12, 68,
  71. 165, 35, 53, 64, 99, 56, 27, 66, 14, 254,
  72. 212, 63, 103, 102, 102, 102, 102, 102, 182, 191,
  73. 195, 252, 174, 22, 55, 97, 73, 64
  74. ]);
  75. });