Forum

Author Topic: Exported camera position data is not scaled  (Read 2968 times)

willfig

  • Newbie
  • *
  • Posts: 35
    • View Profile
Exported camera position data is not scaled
« on: June 19, 2019, 06:44:16 AM »
This was originally posted to the Python Scripting theme but is probably more appropriate here.

I'm working with some custom software that allows some photo overlay tools on dense clouds.  When I import the dense cloud and camera position data from an unscaled model, it works fine.  However, when I import the same from a scaled model, the camera positions are not correct.  We use the script below to export the .xml camera position file as well as a file that contains the transform and x,y.z position data for every camera.  I've looked these over and it looks like the position data exported from the scaled model is exactly the same as that pulled from an unscaled version of the same model.  I'm wondering if anybody knows why this is and how I can get position data for the cameras in the scaled coordinate system.

----------------------------------------------------------------------------------------------------------------------------------------
import PhotoScan
import math
import os
import json

doc = PhotoScan.app.document
chunk = doc.chunk # FIXME thyis is just the active chunk
cams = chunk.cameras

proj_path = doc.path
proj_dir, proj_name = os.path.split(proj_path)
proj_name = proj_name[:-4]

outputs = {}

cams_filename = proj_dir + '/' + proj_name + '.cams.xml'
meta_filename = proj_dir + '/' + proj_name + '.meta.json'

meta_file = open(meta_filename, 'w')

chunk.exportCameras(cams_filename)

for cam in cams:
    key = cam.key
    path = cam.photo.path
    center = cam.center
    if center is not None:
        geo = chunk.transform.matrix.mulp(center)
        if chunk.crs is not None:
            lla = list(chunk.crs.project(geo))
        center = list(center)
   
    agi_trans = cam.transform
    trans = None
    if agi_trans is not None:
        trans = [list(agi_trans.row(n)) for n in range(agi_trans.size[1])]
   
    outputs[key] = {'path' : path, 'center' : center, 'transform' : trans}
   
   
print(outputs)
meta_file.write(json.dumps({'cameras' : outputs}, indent=4))

meta_file.close()
------------------------------------------------------------------------------------------------------------------------------------------