Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: IvanShubin on June 14, 2013, 01:14:10 PM
-
Help me. How to set the coordinates for a camera. I tried а script:
for cam in doc.activeChunk.cameras:
if cam.label == (geo_date[0]+".JPG"):
vec = PhotoScan.Vector()
vec.x = float(geo_date[1])
vec.y = float(geo_date[2])
vec.z = float(geo_date[3])
cam.center = vec
A consol showed me a error:
Traceback (most recent call last):
File "C:/dev/photoscan/load_photo.py", line 35, in <module>
cam.center = vec
AttributeError: attribute 'center' of 'PhotoScan.Camera' objects is not writable
-
Hello Ivan,
Do you need to input geographic coordinates for camera positions according to flight log?
For this task you should use chunk.ground_control.locations. The modified code should be something like the following:
for cam in doc.activeChunk.ground_control.locations.items():
if cam[0].label == (geo_date[0]+".JPG"):
cam[1].coord = ( float(geo_date[1]), float(geo_date[2]), float(geo_date[3]))
-
I would like to replace source coordinates with the estimated coordinates (after optimization) and replace source z values with 0.
My attempt to do this is below but not sure how to call estimated coordinates instead of the source coordinates (cam.coord[0] and cam.coord[1]):
for cam in doc.activeChunk.ground_control.locations.items():
cam[1].coord = (cam[1].coord[0],cam[1].coord[1],0)
cheers,
Javier
-
Hello Javier,
Estimated coordinates are not accessible easily, but you can recalculate them from camera coordinate system:
chunk = PhotoScan.app.document.activeChunk
camera = chunk.cameras[0]
vc = camera.center
vc.size = 4
vc.w = 1
vt = chunk.transform * vc
vt = chunk.projection.project(vt)
So in the vt vector you'll have estimated coordinates.
-
Hello. How to transform coordinates from the geocentric coordinates system to the chunk coordinates system?
-
Hello Ivan,
You should use chunk.crs.project(...) function to transform geocentric coordinates to chunk coordinate system (real-world).
In case you need to access internal chunk coordinates then you should use product of chunk.transform.inv() matrix and vector in geocentric coordinates (extended to four dimensions).
-
Hello,
What is the code for PS 1.1 to extract the estimated camera location?
vt = chunk.transform * vc doesn't seem to work!
Thank you
-
Hello Sebastien,
Please try the following one:
v_est = chunk.crs.project(chunk.transform.matrix.mulp(camera.center))
-
I tried
v_est = chunk.crs.project(chunk.transform.matrix.mulp(camera.center))
It does not work. May be because I don't have crs, I am working on local coodinates.
-
Then you can omit chunk.crs.project function.
-
Great! Thank you!