Improve recognition algorithm

This commit is contained in:
ColonelParrot 2025-01-27 16:00:22 -05:00
parent b6ba8178fc
commit 084b33ff76
2 changed files with 8 additions and 6 deletions

View File

@ -44,7 +44,7 @@ class jscanify {
*/
findPaperContour(img) {
const imgGray = new cv.Mat();
cv.cvtColor(img, imgGray, cv.COLOR_RGBA2GRAY);
cv.Canny(img, imgGray, 50, 200);
const imgBlur = new cv.Mat();
cv.GaussianBlur(
@ -69,6 +69,7 @@ class jscanify {
cv.RETR_CCOMP,
cv.CHAIN_APPROX_SIMPLE
);
let maxArea = 0;
let maxContourIndex = -1;
for (let i = 0; i < contours.size(); ++i) {

View File

@ -20,7 +20,7 @@
}
class jscanify {
constructor() {}
constructor() { }
/**
* Finds the contour of the paper within the image
@ -29,7 +29,7 @@
*/
findPaperContour(img) {
const imgGray = new cv.Mat();
cv.cvtColor(img, imgGray, cv.COLOR_RGBA2GRAY);
cv.Canny(img, imgGray, 50, 200);
const imgBlur = new cv.Mat();
cv.GaussianBlur(
@ -47,7 +47,7 @@
imgThresh,
0,
255,
cv.THRESH_BINARY + cv.THRESH_OTSU
cv.THRESH_OTSU
);
let contours = new cv.MatVector();
@ -60,6 +60,7 @@
cv.RETR_CCOMP,
cv.CHAIN_APPROX_SIMPLE
);
let maxArea = 0;
let maxContourIndex = -1;
for (let i = 0; i < contours.size(); ++i) {