Skip to content

Commit

Permalink
4.10.0-14
Browse files Browse the repository at this point in the history
  • Loading branch information
CezaryDanielNowak committed Jun 20, 2024
1 parent 57ccc9f commit 415ad6e
Show file tree
Hide file tree
Showing 12 changed files with 2,673 additions and 12,508 deletions.
26 changes: 0 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,6 @@ Int8Array(6) [ 1, 4, 2, 5, 3, 6 ]
*/
```

### deno

```ts
import { cv, cvTranslateError } from 'https://deno.land/x/opencv@v4.3.0-10/mod.ts';
// Change the @<version> with the latest or any version you desire.
// Check the available versions here: https://deno.land/x/opencv.
```
Code example:
```ts
import { cv, cvTranslateError } from 'https://deno.land/x/opencv@v4.3.0-10/mod.ts';

let mat = cv.matFromArray(2, 3, cv.CV_8UC1, [1, 2, 3, 4, 5, 6]);
console.log('cols =', mat.cols, '; rows =', mat.rows);
console.log(mat.data8S);

cv.transpose(mat, mat);
console.log('cols =', mat.cols, '; rows =', mat.rows);
console.log(mat.data8S);

/*
cols = 3 ; rows = 2
Int8Array(6) [ 1, 2, 3, 4, 5, 6 ]
cols = 2 ; rows = 3
Int8Array(6) [ 1, 4, 2, 5, 3, 6 ]
*/
```

## Using in the browser
```
Expand Down
2 changes: 0 additions & 2 deletions opencv-bin.js

This file was deleted.

7,902 changes: 0 additions & 7,902 deletions opencv-deno.js

This file was deleted.

7,049 changes: 2,633 additions & 4,416 deletions opencv.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions opencv.min.js

Large diffs are not rendered by default.

Binary file modified opencv.wasm
Binary file not shown.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fast-opencv-wasm",
"version": "4.4.0-14",
"description": "Precompiled OpenCV 4.4.0 to JavaScript + WebAssembly for node.js environment",
"version": "4.10.0-14",
"description": "Precompiled OpenCV 4.10.0 to JavaScript + WebAssembly for node.js environment",
"main": "index.js",
"directories": {
"example": "examples"
Expand All @@ -15,10 +15,9 @@
"/index.d.ts",
"/mod.ts",
"/opencv.js",
"/opencv.min.js",
"/opencv.d.ts",
"/opencv.wasm",
"/opencv-deno.js",
"/opencv-bin.js",
"/types"
],
"repository": {
Expand All @@ -38,6 +37,7 @@
"jimp": "^0.10.2",
"js-beautify": "^1.13.4",
"mocha": "^7.1.2",
"pixelmatch": "^5.2.0"
"pixelmatch": "^5.2.0",
"uglify-js": "^3.18.0"
}
}
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ describe('cvTranslateError', function() {
it('translates error correctly', async function () {
const errString = await errorExample();
assert.deepStrictEqual(errString,
"Exception: OpenCV(4.4.0) /code/modules/imgproc/src/contours.cpp:197: error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl'\n");
"Exception: OpenCV(4.10.0) /code/modules/imgproc/src/contours.cpp:197: error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl'\n");
});
});
17 changes: 8 additions & 9 deletions utils/build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
git clone --branch 4.4.0 --depth 1 https://github.com/opencv/opencv.git
git clone --branch 4.10.0 --depth 1 https://github.com/opencv/opencv.git

# Build
(
cd opencv &&
git fetch --tags &&
git checkout 4.4.0 &&
git checkout 4.10.0 &&

# Add non async flag before compiling in the python build_js.py script
docker run --rm --workdir /code -v "$PWD":/code "trzeci/emscripten:sdk-tag-1.39.4-64bit" python ./platforms/js/build_js.py build_wasm --config ./opencv_js.config.py --build_wasm --build_test --build_flags "-s WASM=1 -s WASM_ASYNC_COMPILATION=0 -s SINGLE_FILE=0 -s USE_PTHREADS=0 "
docker run --rm --workdir /code -v "$PWD":/code -u $(id -u):$(id -g) emscripten/emsdk emcmake python3 ./platforms/js/build_js.py ./build_wasm --clean_build_dir --build_wasm --build_test --build_flags "-s WASM=1 -s WASM_ASYNC_COMPILATION=0 -s SINGLE_FILE=0 -s USE_PTHREADS=0 "
)

# Copy compilation result
Expand All @@ -16,18 +16,17 @@ cp -a ./opencv/build_wasm/ ./build_wasm
# Transpile opencv.js files
node opencvJsMod.js

# Beautify JS
# Beautify and Uglify JS
(
cd ./build_wasm/bin &&
npx js-beautify opencv.js -r &&
npx js-beautify opencv-deno.js -r
npx uglify-js opencv.js -o opencv.min.js --compress --mangle
npx js-beautify opencv.js -r
)

# Copy bins to root
(
cp ./build_wasm/bin/opencv.wasm ../opencv.wasm &&
cp ./build_wasm/bin/opencv-bin.js ../opencv-bin.js &&
cp ./build_wasm/bin/opencv_js.wasm ../opencv.wasm &&
cp ./build_wasm/bin/opencv.js ../opencv.js &&
cp ./build_wasm/bin/opencv-deno.js ../opencv-deno.js &&
cp ./build_wasm/bin/opencv.min.js ../opencv.min.js &&
cp -r ./build_wasm/ ../build_wasm_test
)
65 changes: 10 additions & 55 deletions utils/opencvJsMod.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,22 @@ const path = require('path');

const openCvJs = fs.readFileSync(path.join(__dirname, './build_wasm/bin/opencv.js'), 'utf-8');


// Generate opencv.wasm
const matchResult = openCvJs.match(/var wasmBinaryFile="(.*?)";/gs);

if (matchResult == null) {
throw new Error('WASM Base64 is not found');
}

const wasmBase64 = matchResult[0].replace('var wasmBinaryFile="data:application/octet-stream;base64,', '').replace('";', '');

fs.writeFileSync(path.join(__dirname, './build_wasm/bin/opencv.wasm'), wasmBase64, {encoding: 'base64'});
console.log('Generated OpenCV.wasm');


// Generate opencv-bin.js
const opencvBin = `
export const bin = 'data:application/octet-stream;base64,${wasmBase64}';
`;
fs.writeFileSync(path.join(__dirname, './build_wasm/bin/opencv-bin.js'), opencvBin, {encoding: 'utf8'});
console.log('Generated opencv-bin.js');


// Replace the data with opencvWasmBinaryFile variable
const openCvJsNew = openCvJs.replace(/var wasmBinaryFile="(.*?)";/, 'var wasmBinaryFile=opencvWasmBinaryFile;');


// Add modifications for node.js code
let openCvJsNode = openCvJsNew;
let openCvJsMod = openCvJs;

openCvJsNode =
openCvJsMod =
`(function() {
/* fast-opencv-wasm@${require('../package.json').version} */
let opencvWasmBinaryFile = './opencv.wasm';
return ${openCvJsNode};
return ${openCvJsMod};
})();`;

openCvJsNode = openCvJsNode.replace(/if \(typeof Module === 'undefined'\)(.*)return cv\(Module\)/gms, 'return cv');
openCvJsMod = openCvJsMod.replace(/if \(typeof Module === 'undefined'\)(.*)return cv\(Module\)/gms, 'return cv');

fs.writeFileSync(path.join(__dirname, './build_wasm/bin/opencv.js'), openCvJsNode, {encoding: 'utf8'});
fs.writeFileSync(
path.join(__dirname, './build_wasm/bin/opencv.js'),
openCvJsMod,
{ encoding: 'utf8' }
);
console.log('Updated opencv.js');


// Add modifications for deno code
let openCvJsDeno = openCvJsNew;
openCvJsDeno = openCvJsDeno.replace(/\}\(this, function \(\) \{/, '}($this, function () {');

openCvJsDeno = `
import { bin } from './opencv-bin.js';
let Module = {};
let TextDecoder = undefined;
let document = {};
let opencvWasmBinaryFile = bin;
let $this = {};
${openCvJsDeno}
const cv = $this.cv;
export { cv };
`;

fs.writeFileSync(path.join(__dirname, './build_wasm/bin/opencv-deno.js'), openCvJsDeno, {encoding: 'utf8'});
console.log('Added opencv-deno.js');
92 changes: 0 additions & 92 deletions utils/opencv_js.config.py

This file was deleted.

7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,7 @@ sprintf-js@~1.0.2:
integrity sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
name string-width-cjs
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -1856,6 +1857,7 @@ string.prototype.trimstart@^1.0.8:
es-object-atoms "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
name strip-ansi-cjs
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -1968,6 +1970,11 @@ typed-array-length@^1.0.6:
is-typed-array "^1.1.13"
possible-typed-array-names "^1.0.0"

uglify-js@^3.18.0:
version "3.18.0"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.18.0.tgz#73b576a7e8fda63d2831e293aeead73e0a270deb"
integrity sha512-SyVVbcNBCk0dzr9XL/R/ySrmYf0s372K6/hFklzgcp2lBFyXtw4I7BOdDjlLhE1aVqaI/SHWXWmYdlZxuyF38A==

unbox-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.2.tgz#29032021057d5e6cdbd08c5129c226dff8ed6f9e"
Expand Down

0 comments on commit 415ad6e

Please sign in to comment.