Skip to content

Latest commit

 

History

History

opencv

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Real-time Barcode and QR Code Scanning with Node.js and OpenCV

Build simple Node.js barcode reader applications for both desktop and web using barcode4nodejs and opencv4nodejs.

Prequisites

  • Dynamsoft Barcode Reader Trial License

  • Node.js

  • OpenCV

    For Windows, you must configure the following environment variables before installing the opencv4nodejs package:

    • OPENCV_INCLUDE_DIR: Points to the directory containing the opencv2 subfolder with header files.
    • OPENCV_LIB_DIR: Points to the library directory containing the OpenCV .lib files.

Installation

npm install opencv4nodejs barcode4nodejs

Usage

Set the license key in the desktop.js and web.js files:

dbr.initLicense("LICENSE-KEY")

Desktop App

Run the desktop barcode and QR code scanning app with:

node desktop.js

desktop barcode and QR code reader

Web App

To scan barcodes and QR codes in any web browser, start the web server and then navigate to localhost:2024:

node web.js

reading barcode and QR code in Microsoft Internet Explorer

Q&A

You may encounter the following error when running the code on Windows, even if the opencv4nodejs.node file has been successfully built:

node:internal/modules/cjs/loader:1275
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: The specified module could not be found.
\\?\D:\code\nodejs-barcode\examples\opencv\node_modules\opencv4nodejs\build\Release\opencv4nodejs.node
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1275:18)
    at Module.load (node:internal/modules/cjs/loader:1069:32)
    at Function.Module._load (node:internal/modules/cjs/loader:904:12)
    at Module.require (node:internal/modules/cjs/loader:1093:19)
    at require (node:internal/modules/cjs/helpers:108:18)
    at Object.<anonymous> (D:\code\nodejs-barcode\examples\opencv\node_modules\opencv4nodejs\lib\cv.js:58:8)
    at Module._compile (node:internal/modules/cjs/loader:1191:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10)
    at Module.load (node:internal/modules/cjs/loader:1069:32)
    at Function.Module._load (node:internal/modules/cjs/loader:904:12) {
  code: 'ERR_DLOPEN_FAILED'
}

To resolve this issue, check the dependencies of opencv4nodejs.node with dumpbin:

dumpbin /dependents node_modules\opencv4nodejs\build\Release\opencv4nodejs.node

opencv4nodejs dependency

Then copy the missing DLL, opencv_world410.dll, to the directory where opencv4nodejs.node is located.