npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dynamsoft-capture-vision-for-node

v0.0.1

Published

Dynamsoft Capture Vision (DCV) is a comprehensive SDK that integrates various functional products. It encompasses image capture, content understanding, result parsing, and interactive workflow. Essentially, DCV processes images to extract specific informa

Readme

Dynamsoft Capture Vision for Node

This is a nodejs wrapper for Dynamsoft Capture Vision. You can use it to parse barcodes, recognize partial label text, capture documents, and more.

npm i dynamsoft-capture-vision-for-node

Let's take parsing a QR code in a picture as an example.

const { LiceseManager, CaptureVisionRouter, EnumPresetTemplate } = require('dynamsoft-capture-vision-for-node');
const util = require('node:util');

// You can get your trial license from
// https://www.dynamsoft.com/customer/license/trialLicense -> Barcode Reader -> Desktop/Server
// The current used license is valid for 1 day.
LiceseManager.initLicense('DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9');

//// In some cases you need custom templates provided by Dynamsoft Support
// CaptureVisionRouter.initSettings('path/to/template');

(async()=>{
    // you can get the image from https://github.com/Dynamsoft/capture-vision-for-node
    // The second parameter `templateName` tells the SDK how to process this image.
    let result = await CaptureVisionRouter.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(util.inspect(result, false, null))` to see details
    for(let item of result.barcodeResultItems){
        console.log(item.text);
    }
})();

The capture like API

CaptureVisionRouter.captureAsync(...) process image in worker_threads. The max number of worker is defined in CaptureVisionRouter.maxWorkerCount, by default <logical processor number> - 1, Minimum 1. If you continue to call captureAsync(...) when all workers are busy, it will be queued waiting for execution.

The synchronous version is CaptureVisionRouter.capture(...), which processes images on the main thread.

The capture like APIs can accept file path string or file bytes Uint8Array as input data. Currently supported file types are jpg, png, bmp, gif, pdf.

The capture like APIs also accept DCVImageData as input data. Typically used to process raw data from a camera.

interface DCVImageData{
  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 or DCVImageData, by default, CaptureVisionRouter.captureAsync(...) will transfer bytes into worker. Thus you can't access to these bytes in main thread after captureAsync. This allows for optimal performance.

The following code can prevent bytes from being transferred.

let result = await CaptureVisionRouter.captureAsync(input_data_contains_bytes, {
    templateName: EnumPresetTemplate.XXXX,
    dataTransferType: 'copy'
});

Web Service

Express sample and koa sample shows how to use the SDK in a web service. You do not need to start multiple instance processes in PM2 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 restart app.js when service crashes.

Supported OS/Arch

| os | arch | |:-----|:-------| | windows | x86, x64 | | linux | x64, amd64 | | mac | x64, amd64 |

If you are sure you don't need to support some of these OS/arch, you can delete some files in node_modules/dynamsoft-capture-vision-for-node/dylib and node_modules/koffi, to reduce the size. In some cloud platforms like AWS lambda, size is important.

AWS Lambda

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

Multiple CaptureVisionRouter Instances

In some rare cases you may need multiple CaptureVisionRouter instances, such as customizing different templates for each instance. Here is how to use:

let cvr = new CaptureVisionRouter();

let settings = cvr.outputSettings('<templateName>');
settings.foo = bar;
cvr.initSettings(settings);

let result = await cvr.captureAsync('<image>', '<templateName>');