jscanify
jscanify copied to clipboard
cv.approxPolyDP maxContour.
During testing, I encountered a case where the top-right of my page was incorrectly evaluated as being near the top-left, resulting in a near triangular poly from getCornerPoints(contour)
. What seems to have happened is that there was a point in the contour that was just right of the centre, yet had a bigger distance than the right-hand corner of the page (although the page was at an almost 45 degree angle in the frame, which would be unusual).
Recommend applying a cv.approxPolyDP to the maxContour
prior to getCornerPoints(contour)
to reduce occurrences.
return this.getApproxPoly(maxContour);
}
/** refines a contour to get approximate poly
* @param {*} contour contour to refine
*/
getApproxPoly(contour) {
const peri = cv.arcLength(contour, true);
const approx = new cv.Mat();
cv.arcLength(contour, true) * 0.02
cv.approxPolyDP(contour, approx, 0.1 * peri, true);
return approx;
}