Compare commits

..

5 Commits

Author SHA1 Message Date
ColonelParrot
a8244709e6
Update README.md 2025-02-18 11:55:35 -05:00
ColonelParrot
3f4b902c48 Bump to v1.4.0 2025-02-18 11:38:31 -05:00
ColonelParrot
1fa3133944 optimize extractPaper by saving compute when cornerPoints supplied 2025-02-18 11:36:46 -05:00
ColonelParrot
58b26c34c7 fix skipped tests with before() 2025-02-18 11:36:12 -05:00
ColonelParrot
b4e68b12c9 Update canvas, jsdom and mocha to resolve audit warnings 2025-02-02 00:09:54 -05:00
5 changed files with 1475 additions and 2014 deletions

3266
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "jscanify",
"version": "1.3.3",
"version": "1.4.0",
"description": "Open-source Javascript mobile document scanner.",
"main": "src/jscanify-node.js",
"directories": {
@ -25,8 +25,8 @@
},
"homepage": "https://colonelparrot.github.io/jscanify/",
"dependencies": {
"canvas": "^2.11.2",
"jsdom": "^22.0.0",
"mocha": "^10.2.0"
"canvas": "^3.1.0",
"jsdom": "^26.0.0",
"mocha": "^11.1.0"
}
}

View File

@ -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 { JSDOM } = require("jsdom");
@ -153,9 +153,9 @@ class jscanify {
extractPaper(image, resultWidth, resultHeight, cornerPoints) {
const canvas = createCanvas();
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;
}

View File

@ -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) {
typeof exports === "object" && typeof module !== "undefined"
@ -144,9 +144,9 @@
extractPaper(image, resultWidth, resultHeight, cornerPoints) {
const canvas = document.createElement("canvas");
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;
}

View File

@ -39,21 +39,30 @@ function setup() {
})
}
let scanner;
let cv;
before(function (done) {
console.log("=== beginning tests ===");
console.log("loading OpenCV.js...");
const scanner = new jscanify();
scanner.loadOpenCV(function (cv) {
scanner = new jscanify();
scanner.loadOpenCV(function (loadedCv) {
cv = loadedCv;
console.log("Finished loading OpenCV.js");
console.log("Writing test images to: " + OUTPUT_FOLDER);
setup()
done();
});
});
/**
* tests an individual image
*/
function test(testImage, imageCount) {
describe("image #" + imageCount, function () {
it("should highlight paper", function (done) {
it("should highlight paper", function () {
const highlighted = scanner.highlightPaper(testImage);
const higlightedOutputPath = OUTPUT_FOLDER + "highlighted-" + imageCount + ".jpg";
writeFileSync(
@ -62,10 +71,9 @@ scanner.loadOpenCV(function (cv) {
);
assert.ok(existsSync(higlightedOutputPath));
done();
});
it("should extract paper", function (done) {
it("should extract paper", function () {
const extracted = scanner.extractPaper(testImage, 386, 500);
const extractedOutputPath = OUTPUT_FOLDER + "extracted-" + imageCount + ".jpg";
@ -75,10 +83,9 @@ scanner.loadOpenCV(function (cv) {
);
assert.ok(existsSync(extractedOutputPath));
done();
});
it("should label corner points", function (done) {
it("should label corner points", function () {
const parsedImage = cv.imread(testImage);
const paperContour = scanner.findPaperContour(parsedImage);
const {
@ -111,13 +118,10 @@ scanner.loadOpenCV(function (cv) {
writeFileSync(cornerPointsOutputPath, canvas.toBuffer("image/jpeg"));
assert.ok(existsSync(cornerPointsOutputPath));
done();
});
});
}
setup();
let imageCount = 1;
/*
@ -134,4 +138,3 @@ scanner.loadOpenCV(function (cv) {
});
}
})
});