@srsergio/taptapp-ar 1.0.0
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.
- package/README.md +62 -0
- package/dist/compiler/aframe.d.ts +1 -0
- package/dist/compiler/aframe.js +275 -0
- package/dist/compiler/compiler-base.d.ts +12 -0
- package/dist/compiler/compiler-base.js +165 -0
- package/dist/compiler/compiler.d.ts +9 -0
- package/dist/compiler/compiler.js +24 -0
- package/dist/compiler/compiler.worker.d.ts +1 -0
- package/dist/compiler/compiler.worker.js +28 -0
- package/dist/compiler/controller.d.ts +101 -0
- package/dist/compiler/controller.js +400 -0
- package/dist/compiler/controller.worker.d.ts +1 -0
- package/dist/compiler/controller.worker.js +61 -0
- package/dist/compiler/detector/crop-detector.d.ts +65 -0
- package/dist/compiler/detector/crop-detector.js +59 -0
- package/dist/compiler/detector/detector.d.ts +98 -0
- package/dist/compiler/detector/detector.js +1049 -0
- package/dist/compiler/detector/freak.d.ts +1 -0
- package/dist/compiler/detector/freak.js +89 -0
- package/dist/compiler/detector/kernels/cpu/binomialFilter.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/binomialFilter.js +51 -0
- package/dist/compiler/detector/kernels/cpu/buildExtremas.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/buildExtremas.js +89 -0
- package/dist/compiler/detector/kernels/cpu/computeExtremaAngles.d.ts +7 -0
- package/dist/compiler/detector/kernels/cpu/computeExtremaAngles.js +79 -0
- package/dist/compiler/detector/kernels/cpu/computeExtremaFreak.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/computeExtremaFreak.js +68 -0
- package/dist/compiler/detector/kernels/cpu/computeFreakDescriptors.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/computeFreakDescriptors.js +57 -0
- package/dist/compiler/detector/kernels/cpu/computeLocalization.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/computeLocalization.js +54 -0
- package/dist/compiler/detector/kernels/cpu/computeOrientationHistograms.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/computeOrientationHistograms.js +118 -0
- package/dist/compiler/detector/kernels/cpu/downsampleBilinear.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/downsampleBilinear.js +29 -0
- package/dist/compiler/detector/kernels/cpu/extremaReduction.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/extremaReduction.js +50 -0
- package/dist/compiler/detector/kernels/cpu/fakeShader.d.ts +20 -0
- package/dist/compiler/detector/kernels/cpu/fakeShader.js +80 -0
- package/dist/compiler/detector/kernels/cpu/index.d.ts +1 -0
- package/dist/compiler/detector/kernels/cpu/index.js +25 -0
- package/dist/compiler/detector/kernels/cpu/prune.d.ts +1 -0
- package/dist/compiler/detector/kernels/cpu/prune.js +103 -0
- package/dist/compiler/detector/kernels/cpu/smoothHistograms.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/smoothHistograms.js +47 -0
- package/dist/compiler/detector/kernels/cpu/upsampleBilinear.d.ts +6 -0
- package/dist/compiler/detector/kernels/cpu/upsampleBilinear.js +43 -0
- package/dist/compiler/detector/kernels/index.d.ts +1 -0
- package/dist/compiler/detector/kernels/index.js +2 -0
- package/dist/compiler/detector/kernels/webgl/binomialFilter.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/binomialFilter.js +67 -0
- package/dist/compiler/detector/kernels/webgl/buildExtremas.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/buildExtremas.js +101 -0
- package/dist/compiler/detector/kernels/webgl/computeExtremaAngles.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/computeExtremaAngles.js +78 -0
- package/dist/compiler/detector/kernels/webgl/computeExtremaFreak.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/computeExtremaFreak.js +86 -0
- package/dist/compiler/detector/kernels/webgl/computeFreakDescriptors.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/computeFreakDescriptors.js +52 -0
- package/dist/compiler/detector/kernels/webgl/computeLocalization.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/computeLocalization.js +58 -0
- package/dist/compiler/detector/kernels/webgl/computeOrientationHistograms.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/computeOrientationHistograms.js +116 -0
- package/dist/compiler/detector/kernels/webgl/downsampleBilinear.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/downsampleBilinear.js +46 -0
- package/dist/compiler/detector/kernels/webgl/extremaReduction.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/extremaReduction.js +48 -0
- package/dist/compiler/detector/kernels/webgl/index.d.ts +1 -0
- package/dist/compiler/detector/kernels/webgl/index.js +25 -0
- package/dist/compiler/detector/kernels/webgl/smoothHistograms.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/smoothHistograms.js +49 -0
- package/dist/compiler/detector/kernels/webgl/upsampleBilinear.d.ts +6 -0
- package/dist/compiler/detector/kernels/webgl/upsampleBilinear.js +56 -0
- package/dist/compiler/estimation/esimate-experiment.d.ts +5 -0
- package/dist/compiler/estimation/esimate-experiment.js +267 -0
- package/dist/compiler/estimation/estimate.d.ts +5 -0
- package/dist/compiler/estimation/estimate.js +51 -0
- package/dist/compiler/estimation/estimator.d.ts +13 -0
- package/dist/compiler/estimation/estimator.js +30 -0
- package/dist/compiler/estimation/refine-estimate-experiment.d.ts +6 -0
- package/dist/compiler/estimation/refine-estimate-experiment.js +429 -0
- package/dist/compiler/estimation/refine-estimate.d.ts +6 -0
- package/dist/compiler/estimation/refine-estimate.js +299 -0
- package/dist/compiler/estimation/utils.d.ts +10 -0
- package/dist/compiler/estimation/utils.js +80 -0
- package/dist/compiler/image-list.d.ts +13 -0
- package/dist/compiler/image-list.js +52 -0
- package/dist/compiler/index.d.ts +3 -0
- package/dist/compiler/index.js +10 -0
- package/dist/compiler/input-loader.d.ts +23 -0
- package/dist/compiler/input-loader.js +88 -0
- package/dist/compiler/matching/hamming-distance.d.ts +1 -0
- package/dist/compiler/matching/hamming-distance.js +20 -0
- package/dist/compiler/matching/hierarchical-clustering.d.ts +7 -0
- package/dist/compiler/matching/hierarchical-clustering.js +109 -0
- package/dist/compiler/matching/hough.d.ts +1 -0
- package/dist/compiler/matching/hough.js +169 -0
- package/dist/compiler/matching/matcher.d.ts +28 -0
- package/dist/compiler/matching/matcher.js +48 -0
- package/dist/compiler/matching/matching.d.ts +41 -0
- package/dist/compiler/matching/matching.js +197 -0
- package/dist/compiler/matching/ransacHomography.d.ts +1 -0
- package/dist/compiler/matching/ransacHomography.js +136 -0
- package/dist/compiler/offline-compiler.d.ts +10 -0
- package/dist/compiler/offline-compiler.js +450 -0
- package/dist/compiler/tensorflow-setup.d.ts +7 -0
- package/dist/compiler/tensorflow-setup.js +73 -0
- package/dist/compiler/three.d.ts +66 -0
- package/dist/compiler/three.js +310 -0
- package/dist/compiler/tracker/extract-utils.d.ts +1 -0
- package/dist/compiler/tracker/extract-utils.js +29 -0
- package/dist/compiler/tracker/extract.d.ts +4 -0
- package/dist/compiler/tracker/extract.js +349 -0
- package/dist/compiler/tracker/tracker.d.ts +38 -0
- package/dist/compiler/tracker/tracker.js +327 -0
- package/dist/compiler/utils/cumsum.d.ts +5 -0
- package/dist/compiler/utils/cumsum.js +39 -0
- package/dist/compiler/utils/geometry.d.ts +8 -0
- package/dist/compiler/utils/geometry.js +101 -0
- package/dist/compiler/utils/homography.d.ts +1 -0
- package/dist/compiler/utils/homography.js +138 -0
- package/dist/compiler/utils/images.d.ts +24 -0
- package/dist/compiler/utils/images.js +99 -0
- package/dist/compiler/utils/randomizer.d.ts +5 -0
- package/dist/compiler/utils/randomizer.js +25 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/react/AREditor.d.ts +5 -0
- package/dist/react/AREditor.js +159 -0
- package/dist/react/ProgressDialog.d.ts +13 -0
- package/dist/react/ProgressDialog.js +57 -0
- package/dist/react/types.d.ts +22 -0
- package/dist/react/types.js +14 -0
- package/package.json +53 -0
- package/src/astro/ARScene.astro +59 -0
- package/src/astro/ARVideoTrigger.astro +73 -0
- package/src/astro/overlays/ErrorOverlay.astro +40 -0
- package/src/astro/overlays/LoadingOverlay.astro +28 -0
- package/src/astro/overlays/ScanningOverlay.astro +119 -0
- package/src/astro/scripts/ARScripts.astro +118 -0
- package/src/astro/styles/ARStyles.astro +147 -0
- package/src/compiler/aframe.js +343 -0
- package/src/compiler/compiler-base.js +195 -0
- package/src/compiler/compiler.js +25 -0
- package/src/compiler/compiler.worker.js +30 -0
- package/src/compiler/controller.js +473 -0
- package/src/compiler/controller.worker.js +77 -0
- package/src/compiler/detector/crop-detector.js +68 -0
- package/src/compiler/detector/detector.js +1130 -0
- package/src/compiler/detector/freak.js +91 -0
- package/src/compiler/detector/kernels/cpu/binomialFilter.js +59 -0
- package/src/compiler/detector/kernels/cpu/buildExtremas.js +108 -0
- package/src/compiler/detector/kernels/cpu/computeExtremaAngles.js +91 -0
- package/src/compiler/detector/kernels/cpu/computeExtremaFreak.js +92 -0
- package/src/compiler/detector/kernels/cpu/computeFreakDescriptors.js +68 -0
- package/src/compiler/detector/kernels/cpu/computeLocalization.js +71 -0
- package/src/compiler/detector/kernels/cpu/computeOrientationHistograms.js +141 -0
- package/src/compiler/detector/kernels/cpu/downsampleBilinear.js +33 -0
- package/src/compiler/detector/kernels/cpu/extremaReduction.js +53 -0
- package/src/compiler/detector/kernels/cpu/fakeShader.js +88 -0
- package/src/compiler/detector/kernels/cpu/index.js +26 -0
- package/src/compiler/detector/kernels/cpu/prune.js +114 -0
- package/src/compiler/detector/kernels/cpu/smoothHistograms.js +57 -0
- package/src/compiler/detector/kernels/cpu/upsampleBilinear.js +51 -0
- package/src/compiler/detector/kernels/index.js +2 -0
- package/src/compiler/detector/kernels/webgl/binomialFilter.js +72 -0
- package/src/compiler/detector/kernels/webgl/buildExtremas.js +109 -0
- package/src/compiler/detector/kernels/webgl/computeExtremaAngles.js +82 -0
- package/src/compiler/detector/kernels/webgl/computeExtremaFreak.js +105 -0
- package/src/compiler/detector/kernels/webgl/computeFreakDescriptors.js +56 -0
- package/src/compiler/detector/kernels/webgl/computeLocalization.js +70 -0
- package/src/compiler/detector/kernels/webgl/computeOrientationHistograms.js +129 -0
- package/src/compiler/detector/kernels/webgl/downsampleBilinear.js +50 -0
- package/src/compiler/detector/kernels/webgl/extremaReduction.js +50 -0
- package/src/compiler/detector/kernels/webgl/index.js +26 -0
- package/src/compiler/detector/kernels/webgl/smoothHistograms.js +53 -0
- package/src/compiler/detector/kernels/webgl/upsampleBilinear.js +62 -0
- package/src/compiler/estimation/esimate-experiment.js +316 -0
- package/src/compiler/estimation/estimate.js +67 -0
- package/src/compiler/estimation/estimator.js +34 -0
- package/src/compiler/estimation/refine-estimate-experiment.js +512 -0
- package/src/compiler/estimation/refine-estimate.js +365 -0
- package/src/compiler/estimation/utils.js +97 -0
- package/src/compiler/image-list.js +62 -0
- package/src/compiler/index.js +13 -0
- package/src/compiler/input-loader.js +107 -0
- package/src/compiler/matching/hamming-distance.js +23 -0
- package/src/compiler/matching/hierarchical-clustering.js +131 -0
- package/src/compiler/matching/hough.js +206 -0
- package/src/compiler/matching/matcher.js +59 -0
- package/src/compiler/matching/matching.js +237 -0
- package/src/compiler/matching/ransacHomography.js +192 -0
- package/src/compiler/offline-compiler.js +553 -0
- package/src/compiler/tensorflow-setup.js +88 -0
- package/src/compiler/three.js +368 -0
- package/src/compiler/tracker/extract-utils.js +34 -0
- package/src/compiler/tracker/extract.js +419 -0
- package/src/compiler/tracker/tracker.js +397 -0
- package/src/compiler/utils/cumsum.js +40 -0
- package/src/compiler/utils/geometry.js +114 -0
- package/src/compiler/utils/homography.js +150 -0
- package/src/compiler/utils/images.js +111 -0
- package/src/compiler/utils/randomizer.js +29 -0
- package/src/index.ts +8 -0
- package/src/react/AREditor.tsx +394 -0
- package/src/react/ProgressDialog.tsx +185 -0
- package/src/react/types.ts +35 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// 37 points = 6 rings x 6 points per ring + 1 center
|
|
2
|
+
const FREAK_RINGS = [
|
|
3
|
+
// ring 5
|
|
4
|
+
{
|
|
5
|
+
sigma: 0.55,
|
|
6
|
+
points: [
|
|
7
|
+
[-1.0, 0.0],
|
|
8
|
+
[-0.5, -0.866025],
|
|
9
|
+
[0.5, -0.866025],
|
|
10
|
+
[1.0, -0.0],
|
|
11
|
+
[0.5, 0.866025],
|
|
12
|
+
[-0.5, 0.866025],
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
// ring 4
|
|
16
|
+
{
|
|
17
|
+
sigma: 0.475,
|
|
18
|
+
points: [
|
|
19
|
+
[0.0, 0.930969],
|
|
20
|
+
[-0.806243, 0.465485],
|
|
21
|
+
[-0.806243, -0.465485],
|
|
22
|
+
[-0.0, -0.930969],
|
|
23
|
+
[0.806243, -0.465485],
|
|
24
|
+
[0.806243, 0.465485],
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
// ring 3
|
|
28
|
+
{
|
|
29
|
+
sigma: 0.4,
|
|
30
|
+
points: [
|
|
31
|
+
[0.847306, -0.0],
|
|
32
|
+
[0.423653, 0.733789],
|
|
33
|
+
[-0.423653, 0.733789],
|
|
34
|
+
[-0.847306, 0.0],
|
|
35
|
+
[-0.423653, -0.733789],
|
|
36
|
+
[0.423653, -0.733789],
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
// ring 2
|
|
40
|
+
{
|
|
41
|
+
sigma: 0.325,
|
|
42
|
+
points: [
|
|
43
|
+
[-0.0, -0.741094],
|
|
44
|
+
[0.641806, -0.370547],
|
|
45
|
+
[0.641806, 0.370547],
|
|
46
|
+
[0.0, 0.741094],
|
|
47
|
+
[-0.641806, 0.370547],
|
|
48
|
+
[-0.641806, -0.370547],
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
// ring 1
|
|
52
|
+
{
|
|
53
|
+
sigma: 0.25,
|
|
54
|
+
points: [
|
|
55
|
+
[-0.595502, 0.0],
|
|
56
|
+
[-0.297751, -0.51572],
|
|
57
|
+
[0.297751, -0.51572],
|
|
58
|
+
[0.595502, -0.0],
|
|
59
|
+
[0.297751, 0.51572],
|
|
60
|
+
[-0.297751, 0.51572],
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
// ring 0
|
|
64
|
+
{
|
|
65
|
+
sigma: 0.175,
|
|
66
|
+
points: [
|
|
67
|
+
[0.0, 0.362783],
|
|
68
|
+
[-0.314179, 0.181391],
|
|
69
|
+
[-0.314179, -0.181391],
|
|
70
|
+
[-0.0, -0.362783],
|
|
71
|
+
[0.314179, -0.181391],
|
|
72
|
+
[0.314179, 0.181391],
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
// center
|
|
76
|
+
{
|
|
77
|
+
sigma: 0.1,
|
|
78
|
+
points: [[0, 0]],
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const FREAKPOINTS = [];
|
|
83
|
+
for (let r = 0; r < FREAK_RINGS.length; r++) {
|
|
84
|
+
const sigma = FREAK_RINGS[r].sigma;
|
|
85
|
+
for (let i = 0; i < FREAK_RINGS[r].points.length; i++) {
|
|
86
|
+
const point = FREAK_RINGS[r].points[i];
|
|
87
|
+
FREAKPOINTS.push([sigma, point[0], point[1]]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { FREAKPOINTS };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as FakeShader from "./fakeShader.js";
|
|
2
|
+
|
|
3
|
+
function GetKernels(image) {
|
|
4
|
+
const imageWidth = image.shape[1];
|
|
5
|
+
const key = "w" + imageWidth;
|
|
6
|
+
|
|
7
|
+
const imageHeight = image.shape[0];
|
|
8
|
+
const kernel1 = {
|
|
9
|
+
variableNames: ["p"],
|
|
10
|
+
outputShape: [imageHeight, imageWidth],
|
|
11
|
+
userCode: function () {
|
|
12
|
+
const coords = this.getOutputCoords();
|
|
13
|
+
|
|
14
|
+
let sum = this.getP(coords[0], coords[1] - 2);
|
|
15
|
+
sum += this.getP(coords[0], coords[1] - 1) * 4;
|
|
16
|
+
sum += this.getP(coords[0], coords[1]) * 6;
|
|
17
|
+
sum += this.getP(coords[0], coords[1] + 1) * 4;
|
|
18
|
+
sum += this.getP(coords[0], coords[1] + 2);
|
|
19
|
+
this.setOutput(sum);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const kernel2 = {
|
|
23
|
+
variableNames: ["p"],
|
|
24
|
+
outputShape: [imageHeight, imageWidth],
|
|
25
|
+
userCode: function () {
|
|
26
|
+
const coords = this.getOutputCoords();
|
|
27
|
+
|
|
28
|
+
let sum = this.getP(coords[0] - 2, coords[1]);
|
|
29
|
+
sum += this.getP(coords[0] - 1, coords[1]) * 4;
|
|
30
|
+
sum += this.getP(coords[0], coords[1]) * 6;
|
|
31
|
+
sum += this.getP(coords[0] + 1, coords[1]) * 4;
|
|
32
|
+
sum += this.getP(coords[0] + 2, coords[1]);
|
|
33
|
+
sum /= 256;
|
|
34
|
+
this.setOutput(sum);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
return [kernel1, kernel2];
|
|
38
|
+
//}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const binomialFilter = (args) => {
|
|
42
|
+
//{inputs: UnaryInputs, backend: MathBackendCPU}
|
|
43
|
+
/** @type {import('@tensorflow/tfjs').TensorInfo} */
|
|
44
|
+
const image = args.inputs.image;
|
|
45
|
+
/** @type {MathBackendCPU} */
|
|
46
|
+
const backend = args.backend;
|
|
47
|
+
|
|
48
|
+
const [kernel1, kernel2] = GetKernels(image);
|
|
49
|
+
|
|
50
|
+
const result1 = FakeShader.runCode(backend, kernel1, [image], image.dtype);
|
|
51
|
+
return FakeShader.runCode(backend, kernel2, [result1], image.dtype);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const binomialFilterConfig = {
|
|
55
|
+
//: KernelConfig
|
|
56
|
+
kernelName: "BinomialFilter",
|
|
57
|
+
backendName: "cpu",
|
|
58
|
+
kernelFunc: binomialFilter, // as {} as KernelFunc,
|
|
59
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import * as FakeShader from "./fakeShader.js";
|
|
2
|
+
import { engine } from "@tensorflow/tfjs";
|
|
3
|
+
const FREAK_EXPANSION_FACTOR = 7.0;
|
|
4
|
+
|
|
5
|
+
const LAPLACIAN_THRESHOLD = 3.0;
|
|
6
|
+
const LAPLACIAN_SQR_THRESHOLD = LAPLACIAN_THRESHOLD * LAPLACIAN_THRESHOLD;
|
|
7
|
+
|
|
8
|
+
const EDGE_THRESHOLD = 4.0;
|
|
9
|
+
const EDGE_HESSIAN_THRESHOLD = ((EDGE_THRESHOLD + 1) * (EDGE_THRESHOLD + 1)) / EDGE_THRESHOLD;
|
|
10
|
+
|
|
11
|
+
function GetProgram(image) {
|
|
12
|
+
const imageWidth = image.shape[1];
|
|
13
|
+
const imageHeight = image.shape[0];
|
|
14
|
+
const kernel = {
|
|
15
|
+
variableNames: ["image0", "image1", "image2"],
|
|
16
|
+
outputShape: [imageHeight, imageWidth],
|
|
17
|
+
userCode: function () {
|
|
18
|
+
const coords = this.getOutputCoords();
|
|
19
|
+
|
|
20
|
+
const y = coords[0];
|
|
21
|
+
const x = coords[1];
|
|
22
|
+
|
|
23
|
+
const value = this.getImage1(y, x);
|
|
24
|
+
|
|
25
|
+
// Step 1: find local maxima/minima
|
|
26
|
+
if (value * value < LAPLACIAN_SQR_THRESHOLD) {
|
|
27
|
+
this.setOutput(0.0);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (y < FREAK_EXPANSION_FACTOR || y > imageHeight - 1 - FREAK_EXPANSION_FACTOR) {
|
|
31
|
+
this.setOutput(0.0);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (x < FREAK_EXPANSION_FACTOR || x > imageWidth - 1 - FREAK_EXPANSION_FACTOR) {
|
|
35
|
+
this.setOutput(0.0);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let isMax = true;
|
|
40
|
+
let isMin = true;
|
|
41
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
42
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
43
|
+
const value0 = this.getImage0(y + dy, x + dx);
|
|
44
|
+
const value1 = this.getImage1(y + dy, x + dx);
|
|
45
|
+
const value2 = this.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
|
+
this.setOutput(0.0);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// compute edge score and reject based on threshold
|
|
62
|
+
const dxx = this.getImage1(y, x + 1) + this.getImage1(y, x - 1) - 2 * this.getImage1(y, x);
|
|
63
|
+
const dyy = this.getImage1(y + 1, x) + this.getImage1(y - 1, x) - 2 * this.getImage1(y, x);
|
|
64
|
+
const dxy =
|
|
65
|
+
0.25 *
|
|
66
|
+
(this.getImage1(y - 1, x - 1) +
|
|
67
|
+
this.getImage1(y + 1, x + 1) -
|
|
68
|
+
this.getImage1(y - 1, x + 1) -
|
|
69
|
+
this.getImage1(y + 1, x - 1));
|
|
70
|
+
|
|
71
|
+
const det = dxx * dyy - dxy * dxy;
|
|
72
|
+
|
|
73
|
+
if (Math.abs(det) < 0.0001) {
|
|
74
|
+
// determinant undefined. no solution
|
|
75
|
+
this.setOutput(0.0);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const edgeScore = ((dxx + dyy) * (dxx + dyy)) / det;
|
|
80
|
+
|
|
81
|
+
if (Math.abs(edgeScore) >= EDGE_HESSIAN_THRESHOLD) {
|
|
82
|
+
this.setOutput(0.0);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.setOutput(this.getImage1(y, x));
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return kernel;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const buildExtremas = (args) => {
|
|
93
|
+
let { image0, image1, image2 } = args.inputs;
|
|
94
|
+
/** @type {MathBackendCPU} */
|
|
95
|
+
const backend = args.backend;
|
|
96
|
+
|
|
97
|
+
image0 = engine().runKernel("DownsampleBilinear", { image: image0 });
|
|
98
|
+
image2 = engine().runKernel("UpsampleBilinear", { image: image2, targetImage: image1 });
|
|
99
|
+
const program = GetProgram(image1);
|
|
100
|
+
return FakeShader.runCode(backend, program, [image0, image1, image2], image1.dtype);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const buildExtremasConfig = {
|
|
104
|
+
//: KernelConfig
|
|
105
|
+
kernelName: "BuildExtremas",
|
|
106
|
+
backendName: "cpu",
|
|
107
|
+
kernelFunc: buildExtremas, // as {} as KernelFunc,
|
|
108
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const ORIENTATION_NUM_BINS = 36;
|
|
2
|
+
|
|
3
|
+
export function computeExtremaAnglesImpl(histogram) {
|
|
4
|
+
const resultValues = new Float32Array(histogram.height);
|
|
5
|
+
|
|
6
|
+
function getHistogram(featureIndex, prev) {
|
|
7
|
+
return histogram.values[featureIndex * histogram.width + prev];
|
|
8
|
+
}
|
|
9
|
+
function setOutput(featureIndex, an) {
|
|
10
|
+
resultValues[featureIndex] = an;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function imod(x, y) {
|
|
14
|
+
return Math.trunc(x - y * Math.floor(x / y));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
for (let featureIndex = 0; featureIndex < histogram.height; featureIndex++) {
|
|
18
|
+
let maxIndex = 0;
|
|
19
|
+
for (let i = 1; i < ORIENTATION_NUM_BINS; i++) {
|
|
20
|
+
if (getHistogram(featureIndex, i) > getHistogram(featureIndex, maxIndex)) {
|
|
21
|
+
maxIndex = i;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
let prev = imod(maxIndex - 1 + ORIENTATION_NUM_BINS, ORIENTATION_NUM_BINS);
|
|
25
|
+
let next = imod(maxIndex + 1, ORIENTATION_NUM_BINS);
|
|
26
|
+
/**
|
|
27
|
+
* Fit a quatratic to 3 points. The system of equations is:
|
|
28
|
+
*
|
|
29
|
+
* y0 = A*x0^2 + B*x0 + C
|
|
30
|
+
* y1 = A*x1^2 + B*x1 + C
|
|
31
|
+
* y2 = A*x2^2 + B*x2 + C
|
|
32
|
+
*
|
|
33
|
+
* This system of equations is solved for A,B,C.
|
|
34
|
+
*/
|
|
35
|
+
const p10 = maxIndex - 1;
|
|
36
|
+
const p11 = getHistogram(featureIndex, prev);
|
|
37
|
+
const p20 = maxIndex;
|
|
38
|
+
const p21 = getHistogram(featureIndex, maxIndex);
|
|
39
|
+
const p30 = maxIndex + 1;
|
|
40
|
+
const p31 = getHistogram(featureIndex, next);
|
|
41
|
+
|
|
42
|
+
const d1 = (p30 - p20) * (p30 - p10);
|
|
43
|
+
const d2 = (p10 - p20) * (p30 - p10);
|
|
44
|
+
const d3 = p10 - p20;
|
|
45
|
+
|
|
46
|
+
// If any of the denominators are zero then, just use maxIndex.
|
|
47
|
+
let fbin = maxIndex;
|
|
48
|
+
if (Math.abs(d1) > 0.00001 && Math.abs(d2) > 0.00001 && Math.abs(d3) > 0.00001) {
|
|
49
|
+
const a = p10 * p10;
|
|
50
|
+
const b = p20 * p20;
|
|
51
|
+
|
|
52
|
+
// Solve for the coefficients A,B,C
|
|
53
|
+
let A = (p31 - p21) / d1 - (p11 - p21) / d2;
|
|
54
|
+
if (Number.isNaN(A)) A = 0;
|
|
55
|
+
const B = (p11 - p21 + A * (b - a)) / d3;
|
|
56
|
+
//const C = p11 - (A * a) - (B * p10);
|
|
57
|
+
fbin = -B / (2.0 * A);
|
|
58
|
+
if (Number.isNaN(fbin)) fbin = 0; //console.warn(`computeExtremaAngles::NaN! fbin=${fbin} maxIndex=${maxIndex} A=${A} B=${B} p31=${p31} p21=${p21} p11=${p11}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const an = (2.0 * Math.PI * (fbin + 0.5)) / ORIENTATION_NUM_BINS - Math.PI;
|
|
62
|
+
|
|
63
|
+
setOutput(featureIndex, an);
|
|
64
|
+
}
|
|
65
|
+
return resultValues;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const computeExtremaAngles = (args) => {
|
|
69
|
+
/** @type {import('@tensorflow/tfjs').TensorInfo} */
|
|
70
|
+
const { histograms } = args.inputs;
|
|
71
|
+
/** @type {import('@tensorflow/tfjs-backend-cpu').MathBackendCPU} */
|
|
72
|
+
const backend = args.backend;
|
|
73
|
+
|
|
74
|
+
/** @type {TypedArray} */
|
|
75
|
+
const histogramValues = {
|
|
76
|
+
values: backend.data.get(histograms.dataId).values,
|
|
77
|
+
width: histograms.shape[1],
|
|
78
|
+
height: histograms.shape[0],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const resultValues = computeExtremaAnglesImpl(histogramValues);
|
|
82
|
+
|
|
83
|
+
return backend.makeOutput(resultValues, [histograms.shape[0]], histograms.dtype);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const computeExtremaAnglesConfig = {
|
|
87
|
+
//: KernelConfig
|
|
88
|
+
kernelName: "ComputeExtremaAngles",
|
|
89
|
+
backendName: "cpu",
|
|
90
|
+
kernelFunc: computeExtremaAngles, // as {} as KernelFunc,
|
|
91
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { FREAKPOINTS } from "../../freak.js";
|
|
2
|
+
import * as FakeShader from "./fakeShader.js";
|
|
3
|
+
const FREAK_EXPANSION_FACTOR = 7.0;
|
|
4
|
+
|
|
5
|
+
function GetProgram(prunedExtremasHeight, pyramidImagesLength) {
|
|
6
|
+
const imageVariableNames = [];
|
|
7
|
+
for (let i = 1; i < pyramidImagesLength; i++) {
|
|
8
|
+
imageVariableNames.push("image" + i);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const kernel = {
|
|
12
|
+
variableNames: [...imageVariableNames, "extrema", "angles", "freakPoints"],
|
|
13
|
+
outputShape: [prunedExtremasHeight, FREAKPOINTS.length],
|
|
14
|
+
userCode: function () {
|
|
15
|
+
const getPixel = (octave, y, x) => {
|
|
16
|
+
const key = "getImage" + octave;
|
|
17
|
+
if (octave < 1 || octave >= pyramidImagesLength) return 0.0;
|
|
18
|
+
return this[key](y, x);
|
|
19
|
+
};
|
|
20
|
+
const coords = this.getOutputCoords();
|
|
21
|
+
const featureIndex = coords[0];
|
|
22
|
+
const freakIndex = coords[1];
|
|
23
|
+
|
|
24
|
+
//const freakSigma = this.getFreakPoints(freakIndex, 0);
|
|
25
|
+
const freakX = this.getFreakPoints(freakIndex, 1);
|
|
26
|
+
const freakY = this.getFreakPoints(freakIndex, 2);
|
|
27
|
+
|
|
28
|
+
const octave = this.int(this.getExtrema(featureIndex, 1));
|
|
29
|
+
const inputY = this.getExtrema(featureIndex, 2);
|
|
30
|
+
const inputX = this.getExtrema(featureIndex, 3);
|
|
31
|
+
const inputAngle = this.getAngles(featureIndex);
|
|
32
|
+
const cos = FREAK_EXPANSION_FACTOR * Math.cos(inputAngle);
|
|
33
|
+
const sin = FREAK_EXPANSION_FACTOR * Math.sin(inputAngle);
|
|
34
|
+
|
|
35
|
+
const yp = inputY + freakX * sin + freakY * cos;
|
|
36
|
+
const xp = inputX + freakX * cos + freakY * -sin;
|
|
37
|
+
|
|
38
|
+
const x0 = this.int(Math.floor(xp));
|
|
39
|
+
const x1 = x0 + 1;
|
|
40
|
+
const y0 = this.int(Math.floor(yp));
|
|
41
|
+
const y1 = y0 + 1;
|
|
42
|
+
|
|
43
|
+
const f1 = getPixel(octave, y0, x0);
|
|
44
|
+
const f2 = getPixel(octave, y0, x1);
|
|
45
|
+
const f3 = getPixel(octave, y1, x0);
|
|
46
|
+
const f4 = getPixel(octave, y1, x1);
|
|
47
|
+
|
|
48
|
+
/* const x1f = float(x1);
|
|
49
|
+
const y1f = float(y1);
|
|
50
|
+
const x0f = float(x0);
|
|
51
|
+
const y0f = float(y0); */
|
|
52
|
+
|
|
53
|
+
// ratio for interpolation between four neighbouring points
|
|
54
|
+
const value =
|
|
55
|
+
(x1 - xp) * (y1 - yp) * f1 +
|
|
56
|
+
(xp - x0) * (y1 - yp) * f2 +
|
|
57
|
+
(x1 - xp) * (yp - y0) * f3 +
|
|
58
|
+
(xp - x0) * (yp - y0) * f4;
|
|
59
|
+
|
|
60
|
+
this.setOutput(value);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return kernel;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const computeExtremaFreak = (args) => {
|
|
68
|
+
/** @type {import('@tensorflow/tfjs').TensorInfo} */
|
|
69
|
+
const {
|
|
70
|
+
gaussianImagesT,
|
|
71
|
+
prunedExtremas,
|
|
72
|
+
prunedExtremasAngles,
|
|
73
|
+
freakPointsT,
|
|
74
|
+
pyramidImagesLength,
|
|
75
|
+
} = args.inputs;
|
|
76
|
+
/** @type {MathBackendCPU} */
|
|
77
|
+
const backend = args.backend;
|
|
78
|
+
const prog = GetProgram(prunedExtremas.shape[0], pyramidImagesLength);
|
|
79
|
+
return FakeShader.runCode(
|
|
80
|
+
backend,
|
|
81
|
+
prog,
|
|
82
|
+
[...gaussianImagesT, prunedExtremas, prunedExtremasAngles, freakPointsT],
|
|
83
|
+
"float32",
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const computeExtremaFreakConfig = {
|
|
88
|
+
//: KernelConfig
|
|
89
|
+
kernelName: "ComputeExtremaFreak",
|
|
90
|
+
backendName: "cpu",
|
|
91
|
+
kernelFunc: computeExtremaFreak, // as {} as KernelFunc,
|
|
92
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { FREAKPOINTS } from "../../freak.js";
|
|
2
|
+
|
|
3
|
+
const FREAK_CONPARISON_COUNT = ((FREAKPOINTS.length - 1) * FREAKPOINTS.length) / 2;
|
|
4
|
+
const descriptorCount = Math.ceil(FREAK_CONPARISON_COUNT / 8);
|
|
5
|
+
|
|
6
|
+
function computeFreakDescriptorImpl(extremaFreaks, positionT) {
|
|
7
|
+
const resultValues = new Float32Array(extremaFreaks.height * descriptorCount);
|
|
8
|
+
function getP(y, x) {
|
|
9
|
+
return positionT.values[y * positionT.width + x];
|
|
10
|
+
}
|
|
11
|
+
function getFreak(y, x) {
|
|
12
|
+
return extremaFreaks.values[y * extremaFreaks.width + x];
|
|
13
|
+
}
|
|
14
|
+
function setOutput(y, x, o) {
|
|
15
|
+
resultValues[y * descriptorCount + x] = o;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
for (let featureIndex = 0; featureIndex < extremaFreaks.height; featureIndex++) {
|
|
19
|
+
for (let _descIndex = 0; _descIndex < descriptorCount; _descIndex++) {
|
|
20
|
+
const descIndex = _descIndex * 8;
|
|
21
|
+
let sum = 0;
|
|
22
|
+
for (let i = 0; i < 8; i++) {
|
|
23
|
+
if (descIndex + i >= FREAK_CONPARISON_COUNT) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const p1 = Math.trunc(getP(descIndex + i, 0));
|
|
28
|
+
const p2 = Math.trunc(getP(descIndex + i, 1));
|
|
29
|
+
|
|
30
|
+
const v1 = getFreak(featureIndex, p1);
|
|
31
|
+
const v2 = getFreak(featureIndex, p2);
|
|
32
|
+
|
|
33
|
+
if (v1 < v2 + 0.01) {
|
|
34
|
+
sum += Math.trunc(Math.pow(2.0, 7.0 - i));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
setOutput(featureIndex, _descIndex, sum);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return resultValues;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const computeFreakDescriptor = (args) => {
|
|
45
|
+
const { extremaFreaks, positionT } = args.inputs;
|
|
46
|
+
const { backend } = args;
|
|
47
|
+
|
|
48
|
+
const freaksData = {
|
|
49
|
+
values: backend.data.get(extremaFreaks.dataId).values,
|
|
50
|
+
height: extremaFreaks.shape[0],
|
|
51
|
+
width: extremaFreaks.shape[1],
|
|
52
|
+
};
|
|
53
|
+
const positionData = {
|
|
54
|
+
values: backend.data.get(positionT.dataId).values,
|
|
55
|
+
width: positionT.shape[1],
|
|
56
|
+
};
|
|
57
|
+
//backend.runWebGLProgram(program,[extremaFreaks, positionT],'int32');
|
|
58
|
+
|
|
59
|
+
const resultValues = computeFreakDescriptorImpl(freaksData, positionData);
|
|
60
|
+
return backend.makeOutput(resultValues, [extremaFreaks.shape[0], descriptorCount], "int32");
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const computeFreakDescriptorConfig = {
|
|
64
|
+
//: KernelConfig
|
|
65
|
+
kernelName: "ComputeFreakDescriptors",
|
|
66
|
+
backendName: "cpu",
|
|
67
|
+
kernelFunc: computeFreakDescriptor, // as {} as KernelFunc,
|
|
68
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { tensor } from "@tensorflow/tfjs";
|
|
2
|
+
import * as FakeShader from "./fakeShader.js";
|
|
3
|
+
|
|
4
|
+
function GetProgram(numDogPyramidImages, extremasListLength) {
|
|
5
|
+
const dogVariableNames = [];
|
|
6
|
+
|
|
7
|
+
for (let i = 1; i < numDogPyramidImages; i++) {
|
|
8
|
+
dogVariableNames.push("image" + i);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const program = {
|
|
12
|
+
variableNames: [...dogVariableNames, "extrema"],
|
|
13
|
+
outputShape: [extremasListLength, 3, 3], // 3x3 pixels around the extrema
|
|
14
|
+
userCode: function () {
|
|
15
|
+
const getPixel = (octave, y, x) => {
|
|
16
|
+
const k = "getImage" + octave;
|
|
17
|
+
if (!this.hasOwnProperty(k)) {
|
|
18
|
+
throw new Error(`ComputeLocalization:: ${k} does not exist`);
|
|
19
|
+
}
|
|
20
|
+
return this[k](y, x);
|
|
21
|
+
};
|
|
22
|
+
const coords = this.getOutputCoords();
|
|
23
|
+
const featureIndex = coords[0];
|
|
24
|
+
const score = this.getExtrema(featureIndex, 0);
|
|
25
|
+
if (score == 0.0) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const dy = coords[1] - 1;
|
|
30
|
+
const dx = coords[2] - 1;
|
|
31
|
+
const octave = this.int(this.getExtrema(featureIndex, 1));
|
|
32
|
+
const y = this.int(this.getExtrema(featureIndex, 2));
|
|
33
|
+
const x = this.int(this.getExtrema(featureIndex, 3));
|
|
34
|
+
this.setOutput(getPixel(octave, y + dy, x + dx));
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
//}
|
|
38
|
+
return program;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const int = Math.trunc;
|
|
42
|
+
function clamp(n, min, max) {
|
|
43
|
+
return Math.min(Math.max(min, n), max - 1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const computeLocalization = (args) => {
|
|
47
|
+
/** @type {import('@tensorflow/tfjs').TensorInfo} */
|
|
48
|
+
const { prunedExtremasList, dogPyramidImagesT } = args.inputs;
|
|
49
|
+
/** @type {MathBackendCPU} */
|
|
50
|
+
const backend = args.backend;
|
|
51
|
+
|
|
52
|
+
const program = GetProgram(dogPyramidImagesT.length, prunedExtremasList.length);
|
|
53
|
+
const prunedExtremasT = tensor(
|
|
54
|
+
prunedExtremasList,
|
|
55
|
+
[prunedExtremasList.length, prunedExtremasList[0].length],
|
|
56
|
+
"int32",
|
|
57
|
+
);
|
|
58
|
+
return FakeShader.runCode(
|
|
59
|
+
backend,
|
|
60
|
+
program,
|
|
61
|
+
[...dogPyramidImagesT.slice(1), prunedExtremasT],
|
|
62
|
+
dogPyramidImagesT[0].dtype,
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const computeLocalizationConfig = {
|
|
67
|
+
//: KernelConfig
|
|
68
|
+
kernelName: "ComputeLocalization",
|
|
69
|
+
backendName: "cpu",
|
|
70
|
+
kernelFunc: computeLocalization, // as {} as KernelFunc,
|
|
71
|
+
};
|