Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.02k stars 1.12k forks source link

How do I keep prefab in the correct position even when image tracked is not visible. #948

Closed ABHIJEET-SRIDHAR-M closed 2 years ago

ABHIJEET-SRIDHAR-M commented 2 years ago

Hi, I have a big prefab, like a life size chess board, and I have rendered it using image tracking to get the position of the first square. Since my prefab is huge, and the image only covers the first square, the tracking is very unstable when I try to move around the board, especially when the image is not visible (which it won't be in most cases because I want to move around the chess board to different squares). For some time, the prefab stays in place, but after moving to a bunch of squares, the prefab just moves slightly from its original position, and that messes up the whole board because it's offset now.

I have tried using anchor but that didn't seem to improve the situation much. I was wondering how could I enhance the stability and tracking. Would simply adding plane tracking component help this, or should I somehow consider using 2 images, one in the starting square and one in middle so that whichever image is visible, the tracking could be improved using that image.

Edit: Here is an example of the prefab. Only the first square is recognized through image tracking. So, when i scan the image, the prefab gets instantiated correctly. But when I move to other squares, like top right, the whole position of the prefab changes because the image is left behind.

image

todds-unity commented 2 years ago

What is the condition of the environment in which you are tracking?

High gloss surfaces, reflective surfaces, low detail (or smooth) surfaces, and bad lighting are common causes to bad AR tracking.

ABHIJEET-SRIDHAR-M commented 2 years ago

What is the condition of the environment in which you are tracking?

High gloss surfaces, reflective surfaces, low detail (or smooth) surfaces, and bad lighting are common causes to bad AR tracking.

Hey, this is the type of surface I'm using- a bunch of mats on the floor. Colored black and white. 20211118_162150

It's like by the time i reach the top mats, either the whole prefab is shifted or the offset is so much that they don't appear on the mat at all. Recently, i tried printing out the tracking state and as expected, it is limited as soon as the image leaves the camera view.

tdmowrer commented 2 years ago

Just a thought: make sure you've specified the physical dimensions as accurately as possible.

The way ARCore and ARKit seem to work is to move the reported transform farther or closer to the camera so that it will have the correct apparent screen space position and orientation. For example, if you tell it your image is 10 meters across, it will just move your prefab back until it matches the apparent size of the image marker (which may only be 10 cm across). You wouldn't notice anything was wrong until it stops tracking the image (because it goes out of view). If, however, the physical dimensions exactly match the real image, then it should put it in the right place in the world.

That's just my guess, but it seems to fit the scenario you described.

ABHIJEET-SRIDHAR-M commented 2 years ago

Just a thought: make sure you've specific the physical dimensions as accurately as possible.

The way ARCore and ARKit seem to work is to move the reported transform farther or closer to the camera so that it will have the correct apparent screen space position and orientation. For example, if you tell it your image is 10 meters across, it will just move your prefab back until it matches the apparent size of the image marker (which may only be 10 cm across). You wouldn't notice anything was wrong until it stops tracking the image (because it goes out of view). If, however, the physical dimensions exactly match the real image, then it should put it in the right place in the world.

That's just my guess, but it seems to fit the scenario you described.

Hey, I have set the physical size, but not that accurately... My image is a qr code around 18 cm X 18 cm. I will get the exact dimensions and try it out... Just to test more, should I consider the whole mat bunch to be the image instead of one qr code at the starting mat.

I noticed that my camera tried to focus and refocus which sometimes leads to wrong positions and scales. Maybe disabling this auto focus might improve the tracking as well.

tdmowrer commented 2 years ago

should I consider the whole mat bunch to be the image instead of one qr code at the starting mat.

You should consider your image to be the image :)

So if the image you provide to AR Foundation is a QR code, use the QR code's dimensions. Be careful to include only the size of the QR code and not, e.g., the larger paper you might print it out on.