phonezawphyo / monkey-opencv

Provides method to search subimage inside an image using opencv cv::matchTemplate and cv::minMaxLoc.
9 stars 4 forks source link

MonkeyOpencv

Provides methods built upon opencv.

The following modules are included.

MonkeyOpencv

readImage(imagePath, callback)

Wrapper for cv::imread.

findSubImage(options, callback)

Finds positions of template matches in the source image. Can supply multiple template images.

var MonkeyOpencv = require('monkey-opencv').MonkeyOpencv;
var Constants = require ('monkey-opencv').Constants;
var fs = require ('fs');

MonkeyOpencv.findSubImage({
  source: 'source.png',
  templates: ['template.png'],
  matchPercent: 70,
  maximumMatches: 1,
  downPyramids: 1,
  searchExpansion: 15,
  method: Constants.TM_CCORR_NORMED,
}, function(matches){
  console.log('Matches with callback: ',matches[0].position);
})

// Example with Matrix as a template
MonkeyOpencv.readImage('template.png', function(tmpl) {
  MonkeyOpencv.findSubImage({
    source: 'source.png',
    templates: [tmpl, 'invalid_template.png'],
  })
  .then(function(matches){
    console.log('Matches with Promise: ', matches[0].position);
  }, function(err){});
  });
});

// Example with Buffer as a template
var source = fs.readFileSync('template.png');
MonkeyOpencv.findSubImage({
  source: source,
  templates: ['template.png', 'invalid_template.png'],
})
.then(function(matches){
  console.log('Matches with Promise: ', matches[0].position);
}, function(err){});
});

Installation

npm install --save monkey-opencv

Requirements for building from source

node-gyp, node-pre-gyp

opencv

npm install node-gyp node-pre-gyp -g

Requirements for Mac

XCode

Requirements for windows

Install window build tools. Refer to https://github.com/nodejs/node-gyp.

npm install --global --production windows-build-tools

References

  1. https://github.com/Jmgr/actiona
  2. https://github.com/monai/node-imagesearch
  3. https://github.com/peterbraden/node-opencv