import { Election } from '@votingworks/ballot-encoder'; import { BallotPageLayout, BallotPageMetadata, DetectQRCode, Interpreted } from './types'; export interface Options { readonly election: Election; readonly detectQRCode?: DetectQRCode; readonly markScoreVoteThreshold?: number; readonly testMode?: boolean; /** @deprecated */ decodeQRCode?: DetectQRCode; } export declare const DEFAULT_MARK_SCORE_VOTE_THRESHOLD = 0.12; /** * Interprets ballot images based on templates. A template is simply an empty * ballot and should be exactly what is given to a voter for them to mark. * * @example * * ```ts * const interpreter = new Interpreter(election) * await interpreter.addTemplate(templatePage1) * await interpreter.addTemplate(templatePage2) * console.log(await interpreter.interpretBallot(ballotPage1)) * ``` */ export default class Interpreter { private templates; private readonly election; private readonly testMode; private readonly detectQRCode?; private readonly markScoreVoteThreshold; constructor(election: Election); constructor(options: Options); /** * Adds a template so that this `Interpreter` will be able to scan ballots * printed from it. The template image should be an image of a blank ballot, * either scanned or otherwise rendered as an image. */ addTemplate(imageData: ImageData, metadata?: BallotPageMetadata, { flipped }?: { flipped?: boolean; }): Promise; addTemplate(template: BallotPageLayout): Promise; /** * Gets a template by ballot style, precinct, and page number if present. */ private getTemplate; /** * Sets a template by ballot style, precinct, and page number. */ private setTemplate; /** * Interprets an image as a template, returning the layout information read * from the image. The template image should be an image of a blank ballot, * either scanned or otherwise rendered as an image. */ interpretTemplate(imageData: ImageData, metadata?: BallotPageMetadata, { flipped }?: { flipped?: boolean | undefined; }): Promise; private findContests; /** * Determines whether enough of the template images have been added to allow * scanning a ballot with the given metadata. */ canScanBallot(metadata: BallotPageMetadata): boolean; /** * Interprets an image as a ballot, returning information about the votes cast. */ interpretBallot(imageData: ImageData, metadata?: BallotPageMetadata, { flipped, markScoreVoteThreshold, }?: { flipped?: boolean | undefined; markScoreVoteThreshold?: number | undefined; }): Promise; private findMarks; /** * Get the contests for the given template. */ private getContestsForTemplate; private interpretMarks; private normalizeImageDataAndMetadata; private getMarksForBallot; private targetMarkScore; private mapImageWithPoints; private mapBallotOntoTemplate; }