The CaptureVisionRouter class defines how a user interacts with image-processing and semantic-processing products in their applications. A CaptureVisionRouter instance accepts and processes images from an image source and returns processing results which may contain Final results or Intermediate Results.

In js end of react-native, CaptureVisionRouter uses singleton mode. You can only get CaptureVisionRouter instance by CaptureVisionRouter.getInstance.

Methods

  • Adds a CapturedResultReceiver object as the receiver of captured results. It will return the receiver added itself, convenient to use removeResultReceiver method.

    Code Snippet:

    let router = await CaptureVisionRouter.getInstance();
    let receiver = router.addResultReceiver({
    onCapturedResultReceived: result => {
    // Do something with the result
    },
    });

    Parameters

    Returns CapturedResultReceiver

    return the receiver added in CapturedResultReceiver.

    CaptureVisionRouter.removeResultReceiver

  • Processes ImageData object to derive important information.

    Code Snippet:

    let cameraEnhancer = CameraEnhancer.getInstance();
    let router = CaptureVisionRouter.getInstance();
    let imageData = cameraEnhancer.getImage();
    let result = router.capture(imageData, "ReadSingleBarcode");
    for(let i = 0; i < result.items.length; i++) {
    //...
    }

    Parameters

    Returns undefined | null | CapturedResult

    A CapturedResult object which contains the derived information from the image processed. If an error occurs when processing the image, the CapturedResult object will include error code and error message that describes the reason of the error.

  • Processes a file containing a single image to derive important information.

    Code Snippet:

    let router = CaptureVisionRouter.getInstance();
    let result = router.capture("absolute-image-file-path", "ReadSingleBarcode");
    for(let i = 0; i < result.items.length; i++) {
    //...
    }

    Parameters

    • filePath: string

      The absolute file path and name that you want to capture data from. You have to specify the file name with extension name in the filePath. Supported file type includes “.bmp”, “.jpg”, “.png”, “.gif” or one-page “.tiff”.

    • template: string = ""

      Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:

    Returns undefined | null | CapturedResult

    A CapturedResult object which contains the derived information from the image processed. If an error occurs when processing the image, the CapturedResult object will include error code and error message that describes the reason of the error.

  • Processes An ArrayBuffer object that points to a file in memory to derive important information.

    Parameters

    • fileBytes: ArrayBuffer

      An ArrayBuffer object that points to a file in memory.

    • template: string = ""

      Specifies a “CaptureVisionTemplate” to use. The following value are available for this parameter:

    Returns undefined | null | CapturedResult

    A CapturedResult object which contains the derived information from the image processed. If an error occurs when processing the image, the CapturedResult object will include error code and error message that describes the reason of the error.

  • Get a simplified settings object for the specified template name.

    Parameters

    • templateName: undefined | null | string = ""

      Specify a template with a templateName for the data capturing. If not specified, the preset template named 'Default' will be used.

    Returns Promise<SimplifiedCaptureVisionSettings>

    • A promise that resolves an object of SimplifiedCaptureVisionSettings.

    Error - If getSimplifiedSettings fails, the promise will be rejected with an error. The error may occur when

    • The target template name is invalid.
    • The template you specified is a complex template which can not be output as a SimplifiedCaptureVisionSettings object.
    • Function call is rejected when capturing in progress.
  • Configures runtime settings using a provided JSON string, which contains settings for one or more CaptureVisionTemplates.

    Parameters

    • content: string

      A JSON string that contains Capture Vision settings.

    Returns Promise<void>

    • A promise that resolves or rejected with an error when the operation has completed.
  • Configures runtime settings using a provided JSON file, which contains settings for one or more CaptureVisionTemplates.

    Parameters

    • file: string

      Absolute path of a JSON file that contains Capture Vision settings.

    Returns Promise<void>

    • A promise that resolves or rejected with an error when the operation has completed.
  • Get a JSON string that contains settings for the specified templateName.

    Parameters

    • templateName: string

      The name of the template that you want to output.

    Returns Promise<string>

    • A promise that resolves a JSON string that contains settings for the specified templateName.
  • Generates a JSON file download containing the settings for the specified templateName and saved to specified file path.

    Parameters

    • templateName: string

      The name of the template that you want to output.

    • file: string

      The absolute file path that you want to save the template.

    Returns Promise<void>

    • A promise that resolves or rejected with an error when the operation has completed.
  • Removes all CapturedResultReceiver object added in.

    Returns void

  • Removes the specified CapturedResultReceiver object.

    Code Snippet:

    let router = await CaptureVisionRouter.getInstance();
    let receiver = router.addResultReceiver({
    onCapturedResultReceived: result => {
    // Do something with the result
    },
    });
    //...
    router.removeResultReceiver(receiver);

    Parameters

    Returns void

  • Restores all runtime settings to their original default values.

    Returns Promise<void>

    • A promise that resolves when the operation has completed.

    Error - If resetSettings fails, the promise will be rejected with an error. The error may occur when

    • Function call is rejected when capturing in progress.
  • Initiates a capturing process based on a specified template. This process is repeated for each image fetched from the source.

    Code Snippet:

    let router = CaptureVisionRouter.getInstance();
    await router.startCapturing('ReadSingleBarcode');

    Parameters

    Returns Promise<void>

    Promise - A promise that resolves when the capturing process has successfully started. It does not provide any value upon resolution.

    Error - If the capturing process fails to start, the promise will be rejected with an error. The error may occur due to invalid template names, or a capturing process is already in progress, etc.

    • Always make sure there is no capturing in process or just call await CaptureVisionRouter.stopCapturing() to stop any ongoing capturing process before calling startCapturing.
  • Stops the capturing process.

    Code Snippet:

    let router = await CaptureVisionRouter.getInstance();
    await router.startCapturing("ReadSingleBarcode");
    // ...
    router.stopCapturing();

    Returns Promise<void>

  • Updates the specified templateName with an updated SimplifiedCaptureVisionSettings object. Defined properties will be updated, and undefined properties will retain their original values.

    Code Snippet:

    let router = CaptureVisionRouter.getInstance();
    let settings = {
    timeout: 1000,
    maxParallelTasks: 1,
    barcodeSettings: {
    expectedBarcodesCount: 999,
    barcodeFormatIds: EnumBarcodeFormats.BF_ONED | EnumBarcodeFormats.BF_QR_CODE,
    }
    };
    //Only timeout, maxParallelTasks, expectedBarcodesCount and barcodeFormatIds will be updated.
    router.updateSettings("ReadSingleBarcode", settings);

    Parameters

    • Optionalsettings: null | SimplifiedCaptureVisionSettings

      An object of SimplifiedCaptureVisionSettings. If undefined, will not change settings.

    • templateName: undefined | null | string = ""

      Specify the name of the template that you want to update. If undefined, the preset template named 'Default' will be used.

    Returns Promise<void>

    • A promise that resolves when the operation has completed.

    Error - If updateSettings fails, the promise will be rejected with an error. The error may occur when

    • The target template name is invalid.
    • There exists invalid parameter value in your SimplifiedCaptureVisionSettings.
    • The template you specified is a complex template which can not be output as a SimplifiedCaptureVisionSettings object.
    • Function call is rejected when capturing in progress.
  • Get the singleton instance of CaptureVisionRouter.

    This method ensures that only one instance of CaptureVisionRouter is created and reused throughout the application. If an instance already exists, it will return the existing one. Otherwise, it will create a new instance and return it.

    Returns CaptureVisionRouter

    The singleton instance of CaptureVisionRouter.