Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: IvanShubin on June 14, 2013, 01:14:10 PM

Title: Edit Camera.center coords
Post 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
Title: Re: Edit Camera.center coords
Post by: Alexey Pasumansky on June 14, 2013, 01:41:28 PM
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:

Code: [Select]
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]))
Title: Re: Edit Camera.center coords
Post by: xabierr on July 15, 2013, 08:08:20 AM
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
Title: Re: Edit Camera.center coords
Post by: Alexey Pasumansky on July 15, 2013, 03:00:46 PM
Hello Javier,

Estimated coordinates are not accessible easily, but you can recalculate them from camera coordinate system:

Code: [Select]
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.
Title: Re: Edit Camera.center coords
Post by: IvanShubin on September 03, 2013, 08:36:33 AM
Hello. How to transform coordinates from the geocentric coordinates system to the chunk coordinates system?
Title: Re: Edit Camera.center coords
Post by: Alexey Pasumansky on September 03, 2013, 12:25:22 PM
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).
Title: Re: Edit Camera.center coords
Post by: Seb_B on March 26, 2015, 03:35:45 PM
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
Title: Re: Edit Camera.center coords
Post by: Alexey Pasumansky on March 26, 2015, 03:49:27 PM
Hello Sebastien,

Please try the following one:

Code: [Select]
v_est = chunk.crs.project(chunk.transform.matrix.mulp(camera.center))
Title: Re: Edit Camera.center coords
Post by: Seb_B on March 26, 2015, 03:58:01 PM
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.
Title: Re: Edit Camera.center coords
Post by: Alexey Pasumansky on March 26, 2015, 03:58:35 PM
Then you can omit chunk.crs.project function.
Title: Re: Edit Camera.center coords
Post by: Seb_B on March 26, 2015, 04:00:05 PM
Great! Thank you!