mirror of
https://github.com/ColonelParrot/jscanify.git
synced 2025-12-31 06:31:54 +00:00
Add base folder check, optimizations
This commit is contained in:
parent
2adb81c60f
commit
90cf5246c8
@ -1,8 +1,12 @@
|
|||||||
|
/*
|
||||||
|
run tests with: npm test
|
||||||
|
*/
|
||||||
|
|
||||||
console.log("RUNNING JSCANIFY TESTS");
|
console.log("RUNNING JSCANIFY TESTS");
|
||||||
console.log("Warning: This may take a bit");
|
console.log("Warning: This may take a bit");
|
||||||
|
|
||||||
const { Canvas, createCanvas, Image, ImageData, loadImage } = require("canvas");
|
const { loadImage } = require("canvas");
|
||||||
const { writeFileSync, unlinkSync, existsSync } = require("fs");
|
const { mkdirSync, writeFileSync, unlinkSync, existsSync } = require("fs");
|
||||||
const assert = require("assert");
|
const assert = require("assert");
|
||||||
|
|
||||||
const jscanify = require("../src/jscanify-node");
|
const jscanify = require("../src/jscanify-node");
|
||||||
@ -13,6 +17,8 @@ const outputPaths = {
|
|||||||
extracted: __dirname + "/output/extracted.jpg",
|
extracted: __dirname + "/output/extracted.jpg",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const baseFolder = __dirname.replaceAll("\\", "/") + "/output/";
|
||||||
|
|
||||||
const TEST_IMAGE_PATH = path.join(
|
const TEST_IMAGE_PATH = path.join(
|
||||||
__dirname,
|
__dirname,
|
||||||
"..",
|
"..",
|
||||||
@ -30,6 +36,10 @@ function setup() {
|
|||||||
unlinkSync(path);
|
unlinkSync(path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!existsSync(baseFolder)) {
|
||||||
|
mkdirSync(baseFolder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
@ -39,6 +49,7 @@ function test() {
|
|||||||
console.log("loading OpenCV.js...");
|
console.log("loading OpenCV.js...");
|
||||||
scanner.loadOpenCV(function (cv) {
|
scanner.loadOpenCV(function (cv) {
|
||||||
console.log("Finished loading OpenCV.js");
|
console.log("Finished loading OpenCV.js");
|
||||||
|
console.log("Writing test images to: " + baseFolder);
|
||||||
describe("feature tests", function (done) {
|
describe("feature tests", function (done) {
|
||||||
it("should highlight paper", function (done) {
|
it("should highlight paper", function (done) {
|
||||||
const highlighted = scanner.highlightPaper(testImage);
|
const highlighted = scanner.highlightPaper(testImage);
|
||||||
@ -48,7 +59,7 @@ function test() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(existsSync(outputPaths.highlight));
|
assert.ok(existsSync(outputPaths.highlight));
|
||||||
done()
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should extract paper", function (done) {
|
it("should extract paper", function (done) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user