Skip to content

Commit

Permalink
Added command line sample with sharp
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed Nov 6, 2023
1 parent 37824ea commit 347aa1e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/command-line/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "command-line",
"version": "1.0.0",
"description": "",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"sharp": "^0.32.6"
}
}
32 changes: 32 additions & 0 deletions examples/command-line/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const sharp = require('sharp');
var DocRectifier = require('../../index.js');

const path = require('path');
console.log(DocRectifier.getVersionNumber());
DocRectifier.initLicense('DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==');

var obj = new DocRectifier();
obj.setParameters(DocRectifier.Template.binary);

sharp('../../images/document.png')
.raw() // This ensures the image data is returned as raw pixel data
.toBuffer((err, data, info) => {
if (err) throw err;

const width = info.width;
const height = info.height;
const stride = info.size / info.height;

(async function () {
try {

let results = await obj.detectBufferAsync(data, width, height, stride);
console.log(results);
let result = results[0];
result = await obj.normalizeBufferAsync(data, width, height, stride, result['x1'], result['y1'], result['x2'], result['y2'], result['x3'], result['y3'], result['x4'], result['y4']);
obj.save('test.png');
} catch (error) {
console.log(error);
}
})();
});

0 comments on commit 347aa1e

Please sign in to comment.