qr code detector, marker detector

This commit is contained in:
Michal Kolář
2024-03-04 18:05:35 +01:00
committed by Stanislav Fifik
parent a37605b5b4
commit 6bc3bada6b
33 changed files with 10444 additions and 1 deletions

1
.nvmrc Normal file
View File

@@ -0,0 +1 @@
14

30
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "graphfx",
"version": "0.4.4",
"version": "0.8.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -4064,6 +4064,29 @@
"resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.21.tgz",
"integrity": "sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow=="
},
"@zxing/browser": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/@zxing/browser/-/browser-0.1.4.tgz",
"integrity": "sha512-WYjaav7St4sj/u/Km2llE4NU2Pq3JFIWnczr0tmyCC1KUlp08rV3qpu7iiEB4kOx/CgcCzrSebNnSmFt5B3IFg==",
"requires": {
"@zxing/text-encoding": "^0.9.0"
}
},
"@zxing/library": {
"version": "0.20.0",
"resolved": "https://registry.npmjs.org/@zxing/library/-/library-0.20.0.tgz",
"integrity": "sha512-6Ev6rcqVjMakZFIDvbUf0dtpPGeZMTfyxYg4HkVWioWeN7cRcnUWT3bU6sdohc82O1nPXcjq6WiGfXX2Pnit6A==",
"requires": {
"@zxing/text-encoding": "~0.9.0",
"ts-custom-error": "^3.2.1"
}
},
"@zxing/text-encoding": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/@zxing/text-encoding/-/text-encoding-0.9.0.tgz",
"integrity": "sha512-U/4aVJ2mxI0aDNI8Uq0wEhMgY+u4CNtEb0om3+y3+niDAsoTCOB33UF0sxpzqzdqXLqmvc+vZyAt4O8pPdfkwA==",
"optional": true
},
"ansi-escapes": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz",
@@ -13219,6 +13242,11 @@
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
},
"ts-custom-error": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/ts-custom-error/-/ts-custom-error-3.3.1.tgz",
"integrity": "sha512-5OX1tzOjxWEgsr/YEUWSuPrQ00deKLh6D7OTWcvNHm12/7QPyRh8SYpyWvA4IZv8H/+GQWQEh/kwo95Q9OVW1A=="
},
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",

View File

@@ -38,6 +38,8 @@
"@tensorflow/tfjs-core": "^4.2.0",
"@types/css-font-loading-module": "0.0.2",
"@types/uuid": "^3.4.6",
"@zxing/browser": "^0.1.4",
"@zxing/library": "^0.20.0",
"lodash": "^4.17.21",
"uuid": "^3.3.3"
},

186
src/nodes/MarkerDetector.ts Normal file
View File

@@ -0,0 +1,186 @@
import {
ImageVar,
NumberVar,
StringVar,
} from './io/AbstractIOSet';
import Node from "./Node";
import {canvasPool2D} from "../canvas/CanvasPool";
import {mediaSize} from './canvas';
import {waitForMedia} from "../utils";
import {Detector, Marker} from '../../vendor/ts-aruco/src/aruco'
enum PivotPoint {
LEFT_TOP = "left_top",
RIGHT_TOP = "right_top",
LEFT_BOTTOM = "left_bottom",
RIGHT_BOTTOM = "right_bottom",
CENTER = "center",
}
const inputs = {
image: {
type: 'Image'
} as ImageVar,
markerId: {
type: 'Number',
} as NumberVar,
pivotPoint: {
type: 'String',
enum: [
PivotPoint.LEFT_TOP,
PivotPoint.RIGHT_TOP,
PivotPoint.LEFT_BOTTOM,
PivotPoint.RIGHT_BOTTOM,
PivotPoint.CENTER,
],
} as StringVar,
}
const outputs = {
image: {
type: 'Image'
} as ImageVar,
markerId: {
type: 'Number'
} as NumberVar,
x: {
type: 'Number'
} as NumberVar,
y: {
type: 'Number'
} as NumberVar,
rotation: {
type: 'Number'
} as NumberVar,
x1: {
type: 'Number'
} as NumberVar,
y1: {
type: 'Number'
} as NumberVar,
x2: {
type: 'Number'
} as NumberVar,
y2: {
type: 'Number'
} as NumberVar,
};
type CanvasContext = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
export default class MarkerDetector extends Node<typeof inputs, typeof outputs> {
detector: Detector;
constructor(options = {}) {
super('MarkerDetector', inputs, outputs);
this.detector = new Detector();
}
async _update() {
await waitForMedia(this.in.image.value);
const {width, height} = mediaSize(this.__in.image.value);
if (!this.in.image.value) {
return;
}
const originalImageCanvas = canvasPool2D.createCanvas();
originalImageCanvas.width = width;
originalImageCanvas.height = height;
originalImageCanvas.acquire();
const originalImageCanvasCtx = originalImageCanvas.getContext('2d');
originalImageCanvasCtx.drawImage(this.in.image.value as CanvasImageSource | OffscreenCanvas, 0, 0);
let results = this.detector.detect(originalImageCanvasCtx.getImageData(0, 0, width, height));
if (this.in.markerId.value) {
results = results.filter((marker) => marker.id === this.in.markerId.value);
}
if (results.length === 0) {
this.out.image.value = originalImageCanvas;
this.out.markerId.value = undefined;
this.out.x.value = undefined;
this.out.y.value = undefined;
this.out.rotation.value = undefined;
this.out.x1.value = undefined;
this.out.y1.value = undefined;
this.out.x2.value = undefined;
this.out.y2.value = undefined;
return;
}
const result = results[0];
const {
id,
x,
y,
rotation,
x1,
y1,
x2,
y2,
} = this.calculateOutput(result, this.in.pivotPoint.value as PivotPoint);
this.out.image.value = originalImageCanvas;
this.out.markerId.value = id;
this.out.x.value = x;
this.out.y.value = y;
this.out.rotation.value = rotation;
this.out.x1.value = x1;
this.out.y1.value = y1;
this.out.x2.value = x2;
this.out.y2.value = y2;
}
private calculateOutput(marker: Marker, pivot: PivotPoint = PivotPoint.LEFT_TOP) {
const {points} = marker.corners;
const minX = Math.min(...points.map((p) => p.x));
const minY = Math.min(...points.map((p) => p.y));
const maxX = Math.max(...points.map((p) => p.x));
const maxY = Math.max(...points.map((p) => p.y));
const w = maxX - minX;
const h = maxY - minY;
let x: number, y: number;
switch (pivot) {
case PivotPoint.CENTER:
x = minX + w / 2;
y = minY + h / 2;
break;
case PivotPoint.LEFT_TOP:
x = minX;
y = minY;
break;
case PivotPoint.RIGHT_TOP:
x = maxX;
y = minY;
break;
case PivotPoint.LEFT_BOTTOM:
x = minX;
y = maxY;
break;
case PivotPoint.RIGHT_BOTTOM:
x = maxX;
y = maxY;
break;
}
const rotation = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x) * (180 / Math.PI);
return {
id: marker.id,
x,
y,
rotation,
x1: points[0].x,
y1: points[0].y,
x2: points[1].x,
y2: points[1].y,
};
}
}

157
src/nodes/QRCodeDetector.ts Normal file
View File

@@ -0,0 +1,157 @@
import {
ImageVar,
NumberVar,
} from './io/AbstractIOSet';
import Node from "./Node";
import {canvasPool2D} from "../canvas/CanvasPool";
import {mediaSize} from './canvas';
import {OutputProperties, StringVar} from "graphfx/src/nodes/io/AbstractIOSet";
import {BrowserQRCodeReader} from "@zxing/browser";
import {Result, ResultPoint, NotFoundException} from "@zxing/library";
import {waitForMedia} from "graphfx/src/utils";
const inputs = {
image: {
type: 'Image'
} as ImageVar,
filter: {
type: 'String',
} as StringVar,
}
const outputs = {
image: {
type: 'Image'
} as ImageVar,
rotation: {
type: 'Number',
} as NumberVar,
x: {
type: 'Number',
} as NumberVar,
y: {
type: 'Number',
} as NumberVar,
size: {
type: 'Number',
} as NumberVar,
};
type CanvasContext = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
export default class QRCodeDetector extends Node<typeof inputs, typeof outputs> {
reader: BrowserQRCodeReader;
constructor(options = {}) {
super('QRCodeDetector', inputs, outputs);
this.reader = new BrowserQRCodeReader();
}
async _update() {
await waitForMedia(this.in.image.value);
const {width, height} = mediaSize(this.__in.image.value);
if (!this.in.image.value) {
return;
}
const originalImageCanvas = canvasPool2D.createCanvas();
originalImageCanvas.width = width;
originalImageCanvas.height = height;
originalImageCanvas.acquire();
const originalCanvasCtx = originalImageCanvas.getContext('2d');
originalCanvasCtx.drawImage(this.in.image.value as CanvasImageSource | OffscreenCanvas, 0, 0);
this.out.rotation.value = 0;
this.out.size.value = 0;
this.out.x.value = 0;
this.out.y.value = 0;
while (true) {
try {
// @ts-ignore
const result = this.reader.decodeFromCanvas(originalImageCanvas);
const {
rotation,
size,
x,
y,
} = this.coverQRCode(originalCanvasCtx, result);
if (!this.in.filter.value || result.getText() === this.in.filter.value) {
this.out.rotation.value = rotation;
this.out.size.value = size;
this.out.x.value = x;
this.out.y.value = y;
// this.out.image.value = this.in.image.value;
this.out.image.value = this.in.image.value;
break;
}
} catch (e) {
if (e instanceof NotFoundException) {
break;
}
this.out.image.value = this.in.image.value;
console.log(e);
break;
}
}
}
private calculateDistance = (point1: ResultPoint, point2: ResultPoint) => {
const dx = point1.getX() - point2.getX();
const dy = point1.getY() - point2.getY();
return Math.sqrt(dx * dx + dy * dy);
};
private calculateRotation = (point1: ResultPoint, point2: ResultPoint) => {
const dx = point2.getX() - point1.getX();
const dy = point2.getY() - point1.getY();
return Math.atan2(dy, dx);
};
private coverQRCode(ctx: CanvasContext, result: Result) {
const resultPoints = result.getResultPoints();
if (resultPoints.length < 3) {
console.error('Probably not a QR code')
return;
}
// @ts-ignore estimatedModuleSize is not a part of the public API but we need that value
const qrCodeWidth = this.calculateDistance(resultPoints[0], resultPoints[2]) - resultPoints[0].estimatedModuleSize * 6;
// @ts-ignore estimatedModuleSize is not a part of the public API but we need that value
const finderPatternWidth = resultPoints[0].estimatedModuleSize * 7;
const rotation = this.calculateRotation(resultPoints[0], resultPoints[1]);
// Save the current context state
ctx.save();
// Translate to the center of the top left finder pattern
ctx.translate(resultPoints[0].getX(), resultPoints[0].getY());
// Rotate the context
ctx.rotate(rotation);
// Draw the rectangle
ctx.beginPath();
ctx.rect(-finderPatternWidth / 2, -finderPatternWidth / 2, qrCodeWidth + finderPatternWidth, qrCodeWidth + finderPatternWidth);
ctx.fillStyle = '#FF0000';
ctx.fill();
// Restore the context state
ctx.restore();
const x = (resultPoints[0].getX() + resultPoints[2].getX()) / 2;
const y = (resultPoints[0].getY() + resultPoints[2].getY()) / 2;
return {
// rotation here is in radians and I know it's -90deg, so I need to add 90deg to it
rotation: rotation + Math.PI / 2,
size: qrCodeWidth,
x,
y,
}
}
}

View File

@@ -31,3 +31,5 @@ export {default as BodySegmentation} from './AI/BodySegmentation';
export {default as BodyPartSegmentation} from './AI/BodyPartSegmentation';
export {default as FaceFeaturePosition} from './AI/FaceFeaturePosition';
export {default as Eval} from './Eval';
export {default as QRCodeDetector} from './QRCodeDetector';
export {default as MarkerDetector} from './MarkerDetector';

22
vendor/ts-aruco/.eslintrc.js vendored Normal file
View File

@@ -0,0 +1,22 @@
module.exports = {
ignorePatterns: [
"dist",
"node_modules",
".eslintrc.js",
"samples/vite.config.js",
],
env: {
browser: true,
es2021: true,
},
extends: "standard-with-typescript",
overrides: [],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
rules: {
"@typescript-eslint/semi": [2, "always"],
},
};

View File

@@ -0,0 +1,44 @@
name: Publish to github pages
run-name: ${{ github.actor }} is publishing to GitHub Actions 🚀
on: [push, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Build examples
run: |
cd samples
npm ci
npm run build
# - name: Fix permissions
# run: |
# chmod -c -R +rX "_site/" | while read line; do
# echo "::warning title=Invalid file permissions automatically fixed::$line"
# done
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: "samples/dist"
deploy:
# Add a dependency to the build job
needs: build
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# Specify runner + deployment step
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4 # or the latest "vX.X.X" version tag for this action

1
vendor/ts-aruco/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/node_modules

152
vendor/ts-aruco/LICENSE.txt vendored Normal file
View File

@@ -0,0 +1,152 @@
Copyright (c) 2011 Juan Mellado
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
ArUco
====
BSD License
OpenCV
======
IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
By downloading, copying, installing or using the software you agree to this license.
If you do not agree to this license, do not download, install,
copy or use the software.
License Agreement
For Open Source Computer Vision Library
Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
Copyright (C) 2009, Willow Garage Inc., all rights reserved.
Third party copyrights are property of their respective owners.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistribution's of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistribution's in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of the copyright holders may not be used to endorse or promote products
derived from this software without specific prior written permission.
This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are disclaimed.
In no event shall the Intel Corporation or contributors be liable for any direct,
indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused
and on any theory of liability, whether in contract, strict liability,
or tort (including negligence or otherwise) arising in any way out of
the use of this software, even if advised of the possibility of such damage.
AForge.NET
========
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
StackBoxBlur
==========
Copyright (c) 2010 Mario Klingemann
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

126
vendor/ts-aruco/README.md vendored Normal file
View File

@@ -0,0 +1,126 @@
**js-aruco** is a port to JavaScript of the ArUco library.
[ArUco](http://www.uco.es/investiga/grupos/ava/node/26) is a minimal library for Augmented Reality applications based on OpenCv.
### Demos ###
100% JavaScript (see details bellow):
- [Webcam live demo!](https://jcmellado.github.io/js-aruco/getusermedia/getusermedia.html)
3D Pose Estimation:
- [3D Earth!](https://jcmellado.github.io/js-aruco/debug-posit/debug-posit.html)
Visual Debugging:
- [Debug session jam!](https://jcmellado.github.io/js-aruco/debug/debug.html)
Flash camera access (see details bellow):
- [Webcam live demo!](https://jcmellado.github.io/js-aruco/webcam/webcam.html)
### Videos ###
Webcam video adquisition:
[![js-aruco](http://img.youtube.com/vi/_wzPupbww4I/0.jpg)](http://www.youtube.com/watch?v=_wzPupbww4I)
3D Pose estimation:
[![js-aruco](http://img.youtube.com/vi/9WD4wR3_-JM/0.jpg)](http://www.youtube.com/watch?v=9WD4wR3_-JM)
Visual Debugging:
[![js-aruco](http://img.youtube.com/vi/xvTMRdgySUQ/0.jpg)](http://www.youtube.com/watch?v=xvTMRdgySUQ)
### Markers ###
A 7x7 grid with an external unused black border. Internal 5x5 cells contains id information.
Each row must follow any of the following patterns:
`white - black - black - black - black`
`white - black - white - white - white`
`black - white - black - black - white`
`black - white - white - white - black`
Example:
![Marker](http://www.inmensia.com/files/pictures/external/1001.png)
### Usage ###
Create an `AR.Detector` object:
```
var detector = new AR.Detector();
```
Call `detect` function:
```
var markers = detector.detect(imageData);
```
`markers` result will be an array of `AR.Marker` objects with detected markers.
`AR.Marker` objects have two properties:
* `id`: Marker id.
* `corners`: 2D marker corners.
`imageData` argument must be a valid `ImageData` canvas object.
```
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var imageData = context.getImageData(0, 0, width, height);
```
### 3D Pose Estimation ###
Create an `POS.Posit` object:
```
var posit = new POS.Posit(modelSize, canvas.width);
```
`modelSize` argument must be the real marker size (millimeters).
Call `pose` function:
```
var pose = posit.pose(corners);
```
`corners` must be centered on canvas:
```
var corners = marker.corners;
for (var i = 0; i < corners.length; ++ i){
var corner = corners[i];
corner.x = corner.x - (canvas.width / 2);
corner.y = (canvas.height / 2) - corner.y;
}
```
`pose` result will be a `POS.Pose` object with two estimated pose (if any):
* `bestError`: Error of the best estimated pose.
* `bestRotation`: 3x3 rotation matrix of the best estimated pose.
* `bestTranslation`: Translation vector of the best estimated pose.
* `alternativeError`: Error of the alternative estimated pose.
* `alternativeRotation`: 3x3 rotation matrix of the alternative estimated pose.
* `alternativeTranslation`: Translation vector of the alternative estimated pose.
Note: POS namespace can be taken from posit1.js or posit2.js.
### Flash Demo (deprecated) ###
It uses [Flashcam](https://github.com/jcmellado/flashcam), a minimal Flash library to capture video.

5362
vendor/ts-aruco/package-lock.json generated vendored Normal file

File diff suppressed because it is too large Load Diff

35
vendor/ts-aruco/package.json vendored Normal file
View File

@@ -0,0 +1,35 @@
{
"name": "ts-aruco",
"version": "0.0.1",
"description": "TypeScript port of jcmellado's ArUco library",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/axeljaeger/ts-aruco.git"
},
"keywords": [
"aruco",
"markers",
"augmented",
"reality",
"typescript"
],
"author": "Axel Jäger",
"license": "ISC",
"bugs": {
"url": "https://github.com/axeljaeger/ts-aruco/issues"
},
"homepage": "https://github.com/axeljaeger/ts-aruco#readme",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.21.0",
"eslint": "^8.57.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"typescript": "^5.3.3"
}
}

24
vendor/ts-aruco/samples/.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@@ -0,0 +1,41 @@
<html>
<head>
<title>Augmented Reality</title>
<script type="module" src="/src/debug-posit.ts"></script>
<script>
</script>
</head>
<body style="text-align: center; font-family: monospace;">
<video id="video" width=320 height=240 autoplay="true" style="display:none;"></video>
<div style="margin: 10px;"><strong>-= Augmented Reality =-</strong></div>
<div style="width: 100%;">
<div style="width: 650px; margin-left:auto; margin-right:auto;">
<canvas id="canvas" style="width: 320px; height: 240px; float: left; border: solid 1px black;"></canvas>
<div id="container" style="width: 320px; height: 240px; float: left; border: solid 1px black; background: green;">
</div>
<div style="clear: both;"></div>
<div style="float: left; border: solid 1px black;">
<div id="container1" style="width: 320px; height: 240px; background: red;"></div>
<div id="pose1"></div>
</div>
<div style="float: left; border: solid 1px black;">
<div id="container2" style="width: 320px; height: 240px; background: blue;"></div>
<div id="pose2"></div>
</div>
</div>
</div>
<div style="clear: both;"></div>
<div style="margin: 15px;"><strong>Powered by <a href="http://code.google.com/p/js-aruco/">js-aruco</a> and <a
href="https://github.com/mrdoob/three.js">Three.js</a></strong></div>
</body>
</html>

21
vendor/ts-aruco/samples/debug.html vendored Normal file
View File

@@ -0,0 +1,21 @@
<html>
<head>
<title>Augmented Reality Marker Detector</title>
<script type="module" src="/src/debug.ts"></script>
</head>
<body style="font-family: monospace;">
<center>
<div style="margin: 10px;"><strong>-= Augmented Reality Marker Detector =-</strong></div>
<video id="video" autoplay="true" style="width:320px; height:240px; display:none;"></video>
<canvas id="canvas" style="width:960px; height:620px;"></canvas>
<div style="margin: 15px;"><strong>Powered by <a href="http://code.google.com/p/js-aruco/">js-aruco</a></strong>
</div>
</center>
</body>
</html>

View File

@@ -0,0 +1,19 @@
<html>
<head>
<title>Augmented Reality Marker Detector</title>
</head>
<body style="font-family: monospace;">
<script type="module" src="/src/getusermedia.ts"></script>
<center>
<div style="margin: 10px;"><strong>-= Augmented Reality Marker Detector =-</strong></div>
<video id="video" autoplay="true" style="display:none;"></video>
<canvas id="canvas" style="width:640px; height:480px;"></canvas>
<div style="margin: 15px;"><strong>Powered by <a href="http://code.google.com/p/js-aruco/">js-aruco</a></strong>
</div>
</center>
</body>
</html>

18
vendor/ts-aruco/samples/index.html vendored Normal file
View File

@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Aruco Examples ported to typescript</title>
</head>
<body>
<h1>Aruco demos</h1>
<a href="debug.html">Debug</a>
<a href="debug-posit.html">Debug Posit</a>
<a href="getusermedia.html">Get user media</a>
</body>
</html>

1226
vendor/ts-aruco/samples/package-lock.json generated vendored Normal file

File diff suppressed because it is too large Load Diff

19
vendor/ts-aruco/samples/package.json vendored Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "samples",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"@types/three": "^0.161.2",
"typescript": "^5.2.2",
"vite": "^5.1.4"
},
"dependencies": {
"three": "^0.161.0"
}
}

BIN
vendor/ts-aruco/samples/public/earth.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

View File

@@ -0,0 +1,264 @@
import { Detector, type Marker } from '../../src/aruco';
import { type CVPoint } from '../../src/cv';
import { Posit } from '../../src/posit1';
import * as THREE from 'three';
let video: HTMLVideoElement;
let canvas: HTMLCanvasElement;
let context: CanvasRenderingContext2D;
let imageData: ImageData;
let detector: Detector;
let posit: Posit;
let renderer1: THREE.WebGLRenderer;
let renderer2: THREE.WebGLRenderer;
let renderer3: THREE.WebGLRenderer;
let scene1: THREE.Scene;
let scene2: THREE.Scene;
let scene3: THREE.Scene;
let scene4: THREE.Scene;
let camera1: THREE.PerspectiveCamera;
let camera2: THREE.PerspectiveCamera;
let camera3: THREE.OrthographicCamera;
let camera4: THREE.PerspectiveCamera;
let plane1: THREE.Object3D;
let plane2: THREE.Object3D;
let model: THREE.Object3D;
let texture: THREE.Object3D;
let step = 0.0;
const modelSize = 35.0; // millimeters
function onLoad(): void {
video = document.getElementById('video') as HTMLVideoElement;
canvas = document.getElementById('canvas') as HTMLCanvasElement;
context = canvas.getContext('2d') as CanvasRenderingContext2D;
canvas.width = parseInt(canvas.style.width);
canvas.height = parseInt(canvas.style.height);
navigator.mediaDevices
.getUserMedia({ video: true })
.then(function (stream) {
video.srcObject = stream;
})
.catch(function (err) {
console.log(err.name + ': ' + err.message);
}
);
detector = new Detector();
posit = new Posit(modelSize, canvas.width);
createRenderers();
createScenes();
requestAnimationFrame(tick);
};
function tick(): void {
requestAnimationFrame(tick);
if (video.readyState === video.HAVE_ENOUGH_DATA) {
snapshot();
const markers: Marker[] = detector.detect(imageData);
drawCorners(markers);
updateScenes(markers);
render();
}
};
function snapshot(): void {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
imageData = context.getImageData(0, 0, canvas.width, canvas.height);
};
function drawCorners(markers: Marker[]): void {
context.lineWidth = 3;
for (let i = 0; i < markers.length; ++i) {
const corners = markers[i].corners;
context.strokeStyle = 'red';
context.beginPath();
for (let j = 0; j < corners.points.length; ++j) {
let corner: CVPoint = corners.points[j];
context.moveTo(corner.x, corner.y);
corner = corners.points[(j + 1) % corners.points.length];
context.lineTo(corner.x, corner.y);
}
context.stroke();
context.closePath();
context.strokeStyle = 'green';
context.strokeRect(corners.points[0].x - 2, corners.points[0].y - 2, 4, 4);
}
};
function createRenderers(): void {
renderer1 = new THREE.WebGLRenderer();
renderer1.setClearColor(0xffff00, 1);
renderer1.setSize(canvas.width, canvas.height);
document.getElementById('container1')!.appendChild(renderer1.domElement);
scene1 = new THREE.Scene();
camera1 = new THREE.PerspectiveCamera(40, canvas.width / canvas.height, 1, 1000);
scene1.add(camera1);
renderer2 = new THREE.WebGLRenderer();
renderer2.setClearColor(0xffff00, 1);
renderer2.setSize(canvas.width, canvas.height);
document.getElementById('container2')!.appendChild(renderer2.domElement);
scene2 = new THREE.Scene();
camera2 = new THREE.PerspectiveCamera(40, canvas.width / canvas.height, 1, 1000);
scene2.add(camera2);
renderer3 = new THREE.WebGLRenderer();
renderer3.setClearColor(0xffffff, 1);
renderer3.setSize(canvas.width, canvas.height);
document.getElementById('container')!.appendChild(renderer3.domElement);
scene3 = new THREE.Scene();
camera3 = new THREE.OrthographicCamera(-0.5, 0.5, 0.5, -0.5);
scene3.add(camera3);
scene4 = new THREE.Scene();
camera4 = new THREE.PerspectiveCamera(40, canvas.width / canvas.height, 1, 1000);
scene4.add(camera4);
};
function render(): void {
renderer1.clear();
renderer1.render(scene1, camera1);
renderer2.clear();
renderer2.render(scene2, camera2);
renderer3.autoClear = false;
renderer3.clear();
renderer3.render(scene3, camera3);
renderer3.render(scene4, camera4);
};
function createScenes(): void {
plane1 = createPlane();
scene1.add(plane1);
plane2 = createPlane();
scene2.add(plane2);
texture = createTexture();
scene3.add(texture);
model = createModel();
scene4.add(model);
};
function createPlane(): THREE.Object3D {
const object = new THREE.Object3D();
const geometry = new THREE.PlaneGeometry(1, 1);
const material = new THREE.MeshNormalMaterial();
const mesh = new THREE.Mesh(geometry, material);
object.rotation.order = 'YXZ';
object.add(mesh);
return object;
};
function createTexture(): THREE.Object3D {
const texture = new THREE.VideoTexture(video);
const object = new THREE.Object3D();
const geometry = new THREE.PlaneGeometry(1.0, 1.0);
const material = new THREE.MeshBasicMaterial({ map: texture, depthTest: false, depthWrite: false });
const mesh = new THREE.Mesh(geometry, material);
object.position.z = -1;
object.add(mesh);
return object;
};
function createModel(): THREE.Object3D {
const object = new THREE.Object3D();
const geometry = new THREE.SphereGeometry(0.5, 15, 15, Math.PI);
const texture = new THREE.TextureLoader().load('earth.jpg');
const material = new THREE.MeshBasicMaterial({ map: texture });
const mesh = new THREE.Mesh(geometry, material);
object.add(mesh);
return object;
};
function updateScenes(markers: Marker[]): void {
if (markers.length > 0) {
const corners = markers[0].corners;
for (let i = 0; i < corners.points.length; ++i) {
const corner = corners.points[i];
corner.x = corner.x - (canvas.width / 2);
corner.y = (canvas.height / 2) - corner.y;
}
const pose = posit.pose(corners.points);
updateObject(plane1, pose.bestRotation, pose.bestTranslation);
updateObject(plane2, pose.alternativeRotation, pose.alternativeTranslation);
updateObject(model, pose.bestRotation, pose.bestTranslation);
updatePose('pose1', pose.bestError, pose.bestRotation, pose.bestTranslation);
updatePose('pose2', pose.alternativeError, pose.alternativeRotation, pose.alternativeTranslation);
step += 0.025;
model.rotation.z -= step;
}
// //@ts-ignore
//texture.children[0].material.map.needsUpdate = true;
};
function updateObject(object: THREE.Object3D, rotation: number[][], translation: number[]): void {
object.scale.x = modelSize;
object.scale.y = modelSize;
object.scale.z = modelSize;
object.rotation.x = -Math.asin(-rotation[1][2]);
object.rotation.y = -Math.atan2(rotation[0][2], rotation[2][2]);
object.rotation.z = Math.atan2(rotation[1][0], rotation[1][1]);
object.position.x = translation[0];
object.position.y = translation[1];
object.position.z = -translation[2];
};
function updatePose(id: string, error: number, rotation: number[][], translation: number[]): void {
const yaw = -Math.atan2(rotation[0][2], rotation[2][2]);
const pitch = -Math.asin(-rotation[1][2]);
const roll = Math.atan2(rotation[1][0], rotation[1][1]);
const d = document.getElementById(id);
if (d !== null) {
d.innerHTML = ' error: ' + error +
'<br/>' +
' x: ' + (translation[0] | 0) +
' y: ' + (translation[1] | 0) +
' z: ' + (translation[2] | 0) +
'<br/>' +
' yaw: ' + Math.round(-yaw * 180.0 / Math.PI) +
' pitch: ' + Math.round(-pitch * 180.0 / Math.PI) +
' roll: ' + Math.round(roll * 180.0 / Math.PI);
}
};
window.onload = onLoad;

170
vendor/ts-aruco/samples/src/debug.ts vendored Normal file
View File

@@ -0,0 +1,170 @@
import { Detector, type Marker } from '../../src/aruco.ts';
import { type CVContour, otsu, threshold, warp } from '../../src/cv.ts';
let camera: HTMLVideoElement;
let canvas: HTMLCanvasElement;
let context: CanvasRenderingContext2D;
let imageData: ImageData;
let detector: Detector;
let debugImage: ImageData;
let warpImage: ImageData;
let homographyImage: ImageData;
export const onLoad = (): void => {
camera = document.getElementById('video') as HTMLVideoElement;
canvas = document.getElementById('canvas') as HTMLCanvasElement;
context = canvas!.getContext('2d')!;
camera.width = 320;
camera.height = 240;
canvas.width = parseInt(canvas.style.width);
canvas.height = parseInt(canvas.style.height);
navigator.mediaDevices
.getUserMedia({ video: true })
.then((stream) => {
camera.srcObject = stream;
})
.catch(function (err) {
console.log(err.name + ': ' + err.message);
}
);
imageData = context.getImageData(0, 0, camera.width, camera.height);
detector = new Detector();
debugImage = context.createImageData(camera.width, camera.height);
warpImage = context.createImageData(49, 49);
requestAnimationFrame(tick);
};
const tick = (): void => {
requestAnimationFrame(tick);
if (camera.readyState === camera.HAVE_ENOUGH_DATA) {
snapshot();
const markers = detector.detect(imageData);
drawDebug();
drawCorners(markers);
drawId(markers);
}
};
const snapshot = (): void => {
context.drawImage(camera, 0, 0, camera.width, camera.height);
imageData = context.getImageData(0, 0, camera.width, camera.height);
};
const drawDebug = (): void => {
const width = camera.width; const height = camera.height;
context.clearRect(0, 0, canvas.width, canvas.height);
context.putImageData(imageData, 0, 0);
context.putImageData(createImage(detector.grey!, debugImage), width, 0);
context.putImageData(createImage(detector.thres!, debugImage), width * 2, 0);
drawContours(detector.contours, 0, height, function (hole: any) { return hole ? 'magenta' : 'blue'; });
drawContours(detector.polys, width, height, function () { return 'green'; });
drawContours(detector.candidates, width * 2, height, function () { return 'red'; });
drawWarps(detector.grey!, detector.candidates, height * 2 + 20);
};
const drawContours = (contours: CVContour[], x: number, y: number, fn: any): void => {
let i = contours.length; let j; let contour; let point;
while (i--) {
contour = contours[i];
context.strokeStyle = fn(contour.hole);
context.beginPath();
for (j = 0; j < contour.points?.length; ++j) {
point = contour.points[j];
context.moveTo(x + point.x, y + point.y);
point = contour.points[(j + 1) % contour.points.length];
context.lineTo(x + point.x, y + point.y);
}
context.stroke();
context.closePath();
}
};
const drawWarps = (imageSrc: ImageData, contours: CVContour[], y: number): void => {
let i = contours.length;
let contour;
const offset = (canvas.width - ((warpImage.width + 10) * contours.length)) / 2;
while (i--) {
contour = contours[i];
homographyImage = warp(imageSrc, contour, warpImage.width);
context.putImageData(createImage(homographyImage, warpImage), offset + i * (warpImage.width + 10), y);
homographyImage = threshold(homographyImage, otsu(homographyImage));
context.putImageData(createImage(homographyImage, warpImage), offset + i * (warpImage.width + 10), y + 60);
}
};
const drawCorners = (markers: Marker[]): void => {
context.lineWidth = 3;
for (let i = 0; i !== markers.length; ++i) {
const corners = markers[i].corners.points;
context.strokeStyle = 'red';
context.beginPath();
for (let j = 0; j !== corners.length; ++j) {
let corner = corners[j];
context.moveTo(corner.x, corner.y);
corner = corners[(j + 1) % corners.length];
context.lineTo(corner.x, corner.y);
}
context.stroke();
context.closePath();
context.strokeStyle = 'green';
context.strokeRect(corners[0].x - 2, corners[0].y - 2, 4, 4);
}
};
const drawId = (markers: Marker[]): void => {
context.strokeStyle = 'blue';
context.lineWidth = 1;
for (let i = 0; i !== markers.length; ++i) {
const corners = markers[i].corners.points;
let x = Infinity;
let y = Infinity;
for (let j = 0; j !== corners.length; ++j) {
const corner = corners[j];
x = Math.min(x, corner.x);
y = Math.min(y, corner.y);
}
context.strokeText(`${markers[i].id}`, x, y);
}
};
const createImage = (src: ImageData, dst: ImageData): ImageData => {
let i = src.data.length; let j = (i * 4) + 3;
while (i--) {
dst.data[j -= 4] = 255;
dst.data[j - 1] = dst.data[j - 2] = dst.data[j - 3] = src.data[i];
}
return dst;
};
window.onload = onLoad;

View File

@@ -0,0 +1,97 @@
import { Detector, type Marker } from '../../src/aruco.ts';
let video: HTMLVideoElement;
let canvas: HTMLCanvasElement;
let context: CanvasRenderingContext2D;
let imageData: ImageData;
let detector: Detector;
const onLoad = (): void => {
video = document.getElementById('video')! as HTMLVideoElement;
canvas = document.getElementById('canvas')! as HTMLCanvasElement;
context = canvas.getContext('2d')!;
canvas.width = parseInt(canvas.style.width);
canvas.height = parseInt(canvas.style.height);
navigator.mediaDevices
.getUserMedia({ video: true })
.then(function (stream) {
video.srcObject = stream;
})
.catch(function (err) {
console.log(err.name + ': ' + err.message);
}
);
detector = new Detector();
requestAnimationFrame(tick);
};
const tick = (): void => {
requestAnimationFrame(tick);
if (video.readyState === video.HAVE_ENOUGH_DATA) {
snapshot();
const markers = detector.detect(imageData);
drawCorners(markers);
drawId(markers);
}
};
const snapshot = (): void => {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
imageData = context.getImageData(0, 0, canvas.width, canvas.height);
};
const drawCorners = (markers: Marker[]): void => {
let corners, corner, i, j;
context.lineWidth = 3;
for (i = 0; i !== markers.length; ++i) {
corners = markers[i].corners.points;
context.strokeStyle = 'red';
context.beginPath();
for (j = 0; j !== corners.length; ++j) {
corner = corners[j];
context.moveTo(corner.x, corner.y);
corner = corners[(j + 1) % corners.length];
context.lineTo(corner.x, corner.y);
}
context.stroke();
context.closePath();
context.strokeStyle = 'green';
context.strokeRect(corners[0].x - 2, corners[0].y - 2, 4, 4);
}
};
const drawId = (markers: Marker[]): void => {
let corners, corner, x, y, i, j;
context.strokeStyle = 'blue';
context.lineWidth = 1;
for (i = 0; i !== markers.length; ++i) {
corners = markers[i].corners.points;
x = Infinity;
y = Infinity;
for (j = 0; j !== corners.length; ++j) {
corner = corners[j];
x = Math.min(x, corner.x);
y = Math.min(y, corner.y);
}
context.strokeText(`${markers[i].id}`, x, y);
}
};
window.onload = onLoad;

View File

@@ -0,0 +1 @@
/// <reference types="vite/client" />

23
vendor/ts-aruco/samples/tsconfig.json vendored Normal file
View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}

16
vendor/ts-aruco/samples/vite.config.js vendored Normal file
View File

@@ -0,0 +1,16 @@
import { resolve } from "path";
import { defineConfig } from "vite";
export default defineConfig({
base: "https://axeljaeger.github.io/ts-aruco/",
build: {
rollupOptions: {
input: {
index: resolve(__dirname, "index.html"),
getusermedia: resolve(__dirname, "getusermedia.html"),
debug: resolve(__dirname, "debug.html"),
debugPosit: resolve(__dirname, "debug-posit.html"),
},
},
},
});

284
vendor/ts-aruco/src/aruco.ts vendored Normal file
View File

@@ -0,0 +1,284 @@
/*
Copyright (c) 2011 Juan Mellado
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
References:
- "ArUco: a minimal library for Augmented Reality applications based on OpenCv"
http://www.uco.es/investiga/grupos/ava/node/26
*/
import { type CVContour, adaptiveThreshold, approxPolyDP, countNonZero, findContours, grayscale, isContourConvex, minEdgeLength, otsu, perimeter, threshold, warp } from './cv';
export interface Marker {
id: number
corners: CVContour
}
export class Detector {
binary: number[] = [];
contours: CVContour[] = [];
polys: CVContour[] = [];
candidates: CVContour[] = [];
grey: ImageData | null = null;
thres: ImageData | null = null;
detect (image: ImageData): Marker[] {
this.grey = grayscale(image);
this.thres = adaptiveThreshold(this.grey, 2, 7);
this.contours = findContours(this.thres, this.binary);
this.candidates = this.findCandidates(this.contours, image.width * 0.20, 0.05, 10);
this.candidates = this.clockwiseCorners(this.candidates);
this.candidates = this.notTooNear(this.candidates, 10);
return this.findMarkers(this.grey, this.candidates, 49);
}
findCandidates (contours: CVContour[], minSize: number, epsilon: number, minLength: number): CVContour[] {
const candidates: CVContour[] = [];
const len = contours.length;
let contour;
this.polys = [];
for (let i = 0; i < len; ++i) {
contour = contours[i];
if (contour.points.length >= minSize) {
const poly = approxPolyDP(contour.points, contour.points.length * epsilon);
this.polys.push({
points: poly,
hole: false,
tooNear: false
});
if ((poly.length === 4) && (isContourConvex(poly))) {
if (minEdgeLength(poly) >= minLength) {
candidates.push({
points: poly,
hole: false,
tooNear: false
});
}
}
}
}
return candidates;
};
clockwiseCorners (candidates: CVContour[]): CVContour[] {
const len = candidates.length;
for (let i = 0; i < len; ++i) {
const candidatePoints = candidates[i].points;
const dx1 = candidatePoints[1]?.x - candidatePoints[0].x;
const dy1 = candidatePoints[1]?.y - candidatePoints[0].y;
const dx2 = candidatePoints[2]?.x - candidatePoints[0].x;
const dy2 = candidatePoints[2]?.y - candidatePoints[0].y;
if ((dx1 * dy2 - dy1 * dx2) < 0) {
const swap = candidatePoints[1];
candidatePoints[1] = candidatePoints[3];
candidatePoints[3] = swap;
}
}
return candidates;
};
notTooNear (candidates: CVContour[], minDist: number): CVContour[] {
const notTooNear: CVContour[] = [];
const len = candidates.length;
for (let i = 0; i < len; ++i) {
for (let j = i + 1; j < len; ++j) {
let dist = 0;
for (let k = 0; k < 4; ++k) {
const dx = candidates[i].points[k].x - candidates[j].points[k].x;
const dy = candidates[i].points[k].y - candidates[j].points[k].y;
dist += dx * dx + dy * dy;
}
if ((dist / 4) < (minDist * minDist)) {
if (perimeter(candidates[i]) < perimeter(candidates[j])) {
candidates[i].tooNear = true;
} else {
candidates[j].tooNear = true;
}
}
}
}
for (let i = 0; i < len; ++i) {
if (!candidates[i].tooNear) {
notTooNear.push(candidates[i]);
}
}
return notTooNear;
};
findMarkers (imageSrc: ImageData, candidates: CVContour[], warpSize: number): Marker[] {
const markers: Marker[] = [];
const len = candidates.length;
for (let i = 0; i < len; ++i) {
const candidate = candidates[i];
const warped = warp(imageSrc, candidate, warpSize);
const threshhold = threshold(warped, otsu(warped));
const marker = this.getMarker(threshhold, candidate);
if (marker !== null) {
markers.push(marker);
}
}
return markers;
}
getMarker (imageSrc: ImageData, candidate: CVContour): Marker | null {
const width = (imageSrc.width / 7) >>> 0;
const minZero = (width * width) >> 1;
const bits: number[][] = [];
const rotations: number[][][] = [];
const distances: number[] = [];
let square;
let inc;
for (let i = 0; i < 7; ++i) {
inc = (i === 0 || i === 6) ? 1 : 6;
for (let j = 0; j < 7; j += inc) {
square = { x: j * width, y: i * width, width, height: width };
if (countNonZero(imageSrc, square) > minZero) {
return null;
}
}
}
for (let i = 0; i < 5; ++i) {
bits[i] = [];
for (let j = 0; j < 5; ++j) {
square = { x: (j + 1) * width, y: (i + 1) * width, width, height: width };
bits[i][j] = countNonZero(imageSrc, square) > minZero ? 1 : 0;
}
}
rotations[0] = bits;
distances[0] = this.hammingDistance(rotations[0]);
const pair = { first: distances[0], second: 0 };
for (let i = 1; i < 4; ++i) {
rotations[i] = this.rotate(rotations[i - 1]);
distances[i] = this.hammingDistance(rotations[i]);
if (distances[i] < pair.first) {
pair.first = distances[i];
pair.second = i;
}
}
if (pair.first !== 0) {
return null;
}
return {
id: this.mat2id(rotations[pair.second]),
corners: this.rotate2(candidate, 4 - pair.second)
};
};
hammingDistance (bits: number[][]): number {
const ids = [[1, 0, 0, 0, 0], [1, 0, 1, 1, 1], [0, 1, 0, 0, 1], [0, 1, 1, 1, 0]];
let dist = 0;
for (let i = 0; i < 5; ++i) {
let minSum = Infinity;
for (let j = 0; j < 4; ++j) {
let sum = 0;
for (let k = 0; k < 5; ++k) {
sum += bits[i][k] === ids[j][k] ? 0 : 1;
}
if (sum < minSum) {
minSum = sum;
}
}
dist += minSum;
}
return dist;
};
mat2id (bits: number[][]): number {
let id = 0;
for (let i = 0; i < 5; ++i) {
id <<= 1;
id |= bits[i][1];
id <<= 1;
id |= bits[i][3];
}
return id;
}
rotate (src: number[][]): number[][] {
const dst: number[][] = [];
const len = src.length;
for (let i = 0; i < len; ++i) {
dst[i] = [];
for (let j = 0; j < src[i].length; ++j) {
dst[i][j] = src[src[i].length - j - 1][i];
}
}
return dst;
}
rotate2 (src: CVContour, rotation: number): CVContour {
const dst: CVContour = {
points: [],
hole: false,
tooNear: false
};
const len = src.points.length;
for (let i = 0; i < len; ++i) {
dst.points[i] = src.points[(rotation + i) % len];
}
return dst;
}
}

697
vendor/ts-aruco/src/cv.ts vendored Normal file
View File

@@ -0,0 +1,697 @@
/*
Copyright (c) 2011 Juan Mellado
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
References:
- "OpenCV: Open Computer Vision Library"
http://sourceforge.net/projects/opencvlibrary/
- "Stack Blur: Fast But Goodlooking"
http://incubator.quasimondo.com/processing/fast_blur_deluxe.php
*/
interface CVSlice {
start_index: number
end_index: number
};
export interface CVPoint {
x: number
y: number
};
export interface CVContour {
points: CVPoint[]
hole: boolean
tooNear: boolean
}
export const grayscale = (imageSrc: ImageData): ImageData => {
const imageDst = new ImageData(imageSrc.width, imageSrc.height);
const src = imageSrc.data;
const dst = imageDst.data;
const len = src.length;
let j = 0;
for (let i = 0; i < len; i += 4) {
dst[j++] =
(src[i] * 0.299 + src[i + 1] * 0.587 + src[i + 2] * 0.114 + 0.5) & 0xff;
}
return imageDst;
};
export const threshold = (imageSrc: ImageData, threshold: number): ImageData => {
const src = imageSrc.data;
const imageDst = new ImageData(imageSrc.width, imageSrc.height);
const dst = imageDst.data;
const len = src.length;
const tab: number[] = [];
for (let i = 0; i < 256; ++i) {
tab[i] = i <= threshold ? 0 : 255;
}
for (let i = 0; i < len; ++i) {
dst[i] = tab[src[i]];
}
return imageDst;
};
export const adaptiveThreshold = (imageSrc: ImageData, kernelSize: number, threshold: number): ImageData => {
const src = imageSrc.data;
const imageDst = new ImageData(imageSrc.width, imageSrc.height);
const dst = imageDst.data;
const len = src.length;
const tab: number[] = [];
stackBoxBlur(imageSrc, imageDst, kernelSize);
for (let i = 0; i < 768; ++i) {
tab[i] = (i - 255 <= -threshold) ? 255 : 0;
}
for (let i = 0; i < len; ++i) {
dst[i] = tab[src[i] - dst[i] + 255];
}
return imageDst;
};
export const otsu = (imageSrc: ImageData): number => {
const src = imageSrc.data;
const len = src.length;
const hist: number[] = [];
let threshold = 0;
let sum = 0;
let sumB = 0;
let wB = 0;
let wF = 0;
let max = 0;
for (let i = 0; i < 256; ++i) {
hist[i] = 0;
}
for (let i = 0; i < len; ++i) {
hist[src[i]]++;
}
for (let i = 0; i < 256; ++i) {
sum += hist[i] * i;
}
for (let i = 0; i < 256; ++i) {
wB += hist[i];
if (wB !== 0) {
wF = len - wB;
if (wF === 0) {
break;
}
sumB += hist[i] * i;
const mu = (sumB / wB) - ((sum - sumB) / wF);
const between = wB * wF * mu * mu;
if (between > max) {
max = between;
threshold = i;
}
}
}
return threshold;
};
const stackBoxBlurMult =
[1, 171, 205, 293, 57, 373, 79, 137, 241, 27, 391, 357, 41, 19, 283, 265];
const stackBoxBlurShift =
[0, 9, 10, 11, 9, 12, 10, 11, 12, 9, 13, 13, 10, 9, 13, 13];
class BlurStack {
color: number = 0;
next: BlurStack | null = null;
};
export const stackBoxBlur = (imageSrc: ImageData, imageDst: ImageData, kernelSize: number): ImageData => {
const src = imageSrc.data;
const dst = imageDst.data;
const height = imageSrc.height;
const width = imageSrc.width;
const heightMinus1 = height - 1;
const widthMinus1 = width - 1;
const size = kernelSize + kernelSize + 1;
const radius = kernelSize + 1;
const mult = stackBoxBlurMult[kernelSize];
const shift = stackBoxBlurShift[kernelSize];
let stack: BlurStack | null;
let stackStart: BlurStack | null;
let color: number;
let sum: number;
let pos: number;
let start: number;
let p: number;
stack = stackStart = new BlurStack();
for (let i = 1; i < size; ++i) {
stack = stack.next = new BlurStack();
}
stack.next = stackStart;
pos = 0;
for (let y = 0; y < height; ++y) {
start = pos;
color = src[pos];
sum = radius * color;
stack = stackStart;
for (let i = 0; i < radius; ++i) {
stack!.color = color;
stack = stack!.next;
}
for (let i = 1; i < radius; ++i) {
stack!.color = src[pos + i];
sum += stack!.color;
stack = stack!.next;
}
stack = stackStart;
for (let x = 0; x < width; ++x) {
dst[pos++] = (sum * mult) >>> shift;
p = x + radius;
p = start + (p < widthMinus1 ? p : widthMinus1);
sum -= stack!.color - src[p];
stack!.color = src[p];
stack = stack!.next;
}
}
for (let x = 0; x < width; ++x) {
pos = x;
start = pos + width;
color = dst[pos];
sum = radius * color;
stack = stackStart;
for (let i = 0; i < radius; ++i) {
stack!.color = color;
stack = stack!.next;
}
for (let i = 1; i < radius; ++i) {
stack!.color = dst[start];
sum += stack!.color;
stack = stack!.next;
start += width;
}
stack = stackStart;
for (let y = 0; y < height; ++y) {
dst[pos] = (sum * mult) >>> shift;
p = y + radius;
p = x + ((p < heightMinus1 ? p : heightMinus1) * width);
sum -= stack!.color - dst[p];
stack!.color = dst[p];
stack = stack!.next;
pos += width;
}
}
return imageDst;
};
export const findContours = (imageSrc: ImageData, binary: number[]): CVContour[] => {
const width = imageSrc.width;
const height = imageSrc.height;
const contours: CVContour[] = [];
let pix: number;
const src = binaryBorder(imageSrc, binary);
const deltas = neighborhoodDeltas(width + 2);
let pos = width + 3;
let nbd = 1;
for (let i = 0; i < height; ++i, pos += 2) {
for (let j = 0; j < width; ++j, ++pos) {
pix = src[pos];
if (pix !== 0) {
let outer: boolean;
let hole: boolean;
outer = hole = false;
if (pix === 1 && src[pos - 1] === 0) {
outer = true;
} else if (pix >= 1 && src[pos + 1] === 0) {
hole = true;
}
if (outer || hole) {
++nbd;
contours.push(borderFollowing(src, pos, nbd, { x: j, y: i }, hole, deltas));
}
}
}
}
return contours;
};
const borderFollowing = (src: number[], pos: number, nbd: number, point: CVPoint, hole: boolean, deltas: number[]): CVContour => {
const contour: CVContour = {
hole: false,
points: [],
tooNear: false
};
let pos1: number;
let pos3: number;
let pos4: number;
let s: number;
let s_end: number;
contour.hole = hole;
s = s_end = hole ? 0 : 4;
do {
s = (s - 1) & 7;
pos1 = pos + deltas[s];
if (src[pos1] !== 0) {
break;
}
} while (s !== s_end);
if (s === s_end) {
src[pos] = -nbd;
contour.points.push({ x: point.x, y: point.y });
} else {
pos3 = pos;
while (true) {
s_end = s;
do {
pos4 = pos3 + deltas[++s];
} while (src[pos4] === 0);
s &= 7;
if (((s - 1) >>> 0) < (s_end >>> 0)) {
src[pos3] = -nbd;
} else if (src[pos3] === 1) {
src[pos3] = nbd;
}
contour.points.push({ x: point.x, y: point.y });
point.x += neighborhood[s][0];
point.y += neighborhood[s][1];
if ((pos4 === pos) && (pos3 === pos1)) {
break;
}
pos3 = pos4;
s = (s + 4) & 7;
}
}
return contour;
};
const neighborhood =
[[1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1], [0, 1], [1, 1]];
const neighborhoodDeltas = (width: number): number[] => {
const deltas: number[] = [];
const len = neighborhood.length;
for (let i = 0; i < len; ++i) {
deltas[i] = neighborhood[i][0] + (neighborhood[i][1] * width);
}
return deltas.concat(deltas);
};
export const approxPolyDP = (contour: CVPoint[], epsilon: number): CVPoint[] => {
let slice: CVSlice = { start_index: 0, end_index: 0 };
const right_slice: CVSlice = { start_index: 0, end_index: 0 };
const poly: CVPoint[] = [];
const stack: CVSlice[] = [];
const len = contour.length;
let start_pt: CVPoint;
let end_pt: CVPoint;
let dist: number; let max_dist: number; let le_eps: boolean;
let dx: number;
let dy: number; let k: number;
epsilon *= epsilon;
k = 0;
for (let i = 0; i < 3; ++i) {
max_dist = 0;
k = (k + right_slice.start_index) % len;
start_pt = contour[k];
if (++k === len) { k = 0; }
for (let j = 1; j < len; ++j) {
const pt = contour[k];
if (++k === len) { k = 0; }
dx = pt.x - start_pt.x;
dy = pt.y - start_pt.y;
dist = dx * dx + dy * dy;
if (dist > max_dist) {
max_dist = dist;
right_slice.start_index = j;
}
}
}
if (max_dist! <= epsilon) {
poly.push({ x: start_pt!.x, y: start_pt!.y });
} else {
slice.start_index = k;
slice.end_index = (right_slice.start_index += slice.start_index);
right_slice.start_index -= right_slice.start_index >= len ? len : 0;
right_slice.end_index = slice.start_index;
if (right_slice.end_index < right_slice.start_index) {
right_slice.end_index += len;
}
stack.push({ start_index: right_slice.start_index, end_index: right_slice.end_index });
stack.push({ start_index: slice.start_index, end_index: slice.end_index });
}
while (stack.length !== 0) {
slice = stack.pop()!;
end_pt = contour[slice.end_index % len];
start_pt = contour[k = slice.start_index % len];
if (++k === len) { k = 0; }
if (slice.end_index <= slice.start_index + 1) {
le_eps = true;
} else {
max_dist = 0;
dx = end_pt.x - start_pt.x;
dy = end_pt.y - start_pt.y;
for (let i = slice.start_index + 1; i < slice.end_index; ++i) {
const pt = contour[k];
if (++k === len) { k = 0; }
dist = Math.abs((pt.y - start_pt.y) * dx - (pt.x - start_pt.x) * dy);
if (dist > max_dist) {
max_dist = dist;
right_slice.start_index = i;
}
}
le_eps = max_dist * max_dist <= epsilon * (dx * dx + dy * dy);
}
if (le_eps) {
poly.push({ x: start_pt.x, y: start_pt.y });
} else {
right_slice.end_index = slice.end_index;
slice.end_index = right_slice.start_index;
stack.push({ start_index: right_slice.start_index, end_index: right_slice.end_index });
stack.push({ start_index: slice.start_index, end_index: slice.end_index });
}
}
return poly;
};
export const warp = (imageSrc: ImageData, contour: CVContour, warpSize: number): ImageData => {
const imageDst = new ImageData(warpSize, warpSize);
const src = imageSrc.data; const dst = imageDst.data;
const width = imageSrc.width; const height = imageSrc.height;
let pos = 0;
let p1: number; let p2: number; let p3: number; let p4: number;
let r: number; let s: number; let t: number; let u: number; let v: number; let w: number;
const m = getPerspectiveTransform(contour, warpSize - 1);
r = m[8];
s = m[2];
t = m[5];
for (let i = 0; i < warpSize; ++i) {
r += m[7];
s += m[1];
t += m[4];
u = r;
v = s;
w = t;
for (let j = 0; j < warpSize; ++j) {
u += m[6];
v += m[0];
w += m[3];
const x = v / u;
const y = w / u;
const sx1 = x >>> 0;
const sx2 = (sx1 === width - 1) ? sx1 : sx1 + 1;
const dx1 = x - sx1;
const dx2 = 1.0 - dx1;
const sy1 = y >>> 0;
const sy2 = (sy1 === height - 1) ? sy1 : sy1 + 1;
const dy1 = y - sy1;
const dy2 = 1.0 - dy1;
p1 = p2 = sy1 * width;
p3 = p4 = sy2 * width;
dst[pos++] =
(dy2 * (dx2 * src[p1 + sx1] + dx1 * src[p2 + sx2]) +
dy1 * (dx2 * src[p3 + sx1] + dx1 * src[p4 + sx2])) & 0xff;
}
}
return imageDst;
};
const getPerspectiveTransform = (src: CVContour, size: number): number[] => {
const rq = square2quad(src);
rq[0] /= size;
rq[1] /= size;
rq[3] /= size;
rq[4] /= size;
rq[6] /= size;
rq[7] /= size;
return rq;
};
const square2quad = (srcC: CVContour): number[] => {
const sq: number[] = [];
const src = srcC.points;
const px = src[0].x - src[1].x + src[2].x - src[3].x;
const py = src[0].y - src[1].y + src[2].y - src[3].y;
if (px === 0 && py === 0) {
sq[0] = src[1].x - src[0].x;
sq[1] = src[2].x - src[1].x;
sq[2] = src[0].x;
sq[3] = src[1].y - src[0].y;
sq[4] = src[2].y - src[1].y;
sq[5] = src[0].y;
sq[6] = 0;
sq[7] = 0;
sq[8] = 1;
} else {
const dx1 = src[1].x - src[2].x;
const dx2 = src[3].x - src[2].x;
const dy1 = src[1].y - src[2].y;
const dy2 = src[3].y - src[2].y;
const den = dx1 * dy2 - dx2 * dy1;
sq[6] = (px * dy2 - dx2 * py) / den;
sq[7] = (dx1 * py - px * dy1) / den;
sq[8] = 1;
sq[0] = src[1].x - src[0].x + sq[6] * src[1].x;
sq[1] = src[3].x - src[0].x + sq[7] * src[3].x;
sq[2] = src[0].x;
sq[3] = src[1].y - src[0].y + sq[6] * src[1].y;
sq[4] = src[3].y - src[0].y + sq[7] * src[3].y;
sq[5] = src[0].y;
}
return sq;
};
export const isContourConvex = (contour: CVPoint[]): boolean => {
let orientation = 0; let convex = true;
const len = contour.length;
let j = 0;
let cur_pt: CVPoint;
let prev_pt: CVPoint;
let dx0: number;
let dy0: number;
prev_pt = contour[len - 1];
cur_pt = contour[0];
dx0 = cur_pt.x - prev_pt.x;
dy0 = cur_pt.y - prev_pt.y;
for (let i = 0; i < len; ++i) {
if (++j === len) { j = 0; }
prev_pt = cur_pt;
cur_pt = contour[j];
const dx = cur_pt.x - prev_pt.x;
const dy = cur_pt.y - prev_pt.y;
const dxdy0 = dx * dy0;
const dydx0 = dy * dx0;
orientation |= dydx0 > dxdy0 ? 1 : (dydx0 < dxdy0 ? 2 : 3);
if (orientation === 3) {
convex = false;
break;
}
dx0 = dx;
dy0 = dy;
}
return convex;
};
export const perimeter = (poly: CVContour): number => {
const len = poly.points.length;
let j = len - 1;
let p = 0.0;
for (let i = 0; i < len; j = i++) {
const dx = poly.points[i].x - poly.points[j].x;
const dy = poly.points[i].y - poly.points[j].y;
p += Math.sqrt(dx * dx + dy * dy);
}
return p;
};
export const minEdgeLength = (poly: CVPoint[]): number => {
const len = poly.length;
let j = len - 1;
let min = Infinity;
for (let i = 0; i < len; j = i++) {
const dx = poly[i].x - poly[j].x;
const dy = poly[i].y - poly[j].y;
const d = dx * dx + dy * dy;
if (d < min) {
min = d;
}
}
return Math.sqrt(min);
};
export const countNonZero = (imageSrc: ImageData, square: { height: any, width: any, x: number, y: number }): number => {
const src = imageSrc.data;
const height = square.height;
const width = square.width;
const span = imageSrc.width - width;
let pos = square.x + (square.y * imageSrc.width);
let nz = 0;
for (let i = 0; i < height; ++i) {
for (let j = 0; j < width; ++j) {
if (src[pos++] !== 0) {
++nz;
}
}
pos += span;
}
return nz;
};
const binaryBorder = (imageSrc: ImageData, dst: number[]): number[] => {
const src = imageSrc.data;
const height = imageSrc.height;
const width = imageSrc.width;
let posSrc = 0;
let posDst = 0;
for (let j = -2; j < width; ++j) {
dst[posDst++] = 0;
}
for (let i = 0; i < height; ++i) {
dst[posDst++] = 0;
for (let j = 0; j < width; ++j) {
dst[posDst++] = (src[posSrc++] === 0 ? 0 : 1);
}
dst[posDst++] = 0;
}
for (let j = -2; j < width; ++j) {
dst[posDst++] = 0;
}
return dst;
};

516
vendor/ts-aruco/src/posit1.ts vendored Normal file
View File

@@ -0,0 +1,516 @@
/*
Copyright (c) 2012 Juan Mellado
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { type CVPoint } from './cv';
import { svdcmp } from './svd';
/*
References:
- "Iterative Pose Estimation using Coplanar Feature Points"
Denis Oberkampf, Daniel F. DeMenthon, Larry S. Davis
http://www.cfar.umd.edu/~daniel/daniel_papersfordownload/CoplanarPts.pdf
*/
class Pose {
bestError: any;
bestRotation: any;
bestTranslation: any;
alternativeError: any;
alternativeRotation: any;
alternativeTranslation: any;
constructor(error1: number, rotation1: number[][], translation1: number[], error2: number, rotation2: number[][], translation2: number[]) {
this.bestError = error1;
this.bestRotation = rotation1;
this.bestTranslation = translation1;
this.alternativeError = error2;
this.alternativeRotation = rotation2;
this.alternativeTranslation = translation2;
}
}
export class Posit {
objectPoints: number[][];
focalLength: number;
objectVectors: number[][];
objectNormal: number[];
objectMatrix: number[][];
constructor(modelSize: number, focalLength: number) {
this.objectPoints = this.buildModel(modelSize);
this.focalLength = focalLength;
this.objectVectors = [];
this.objectNormal = [];
this.objectMatrix = [[], [], []];
this.init();
};
buildModel(modelSize: number): number[][] {
const half = modelSize / 2.0;
return [
[-half, half, 0.0],
[half, half, 0.0],
[half, -half, 0.0],
[-half, -half, 0.0]];
}
init(): void {
const np = this.objectPoints.length;
const vectors: number[][] = []; const n: any[] = []; let len = 0.0; let row = 2;
for (let i = 0; i < np; ++i) {
this.objectVectors[i] = [this.objectPoints[i][0] - this.objectPoints[0][0],
this.objectPoints[i][1] - this.objectPoints[0][1],
this.objectPoints[i][2] - this.objectPoints[0][2]];
vectors[i] = [this.objectVectors[i][0],
this.objectVectors[i][1],
this.objectVectors[i][2]];
}
while (len === 0.0) {
n[0] = this.objectVectors[1][1] * this.objectVectors[row][2] -
this.objectVectors[1][2] * this.objectVectors[row][1];
n[1] = this.objectVectors[1][2] * this.objectVectors[row][0] -
this.objectVectors[1][0] * this.objectVectors[row][2];
n[2] = this.objectVectors[1][0] * this.objectVectors[row][1] -
this.objectVectors[1][1] * this.objectVectors[row][0];
len = Math.sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]);
++row;
}
for (let i = 0; i < 3; ++i) {
this.objectNormal[i] = n[i] / len;
}
this.pseudoInverse(vectors, np, this.objectMatrix);
}
pose(imagePoints: CVPoint[]): Pose {
const posRotation1 = [[], [], []]; const posRotation2 = [[], [], []];
const posTranslation: number[] = [];
const rotation1 = [[], [], []]; const rotation2 = [[], [], []];
const translation1: number[] = [];
const translation2: number[] = [];
let error1; let error2; let i; let j;
this.pos(imagePoints, posRotation1, posRotation2, posTranslation);
const valid1 = this.isValid(posRotation1, posTranslation);
if (valid1) {
error1 = this.iterate(imagePoints, posRotation1, posTranslation, rotation1, translation1);
} else {
error1 = { euclidean: -1.0, pixels: -1, maximum: -1.0 };
}
const valid2 = this.isValid(posRotation2, posTranslation);
if (valid2) {
error2 = this.iterate(imagePoints, posRotation2, posTranslation, rotation2, translation2);
} else {
error2 = { euclidean: -1.0, pixels: -1, maximum: -1.0 };
}
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
if (valid1) {
translation1[i] -= rotation1[i][j] * this.objectPoints[0][j];
}
if (valid2) {
translation2[i] -= rotation2[i][j] * this.objectPoints[0][j];
}
}
}
return error1.euclidean < error2.euclidean
? new Pose(error1.pixels, rotation1, translation1, error2.pixels, rotation2, translation2)
: new Pose(error2.pixels, rotation2, translation2, error1.pixels, rotation1, translation1);
};
pos(imagePoints: CVPoint[], rotation1: number[][], rotation2: number[][], translation: number[]): void {
const np = this.objectPoints.length; const imageVectors: any[] = [];
const i0: number[] = []; const j0: number[] = []; const ivec: number[] = []; const jvec: number[] = []; const row1: number[] = []; const row2: number[] = []; const row3: number[] = [];
let i0i0; let j0j0; let i0j0; let delta; let q; let lambda; let mu; let scale; let i; let j;
for (i = 0; i < np; ++i) {
imageVectors[i] = [imagePoints[i].x - imagePoints[0].x,
imagePoints[i].y - imagePoints[0].y];
}
// i0 and j0
for (i = 0; i < 3; ++i) {
i0[i] = 0.0;
j0[i] = 0.0;
for (j = 0; j < np; ++j) {
i0[i] += this.objectMatrix[i][j] * imageVectors[j][0];
j0[i] += this.objectMatrix[i][j] * imageVectors[j][1];
}
}
i0i0 = i0[0] * i0[0] + i0[1] * i0[1] + i0[2] * i0[2];
j0j0 = j0[0] * j0[0] + j0[1] * j0[1] + j0[2] * j0[2];
i0j0 = i0[0] * j0[0] + i0[1] * j0[1] + i0[2] * j0[2];
// Lambda and mu
delta = (j0j0 - i0i0) * (j0j0 - i0i0) + 4.0 * (i0j0 * i0j0);
if (j0j0 - i0i0 >= 0.0) {
q = (j0j0 - i0i0 + Math.sqrt(delta)) / 2.0;
} else {
q = (j0j0 - i0i0 - Math.sqrt(delta)) / 2.0;
}
if (q >= 0.0) {
lambda = Math.sqrt(q);
if (lambda === 0.0) {
mu = 0.0;
} else {
mu = -i0j0 / lambda;
}
} else {
lambda = Math.sqrt(-(i0j0 * i0j0) / q);
if (lambda === 0.0) {
mu = Math.sqrt(i0i0 - j0j0);
} else {
mu = -i0j0 / lambda;
}
}
// First rotation
for (i = 0; i < 3; ++i) {
ivec[i] = i0[i] + lambda * this.objectNormal[i];
jvec[i] = j0[i] + mu * this.objectNormal[i];
}
scale = Math.sqrt(ivec[0] * ivec[0] + ivec[1] * ivec[1] + ivec[2] * ivec[2]);
for (i = 0; i < 3; ++i) {
row1[i] = ivec[i] / scale;
row2[i] = jvec[i] / scale;
}
row3[0] = row1[1] * row2[2] - row1[2] * row2[1];
row3[1] = row1[2] * row2[0] - row1[0] * row2[2];
row3[2] = row1[0] * row2[1] - row1[1] * row2[0];
for (i = 0; i < 3; ++i) {
rotation1[0][i] = row1[i];
rotation1[1][i] = row2[i];
rotation1[2][i] = row3[i];
}
// Second rotation
for (i = 0; i < 3; ++i) {
ivec[i] = i0[i] - lambda * this.objectNormal[i];
jvec[i] = j0[i] - mu * this.objectNormal[i];
}
for (i = 0; i < 3; ++i) {
row1[i] = ivec[i] / scale;
row2[i] = jvec[i] / scale;
}
row3[0] = row1[1] * row2[2] - row1[2] * row2[1];
row3[1] = row1[2] * row2[0] - row1[0] * row2[2];
row3[2] = row1[0] * row2[1] - row1[1] * row2[0];
for (i = 0; i < 3; ++i) {
rotation2[0][i] = row1[i];
rotation2[1][i] = row2[i];
rotation2[2][i] = row3[i];
}
// Translation
translation[0] = imagePoints[0].x / scale;
translation[1] = imagePoints[0].y / scale;
translation[2] = this.focalLength / scale;
}
isValid(rotation: number[][], translation: number[]): boolean {
const np = this.objectPoints.length; let zmin = Infinity; let i = 0; let zi;
for (; i < np; ++i) {
zi = translation[2] +
(rotation[2][0] * this.objectVectors[i][0] +
rotation[2][1] * this.objectVectors[i][1] +
rotation[2][2] * this.objectVectors[i][2]);
if (zi < zmin) {
zmin = zi;
}
}
return zmin >= 0.0;
}
iterate(imagePoints: CVPoint[], posRotation: any[][], posTranslation: any[], rotation: number[][], translation: number[]) {
const np = this.objectPoints.length;
const oldSopImagePoints: CVPoint[] = []; const sopImagePoints: CVPoint[] = [];
const rotation1 = [[], [], []]; const rotation2 = [[], [], []];
const translation1: number[] = []; const translation2: number[] = [];
let converged = false; let iteration = 0;
let oldImageDifference; let imageDifference; let factor;
let error; let error1; let error2; let delta; let i; let j;
for (i = 0; i < np; ++i) {
oldSopImagePoints[i] = {
x: imagePoints[i].x,
y: imagePoints[i].y
};
}
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
rotation[i][j] = posRotation[i][j];
}
translation[i] = posTranslation[i];
}
for (i = 0; i < np; ++i) {
factor = 0.0;
for (j = 0; j < 3; ++j) {
factor += this.objectVectors[i][j] * rotation[2][j] / translation[2];
}
sopImagePoints[i] = {
x: (1.0 + factor) * imagePoints[i].x,
y: (1.0 + factor) * imagePoints[i].y
};
}
imageDifference = 0.0;
for (i = 0; i < np; ++i) {
imageDifference += Math.abs(sopImagePoints[i].x - oldSopImagePoints[i].x);
imageDifference += Math.abs(sopImagePoints[i].y - oldSopImagePoints[i].y);
}
for (i = 0; i < 3; ++i) {
translation1[i] = translation[i] -
(rotation[i][0] * this.objectPoints[0][0] +
rotation[i][1] * this.objectPoints[0][1] +
rotation[i][2] * this.objectPoints[0][2]);
}
error = error1 = this.error(imagePoints, rotation, translation1);
// Convergence
converged = (error1.pixels === 0.0) || (imageDifference < 0.01);
while (iteration++ < 100 && !converged) {
for (i = 0; i < np; ++i) {
oldSopImagePoints[i].x = sopImagePoints[i].x;
oldSopImagePoints[i].y = sopImagePoints[i].y;
}
this.pos(sopImagePoints, rotation1, rotation2, translation);
for (i = 0; i < 3; ++i) {
translation1[i] = translation[i] -
(rotation1[i][0] * this.objectPoints[0][0] +
rotation1[i][1] * this.objectPoints[0][1] +
rotation1[i][2] * this.objectPoints[0][2]);
translation2[i] = translation[i] -
(rotation2[i][0] * this.objectPoints[0][0] +
rotation2[i][1] * this.objectPoints[0][1] +
rotation2[i][2] * this.objectPoints[0][2]);
}
error1 = this.error(imagePoints, rotation1, translation1);
error2 = this.error(imagePoints, rotation2, translation2);
if ((error1.euclidean >= 0.0) && (error2.euclidean >= 0.0)) {
if (error2.euclidean < error1.euclidean) {
error = error2;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
rotation[i][j] = rotation2[i][j];
}
}
} else {
error = error1;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
rotation[i][j] = rotation1[i][j];
}
}
}
}
if ((error1.euclidean < 0.0) && (error2.euclidean >= 0.0)) {
error = error2;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
rotation[i][j] = rotation2[i][j];
}
}
}
if ((error2.euclidean < 0.0) && (error1.euclidean >= 0.0)) {
error = error1;
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
rotation[i][j] = rotation1[i][j];
}
}
}
for (i = 0; i < np; ++i) {
factor = 0.0;
for (j = 0; j < 3; ++j) {
factor += this.objectVectors[i][j] * rotation[2][j] / translation[2];
}
sopImagePoints[i].x = (1.0 + factor) * imagePoints[i].x;
sopImagePoints[i].y = (1.0 + factor) * imagePoints[i].y;
}
oldImageDifference = imageDifference;
imageDifference = 0.0;
for (i = 0; i < np; ++i) {
imageDifference += Math.abs(sopImagePoints[i].x - oldSopImagePoints[i].x);
imageDifference += Math.abs(sopImagePoints[i].y - oldSopImagePoints[i].y);
}
delta = Math.abs(imageDifference - oldImageDifference);
converged = (error.pixels === 0.0) || (delta < 0.01);
}
return error;
}
error(imagePoints: CVPoint[], rotation: number[][], translation: number[]) {
const np = this.objectPoints.length;
const move: number[][] = []; const projection: number[][] = []; const errorvec: number[][] = [];
let euclidean = 0.0; let pixels = 0.0; let maximum = 0.0;
let i; let j; let k;
if (!this.isValid(rotation, translation)) {
return { euclidean: -1.0, pixels: -1, maximum: -1.0 };
}
for (i = 0; i < np; ++i) {
move[i] = [];
for (j = 0; j < 3; ++j) {
move[i][j] = translation[j];
}
}
for (i = 0; i < np; ++i) {
for (j = 0; j < 3; ++j) {
for (k = 0; k < 3; ++k) {
move[i][j] += rotation[j][k] * this.objectPoints[i][k];
}
}
}
for (i = 0; i < np; ++i) {
projection[i] = [];
for (j = 0; j < 2; ++j) {
projection[i][j] = this.focalLength * move[i][j] / move[i][2];
}
}
for (i = 0; i < np; ++i) {
errorvec[i] = [projection[i][0] - imagePoints[i].x,
projection[i][1] - imagePoints[i].y];
}
for (i = 0; i < np; ++i) {
euclidean += Math.sqrt(errorvec[i][0] * errorvec[i][0] +
errorvec[i][1] * errorvec[i][1]);
pixels += Math.abs(Math.round(projection[i][0]) - Math.round(imagePoints[i].x)) +
Math.abs(Math.round(projection[i][1]) - Math.round(imagePoints[i].y));
if (Math.abs(errorvec[i][0]) > maximum) {
maximum = Math.abs(errorvec[i][0]);
}
if (Math.abs(errorvec[i][1]) > maximum) {
maximum = Math.abs(errorvec[i][1]);
}
}
return { euclidean: euclidean / np, pixels, maximum };
}
pseudoInverse(a: number[][], n: number, b: number[][]): void {
const w: number[] = []; const v = [[], [], []]; const s: number[][] = [[], [], []];
let wmax = 0.0; let cn = 0;
let i: number; let j: number; let k: number;
svdcmp(a, n, 3, w, v);
for (i = 0; i < 3; ++i) {
if (w[i] > wmax) {
wmax = w[i];
}
}
wmax *= 0.01;
for (i = 0; i < 3; ++i) {
if (w[i] < wmax) {
w[i] = 0.0;
}
}
for (j = 0; j < 3; ++j) {
if (w[j] === 0.0) {
++cn;
for (k = j; k < 2; ++k) {
for (i = 0; i < n; ++i) {
a[i][k] = a[i][k + 1];
}
for (i = 0; i < 3; ++i) {
v[i][k] = v[i][k + 1];
}
}
}
}
for (j = 0; j < 2; ++j) {
if (w[j] === 0.0) {
w[j] = w[j + 1];
}
}
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3 - cn; ++j) {
s[i][j] = v[i][j] / w[j];
}
}
for (i = 0; i < 3; ++i) {
for (j = 0; j < n; ++j) {
b[i][j] = 0.0;
for (k = 0; k < 3 - cn; ++k) {
b[i][j] += s[i][k] * a[j][k];
}
}
}
}
}

497
vendor/ts-aruco/src/posit2.ts vendored Normal file
View File

@@ -0,0 +1,497 @@
/*
Copyright (c) 2012 Juan Mellado
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { svdcmp } from './svd';
/*
References:
- "3D Pose Estimation"
Andrew Kirillow
http://www.aforgenet.com/articles/posit/
*/
var POS = POS || {};
POS.Posit = function (modelSize, focalLength) {
this.model = this.buildModel(modelSize);
this.focalLength = focalLength;
this.init();
};
POS.Posit.prototype.buildModel = function (modelSize) {
const half = modelSize / 2.0;
return [
new Vec3(-half, half, 0.0),
new Vec3(half, half, 0.0),
new Vec3(half, -half, 0.0),
new Vec3(-half, -half, 0.0)];
};
POS.Posit.prototype.init = function () {
const d = new Vec3(); const v = new Mat3(); let u;
this.modelVectors = Mat3.fromRows(
Vec3.sub(this.model[1], this.model[0]),
Vec3.sub(this.model[2], this.model[0]),
Vec3.sub(this.model[3], this.model[0]));
u = Mat3.clone(this.modelVectors);
svdcmp(u.m, 3, 3, d.v, v.m);
this.modelPseudoInverse = Mat3.mult(
Mat3.mult(v, Mat3.fromDiagonal(Vec3.inverse(d))), Mat3.transpose(u));
this.modelNormal = v.column(d.minIndex());
};
POS.Posit.prototype.pose = function (points) {
const eps = new Vec3(1.0, 1.0, 1.0);
const rotation1 = new Mat3(); const rotation2 = new Mat3();
const translation1 = new Vec3(); const translation2 = new Vec3();
let error1; let error2;
this.pos(points, eps, rotation1, rotation2, translation1, translation2);
error1 = this.iterate(points, rotation1, translation1);
error2 = this.iterate(points, rotation2, translation2);
return error1 < error2
? new POS.Pose(error1, rotation1.m, translation1.v, error2, rotation2.m, translation2.v)
: new POS.Pose(error2, rotation2.m, translation2.v, error1, rotation1.m, translation1.v);
};
POS.Posit.prototype.pos = function (points, eps, rotation1, rotation2, translation1, translation2) {
const xi = new Vec3(points[1].x, points[2].x, points[3].x);
const yi = new Vec3(points[1].y, points[2].y, points[3].y);
const xs = Vec3.addScalar(Vec3.mult(xi, eps), -points[0].x);
const ys = Vec3.addScalar(Vec3.mult(yi, eps), -points[0].y);
const i0 = Mat3.multVector(this.modelPseudoInverse, xs);
const j0 = Mat3.multVector(this.modelPseudoInverse, ys);
const s = j0.square() - i0.square();
const ij = Vec3.dot(i0, j0);
let r = 0.0; let theta = 0.0;
let i; let j; let k; let inorm; let jnorm; let scale; let temp; let lambda; let mu;
if (s === 0.0) {
r = Math.sqrt(Math.abs(2.0 * ij));
theta = (-Math.PI / 2.0) * (ij < 0.0 ? -1 : (ij > 0.0 ? 1.0 : 0.0));
} else {
r = Math.sqrt(Math.sqrt(s * s + 4.0 * ij * ij));
theta = Math.atan(-2.0 * ij / s);
if (s < 0.0) {
theta += Math.PI;
}
theta /= 2.0;
}
lambda = r * Math.cos(theta);
mu = r * Math.sin(theta);
// First possible rotation/translation
i = Vec3.add(i0, Vec3.multScalar(this.modelNormal, lambda));
j = Vec3.add(j0, Vec3.multScalar(this.modelNormal, mu));
inorm = i.normalize();
jnorm = j.normalize();
k = Vec3.cross(i, j);
rotation1.copy(Mat3.fromRows(i, j, k));
scale = (inorm + jnorm) / 2.0;
temp = Mat3.multVector(rotation1, this.model[0]);
translation1.v = [
points[0].x / scale - temp.v[0],
points[0].y / scale - temp.v[1],
this.focalLength / scale];
// Second possible rotation/translation
i = Vec3.sub(i0, Vec3.multScalar(this.modelNormal, lambda));
j = Vec3.sub(j0, Vec3.multScalar(this.modelNormal, mu));
inorm = i.normalize();
jnorm = j.normalize();
k = Vec3.cross(i, j);
rotation2.copy(Mat3.fromRows(i, j, k));
scale = (inorm + jnorm) / 2.0;
temp = Mat3.multVector(rotation2, this.model[0]);
translation2.v = [
points[0].x / scale - temp.v[0],
points[0].y / scale - temp.v[1],
this.focalLength / scale];
};
POS.Posit.prototype.iterate = function (points, rotation, translation) {
let prevError = Infinity;
const rotation1 = new Mat3(); const rotation2 = new Mat3();
const translation1 = new Vec3(); const translation2 = new Vec3();
let i = 0; let eps; let error; let error1; let error2;
for (; i < 100; ++i) {
eps = Vec3.addScalar(Vec3.multScalar(
Mat3.multVector(this.modelVectors, rotation.row(2)), 1.0 / translation.v[2]), 1.0);
this.pos(points, eps, rotation1, rotation2, translation1, translation2);
error1 = this.getError(points, rotation1, translation1);
error2 = this.getError(points, rotation2, translation2);
if (error1 < error2) {
rotation.copy(rotation1);
translation.copy(translation1);
error = error1;
} else {
rotation.copy(rotation2);
translation.copy(translation2);
error = error2;
}
if ((error <= 2.0) || (error > prevError)) {
break;
}
prevError = error;
}
return error;
};
POS.Posit.prototype.getError = function (points, rotation, translation) {
let v1 = Vec3.add(Mat3.multVector(rotation, this.model[0]), translation);
let v2 = Vec3.add(Mat3.multVector(rotation, this.model[1]), translation);
let v3 = Vec3.add(Mat3.multVector(rotation, this.model[2]), translation);
let v4 = Vec3.add(Mat3.multVector(rotation, this.model[3]), translation);
let modeled; let ia1; let ia2; let ia3; let ia4; let ma1; let ma2; let ma3; let ma4;
v1 = v1.v; v2 = v2.v; v3 = v3.v; v4 = v4.v;
v1[0] *= this.focalLength / v1[2];
v1[1] *= this.focalLength / v1[2];
v2[0] *= this.focalLength / v2[2];
v2[1] *= this.focalLength / v2[2];
v3[0] *= this.focalLength / v3[2];
v3[1] *= this.focalLength / v3[2];
v4[0] *= this.focalLength / v4[2];
v4[1] *= this.focalLength / v4[2];
modeled = [
{ x: v1[0], y: v1[1] },
{ x: v2[0], y: v2[1] },
{ x: v3[0], y: v3[1] },
{ x: v4[0], y: v4[1] }
];
ia1 = this.angle(points[0], points[1], points[3]);
ia2 = this.angle(points[1], points[2], points[0]);
ia3 = this.angle(points[2], points[3], points[1]);
ia4 = this.angle(points[3], points[0], points[2]);
ma1 = this.angle(modeled[0], modeled[1], modeled[3]);
ma2 = this.angle(modeled[1], modeled[2], modeled[0]);
ma3 = this.angle(modeled[2], modeled[3], modeled[1]);
ma4 = this.angle(modeled[3], modeled[0], modeled[2]);
return (Math.abs(ia1 - ma1) +
Math.abs(ia2 - ma2) +
Math.abs(ia3 - ma3) +
Math.abs(ia4 - ma4)) / 4.0;
};
POS.Posit.prototype.angle = function (a, b, c) {
const x1 = b.x - a.x; const y1 = b.y - a.y;
const x2 = c.x - a.x; const y2 = c.y - a.y;
return Math.acos((x1 * x2 + y1 * y2) /
(Math.sqrt(x1 * x1 + y1 * y1) * Math.sqrt(x2 * x2 + y2 * y2))) * 180.0 / Math.PI;
};
POS.Pose = function (error1, rotation1, translation1, error2, rotation2, translation2) {
this.bestError = error1;
this.bestRotation = rotation1;
this.bestTranslation = translation1;
this.alternativeError = error2;
this.alternativeRotation = rotation2;
this.alternativeTranslation = translation2;
};
var Vec3 = function (x, y, z) {
this.v = [x || 0.0, y || 0.0, z || 0.0];
};
Vec3.prototype.copy = function (a) {
const v = this.v;
a = a.v;
v[0] = a[0];
v[1] = a[1];
v[2] = a[2];
return this;
};
Vec3.add = function (a, b) {
const vector = new Vec3(); const v = vector.v;
a = a.v; b = b.v;
v[0] = a[0] + b[0];
v[1] = a[1] + b[1];
v[2] = a[2] + b[2];
return vector;
};
Vec3.sub = function (a, b) {
const vector = new Vec3(); const v = vector.v;
a = a.v; b = b.v;
v[0] = a[0] - b[0];
v[1] = a[1] - b[1];
v[2] = a[2] - b[2];
return vector;
};
Vec3.mult = function (a, b) {
const vector = new Vec3(); const v = vector.v;
a = a.v; b = b.v;
v[0] = a[0] * b[0];
v[1] = a[1] * b[1];
v[2] = a[2] * b[2];
return vector;
};
Vec3.addScalar = function (a, b) {
const vector = new Vec3(); const v = vector.v;
a = a.v;
v[0] = a[0] + b;
v[1] = a[1] + b;
v[2] = a[2] + b;
return vector;
};
Vec3.multScalar = function (a, b) {
const vector = new Vec3(); const v = vector.v;
a = a.v;
v[0] = a[0] * b;
v[1] = a[1] * b;
v[2] = a[2] * b;
return vector;
};
Vec3.dot = function (a, b) {
a = a.v; b = b.v;
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
};
Vec3.cross = function (a, b) {
a = a.v; b = b.v;
return new Vec3(
a[1] * b[2] - a[2] * b[1],
a[2] * b[0] - a[0] * b[2],
a[0] * b[1] - a[1] * b[0]);
};
Vec3.prototype.normalize = function () {
const v = this.v;
const len = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
if (len > 0.0) {
v[0] /= len;
v[1] /= len;
v[2] /= len;
}
return len;
};
Vec3.inverse = function (a) {
const vector = new Vec3(); const v = vector.v;
a = a.v;
if (a[0] !== 0.0) {
v[0] = 1.0 / a[0];
}
if (a[1] !== 0.0) {
v[1] = 1.0 / a[1];
}
if (a[2] !== 0.0) {
v[2] = 1.0 / a[2];
}
return vector;
};
Vec3.prototype.square = function () {
const v = this.v;
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
};
Vec3.prototype.minIndex = function () {
const v = this.v;
return v[0] < v[1] ? (v[0] < v[2] ? 0 : 2) : (v[1] < v[2] ? 1 : 2);
};
var Mat3 = function () {
this.m = [[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]];
};
Mat3.clone = function (a) {
const matrix = new Mat3(); const m = matrix.m;
a = a.m;
m[0][0] = a[0][0];
m[0][1] = a[0][1];
m[0][2] = a[0][2];
m[1][0] = a[1][0];
m[1][1] = a[1][1];
m[1][2] = a[1][2];
m[2][0] = a[2][0];
m[2][1] = a[2][1];
m[2][2] = a[2][2];
return matrix;
};
Mat3.prototype.copy = function (a) {
const m = this.m;
a = a.m;
m[0][0] = a[0][0];
m[0][1] = a[0][1];
m[0][2] = a[0][2];
m[1][0] = a[1][0];
m[1][1] = a[1][1];
m[1][2] = a[1][2];
m[2][0] = a[2][0];
m[2][1] = a[2][1];
m[2][2] = a[2][2];
return this;
};
Mat3.fromRows = function (a, b, c) {
const matrix = new Mat3(); const m = matrix.m;
a = a.v; b = b.v; c = c.v;
m[0][0] = a[0];
m[0][1] = a[1];
m[0][2] = a[2];
m[1][0] = b[0];
m[1][1] = b[1];
m[1][2] = b[2];
m[2][0] = c[0];
m[2][1] = c[1];
m[2][2] = c[2];
return matrix;
};
Mat3.fromDiagonal = function (a) {
const matrix = new Mat3(); const m = matrix.m;
a = a.v;
m[0][0] = a[0];
m[1][1] = a[1];
m[2][2] = a[2];
return matrix;
};
Mat3.transpose = function (a) {
const matrix = new Mat3(); const m = matrix.m;
a = a.m;
m[0][0] = a[0][0];
m[0][1] = a[1][0];
m[0][2] = a[2][0];
m[1][0] = a[0][1];
m[1][1] = a[1][1];
m[1][2] = a[2][1];
m[2][0] = a[0][2];
m[2][1] = a[1][2];
m[2][2] = a[2][2];
return matrix;
};
Mat3.mult = function (a, b) {
const matrix = new Mat3(); const m = matrix.m;
a = a.m; b = b.m;
m[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0] + a[0][2] * b[2][0];
m[0][1] = a[0][0] * b[0][1] + a[0][1] * b[1][1] + a[0][2] * b[2][1];
m[0][2] = a[0][0] * b[0][2] + a[0][1] * b[1][2] + a[0][2] * b[2][2];
m[1][0] = a[1][0] * b[0][0] + a[1][1] * b[1][0] + a[1][2] * b[2][0];
m[1][1] = a[1][0] * b[0][1] + a[1][1] * b[1][1] + a[1][2] * b[2][1];
m[1][2] = a[1][0] * b[0][2] + a[1][1] * b[1][2] + a[1][2] * b[2][2];
m[2][0] = a[2][0] * b[0][0] + a[2][1] * b[1][0] + a[2][2] * b[2][0];
m[2][1] = a[2][0] * b[0][1] + a[2][1] * b[1][1] + a[2][2] * b[2][1];
m[2][2] = a[2][0] * b[0][2] + a[2][1] * b[1][2] + a[2][2] * b[2][2];
return matrix;
};
Mat3.multVector = function (m, a) {
m = m.m; a = a.v;
return new Vec3(
m[0][0] * a[0] + m[0][1] * a[1] + m[0][2] * a[2],
m[1][0] * a[0] + m[1][1] * a[1] + m[1][2] * a[2],
m[2][0] * a[0] + m[2][1] * a[1] + m[2][2] * a[2]);
};
Mat3.prototype.column = function (index) {
const m = this.m;
return new Vec3(m[0][index], m[1][index], m[2][index]);
};
Mat3.prototype.row = function (index) {
const m = this.m;
return new Vec3(m[index][0], m[index][1], m[index][2]);
};

283
vendor/ts-aruco/src/svd.ts vendored Normal file
View File

@@ -0,0 +1,283 @@
/*
Copyright (c) 2012 Juan Mellado
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
References:
- "Numerical Recipes in C - Second Edition"
http://www.nr.com/
*/
export const svdcmp = (a: number[][], m: number, n: number, w: number[], v: number[][]): boolean => {
let flag; let i: number; let its; let j: number; let jj; let k; let l: number = 0; let nm: number = 0;
let anorm = 0.0; let c; let f; let g = 0.0; let h; let s; let scale = 0.0; let x; let y; let z; const rv1: number[] = [];
// Householder reduction to bidiagonal form
for (i = 0; i < n; ++i) {
l = i + 1;
rv1[i] = scale * g;
g = s = scale = 0.0;
if (i < m) {
for (k = i; k < m; ++k) {
scale += Math.abs(a[k][i]);
}
if (scale !== 0.0) {
for (k = i; k < m; ++k) {
a[k][i] /= scale;
s += a[k][i] * a[k][i];
}
f = a[i][i];
g = -sign(Math.sqrt(s), f);
h = f * g - s;
a[i][i] = f - g;
for (j = l; j < n; ++j) {
for (s = 0.0, k = i; k < m; ++k) {
s += a[k][i] * a[k][j];
}
f = s / h;
for (k = i; k < m; ++k) {
a[k][j] += f * a[k][i];
}
}
for (k = i; k < m; ++k) {
a[k][i] *= scale;
}
}
}
w[i] = scale * g;
g = s = scale = 0.0;
if ((i < m) && (i !== n - 1)) {
for (k = l; k < n; ++k) {
scale += Math.abs(a[i][k]);
}
if (scale !== 0.0) {
for (k = l; k < n; ++k) {
a[i][k] /= scale;
s += a[i][k] * a[i][k];
}
f = a[i][l];
g = -sign(Math.sqrt(s), f);
h = f * g - s;
a[i][l] = f - g;
for (k = l; k < n; ++k) {
rv1[k] = a[i][k] / h;
}
for (j = l; j < m; ++j) {
for (s = 0.0, k = l; k < n; ++k) {
s += a[j][k] * a[i][k];
}
for (k = l; k < n; ++k) {
a[j][k] += s * rv1[k];
}
}
for (k = l; k < n; ++k) {
a[i][k] *= scale;
}
}
}
anorm = Math.max(anorm, (Math.abs(w[i]) + Math.abs(rv1[i])));
}
// Acumulation of right-hand transformation
for (i = n - 1; i >= 0; --i) {
if (i < n - 1) {
if (g !== 0.0) {
for (j = l; j < n; ++j) {
v[j][i] = (a[i][j] / a[i][l]) / g;
}
for (j = l; j < n; ++j) {
for (s = 0.0, k = l; k < n; ++k) {
s += a[i][k] * v[k][j];
}
for (k = l; k < n; ++k) {
v[k][j] += s * v[k][i];
}
}
}
for (j = l; j < n; ++j) {
v[i][j] = v[j][i] = 0.0;
}
}
v[i][i] = 1.0;
g = rv1[i];
l = i;
}
// Acumulation of left-hand transformation
for (i = Math.min(n, m) - 1; i >= 0; --i) {
l = i + 1;
g = w[i];
for (j = l; j < n; ++j) {
a[i][j] = 0.0;
}
if (g !== 0.0) {
g = 1.0 / g;
for (j = l; j < n; ++j) {
for (s = 0.0, k = l; k < m; ++k) {
s += a[k][i] * a[k][j];
}
f = (s / a[i][i]) * g;
for (k = i; k < m; ++k) {
a[k][j] += f * a[k][i];
}
}
for (j = i; j < m; ++j) {
a[j][i] *= g;
}
} else {
for (j = i; j < m; ++j) {
a[j][i] = 0.0;
}
}
++a[i][i];
}
// Diagonalization of the bidiagonal form
for (k = n - 1; k >= 0; --k) {
for (its = 1; its <= 30; ++its) {
flag = true;
for (l = k; l >= 0; --l) {
nm = l - 1;
if (Math.abs(rv1[l]) + anorm === anorm) {
flag = false;
break;
}
if (Math.abs(w[nm]) + anorm === anorm) {
break;
}
}
if (flag) {
c = 0.0;
s = 1.0;
for (i = l; i <= k; ++i) {
f = s * rv1[i];
if (Math.abs(f) + anorm === anorm) {
break;
}
g = w[i];
h = pythag(f, g);
w[i] = h;
h = 1.0 / h;
c = g * h;
s = -f * h;
for (j = 1; j <= m; ++j) {
y = a[j][nm];
z = a[j][i];
a[j][nm] = y * c + z * s;
a[j][i] = z * c - y * s;
}
}
}
// Convergence
z = w[k];
if (l === k) {
if (z < 0.0) {
w[k] = -z;
for (j = 0; j < n; ++j) {
v[j][k] = -v[j][k];
}
}
break;
}
if (its === 30) {
return false;
}
// Shift from bottom 2-by-2 minor
x = w[l];
nm = k - 1;
y = w[nm];
g = rv1[nm];
h = rv1[k];
f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y);
g = pythag(f, 1.0);
f = ((x - z) * (x + z) + h * ((y / (f + sign(g, f))) - h)) / x;
// Next QR transformation
c = s = 1.0;
for (j = l; j <= nm; ++j) {
i = j + 1;
g = rv1[i];
y = w[i];
h = s * g;
g = c * g;
z = pythag(f, h);
rv1[j] = z;
c = f / z;
s = h / z;
f = x * c + g * s;
g = g * c - x * s;
h = y * s;
y *= c;
for (jj = 0; jj < n; ++jj) {
x = v[jj][j];
z = v[jj][i];
v[jj][j] = x * c + z * s;
v[jj][i] = z * c - x * s;
}
z = pythag(f, h);
w[j] = z;
if (z !== 0.0) {
z = 1.0 / z;
c = f * z;
s = h * z;
}
f = c * g + s * y;
x = c * y - s * g;
for (jj = 0; jj < m; ++jj) {
y = a[jj][j];
z = a[jj][i];
a[jj][j] = y * c + z * s;
a[jj][i] = z * c - y * s;
}
}
rv1[l] = 0.0;
rv1[k] = f;
w[k] = x;
}
}
return true;
};
const pythag = (a: number, b: number): number => {
const at = Math.abs(a);
const bt = Math.abs(b);
let ct;
if (at > bt) {
ct = bt / at;
return at * Math.sqrt(1.0 + ct * ct);
}
if (bt === 0.0) {
return 0.0;
}
ct = at / bt;
return bt * Math.sqrt(1.0 + ct * ct);
};
const sign = (a: number, b: number): number => {
return b >= 0.0 ? Math.abs(a) : -Math.abs(a);
};

109
vendor/ts-aruco/tsconfig.json vendored Normal file
View File

@@ -0,0 +1,109 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}