@srsergio/taptapp-ar 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/compiler/controller.d.ts +15 -22
  2. package/dist/compiler/controller.js +73 -92
  3. package/dist/compiler/detector/crop-detector.d.ts +20 -51
  4. package/dist/compiler/detector/crop-detector.js +21 -15
  5. package/dist/compiler/input-loader.d.ts +15 -17
  6. package/dist/compiler/input-loader.js +58 -76
  7. package/dist/compiler/matching/hamming-distance.js +4 -4
  8. package/dist/compiler/matching/matcher.js +2 -2
  9. package/dist/compiler/matching/matching.d.ts +2 -16
  10. package/dist/compiler/matching/matching.js +72 -60
  11. package/dist/compiler/offline-compiler.d.ts +9 -29
  12. package/dist/compiler/offline-compiler.js +38 -72
  13. package/dist/compiler/three.js +0 -4
  14. package/dist/compiler/tracker/tracker.d.ts +26 -12
  15. package/dist/compiler/tracker/tracker.js +158 -259
  16. package/package.json +1 -1
  17. package/src/compiler/controller.js +71 -93
  18. package/src/compiler/detector/crop-detector.js +26 -15
  19. package/src/compiler/input-loader.js +62 -88
  20. package/src/compiler/matching/hamming-distance.js +4 -4
  21. package/src/compiler/matching/hough.js +1 -1
  22. package/src/compiler/matching/matcher.js +2 -2
  23. package/src/compiler/matching/matching.js +80 -72
  24. package/src/compiler/offline-compiler.js +38 -75
  25. package/src/compiler/three.js +0 -4
  26. package/src/compiler/tracker/tracker.js +183 -283
  27. package/dist/compiler/compiler-base.d.ts +0 -8
  28. package/dist/compiler/compiler-base.js +0 -179
  29. package/dist/compiler/compiler.d.ts +0 -9
  30. package/dist/compiler/compiler.js +0 -24
  31. package/dist/compiler/compiler.worker.d.ts +0 -1
  32. package/dist/compiler/compiler.worker.js +0 -28
  33. package/dist/compiler/detector/detector.d.ts +0 -97
  34. package/dist/compiler/detector/detector.js +0 -1042
  35. package/dist/compiler/detector/kernels/cpu/binomialFilter.d.ts +0 -6
  36. package/dist/compiler/detector/kernels/cpu/binomialFilter.js +0 -50
  37. package/dist/compiler/detector/kernels/cpu/buildExtremas.d.ts +0 -6
  38. package/dist/compiler/detector/kernels/cpu/buildExtremas.js +0 -89
  39. package/dist/compiler/detector/kernels/cpu/computeExtremaAngles.d.ts +0 -7
  40. package/dist/compiler/detector/kernels/cpu/computeExtremaAngles.js +0 -79
  41. package/dist/compiler/detector/kernels/cpu/computeExtremaFreak.d.ts +0 -6
  42. package/dist/compiler/detector/kernels/cpu/computeExtremaFreak.js +0 -68
  43. package/dist/compiler/detector/kernels/cpu/computeFreakDescriptors.d.ts +0 -6
  44. package/dist/compiler/detector/kernels/cpu/computeFreakDescriptors.js +0 -57
  45. package/dist/compiler/detector/kernels/cpu/computeLocalization.d.ts +0 -6
  46. package/dist/compiler/detector/kernels/cpu/computeLocalization.js +0 -50
  47. package/dist/compiler/detector/kernels/cpu/computeOrientationHistograms.d.ts +0 -6
  48. package/dist/compiler/detector/kernels/cpu/computeOrientationHistograms.js +0 -100
  49. package/dist/compiler/detector/kernels/cpu/downsampleBilinear.d.ts +0 -6
  50. package/dist/compiler/detector/kernels/cpu/downsampleBilinear.js +0 -29
  51. package/dist/compiler/detector/kernels/cpu/extremaReduction.d.ts +0 -6
  52. package/dist/compiler/detector/kernels/cpu/extremaReduction.js +0 -50
  53. package/dist/compiler/detector/kernels/cpu/fakeShader.d.ts +0 -20
  54. package/dist/compiler/detector/kernels/cpu/fakeShader.js +0 -80
  55. package/dist/compiler/detector/kernels/cpu/index.d.ts +0 -1
  56. package/dist/compiler/detector/kernels/cpu/index.js +0 -25
  57. package/dist/compiler/detector/kernels/cpu/prune.d.ts +0 -7
  58. package/dist/compiler/detector/kernels/cpu/prune.js +0 -62
  59. package/dist/compiler/detector/kernels/cpu/smoothHistograms.d.ts +0 -6
  60. package/dist/compiler/detector/kernels/cpu/smoothHistograms.js +0 -47
  61. package/dist/compiler/detector/kernels/cpu/upsampleBilinear.d.ts +0 -6
  62. package/dist/compiler/detector/kernels/cpu/upsampleBilinear.js +0 -43
  63. package/dist/compiler/detector/kernels/index.d.ts +0 -1
  64. package/dist/compiler/detector/kernels/index.js +0 -2
  65. package/dist/compiler/detector/kernels/webgl/binomialFilter.d.ts +0 -6
  66. package/dist/compiler/detector/kernels/webgl/binomialFilter.js +0 -67
  67. package/dist/compiler/detector/kernels/webgl/buildExtremas.d.ts +0 -6
  68. package/dist/compiler/detector/kernels/webgl/buildExtremas.js +0 -101
  69. package/dist/compiler/detector/kernels/webgl/computeExtremaAngles.d.ts +0 -6
  70. package/dist/compiler/detector/kernels/webgl/computeExtremaAngles.js +0 -78
  71. package/dist/compiler/detector/kernels/webgl/computeExtremaFreak.d.ts +0 -6
  72. package/dist/compiler/detector/kernels/webgl/computeExtremaFreak.js +0 -86
  73. package/dist/compiler/detector/kernels/webgl/computeFreakDescriptors.d.ts +0 -6
  74. package/dist/compiler/detector/kernels/webgl/computeFreakDescriptors.js +0 -52
  75. package/dist/compiler/detector/kernels/webgl/computeLocalization.d.ts +0 -6
  76. package/dist/compiler/detector/kernels/webgl/computeLocalization.js +0 -58
  77. package/dist/compiler/detector/kernels/webgl/computeOrientationHistograms.d.ts +0 -6
  78. package/dist/compiler/detector/kernels/webgl/computeOrientationHistograms.js +0 -116
  79. package/dist/compiler/detector/kernels/webgl/downsampleBilinear.d.ts +0 -6
  80. package/dist/compiler/detector/kernels/webgl/downsampleBilinear.js +0 -46
  81. package/dist/compiler/detector/kernels/webgl/extremaReduction.d.ts +0 -6
  82. package/dist/compiler/detector/kernels/webgl/extremaReduction.js +0 -48
  83. package/dist/compiler/detector/kernels/webgl/index.d.ts +0 -1
  84. package/dist/compiler/detector/kernels/webgl/index.js +0 -25
  85. package/dist/compiler/detector/kernels/webgl/smoothHistograms.d.ts +0 -6
  86. package/dist/compiler/detector/kernels/webgl/smoothHistograms.js +0 -49
  87. package/dist/compiler/detector/kernels/webgl/upsampleBilinear.d.ts +0 -6
  88. package/dist/compiler/detector/kernels/webgl/upsampleBilinear.js +0 -56
  89. package/dist/compiler/tensorflow-setup.d.ts +0 -6
  90. package/dist/compiler/tensorflow-setup.js +0 -99
  91. package/src/compiler/compiler-base.js +0 -210
  92. package/src/compiler/compiler.js +0 -25
  93. package/src/compiler/compiler.worker.js +0 -30
  94. package/src/compiler/detector/detector.js +0 -1119
  95. package/src/compiler/detector/kernels/cpu/binomialFilter.js +0 -58
  96. package/src/compiler/detector/kernels/cpu/buildExtremas.js +0 -108
  97. package/src/compiler/detector/kernels/cpu/computeExtremaAngles.js +0 -91
  98. package/src/compiler/detector/kernels/cpu/computeExtremaFreak.js +0 -92
  99. package/src/compiler/detector/kernels/cpu/computeFreakDescriptors.js +0 -68
  100. package/src/compiler/detector/kernels/cpu/computeLocalization.js +0 -67
  101. package/src/compiler/detector/kernels/cpu/computeOrientationHistograms.js +0 -124
  102. package/src/compiler/detector/kernels/cpu/downsampleBilinear.js +0 -33
  103. package/src/compiler/detector/kernels/cpu/extremaReduction.js +0 -53
  104. package/src/compiler/detector/kernels/cpu/fakeShader.js +0 -88
  105. package/src/compiler/detector/kernels/cpu/index.js +0 -26
  106. package/src/compiler/detector/kernels/cpu/prune.js +0 -78
  107. package/src/compiler/detector/kernels/cpu/smoothHistograms.js +0 -57
  108. package/src/compiler/detector/kernels/cpu/upsampleBilinear.js +0 -51
  109. package/src/compiler/detector/kernels/index.js +0 -2
  110. package/src/compiler/detector/kernels/webgl/binomialFilter.js +0 -72
  111. package/src/compiler/detector/kernels/webgl/buildExtremas.js +0 -109
  112. package/src/compiler/detector/kernels/webgl/computeExtremaAngles.js +0 -82
  113. package/src/compiler/detector/kernels/webgl/computeExtremaFreak.js +0 -105
  114. package/src/compiler/detector/kernels/webgl/computeFreakDescriptors.js +0 -56
  115. package/src/compiler/detector/kernels/webgl/computeLocalization.js +0 -70
  116. package/src/compiler/detector/kernels/webgl/computeOrientationHistograms.js +0 -129
  117. package/src/compiler/detector/kernels/webgl/downsampleBilinear.js +0 -50
  118. package/src/compiler/detector/kernels/webgl/extremaReduction.js +0 -50
  119. package/src/compiler/detector/kernels/webgl/index.js +0 -26
  120. package/src/compiler/detector/kernels/webgl/smoothHistograms.js +0 -53
  121. package/src/compiler/detector/kernels/webgl/upsampleBilinear.js +0 -62
  122. package/src/compiler/tensorflow-setup.js +0 -116
@@ -1,80 +0,0 @@
1
- import { zeros, map, flatten as mathjsflatten } from "mathjs";
2
- /**
3
- * @typedef {Object} Kernel
4
- * @property {string[]} variableNames
5
- * @property {number[]} outputShape
6
- * @property {Function} userCode
7
- */
8
- /**
9
- *
10
- * @param {MathBackendCPU} backend
11
- * @param {Kernel} kernel
12
- * @param {Array<.TensorInfo>} inputs
13
- * @param {DataType} dtype
14
- * @returns {Tensor}
15
- */
16
- function runCode(backend, kernel, inputs, dtype) {
17
- const inputData = inputs.map((value) => {
18
- return backend.data.get(value.dataId).values;
19
- });
20
- //create getter functions for every variable name, clamping the input.
21
- const tempData = {};
22
- kernel.variableNames.forEach((name, index) => {
23
- const funName = `get${capFirstLetter(name)}`;
24
- //console.log("Making function:",funName,inputs[index].shape);
25
- tempData[funName] = function (...args) {
26
- const inputIndex = index;
27
- for (let i = 0; i < args.length; i++) {
28
- args[i] = clampInt(args[i], 0, inputs[inputIndex].shape[i]);
29
- }
30
- return inputData[index][flatten(args, inputs[inputIndex].shape)];
31
- };
32
- });
33
- tempData.int = Math.trunc;
34
- tempData.atan = Math.atan2;
35
- //create an empty matrix to map the output size, because i'm lazy and want to use Matrix.map(...)
36
- //const temp = new Matrix();
37
- //console.log("Creating output shape:",kernel.outputShape);
38
- const temp = zeros(kernel.outputShape); //reshape([0,0,0],kernel.outputShape);
39
- const output = map(temp, (_value, index) => {
40
- tempData.getOutputCoords = () => {
41
- return index;
42
- };
43
- let out;
44
- tempData.setOutput = (newValue) => {
45
- out = Number.isNaN(newValue) ? 0 : Math.fround(newValue);
46
- };
47
- //bind the method calls and run the code
48
- kernel.userCode.bind(tempData)();
49
- return out;
50
- });
51
- //output.flat()
52
- //convert the output from a matrix into a tensor
53
- return backend.makeOutput(mathjsflatten(output), kernel.outputShape, dtype);
54
- }
55
- /**
56
- *
57
- * @param {string} word
58
- * @returns
59
- */
60
- function capFirstLetter(word) {
61
- return word[0].toUpperCase() + word.substring(1);
62
- }
63
- function clampInt(n, min, max) {
64
- return Math.min(Math.max(n, min), max - 1);
65
- }
66
- /**
67
- *
68
- * @param {number[]} input
69
- * @param {number[]} max
70
- * @returns
71
- */
72
- function flatten(input, max) {
73
- return input.reduce((prev, current, index) => {
74
- for (let i = index + 1; i < max.length; i++) {
75
- current *= max[i];
76
- }
77
- return prev + current;
78
- }, 0);
79
- }
80
- export { runCode };
@@ -1 +0,0 @@
1
- export {};
@@ -1,25 +0,0 @@
1
- import { registerKernel } from "@tensorflow/tfjs";
2
- import { binomialFilterConfig } from "./binomialFilter.js";
3
- import { buildExtremasConfig } from "./buildExtremas.js";
4
- import { computeExtremaAnglesConfig } from "./computeExtremaAngles.js";
5
- import { computeExtremaFreakConfig } from "./computeExtremaFreak.js";
6
- import { computeFreakDescriptorConfig } from "./computeFreakDescriptors.js";
7
- import { computeLocalizationConfig } from "./computeLocalization.js";
8
- import { computeOrientationHistogramsConfig } from "./computeOrientationHistograms.js";
9
- import { downsampleBilinearConfig } from "./downsampleBilinear.js";
10
- import { extremaReductionConfig } from "./extremaReduction.js";
11
- import { smoothHistogramsConfig } from "./smoothHistograms.js";
12
- import { upsampleBilinearConfig } from "./upsampleBilinear.js";
13
- //export function Register(){
14
- registerKernel(binomialFilterConfig);
15
- registerKernel(buildExtremasConfig);
16
- registerKernel(computeExtremaAnglesConfig);
17
- registerKernel(computeExtremaFreakConfig);
18
- registerKernel(computeFreakDescriptorConfig);
19
- registerKernel(computeLocalizationConfig);
20
- registerKernel(computeOrientationHistogramsConfig);
21
- registerKernel(downsampleBilinearConfig);
22
- registerKernel(extremaReductionConfig);
23
- registerKernel(smoothHistogramsConfig);
24
- registerKernel(upsampleBilinearConfig);
25
- //}
@@ -1,7 +0,0 @@
1
- export namespace pruneConfig {
2
- export let kernelName: string;
3
- export let backendName: string;
4
- export { prune as kernelFunc };
5
- }
6
- export function prune(args: any): any;
7
- export function pruneImpl(vals: any, width: any, height: any): Float32Array<ArrayBuffer>;
@@ -1,62 +0,0 @@
1
- function clamp(n, min, max) {
2
- return Math.min(Math.max(min, n), max - 1);
3
- }
4
- const pruneImpl = (vals, width, height) => {
5
- const w = Math.floor(width / 2);
6
- const h = Math.floor(height / 2);
7
- const resultValues = new Float32Array(w * h);
8
- function getExtrema(x, y) {
9
- x = clamp(x, 0, width);
10
- y = clamp(y, 0, height);
11
- return vals[y * width + x];
12
- }
13
- function setOutput(x, y, o) {
14
- resultValues[y * width + x] = o;
15
- }
16
- for (let x = 0; x < w; x++) {
17
- for (let y = 0; y < h; y++) {
18
- const x2 = x * 2;
19
- const y2 = y * 2;
20
- let location = 0.0;
21
- let values = getExtrema(x2, y2);
22
- if (getExtrema(x2, y2 + 1) != 0.0) {
23
- location = 1.0;
24
- values = getExtrema(x2, y2 + 1);
25
- }
26
- else if (getExtrema(x2 + 1, y2) != 0.0) {
27
- location = 2.0;
28
- values = getExtrema(x2 + 1, y2);
29
- }
30
- else if (getExtrema(x2 + 1, y2 + 1) != 0.0) {
31
- location = 3.0;
32
- values = getExtrema(x2 + 1, y2 + 1);
33
- }
34
- if (values < 0.0) {
35
- setOutput(x, y, location * -1000.0 + values);
36
- }
37
- else {
38
- setOutput(x, y, location * 1000.0 + values);
39
- }
40
- }
41
- }
42
- return resultValues;
43
- };
44
- const prune = (args) => {
45
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
46
- const x = args.inputs.x;
47
- /** @type {MathBackendCPU} */
48
- const cpuBackend = args.backend;
49
- const imageHeight = x.shape[0];
50
- const imageWidth = x.shape[1];
51
- /** @type {TypedArray} */
52
- const values = cpuBackend.data.get(x.dataId).values;
53
- const resultValues = pruneImpl(values, imageWidth, imageHeight);
54
- return cpuBackend.makeOutput(resultValues, [Math.floor(imageHeight / 2), Math.floor(imageWidth / 2)], "float32");
55
- };
56
- const pruneConfig = {
57
- //: KernelConfig
58
- kernelName: "Prune",
59
- backendName: "cpu",
60
- kernelFunc: prune, // as {} as KernelFunc,
61
- };
62
- export { pruneConfig, prune, pruneImpl, };
@@ -1,6 +0,0 @@
1
- export function smoothHistograms(args: any): any;
2
- export namespace smoothHistogramsConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { smoothHistograms as kernelFunc };
6
- }
@@ -1,47 +0,0 @@
1
- const ORIENTATION_NUM_BINS = 36;
2
- const ORIENTATION_SMOOTHING_ITERATIONS = 5;
3
- function smoothHistogramsImpl(histograms) {
4
- const resultValues = new Float32Array(histograms.height * ORIENTATION_NUM_BINS);
5
- function getHistogram(y, x) {
6
- return histograms.values[y * histograms.width + x];
7
- }
8
- function setOutput(y, x, o) {
9
- resultValues[y * ORIENTATION_NUM_BINS + x] = o;
10
- }
11
- function imod(x, y) {
12
- return Math.trunc(x - y * Math.floor(x / y));
13
- }
14
- for (let featureIndex = 0; featureIndex < histograms.height; featureIndex++) {
15
- for (let binIndex = 0; binIndex < ORIENTATION_NUM_BINS; binIndex++) {
16
- const prevBin = imod(binIndex - 1 + ORIENTATION_NUM_BINS, ORIENTATION_NUM_BINS);
17
- const nextBin = imod(binIndex + 1, ORIENTATION_NUM_BINS);
18
- const result = 0.274068619061197 * getHistogram(featureIndex, prevBin) +
19
- 0.451862761877606 * getHistogram(featureIndex, binIndex) +
20
- 0.274068619061197 * getHistogram(featureIndex, nextBin);
21
- setOutput(featureIndex, binIndex, result);
22
- }
23
- }
24
- return resultValues;
25
- }
26
- export const smoothHistograms = (args) => {
27
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
28
- const { histograms } = args.inputs;
29
- /** @type {MathBackendCPU} */
30
- const backend = args.backend;
31
- const histogramsData = {
32
- values: backend.data.get(histograms.dataId).values,
33
- height: histograms.shape[0],
34
- width: histograms.shape[1],
35
- };
36
- //const program = GetProgram(histograms);
37
- for (let i = 0; i < ORIENTATION_SMOOTHING_ITERATIONS; i++) {
38
- histogramsData.values = smoothHistogramsImpl(histogramsData); //backend.runWebGLProgram(program, [histograms], histograms.dtype);//this._compileAndRun(program, [histograms]);
39
- }
40
- return backend.makeOutput(histogramsData.values, [histograms.shape[0], ORIENTATION_NUM_BINS], histograms.dtype);
41
- };
42
- export const smoothHistogramsConfig = {
43
- //: KernelConfig
44
- kernelName: "SmoothHistograms",
45
- backendName: "cpu",
46
- kernelFunc: smoothHistograms, // as {} as KernelFunc,
47
- };
@@ -1,6 +0,0 @@
1
- export function upsampleBilinear(args: any): Tensor;
2
- export namespace upsampleBilinearConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { upsampleBilinear as kernelFunc };
6
- }
@@ -1,43 +0,0 @@
1
- import * as FakeShader from "./fakeShader.js";
2
- function getProgram(targetImage) {
3
- const kernel = {
4
- variableNames: ["p"],
5
- outputShape: [targetImage.shape[0], targetImage.shape[1]],
6
- userCode: function () {
7
- const coords = this.getOutputCoords();
8
- const j = coords[0];
9
- const i = coords[1];
10
- const sj = Math.fround(0.5 * j) - 0.25;
11
- const si = Math.fround(0.5 * i) - 0.25;
12
- const sj0 = Math.floor(sj);
13
- const sj1 = Math.ceil(sj);
14
- const si0 = Math.floor(si);
15
- const si1 = Math.ceil(si);
16
- const sj0I = this.int(sj0);
17
- const sj1I = this.int(sj1);
18
- const si0I = this.int(si0);
19
- const si1I = this.int(si1);
20
- let sum = 0.0;
21
- sum += this.getP(sj0I, si0I) * Math.fround((si1 - si) * (sj1 - sj));
22
- sum += this.getP(sj1I, si0I) * Math.fround((si1 - si) * (sj - sj0));
23
- sum += this.getP(sj0I, si1I) * Math.fround((si - si0) * (sj1 - sj));
24
- sum += this.getP(sj1I, si1I) * Math.fround((si - si0) * (sj - sj0));
25
- this.setOutput(sum);
26
- },
27
- };
28
- return kernel;
29
- }
30
- export const upsampleBilinear = (args) => {
31
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
32
- const { image, targetImage } = args.inputs;
33
- /** @type {MathBackendCPU} */
34
- const cpuBackend = args.backend;
35
- const program = getProgram(targetImage);
36
- return FakeShader.runCode(cpuBackend, program, [image], image.dtype);
37
- };
38
- export const upsampleBilinearConfig = {
39
- //: KernelConfig
40
- kernelName: "UpsampleBilinear",
41
- backendName: "cpu",
42
- kernelFunc: upsampleBilinear, // as {} as KernelFunc,
43
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import "./webgl/index.js";
2
- import "./cpu/index.js";
@@ -1,6 +0,0 @@
1
- export function binomialFilter(args: any): any;
2
- export namespace binomialFilterConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { binomialFilter as kernelFunc };
6
- }
@@ -1,67 +0,0 @@
1
- const cache = {};
2
- /**
3
- *
4
- * @param {string} key
5
- * @param {TensorInfo} image
6
- * @returns {[GPGPUProgram,GPGPUProgram]}
7
- */
8
- function GetKernels(image) {
9
- const imageWidth = image.shape[1];
10
- const imageHeight = image.shape[0];
11
- const key = "w" + imageWidth + "h" + imageHeight;
12
- if (!cache.hasOwnProperty(key)) {
13
- const kernel1 = {
14
- variableNames: ["p"],
15
- outputShape: [imageHeight, imageWidth],
16
- userCode: `
17
- void main() {
18
- ivec2 coords = getOutputCoords();
19
-
20
- float sum = getP(coords[0], coords[1]-2);
21
- sum += getP(coords[0], coords[1]-1) * 4.;
22
- sum += getP(coords[0], coords[1]) * 6.;
23
- sum += getP(coords[0], coords[1]+1) * 4.;
24
- sum += getP(coords[0], coords[1]+2);
25
- setOutput(sum);
26
- }
27
- `,
28
- };
29
- const kernel2 = {
30
- variableNames: ["p"],
31
- outputShape: [imageHeight, imageWidth],
32
- userCode: `
33
- void main() {
34
- ivec2 coords = getOutputCoords();
35
-
36
- float sum = getP(coords[0]-2, coords[1]);
37
- sum += getP(coords[0]-1, coords[1]) * 4.;
38
- sum += getP(coords[0], coords[1]) * 6.;
39
- sum += getP(coords[0]+1, coords[1]) * 4.;
40
- sum += getP(coords[0]+2, coords[1]);
41
- sum /= 256.;
42
- setOutput(sum);
43
- }
44
- `,
45
- };
46
- cache[key] = [kernel1, kernel2];
47
- }
48
- return cache[key];
49
- }
50
- export const binomialFilter = (args) => {
51
- //{inputs: UnaryInputs, backend: MathBackendCPU}
52
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
53
- const image = args.inputs.image;
54
- /** @type {MathBackendWebGL} */
55
- const backend = args.backend;
56
- const [kernel1, kernel2] = GetKernels(image);
57
- const result1 = backend.runWebGLProgram(kernel1, [image], image.dtype);
58
- const result2 = backend.runWebGLProgram(kernel2, [result1], image.dtype);
59
- backend.disposeIntermediateTensorInfo(result1);
60
- return result2;
61
- };
62
- export const binomialFilterConfig = {
63
- //: KernelConfig
64
- kernelName: "BinomialFilter",
65
- backendName: "webgl",
66
- kernelFunc: binomialFilter, // as {} as KernelFunc,
67
- };
@@ -1,6 +0,0 @@
1
- export function buildExtremas(args: any): any;
2
- export namespace buildExtremasConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { buildExtremas as kernelFunc };
6
- }
@@ -1,101 +0,0 @@
1
- import { engine } from "@tensorflow/tfjs";
2
- const FREAK_EXPANSION_FACTOR = 7.0;
3
- const LAPLACIAN_THRESHOLD = 3.0;
4
- const LAPLACIAN_SQR_THRESHOLD = LAPLACIAN_THRESHOLD * LAPLACIAN_THRESHOLD;
5
- const EDGE_THRESHOLD = 4.0;
6
- const EDGE_HESSIAN_THRESHOLD = ((EDGE_THRESHOLD + 1) * (EDGE_THRESHOLD + 1)) / EDGE_THRESHOLD;
7
- const cache = {};
8
- function GetProgram(image) {
9
- const imageWidth = image.shape[1];
10
- const imageHeight = image.shape[0];
11
- const kernelKey = "w" + imageWidth + "h" + imageHeight;
12
- if (!cache.hasOwnProperty(kernelKey)) {
13
- const kernel = {
14
- variableNames: ["image0", "image1", "image2"],
15
- outputShape: [imageHeight, imageWidth],
16
- userCode: `
17
- void main() {
18
- ivec2 coords = getOutputCoords();
19
-
20
- int y = coords[0];
21
- int x = coords[1];
22
-
23
- float value = getImage1(y, x);
24
-
25
- // Step 1: find local maxima/minima
26
- if (value * value < ${LAPLACIAN_SQR_THRESHOLD}.) {
27
- setOutput(0.);
28
- return;
29
- }
30
- if (y < ${FREAK_EXPANSION_FACTOR} || y > ${imageHeight - 1 - FREAK_EXPANSION_FACTOR}) {
31
- setOutput(0.);
32
- return;
33
- }
34
- if (x < ${FREAK_EXPANSION_FACTOR} || x > ${imageWidth - 1 - FREAK_EXPANSION_FACTOR}) {
35
- setOutput(0.);
36
- return;
37
- }
38
-
39
- bool isMax = true;
40
- bool isMin = true;
41
- for (int dy = -1; dy <= 1; dy++) {
42
- for (int dx = -1; dx <= 1; dx++) {
43
- float value0 = getImage0(y+dy, x+dx);
44
- float value1 = getImage1(y+dy, x+dx);
45
- float value2 = getImage2(y+dy, x+dx);
46
-
47
- if (value < value0 || value < value1 || value < value2) {
48
- isMax = false;
49
- }
50
- if (value > value0 || value > value1 || value > value2) {
51
- isMin = false;
52
- }
53
- }
54
- }
55
-
56
- if (!isMax && !isMin) {
57
- setOutput(0.);
58
- return;
59
- }
60
-
61
- // compute edge score and reject based on threshold
62
- float dxx = getImage1(y, x+1) + getImage1(y, x-1) - 2. * getImage1(y, x);
63
- float dyy = getImage1(y+1, x) + getImage1(y-1, x) - 2. * getImage1(y, x);
64
- float dxy = 0.25 * (getImage1(y-1,x-1) + getImage1(y+1,x+1) - getImage1(y-1,x+1) - getImage1(y+1,x-1));
65
-
66
- float det = (dxx * dyy) - (dxy * dxy);
67
-
68
- if (abs(det) < 0.0001) { // determinant undefined. no solution
69
- setOutput(0.);
70
- return;
71
- }
72
-
73
- float edgeScore = (dxx + dyy) * (dxx + dyy) / det;
74
-
75
- if (abs(edgeScore) >= ${EDGE_HESSIAN_THRESHOLD} ) {
76
- setOutput(0.);
77
- return;
78
- }
79
- setOutput(getImage1(y,x));
80
- }
81
- `,
82
- };
83
- cache[kernelKey] = kernel;
84
- }
85
- return cache[kernelKey];
86
- }
87
- export const buildExtremas = (args) => {
88
- let { image0, image1, image2 } = args.inputs;
89
- /** @type {MathBackendWebGL} */
90
- const backend = args.backend;
91
- const program = GetProgram(image1);
92
- image0 = engine().runKernel("DownsampleBilinear", { image: image0 });
93
- image2 = engine().runKernel("UpsampleBilinear", { image: image2, targetImage: image1 });
94
- return backend.runWebGLProgram(program, [image0, image1, image2], image1.dtype);
95
- };
96
- export const buildExtremasConfig = {
97
- //: KernelConfig
98
- kernelName: "BuildExtremas",
99
- backendName: "webgl",
100
- kernelFunc: buildExtremas, // as {} as KernelFunc,
101
- };
@@ -1,6 +0,0 @@
1
- export function computeExtremaAngles(args: any): any;
2
- export namespace computeExtremaAnglesConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { computeExtremaAngles as kernelFunc };
6
- }
@@ -1,78 +0,0 @@
1
- const ORIENTATION_NUM_BINS = 36;
2
- const cache = {};
3
- function GetProgram(histograms) {
4
- const key = histograms.shape[0];
5
- if (!cache.hasOwnProperty(key)) {
6
- const kernel = {
7
- variableNames: ["histogram"],
8
- outputShape: [histograms.shape[0]],
9
- userCode: `
10
- void main() {
11
- int featureIndex = getOutputCoords();
12
-
13
- int maxIndex = 0;
14
- for (int i = 1; i < ${ORIENTATION_NUM_BINS}; i++) {
15
- if (getHistogram(featureIndex, i) > getHistogram(featureIndex, maxIndex)) {
16
- maxIndex = i;
17
- }
18
- }
19
-
20
- int prev = imod(maxIndex - 1 + ${ORIENTATION_NUM_BINS}, ${ORIENTATION_NUM_BINS});
21
- int next = imod(maxIndex + 1, ${ORIENTATION_NUM_BINS});
22
-
23
- /**
24
- * Fit a quatratic to 3 points. The system of equations is:
25
- *
26
- * y0 = A*x0^2 + B*x0 + C
27
- * y1 = A*x1^2 + B*x1 + C
28
- * y2 = A*x2^2 + B*x2 + C
29
- *
30
- * This system of equations is solved for A,B,C.
31
- */
32
- float p10 = float(maxIndex - 1);
33
- float p11 = getHistogram(featureIndex, prev);
34
- float p20 = float(maxIndex);
35
- float p21 = getHistogram(featureIndex, maxIndex);
36
- float p30 = float(maxIndex + 1);
37
- float p31 = getHistogram(featureIndex, next);
38
-
39
- float d1 = (p30-p20)*(p30-p10);
40
- float d2 = (p10-p20)*(p30-p10);
41
- float d3 = p10-p20;
42
-
43
- // If any of the denominators are zero then, just use maxIndex.
44
- float fbin = float(maxIndex);
45
- if ( abs(d1) > 0.00001 && abs(d2) > 0.00001 && abs(d3) > 0.00001) {
46
- float a = p10*p10;
47
- float b = p20*p20;
48
-
49
- // Solve for the coefficients A,B,C
50
- float A = ((p31-p21)/d1)-((p11-p21)/d2);
51
- float B = ((p11-p21)+(A*(b-a)))/d3;
52
- float C = p11-(A*a)-(B*p10);
53
- fbin = -B / (2. * A);
54
- }
55
-
56
- float an = 2.0 *${Math.PI} * (fbin + 0.5) / ${ORIENTATION_NUM_BINS}. - ${Math.PI};
57
- setOutput(an);
58
- }
59
- `,
60
- };
61
- cache[key] = kernel;
62
- }
63
- return cache[key];
64
- }
65
- export const computeExtremaAngles = (args) => {
66
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
67
- const { histograms } = args.inputs;
68
- /** @type {MathBackendWebGL} */
69
- const backend = args.backend;
70
- const program = GetProgram(histograms);
71
- return backend.runWebGLProgram(program, [histograms], histograms.dtype);
72
- };
73
- export const computeExtremaAnglesConfig = {
74
- //: KernelConfig
75
- kernelName: "ComputeExtremaAngles",
76
- backendName: "webgl",
77
- kernelFunc: computeExtremaAngles, // as {} as KernelFunc,
78
- };
@@ -1,6 +0,0 @@
1
- export function computeExtremaFreak(args: any): any;
2
- export namespace computeExtremaFreakConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { computeExtremaFreak as kernelFunc };
6
- }
@@ -1,86 +0,0 @@
1
- import { FREAKPOINTS } from "../../freak.js";
2
- const FREAK_EXPANSION_FACTOR = 7.0;
3
- const cache = {};
4
- function GetProgram(imageCount, prunedExtremas) {
5
- const key = `${imageCount}|${prunedExtremas.shape[0]}`;
6
- if (!cache.hasOwnProperty(key)) {
7
- const imageVariableNames = [];
8
- for (let i = 1; i < imageCount; i++) {
9
- imageVariableNames.push("image" + i);
10
- }
11
- let pixelsSubCodes = `float getPixel(int octave, int y, int x) {`;
12
- for (let i = 1; i < imageCount; i++) {
13
- pixelsSubCodes += `
14
- if (octave == ${i}) {
15
- return getImage${i}(y, x);
16
- }
17
- `;
18
- }
19
- pixelsSubCodes += `}`;
20
- const kernel = {
21
- variableNames: [...imageVariableNames, "extrema", "angles", "freakPoints"],
22
- outputShape: [prunedExtremas.shape[0], FREAKPOINTS.length],
23
- userCode: `
24
- ${pixelsSubCodes}
25
- void main() {
26
- ivec2 coords = getOutputCoords();
27
- int featureIndex = coords[0];
28
- int freakIndex = coords[1];
29
-
30
- float freakSigma = getFreakPoints(freakIndex, 0);
31
- float freakX = getFreakPoints(freakIndex, 1);
32
- float freakY = getFreakPoints(freakIndex, 2);
33
-
34
- int octave = int(getExtrema(featureIndex, 1));
35
- float inputY = getExtrema(featureIndex, 2);
36
- float inputX = getExtrema(featureIndex, 3);
37
- float inputAngle = getAngles(featureIndex);
38
- float cos = ${FREAK_EXPANSION_FACTOR}. * cos(inputAngle);
39
- float sin = ${FREAK_EXPANSION_FACTOR}. * sin(inputAngle);
40
-
41
- float yp = inputY + freakX * sin + freakY * cos;
42
- float xp = inputX + freakX * cos + freakY * -sin;
43
-
44
- int x0 = int(floor(xp));
45
- int x1 = x0 + 1;
46
- int y0 = int(floor(yp));
47
- int y1 = y0 + 1;
48
-
49
- float f1 = getPixel(octave, y0, x0);
50
- float f2 = getPixel(octave, y0, x1);
51
- float f3 = getPixel(octave, y1, x0);
52
- float f4 = getPixel(octave, y1, x1);
53
-
54
- float x1f = float(x1);
55
- float y1f = float(y1);
56
- float x0f = float(x0);
57
- float y0f = float(y0);
58
-
59
- // ratio for interpolation between four neighbouring points
60
- float value = (x1f - xp) * (y1f - yp) * f1
61
- + (xp - x0f) * (y1f - yp) * f2
62
- + (x1f - xp) * (yp - y0f) * f3
63
- + (xp - x0f) * (yp - y0f) * f4;
64
-
65
- setOutput(value);
66
- }
67
- `,
68
- };
69
- cache[key] = kernel;
70
- }
71
- return cache[key];
72
- }
73
- export const computeExtremaFreak = (args) => {
74
- /** @type {import('@tensorflow/tfjs').TensorInfo} */
75
- const { gaussianImagesT, prunedExtremas, prunedExtremasAngles, freakPointsT, pyramidImagesLength, } = args.inputs;
76
- /** @type {MathBackendWebGL} */
77
- const backend = args.backend;
78
- const program = GetProgram(pyramidImagesLength, prunedExtremas);
79
- return backend.runWebGLProgram(program, [...gaussianImagesT, prunedExtremas, prunedExtremasAngles, freakPointsT], "float32");
80
- };
81
- export const computeExtremaFreakConfig = {
82
- //: KernelConfig
83
- kernelName: "ComputeExtremaFreak",
84
- backendName: "webgl",
85
- kernelFunc: computeExtremaFreak, // as {} as KernelFunc,
86
- };
@@ -1,6 +0,0 @@
1
- export function computeFreakDescriptor(args: any): any;
2
- export namespace computeFreakDescriptorConfig {
3
- export let kernelName: string;
4
- export let backendName: string;
5
- export { computeFreakDescriptor as kernelFunc };
6
- }