-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
350 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var Quagga = require('../lib/quagga'); | ||
|
||
Quagga.decodeSingle({ | ||
src: "../test/fixtures/code_128/image-001.jpg", | ||
numOfWorkers: 0, | ||
inputStream: { | ||
size: 640 | ||
} | ||
}, function(result) { | ||
if(result.codeResult) { | ||
console.log("result", result.codeResult.code); | ||
} else { | ||
console.log("not detected"); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* jshint undef: true, unused: true, browser:true, devel: true */ | ||
/* global define */ | ||
|
||
define(["cv_utils"], function(CVUtils) { | ||
"use strict"; | ||
|
||
var FrameGrabber = {}; | ||
|
||
FrameGrabber.create = function(inputStream) { | ||
var _that = {}, | ||
_streamConfig = inputStream.getConfig(), | ||
_video_size = CVUtils.imageRef(inputStream.getRealWidth(), inputStream.getRealHeight()), | ||
_size =_streamConfig.size ? CVUtils.imageRef(inputStream.getWidth(), inputStream.getHeight()) : _video_size, | ||
_sx = 0, | ||
_sy = 0, | ||
_dx = 0, | ||
_dy = 0, | ||
_sWidth, | ||
_dWidth, | ||
_sHeight, | ||
_dHeight, | ||
_canvas = null, | ||
_ctx = null, | ||
_data = null; | ||
|
||
_sWidth = _video_size.x; | ||
_dWidth = _size.x; | ||
_sHeight = _video_size.y; | ||
_dHeight = _size.y; | ||
|
||
_data = new Uint8Array(_size.x * _size.y); | ||
|
||
/** | ||
* Uses the given array as frame-buffer | ||
*/ | ||
_that.attachData = function(data) { | ||
_data = data; | ||
}; | ||
|
||
/** | ||
* Returns the used frame-buffer | ||
*/ | ||
_that.getData = function() { | ||
return _data; | ||
}; | ||
|
||
/** | ||
* Fetches a frame from the input-stream and puts into the frame-buffer. | ||
* The image-data is converted to gray-scale and then half-sampled if configured. | ||
*/ | ||
_that.grab = function() { | ||
var doHalfSample = _streamConfig.halfSample, | ||
frame = inputStream.getFrame(); | ||
|
||
if (frame) { | ||
if(doHalfSample){ | ||
CVUtils.grayAndHalfSampleFromCanvasData(frame.data, _size, _data); | ||
} else { | ||
CVUtils.computeGray(frame.data, _data); | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
_that.getSize = function() { | ||
return _size; | ||
}; | ||
|
||
return _that; | ||
}; | ||
|
||
return (FrameGrabber); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* jshint undef: true, unused: true, browser:true, devel: true */ | ||
/* global define */ | ||
|
||
define(function() { | ||
"use strict"; | ||
|
||
var GetPixels = require("get-pixels"); | ||
|
||
var InputStream = {}; | ||
|
||
InputStream.createImageStream = function() { | ||
var that = {}; | ||
var _config = null; | ||
|
||
var width = 0, | ||
height = 0, | ||
frameIdx = 0, | ||
paused = true, | ||
loaded = false, | ||
frame = null, | ||
baseUrl, | ||
ended = false, | ||
size, | ||
calculatedWidth, | ||
calculatedHeight, | ||
_eventNames = ['canrecord', 'ended'], | ||
_eventHandlers = {}; | ||
|
||
function loadImages() { | ||
loaded = false; | ||
GetPixels(baseUrl, function(err, pixels) { | ||
if (err) { | ||
console.log(err); | ||
exit(1); | ||
} | ||
loaded = true; | ||
console.log(pixels.shape); | ||
frame = pixels; | ||
width = pixels.shape[0]; | ||
height = pixels.shape[1]; | ||
calculatedWidth = _config.size ? width/height > 1 ? _config.size : Math.floor((width/height) * _config.size) : width; | ||
calculatedHeight = _config.size ? width/height > 1 ? Math.floor((height/width) * _config.size) : _config.size : height; | ||
|
||
|
||
setTimeout(function() { | ||
publishEvent("canrecord", []); | ||
}, 0); | ||
}); | ||
} | ||
|
||
function publishEvent(eventName, args) { | ||
var j, | ||
handlers = _eventHandlers[eventName]; | ||
|
||
if (handlers && handlers.length > 0) { | ||
for ( j = 0; j < handlers.length; j++) { | ||
handlers[j].apply(that, args); | ||
} | ||
} | ||
} | ||
|
||
|
||
that.trigger = publishEvent; | ||
|
||
that.getWidth = function() { | ||
return calculatedWidth; | ||
}; | ||
|
||
that.getHeight = function() { | ||
return calculatedHeight; | ||
}; | ||
|
||
that.setWidth = function(width) { | ||
calculatedWidth = width; | ||
}; | ||
|
||
that.setHeight = function(height) { | ||
calculatedHeight = height; | ||
}; | ||
|
||
that.getRealWidth = function() { | ||
return width; | ||
}; | ||
|
||
that.getRealHeight = function() { | ||
return height; | ||
}; | ||
|
||
that.setInputStream = function(stream) { | ||
_config = stream; | ||
baseUrl = _config.src; | ||
size = 1; | ||
loadImages(); | ||
}; | ||
|
||
that.ended = function() { | ||
return ended; | ||
}; | ||
|
||
that.setAttribute = function() {}; | ||
|
||
that.getConfig = function() { | ||
return _config; | ||
}; | ||
|
||
that.pause = function() { | ||
paused = true; | ||
}; | ||
|
||
that.play = function() { | ||
paused = false; | ||
}; | ||
|
||
that.setCurrentTime = function(time) { | ||
frameIdx = time; | ||
}; | ||
|
||
that.addEventListener = function(event, f) { | ||
if (_eventNames.indexOf(event) !== -1) { | ||
if (!_eventHandlers[event]) { | ||
_eventHandlers[event] = []; | ||
} | ||
_eventHandlers[event].push(f); | ||
} | ||
}; | ||
|
||
that.getFrame = function() { | ||
if (!loaded){ | ||
return null; | ||
} | ||
return frame; | ||
}; | ||
|
||
return that; | ||
}; | ||
|
||
return (InputStream); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var requirejs = require('requirejs'); | ||
|
||
requirejs.config({ | ||
"baseUrl" : "../src", | ||
"paths" : { | ||
"typedefs" : "typedefs", | ||
"input_stream": "../lib/input_stream", | ||
"frame_grabber": "../lib/frame_grabber" | ||
} | ||
}); | ||
|
||
module.exports = requirejs('quagga'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ | |
"name": "quagga", | ||
"version": "0.6.6", | ||
"description": "An advanced barcode-scanner written in JavaScript", | ||
"main": "dist/quagga.js", | ||
"main": "lib/quagga.js", | ||
"browser": "dist/quagga.js", | ||
"devDependencies": { | ||
"async": "^0.9.0", | ||
"grunt": "~0.4.5", | ||
|
@@ -46,5 +47,9 @@ | |
"imageprocessing" | ||
], | ||
"author": "Christoph Oberhofer <[email protected]>", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"dependencies": { | ||
"get-pixels": "^3.2.2", | ||
"gl-matrix": "^2.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.