Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

split up into a detect module and example

  • Loading branch information...
commit 713368861e24a8963ff4eef9eb240b453495579c 1 parent 96141b8
@substack authored
Showing with 12 additions and 7 deletions.
  1. +5 −0 example/train.js
  2. +7 −7 { → lib}/detect.js
View
5 example/train.js
@@ -0,0 +1,5 @@
+var detect = require('../lib/detect');
+var fs = require('fs');
+var buf = fs.readFileSync(process.argv[2]);
+
+console.log(detect(1280, 720, buf));
View
14 detect.js → lib/detect.js
@@ -3,12 +3,12 @@ var Canvas = require('canvas');
var Image = Canvas.Image;
var rgb2hsl = require('color-convert').rgb2hsl;
-var canvas = new Canvas(1280 / 4, 720 / 4);
-var ctx = canvas.getContext('2d');
-
-fs.readFile(process.argv[2], function (err, src) {
+module.exports = function (w, h, buf) {
+ var canvas = new Canvas(w / 4, h / 4);
+ var ctx = canvas.getContext('2d');
+
var img = new Image();
- img.src = src;
+ img.src = buf;
ctx.drawImage(img, 0, 0, img.width / 4, img.height / 4);
var data = ctx.getImageData(0, 0, img.width / 4, img.height / 4).data;
@@ -22,5 +22,5 @@ fs.readFile(process.argv[2], function (err, src) {
matches ++;
}
}
- console.log(matches > 30);
-});
+ return matches > 30;
+};
Please sign in to comment.
Something went wrong with that request. Please try again.