diff --git a/src/jscanify-node.js b/src/jscanify-node.js index 6779fb1..cd3376c 100644 --- a/src/jscanify-node.js +++ b/src/jscanify-node.js @@ -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, diff --git a/src/jscanify.js b/src/jscanify.js index bd3a16c..bd49461 100644 --- a/src/jscanify.js +++ b/src/jscanify.js @@ -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,