jscanify 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/package.json +1 -1
- package/src/jscanify-node.js +13 -2
- package/src/jscanify.js +13 -5
package/README.md
CHANGED
|
@@ -22,7 +22,6 @@ Supports the web, NodeJS, <a href="https://github.com/ColonelParrot/react-scanif
|
|
|
22
22
|
Available on <a href="https://www.npmjs.com/package/jscanify">npm</a> or via <a href="https://www.jsdelivr.com/package/gh/ColonelParrot/jscanify">cdn</a><br/>
|
|
23
23
|
</p>
|
|
24
24
|
|
|
25
|
-
|
|
26
25
|
**Features**:
|
|
27
26
|
|
|
28
27
|
- paper detection & highlighting
|
|
@@ -39,6 +38,8 @@ Available on <a href="https://www.npmjs.com/package/jscanify">npm</a> or via <a
|
|
|
39
38
|
|
|
40
39
|
<img src="docs/images/github-explanation-long.png" />
|
|
41
40
|
|
|
41
|
+
<h3 align="center" margin="0"><a href="https://github.com/puffinsoft/jscanify/wiki">➡️ view documentation</a></h3>
|
|
42
|
+
|
|
42
43
|
<hr/>
|
|
43
44
|
|
|
44
45
|
## Quickstart
|
|
@@ -125,3 +126,5 @@ To export the paper to a PDF, see [here](https://stackoverflow.com/questions/236
|
|
|
125
126
|
|
|
126
127
|
- for optimal paper detection, the paper should be placed on a flat surface with a solid background color
|
|
127
128
|
- we recommend wrapping your code using `jscanify` in a window `load` event listener to ensure OpenCV is loaded
|
|
129
|
+
|
|
130
|
+
<h3 align="center" margin="0"><a href="https://github.com/puffinsoft/jscanify/wiki">➡️ view documentation</a></h3>
|
package/package.json
CHANGED
package/src/jscanify-node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! jscanify v1.3.
|
|
1
|
+
/*! jscanify v1.3.3 | (c) ColonelParrot and other contributors | MIT License */
|
|
2
2
|
|
|
3
3
|
const { Canvas, createCanvas, Image, ImageData } = require("canvas");
|
|
4
4
|
const { JSDOM } = require("jsdom");
|
|
@@ -80,7 +80,10 @@ class jscanify {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
const maxContour =
|
|
83
|
+
const maxContour =
|
|
84
|
+
maxContourIndex >= 0 ?
|
|
85
|
+
contours.get(maxContourIndex) :
|
|
86
|
+
null;
|
|
84
87
|
|
|
85
88
|
imgGray.delete();
|
|
86
89
|
imgBlur.delete();
|
|
@@ -138,6 +141,9 @@ class jscanify {
|
|
|
138
141
|
|
|
139
142
|
/**
|
|
140
143
|
* Extracts and undistorts the image detected within the frame.
|
|
144
|
+
*
|
|
145
|
+
* Returns `null` if no paper is detected.
|
|
146
|
+
*
|
|
141
147
|
* @param {*} image image to process
|
|
142
148
|
* @param {*} resultWidth desired result paper width
|
|
143
149
|
* @param {*} resultHeight desired result paper height
|
|
@@ -148,6 +154,11 @@ class jscanify {
|
|
|
148
154
|
const canvas = createCanvas();
|
|
149
155
|
const img = cv.imread(image);
|
|
150
156
|
const maxContour = this.findPaperContour(img);
|
|
157
|
+
|
|
158
|
+
if(maxContour == null){
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
151
162
|
const {
|
|
152
163
|
topLeftCorner,
|
|
153
164
|
topRightCorner,
|
package/src/jscanify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! jscanify v1.3.
|
|
1
|
+
/*! jscanify v1.3.3 | (c) ColonelParrot and other contributors | MIT License */
|
|
2
2
|
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === "object" && typeof module !== "undefined"
|
|
@@ -71,7 +71,10 @@
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const maxContour =
|
|
74
|
+
const maxContour =
|
|
75
|
+
maxContourIndex >= 0 ?
|
|
76
|
+
contours.get(maxContourIndex) :
|
|
77
|
+
null;
|
|
75
78
|
|
|
76
79
|
imgGray.delete();
|
|
77
80
|
imgBlur.delete();
|
|
@@ -129,7 +132,10 @@
|
|
|
129
132
|
|
|
130
133
|
/**
|
|
131
134
|
* Extracts and undistorts the image detected within the frame.
|
|
132
|
-
*
|
|
135
|
+
*
|
|
136
|
+
* Returns `null` if no paper is detected.
|
|
137
|
+
*
|
|
138
|
+
* @param {*} image image to process
|
|
133
139
|
* @param {*} resultWidth desired result paper width
|
|
134
140
|
* @param {*} resultHeight desired result paper height
|
|
135
141
|
* @param {*} cornerPoints optional custom corner points, in case automatic corner points are incorrect
|
|
@@ -137,11 +143,13 @@
|
|
|
137
143
|
*/
|
|
138
144
|
extractPaper(image, resultWidth, resultHeight, cornerPoints) {
|
|
139
145
|
const canvas = document.createElement("canvas");
|
|
140
|
-
|
|
141
146
|
const img = cv.imread(image);
|
|
142
|
-
|
|
143
147
|
const maxContour = this.findPaperContour(img);
|
|
144
148
|
|
|
149
|
+
if(maxContour == null){
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
145
153
|
const {
|
|
146
154
|
topLeftCorner,
|
|
147
155
|
topRightCorner,
|