jeromeetienne / AR.js

Efficient Augmented Reality for the Web - 60fps on mobile!
MIT License
15.79k stars 2.22k forks source link

Custom Marker - ARToolkit wrong calculations (marker is gone) #375

Closed Ufosek closed 5 years ago

Ufosek commented 6 years ago

Hi! First of all - this is a really great project because in my opinion AR in mobile web browser gives a huge range of opportunities to create really engaging experience.

I was creating an AR project that showed some animation when you pointed at marker. Detection works well however sometimes our model (made in aframe) was just gone. I thought it may be because of temporary loosing marker but when I analyzed aframe-ar.js it appeared that sometimes it calculates totally wrong position of transform matrix (position). When I point at other place (tracking is gone) then usually it detects it again and start working.

In aframe-ar.js there is a function ARController.prototype.process. It uses artoolkit.detectMarker to detect marker. I was logging transform_mat which encapsulates position, rotation and scale after execution of this.transMatToGLMat(visible.matrix, this.transform_mat). When everything is ok it looks like this:

0.9953707456588745, 0.09607170522212982, -0.002796075539663434, 0,  0.08150871843099594, -0.8283565044403076, 0.5542392134666443, 0, 0.05093061923980713, -0.5519015789031982, -0.8323522806167603, 0, 0.2277069240808487, 0.11962230503559113, 6.253724575042725, 1

However sometimes something strange appears in 12,13 and 14 indexes:

-0.9881125688552856, 0.06839525699615479, 0.13767963647842407, 0, -0.0630795881152153, -0.9970983266830444, 0.042613908648490906, 0, 0.14019463956356049, 0.03342254087328911,  0.9895596504211426, 0, -917.4149169921875. -1586.331787109375, 6029.3037109375, 1

As far as I am concerned these values are responsible for translation. So "system" detects markers, tracks properly, however with those wrong calculations it positions my model somewhere totally far far away from desired location.

I am not sure where and what is wrong but probably something in ArToolkit (which is compiled to JS so I cannot analyze it here) - maybe in artoolkit.detectMarker function.

This error is easy to detect (just check 12,13 or 14 value and if it exceeds normal values (like 100) - we got error) however I have no idea how to solve it. I tried "hot-fix" by reseting tracking but I could not find a way to do this and now I just prompt user a message that we has to move his phone which is very poor solution.

Anyone has any idea what may be wrong?

aframe code:

 <a-scene embedded arjs='sourceType: webcam; detectionMode: mono; debugUIEnabled: false; isMobile: true;'>
     <a-marker-camera id='mainMarker' preset='custom' type='pattern' url='img/pattern-marker2.patt'>
         <a-plane id="animPlane" position="-0.5 0 -2.1" rotation="270 0 0" width="3" height="6" material='opacity: 0.9;'></a-plane>
     </a-marker-camera>
</a-scene>

I attach marker image. You can create pattern (here: https://jeromeetienne.github.io/AR.js/three.js/examples/marker-training/examples/generator.html) by uploading this and setting ratio to 0.58.

logo

Thanks in advance!

ThorstenBux commented 6 years ago

Are you using a camera calibration file? Can you provide steps to reproduce?

Ufosek commented 6 years ago

@ThorstenBux I am using aframe-ar from https://cdn.rawgit.com/jeromeetienne/AR.js/1.5.0/aframe/build/aframe-ar.js and I guess camera calibration is done there.

ThorstenBux commented 6 years ago

Well, if you guess you don't know. I don't know about aframe-ar so I can't say. The provided link isn't working for me.

Ufosek commented 6 years ago

@ThorstenBux This is almost the same code as in https://github.com/jeromeetienne/AR.js/blob/master/README.md#augmented-reality-for-the-web-in-less-than-10-lines-of-html

It uses camera_para.dat file from: cameraParametersUrl: ARjs.Context.baseURL + 'parameters/camera_para.dat',

ThorstenBux commented 6 years ago

Also, link not working :). Anyways, that is most likely using a default calibration with would be an identity matrix. What kind of camera are you using?

Ufosek commented 6 years ago

@ThorstenBux I formated links not properly - it will be working now. I have tested in on iPhone6/7/8/X. It may be something with camera calibration however with test marker (with the same default calib) there are no such exceptions, thats what I guess it may be specific to this marker.

ThorstenBux commented 6 years ago

You could try this marker with a bigger boarder as a test but I don't see anything too specific with this marker

Udanita commented 6 years ago

The project is really amazing but it will be the greatest if is possible to allow the recognization with the opencv.js templatematching. I would love to be able to do but i'm not. Do you think is possible to modify the code using that matchtemplate from opencv? It will give the possibility to use every jpg image so the project will dominate the AR worldwide

spartalisdigital commented 6 years ago

Gostaria muito de usar o opencv.js para rastreamento de posição. Alguém gostaria de dar continuidade a isso?

nicolocarpignoli commented 5 years ago

This PR has been closed due to inactivity. Please open a new, updated issue if the problem or the question is still relevant.

Hrishikesh2900 commented 4 years ago

I created a Custom Marker in Artoolkit through the reference of this website: https://atechdaily.com/posts/Create-Custom-Marker-in-Artoolkit