我正在使用2种自定义模式,并试图使AR.js识别它们。这两个标记都是我使用AR.js Marker Training制作为图案的6x6条形码,并将下载的图案放入文件夹中(分别为500.patt和600.patt)。如图所示,当我将其显示为单个标记时,将同时标识两个标记。
此外,当识别到标记时,我想做出反应(这就是控制台打印的原因),但是尽管绘制了两个标记的形状,但控制台中没有打印。
我的代码:
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ar.js</title>
</head>
<!-- include A-Frame obviously -->
<script src="https://aframe.io/releases/0.6.0/aframe.min.js"></script>
<!-- include ar.js for A-Frame -->
<script src="https://jeromeetienne.github.io/AR.js/aframe/build/aframe-ar.js"></script>
<body style='margin : 0px; overflow: hidden;'>
<a-scene embedded arjs="patternRatio: 0.90">
<!-- create your content here. just a box for now -->
<!-- define a camera which will move according to the marker position -->
<a-marker-camera type='pattern' url='500.patt'>
<a-box position='0 0.5 0' material='opacity: 0.5; color: red;'></a-box>
console.log(500);
</a-marker-camera>
<a-marker-camera type='pattern' url='600.patt'>
<a-sphere position='0 0.5 0' material='opacity: 0.5; color: blue;'></a-sphere>
console.log(600);
</a-marker-camera>
</a-scene>
</body>
</html>`
如何使模式识别仅显示一项并打印正确的模式?
谢谢
答案 0 :(得分:1)
在识别标记后如何将某些内容记录到控制台:
AFRAME.registerComponent('registerevents', {
init: function () {
var marker = this.el;
marker.addEventListener('markerFound', function() {
var markerId = marker.id;
console.log('! markerFound', markerId);
// do additional things you want to do
});
marker.addEventListener('markerLost', function() {
var markerId = marker.id;
console.log('! markerLost', markerId);
// do additional things you want to do
});
}
});
然后将registerevents
组件添加到标记中:
<a-marker id="marker" preset='hiro' registerevents>
应该这样做。