Thanks for downloading Dynamsoft Label Recognizer Package!
Your download will start shortly. If your download does not begin, click here to retry.
Recognition APIs
Recognize Labels from Still Images
API Name | Description |
---|---|
recognize() | Recognizes labels from an image. |
recognizeBase64String() | Recognizes labels from a base64-encoded image (with or without MIME). |
recognizeUrl() | Recognizes labels from an image specified by its URL. |
recognizeBuffer() | Recognizes labels from raw image data. |
Recognize Labels from Video Frames
API Name | Description |
---|---|
onUniqueRead | This event is triggered when a new, unduplicated label is found. |
onFrameRead | This event is triggered after the library finishes scanning a frame. |
recognizeCurrentFrame() | Scans the current frame of the video for labels. |
startScanning() | Open the camera and starts continuous scanning of incoming frames. |
pauseScanning() | Pause continuous scanning but keep the video stream. |
resumeScanning() | Resumes continuous scanning. |
stopScanning() | Stops continuous scanning and closes the video stream. |
recognize
Recognizes labels from an image.
recognize(source: Blob | Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | string): Promise<DLRResult[]>
Parameters
source
: specifies the image to recognize. The supported image formats include png
, jpeg
, bmp
, gif
and a few others (some browsers support webp
, tif
). Also note that the image can be specified in a lot of ways including binary data, base64 string (with MIME), URL, etc.
Return value
A promise resolving to a DLRResult
object that contains all the label results found in this image.
Code snippet
let results1 = await recognizer.recognize(blob);
let results2 = await recognizer.recognize(htmlImageElement);
let results3 = await recognizer.recognize(url);
let results4 = await recognizer.recognize(strBase64WithMime); // like `data:image/png;base64,iV************`
You can even use an HTMLVideoElement
as the source. If the video is playing, the current frame will be recognized.
let results;
try {
// The current frame will be recognized.
results = await recognizer.recognize(htmlVideoElement);
for (let result of results) {
for (let lineResult of result.lineResults) {
console.log(lineResult.text);
}
}
} catch (ex) {
// If there is no frame in the video, throw an exception.
}
See also
- Blob
- Buffer
- ArrayBuffer
- Uint8Array
- Uint8ClampedArray
- HTMLImageElement
- HTMLCanvasElement
- HTMLVideoElement
- DLRResult
recognizeBase64String
Recognizes labels from a base64-encoded image (with or without MIME).
recognizeBase64String(base64Str: string): Promise<DLRResult[]>
Parameters
base64Str
: specifies the image represented by a string.
Return value
A promise resolving to a DLRResult
object that contains all the label results found in this image.
Code snippet
let results = await recognizer.recognizeBase64String(strBase64); //e.g. `data:image/jpg;base64,Xfjshekk....` or `Xfjshekk...`.
for (let result of results) {
for (let lineResult of result.lineResults) {
console.log(lineResult.text);
}
}
See also
recognizeUrl
Recognizes labels from an image specified by its URL. Note that the image should either be from the same domain or has the ‘Access-Control-Allow-Origin’ header set to allow access from your current domain.
recognizeUrl(url: string): Promise<DLRResult[]>
Parameters
url
: specifies the image by its URL.
Return value
A promise resolving to a DLRResult
object that contains all the label results found in this image.
Code snippet
let results = await recognizer.recognizeUrl("https://www.yourdomain.com/imageWithBarcodes.png");
for (let result of results) {
for (let lineResult of result.lineResults) {
console.log(lineResult.text);
}
}
See also
recognizeBuffer
Recognizes labels from raw image data.
recognizeBuffer(buffer: Blob | Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray, width: number, height: number, stride: number, format: EnumImagePixelFormat): Promise<DLRResult[]>
Parameters
buffer
: specifies the image represented by a Uint8Array
, Uint8ClampedArray
, ArrayBuffer
, Blob
or Buffer
object.
Return value
A promise resolving to a DLRResult
object that contains all the label results found in this image.
See also
onFrameRead | This event is triggered after the library finishes scanning a frame. |
recognizeCurrentFrame() | Scans the current frame of the video for labels. |
onUniqueRead
This event is triggered when a new, unduplicated label is found.
onUniqueRead: (txt: string, results: DLRLineResult[]) => void
Arguments
txt
: a string that holds the label text.
results
: one or more DLRLineResult
object(s) that contains more detailed info about the returned text.
Code Snippet
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance({
runtimeSettings: "video-passportMRZ"
});
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
await enhancer.setUIElement(Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL);
recognizer.cameraEnhancer = enhancer;
recognizer.onUniqueRead = (txt, results) => {
console.log(txt);
for (let result of results) {
for (let lineResult of result.lineResults) {
console.log(lineResult.text);
}
}
}
recognizer.startScanning(true);
See also
onFrameRead
This event is triggered after the library finishes scanning a frame.
onFrameRead: (results: DLRResult[]) => void
Arguments
results
: a DLRResult
object that contains all the label results in this frame.
Code Snippet
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance({
runtimeSettings: "video-passportMRZ"
});
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
await enhancer.setUIElement(Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL);
recognizer.cameraEnhancer = enhancer;
recognizer.onFrameRead = results => {
for (let result of results) {
for (let lineResult of result.lineResults) {
console.log(lineResult.text);
}
}
};
recognizer.startScanning(true);
See also
recognizeCurrentFrame
Scans the current frame of the video for barcodes.
recognizeCurrentFrame(): Promise<DLRResult[]>
Parameters
None.
Return value
A promise resolving to a DLRResult
object that contains all the label results found in this frame.
Code Snippet
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance({
runtimeSettings: "video-passportMRZ"
});
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
await enhancer.setUIElement(Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL);
recognizer.cameraEnhancer = enhancer;
await cEnhancer.open();
let results = await recognizer.recognizeCurrentFrame();
for (let result of results) {
for (let lineResult of result.lineResults) {
console.log(lineResult.text);
}
}
See also
startScanning
Open the camera and starts continuous scanning of incoming frames.
startScanning(appendOrShowUI?: boolean): Promise<PlayCallbackInfo>;
Parameters
appendOrShowUI
: this parameter specifies how to handle the UI that comes with the bound CameraEnhancer instance. When set to true, if the UI doesn’t exist in the DOM tree, the CameraEnhancer instance will append it in the DOM and show it; if the UI already exists in the DOM tree but is hidden, it’ll be displayed. When not set or set to false, it means not to change the original state of that UI: if it doesn’t exist in the DOM tree, nothing shows up on the page; if it exists in the DOM tree, it may or may not show up depending on its original state.
Return value
A promise resolving to a PlayCallbackInfo
object which contains the resolution of the video.
Code Snippet
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance({
runtimeSettings: "video-passportMRZ"
});
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
await enhancer.setUIElement(Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL);
recognizer.cameraEnhancer = enhancer;
recognizer.onUniqueRead = (txt, results) => {
console.log(txt);
for (let result of results) {
for (let lineResult of result.lineResults) {
console.log(lineResult.text);
}
}
}
recognizer.startScanning(true);
See also
pauseScanning
Pause continuous scanning but keep the video stream.
pauseScanning(): void;
resumeScanning
Resumes continuous scanning.
resumeScanning(): void;
stopScanning
Stops continuous scanning and closes the video stream.
stopScanning(hideUI?: boolean): void;
Parameters
hideUI
: this parameter specifies how to handle the UI that comes with the bound CameraEnhancer instance. When set to true, if the UI doesn’t exist in the DOM tree or it exists but is hidden, nothing is done; if the UI already exists in the DOM tree and is shown, it’ll be hidden. When not set or set to false, it means not to change the original state of that UI: if it doesn’t exist in the DOM tree, nothing happens; if it exists in the DOM tree, it may or may not be hidden depending on its original state.
Return value
None.
Code Snippet
let recognizer = await Dynamsoft.DLR.LabelRecognizer.createInstance({
runtimeSettings: "video-passportMRZ"
});
let enhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance();
await enhancer.setUIElement(Dynamsoft.DLR.LabelRecognizer.defaultUIElementURL);
recognizer.cameraEnhancer = enhancer;
recognizer.onUniqueRead = (txt, results) => {
console.log(txt);
for (let result of results) {
for (let lineResult of result.lineResults) {
console.log(lineResult.text);
}
}
// Stops scanning the video input as soon as a label is found.
recognizer.stopScanning(true);
}
await recognizer.startScanning(true);
See also