nodejs not working \w sample code
See original GitHub issuehttps://github.com/zxing-js/library/issues/148#issuecomment-479674044
it does not work with the latest version
i keep receiving: ‘(node:27418) UnhandledPromiseRejectionWarning: Error: SOI not found’ all time
const { MultiFormatReader, BarcodeFormat, DecodeHintType, RGBLuminanceSource, BinaryBitmap, HybridBinarizer } = require('@zxing/library');
const fs = require('fs');
const jpeg = require('jpeg-js');
const readFile = path => new Promise((resolve, reject) => fs.readFile(path, (err, content) => {
if(err) return reject(err);
else return resolve(content);
}))
readFile('Qr-1.png').then(jpegData => {
const rawImageData = jpeg.decode(jpegData);
const hints = new Map();
const formats = [BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX];
hints.set(DecodeHintType.POSSIBLE_FORMATS, formats);
hints.set(DecodeHintType.TRY_HARDER, true);
const reader = new MultiFormatReader();
reader.setHints(hints);
const len = rawImageData.width * rawImageData.height;
const luminancesUint8Array = new Uint8Array(len);
for(let i = 0; i < len; i++){
luminancesUint8Array[i] = ((rawImageData.data[i*4]+rawImageData.data[i*4+1]*2+rawImageData.data[i*4+2]) / 4) & 0xFF;
}
const luminanceSource = new RGBLuminanceSource(luminancesUint8Array, rawImageData.width, rawImageData.height);
console.log(luminanceSource)
const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
const decoded = reader.decode(binaryBitmap);
console.log(decoded)
})
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
15 Common Error Codes in Node.js and How to Fix Them
15 Common Error Codes in Node.js and How to Fix Them ... Here's an example of how the error often appears in the...
Read more >Node.js - Basic example not working - Stack Overflow
I have been trying to figure out why i cant get even the most basic Node.js application to run, all day. I have...
Read more >Build Node.js Apps with Visual Studio Code
The Visual Studio Code editor has great support for writing and debugging Node.js applications. This tutorial takes you from Hello World to a...
Read more >6 reasons your Node.js apps are failing - IBM Developer
Poor performance; Crash or abort in native code ; Unexpected application behavior or functional issue. The approach you take to diagnose the problem...
Read more >Top 10 Most Common Node.js Developer Mistakes - Toptal
js problems can have devastating effects on your program. Some may be the cause of frustration while you're trying to implement the simplest...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, first of all, are you using JPEG files?
Jimp
at the place ofjpeg-js
… this problem Might be resolved