Add null check in extractPaper

This commit is contained in:
ColonelParrot 2025-02-01 21:06:30 -05:00
parent e2af210cf2
commit c8e6ab035d
2 changed files with 16 additions and 3 deletions

View File

@ -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,

View File

@ -132,6 +132,9 @@
/**
* 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
@ -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,