PDA

View Full Version : 3D projection of real world coordinates



Milo221
03-24-2009, 07:56 AM
I am trying to write a simple application which overlays on a photograph 'markers' which highlight certain features. For example, say you where standing on a hill and took a photograph of the skyline - I would like to "mark" points of interest such as buildings etc.

Therefore, I am not writing a 3D graphics application - i'm just trying to get a 3D projection of the landscape in the photograph to be able to accurately annotate it.

To achieve this I know i'll need this information (which I have access to):

Camera: GPS Coordinates, Elevation, Compass Bearing and Tilt (up and down)
Points of interest: GPS Coordinates, Elevation

I am able to work out elements such as distance (in metres) and the angle from the coordinates the photograph was taken to the coordinates of the point of interest I wish to "mark", so in theory I have all the information I need to accurately annotate the photograph.

However...

I have no idea how I go about using 3D projection, creating a model of the world and converting it to screen pixels using OpenGL. I posted a similar message on another forum, whose members suggested using OpenGL to "plug in" the real world x,y,z coordinates and allow OpenGL to return the x,y screen pixels.

So before I spend another day hunting around for a tutorial on how to do this could someone kindly point me in the right direction? Any help and advice which will help me understand this would be greatly appreciated.

Oh and I will need to use the OpenGL ES 1.0 specification to create this if that makes any difference.

Many thanks

zeoverlord
03-24-2009, 11:39 AM
If i get you right then all you have to do is match the projection matrix with the photograph and then just feed the actual rellative coordinates of the PoE trough the matrix.
Technically you won't need openGL for that.

Milo221
03-24-2009, 01:10 PM
Okay, I didnt really understand much of that, I really am a beginner when it comes to anything 3D. For example, what is the projection matrix and the PoE?

Will I have to calculate the distance to the horizon in the photograph to be able to plot accurately the 'relative coordinates' in the foreground?

If anyone has a good beginner tutorial to explain what I need to understand, or be willing to explain it - i'd be very greatful!

Thanks

ZbuffeR
03-24-2009, 01:47 PM
It is easier if you know about vector and matrix multiplications.
http://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection
http://en.wikipedia.org/wiki/3D_projection#Perspective_projection
http://www.opengl.org/resources/faq/technical/transformations.htm
http://www.opengl.org/documentation/spec...000000000000000 (http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node23.html#SECTION005100000000000000000) (and subsequent pages)
http://www.ugrad.cs.ubc.ca/~cs414/notes/ogl_vvol.html

Ilian Dinev
03-24-2009, 01:50 PM
Projection, simplified is:
ScreenX = ViewX / ViewZ
ScreenY = ViewY / ViewZ

ViewZ is almost "how far the object is from the camera"

So, if you know the X:Y coordinates of a dot on screen, and how far that dot actually is from the camera, you can roughly calculate ViewX and ViewY.

For in-depth correct info on projection transformations, see http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html
(you don't need to study the code there, just the description of how and why calculations are done)

Milo221
03-25-2009, 02:43 AM
Thanks for those links i'll try and decipher what I need to learn from them - its all proving a little confusing at present, however I shall persevere and try to undertand it.


Projection, simplified is:
ScreenX = ViewX / ViewZ
ScreenY = ViewY / ViewZ

ViewZ is almost "how far the object is from the camera"

So, if you know the X:Y coordinates of a dot on screen, and how far that dot actually is from the camera, you can roughly calculate ViewX and ViewY.



Ilian, the trouble is I do not know the X:Y coordinates of the dot on the screen where a point of interest i.e. a building is displayed - this is what I am trying to calculate. All I have is the x,y,z coordinates of the points of interest and the x,y,z coordinates, compass bearing and tilt of the camera. Note: the coordinates exist in the form of GPS coordinates (X:Y) and a elevation above sea level value (Z), I need to convert these into coordinates for a model...

What I need to learn is how to create a 3D model with this data and then calculate from the 3D model the X:Y coordinates on the screen where each point of interest is displayed. I.e. The pixel X=200, Y=124 on the screen is the location of the building.

Will I need OpenGL to be able to do this or is it a more straight forward problem?

Again, thanks for your time!

ZbuffeR
03-25-2009, 03:19 AM
No real need for opengl.

Mathematically speaking, it is just :
posXYZ * ModelViewMatrix * ProjectionMatrix = screenposXY

You know posXYZ, and want screenposXY.
You have to fill the ModelViewMatrix with correct values depending on the xyz+ bearing and tilt of camera.
You have to fill the ProjectionMatrix with values depending on the camera projection, such as horizontal and vertical field of view, and the scale you want to work with (max xy values at the edge of the photograph, whether center is at 0,0 or not, etc)

Milo221
03-25-2009, 06:28 AM
Thanks ZbuffeR,

Its getting more clear what I need to do now. I'll have to read up on ModelViewMatrix and ProjectionMatrix, then hopefully it'll be easier to understand what needs to be done.

Does anyone know of any good books/tutorial/sample code etc which may help? Currently I have no idea how to set scale i.e. meters between camera and points and setting angle/tilt of camera etc.

ZbuffeR
03-25-2009, 07:22 AM
The page given by Ilian is already very good, quite accessible yet complete.
Have a look at the matrices that are used under the hood for each of these transformations :
http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml
http://www.opengl.org/sdk/docs/man/xhtml/glTranslate.xml

If you feel really lost, you may find it easier to play with http://processing.org drawing colored triangle and doing transformations (there is a simple bridge to opengl), so that you see easily the results.
Try doing what you want with the basic rotate/translate + gluPerpective.

Scale : it is your choice
Angle/tilt of camera : use glRotate, one for each rotation axis
glRotatef(aroundz,0,0,1);
glRotatef(aroundx,1,0,0);
glRotatef(aroundy,0,1,0);

Milo221
03-25-2009, 08:17 AM
Brilliant, i'll have a look and no doubt post back here if I get into difficulties.

So from what your saying, I will need to use OpenGL, in part, to accomplish this task...

Thanks!

ZbuffeR
03-25-2009, 09:36 AM
Yes, but you have to understand, that GL is meant for graphics, not really to run precise calculations, even if it can be abused for that.

Milo221
03-30-2009, 01:53 PM
Okay, I have struggled with this and haven't got very far. I have realised that OpenGL is intended for projection graphical models in perspective rather than be using to calculate the figures i'm after. I'll have to try and find another solution to this problem.

Its a problem, that I cant find any good examples/tutorials or anything which describes what i'm trying to implement though.

eoywn
11-28-2011, 06:11 PM
Hi,

This is the first time I post here.

Currently I am doing a project using Windows Mobile to use the digital compass in i8000 to know the direction of the phone owner.

I am not sure if I can obtain the compass data.
Is it possible to call out the compass reading?

BionicBytes
11-29-2011, 03:12 AM
Dude, you have just hijacked someones thread!
That's not good form, you know!



I am not sure if I can obtain the compass data.
Is it possible to call out the compass reading?

What has this got to do with this topic, or even OpenGL ?

thokra
11-29-2011, 03:38 AM
[..] to know the direction of the phone owner.

I think he's connecting this to the forum topic.

Is this OpenGL related? No. It isn't. This board is neither about Windows Phone, nor about some compass app tailored to this particular platform. Ask the app vendor.