Thursday, 15 March 2012

javascript - using cv.readImage() with stream in nodejs -



javascript - using cv.readImage() with stream in nodejs -

im trying build https://github.com/xenomuta/caraweb facedetection opencv , nodejs.

im using ubuntu , im able stream pictures webcam.

so .js webcam

var socket = io.connect(); var fps = 30; socket.on('connect', function () { $('.serverstatus').text('connected') }); socket.on('connecting', function () { $('.serverstatus').text('connecting') }); socket.on('disconnect', function () { $('.serverstatus').text('disconnected') }); var declinedcam = function(e) { alert('you have enable webcam'); }; window.url = window.url || window.webkiturl; navigator.getusermedia = (navigator.getusermedia || navigator.webkitgetusermedia || navigator.mozgetusermedia || navigator.msgetusermedia); var video = document.queryselector('video'); if (navigator.getusermedia) { navigator.getusermedia({video: true}, function(stream) { video.src = window.url.createobjecturl(stream); }, declinedcam); } else { alert('your browser not back upwards webcamcontrol'); } video.addeventlistener('play', function(e) { var canvas = document.getelementbyid('frontendcanvas'); var gobyscale = (video.videoheight >= video.videowidth) ? 'height':'width'; var scale = (300/ video['video'+gobyscale]); canvas.width = video.videowidth * scale; canvas.style.width = canvas.width + 'px'; canvas.height = video.videoheight * scale; canvas.style.height = canvas.height + 'px'; var ctx = canvas.getcontext('2d'); setinterval(function() { if(video.paused !== true){ ctx.drawimage(video, 0, 0, video.videowidth*scale, video.videoheight*scale); socket.emit('videostream', canvas.todataurl('image/webp')); } }, 1000 / fps) }, false);

and app.js

var express = require('express.io'); var app = express(); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); var cookieparser = require('cookie-parser'); var bodyparser = require('body-parser'); var routes = require('./routes/index'); var backend = require('./routes/backend'); var cv = require('opencv'); var fs = require('fs'); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); // connection setup app.http().io(); app.io.sockets.on('connection', function(socket) { socket.on('videostream', function(data) { socket.broadcast.emit('sendvideo', data); var buffer = new buffer(data, 'base64'); }); })

when im trying observe face in picture, im using this:

cv.readimage("/picture.png", function(err, im){});

but how can utilize info webcamstream observe people in front end of cam? give thanks you!

javascript node.js opencv stream webcam

No comments:

Post a Comment