mirror of
https://github.com/ColonelParrot/jscanify.git
synced 2025-12-30 22:31:52 +00:00
Add null check in extractPaper
This commit is contained in:
parent
e2af210cf2
commit
c8e6ab035d
@ -141,6 +141,9 @@ class jscanify {
|
||||
|
||||
/**
|
||||
* Extracts and undistorts the image detected within the frame.
|
||||
*
|
||||
* Returns `null` if no paper is detected.
|
||||
*
|
||||
* @param {*} image image to process
|
||||
* @param {*} resultWidth desired result paper width
|
||||
* @param {*} resultHeight desired result paper height
|
||||
@ -151,6 +154,11 @@ class jscanify {
|
||||
const canvas = createCanvas();
|
||||
const img = cv.imread(image);
|
||||
const maxContour = this.findPaperContour(img);
|
||||
|
||||
if(maxContour == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
const {
|
||||
topLeftCorner,
|
||||
topRightCorner,
|
||||
|
||||
@ -132,7 +132,10 @@
|
||||
|
||||
/**
|
||||
* Extracts and undistorts the image detected within the frame.
|
||||
* @param {*} image image to process
|
||||
*
|
||||
* Returns `null` if no paper is detected.
|
||||
*
|
||||
* @param {*} image image to process
|
||||
* @param {*} resultWidth desired result paper width
|
||||
* @param {*} resultHeight desired result paper height
|
||||
* @param {*} cornerPoints optional custom corner points, in case automatic corner points are incorrect
|
||||
@ -140,11 +143,13 @@
|
||||
*/
|
||||
extractPaper(image, resultWidth, resultHeight, cornerPoints) {
|
||||
const canvas = document.createElement("canvas");
|
||||
|
||||
const img = cv.imread(image);
|
||||
|
||||
const maxContour = this.findPaperContour(img);
|
||||
|
||||
if(maxContour == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
const {
|
||||
topLeftCorner,
|
||||
topRightCorner,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user