mirror of
https://github.com/ColonelParrot/jscanify.git
synced 2025-12-31 06:31:54 +00:00
Compare commits
5 Commits
9749c97498
...
a8244709e6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8244709e6 | ||
|
|
3f4b902c48 | ||
|
|
1fa3133944 | ||
|
|
58b26c34c7 | ||
|
|
b4e68b12c9 |
3266
package-lock.json
generated
3266
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "jscanify",
|
"name": "jscanify",
|
||||||
"version": "1.3.3",
|
"version": "1.4.0",
|
||||||
"description": "Open-source Javascript mobile document scanner.",
|
"description": "Open-source Javascript mobile document scanner.",
|
||||||
"main": "src/jscanify-node.js",
|
"main": "src/jscanify-node.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
@ -25,8 +25,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://colonelparrot.github.io/jscanify/",
|
"homepage": "https://colonelparrot.github.io/jscanify/",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"canvas": "^2.11.2",
|
"canvas": "^3.1.0",
|
||||||
"jsdom": "^22.0.0",
|
"jsdom": "^26.0.0",
|
||||||
"mocha": "^10.2.0"
|
"mocha": "^11.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/*! jscanify v1.3.3 | (c) ColonelParrot and other contributors | MIT License */
|
/*! jscanify v1.4.0 | (c) ColonelParrot and other contributors | MIT License */
|
||||||
|
|
||||||
const { Canvas, createCanvas, Image, ImageData } = require("canvas");
|
const { Canvas, createCanvas, Image, ImageData } = require("canvas");
|
||||||
const { JSDOM } = require("jsdom");
|
const { JSDOM } = require("jsdom");
|
||||||
@ -153,9 +153,9 @@ class jscanify {
|
|||||||
extractPaper(image, resultWidth, resultHeight, cornerPoints) {
|
extractPaper(image, resultWidth, resultHeight, cornerPoints) {
|
||||||
const canvas = createCanvas();
|
const canvas = createCanvas();
|
||||||
const img = cv.imread(image);
|
const img = cv.imread(image);
|
||||||
const maxContour = this.findPaperContour(img);
|
const maxContour = cornerPoints ? null : this.findPaperContour(img);
|
||||||
|
|
||||||
if(maxContour == null){
|
if(maxContour == null && cornerPoints === undefined){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/*! jscanify v1.3.3 | (c) ColonelParrot and other contributors | MIT License */
|
/*! jscanify v1.4.0 | (c) ColonelParrot and other contributors | MIT License */
|
||||||
|
|
||||||
(function (global, factory) {
|
(function (global, factory) {
|
||||||
typeof exports === "object" && typeof module !== "undefined"
|
typeof exports === "object" && typeof module !== "undefined"
|
||||||
@ -144,9 +144,9 @@
|
|||||||
extractPaper(image, resultWidth, resultHeight, cornerPoints) {
|
extractPaper(image, resultWidth, resultHeight, cornerPoints) {
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
const img = cv.imread(image);
|
const img = cv.imread(image);
|
||||||
const maxContour = this.findPaperContour(img);
|
const maxContour = cornerPoints ? null : this.findPaperContour(img);
|
||||||
|
|
||||||
if(maxContour == null){
|
if(maxContour == null && cornerPoints === undefined){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,21 +39,30 @@ function setup() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("=== beginning tests ===");
|
let scanner;
|
||||||
console.log("loading OpenCV.js...");
|
let cv;
|
||||||
|
|
||||||
const scanner = new jscanify();
|
before(function (done) {
|
||||||
scanner.loadOpenCV(function (cv) {
|
console.log("=== beginning tests ===");
|
||||||
|
console.log("loading OpenCV.js...");
|
||||||
|
|
||||||
|
scanner = new jscanify();
|
||||||
|
scanner.loadOpenCV(function (loadedCv) {
|
||||||
|
cv = loadedCv;
|
||||||
|
|
||||||
console.log("Finished loading OpenCV.js");
|
console.log("Finished loading OpenCV.js");
|
||||||
console.log("Writing test images to: " + OUTPUT_FOLDER);
|
console.log("Writing test images to: " + OUTPUT_FOLDER);
|
||||||
|
setup()
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tests an individual image
|
* tests an individual image
|
||||||
*/
|
*/
|
||||||
function test(testImage, imageCount) {
|
function test(testImage, imageCount) {
|
||||||
describe("image #" + imageCount, function () {
|
describe("image #" + imageCount, function () {
|
||||||
it("should highlight paper", function (done) {
|
it("should highlight paper", function () {
|
||||||
const highlighted = scanner.highlightPaper(testImage);
|
const highlighted = scanner.highlightPaper(testImage);
|
||||||
const higlightedOutputPath = OUTPUT_FOLDER + "highlighted-" + imageCount + ".jpg";
|
const higlightedOutputPath = OUTPUT_FOLDER + "highlighted-" + imageCount + ".jpg";
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
@ -62,10 +71,9 @@ scanner.loadOpenCV(function (cv) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(existsSync(higlightedOutputPath));
|
assert.ok(existsSync(higlightedOutputPath));
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should extract paper", function (done) {
|
it("should extract paper", function () {
|
||||||
const extracted = scanner.extractPaper(testImage, 386, 500);
|
const extracted = scanner.extractPaper(testImage, 386, 500);
|
||||||
const extractedOutputPath = OUTPUT_FOLDER + "extracted-" + imageCount + ".jpg";
|
const extractedOutputPath = OUTPUT_FOLDER + "extracted-" + imageCount + ".jpg";
|
||||||
|
|
||||||
@ -75,10 +83,9 @@ scanner.loadOpenCV(function (cv) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(existsSync(extractedOutputPath));
|
assert.ok(existsSync(extractedOutputPath));
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should label corner points", function (done) {
|
it("should label corner points", function () {
|
||||||
const parsedImage = cv.imread(testImage);
|
const parsedImage = cv.imread(testImage);
|
||||||
const paperContour = scanner.findPaperContour(parsedImage);
|
const paperContour = scanner.findPaperContour(parsedImage);
|
||||||
const {
|
const {
|
||||||
@ -111,27 +118,23 @@ scanner.loadOpenCV(function (cv) {
|
|||||||
writeFileSync(cornerPointsOutputPath, canvas.toBuffer("image/jpeg"));
|
writeFileSync(cornerPointsOutputPath, canvas.toBuffer("image/jpeg"));
|
||||||
|
|
||||||
assert.ok(existsSync(cornerPointsOutputPath));
|
assert.ok(existsSync(cornerPointsOutputPath));
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setup();
|
let imageCount = 1;
|
||||||
|
|
||||||
let imageCount = 1;
|
/*
|
||||||
|
|
||||||
/*
|
|
||||||
* go through all images in test image directory
|
* go through all images in test image directory
|
||||||
*/
|
*/
|
||||||
readdirSync(TEST_IMAGE_DIRECTORY).forEach((file) => {
|
readdirSync(TEST_IMAGE_DIRECTORY).forEach((file) => {
|
||||||
const TEST_IMAGE_PATH = path.join(TEST_IMAGE_DIRECTORY, file);
|
const TEST_IMAGE_PATH = path.join(TEST_IMAGE_DIRECTORY, file);
|
||||||
|
|
||||||
if(!file.endsWith("-sized.png")){ // these images are for the website, not testing
|
if (!file.endsWith("-sized.png")) { // these images are for the website, not testing
|
||||||
let tempCount = imageCount++;
|
let tempCount = imageCount++;
|
||||||
|
|
||||||
loadImage(TEST_IMAGE_PATH).then(function (image) {
|
loadImage(TEST_IMAGE_PATH).then(function (image) {
|
||||||
test(image, tempCount);
|
test(image, tempCount);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
|
||||||
Loading…
x
Reference in New Issue
Block a user