All Projects â†’ reg-viz â†’ x-img-diff-js

reg-viz / x-img-diff-js

Licence: MIT License
🎨 JavaScript library which compares 2 images and detect structural difference information using OpenCV(WebAssembly)

Programming Languages

C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to x-img-diff-js

rustwasmc
Tool for building Rust functions for Node.js. Combine the performance of Rust, safety and portability of WebAssembly, and ease of use of JavaScript.
Stars: ✭ 97 (+125.58%)
Mutual labels:  webassembly, wasm
wapc-rust
Rust-based WebAssembly Host Runtime for waPC-compliant modules
Stars: ✭ 75 (+74.42%)
Mutual labels:  webassembly, wasm
warpy
WebAssembly interpreter in RPython
Stars: ✭ 54 (+25.58%)
Mutual labels:  webassembly, wasm
node-wasi
WASI for Node.js
Stars: ✭ 64 (+48.84%)
Mutual labels:  webassembly, wasm
golang-wasm
Golang-WASM provides a simple idiomatic, and comprehensive API and bindings for working with WebAssembly for Go and JavaScript developers
Stars: ✭ 57 (+32.56%)
Mutual labels:  webassembly, wasm
cabasa
Haxe Framework for WebAssembly
Stars: ✭ 30 (-30.23%)
Mutual labels:  webassembly, wasm
wasm-fizzbuzz
WebAssembly from Scratch: From FizzBuzz to DooM.
Stars: ✭ 1,364 (+3072.09%)
Mutual labels:  webassembly, wasm
TypeScriptXX
🧷 Stay safe! Type-safe scripting for C++ using TypeScriptToLua and CMake with auto-generated declarations.
Stars: ✭ 33 (-23.26%)
Mutual labels:  webassembly, wasm
pywasm3
Python bindings for Wasm3, the fastest WebAssembly interpreter
Stars: ✭ 34 (-20.93%)
Mutual labels:  webassembly, wasm
holyc
An easy to use C++ to WASM compiler (Highly-experimental)
Stars: ✭ 33 (-23.26%)
Mutual labels:  webassembly, wasm
image-hub
Image Hub is a sample application for exploring WebAssembly modules used as Envoy filters.
Stars: ✭ 56 (+30.23%)
Mutual labels:  webassembly, wasm
learn-wasm
🎲 Learning WebAssembly
Stars: ✭ 57 (+32.56%)
Mutual labels:  webassembly, wasm
koder
QR/bar code scanner for the Browser
Stars: ✭ 73 (+69.77%)
Mutual labels:  webassembly, wasm
block-aligner
SIMD-accelerated library for computing global and X-drop affine gap penalty sequence-to-sequence or sequence-to-profile alignments using an adaptive block-based algorithm.
Stars: ✭ 58 (+34.88%)
Mutual labels:  webassembly, wasm
gearoenix
Cross-platform C++ 3D game engine.
Stars: ✭ 33 (-23.26%)
Mutual labels:  webassembly, wasm
go-wasm-examples
Some small examples of using Go and WebAssembly
Stars: ✭ 22 (-48.84%)
Mutual labels:  webassembly, wasm
imgalign
Webapplication for image stitching and aligning
Stars: ✭ 162 (+276.74%)
Mutual labels:  webassembly, wasm
vmrp
mrp emulator, virtual machine, mrp模拟器
Stars: ✭ 126 (+193.02%)
Mutual labels:  webassembly, wasm
rustexp
A Rust regular expression editor and tester that runs entirely within the browser!
Stars: ✭ 59 (+37.21%)
Mutual labels:  webassembly, wasm
idris-codegen-wasm
WebAssembly Code Generation Backend for Idris Compiler
Stars: ✭ 79 (+83.72%)
Mutual labels:  webassembly, wasm

x-img-diff-js

CircleCI npm version

JavaScript(Web Assembly) porting project for Quramy/x-img-diff, which extracts structual information of a bit different 2 images.

Demonstration

See https://reg-viz.github.io/x-img-diff-js/

Usage

Node.js

You need Node.js >= v8.0.0

npm install x-img-diff-js pngjs
const fs = require('fs');
const PNG = require('pngjs').PNG;

const detectDiff = require('x-img-diff-js');

function decodePng(filename) {
  return new Promise((resolve, reject) => {
    fs.readFile(filename, (err, buffer) => {
      if (err) return reject(err);
      resolve(PNG.sync.read(buffer));
    });
  });
}

async function main() {
  const [img1, img2] = await Promise.all([
    decodePng('demo/img/actual.png')),
    decodePng('demo/img/expected.png')),
  ]);
  const diffResult = await detectDiff(img1, img2);
  console.log("diff result:", diffResult);
  console.log("the number of matching area:", diffResult.matches.length);
  console.log("img1's macthing area bounding rect:", diffResult.matches[0][0].bounding);
  console.log("img2's matching area bounding rect:", diffResult.matches[0][1].bounding);
  console.log("diff marker rectangulars in img1's matching area", diffResult.matches[0][0].diffMarkers.length);
}

main();

Browser

See demo directory in this repository.

API

function detectDiff

detectDiff(img1: Image, img2: Image, opt?: DetectDiffOptions): Promise<DetectDiffResult>
  • img1, img2 - Required - Input images.
  • opt - Optional - An object to configure detection.

type Image

type Image = {
  width: number;
  height: number;
  data: Uint8Array;
}

type DetectDiffOptions

A option object. See https://github.com/Quramy/x-img-diff#usage .

type DetectDiffResult

type DetectDiffResult = {
  matces: MatchingRegions[];
  strayingRects: Rect[][];
}
  • matces - An array of each matching region.
  • strayingRects - An array of keypoints recatangle. strayingRects[0] corresponds to img1, strayingRects[1] does to img2.

type MatchingRegions

type MatchingRegions = {
  bounding: Rect;
  center: Rect;
  diffMarkers: Rect[];
}[];
  • bounding - Bounding rectangle of this region.
  • center - Center rectangle of this region.
  • diffMarkers - An array of different parts.

A MatchingRegions is a couple of objects. The 1st corresponds to img1, and 2nd does to img2. And you can get how far the region moved using center property.

// m is an item of DetectDiffResult#mathes
const translationVector = {
  x: m[1].center.x - m[0].center.x,
  y: m[1].center.y - m[0].center.y,
};

type Rect

type Rect = {
  x: number;
  y: number;
  width: number;
  height: number;
}

Represents a rectangle.

function detectDiff.getBrowserJsPath

detectDiff.getBrowserJsPath(): string 

Returns the absolute path of the JavaScript file which should be loaded in Browser env.

function detectDiff.getBrowserWasmPath

detectDiff.getBrowserWasmPath(): string 

Returns the absolute path of the Web Assembly(.wasm) file which should be loaded in Browser env.

How to build module

  1. Clone this repo and change the current directory to it.

  2. Get OpenCV source code

git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 3.1.0
cd ..
  1. Get x-img-diff source code
git clone https://github.com/quramy/x-img-diff.git
  1. Execute docker
$ docker-compose build
$ docker-compose run emcc

Run module in your local machine

python -mhttp.server
open http://localhost:8000/index.html

License

MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].