@camera.ui/camera-ui-wasm-motion 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ All notable changes to this project will be documented in this file.
2
+
3
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
+
6
+ ## [X.X.X] - ???
7
+
8
+ - Initial Release
@@ -0,0 +1 @@
1
+ # Contributing
package/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2024 seydx <dev@seydx.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @camera.ui/camera-ui-wasm-motion
@@ -0,0 +1,24 @@
1
+ import type { CameraDevice, CameraStorage, PluginAPI, PluginLogger } from '@camera.ui/types';
2
+ export declare class CameraDetector {
3
+ cameraStorage: CameraStorage;
4
+ private api;
5
+ private cameraDevice;
6
+ private logger;
7
+ private started;
8
+ private closed;
9
+ private wasmModule?;
10
+ private firstFramePtr;
11
+ private tempPtr;
12
+ private visitedPtr;
13
+ private queuePtr;
14
+ private memoryBuffer;
15
+ private lastFrameTime;
16
+ constructor(cameraDevice: CameraDevice, api: PluginAPI, logger: PluginLogger);
17
+ start(): Promise<void>;
18
+ close(): void;
19
+ restart(): void;
20
+ private startDetection;
21
+ private setupFirstFrame;
22
+ private getMotionData;
23
+ private createCameraStorage;
24
+ }
@@ -0,0 +1,250 @@
1
+ import { instantiate } from '@assemblyscript/loader';
2
+ import fs from 'node:fs';
3
+ import { resolve } from 'node:path';
4
+ const defaultThreshold = 50;
5
+ const defaultBlurRadius = 9;
6
+ const defaultDilationSize = 3;
7
+ const defaultMotionArea = 250;
8
+ const defaultReferenceFrameFrequency = 5;
9
+ const __dirname = new URL('.', import.meta.url).pathname;
10
+ export class CameraDetector {
11
+ cameraStorage;
12
+ api;
13
+ cameraDevice;
14
+ logger;
15
+ started = false;
16
+ closed = false;
17
+ wasmModule;
18
+ firstFramePtr = null;
19
+ tempPtr = 0;
20
+ visitedPtr = 0;
21
+ queuePtr = 0;
22
+ // private boxesPtr = 0;
23
+ memoryBuffer;
24
+ lastFrameTime = 0;
25
+ constructor(cameraDevice, api, logger) {
26
+ this.api = api;
27
+ this.cameraDevice = cameraDevice;
28
+ this.logger = logger;
29
+ this.cameraStorage = this.createCameraStorage();
30
+ this.cameraDevice.onConnected.subscribe((connected) => {
31
+ if (connected) {
32
+ this.start();
33
+ }
34
+ else {
35
+ this.close();
36
+ }
37
+ });
38
+ }
39
+ async start() {
40
+ if (!this.started) {
41
+ this.started = true;
42
+ this.closed = false;
43
+ this.logger.log(`Starting motion detection for camera ${this.cameraDevice.name}`);
44
+ if (!this.wasmModule) {
45
+ const wasmPath = resolve(__dirname, './wasm/build/detector.wasm');
46
+ this.wasmModule = await instantiate(fs.readFileSync(wasmPath), {
47
+ console: {
48
+ log: (messagePtr) => {
49
+ this.logger.log(this.wasmModule.exports.__getString(messagePtr));
50
+ },
51
+ },
52
+ env: {
53
+ abort: (msg, file, line, column) => {
54
+ this.logger.error('WASM Error message: ', this.wasmModule.exports.__getString(msg));
55
+ this.logger.error('WASM Error file: ', this.wasmModule.exports.__getString(file));
56
+ this.logger.error('WASM Error line: ', line);
57
+ this.logger.error('WASM Error column: ', column);
58
+ },
59
+ },
60
+ });
61
+ this.memoryBuffer = new Uint8Array(this.wasmModule.exports.memory.buffer);
62
+ const width = this.cameraDevice.frameWorkerSettings.resolution;
63
+ const maxFrameLength = width * width;
64
+ this.tempPtr = this.wasmModule.exports.__pin(this.wasmModule.exports.__new(maxFrameLength, this.wasmModule.exports.Uint8Array_ID.value));
65
+ this.visitedPtr = this.wasmModule.exports.__pin(this.wasmModule.exports.__new(maxFrameLength, this.wasmModule.exports.Uint8Array_ID.value));
66
+ this.queuePtr = this.wasmModule.exports.__pin(this.wasmModule.exports.__new(maxFrameLength * 4, this.wasmModule.exports.Uint8Array_ID.value));
67
+ // this.boxesPtr = this.wasmModule.exports.__pin(this.wasmModule.exports.__new(maxFrameLength * 4, this.wasmModule.exports.Uint8Array_ID.value));
68
+ }
69
+ this.startDetection();
70
+ }
71
+ }
72
+ close() {
73
+ if (this.started && !this.closed) {
74
+ this.started = false;
75
+ this.closed = true;
76
+ this.logger.log(`Stopping motion detection for camera ${this.cameraDevice.name}`);
77
+ }
78
+ }
79
+ restart() {
80
+ this.logger.log(`Restarting motion detection for camera ${this.cameraDevice.name}`);
81
+ this.close();
82
+ if (this.cameraDevice.connected) {
83
+ this.start();
84
+ }
85
+ }
86
+ async startDetection() {
87
+ try {
88
+ for await (const frame of this.cameraDevice.getFrames()) {
89
+ if (this.closed) {
90
+ break;
91
+ }
92
+ const frameImage = await frame.toBuffer({
93
+ format: {
94
+ to: 'gray',
95
+ },
96
+ });
97
+ const detections = [];
98
+ const dets = this.getMotionData(frameImage.image, frameImage.info.width, frameImage.info.height);
99
+ for (const det of dets) {
100
+ detections.push({
101
+ label: 'motion',
102
+ confidence: 1,
103
+ boundingBox: [det[0], det[1], det[2], det[3]],
104
+ inputWidth: frameImage.info.width,
105
+ inputHeight: frameImage.info.height,
106
+ origWidth: frame.metadata.origWidth,
107
+ origHeight: frame.metadata.origHeight,
108
+ });
109
+ }
110
+ await this.cameraDevice.updateState('motion', { detections: detections }, frame);
111
+ }
112
+ }
113
+ catch (error) {
114
+ this.logger.error(this.cameraDevice.name, 'Error generating frames', error);
115
+ }
116
+ }
117
+ setupFirstFrame(frame, width, height, blurRadius) {
118
+ if (this.firstFramePtr !== null) {
119
+ this.wasmModule.exports.__unpin(this.firstFramePtr);
120
+ this.wasmModule.exports.__collect();
121
+ this.firstFramePtr = null;
122
+ }
123
+ const frameLength = width * height;
124
+ const framePtr = this.wasmModule.exports.__pin(this.wasmModule.exports.__newArrayBuffer(frame));
125
+ this.wasmModule.exports.stackBlur(framePtr, this.tempPtr, width, height, blurRadius);
126
+ this.firstFramePtr = this.wasmModule.exports.__pin(this.wasmModule.exports.__newArrayBuffer(new Uint8Array(this.memoryBuffer.buffer, framePtr, frameLength)));
127
+ this.wasmModule.exports.__unpin(framePtr);
128
+ }
129
+ getMotionData(frame, width, height) {
130
+ if (!this.wasmModule) {
131
+ throw new Error('Wasm not initiated');
132
+ }
133
+ const motionArea = this.cameraStorage.values.area;
134
+ const threshold = this.cameraStorage.values.threshold;
135
+ const blurRadius = this.cameraStorage.values.blurRadius;
136
+ const dilationSize = this.cameraStorage.values.dilationSize;
137
+ const referenceFrameFrequency = this.cameraStorage.values.referenceFrameFrequency;
138
+ const now = Date.now();
139
+ if (this.firstFramePtr === null || now - this.lastFrameTime > referenceFrameFrequency * 1000) {
140
+ this.lastFrameTime = now;
141
+ this.setupFirstFrame(frame, width, height, blurRadius);
142
+ return [];
143
+ }
144
+ const frameLength = width * height;
145
+ const framePtr = this.wasmModule.exports.__pin(this.wasmModule.exports.__newArrayBuffer(frame));
146
+ const boxesPtr = this.wasmModule.exports.__pin(this.wasmModule.exports.__new(frameLength, this.wasmModule.exports.Uint8Array_ID.value));
147
+ this.wasmModule.exports.stackBlur(framePtr, this.tempPtr, width, height, blurRadius);
148
+ this.wasmModule.exports.createMotionMask(this.firstFramePtr, framePtr, width, height, threshold);
149
+ this.wasmModule.exports.dilate(framePtr, this.tempPtr, width, height, dilationSize);
150
+ const numBoxes = this.wasmModule.exports.findBoundingBoxes(framePtr, this.visitedPtr, this.queuePtr, boxesPtr, width, height, motionArea);
151
+ const boxes = [];
152
+ const boxesArray = new Int32Array(this.wasmModule.exports.memory.buffer, boxesPtr, numBoxes * 4);
153
+ for (let i = 0; i < numBoxes; i++) {
154
+ const x = boxesArray[i * 4];
155
+ const y = boxesArray[i * 4 + 1];
156
+ const w = boxesArray[i * 4 + 2];
157
+ const h = boxesArray[i * 4 + 3];
158
+ boxes.push([x, y, x + w, y + h]);
159
+ }
160
+ // console.log('Bounding boxes:', boxes);
161
+ this.wasmModule.exports.__unpin(framePtr);
162
+ this.wasmModule.exports.__unpin(boxesPtr);
163
+ this.wasmModule.exports.__collect();
164
+ return boxes;
165
+ }
166
+ createCameraStorage() {
167
+ let cameraStorage = this.api.storageController.getCameraStorage(this.cameraDevice.id);
168
+ if (!cameraStorage) {
169
+ cameraStorage = this.api.storageController.createCameraStorage(this, this.cameraDevice.id, {
170
+ area: {
171
+ type: 'number',
172
+ key: 'area',
173
+ title: 'Area',
174
+ description: 'Minimum area for a motion detection',
175
+ store: true,
176
+ defaultValue: defaultMotionArea,
177
+ minimum: 10,
178
+ maximum: 1000,
179
+ step: 1,
180
+ required: true,
181
+ onSet: async (newValue, oldValue) => {
182
+ this.logger.log(this.cameraDevice.name, `Motion area changed from ${oldValue} to ${newValue}`);
183
+ },
184
+ },
185
+ threshold: {
186
+ type: 'number',
187
+ key: 'threshold',
188
+ title: 'Threshold',
189
+ description: 'Threshold for motion detection',
190
+ store: true,
191
+ defaultValue: defaultThreshold,
192
+ minimum: 1,
193
+ maximum: 255,
194
+ step: 1,
195
+ required: true,
196
+ onSet: async (newValue, oldValue) => {
197
+ this.logger.log(this.cameraDevice.name, `Motion threshold changed from ${oldValue} to ${newValue}`);
198
+ },
199
+ },
200
+ blurRadius: {
201
+ type: 'number',
202
+ key: 'blurRadius',
203
+ title: 'Blur Radius',
204
+ description: 'Blur radius for motion detection',
205
+ store: true,
206
+ defaultValue: defaultBlurRadius,
207
+ minimum: 1,
208
+ maximum: 21,
209
+ step: 1,
210
+ required: true,
211
+ onSet: async (newValue, oldValue) => {
212
+ this.logger.log(this.cameraDevice.name, `Motion blur radius changed from ${oldValue} to ${newValue}`);
213
+ },
214
+ },
215
+ dilationSize: {
216
+ type: 'number',
217
+ key: 'dilationSize',
218
+ title: 'Dilation Size',
219
+ description: 'Dilation size for motion detection',
220
+ store: true,
221
+ defaultValue: defaultDilationSize,
222
+ minimum: 1,
223
+ maximum: 21,
224
+ step: 1,
225
+ required: true,
226
+ onSet: async (newValue, oldValue) => {
227
+ this.logger.log(this.cameraDevice.name, `Motion dilation size changed from ${oldValue} to ${newValue}`);
228
+ },
229
+ },
230
+ referenceFrameFrequency: {
231
+ type: 'number',
232
+ key: 'referenceFrameFrequency',
233
+ title: 'Reference Frame Frequency',
234
+ description: 'Frequency to update the reference frame',
235
+ store: true,
236
+ defaultValue: defaultReferenceFrameFrequency,
237
+ minimum: 1,
238
+ maximum: 60,
239
+ step: 1,
240
+ required: true,
241
+ onSet: async (newValue, oldValue) => {
242
+ this.logger.log(this.cameraDevice.name, `Motion reference frame frequency changed from ${oldValue}s to ${newValue}s`);
243
+ },
244
+ },
245
+ });
246
+ }
247
+ return cameraStorage;
248
+ }
249
+ }
250
+ //# sourceMappingURL=detector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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EAAE;oBACX,IAAI,EAAE,CAAC;oBACP,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,KAAK,EAAE,QAAgB,EAAE,QAAgB,EAAE,EAAE;wBAClD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,qCAAqC,QAAQ,OAAO,QAAQ,EAAE,CAAC,CAAC;oBAC1G,CAAC;iBACF;gBACD,uBAAuB,EAAE;oBACvB,IAAI,EAAE,QAAQ;oBACd,GAAG,EAAE,yBAAyB;oBAC9B,KAAK,EAAE,2BAA2B;oBAClC,WAAW,EAAE,yCAAyC;oBACtD,KAAK,EAAE,IAAI;oBACX,YAAY,EAAE,8BAA8B;oBAC5C,OAAO,EAAE,CAAC;oBACV,OAAO,EAAE,EAAE;oBACX,IAAI,EAAE,CAAC;oBACP,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,KAAK,EAAE,QAAgB,EAAE,QAAgB,EAAE,EAAE;wBAClD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,iDAAiD,QAAQ,QAAQ,QAAQ,GAAG,CAAC,CAAC;oBACxH,CAAC;iBACF;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,aAAa,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import type { BasePlugin, CameraDevice, FormSubmitResponse, PluginAPI, PluginLogger } from '@camera.ui/types';
2
+ export default class WASMMotion implements BasePlugin {
3
+ logger: PluginLogger;
4
+ api: PluginAPI;
5
+ private cameras;
6
+ private detectors;
7
+ constructor(logger: PluginLogger, api: PluginAPI);
8
+ configureCameras(cameras: CameraDevice[]): void;
9
+ onFormSubmit(actionId: string, payload: any): Promise<FormSubmitResponse | void>;
10
+ private start;
11
+ private stop;
12
+ private cameraSelected;
13
+ private cameraDeselected;
14
+ private createDetector;
15
+ private removeDetector;
16
+ }
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ import { CameraDetector } from './detector.js';
2
+ export default class WASMMotion {
3
+ logger;
4
+ api;
5
+ cameras = new Map();
6
+ detectors = new Map();
7
+ constructor(logger, api) {
8
+ this.api = api;
9
+ this.logger = logger;
10
+ this.api.on('finishLaunching', this.start.bind(this));
11
+ this.api.on('shutdown', this.stop.bind(this));
12
+ this.api.deviceManager.on('cameraSelected', this.cameraSelected.bind(this));
13
+ this.api.deviceManager.on('cameraDeselected', this.cameraDeselected.bind(this));
14
+ }
15
+ configureCameras(cameras) {
16
+ for (const camera of cameras) {
17
+ this.cameras.set(camera.id, camera);
18
+ }
19
+ }
20
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
21
+ async onFormSubmit(actionId, payload) { }
22
+ async start() {
23
+ this.logger.log('Plugin started');
24
+ for (const camera of this.cameras) {
25
+ this.createDetector(camera[1]);
26
+ }
27
+ }
28
+ stop() {
29
+ this.logger.log('Plugin stopped');
30
+ for (const detector of this.detectors.values()) {
31
+ detector.close();
32
+ }
33
+ this.detectors.clear();
34
+ }
35
+ cameraSelected(camera, extension) {
36
+ this.logger.log(`Camera added (${extension}): ${camera.name}`);
37
+ this.cameras.set(camera.id, camera);
38
+ this.createDetector(camera);
39
+ }
40
+ cameraDeselected(cameraId, extension) {
41
+ const camera = this.cameras.get(cameraId);
42
+ if (camera) {
43
+ this.logger.log(`Camera removed (${extension}): ${camera.name}`);
44
+ this.removeDetector(cameraId);
45
+ this.cameras.delete(cameraId);
46
+ }
47
+ }
48
+ createDetector(cameraDevice) {
49
+ const detector = new CameraDetector(cameraDevice, this.api, this.logger);
50
+ this.detectors.set(cameraDevice.id, detector);
51
+ }
52
+ removeDetector(cameraId) {
53
+ const detector = this.detectors.get(cameraId);
54
+ if (detector) {
55
+ detector.close();
56
+ this.detectors.delete(cameraId);
57
+ }
58
+ }
59
+ }
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names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AE,EAAE,QAAQ,CAAC,CAAC;IAChD,CAAC;IAEO,cAAc,CAAC,QAAgB;QACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE9C,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,187 @@
1
+ declare namespace __AdaptedExports {
2
+ /** Exported memory */
3
+ export const memory: WebAssembly.Memory;
4
+ // Exported runtime interface
5
+ export function __new(size: number, id: number): number;
6
+ export function __pin(ptr: number): number;
7
+ export function __unpin(ptr: number): void;
8
+ export function __collect(): void;
9
+ export const __rtti_base: number;
10
+ /**
11
+ * assembly/console/log
12
+ * @param s `~lib/string/String`
13
+ */
14
+ export function log(s: string): void;
15
+ /**
16
+ * assembly/index/resetStackPool
17
+ * @param radius `i32`
18
+ */
19
+ export function resetStackPool(radius: number): void;
20
+ /**
21
+ * assembly/index/stackBlur
22
+ * @param framePtr `usize`
23
+ * @param tempPtr `usize`
24
+ * @param width `i32`
25
+ * @param height `i32`
26
+ * @param radius `i32`
27
+ */
28
+ export function stackBlur(framePtr: number, tempPtr: number, width: number, height: number, radius: number): void;
29
+ /**
30
+ * assembly/index/createMotionMask
31
+ * @param frame1Ptr `usize`
32
+ * @param frame2Ptr `usize`
33
+ * @param width `i32`
34
+ * @param height `i32`
35
+ * @param threshold `i32`
36
+ */
37
+ export function createMotionMask(frame1Ptr: number, frame2Ptr: number, width: number, height: number, threshold: number): void;
38
+ /**
39
+ * assembly/index/dilate
40
+ * @param framePtr `usize`
41
+ * @param tempPtr `usize`
42
+ * @param width `i32`
43
+ * @param height `i32`
44
+ * @param size `i32`
45
+ */
46
+ export function dilate(framePtr: number, tempPtr: number, width: number, height: number, size: number): void;
47
+ /**
48
+ * assembly/index/findBoundingBoxes
49
+ * @param framePtr `usize`
50
+ * @param visitedPtr `usize`
51
+ * @param queuePtr `usize`
52
+ * @param boxesPtr `usize`
53
+ * @param width `i32`
54
+ * @param height `i32`
55
+ * @param minArea `i32`
56
+ * @returns `i32`
57
+ */
58
+ export function findBoundingBoxes(framePtr: number, visitedPtr: number, queuePtr: number, boxesPtr: number, width: number, height: number, minArea: number): number;
59
+ /**
60
+ * assembly/index/detectMotion
61
+ * @param frame1Ptr `usize`
62
+ * @param frame2Ptr `usize`
63
+ * @param tempPtr `usize`
64
+ * @param visitedPtr `usize`
65
+ * @param queuePtr `usize`
66
+ * @param boxesPtr `usize`
67
+ * @param width `i32`
68
+ * @param height `i32`
69
+ * @param blurRadius `i32`
70
+ * @param dilationSize `i32`
71
+ * @param motionThreshold `i32`
72
+ * @param motionArea `i32`
73
+ * @returns `i32`
74
+ */
75
+ export function detectMotion(frame1Ptr: number, frame2Ptr: number, tempPtr: number, visitedPtr: number, queuePtr: number, boxesPtr: number, width: number, height: number, blurRadius: number, dilationSize: number, motionThreshold: number, motionArea: number): number;
76
+ /** assembly/index/Uint8Array_ID */
77
+ export const Uint8Array_ID: {
78
+ /** @type `u32` */
79
+ get value(): number
80
+ };
81
+ /**
82
+ * assembly/test/blurFrameSIMD
83
+ * @param framePtr `usize`
84
+ * @param tempFramePtr `usize`
85
+ * @param width `i32`
86
+ * @param height `i32`
87
+ * @param radius `i32`
88
+ */
89
+ export function blurFrameSIMD(framePtr: number, tempFramePtr: number, width: number, height: number, radius: number): void;
90
+ /**
91
+ * assembly/test/detectMotionSIMD
92
+ * @param prevFramePtr `usize`
93
+ * @param currentFramePtr `usize`
94
+ * @param width `i32`
95
+ * @param height `i32`
96
+ * @param threshold `i32`
97
+ * @param motionMaskPtr `usize`
98
+ */
99
+ export function detectMotionSIMD(prevFramePtr: number, currentFramePtr: number, width: number, height: number, threshold: number, motionMaskPtr: number): void;
100
+ /**
101
+ * assembly/test/dilateMotionMask
102
+ * @param motionMaskPtr `usize`
103
+ * @param tempMaskPtr `usize`
104
+ * @param width `i32`
105
+ * @param height `i32`
106
+ * @param dilationSize `i32`
107
+ */
108
+ export function dilateMotionMask(motionMaskPtr: number, tempMaskPtr: number, width: number, height: number, dilationSize: number): void;
109
+ /**
110
+ * assembly/test/calculateBoundingBoxes
111
+ * @param motionMaskPtr `usize`
112
+ * @param visitedPtr `usize`
113
+ * @param width `i32`
114
+ * @param height `i32`
115
+ * @param motionArea `i32`
116
+ * @param boundingBoxesPtr `usize`
117
+ * @param stackXPtr `usize`
118
+ * @param stackYPtr `usize`
119
+ * @returns `i32`
120
+ */
121
+ export function calculateBoundingBoxes(motionMaskPtr: number, visitedPtr: number, width: number, height: number, motionArea: number, boundingBoxesPtr: number, stackXPtr: number, stackYPtr: number): number;
122
+ /**
123
+ * assembly/test/calculateBoundingBoxesSIMD
124
+ * @param motionMaskPtr `usize`
125
+ * @param visitedPtr `usize`
126
+ * @param width `i32`
127
+ * @param height `i32`
128
+ * @param motionArea `i32`
129
+ * @param boundingBoxesPtr `usize`
130
+ * @param stackXPtr `usize`
131
+ * @param stackYPtr `usize`
132
+ * @returns `i32`
133
+ */
134
+ export function calculateBoundingBoxesSIMD(motionMaskPtr: number, visitedPtr: number, width: number, height: number, motionArea: number, boundingBoxesPtr: number, stackXPtr: number, stackYPtr: number): number;
135
+ /**
136
+ * assembly/test2/detectMotion
137
+ * @param prevFramePtr `usize`
138
+ * @param curFramePtr `usize`
139
+ * @param blurFrame1Ptr `usize`
140
+ * @param blurFrame2Ptr `usize`
141
+ * @param motionMaskPtr `usize`
142
+ * @param dilateMaskPtr `usize`
143
+ * @param boundingBoxesPtr `usize`
144
+ * @param width `i32`
145
+ * @param height `i32`
146
+ * @param blurRadius `i32`
147
+ * @param threshold `i32`
148
+ * @param dilationSize `i32`
149
+ * @param motionArea `i32`
150
+ * @returns `i32`
151
+ */
152
+ export function detectMotion(prevFramePtr: number, curFramePtr: number, blurFrame1Ptr: number, blurFrame2Ptr: number, motionMaskPtr: number, dilateMaskPtr: number, boundingBoxesPtr: number, width: number, height: number, blurRadius: number, threshold: number, dilationSize: number, motionArea: number): number;
153
+ /**
154
+ * assembly/test3/blurFrame
155
+ * @param framePtr `usize`
156
+ * @param blurPtr `usize`
157
+ * @param width `i32`
158
+ * @param height `i32`
159
+ * @param radius `i32`
160
+ */
161
+ export function blurFrame(framePtr: number, blurPtr: number, width: number, height: number, radius: number): void;
162
+ /**
163
+ * assembly/test3/detectMotion
164
+ * @param frame1Ptr `usize`
165
+ * @param frame2Ptr `usize`
166
+ * @param blurredFrame1Ptr `usize`
167
+ * @param blurredFrame2Ptr `usize`
168
+ * @param maskPtr `usize`
169
+ * @param dilatePtr `usize`
170
+ * @param visitedPtr `usize`
171
+ * @param queuePtr `usize`
172
+ * @param boxesPtr `usize`
173
+ * @param width `i32`
174
+ * @param height `i32`
175
+ * @param blurRadius `i32`
176
+ * @param dilationSize `i32`
177
+ * @param motionThreshold `i32`
178
+ * @param motionArea `i32`
179
+ * @returns `i32`
180
+ */
181
+ export function detectMotion(frame1Ptr: number, frame2Ptr: number, blurredFrame1Ptr: number, blurredFrame2Ptr: number, maskPtr: number, dilatePtr: number, visitedPtr: number, queuePtr: number, boxesPtr: number, width: number, height: number, blurRadius: number, dilationSize: number, motionThreshold: number, motionArea: number): number;
182
+ }
183
+ /** Instantiates the compiled WebAssembly module with the given imports. */
184
+ export declare function instantiate(module: WebAssembly.Module, imports: {
185
+ console: unknown,
186
+ env: unknown,
187
+ }): Promise<typeof __AdaptedExports>;
@@ -0,0 +1,65 @@
1
+ export async function instantiate(module, imports = {}) {
2
+ const __module0 = imports.console;
3
+ const adaptedImports = {
4
+ console: Object.assign(Object.create(__module0), {
5
+ log(s) {
6
+ // assembly/console/log(~lib/string/String) => void
7
+ s = __liftString(s >>> 0);
8
+ __module0.log(s);
9
+ },
10
+ }),
11
+ env: Object.assign(Object.create(globalThis), imports.env || {}, {
12
+ abort(message, fileName, lineNumber, columnNumber) {
13
+ // ~lib/builtins/abort(~lib/string/String | null?, ~lib/string/String | null?, u32?, u32?) => void
14
+ message = __liftString(message >>> 0);
15
+ fileName = __liftString(fileName >>> 0);
16
+ lineNumber = lineNumber >>> 0;
17
+ columnNumber = columnNumber >>> 0;
18
+ (() => {
19
+ // @external.js
20
+ throw Error(`${message} in ${fileName}:${lineNumber}:${columnNumber}`);
21
+ })();
22
+ },
23
+ }),
24
+ };
25
+ const { exports } = await WebAssembly.instantiate(module, adaptedImports);
26
+ const memory = exports.memory || imports.env.memory;
27
+ const adaptedExports = Object.setPrototypeOf({
28
+ log(s) {
29
+ // assembly/console/log(~lib/string/String) => void
30
+ s = __lowerString(s) || __notnull();
31
+ exports.log(s);
32
+ },
33
+ Uint8Array_ID: {
34
+ // assembly/index/Uint8Array_ID: u32
35
+ valueOf() { return this.value; },
36
+ get value() {
37
+ return exports.Uint8Array_ID.value >>> 0;
38
+ }
39
+ },
40
+ }, exports);
41
+ function __liftString(pointer) {
42
+ if (!pointer) return null;
43
+ const
44
+ end = pointer + new Uint32Array(memory.buffer)[pointer - 4 >>> 2] >>> 1,
45
+ memoryU16 = new Uint16Array(memory.buffer);
46
+ let
47
+ start = pointer >>> 1,
48
+ string = "";
49
+ while (end - start > 1024) string += String.fromCharCode(...memoryU16.subarray(start, start += 1024));
50
+ return string + String.fromCharCode(...memoryU16.subarray(start, end));
51
+ }
52
+ function __lowerString(value) {
53
+ if (value == null) return 0;
54
+ const
55
+ length = value.length,
56
+ pointer = exports.__new(length << 1, 2) >>> 0,
57
+ memoryU16 = new Uint16Array(memory.buffer);
58
+ for (let i = 0; i < length; ++i) memoryU16[(pointer >>> 1) + i] = value.charCodeAt(i);
59
+ return pointer;
60
+ }
61
+ function __notnull() {
62
+ throw TypeError("value must not be null");
63
+ }
64
+ return adaptedExports;
65
+ }
Binary file
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "displayName": "WASM Motion",
3
+ "name": "@camera.ui/camera-ui-wasm-motion",
4
+ "version": "0.0.1",
5
+ "description": "camera.ui wasm motion detection plugin",
6
+ "author": "seydx (https://github.com/seydx/camera.ui)",
7
+ "main": "./dist/index.js",
8
+ "type": "module",
9
+ "scripts": {
10
+ "build": "rimraf dist && npm run build:wasm && tsc && copyfiles -u 2 src/wasm/build/**/* ./dist/wasm/",
11
+ "build:wasm": "cd ./src/wasm && asc assembly/* --config asconfig.json && cd ../../",
12
+ "format": "prettier --write 'src/' --ignore-unknown --no-error-on-unmatched-pattern",
13
+ "lint": "eslint --fix --ext .js,.ts .",
14
+ "update": "updates --update ./",
15
+ "install-updates": "npm i --save",
16
+ "prepublishOnly": "npm i --package-lock-only && npm run lint && npm run format && npm run build"
17
+ },
18
+ "devDependencies": {
19
+ "@camera.ui/types": "^0.0.53",
20
+ "@rushstack/eslint-patch": "^1.10.4",
21
+ "@types/fs-extra": "^11.0.4",
22
+ "@types/node": "^22.1.0",
23
+ "@types/ws": "^8.5.12",
24
+ "@typescript-eslint/eslint-plugin": "^8.0.1",
25
+ "@typescript-eslint/parser": "^8.0.1",
26
+ "assemblyscript": "^0.27.29",
27
+ "assemblyscript-prettier": "^3.0.1",
28
+ "concurrently": "^8.2.2",
29
+ "copyfiles": "^2.4.1",
30
+ "eslint": "8.57.0",
31
+ "eslint-config-prettier": "^9.1.0",
32
+ "eslint-plugin-prettier": "^5.2.1",
33
+ "fs-extra": "^11.2.0",
34
+ "prettier": "^3.3.3",
35
+ "rimraf": "^6.0.1",
36
+ "set-interval-async": "^3.0.3",
37
+ "sharp": "^0.33.4",
38
+ "typescript": "^5.5.4",
39
+ "updates": "^16.3.7"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/seydx/camera.ui/issues"
43
+ },
44
+ "engines": {
45
+ "camera.ui": ">=0.0.1",
46
+ "node": ">=18.12.0"
47
+ },
48
+ "homepage": "https://github.com/seydx/camera.ui#readme",
49
+ "keywords": [
50
+ "camera-ui-plugin",
51
+ "smtp",
52
+ "motion",
53
+ "detection"
54
+ ],
55
+ "license": "MIT",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/seydx/camera.ui.git"
59
+ },
60
+ "camera.ui": {
61
+ "extension": "motionDetection",
62
+ "dependencies": []
63
+ },
64
+ "dependencies": {
65
+ "@assemblyscript/loader": "^0.27.29",
66
+ "as-wasi": "^0.6.0"
67
+ }
68
+ }