Fix incorrect getCornerPoints return. Remove flip

This commit is contained in:
ColonelParrot 2023-05-10 10:45:10 -04:00
parent c1ed3c8339
commit 9fe661d4e8
2 changed files with 8 additions and 18 deletions

View File

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

View File

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