Mindar.JS——实现AR图像追踪插入图片或视频

news2024/9/22 4:04:06

Mindar.JS使用方式

在这里插入图片描述

注意:此篇文章需要启动https才可调用相机权限

图像追踪示例

  1. 需要用到两个js库
    <script src="./js/aframe.min.js"></script>
    <script src="./js/mindar-image-aframe.prod.js"></script>
  1. 下面看一下标签结构

这里是默认配置

    document.addEventListener("DOMContentLoaded", function () {
      const sceneEl = document.querySelector('a-scene');
      let arSystem;
      sceneEl.addEventListener('loaded', function () {
        // alert('执行')
        arSystem = sceneEl.systems["mindar-image-system"];

      });
      const startButton = document.querySelector("#example-start-button");
      startButton.addEventListener('click', () => {
        console.log("start");
        arSystem.start(); // start AR 
        arSystem.pause(true);
      });
      sceneEl.addEventListener("arReady", (event) => {
        alert('AR引擎已启动')
      });
      sceneEl.addEventListener("arError", (event) => {
        alert('相机未启动成功!')
      });
    });

上面图片提到需要一个Mind文件,这个文件就是图像识别的图片,工具在这里图像目标编辑器

图像目标编辑器

在这里插入图片描述
在这里插入图片描述
如果是图片识别显示图片的话就很简单了

关于渲染视频

如果我想扫描图片展示视频该如何去操作呢?
我这里加了两张png图片用来做暂停按钮
请添加图片描述

请添加图片描述
我这里按顺序称谓opc.png背景2.png按钮
当我们点击背景时让视频暂停,并让按钮层级往内移动 或者 让按钮隐藏
再次点击背景让视频播放,让按钮显示

const portfolio = document.querySelector("#portfolio-panel");
    const paintandquestPreviewButton = document.querySelector("#paintandquest-preview-button");
    const paintandquestPreviewButton2 = document.querySelector("#paintandquest-preview-button2");
    portfolio.setAttribute("visible", true);
    let y = 0;
    let status = false;
    paintandquestPreviewButton.addEventListener('click', () => {
      if (status == false) {
        // paintandquestPreviewButton.setAttribute("visible", false);
        const testVideo = document.createElement("video");
        const canplayWebm = testVideo.canPlayType('video/webm; codecs="vp8, vorbis"');
        if (canplayWebm == "") {
          document.querySelector("#paintandquest-video-link").setAttribute("src", "#paintandquest-video-mp4");
          document.querySelector("#paintandquest-video-mp4").play();
        } else {
          paintandquestPreviewButton2.setAttribute("visible", false);
          document.querySelector("#paintandquest-video-link").setAttribute("src", "#paintandquest-video-mp4");
          document.querySelector("#paintandquest-video-mp4").play();
          // alert('播放')
          status = true
        }
      } else {
        paintandquestPreviewButton2.setAttribute("visible", true);
        // alert('暂停')
        // portfolio.setAttribute("visible", true);
        document.querySelector("#paintandquest-video-mp4").pause();

        status = false;
      }
    });
    portfolio.setAttribute("position", "0 " + y + " -0.01");

完整代码:

<!--
 * @Description: 
 * @Autor: Southern Wind
 * @Date: 2023-07-25 11:21:40
 * @LastEditors: Southern Wind
 * @LastEditTime: 2023-07-25 12:00:42
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>AR相机</title>
  <script src="./js/aframe.min.js"></script>
  <script src="./js/mindar-image-aframe.prod.js"></script>

  <script src="./js/vconsole.min.js"></script>
</head>

<body>
  <div style="position: absolute; z-index: 1000">
    <button id="example-start-button">重新加载</button>
  </div>
  <a-scene mindar-image="imageTargetSrc: ./targets.mind;" vr-mode-ui="enabled: false" device-orientation-permission-ui="enabled: false">
    <a-assets>
      <img id="paintandquest-preview" src="./images/opc.png" />
      <img id="paintandquest-preview2" src="./images/2.png" />
      <video id="paintandquest-video-mp4" autoplay="false" loop="true" src="./1234.mp4" playsinline webkit-playsinline></video>

    </a-assets>

    <a-camera position="0 0 0" look-controls="enabled:  false" cursor="fuse: false; rayOrigin: mouse;" raycaster="far: 10000; objects: .clickable"></a-camera>
    <a-entity mindar-image-target="targetIndex: 0" mytarget>
      <a-entity visible=false id="portfolio-panel" position="0 0 -0.01">
        <a-image id="paintandquest-preview-button" class="clickable" src="#paintandquest-preview" alpha-test="0.5" position="0 0 0.1" height="0.552" width="1">
        </a-image>
        <a-image id="paintandquest-preview-button2" class="clickable" src="#paintandquest-preview2" alpha-test="0.5" position="0 0 0.05" height="0.552" width="1">
        </a-image>
        <a-video id="paintandquest-video-link" webkit-playsinline playsinline width="1" height="0.552" position="0 0 0"></a-video>
      </a-entity>
    </a-entity>
  </a-scene>
  <script>
    const vConsole = new VConsole()
    console.log(vConsole);
  </script>
  <script>
    const portfolio = document.querySelector("#portfolio-panel");
    const paintandquestPreviewButton = document.querySelector("#paintandquest-preview-button");
    const paintandquestPreviewButton2 = document.querySelector("#paintandquest-preview-button2");
    portfolio.setAttribute("visible", true);
    let y = 0;
    let status = false;


    paintandquestPreviewButton.addEventListener('click', () => {
      if (status == false) {
        // paintandquestPreviewButton.setAttribute("visible", false);
        const testVideo = document.createElement("video");
        const canplayWebm = testVideo.canPlayType('video/webm; codecs="vp8, vorbis"');
        if (canplayWebm == "") {
          document.querySelector("#paintandquest-video-link").setAttribute("src", "#paintandquest-video-mp4");
          document.querySelector("#paintandquest-video-mp4").play();
        } else {
          paintandquestPreviewButton2.setAttribute("visible", false);
          document.querySelector("#paintandquest-video-link").setAttribute("src", "#paintandquest-video-mp4");
          document.querySelector("#paintandquest-video-mp4").play();
          // alert('播放')
          status = true

        }
      } else {
        paintandquestPreviewButton2.setAttribute("visible", true);
        // alert('暂停')
        // portfolio.setAttribute("visible", true);
        document.querySelector("#paintandquest-video-mp4").pause();

        status = false;
      }

    });
    portfolio.setAttribute("position", "0 " + y + " -0.01");


    document.addEventListener("DOMContentLoaded", function () {
      const sceneEl = document.querySelector('a-scene');
      let arSystem;
      sceneEl.addEventListener('loaded', function () {
        // alert('执行')
        arSystem = sceneEl.systems["mindar-image-system"];

      });
      const startButton = document.querySelector("#example-start-button");
      startButton.addEventListener('click', () => {
        console.log("start");
        arSystem.start(); // start AR 
        arSystem.pause(true);
      });
      sceneEl.addEventListener("arReady", (event) => {
        alert('AR引擎已启动')
      });
      sceneEl.addEventListener("arError", (event) => {
        alert('相机未启动成功!')
      });
    });
  </script>

</body>

</html>

gitee地址
实际效果:

手机端ar图像测试

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/802163.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

一款性价比高的知识管理系统应具备的功能

编者按&#xff1a;市面上的知识管理系统有不同的类型&#xff0c;有针对文件管理的&#xff0c;也有针对内容管理的&#xff0c;各有长处&#xff0c;那么一款好用的KMS大概都具备哪些优点呢&#xff1f; 关键词&#xff1a;知识管理系统、免运维/安装、 随着企业对企业隐形知…

PyCharm解决Git冲突

什么时候会出现冲突 当我们从远程的仓库pull下来的时候&#xff0c;如果远程仓库跟本地仓库修改了同一个文件&#xff0c;在pull的过程中就会提示合并冲突&#xff1a; $ git pull remote developremote: Enumerating objects: 27, done.remote: Counting objects: 100% (27/2…

Postgres日期格式化

1、替换dual的方法 oracle: select ‘111’ phone from dual; Postgres: select ‘111’ phone ; 2、char类型格式化成日期 to_date(‘20230728’,‘yyyyMMdd’) 3、两个日期取相差的天数&#xff08;非绝对值&#xff0c;带正负号&#xff09; extract(day from now()-to_date…

git的clone,上传,mirror与upstream同步

文章目录 clone日志信息的同步子树合并同步 clone clone他人项目&#xff0c;git到自己的项目 rm -rf .git .git存放原始项目的日志信息&#xff0c;这里需要添加自己的日志信息&#xff0c;需要删除重写。也可手动删除 git init 初始化文件&#xff0c;依据本地日志信息生产.…

在CentOS 7上挂载硬盘到系统的步骤及操作

目录 1&#xff1a;查询未挂载硬盘2&#xff1a;创建挂载目录3&#xff1a;检查磁盘是否被分区4&#xff1a;格式化硬盘5&#xff1a;挂载目录6&#xff1a;检查挂载状态7&#xff1a;设置开机自动挂载总结&#xff1a; 本文介绍了在CentOS 7上挂载硬盘到系统的详细步骤。通过确…

信息安全:物理与环境安全技术.

信息安全&#xff1a;物理与环境安全技术. 传统上的物理安全也称为 实体安全 &#xff0c;是指包括 环境、设备和记录介质在内的所有支持网络信息系统运行的硬件的总体安全&#xff0c;是网络信息系统安全、可靠、不间断运行的基本保证&#xff0c;并且确保在信息进行加工处理、…

企业电子招投标采购系统源码之-java spring cloud+spring boot

​ 信息数智化招采系统 服务框架&#xff1a;Spring Cloud、Spring Boot2、Mybatis、OAuth2、Security 前端架构&#xff1a;VUE、Uniapp、Layui、Bootstrap、H5、CSS3 涉及技术&#xff1a;Eureka、Config、Zuul、OAuth2、Security、OSS、Turbine、Zipkin、Feign、Monitor、…

LC-2050. 并行课程 III(小根堆 + 拓扑排序)

2050. 并行课程 III 难度困难42 给你一个整数 n &#xff0c;表示有 n 节课&#xff0c;课程编号从 1 到 n 。同时给你一个二维整数数组 relations &#xff0c;其中 relations[j] [prevCoursej, nextCoursej] &#xff0c;表示课程 prevCoursej 必须在课程 nextCoursej 之前…

TBOX相关芯片学习

芯片学习 ESIM–嵌入式SIM卡 ESIM将SIM卡直接嵌入到目标设备芯片&#xff0c;而不是作为独立的可移除文件 功能架构&#xff1a; SM-SR:签约管理安全路由服务器&#xff0c;主要功能是实现eUICC远程配置数据的安全路由和传输 SM-DP:签约管理数据准备服务器&#xff0c;主要功…

【产品经理】高阶产品如何处理需求?(3方法论+2案例+1清单)

不管你是萌新小白&#xff0c;还是工作了几年的“老油条”&#xff0c;需求一直是产品经理工作的重点。只不过&#xff0c;不同年限的产品经理需要面对的需求大有不同&#xff0c;对能力的要求更高。 不知你是否遇过以下问题&#xff1f; 你接手一个项目后&#xff0c;不知从何…

SDN系统方法 | 8. 网络虚拟化

随着互联网和数据中心流量的爆炸式增长&#xff0c;SDN已经逐步取代静态路由交换设备成为构建网络的主流方式&#xff0c;本系列是免费电子书《Software-Defined Networks: A Systems Approach》的中文版&#xff0c;完整介绍了SDN的概念、原理、架构和实现方式。原文: Softwar…

【软件测试】如何设计测试用例?

文章目录 1.设计测试用例的万能公式2.测试用例的具体设计方法2.1 等价类2.2 边界值2.3 判定表(因果图)2.4 场景设计法2.5 正交法2.6 错误猜测法 3.总结 1.设计测试用例的万能公式 设计测试用例的万能公式: 功能测试性能测试界面测试兼容性测试易用性测试安全测试 功能测试:验证…

ORB-SLAM3 数据集配置与评价

ORB-SLAM3运行EuRoC和TUM-VI数据集。EuRoC利用微型飞行器(MAV ) 收集的视觉惯性数据集&#xff0c;TUM-VI 是由实验人员手持视觉-惯性传感器收集的数据集。这两个是在视觉SLAM中比较常用的数据集&#xff0c;所以测试并加以记录。 文章目录 一、EuRoC数据集测试1、官网下载2、…

AtcoderABC230场

A - AtCoder Quiz 3A - AtCoder Quiz 3 题目大意 给定一个整数N&#xff0c;以AGCXXX的格式打印第N次AGC的名称&#xff0c;其中XXX是以零填充的3位数字。 思路分析 根据题目要求&#xff0c;当N≥42时&#xff0c;输出AGC加上N1&#xff0c;并补齐为3位数字的格式&#xff…

作为一名程序员,IVX你值得拥有

目录 一、IVX是什么 二、IVX编程盒子——低代码平台的首个硬件产品 iVX做硬件的原因 iVX自身特点——安全、方便、高效、低耗 三、IVX编程盒子自带的Demo系统 1. 问题反馈、在线沟通和工单处理系统 2. 大屏幕监管平台 四、IVX和其他代码平台的区别 五、低代码未来的发展…

企业知识文档管理+群晖nas安全云存储

企业知识管理系统&#xff0c;利用软件系统或其他工具的企业管理方法&#xff0c;利用软件系统或其他工具&#xff0c;对组织中大量的有价值的方案、策划、成果、经验等知识进行分类存储和管理&#xff0c;积累知识资产避免流失&#xff0c;促进知识的学习、共享、培训、再利用…

配对卡方分析

一、案例介绍 某医院用两种不同方法对53例肺癌患者进行诊断&#xff0c;收集到结果如下表&#xff0c;现在想知道两种方法的检测结果有无差别。 二、问题分析 本案例分析的目的是比较两种方法对同一批样本的检测结果有无差别&#xff0c;且检测结果为二分类变量&#xff08;阳…

确保API安全的5个推荐措施

如今社会随着互联网应用领域愈发宽广&#xff0c;我们对应用程序编程接口 (API) 的依赖也越来越巨大。因为当我们开发应用程序时&#xff0c;API可以无缝、流畅且无形地在幕后完成各种任务&#xff0c;比如从您自己的应用程序时向另一个应用程序中提取您请求的数据。它们是我们…

问题记录::

一、编码器报7382错误&#xff01;&#xff01;&#xff01; 注&#xff1a;不是机器有问题&#xff0c;是默认参数中的编码器复位是没有使能的&#xff01;&#xff01;&#xff01; 解决步骤&#xff1a;1、打开科伺驱动软件&#xff1b;一级登录&#xff1b;连接驱动&…