Comments (5)
Web workers would indeed make a lot of sense in this context. The main problem to solve when using web workers is how to pass the image-data into the worker. Sure, there is the option to use Transferables, but then I lose access to the already allocated memory and have to re-allocate the buffer for every new frame. And copying the entire buffer to the web worker context does only waste resources. Do you have experience in working with web workers? Do you know how to solve this problem in a memory- and CPU efficient way?
from quaggajs.
Worker.postMessage works in both directions, including the list of Transferables. So you can get your buffer back. It doesn't make sense to even try to process frames while the web worker is going so just ignore those frames until the web worker returns.
from quaggajs.
I would do something like this:
var video = document.querySelector('#video'),
canvas = document.createElement('canvas');
navigator.getMedia(
{
video: true,
audio: false
},
function(stream) {
if (navigator.mozGetUserMedia) {
video.mozSrcObject = stream;
} else {
var vendorURL = window.URL || window.webkitURL;
video.src = vendorURL ? vendorURL.createObjectURL(stream) : stream;
}
video.play();
decodeBarcode();
},
function(err) {
console.log('An error occured! ' + err);
}
);
var workerCount = 0,
ctx = canvas.getContext('2d')
function decodeBarcode() {
if (workerCount === 0) {
if (decodeWorker === null) {
decodeWorker = new Worker('decoder.js');
decodeWorker.onmessage = receiveMessage;
}
workerCount++;
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
decodeWorker.postMessage({
imageData: ctx.getImageData(0, 0, canvas.width, canvas.height).data,
width: canvas.width,
height: canvas.height
});
}
}
function receiveMessage(e) {
workerCount--;
if (e.data.success === true) {
alert(e.data.result);
}
decodeBarcode();
}
from quaggajs.
Finally, after multiple iterations of different approaches, I managed to find a good solution which works for most use-cases. If you are interested, take a look at the issue-1a branch. Feedback is greatly appreciated.
from quaggajs.
This issue should be solved with #12
from quaggajs.
Related Issues (20)
- Quagga onDetected() uses detected results from decodeSingle()
- 39 vin
- I would like to add the getStream method to Camera_Access. HOT 1
- No results from the scanner on > iOS 14 HOT 16
- Unable to read large QR code HOT 9
- Support for PDF417 HOT 1
- Question: Is this project still maintained? HOT 6
- Scan barcode (code39) succeeded in Android. But failed on iPhone. No response.
- Command Line Application with Node
- QuaggaJS Barcode scanner not working for Androids HOT 1
- i would like to know if it quaggaJS supports accessibility features. Specifically, I am looking for support for screen readers, keyboard navigation, and high-contrast mode. Can you please let me know if your quaggaJS has these features, and if there are any other accessibility features that you support?
- Using quagga with recent Iphone - problem of camera focusins ?
- Any idea what permissions I need to grant on a Cordova (phone gap) app for the Quagga JS to work on iOS? HOT 1
- pass the scanned barcode as text in input text HOT 1
- incremental scanner
- MSI reader support
- Lib is not detecting code correctly
- Width and Height inverted on mobile, but correct on desktop
- ReferenceError: exit is not defined HOT 1
- Zoom always returning null? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quaggajs.