Use camera as background, while display objects in A-frame

断了今生、忘了曾经 提交于 2020-01-16 18:54:35

问题


I want to use camera video feed as background in a-frame, while overlaying objects on it. I know it is possible but I don't know how exactly to do it. so I am here to ask for help!


回答1:


You can have a simple overlay by adding an element before the scene:

<img src='overlay.jpg' />
<a-scene></a-scene>

fiddle here.


Here is a nice article about using a camera stream, I'll just use a basic version of it:

html

<video autoplay></video>
<a-scene></a-scene>

js

// grab the video element
const video = document.querySelector('video');
// this object needs to be an argument of getUserMedia
const constraints = {
   video: true
};
// when you grab the stream - display it on the <video> element
navigator.mediaDevices.getUserMedia(constraints).
    then((stream) => {video.srcObject = stream});

Fiddle here.



来源:https://stackoverflow.com/questions/57122974/use-camera-as-background-while-display-objects-in-a-frame

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