Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

Dynamsoft/capture-vision-nodejs-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a Node.js wrapper forDynamsoft Capture Vision, enabling you to read barcodes, recognize partial label text, capture documents, and perform other advanced vision tasks.

Install the SDK

npm i dynamsoft-capture-vision-for-node@3.0.1007 -E

Getting Started

Take barcode reading from an image as an example.

const{ LicenseManager, CaptureVisionRouter, EnumPresetTemplate}=require('dynamsoft-capture-vision-for-node');// You can get your trial license from// https://www.dynamsoft.com/customer/license/trialLicense -> Barcode Reader / Capture Vision Suite -> Desktop/Server/Embedded// The current license is valid for only one day.LicenseManager.initLicense('DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9');(async()=>{// you can get the image from https://github.com/Dynamsoft/capture-vision-nodejs-samples/blob/main/AllSupportedBarcodeTypes.png// The second parameter `templateName` tells the SDK how to process this image.letresult=awaitCaptureVisionRouter.captureAsync('./AllSupportedBarcodeTypes.png',EnumPresetTemplate.PT_READ_BARCODES_READ_RATE_FIRST);// refer to https://www.dynamsoft.com/capture-vision/docs/server/programming/cplusplus/api-reference/capture-vision-router/auxiliary-classes/captured-result.html?product=dbr&lang=cplusplus// or run `console.log(require('node:util').inspect(result, false, null))` to see detailsfor(letitemofresult.barcodeResultItems){console.log(item.text);}// Terminate workers so you can exit the process.// Don't call it if you still need to use the SDK.awaitCaptureVisionRouter.terminateIdleWorkers();})();

If your trial license has expired, please visithttps://www.dynamsoft.com/customer/license/trialLicense -> Barcode Reader / Capture Vision Suite -> Desktop/Server.

Note

Guides for tasks such as Label Recognition and Document Capturing are under development. You can refer to theC++ document while writing code for Node.js. Orcontact us for assistance.

Template Customization

The functionality of DCV largely depends on the choice of template. Dynamsoft offers preset templates inEnumPresetTemplate.XXXX. Here is the part about barcodes:

/** compatible with "read-barcodes" */PT_READ_BARCODES="ReadBarcodes_Default",/** Represents a barcode reading mode where speed is prioritized. */PT_READ_BARCODES_SPEED_FIRST="ReadBarcodes_SpeedFirst",/** Represents a barcode reading mode where barcode read rate is prioritized. */PT_READ_BARCODES_READ_RATE_FIRST="ReadBarcodes_ReadRateFirst",/** Represents a barcode reading mode for single barcode code detection. */PT_READ_SINGLE_BARCODE="ReadSingleBarcode",

How to Specify the Barcode Formats

Below is an example illustrating how to modify the target barcode formats forPT_READ_BARCODES_READ_RATE_FIRST.

  1. Copy the SDK'sTemplates\DBR-PresetTemplates.json to your directory. This file contains all the preset templates related to barcode reading.

  2. SearchBarcodeFormatIds and choose the one you need.

    e.g., If you only want to read specific barcode formats and ensure a high recognition rate inPT_READ_BARCODES_READ_RATE_FIRST, you can modify theBarcodeFormatIds object in thetask-read-barcodes-read-rate task.

  3. Suppose you only want to recognizeQRCode andDataMatrix; you can changeBarcodeFormatIds like this. You can get barcode format stringshere.

     "Name": "task-read-barcodes-read-rate", "ExpectedBarcodesCount": 0, "BarcodeFormatIds": [-  "BF_DEFAULT"+  "BF_QR_CODE",+  "BF_DATAMATRIX" ],
  4. Apply this template.

    CaptureVisionRouter.initSettings('path/to/the/template/file');

Warning

Due to its powerful customization capabilities, the number of configurable parameters in the templates is extensive and relatively complex. To ease your workload, if the preset templates do not meet your requirements, feel free tocontact us for a customized template.

About thecapture like API

captureAsync(...) processes images inworker. The maximum number of workers is defined byCaptureVisionRouter.maxWorkerCount, which defaults to<logical processor number> - 1 (minimum of 1). If you continue to callcaptureAsync(...) while all workers are busy, the tasks will be queued and wait for execution. You can get the queue length byCaptureVisionRouter.waitQueueLength.

The synchronous version iscapture(...), which processes images on the main thread.

Thecapture -like APIs can accept file pathstring or file bytesUint8Array as input data. Currently supported file types are jpg, png, bmp, gif, pdf, tiff. Thecapture like APIs also acceptDCVImageData as input data. Typically used to process raw data from a camera.

interfaceDCVImageData{bytes:Uint8Array;width:number;height:number;stride:number;format:EnumImagePixelFormat;/** EXIF orientation; 1 or undefined means no rotate. */orientation?:number;}

If input data is file bytes orDCVImageData, by default,captureAsync(...) willtransfer bytes into worker. Thus you can't access these bytes in the main thread aftercaptureAsync. This allows for optimal performance.

The following code can prevent bytes from being transferred.

letresult=awaitCaptureVisionRouter.captureAsync(input_data_contains_bytes,{templateName:EnumPresetTemplate.XXXX,dataTransferType:'copy'});

For multi-page PDFs and TIFFs, you can usecaptureMultiPages.

letresults=awaitCaptureVisionRouter.captureMultiPagesAsync('./multi-page.pdf',EnumPresetTemplate.XXXX);for(letresultofresults){consttag=result.originalImageTag;console.log(`# page${tag.pageNumber}/${tag.totalPages}:`);for(letitemofresult.barcodeResultItems){console.log(item.text);}}

Supported OS/Arch

Node.js >= 16.x

osarch
win32 (windows)x86, x64 (Vista or newer)
linuxx64 (glibc >= 2.18), arm64
darwin (mac)x64, arm64

Caution

Since the Dynamsoft Capture Vision 3.x version of.dylib is not fully released, only the barcode reader feature is available on thedarwin platform.

You can force(-f) install resource packages (dynamic libraries) for other OS/arch. So you can develop and deploy on different machines. You can check the<OS>-<arch>@<version> in this SDK'spackage.json->optionalDependencies.

npm i dynamsoft-capture-vision-for-node-lib-<OS>-<arch>@<version> -f -E

Samples

Web Service

Express sample andkoa sample show how to use the SDK in a web service.

You do not need to start multiple process instances inPM2 Cluster mode. As mentioned above, Dynamsoft Capture Vision for Node already manages a thread pool. However,pm2 start app.js is still useful, it can automatically restartapp.js when the service crashes.

AWS Lambda

We also made a special adaptation for AWS Lambda; seethis sample. Other similar single-function platforms may have some compatibility issues. If you have any needs, please contact us.

Special Notes

AI Model for Label Recognizer

When performing text recognition tasks, you need to installdynamsoft-capture-vision-for-node-model. You can check the<version> in the SDK'spackage.json->peerDependencies.

npm i dynamsoft-capture-vision-for-node-model@<version> -E

MultipleCaptureVisionRouter Instances

In somerare cases, you may need multipleCaptureVisionRouter instances, such as customizing different templates for each instance. Here is how to use:

letcvr=newCaptureVisionRouter();letsettings=cvr.outputSettings('<templateName>');settings.foo=bar;cvr.initSettings(settings);letresult=awaitcvr.captureAsync('<image>','<templateName>');

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp