@techstark/opencv-js 4.12.0-release.1 → 5.0.0-release.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/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # opencv-js
2
2
 
3
- OpenCV JavaScript version (NPM package) for node.js or browser. Get started guide [OpenCV.js Tutorials](https://docs.opencv.org/4.12.0/#:~:text=OpenCV%2DPython%20Tutorials-,OpenCV.js%20Tutorials,-Tutorials%20for%20contrib).
3
+ OpenCV JavaScript version (NPM package) for node.js or browser. Get started guide [OpenCV.js Tutorials](https://docs.opencv.org/5.0.0/#:~:text=OpenCV%2DPython%20Tutorials-,OpenCV.js%20Tutorials,-Tutorials%20for%20contrib).
4
4
 
5
- The file `opencv.js` was downloaded from https://docs.opencv.org/4.12.0/opencv.js
5
+ The file `opencv.js` was downloaded from https://docs.opencv.org/5.0.0/opencv.js
6
6
 
7
7
  TypeScript is supported (thanks to `mirada`).
8
8
 
@@ -16,10 +16,14 @@ async function getOpenCv() {
16
16
  if (cvModule instanceof Promise) {
17
17
  cv = await cvModule;
18
18
  } else {
19
- await new Promise((resolve) => {
20
- cvModule.onRuntimeInitialized = () => resolve();
21
- });
22
- cv = cvModule;
19
+ if (cvModule.Mat) {
20
+ cv = cvModule;
21
+ } else {
22
+ await new Promise((resolve) => {
23
+ cvModule.onRuntimeInitialized = () => resolve();
24
+ });
25
+ cv = cvModule;
26
+ }
23
27
  }
24
28
  return { cv };
25
29
  }
package/dist/opencv.js CHANGED
Binary file
@@ -1,14 +1,22 @@
1
- diff --git a/dist/opencv.js b/dist/opencv.js
2
- index af4111b..3ba8a69 100644
3
1
  --- a/dist/opencv.js
4
2
  +++ b/dist/opencv.js
5
- @@ -41,7 +41,7 @@ else if (typeof define === 'function' && define['amd'])
6
- define([], () => cv);
7
-
8
- if (typeof Module === 'undefined')
3
+ @@ UMD wrapper call @@
4
+ -}(this, function () {
5
+ +}(globalThis, function () {
6
+
7
+ Fixes: In browser ESM (<script type="module">), top-level `this` is
8
+ undefined. The UMD else branch `root.cv = factory()` then throws:
9
+ TypeError: Cannot set properties of undefined (setting 'cv')
10
+ Using `globalThis` is always defined in modern environments.
11
+
12
+ @@ UMD factory tail @@
13
+ - if (typeof Module === 'undefined')
9
14
  - Module = {};
15
+ + if (typeof Module === 'undefined')
10
16
  + var Module = {};
11
- return cv(Module);
12
- }));
13
-
14
-
17
+
18
+ Fixes: When opencv.js is bundled by Webpack (which wraps everything in
19
+ "use strict"), the bare `Module = {}` assignment throws:
20
+ ReferenceError: Module is not defined
21
+ Declaring with `var` creates a local variable instead of an implicit
22
+ global assignment, which is safe in strict mode.
@@ -0,0 +1,33 @@
1
+ import type { Algorithm, double, InputArray, OutputArray } from "./_types";
2
+ /**
3
+ * Base class for background/foreground segmentation algorithms.
4
+ *
5
+ * The class is only used to define the common interface for the whole family of background/foreground
6
+ * segmentation algorithms.
7
+ *
8
+ * Source:
9
+ * [opencv2/video.hpp](https://github.com/opencv/opencv/tree/master/modules/video/include/opencv2/video/background_segm.hpp).
10
+ */
11
+ export declare class BackgroundSubtractor extends Algorithm {
12
+ constructor();
13
+ /**
14
+ * Computes a foreground mask.
15
+ *
16
+ * @param image Next video frame.
17
+ * @param fgmask The output foreground mask as an 8-bit binary image.
18
+ * @param learningRate The value between 0 and 1 that indicates how fast the background model is learnt.
19
+ * Negative parameter value makes the algorithm use some automatically chosen learning rate.
20
+ * 0 means that the background model is not updated at all, 1 means that the background model is
21
+ * completely reinitialized from the last frame.
22
+ */
23
+ apply(image: InputArray, fgmask: OutputArray, learningRate?: double): void;
24
+ /**
25
+ * Computes a background image.
26
+ *
27
+ * @param backgroundImage The output background image.
28
+ *
29
+ * @note Sometimes the background image can be very blurry, as it contain the average background
30
+ * statistics.
31
+ */
32
+ getBackgroundImage(backgroundImage: OutputArray): void;
33
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=BackgroundSubtractor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackgroundSubtractor.js","sourceRoot":"","sources":["../../../../src/types/opencv/BackgroundSubtractor.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { BackgroundSubtractor, bool, double, int } from "./_types";
2
+ /**
3
+ * Gaussian Mixture-based Background/Foreground Segmentation Algorithm.
4
+ *
5
+ * The class implements the Gaussian mixture model background subtraction described in [Zivkovic2004]
6
+ * and [Zivkovic2006].
7
+ *
8
+ * Source:
9
+ * [opencv2/video.hpp](https://github.com/opencv/opencv/tree/master/modules/video/include/opencv2/video/background_segm.hpp).
10
+ */
11
+ export declare class BackgroundSubtractorMOG2 extends BackgroundSubtractor {
12
+ /**
13
+ * @param history Length of the history.
14
+ * @param varThreshold Threshold on the squared Mahalanobis distance between the pixel and the model
15
+ * to decide whether a pixel is well described by the background model. This parameter does not
16
+ * affect the background update.
17
+ * @param detectShadows If true, the algorithm will detect shadows and mark them. It decreases the
18
+ * speed a bit, so if you do not need this feature, set the parameter to false.
19
+ */
20
+ constructor(history?: int, varThreshold?: double, detectShadows?: bool);
21
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=BackgroundSubtractorMOG2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackgroundSubtractorMOG2.js","sourceRoot":"","sources":["../../../../src/types/opencv/BackgroundSubtractorMOG2.ts"],"names":[],"mappings":""}
@@ -706,6 +706,11 @@ export declare class Mat extends EmscriptenEmbindInstance {
706
706
  * the array copy is a continuous array occupying [total()]*elemSize() bytes.
707
707
  */
708
708
  clone(): Mat;
709
+ /**
710
+ * Creates a deep copy of the Mat with independent data buffer.
711
+ * This method ensures the copied Mat has its own data that is independent of the original.
712
+ */
713
+ mat_clone(): Mat;
709
714
  /**
710
715
  * The method makes a new header for the specified matrix column and returns it. This is an O(1)
711
716
  * operation, regardless of the matrix size. The underlying data of the new matrix is shared with the
@@ -1,6 +1,8 @@
1
1
  export * from "./Affine3";
2
2
  export * from "./Algorithm";
3
3
  export * from "./AutoBuffer";
4
+ export * from "./BackgroundSubtractor";
5
+ export * from "./BackgroundSubtractorMOG2";
4
6
  export * from "./BFMatcher";
5
7
  export * from "./BOWTrainer";
6
8
  export * from "./calib3d";
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Affine3"), exports);
18
18
  __exportStar(require("./Algorithm"), exports);
19
19
  __exportStar(require("./AutoBuffer"), exports);
20
+ __exportStar(require("./BackgroundSubtractor"), exports);
21
+ __exportStar(require("./BackgroundSubtractorMOG2"), exports);
20
22
  __exportStar(require("./BFMatcher"), exports);
21
23
  __exportStar(require("./BOWTrainer"), exports);
22
24
  __exportStar(require("./calib3d"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"_types.js","sourceRoot":"","sources":["../../../../src/types/opencv/_types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,8CAA4B;AAC5B,+CAA6B;AAC7B,8CAA4B;AAC5B,+CAA6B;AAC7B,4CAA0B;AAC1B,sDAAoC;AACpC,+CAA6B;AAC7B,iDAA+B;AAC/B,uDAAqC;AACrC,+CAA6B;AAC7B,sDAAoC;AACpC,wCAAsB;AACtB,kDAAgC;AAChC,8CAA4B;AAC5B,8CAA4B;AAC5B,oDAAkC;AAClC,4CAA0B;AAC1B,sDAAoC;AACpC,kDAAgC;AAChC,8DAA4C;AAC5C,qDAAmC;AACnC,iDAA+B;AAC/B,oDAAkC;AAClC,mDAAiC;AACjC,iDAA+B;AAC/B,iDAA+B;AAC/B,mDAAiC;AACjC,kDAAgC;AAChC,sDAAoC;AACpC,2CAAyB;AACzB,6CAA2B;AAC3B,wCAAsB;AACtB,4CAA0B;AAC1B,0CAAwB;AACxB,yCAAuB;AACvB,yCAAuB;AACvB,8CAA4B;AAC5B,wCAAsB;AACtB,wCAAsB;AACtB,kDAAgC;AAChC,gDAA8B;AAC9B,+CAA6B;AAC7B,8CAA4B;AAC5B,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B"}
1
+ {"version":3,"file":"_types.js","sourceRoot":"","sources":["../../../../src/types/opencv/_types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,8CAA4B;AAC5B,+CAA6B;AAC7B,yDAAuC;AACvC,6DAA2C;AAC3C,8CAA4B;AAC5B,+CAA6B;AAC7B,4CAA0B;AAC1B,sDAAoC;AACpC,+CAA6B;AAC7B,iDAA+B;AAC/B,uDAAqC;AACrC,+CAA6B;AAC7B,sDAAoC;AACpC,wCAAsB;AACtB,kDAAgC;AAChC,8CAA4B;AAC5B,8CAA4B;AAC5B,oDAAkC;AAClC,4CAA0B;AAC1B,sDAAoC;AACpC,kDAAgC;AAChC,8DAA4C;AAC5C,qDAAmC;AACnC,iDAA+B;AAC/B,oDAAkC;AAClC,mDAAiC;AACjC,iDAA+B;AAC/B,iDAA+B;AAC/B,mDAAiC;AACjC,kDAAgC;AAChC,sDAAoC;AACpC,2CAAyB;AACzB,6CAA2B;AAC3B,wCAAsB;AACtB,4CAA0B;AAC1B,0CAAwB;AACxB,yCAAuB;AACvB,yCAAuB;AACvB,8CAA4B;AAC5B,wCAAsB;AACtB,wCAAsB;AACtB,kDAAgC;AAChC,gDAA8B;AAC9B,+CAA6B;AAC7B,8CAA4B;AAC5B,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techstark/opencv-js",
3
- "version": "4.12.0-release.1",
3
+ "version": "5.0.0-release.1",
4
4
  "description": "OpenCV JavaScript version for node.js or browser",
5
5
  "main": "dist/opencv.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -12,15 +12,16 @@
12
12
  "build": "tsc",
13
13
  "prepack": "npm run build",
14
14
  "format": "prettier --write \"src/**/*.ts\"",
15
- "test": "jest"
15
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
16
+ "test:compat": "node test/compat/run-all.mjs"
16
17
  },
17
18
  "devDependencies": {
18
- "@types/jest": "^29.5.14",
19
- "jest": "^29.7.0",
20
- "jimp": "^1.6.0",
21
- "prettier": "^3.5.3",
22
- "ts-jest": "^29.3.4",
23
- "typescript": "^5.8.3"
19
+ "@types/jest": "^30.0.0",
20
+ "jest": "^30.0.0",
21
+ "jimp": "^1.6.1",
22
+ "prettier": "^3.8.4",
23
+ "ts-jest": "^29.4.11",
24
+ "typescript": "^6.0.3"
24
25
  },
25
26
  "repository": {
26
27
  "type": "git",
@@ -0,0 +1,36 @@
1
+ import type { Algorithm, bool, double, InputArray, OutputArray } from "./_types";
2
+
3
+ /**
4
+ * Base class for background/foreground segmentation algorithms.
5
+ *
6
+ * The class is only used to define the common interface for the whole family of background/foreground
7
+ * segmentation algorithms.
8
+ *
9
+ * Source:
10
+ * [opencv2/video.hpp](https://github.com/opencv/opencv/tree/master/modules/video/include/opencv2/video/background_segm.hpp).
11
+ */
12
+ export declare class BackgroundSubtractor extends Algorithm {
13
+ public constructor();
14
+
15
+ /**
16
+ * Computes a foreground mask.
17
+ *
18
+ * @param image Next video frame.
19
+ * @param fgmask The output foreground mask as an 8-bit binary image.
20
+ * @param learningRate The value between 0 and 1 that indicates how fast the background model is learnt.
21
+ * Negative parameter value makes the algorithm use some automatically chosen learning rate.
22
+ * 0 means that the background model is not updated at all, 1 means that the background model is
23
+ * completely reinitialized from the last frame.
24
+ */
25
+ public apply(image: InputArray, fgmask: OutputArray, learningRate?: double): void;
26
+
27
+ /**
28
+ * Computes a background image.
29
+ *
30
+ * @param backgroundImage The output background image.
31
+ *
32
+ * @note Sometimes the background image can be very blurry, as it contain the average background
33
+ * statistics.
34
+ */
35
+ public getBackgroundImage(backgroundImage: OutputArray): void;
36
+ }
@@ -0,0 +1,22 @@
1
+ import type { BackgroundSubtractor, bool, double, int } from "./_types";
2
+
3
+ /**
4
+ * Gaussian Mixture-based Background/Foreground Segmentation Algorithm.
5
+ *
6
+ * The class implements the Gaussian mixture model background subtraction described in [Zivkovic2004]
7
+ * and [Zivkovic2006].
8
+ *
9
+ * Source:
10
+ * [opencv2/video.hpp](https://github.com/opencv/opencv/tree/master/modules/video/include/opencv2/video/background_segm.hpp).
11
+ */
12
+ export declare class BackgroundSubtractorMOG2 extends BackgroundSubtractor {
13
+ /**
14
+ * @param history Length of the history.
15
+ * @param varThreshold Threshold on the squared Mahalanobis distance between the pixel and the model
16
+ * to decide whether a pixel is well described by the background model. This parameter does not
17
+ * affect the background update.
18
+ * @param detectShadows If true, the algorithm will detect shadows and mark them. It decreases the
19
+ * speed a bit, so if you do not need this feature, set the parameter to false.
20
+ */
21
+ public constructor(history?: int, varThreshold?: double, detectShadows?: bool);
22
+ }
@@ -787,6 +787,12 @@ export declare class Mat extends EmscriptenEmbindInstance {
787
787
  */
788
788
  public clone(): Mat;
789
789
 
790
+ /**
791
+ * Creates a deep copy of the Mat with independent data buffer.
792
+ * This method ensures the copied Mat has its own data that is independent of the original.
793
+ */
794
+ public mat_clone(): Mat;
795
+
790
796
  /**
791
797
  * The method makes a new header for the specified matrix column and returns it. This is an O(1)
792
798
  * operation, regardless of the matrix size. The underlying data of the new matrix is shared with the
@@ -1,6 +1,8 @@
1
1
  export * from "./Affine3";
2
2
  export * from "./Algorithm";
3
3
  export * from "./AutoBuffer";
4
+ export * from "./BackgroundSubtractor";
5
+ export * from "./BackgroundSubtractorMOG2";
4
6
  export * from "./BFMatcher";
5
7
  export * from "./BOWTrainer";
6
8
  export * from "./calib3d";