Search code examples
javaandroidimage-processingaugmented-reality

Augmented reality - Image size transform


I am currently working on an app that will display images on the camera view (basically an augmented reality), but are finding that the images don't appear "real". The reason for this is because the size of my images do not change the same way that things in real life do.

The data I have is: the image original size (height,width), image location (lat,long, alt), the phone location an therefor the distance between the phone and the image.

For example, let's say I placed an image in augmented reality at lat = 43, long = -70, alt = 0. If I started walking closer to this point with my phone, we should see the image getting larger as we get closer, but as of right now that increase in size is linear. However, as we started walking closer to the image in real life we would see it getting bigger according to a specific function.

Any ideas as to what that function might be?


Solution

  • Disclaimer: This is all in my opinion and I do not have exact functions.

    Step 1: The Viewport Assumption

    What you need to consider is a viewport. When walking, you have an area of vision. Let us simplify this scenario by considering that when looking, the average person does not use their peripheral vision (for simplicity, obviously this is not true in real life). Considering that when looking forward, you view 180 degrees - and without peripheral, let us assume that 45 degrees from both left and right are removed. This is going to present a viewport which is 90 degrees wide, at its base the viewer will look out at a right angle triangle 45 degrees to the left, and 45 degrees to the right. Please note that none of this is measured or purely scientific, but for making augmented-reality certain assumptions can make processing a lot easier.

    Step 2: The Benefit Of A Viewport

    Now, based on the previous definition of the viewport - consider what part of that view an object from a large distance will occupy. This can actually begin to generate real math :)! As you close in, the object will get bigger because it takes up a larger part of the view. The part of the view that the object takes up is going to a relation between the size of the object and the size of the view. In this case, the size of the view is the arclength of the viewport!

    Step 3: Some Math

    Let us make another assumption to simplify the process. Lets assume that instead of viewing the real arc, we view the hypotenuse of the viewport. When looking from a distance d, with a view of 90 degrees, the hypotenuse of the viewport will be

    hypotenuse = 2.83 * d
    //Note: 2.83 is approx. 2 * sqr. root of 2
    

    Step 4: Conclusions And Application

    So if you are standing 100 feet from an object, then your viewport is going to be 283 feet. If the object, such as the front of a car, takes up 6 feet, then that would be only 6/283 = 2% of the full view.

    However, if you are standing 50 feet from that same car, then the relation would be 6 / 141 = 4% of the full view.

    You can see that this is clearly a linear relationship. If you know what the size of the object is (lets call that s), then the percent of the view that should take would be

    view % = s / 2.83d
    

    Also what is shown here is that determining the size of the object is very important and could be hard to infer from just a single .jpg image. I could have a picture of a size 5 soccer ball which was 2500px by 2500px. Does that mean that it is huge? No, but it would look huge if the only assumption of its size was from the total pixel count. Along the same lines I could have a 100px by 100px picture of earth but I would hope that doesn't show up as tiny.

    Solving for the size of the object will yield results allowing for a user to approach an object in augmented reality. Knowing how to scale the image as a user approaches is rather trivial.