Skip to content
ColonelParrot edited this page Feb 15, 2025 · 3 revisions

These are the methods offered by the jscanify API.

This reference gives you a better understanding of the library's capabilities.

Tip

any parameter of type jscanifyImage is a value that cv.imread can process. This includes the HTMLImageElement, HTMLCanvasElement and File.

Core Methods

findPaperContour

Method signature:

findPaperContour(mat: cv.Mat): cv.Mat

This method finds the contour of the paper within the image matrix.

Returns an image matrix containing the contour, to be passed to getCornerPoints.

highlightPaper

Method signature:

highlightPaper(image: jscanifyImage, options: object): HTMLCanvasElement

This method detects the paper in the image and returns a canvas with the image highlighted.

The options allow the color and thickness of the highlight to be customized:

{
    "color": "#FFFFFF",
    "thickness": 15
}

extractPaper

Method signature:

extractPaper(image: jscanifyImage, resultWidth: width, resultHeight: width, cornerPoints?: object): HTMLCanvasElement | null

This method extracts the paper in the image with dimensions resultWidth x resultHeight and returns a canvas of it.

Optionally, you can provide custom corner points. If custom points are supplied, the detection is skipped, saving compute, and only the perspective correction is applied.

getCornerPoints

Method signature:

getCornerPoints(contour: cv.Mat): object

Calculates the corner points of a contour, returning a result in the following format:

{
    topLeftCorner: { x: ..., y: ... },
    topRightCorner: { x: ..., y: ... },
    bottomLeftCorner: { x: ..., y: ... },
    bottomRightCorner: { x: ..., y: ... },
}

Clone this wiki locally