/** * Copyright (c) Microblink Ltd. All rights reserved. */ import { PreferredCameraType, SelectedCamera } from "./CameraUtils"; import { RecognizerRunner, RecognizerResultState } from "./DataStructures"; /** * Explanation why VideoRecognizer has failed to open the camera feed. */ export declare enum NotSupportedReason { /** navigator.mediaDevices.getUserMedia is not supported by current browser for current context. */ MediaDevicesNotSupported = "MediaDevicesNotSupported", /** Camera with requested features is not available on current device. */ CameraNotFound = "CameraNotFound", /** Camera access was not granted by the user. */ CameraNotAllowed = "CameraNotAllowed", /** Unable to start playing because camera is already in use. */ CameraInUse = "CameraInUse", /** Camera is currently not available due to a OS or hardware error. */ CameraNotAvailable = "CameraNotAvailable", /** There is no provided video element to which the camera feed should be redirected. */ VideoElementNotProvided = "VideoElementNotProvided" } /** * Indicates mode of recognition in VideoRecognizer. */ export declare enum VideoRecognitionMode { /** Normal recognition */ Recognition = 0, /** Indefinite scan. Useful for profiling the performance of scan (using onDebugText metadata callback) */ RecognitionTest = 1, /** Only detection. Useful for profiling the performance of detection (using onDebugText metadata callback) */ DetectionTest = 2 } /** * Invoked when VideoRecognizer finishes the recognition of the video stream. * @param recognitionState The state of recognition after finishing. If RecognizerResultState.Empty or * RecognizerResultState.Empty are returned, this indicates that the scanning * was cancelled or timeout has been reached. */ export declare type OnScanningDone = (recognitionState: RecognizerResultState) => Promise | void; /** * A wrapper around RecognizerRunner that can use it to perform recognition of video feeds - either from live camera or * from predefined video file. */ export declare class VideoRecognizer { /** * Creates a new VideoRecognizer by opening a camera stream and attaching it to given HTMLVideoElement. If camera * cannot be accessed, the returned promise will be rejected. * * @param cameraFeed HTMLVideoELement to which camera stream should be attached * @param recognizerRunner RecognizerRunner that should be used for video stream recognition * @param cameraId User can provide specific camera ID to be selected and used * @param preferredCameraType Whether back facing or front facing camera is preferred. Obeyed only if there is * a choice (i.e. if device has only front-facing camera, the opened camera will be a front-facing camera, * regardless of preference) */ static createVideoRecognizerFromCameraStream(cameraFeed: HTMLVideoElement, recognizerRunner: RecognizerRunner, cameraId?: string | null, preferredCameraType?: PreferredCameraType): Promise; /** * Creates a new VideoRecognizer by attaching the given URL to video to given HTMLVideoElement and using it to * display video frames while processing them. * * @param videoPath URL of the video file that should be recognized. * @param videoFeed HTMLVideoElement to which video file will be attached * @param recognizerRunner RecognizerRunner that should be used for video stream recognition. */ static createVideoRecognizerFromVideoPath(videoPath: string, videoFeed: HTMLVideoElement, recognizerRunner: RecognizerRunner): Promise; /** * **Use only if provided factory functions are not well-suited for your use case.** * * Creates a new VideoRecognizer with provided HTMLVideoElement. * * Keep in mind that HTMLVideoElement **must have** a video feed which is ready to use. * * - If you want to take advantage of provided camera management, use `createVideoRecognizerFromCameraStream` * - In case that static video file should be processed, use `createVideoRecognizerFromVideoPath` * * @param videoFeed HTMLVideoElement with video feed which is going to be processed * @param recognizerRunner RecognizerRunner that should be used for video stream recognition * @param cameraFlipped Whether the camera is flipped, e.g. if front-facing camera is used * @param allowManualVideoPlayout Whether to allow manual video playout. Default value is `false` */ constructor(videoFeed: HTMLVideoElement, recognizerRunner: RecognizerRunner, cameraFlipped?: boolean, allowManualVideoPlayout?: boolean, deviceId?: string | null); deviceId: string | null; flipCamera(): Promise; isCameraFlipped(): boolean; /** * Sets the video recognition mode to be used. * * @param videoRecognitionMode the video recognition mode to be used. */ setVideoRecognitionMode(videoRecognitionMode: VideoRecognitionMode): Promise; /** * Starts the recognition of the video stream associated with this VideoRecognizer. The stream will be unpaused and * recognition loop will start. After recognition completes, a onScanningDone callback will be invoked with state of * the recognition. * * NOTE: As soon as the execution of the callback completes, the recognition loop will continue and recognition * state will be retained. To clear the recognition state, use resetRecognizers (within your callback). To * pause the recognition loop, use pauseRecognition (within your callback) - to resume it later use * resumeRecognition. To completely stop the recognition and video feed, while keeping the ability to use this * VideoRecognizer later, use pauseVideoFeed. To completely stop the recognition and video feed and release * all the resources involved with video stream, use releaseVideoFeed. * * @param onScanningDone Callback that will be invoked when recognition completes. * @param recognitionTimeoutMs Amount of time before returned promise will be resolved regardless of whether * recognition was successful or not. */ startRecognition(onScanningDone: OnScanningDone, recognitionTimeoutMs?: number): Promise; /** * Performs the recognition of the video stream associated with this VideoRecognizer. The stream will be * unpaused, recognition will be performed and promise will be resolved with recognition status. After * the resolution of returned promise, the video stream will be paused, but not released. To release the * stream, use function releaseVideoFeed. * * This is a simple version of startRecognition that should be used for most cases, like when you only need * to perform one scan per video session. * * @param recognitionTimeoutMs Amount of time before returned promise will be resolved regardless of whether * recognition was successful or not. */ recognize(recognitionTimeoutMs?: number): Promise; /** * Cancels current ongoing recognition. Note that after cancelling the recognition, the callback given to * startRecognition will be immediately called. This also means that the promise returned from method * recognize will be resolved immediately. */ cancelRecognition(): void; /** * Pauses the video feed. You can resume the feed by calling recognize or startRecognition. * Note that this pauses both the camera feed and recognition. If you just want to pause * recognition, while keeping the camera feed active, call method pauseRecognition. */ pauseVideoFeed(): void; /** * Pauses the recognition. This means that video frames that arrive from given video source * will not be recognized. To resume recognition, call resumeRecognition(boolean). * Unlike cancelRecognition, the callback given to startRecognition will not be invoked after pausing * the recognition (unless there is already processing in-flight that may call the callback just before * pausing the actual recognition loop). */ pauseRecognition(): void; /** * Convenience method for invoking resetRecognizers on associated RecognizerRunner. * @param hardReset Same as in RecognizerRunner.resetRecognizers. */ resetRecognizers(hardReset: boolean): Promise; /** * Convenience method for accessing RecognizerRunner associated with this VideoRecognizer. * Sometimes it's useful to reconfigure RecognizerRunner while handling onScanningDone callback * and this method makes that much more convenient. */ getRecognizerRunner(): RecognizerRunner; /** * Resumes the recognition. The video feed must not be paused. If it is, an error will be thrown. * If video feed is paused, you should use recognize or startRecognition methods. * @param resetRecognizers Indicates whether resetRecognizers should be invoked while resuming the recognition */ resumeRecognition(resetRecognizers: boolean): Promise; /** * Stops all media stream tracks associated with current HTMLVideoElement and removes any references to it. * Note that after calling this method you can no longer use this VideoRecognizer for recognition. * This method should be called after you no longer plan on performing video recognition to let browser know * that it can release resources related to any media streams used. */ releaseVideoFeed(): void; /** * Change currently used camera device for recognition. To get list of available camera devices * use "getCameraDevices" method. * * Keep in mind that this method will reset recognizers. * * @param camera Desired camera device which should be used for recognition. */ changeCameraDevice(camera: SelectedCamera): Promise; /** ********************************************************************************************* * PRIVATE AREA */ private videoFeed; private recognizerRunner; private cancelled; private timedOut; private recognitionPaused; private recognitionTimeoutMs; private timeoutID; private videoRecognitionMode; private onScanningDone; private allowManualVideoPlayout; private cameraFlipped; private shouldReleaseVideoFeed; private isProblematicFocus; private playPauseEvent; private recognitionLoop; private clearTimeout; }