How to save 3D coordinate (long/alt/height) corresponding to each pixel in an image?

Hello everyone.

1. A concise explanation of the problem you’re experiencing.

The aim is to save the longitude, altitude and height information for each pixel in any camera view. A highly similar method can be found in https://github.com/CesiumGS/cesium/issues/4368.

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

quick SandCastle testbed (shared by another enthusiastic Cesium user). This code allows to obtain 3D coordinate for the pixel which the mouse points to. I was wondering if there is any way to save such pixel-wise 3D coordinate for all the pixels in the image.

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

We are doing a camera localization project, which requires labelled images to construct 2D-3D correspondence. (x,y pixel <—> longtitude, altitude, height coordinates)

4. The Cesium version you’re using, your operating system and browser.

To combine this feature in our feature rendering code, we would use the latest Cesium version I suppose. At this moment, we have digital terrain models + high-quality ortho-photos.

OS: linux ubuntu 18

browser: firefox

Thanks!

Qi YAN

You can programmatically call pickPosition on any location, not just the mouse position. So you could get your polygon coordinates in world space, and then iterate over that space at some granularity and obtain all those positions.

This sounds like a cool project - will it be publicly available?

Thanks so much for your message. I had another question about the following code to generate the coordinates automatically:

var stringCart = "[";

for(var ii=0;ii<viewer.canvas.width;ii++){

for(var jj=0;jj<viewer.canvas.height;jj++){

var cur_pos = new Cesium.Cartesian2(ii, jj);

var ppCartesian = viewer.scene.pickPosition(cur_pos);

var ppCartographic = Cesium.Cartographic.fromCartesian(ppCartesian);

var s = Cesium.Math.toDegrees(ppCartographic.latitude).toFixed(4);

stringCart += “(” + s.toString() + “,”;

s = Cesium.Math.toDegrees(ppCartographic.longitude).toFixed(4);

stringCart += s.toString() + “,”;

s = ppCartographic.height.toFixed(0);

stringCart += s.toString() + “),”;

stringCart += “,test,”

}

}

stringCart += “]”;

downloadText(stringCart, “Coor.txt”);

It doesn’t work and in my test the problem is related to “Cesium.Cartographic.fromCartesian”. I checked the documentation and still could not solve the problem. BTW, Cesium 1.63 is used at the moment.

We are still working on this project and once we have some nice results, the proejct would be made public I suppose. :slight_smile: