Coder Social home page Coder Social logo

bennettchina / opencv-contrib-wasm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hpmason/opencv-contrib-wasm

0.0 0.0 0.0 5.92 MB

Precompiled OpenCV 4.5.3 w/ Contrib modules to JavaScript + WebAssembly for node and deno. ๐Ÿฆ•

Home Page: https://deno.land/x/opencv_contrib

License: BSD 3-Clause "New" or "Revised" License

Shell 11.89% JavaScript 71.72% TypeScript 16.39%

opencv-contrib-wasm's Introduction

OpenCV-Contrib-Wasm

(This is a fork of OpenCV-Wasm with the added opencv_contrib modules) Unless you are using a module like aruco, you will want to the original repo this was forked from.

Test

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).

This module has zero dependencies.

Examples

Code Input Output
dilation.js (node) dilation.ts (deno) image sample 1 dilation
templateMatching.js (node) templateMatching.ts (deno) source:
image sample 2
template:
image sample 2 template
template matching

Installation

node

npm install @hpmason/opencv-contrib-wasm

Code example:

const { cv, cvTranslateError } = require('@hpmason/opencv-contrib-wasm');

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 ]
*/

deno

import { cv, cvTranslateError } from 'https://deno.land/x/[email protected]/mod.ts';
// Change the @<version> with the latest or any version you desire.
// Check the available versions here: https://deno.land/x/opencv_contrib.

Code example:

import { cv, cvTranslateError } from 'https://deno.land/x/[email protected]/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 ]
*/

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.5.3/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).

You can check the files inside examples folder as reference on how to initialize, loading images, and saving images.

Error Handling

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.

const { cv, cvTranslateError } = require('@hpmason/opencv-contrib-wasm');

try {
    // Your OpenCV code
} catch (err) {
    console.log(cvTranslateError(cv, err));
}

Versioning

This npm module uses the following versioning number:

<opencv version>-<this module version>

For Example

4.5.3-0
OpenCV version 4.5.3
OpenCV-Contrib-Wasm Module version 0

Development

Building

Run the following script on macOS or Linux (tested on Ubuntu). You need docker on the system.

npm install
(cd ./utils && sh ./build.sh)
(cd utils && node generateCvProps.js)

Testing

After completing the build script, you can run the test provided by OpenCV, and the test from this repo.

# OpenCV's test
(cd ./build_wasm_test/bin && npm install)
(cd ./build_wasm_test/bin && node tests.js)

# This repo's test
npm test

Authors

  • Ezzat Chamudi (Original work and repo) - echamudi
  • Mason Ginter (This fork) - hpmason

See also the list of contributors who participated in this project.

License

Copyright ยฉ 2020 Ezzat Chamudi, Mason Ginter, and OpenCV-Wasm Project Authors

OpenCV-Contrib-Wasm code is licensed under BSD-3-Clause. Images, logos, docs, and articles in this project are released under CC-BY-SA-4.0.

OpenCV License.

Libraries, dependencies, and tools used in this project are tied with their licenses.

opencv-contrib-wasm's People

Contributors

echamudi avatar hpmason avatar rwv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.