Skip to content

Commit

Permalink
renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
CezaryDanielNowak committed Jun 4, 2024
1 parent cc912b4 commit 85e3302
Show file tree
Hide file tree
Showing 6 changed files with 7,292 additions and 9,927 deletions.
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# OpenCV-Wasm

[![Build Status](https://travis-ci.org/echamudi/opencv-wasm.svg?branch=master)](https://travis-ci.org/echamudi/opencv-wasm)

Precompiled OpenCV to JavaScript + WebAssembly for node.js and deno environment. 🦕

In this Wasm-compiled OpenCV, there's no need to have OpenCV installed in the machine. The entire OpenCV library is already inside this package (`opencv.js` and `opencv.wasm`).
Expand All @@ -24,7 +22,7 @@ npm install opencv-wasm
```
Code example:
```js
const { cv, cvTranslateError } = require('opencv-wasm');
const { cv, cvTranslateError } = require('fast-opencv-wasm');

let mat = cv.matFromArray(2, 3, cv.CV_8UC1, [1, 2, 3, 4, 5, 6]);
console.log('cols =', mat.cols, '; rows =', mat.rows);
Expand Down Expand Up @@ -69,9 +67,33 @@ Int8Array(6) [ 1, 4, 2, 5, 3, 6 ]
*/
```

## Using in the browser
```
<script src="/opencv.js"></script>
<script>
function getBinaryPromise(wasmBinary) {
return fetch(wasmBinary, {
credentials: "same-origin",
crossOrigin: "anonymous",
}).then(function(response) {
if (!response["ok"]) {
throw "failed to load wasm binary file at '" + wasmBinary + "'"
}
return response["arrayBuffer"]();
});
}
getBinaryPromise('./opencv.wasm').then((wasmBinary) => {
cv = cv({ wasmBinary });
});
</script>
```


## Usage

Because this module is using the same code as the official OpenCV.js for the web, you can use the same documentation at the web: https://docs.opencv.org/4.3.0/d5/d10/tutorial_js_root.html
Because this module is using the same code as the official OpenCV.js for the web, you can use the same documentation at the web: https://docs.opencv.org/4.5.5/d5/d10/tutorial_js_root.html

There are some minor initialization changes, because this module will be loaded synchronously instead of the OpenCV's default (asynchronously).

Expand All @@ -82,7 +104,7 @@ You can check the files inside [examples](https://github.com/echamudi/opencv-was
By default, mistakes in code will produce error code. You can use the following snippet to translate the error code into meaningful statement from OpenCV.

```js
const { cv, cvTranslateError } = require('opencv-wasm');
const { cv, cvTranslateError } = require('fast-opencv-wasm');

try {
// Your OpenCV code
Expand Down
19 changes: 10 additions & 9 deletions browser.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@

<script>
function getBinaryPromise(wasmBinary) {

return fetch(wasmBinary, {
credentials: "same-origin"
credentials: "same-origin",
crossOrigin: "anonymous",
}).then(function(response) {
if (!response["ok"]) {
throw "failed to load wasm binary file at '" + wasmBinary + "'"
}
return response["arrayBuffer"]()
})
if (!response["ok"]) {
throw "failed to load wasm binary file at '" + wasmBinary + "'"
}
return response["arrayBuffer"]();
});
}

getBinaryPromise('./opencv.wasm').then((wasmBinary) => {
console.log(cv({ wasmBinary }))
});
cv = cv({ wasmBinary });

console.log('cv', cv);
});
</script>

</body>
Expand Down
Loading

0 comments on commit 85e3302

Please sign in to comment.