mirror of
https://github.com/ColonelParrot/jscanify.git
synced 2025-12-31 06:31:54 +00:00
Fix incorrect getCornerPoints return. Remove flip
This commit is contained in:
parent
c1ed3c8339
commit
9fe661d4e8
@ -187,11 +187,6 @@ class jscanify {
|
|||||||
);
|
);
|
||||||
|
|
||||||
cv.imshow(canvas, warpedDst);
|
cv.imshow(canvas, warpedDst);
|
||||||
const canvasContext = canvas.getContext("2d");
|
|
||||||
canvasContext.save();
|
|
||||||
canvasContext.scale(1, -1);
|
|
||||||
canvasContext.drawImage(canvas, 0, -resultHeight);
|
|
||||||
canvasContext.restore();
|
|
||||||
|
|
||||||
img.delete();
|
img.delete();
|
||||||
warpedDst.delete();
|
warpedDst.delete();
|
||||||
@ -222,25 +217,25 @@ class jscanify {
|
|||||||
for (let i = 0; i < contour.data32S.length; i += 2) {
|
for (let i = 0; i < contour.data32S.length; i += 2) {
|
||||||
const point = { x: contour.data32S[i], y: contour.data32S[i + 1] };
|
const point = { x: contour.data32S[i], y: contour.data32S[i + 1] };
|
||||||
const dist = distance(point, center);
|
const dist = distance(point, center);
|
||||||
if (point.x < center.x && point.y > center.y) {
|
if (point.x < center.x && point.y < center.y) {
|
||||||
// top left
|
// top left
|
||||||
if (dist > topLeftCornerDist) {
|
if (dist > topLeftCornerDist) {
|
||||||
topLeftCorner = point;
|
topLeftCorner = point;
|
||||||
topLeftCornerDist = dist;
|
topLeftCornerDist = dist;
|
||||||
}
|
}
|
||||||
} else if (point.x > center.x && point.y > center.y) {
|
} else if (point.x > center.x && point.y < center.y) {
|
||||||
// top right
|
// top right
|
||||||
if (dist > topRightCornerDist) {
|
if (dist > topRightCornerDist) {
|
||||||
topRightCorner = point;
|
topRightCorner = point;
|
||||||
topRightCornerDist = dist;
|
topRightCornerDist = dist;
|
||||||
}
|
}
|
||||||
} else if (point.x < center.x && point.y < center.y) {
|
} else if (point.x < center.x && point.y > center.y) {
|
||||||
// bottom left
|
// bottom left
|
||||||
if (dist > bottomLeftCornerDist) {
|
if (dist > bottomLeftCornerDist) {
|
||||||
bottomLeftCorner = point;
|
bottomLeftCorner = point;
|
||||||
bottomLeftCornerDist = dist;
|
bottomLeftCornerDist = dist;
|
||||||
}
|
}
|
||||||
} else if (point.x > center.x && point.y < center.y) {
|
} else if (point.x > center.x && point.y > center.y) {
|
||||||
// bottom right
|
// bottom right
|
||||||
if (dist > bottomRightCornerDist) {
|
if (dist > bottomRightCornerDist) {
|
||||||
bottomRightCorner = point;
|
bottomRightCorner = point;
|
||||||
|
|||||||
@ -184,11 +184,6 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
cv.imshow(canvas, warpedDst);
|
cv.imshow(canvas, warpedDst);
|
||||||
const canvasContext = canvas.getContext("2d");
|
|
||||||
canvasContext.save()
|
|
||||||
canvasContext.scale(1, -1)
|
|
||||||
canvasContext.drawImage(canvas, 0, -resultHeight)
|
|
||||||
canvasContext.restore()
|
|
||||||
|
|
||||||
img.delete()
|
img.delete()
|
||||||
warpedDst.delete()
|
warpedDst.delete()
|
||||||
@ -219,25 +214,25 @@
|
|||||||
for (let i = 0; i < contour.data32S.length; i += 2) {
|
for (let i = 0; i < contour.data32S.length; i += 2) {
|
||||||
const point = { x: contour.data32S[i], y: contour.data32S[i + 1] };
|
const point = { x: contour.data32S[i], y: contour.data32S[i + 1] };
|
||||||
const dist = distance(point, center);
|
const dist = distance(point, center);
|
||||||
if (point.x < center.x && point.y > center.y) {
|
if (point.x < center.x && point.y < center.y) {
|
||||||
// top left
|
// top left
|
||||||
if (dist > topLeftCornerDist) {
|
if (dist > topLeftCornerDist) {
|
||||||
topLeftCorner = point;
|
topLeftCorner = point;
|
||||||
topLeftCornerDist = dist;
|
topLeftCornerDist = dist;
|
||||||
}
|
}
|
||||||
} else if (point.x > center.x && point.y > center.y) {
|
} else if (point.x > center.x && point.y < center.y) {
|
||||||
// top right
|
// top right
|
||||||
if (dist > topRightCornerDist) {
|
if (dist > topRightCornerDist) {
|
||||||
topRightCorner = point;
|
topRightCorner = point;
|
||||||
topRightCornerDist = dist;
|
topRightCornerDist = dist;
|
||||||
}
|
}
|
||||||
} else if (point.x < center.x && point.y < center.y) {
|
} else if (point.x < center.x && point.y > center.y) {
|
||||||
// bottom left
|
// bottom left
|
||||||
if (dist > bottomLeftCornerDist) {
|
if (dist > bottomLeftCornerDist) {
|
||||||
bottomLeftCorner = point;
|
bottomLeftCorner = point;
|
||||||
bottomLeftCornerDist = dist;
|
bottomLeftCornerDist = dist;
|
||||||
}
|
}
|
||||||
} else if (point.x > center.x && point.y < center.y) {
|
} else if (point.x > center.x && point.y > center.y) {
|
||||||
// bottom right
|
// bottom right
|
||||||
if (dist > bottomRightCornerDist) {
|
if (dist > bottomRightCornerDist) {
|
||||||
bottomRightCorner = point;
|
bottomRightCorner = point;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user