mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Added camera selection to example; Upgrade to webpack 2.2
This commit is contained in:
@@ -1 +1 @@
|
||||
@import url("http://fonts.googleapis.com/css?family=Ubuntu:400,700|Cabin+Condensed:400,600");
|
||||
@import url("https://fonts.googleapis.com/css?family=Ubuntu:400,700|Cabin+Condensed:400,600");
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
/* Main Secondary color (2) */
|
||||
/* Generated by Paletton.com ├é┬® 2002-2014 */
|
||||
/* http://paletton.com */
|
||||
@import url("http://fonts.googleapis.com/css?family=Ubuntu:400,700|Cabin+Condensed:400,600");
|
||||
@import url("https://fonts.googleapis.com/css?family=Ubuntu:400,700|Cabin+Condensed:400,600");
|
||||
/* line 1, ../sass/_viewport.scss */
|
||||
#interactive.viewport {
|
||||
width: 640px;
|
||||
|
||||
@@ -81,6 +81,11 @@
|
||||
<option value="8">8</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>Camera</span>
|
||||
<select name="input-stream_constraints" id="deviceSelection">
|
||||
</select>
|
||||
</label>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div id="result_strip">
|
||||
@@ -91,7 +96,7 @@
|
||||
</section>
|
||||
<footer>
|
||||
<p>
|
||||
© Copyright by Christoph Oberhofer
|
||||
© Made with ❤️ by Christoph Oberhofer
|
||||
</p>
|
||||
</footer>
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@ $(function() {
|
||||
}
|
||||
});
|
||||
var App = {
|
||||
init : function() {
|
||||
init: function() {
|
||||
var self = this;
|
||||
|
||||
Quagga.init(this.state, function(err) {
|
||||
if (err) {
|
||||
return self.handleError(err);
|
||||
}
|
||||
Quagga.registerResultCollector(resultCollector);
|
||||
//Quagga.registerResultCollector(resultCollector);
|
||||
App.attachListeners();
|
||||
Quagga.start();
|
||||
});
|
||||
@@ -25,9 +25,31 @@ $(function() {
|
||||
handleError: function(err) {
|
||||
console.log(err);
|
||||
},
|
||||
initCameraSelection: function(){
|
||||
var streamLabel = Quagga.CameraAccess.getActiveStreamLabel();
|
||||
|
||||
return Quagga.CameraAccess.enumerateVideoDevices()
|
||||
.then(function(devices) {
|
||||
function pruneText(text) {
|
||||
return text.length > 30 ? text.substr(0, 30) : text;
|
||||
}
|
||||
var $deviceSelection = document.getElementById("deviceSelection");
|
||||
while ($deviceSelection.firstChild) {
|
||||
$deviceSelection.removeChild($deviceSelection.firstChild);
|
||||
}
|
||||
devices.forEach(function(device) {
|
||||
var $option = document.createElement("option");
|
||||
$option.value = device.deviceId || device.id;
|
||||
$option.appendChild(document.createTextNode(pruneText(device.label || device.deviceId || device.id)));
|
||||
$option.selected = streamLabel === device.label;
|
||||
$deviceSelection.appendChild($option);
|
||||
});
|
||||
});
|
||||
},
|
||||
attachListeners: function() {
|
||||
var self = this;
|
||||
|
||||
self.initCameraSelection();
|
||||
$(".controls").on("click", "button.stop", function(e) {
|
||||
e.preventDefault();
|
||||
Quagga.stop();
|
||||
@@ -64,7 +86,11 @@ $(function() {
|
||||
|
||||
return parts.reduce(function(o, key, i) {
|
||||
if (setter && (i + 1) === depth) {
|
||||
o[key] = val;
|
||||
if (typeof o[key] === "object" && typeof val === "object") {
|
||||
Object.assign(o[key], val);
|
||||
} else {
|
||||
o[key] = val;
|
||||
}
|
||||
}
|
||||
return key in o ? o[key] : {};
|
||||
}, obj);
|
||||
@@ -95,10 +121,15 @@ $(function() {
|
||||
inputMapper: {
|
||||
inputStream: {
|
||||
constraints: function(value){
|
||||
var values = value.split('x');
|
||||
if (/^(\d+)x(\d+)$/.test(value)) {
|
||||
var values = value.split('x');
|
||||
return {
|
||||
width: {min: parseInt(values[0])},
|
||||
height: {min: parseInt(values[1])}
|
||||
};
|
||||
}
|
||||
return {
|
||||
width: {min: parseInt(values[0])},
|
||||
height: {min: parseInt(values[1])}
|
||||
deviceId: value
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
@@ -37,7 +37,6 @@ module.exports = function(config) {
|
||||
plugins: [
|
||||
'karma-chrome-launcher',
|
||||
'karma-mocha',
|
||||
'karma-requirejs',
|
||||
'karma-chai',
|
||||
'karma-sinon',
|
||||
'karma-sinon-chai',
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ module.exports = function(config) {
|
||||
}, {
|
||||
test: /\.js$/,
|
||||
include: path.resolve('src'),
|
||||
loader: 'babel-istanbul'
|
||||
loader: 'babel-istanbul-loader'
|
||||
}]
|
||||
},
|
||||
resolve: {
|
||||
|
||||
+7
-6
@@ -9,6 +9,7 @@
|
||||
"babel-cli": "^6.5.1",
|
||||
"babel-core": "^6.21.0",
|
||||
"babel-eslint": "^7.1.1",
|
||||
"babel-istanbul": "^0.8.0",
|
||||
"babel-istanbul-loader": "^0.1.0",
|
||||
"babel-loader": "^6.2.10",
|
||||
"babel-plugin-add-module-exports": "^0.2.1",
|
||||
@@ -41,23 +42,23 @@
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-cli": "^0.1.13",
|
||||
"grunt-contrib-nodeunit": "^0.4.1",
|
||||
"grunt-karma": "^0.12.1",
|
||||
"grunt-karma": "^2.0.0",
|
||||
"isparta-loader": "^2.0.0",
|
||||
"karma": "^0.13.9",
|
||||
"karma": "^1.3.0",
|
||||
"karma-chai": "0.1.0",
|
||||
"karma-chrome-launcher": "^0.2.0",
|
||||
"karma-coverage": "^0.5.2",
|
||||
"karma-chrome-launcher": "^2.0.0",
|
||||
"karma-coverage": "^1.1.1",
|
||||
"karma-firefox-launcher": "^0.1.7",
|
||||
"karma-mocha": "~0.2.0",
|
||||
"karma-phantomjs-launcher": "^0.2.1",
|
||||
"karma-sinon": "^1.0.4",
|
||||
"karma-sinon-chai": "^1.1.0",
|
||||
"karma-source-map-support": "^1.1.0",
|
||||
"karma-webpack": "^1.7.0",
|
||||
"karma-webpack": "^1.8.1",
|
||||
"lolex": "^1.4.0",
|
||||
"mocha": "^2.3.2",
|
||||
"phantomjs": "^1.9.18",
|
||||
"sinon": "^1.16.1",
|
||||
"sinon": "^1.17.7",
|
||||
"sinon-chai": "^2.8.0",
|
||||
"webpack": "^2.2.0-rc.3",
|
||||
"webpack-sources": "^0.1.3"
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXAIBAAKBgQC9ORap3LvRegtrhRc8dLdH9Bp2QokcKEsWbtvyhtjisRRm2slK
|
||||
A6Q11McB/YTb7oImFfNaCX+7vdM1oVXVLJ0ekQaNljXG5Dy7DXEcT1V6gpN4xmZJ
|
||||
8f/KZ45VBINN0Ha74L7nS4kgImh5yvNolNr4IdlSjGf09kciFy8S3kPlGQIDAQAB
|
||||
AoGAYDlaxBCC1liY3Bl3IoA7//QrTL4zGUWIQaUoZmGag1UHifJycBf/9nv4o5N3
|
||||
b5wPRSzebofsE93JPTmI+3nPf62k5rS2xOo8swwOZc+f5/v0EnUNixD7P0jBiLVR
|
||||
B8kbMvNdNn33HuynW1/MSBFE0cfeDH2i8SVl+Z+fHYIUW10CQQD0yWB8xeM8AxYB
|
||||
/ZZWClem6gf1lQAYLzid3x51pkLqRFpX+rG251cSBUouE+kVO14j2xrBqCyyOwNu
|
||||
17eazy3DAkEAxeQdWP9b11ihKOf/kjXiczltLnBsotn6K9EEAe0QuH/6iXLm86mL
|
||||
ZiQe+TrY1GWbK3ns0sfXgNJ2aeaRkeZn8wJAWF5WedTKisCmckOEwTzslbJI+0w2
|
||||
A4UQkFWa3mgOIhpY7wfunhP35+aG+AlyDJspChKwHxdCQ3lwbNRtUPLYFwJBAK8G
|
||||
9QIbUbLlPB1/HOfH6xM4rp3NZ/idzQxmISJG+GwHHaPmUekfgyEDP7X2W4N4nsbU
|
||||
XyeLA8t32q4N9aDS5gsCQDHqhsXqnY6e4IEZrvf90l2V1PpnTKfEl/F5wye3g69G
|
||||
JN57scVUBHP/KKoyfge0fytWiQN/56KvWH+G5+N/JyA=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
-----BEGIN CERTIFICATE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dT9r
|
||||
Ysx2ucAF6lNHayekRmNq
|
||||
-----END CERTIFICATE-----
|
||||
@@ -0,0 +1,30 @@
|
||||
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
|
||||
# generate server.xml with the following command:
|
||||
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
|
||||
# run as follows:
|
||||
# python simple-https-server.py
|
||||
# then in your browser, visit:
|
||||
# https://localhost:4443
|
||||
|
||||
import BaseHTTPServer, SimpleHTTPServer
|
||||
import ssl
|
||||
import sys, getopt
|
||||
|
||||
host = 'localhost'
|
||||
port = 4443
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:],"",["host=", "port="])
|
||||
except getopt.GetoptError:
|
||||
print 'simple-https-server.py --host <host> --port <port>'
|
||||
sys.exit(2)
|
||||
for opt, arg in opts:
|
||||
if opt in ("--host"):
|
||||
host = arg
|
||||
elif opt in ("--port"):
|
||||
port = int(arg)
|
||||
print 'host is ', host
|
||||
print 'port is ', port
|
||||
|
||||
httpd = BaseHTTPServer.HTTPServer((host, port), SimpleHTTPServer.SimpleHTTPRequestHandler)
|
||||
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='./server.pem', server_side=True)
|
||||
httpd.serve_forever()
|
||||
@@ -24,3 +24,28 @@ Math.imul = Math.imul || function(a, b) {
|
||||
// the final |0 converts the unsigned value into a signed value
|
||||
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0) | 0);
|
||||
};
|
||||
|
||||
if (typeof Object.assign !== 'function') {
|
||||
Object.assign = function(target) { // .length of function is 2
|
||||
'use strict';
|
||||
if (target === null) { // TypeError if undefined or null
|
||||
throw new TypeError('Cannot convert undefined or null to object');
|
||||
}
|
||||
|
||||
var to = Object(target);
|
||||
|
||||
for (var index = 1; index < arguments.length; index++) {
|
||||
var nextSource = arguments[index];
|
||||
|
||||
if (nextSource !== null) { // Skip over if undefined or null
|
||||
for (var nextKey in nextSource) {
|
||||
// Avoid bugs when hasOwnProperty is shadowed
|
||||
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
||||
to[nextKey] = nextSource[nextKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return to;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -109,6 +109,11 @@ export function pickConstraints(videoConstraints) {
|
||||
return Promise.resolve(normalizedConstraints);
|
||||
}
|
||||
|
||||
function enumerateVideoDevices() {
|
||||
return enumerateDevices()
|
||||
.then(devices => devices.filter(device => device.kind === 'videoinput'));
|
||||
}
|
||||
|
||||
export default {
|
||||
request: function(video, videoConstraints) {
|
||||
return pickConstraints(videoConstraints)
|
||||
@@ -120,5 +125,14 @@ export default {
|
||||
tracks[0].stop();
|
||||
}
|
||||
streamRef = null;
|
||||
},
|
||||
enumerateVideoDevices,
|
||||
getActiveStreamLabel: function() {
|
||||
if (streamRef) {
|
||||
const tracks = streamRef.getVideoTracks();
|
||||
if (tracks && tracks.length) {
|
||||
return tracks[0].label;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+2
-1
@@ -539,5 +539,6 @@ export default {
|
||||
},
|
||||
ImageWrapper: ImageWrapper,
|
||||
ImageDebug: ImageDebug,
|
||||
ResultCollector: ResultCollector
|
||||
ResultCollector: ResultCollector,
|
||||
CameraAccess: CameraAccess,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user