How can i use chrome webcam API and the processing.js to manipulate the video?

一笑奈何 提交于 2019-12-08 11:48:14

问题


As topic, I want to play with the webcam and chrome webcam API comes in handy, no plugin is needed.

However, I am not familiar with javascript syntax, so I still want to use processing.js to manipulate the video. So how should the code be like?

GetUserMedia in the canvas,then? How can i tell the processing.js that there is a video in the canvas?

import processing.video should not work because it is processing.js instead of processing.


回答1:


According to this: https://github.com/austinhappel/webcam-processingjs/blob/master/js/webcam-processing.js , you need to call the webcam's method, e.g.:

ctx.drawImage(myImg, imageOffset, 0, height / width * nb, nb);

from there on you can manipulate the pixels on the canvas manually

p.loadPixels();
imgPixelData = p.pixels.toArray();

They provide a WEBCAM class here that calls getUserMedia: https://github.com/austinhappel/webcam-processingjs/blob/master/js/webcam.js

Key lines are here:

if (navigator.getUserMedia) {
  navigator.getUserMedia({video: true}, function (stream) {
    self.video.src = stream;
    self.localMediaStream = stream;
  }, onWebcamFail);
} else if (navigator.webkitGetUserMedia) {
  navigator.webkitGetUserMedia({video: true}, function (stream) {
    self.video.src = window.webkitURL.createObjectURL(stream);
    self.localMediaStream = stream;
}, onWebcamFail);

Good luck! I've only done this in Java, so let us know if you get javascript and the webcam to play nice. I presume you need the newest build of chrome for any of this to work.



来源:https://stackoverflow.com/questions/12719294/how-can-i-use-chrome-webcam-api-and-the-processing-js-to-manipulate-the-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!