mirror of
https://github.com/ColonelParrot/jscanify.git
synced 2025-12-30 22:31:52 +00:00
Streamline node & web flip
This commit is contained in:
parent
90cf5246c8
commit
c1ed3c8339
@ -4,8 +4,8 @@
|
|||||||
typeof exports === "object" && typeof module !== "undefined"
|
typeof exports === "object" && typeof module !== "undefined"
|
||||||
? (module.exports = factory())
|
? (module.exports = factory())
|
||||||
: typeof define === "function" && define.amd
|
: typeof define === "function" && define.amd
|
||||||
? define(factory)
|
? define(factory)
|
||||||
: (global.jscanify = factory());
|
: (global.jscanify = factory());
|
||||||
})(this, function () {
|
})(this, function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
class jscanify {
|
class jscanify {
|
||||||
constructor() { }
|
constructor() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the contour of the paper within the image
|
* Finds the contour of the paper within the image
|
||||||
@ -184,26 +184,15 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
cv.imshow(canvas, warpedDst);
|
cv.imshow(canvas, warpedDst);
|
||||||
|
const canvasContext = canvas.getContext("2d");
|
||||||
|
canvasContext.save()
|
||||||
|
canvasContext.scale(1, -1)
|
||||||
|
canvasContext.drawImage(canvas, 0, -resultHeight)
|
||||||
|
canvasContext.restore()
|
||||||
|
|
||||||
const newImg = document.createElement("img");
|
img.delete()
|
||||||
newImg.src = canvas.toDataURL();
|
warpedDst.delete()
|
||||||
newImg.onload = function () {
|
onComplete(canvas)
|
||||||
// flip unwarped image
|
|
||||||
|
|
||||||
let ctx = canvas.getContext("2d");
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
||||||
canvas.width = resultWidth;
|
|
||||||
canvas.height = resultHeight;
|
|
||||||
ctx.setTransform(1, 0, 0, -1, 0, canvas.height);
|
|
||||||
|
|
||||||
ctx.drawImage(newImg, 0, 0);
|
|
||||||
|
|
||||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
||||||
|
|
||||||
img.delete();
|
|
||||||
warpedDst.delete();
|
|
||||||
onComplete(canvas);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -211,7 +200,7 @@
|
|||||||
* @param {*} contour contour from {@link findPaperContour}
|
* @param {*} contour contour from {@link findPaperContour}
|
||||||
* @returns object with properties `topLeftCorner`, `topRightCorner`, `bottomLeftCorner`, `bottomRightCorner`, each with `x` and `y` property
|
* @returns object with properties `topLeftCorner`, `topRightCorner`, `bottomLeftCorner`, `bottomRightCorner`, each with `x` and `y` property
|
||||||
*/
|
*/
|
||||||
getCornerPoints(contour) {
|
getCornerPoints(contour) {
|
||||||
let rect = cv.minAreaRect(contour);
|
let rect = cv.minAreaRect(contour);
|
||||||
const center = rect.center;
|
const center = rect.center;
|
||||||
|
|
||||||
@ -264,7 +253,6 @@
|
|||||||
bottomRightCorner,
|
bottomRightCorner,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return jscanify;
|
return jscanify;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user