Brief.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. var tracking = require('./utils/sandbox.js');
  3. module.exports = {
  4. setUp: function(done) {
  5. done();
  6. },
  7. tearDown: function(done) {
  8. done();
  9. },
  10. // TODO: Update this test to generate randomWindowOffsets_ and randomImageOffsets_ instead.
  11. testGetDescriptors: function(test) {
  12. var descriptors;
  13. var descriptorsPerKeypoint = tracking.Brief.N / 32;
  14. var grayScale = [
  15. 0, 0, 1, 0, 0, 0,
  16. 1, 9, 0, 9, 1, 0,
  17. 0, 1, 1, 1, 0, 0
  18. ];
  19. var repeat = [-7, 7, -6, 6, -5, 5, -1, 1];
  20. var width = 6;
  21. // Write the offsets manually, as we can't verify results that are obtained randomly.
  22. tracking.Brief.randomImageOffsets_[width] = [];
  23. for (var i = 0; i < tracking.Brief.N; i++) {
  24. var position = i % 4;
  25. tracking.Brief.randomImageOffsets_[width].push(repeat[position * 2], repeat[position * 2 + 1]);
  26. }
  27. descriptors = tracking.Brief.getDescriptors(grayScale, width, [1, 1, 3, 1]);
  28. test.equal(2 * descriptorsPerKeypoint, descriptors.length, 'There should be 8 descriptor words');
  29. for (var j = 0; j < descriptorsPerKeypoint; j++) {
  30. test.equal(858993459, descriptors[j], 'Descriptor should be 858993459');
  31. }
  32. for (var k = descriptorsPerKeypoint; k < 2 * descriptorsPerKeypoint; k++) {
  33. test.equal(-286331154, descriptors[k], 'Descriptor should be -286331154');
  34. }
  35. test.done();
  36. },
  37. testGetMatchings: function(test) {
  38. var descriptors1;
  39. var descriptors2;
  40. var grayScale1 = [
  41. 0, 0, 1, 0, 0, 0,
  42. 1, 9, 0, 9, 1, 0,
  43. 0, 1, 1, 1, 0, 0
  44. ];
  45. var grayScale2 = [
  46. 0, 0, 0, 1, 0, 0,
  47. 0, 1, 9, 0, 9, 1,
  48. 0, 0, 1, 1, 1, 0
  49. ];
  50. var keypoints1 = [1, 1, 3, 1];
  51. var keypoints2 = [4, 1, 2, 1];
  52. var matchings;
  53. var width = 6;
  54. descriptors1 = tracking.Brief.getDescriptors(grayScale1, width, keypoints1);
  55. descriptors2 = tracking.Brief.getDescriptors(grayScale2, width, keypoints2);
  56. matchings = tracking.Brief.match(keypoints1, descriptors1, keypoints2, descriptors2);
  57. test.equal(2, matchings.length, 'There should be 2 matchings');
  58. test.equal(1, matchings[0].index2, 'Keypoint 0 from 1st array should match keypoint 1 from the 2nd');
  59. test.equal(0, matchings[1].index2, 'Keypoint 1 from 1st array should match keypoint 0 from the 2nd');
  60. test.done();
  61. }
  62. };