Jul 182010

Perspective Transform from Map Data to Road Image

Transforming a flat map into what the road image looks like is done by squishing the top of the image down and stretching the bottom two points outward. As in any other image, this changes the perceived perspective to be similar to our own. Some issues in making the transformed image match the road image are as follows. The ending height of the transformed image is dependent on the visible horizon. So if the visible horizon is very high in the image then, of course, the squished/transformed image must match this height. Another issue with height is the distance that the viewer can see. If the viewer can see a mile into the distance, then the before-transformed map image should be squished starting at a point higher on the map (i.e. a mile up), so that the correct road data will correspond to the visible road (i.e. so the length of the visible road will match the length of the map data that is overlaid on top of it). So there are at least two things we must know to transform the flat map image correctly to correspond to the perspective view of the road: the height of the horizon and the distance to the horizon. Unfortunately these things aren’t easily available. I think that people will rarely be able to see a mile in front of them while driving however, unless they live in the middle of a particular “nowhere” which happens to be flat, like Kansas or Nevada. In most situations the distance to the horizon is probably significantly limited by buildings, turns, etc.

Perspective Transform in Java

Doing a perspective transformation on a set of lines seems to be simple. However, there are some issues applying it to the road lines. When lines are drawn too far off screen the transformation doesn’t work correctly. Since the road lines drawn currently includes many off-screen lines, it’s not working… It may seem like it’s only necessary to figure out which lines actually need to be drawn and which don’t before doing the transformation. This is easier said than done though, when considering lines where neither point is visible, but the line crosses through a visible area. Also, this probably won’t work since some lines may be extremely long and still pass through the visible area (and still cause the error since they’re so long). So in reality it may be necessary to find only the points on each line which cross through the visible area, thus minimizing the length of the line and cutting off any part of the line not within the visible area, and then applying the transformation after all that is done.

 Posted by at 8:42 pm