app.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // 别间隔时间(毫秒), 识别服务地址, 认证token
  2. const webAR = new WebAR(1000, 'https://cn1-crs.easyar.com:8443/search', 'I63ooxI48OcR9MseGyf9F3UpVoa4Seio4CtCM1k2kHD59TngdniDdS2FXAx3UWlStF+eUKVvoEJWuU2+bGgpcQ==');
  3. // 列出并打开设备上的摄像头
  4. document.querySelector('#openCamera').addEventListener('click', function () {
  5. const videoSelect = document.querySelector('#videoDevice');
  6. webAR.listCamera(videoSelect)
  7. .then(msg => {
  8. // 隐藏"打开摄像头"按钮
  9. this.style.display = 'none';
  10. videoSelect.style.display = 'inline-block';
  11. document.querySelector('#start').style.display = 'inline-block';
  12. document.querySelector('#stop').style.display = 'inline-block';
  13. videoSelect.onchange = () => {
  14. webAR.openCamera(JSON.parse(videoSelect.value));
  15. };
  16. // 打开摄像头
  17. // 打开后置摄像头参数: {audio: false, video: {facingMode: {exact: 'environment'}}}
  18. webAR.openCamera(JSON.parse(videoSelect.value))
  19. .then(msg => {
  20. console.info(msg);
  21. }).catch(err => {
  22. console.info(err);
  23. });
  24. })
  25. .catch(err => {
  26. // 没有找到摄像头
  27. console.info(err);
  28. });
  29. });
  30. // 开启识别
  31. document.querySelector('#start').addEventListener('click', () => {
  32. webAR.startRecognize((msg) => {
  33. console.info(msg);
  34. // 可以将 setting 作为meta上传到EasyAR的云识别,使用方法如下
  35. // const setting = JSON.parse(window.atob(msg.target.meta));
  36. const setting = {
  37. video: '//staticfile-cdn.sightp.com/sightp/webar/webardemo-final.mp4',
  38. };
  39. const video = document.createElement('video');
  40. video.setAttribute('controls', 'controls');
  41. video.setAttribute('playsinline', 'playsinline');
  42. video.setAttribute('style', 'position:absolute;top:0;left:0;width:100%;height:100%;z-index:99');
  43. document.body.appendChild(video);
  44. video.src = setting.video;
  45. video.play();
  46. });
  47. }, false);
  48. // 暂停识别
  49. document.querySelector('#stop').addEventListener('click', () => {
  50. webAR.stopRecognize();
  51. }, false);
  52. //# sourceMappingURL=app.js.map