Created
November 15, 2015 19:46
-
-
Save julianduque/cd6a517a27a7311b20a6 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Streaming</title> | |
</head> | |
<body> | |
<img id="video" /> | |
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
var socket = io.connect() | |
var video = document.querySelector('#video') | |
socket.on('image', function (buffer) { | |
video.src = 'data:image/jpeg;base64,' + buffer | |
}) | |
</script> | |
</body> | |
</html> | |
<!-- ponerlo en la carpeta public --> |
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
var http = require('http') | |
var path = require('path') | |
var express = require('express') | |
var EventEmitter = require('events').EventEmitter | |
var events = new EventEmitter() | |
var app = express() | |
app.use(express.static(path.join(__dirname, 'public'))) | |
var server = http.createServer(app) | |
var io = require('socket.io')(server) | |
io.on('connection', function (socket) { | |
events.on('image', function (buffer) { | |
socket.emit('image', buffer) | |
}) | |
}) | |
server.listen(8080) | |
var cv = require('opencv') | |
try { | |
var camera = new cv.VideoCapture(1) | |
function loop () { | |
camera.read(function (err, im) { | |
if (err) throw err | |
events.emit('image', im.toBuffer().toString('base64')) | |
}) | |
} | |
setInterval(loop, 500) | |
} catch (e) { | |
console.error(e.message) | |
} |
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
{ | |
"name": "rt-webcam", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"express": "^4.13.3", | |
"opencv": "^3.2.0", | |
"socket.io": "^1.3.7" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment