# CaptureVisionRouter Multiple Image Processing

| Name                                                  | Description                                                                            |
| ----------------------------------------------------- | -------------------------------------------------------------------------------------- |
| [setInput()](#setinput)                               | Sets up an image source to provide images for continuous processing.                   |
| [getInput()](#getinput)                               | Returns the image source object.                                                       |
| [addResultReceiver()](#addresultreceiver)             | Adds a `CapturedResultReceiver` object as the receiver of captured results.            |
| [removeResultReceiver()](#removeresultreceiver)       | Removes the specified `CapturedResultReceiver` object.                                 |
| [removeAllResultReceivers()](#removeallresultreceivers) | Removes all `CapturedResultReceiver` objects.                                        |
| [addResultFilter()](#addresultfilter)                 | Adds a `MultiFrameResultCrossFilter` object to filter non-essential results.           |
| [removeResultFilter()](#removeresultfilter)           | Removes the specified `MultiFrameResultCrossFilter` object.                            |
| [removeAllResultFilters()](#removeallresultfilters)   | Removes all `MultiFrameResultCrossFilter` objects.                                     |
| [startCapturing()](#startcapturing)                   | Initiates a capturing process based on a specified template.                           |
| [stopCapturing()](#stopcapturing)                     | Stops the capturing process.                                                           |
| [switchCapturingTemplate()](#switchcapturingtemplate) | Switches the currently active capturing template during the image processing workflow. |

<!-- 
| [addImageSourceStateListener()](#addimagesourcestatelistener)       | Adds an `ImageSourceStateListener` object that monitors changes in the state of an image source. |
| [removeImageSourceStateListener()](#removeimagesourcestatelistener) | Removes the specified `ImageSourceStateListener` object.                                     | -->
<!-- 
| [addCaptureStateListener()](#addcapturestatelistener)               | Adds a CaptureStateListener object to listen to the state changes of the capture process.  |
| [removeCaptureStateListener()](#removecapturestatelistener)         | Removes the specified CaptureStateListener object.                                         | -->

## setInput

Sets up an image source to provide images for continuous processing.

**Syntax**

```typescript
setInput(imageSource: ImageSourceAdapter): void;
```

**Parameters**

`imageSource`: The image source which is compliant with the `ImageSourceAdapter` interface.

**Return Value**

None.

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
let view = await Dynamsoft.DCE.CameraView.createInstance();
cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(view);
router.setInput(cameraEnhancer);
```

**See Also**

[ImageSourceAdapter](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/core/image-source-adapter.md)

## getInput

Returns the image source object.

**Syntax**

```typescript
getInput(): ImageSourceAdapter;
```

**Parameters**

None.

**Return Value**

Returns the current image source.

**Code snippet**

```javascript
const imageSource = CaptureVisionRouter.getInput();
```

<!--
## addCaptureStateListener

Adds an object that listens to the state changes of the capture process.

**Syntax**

```typescript
addCaptureStateListener(listener: CaptureStateListener): void;
```

**Parameters**

`listener`: The capture state listener object to be added.

**Return Value**

None.

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
let csl = {
            onCaptureStateChanged(state) {
                console.log("run CaptureStateListener", state);
            }
        }
router.addCaptureStateListener(csl);
```

## removeCaptureStateListener

Removes an object which listens to the state changes of the capture process.

**Syntax**

```typescript
removeCaptureStateListener(listener: CaptureStateListener): void;
```

**Parameters**

`listener`: The capture state listener object to be added.

**Return Value**

None.

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
let csl = {
            onCaptureStateChanged(state) {
                console.log("run CaptureStateListener", state);
            }
        }
router.removeCaptureStateListener(csl);
```
-->
<!-- 
## addImageSourceStateListener

Adds an `ImageSourceStateListener` object that monitors changes in the state of an image source.

**Syntax**

```typescript
addImageSourceStateListener(listener: ImageSourceStateListener): void;
```

**Parameters**

`listener`: The listener object, of type `ImageSourceStateListener`.

**Return Value**

None.

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
let listener = {
    onImageSourceStateReceived(state) {
        console.log("run ImageSourceAdapterStatusListener", state);
    }
}
router.addImageSourceStateListener(listener);
```

## removeImageSourceStateListener

Removes the specified `ImageSourceStateListener` object.

**Syntax**

```typescript
removeImageSourceStateListener(listener: ImageSourceStateListener): boolean;
```

**Parameters**

`listener`: The listener object, of type `ImageSourceStateListener`.

**Return Value**

Boolean indicating whether the operation succeeded.

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
let listener = {
    onImageSourceStateReceived(state) {
        console.log("run ImageSourceAdapterStatusListener", state);
    }
}
router.removeImageSourceStateListener(listener);
``` -->

## addResultReceiver

Adds a `CapturedResultReceiver` object as the receiver of captured results.

**Syntax**

```typescript
addResultReceiver(receiver: CapturedResultReceiver): Promise<void>;
```

**Parameters**

`receiver`: The receiver object, of type `CapturedResultReceiver`.

**Return Value**

None.

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
const resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();
resultReceiver.onCapturedResultReceived = (result) => {
    /* Do something with the result */
};
await router.addResultReceiver(resultReceiver);
```

**See also**

[CapturedResultReceiver](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/captured-result-receiver.md)

**Remarks**

This method was updated to an asynchronous method in in CaptureVisionBundle version 3.4.2000 & BarcodeReaderBundle version 11.4.2000.

## removeResultReceiver

Removes the specified `CapturedResultReceiver` object.

**Syntax**

```typescript
removeResultReceiver(receiver: CapturedResultReceiver): Promise<void>;
```

**Parameters**

`receiver`: The receiver object, of type `CapturedResultReceiver`.

**Return Value**

None.

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
const resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();
resultReceiver.onCapturedResultReceived = (result) => {
    /* Do something with the result */
};
await router.addResultReceiver(resultReceiver);
//...
await router.removeResultReceiver(resultReceiver);
```

**See also**

[CapturedResultReceiver](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/captured-result-receiver.md)

**Remarks**

This method was updated to an asynchronous method in in CaptureVisionBundle version 3.4.2000 & BarcodeReaderBundle version 11.4.2000.

## removeAllResultReceivers

Removes all `CapturedResultReceiver` objects.

**Syntax**

```typescript
removeAllResultReceivers(): void;
```

**Parameters**

None.

**Return Value**

None.

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
const receiver1 = new Dynamsoft.CVR.CapturedResultReceiver();
const receiver2 = new Dynamsoft.CVR.CapturedResultReceiver();
// ...
await router.addResultReceiver(receiver1);
await router.addResultReceiver(receiver2);
// ...
router.removeAllResultReceivers();
```

**See also**

[CapturedResultReceiver](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/captured-result-receiver.md)

**Remarks**

Added in CaptureVisionBundle version 3.4.2000 & BarcodeReaderBundle version 11.4.2000.

## addResultFilter

Adds a `MultiFrameResultCrossFilter` object to filter non-essential results.

**Syntax**

```typescript
addResultFilter(filter: MultiFrameResultCrossFilter): Promise<void>;
```

**Parameters**

`filter`: The filter object, of type `MultiFrameResultCrossFilter`.

**Return Value**

A promise that resolves when the operation has successfully completed. It does not provide any value upon resolution.

**Code snippet**

```javascript
filter = new Dynamsoft.Utility.MultiFrameResultCrossFilter();
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
router.addResultFilter(filter);
```

> In the provided code snippet, the default filter implementation is utilized. This filter can offer cross-validation and de-duplication functionalities. To utilize this filter, it's necessary to include the corresponding package `dynamsoft-utility`.

**See also**

[MultiFrameResultCrossFilter](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/utility/multi-frame-result-cross-filter.md)

## removeResultFilter

Removes the specified `MultiFrameResultCrossFilter` object.

**Syntax**

```typescript
removeResultFilter(filter: MultiFrameResultCrossFilter): : Promise<void>;
```

**Parameters**

`filter`: The filter object, of type `MultiFrameResultCrossFilter`.

**Return Value**

A promise that resolves when the operation has successfully completed. It does not provide any value upon resolution.

**Code snippet**

```javascript
filter = new Dynamsoft.Utility.MultiFrameResultCrossFilter();
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
router.addResultFilter(filter);
// ...
router.removeResultFilter(filter);
```

## removeAllResultFilters

Removes all `MultiFrameResultCrossFilter` objects.

**Syntax**

```typescript
removeAllResultFilters(): Promise<void>;
```

**Parameters**

None.

**Return Value**

A promise that resolves when the operation has successfully completed. It does not provide any value upon resolution.

**Code snippet**

```javascript
filter1 = new Dynamsoft.Utility.MultiFrameResultCrossFilter();
filter2 = new Dynamsoft.Utility.MultiFrameResultCrossFilter();
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
await router.addResultFilter(filter1);
await router.addResultFilter(filter2);
// ...
await router.removeAllResultFilters();
```

**See also**

[MultiFrameResultCrossFilter](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/utility/multi-frame-result-cross-filter.md)

**Remarks**

Added in CaptureVisionBundle version 3.4.2000 & BarcodeReaderBundle version 11.4.2000.

## startCapturing

Initiates a capturing process based on a specified template. This process is repeated for each image fetched from the source.

**Syntax**

```typescript
startCapturing(templateName?: string): Promise<void>;
```

**Parameters**

`templateName`: specifies a "CaptureVisionTemplate" to use. If not specified, the preset template named 'Default' will be used.

There are two types of CaptureVisionTemplates: the [preset ones](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/preset-templates.md) which come with the SDK and the custom ones that get initialized when the user calls [initSettings](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/settings.md#initsettings). 

Please be aware that the [preset CaptureVisionTemplates](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/preset-templates.md)  will be overwritten if the user calls [initSettings](https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/api-reference/capture-vision-router/settings.md#initsettings) and passes customized settings.

**Return Value**

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

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
await router.startCapturing("ReadSingleBarcode");
```

## stopCapturing

Stops the capturing process.

**Syntax**

```typescript
stopCapturing(): void;
```

**Parameters**

None.

**Return Value**

None.

**Code snippet**

```javascript
router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
await router.startCapturing("ReadSingleBarcode");
// ...
router.stopCapturing();
```

## switchCapturingTemplate

Switches the currently active capturing template during the image processing workflow. This allows dynamic reconfiguration of the capture process without restarting or reinitializing the system, enabling different settings or rules to be applied on the fly.

**Syntax**

```typescript
switchCapturingTemplate(templateName: string): Promise<void>;
```

**Parameters**

`templateName`: The name of the new capturing template to apply.

**Return Value**

A promise that resolves when the operation has completed.

**Code snippet**

```javascript
let router = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
await router.startCapturing("ReadSingleBarcode");
// Switching to ReadRateFirst template
await router.switchCapturingTemplate("ReadBarcodes_ReadRateFirst");
```

**Remarks**

Introduced in Dynamsoft Barcode Reader Bundle version 11.2.2000 and Dynamsoft Capture Vision Bundle version 3.2.2000.
