Frame Acquisition
API Name | Description |
---|---|
setScanRegion() | Specifies which part of the original video is considered when processing frames. |
getScanRegion() | Returns the scan region. |
getFrame() | Returns a DCEFrame object which contains the image data of the latest frame from the video input. |
getFrameFromBuffer() | Returns a DCEFrame object which contains the image data of the specified buffered frame. |
clearFrameBuffer() | Removes all buffered frames. |
startFetchingLoop() | Starts a fetching loop that continuously put frames in a buffer. |
stopFetchingLoop() | Stops the fetching loop. |
isFetchingLoopStarted() | Returns the state of the fetching loop. |
framePixelFormat | Sets or returns the pixel format of the images generated by getFrame(). |
maxNumberOfFramesInBuffer | Sets or returns how many frames can be buffered. |
numberOfFramesInBuffer | Returns how many frames there are in the buffer. |
loopInterval | Returns or sets the start time of the next fetch operation. |
singleFrameMode | Returns or sets whether to enable the singe-frame mode. |
setScanRegion
Specifies which part of the original video is considered when processing frames.
setScanRegion(region: Region): void;
Parameters
region
: a Region
object that specifies a part of the video.
Return value
None.
Code Snippet
let region = {
regionLeft: 25,
regionTop: 25,
regionRight: 75,
regionBottom: 75,
regionMeasuredByPercentage: true
};
enhancer.setScanRegion(region);
See also
getScanRegion
Returns the scan region.
getScanRegion(): Region;
Parameters
None.
Return value
A Region
object which specifies the scan region.
Code Snippet
let region = enhancer.getScanRegion();
See also
getFrame
Returns a DCEFrame
object which contains the image data of the latest frame from the video input.
getFrame(): DCEFrame;
Parameters
None.
Return value
A DCEFrame
object which contains the image data of the frame and related information.
Code Snippet
let frameData = enhancer.getFrame();
document.body.appendChild(frameData.toCanvas());
See also
getFrameFromBuffer
Returns a DCEFrame
object which contains the image data of the specified buffered frame.
getFrameFromBuffer(index?: number): DCEFrame;
Parameters
index
: specifies which buffered frame to return when maxNumberOfFramesInBuffer
is bigger than 1. If not specified, the latest buffered frame is returned.
Return value
A DCEFrame
object which contains the image data of the frame and related information.
Code Snippet
let frameData = enhancer.getFrameFromBuffer();
document.body.appendChild(frameData.toCanvas());
See also
clearFrameBuffer
Removes all buffered frames.
clearFrameBuffer(): void;
Parameters
None.
Return value
None.
Code Snippet
enhancer.clearFrameBuffer();
startFetchingLoop
Starts a fetching loop that continuously put frames in a buffer.
When the API is called, the SDK immediately fetches a frame and puts it into the buffer, then waits for the time set by “loopInterval” before fetching the next frame, and so on.
startFetchingLoop(): void;
Parameters
None.
Return value
None.
See also
stopFetchingLoop
Stops the fetching loop and clears the frames buffer.
stopFetchingLoop(): void;
Parameters
None.
Return value
None.
isFetchingLoopStarted
Returns the state of the fetching loop.
isFetchingLoopStarted(): Boolean;
Parameters
None.
Return value
None.
framePixelFormat
Sets or returns the color mode of the images generated by getFrame(). The value is limited to “rgba” (default), “rbga”, “grba”, “gbra”, “brga”, “bgra”, “grey” and “grey32”.
framePixelFormat: string;
maxNumberOfFramesInBuffer
Sets or returns how many frames can be buffered.
maxNumberOfFramesInBuffer: number;
numberOfFramesInBuffer
Returns how many frames there are in the buffer.
readonly numberOfFramesInBuffer: number;
loopInterval
Returns or sets the start time of the next fetch operation.
loopInterval: number;
See also
singleFrameMode
Returns or sets whether to enable the singe-frame mode. When the single-frame mode is enabled, the video will not stream in the built-in UI of the library. Instead, the user can click the UI to invoke the system camera interface to catch a frame or select an existing image from the device storage.
To get the actual data, add a event handler to the event ‘singleFrameAcquired’.
singleFrameMode: boolean;
Code Snippet
(async () => {
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
enhancer.on('singleFrameAcquired', frameData => {
document.body.appendChild(frameData.toCanvas());
});
enhancer.singleFrameMode = true;
await enhancer.open(true);
})();