hiukim / mind-ar-js

Web Augmented Reality. Image Tracking, Face Tracking. Tensorflow.js
MIT License
2.13k stars 394 forks source link

Issue with `targetFound` event in mindAR #469

Closed ToorDev closed 7 months ago

ToorDev commented 7 months ago

Hello,

I am trying to use mindAR for a WebAR project and I am encountering an issue with the targetFoundevent.

Here is the code I am using:

//JavaScript

mainElement.addEventListener("targetFound", (event) => {
  console.log("target found");
  console.log(event.detail);
});

When this event is triggered, event.detail is always null. I have tried using exactly the same code as provided in the mindAR documentation, but the issue persists.

I am using the following versions of the libraries:

A-Frame: 1.4.2 mindAR: 1.2.2 Can you help me resolve this issue? Thank you in advance for your assistance.

Best regards

BostonLeeK commented 7 months ago

check event.target

BostonLeeK commented 7 months ago

@ToorDev if it helps, close please issue

ToorDev commented 7 months ago

Thank you for your quick response @BostonLeeK. I tried using event.target, but it doesn't seem to solve my issue. event.target returns the HTML code of the <a-entity> element, which doesn't allow me to retrieve the ID of the detected target image.

What I'm trying to do is retrieve the ID of the detected target image when the targetFound event is triggered. I need this ID to retrieve specific elements from an array based on the detected image.

Here is the code I'm currently using:

mainElement.addEventListener("targetFound", (event) => {
  console.log("target found");
  console.log(event.detail);
});

When this event is triggered, event.detail is always null. I would like to know how I can get the ID of the detected target image from this event.

Thank you in advance for your help.

BostonLeeK commented 7 months ago

@ToorDev like I know there is no i'd on marker, there is targetIndex (or something like that). You can select it by just event.target.targetIndex and it will give you index. event.target return not HTML but DOM element so you can check what params was assign and select it.

ToorDev commented 7 months ago

Thank you for your suggestion. However, I’m still receiving ‘undefined’ as a response. My issue seems to be quite specific and, as I’m not very proficient in JavaScript, I’m going to close this issue and try a different approach. Thanks anyway to @BostonLeeK for your help.