在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:serratus/quaggaJS开源软件地址:https://github.com/serratus/quaggaJS开源编程语言:JavaScript 98.0%开源软件介绍:quaggaJS
What is QuaggaJS?QuaggaJS is a barcode-scanner entirely written in JavaScript supporting real-
time localization and decoding of various types of barcodes such as EAN,
CODE 128, CODE 39, EAN 8, UPC-A, UPC-C, I2of5,
2of5, CODE 93 and CODABAR. The library is also capable of using
Try some examples and check out the blog post (How barcode-localization works in QuaggaJS) if you want to dive deeper into this topic. Yet another barcode library?This is not yet another port of the great zxing library, but more of an extension to it. This implementation features a barcode locator which is capable of finding a barcode-like pattern in an image resulting in an estimated bounding box including the rotation. Simply speaking, this reader is invariant to scale and rotation, whereas other libraries require the barcode to be aligned with the viewport. Browser SupportQuagga makes use of many modern Web-APIs which are not implemented by all browsers yet. There are two modes in which Quagga operates: 1. analyzing static images and 2. using a camera to decode the images from a live-stream. The latter requires the presence of the MediaDevices API. You can track the compatibility of the used Web-APIs for each mode: Static ImagesThe following APIs need to be implemented in your browser: Live StreamIn addition to the APIs mentioned above: Important: Accessing Feature-detection of getUserMediaEvery browser seems to differently implement the Here's how you can test your browser's capabilities: if (navigator.mediaDevices && typeof navigator.mediaDevices.getUserMedia === 'function') {
// safely access `navigator.mediaDevices.getUserMedia`
} The above condition evaluates to:
InstallingQuaggaJS can be installed using npm, bower, or by including it with the script tag. NPM> npm install quagga And then import it as dependency in your project: import Quagga from 'quagga'; // ES6
const Quagga = require('quagga').default; // Common JS (important: default) Currently, the full functionality is only available through the browser. When using QuaggaJS within node, only file-based decoding is available. See the example for node_examples. BowerYou can also install QuaggaJS through bower: > bower install quagga Script-Tag Anno 1998You can simply include Getting StartedFor starters, have a look at the examples to get an idea where to go from here. BuildingYou can build the library yourself by simply cloning the repo and typing: > npm install
> npm run build This npm script builds a non optimized version NodeThe code in the APIYou can check out the examples to get an idea of how to use QuaggaJS. Basically the library exposes the following API: Quagga.init(config, callback)This method initializes the library for a given configuration If you do not specify a target, QuaggaJS would look for an element that matches
the CSS selector Quagga.init({
inputStream : {
name : "Live",
type : "LiveStream",
target: document.querySelector('#yourElement') // Or '#yourElement' (optional)
},
decoder : {
readers : ["code_128_reader"]
}
}, function(err) {
if (err) {
console.log(err);
return
}
console.log("Initialization finished. Ready to start");
Quagga.start();
}); Quagga.start()When the library is initialized, the Quagga.stop()If the decoder is currently running, after calling Quagga.onProcessed(callback)This method registers a Quagga.onDetected(callback)Registers a Quagga.decodeSingle(config, callback)In contrast to the calls described above, this method does not rely on
Quagga.offProcessed(handler)In case the Quagga.offDetected(handler)In case the The result objectThe callbacks passed into {
"codeResult": {
"code": "FANAVF1461710", // the decoded code as a string
"format": "code_128", // or code_39, codabar, ean_13, ean_8, upc_a, upc_e
"start": 355,
"end": 26,
"codeset": 100,
"startInfo": {
"error": 1.0000000000000002,
"code": 104,
"start": 21,
"end": 41
},
"decodedCodes": [{
"code": 104,
"start": 21,
"end": 41
},
// stripped for brevity
{
"error": 0.8888888888888893,
"code": 106,
"start": 328,
"end": 350
}],
"endInfo": {
"error": 0.8888888888888893,
"code": 106,
"start": 328,
"end": 350
},
"direction": -1
},
"line": [{
"x": 25.97278706156836,
"y": 360.5616435369468
}, {
"x": 401.9220519377024,
"y": 70.87524989906444
}],
"angle": -0.6565217179979483,
"pattern": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, /* ... */ 1],
"box": [
[77.4074243622672, 410.9288668804402],
[0.050203235235130705, 310.53619724086366],
[360.15706727788256, 33.05711026051813],
[437.5142884049146, 133.44977990009465]
],
"boxes": [
[
[77.4074243622672, 410.9288668804402],
[0.050203235235130705, 310.53619724086366],
[360.15706727788256, 33.05711026051813],
[437.5142884049146, 133.44977990009465]
],
[
[248.90769330706507, 415.2041489551161],
[198.9532321622869, 352.62160512937635],
[339.546160777576, 240.3979259789976],
[389.5006219223542, 302.98046980473737]
]
]
} ConfigurationThe configuration that ships with QuaggaJS covers the default use-cases and can be fine-tuned for specific requirements. The configuration is managed by the {
numOfWorkers: 4,
locate: true,
inputStream: {...},
frequency: 10,
decoder:{...},
locator: {...},
debug: false,
} numOfWorkersQuaggaJS supports web-workers out of the box and runs with In case you don't know the number upfront, or if the variety of devices is
too big, you can either use locateOne of the main features of QuaggaJS is its ability to locate a barcode in a
given image. The Why would someone turn this feature off? Localizing a barcode is a computationally expensive operation and might not work properly on some devices. Another reason would be the lack of auto-focus producing blurry images which makes the localization feature very unstable. However, even if none of the above apply, there is one more case where it might
be useful to disable inputStreamThe {
name: "Live",
type: "LiveStream",
constraints: {
width: 640,
height: 480,
facingMode: "environment",
deviceId: "7832475934759384534"
},
area: { // defines rectangle of the detection/localization area
top: "0%", // top offset
right: "0%", // right offset
left: "0%", // left offset
bottom: "0%" // bottom offset
},
singleChannel: false // true: only the red color-channel is read
} First, the Second, the Thirdly, the The last key frequencyThis top-level property controls the scan-frequency of the video-stream. It's optional and defines the maximum number of scans per second. This renders useful for cases where the scan-session is long-running and resources such as CPU power are of concern. decoderQuaggaJS usually runs in a two-stage manner ( {
readers: [
'code_128_reader'
],
debug: {
drawBoundingBox: false,
showFrequency: false,
drawScanline: false,
showPattern: false
}
multiple: false
} The most important property is
Why are not all types activated by default? Simply because one should explicitly define the set of barcodes for their use-case. More decoders means more possible clashes, or false-positives. One should take care of the order the readers are given, since some might return a value even though it is not the correct type (EAN-13 vs. UPC-A). The The remaining properties Enabling extended EANThe default setting for decoder: {
readers: [{
format: "ean_reader",
config: {
supplements: [
'ean_5_reader', 'ean_2_reader'
]
}
}]
} Beware that the order of the It's important to mention that, if supplements are supplied, regular EAN-13
codes cannot be read any more with the same reader. If you want to read EAN-13
with and without extensions you have to add another locatorThe Only two properties are relevant for the use in Quagga ( {
halfSample: true,
patchSize: "medium", // x-small, small, medium, large, x-large
debug: {
showCanvas: false,
showPatches: false,
showFoundPatches: false,
showSkeleton: false,
showLabels: false,
showPatchLabels: false,
showRemainingPatchLabels: false,
boxFromPatches: {
showTransformed: false,
showTransformedBox: false,
showBB: false
}
}
} The The second property ExamplesThe following example takes an image Quagga.decodeSingle({
decoder: {
readers: ["code_128_reader"] // List of active readers
},
locate: true,
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论