Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: stephhstuff on June 07, 2022, 07:44:30 PM

Title: updateTransform() not working
Post by: stephhstuff on June 07, 2022, 07:44:30 PM
Hello,

I am trying to scale my model using scalebars, but when I apply the updateTransform() function, nothing seems to happen. I run the script from the Metashape GUI, and when the script finishes running, I can see the scale bar successfully created, and if I manually press the update transform button in the reference tab, it updates. This isn't what I want though, as later in the script I want to use the coordinates of the scaled model to input into a CAD software for editing after, so I need it to update automatically.

Any help with this would be greatly appreciated!

Thanks

Relevant code below:

Code: [Select]
#place markers on model relative to ref img
camera = chunk.cameras[0]
point2D_1 = Metashape.Vector(marker_pts_px[0]) # coordinates of the point on the given photo
point2D_2 = Metashape.Vector(marker_pts_px[1])
sensor = camera.sensor
calibration = sensor.calibration
x = chunk.point_cloud.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(point2D_1)))
chunk.addMarker(point = x, visibility=False)
y = chunk.point_cloud.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(point2D_2)))
chunk.addMarker(point = y, visibility=False)
doc.save()

#add scalebar

chunk.addScalebar(chunk.markers[0], chunk.markers[1])
chunk.scalebars[0].reference.distance = input          #input argument
chunk.scalebars[0].reference.enabled = True
chunk.updateTransform()
doc.save()


#below rotates and translates everything to camera frame of reference
T = chunk.transform.matrix
origin = (-1) * camera.center
R = Metashape.Matrix().Rotation(camera.transform.rotation()*Metashape.Matrix().Diag([1,-1,-1]))
origin = R.inv().mulp(origin)
chunk.transform.matrix = Metashape.Matrix().Translation(origin) * R.inv()
doc.save()

# save model as .obj

if chunk.model:
    chunk.exportModel(output_folder + '/model.obj')

Title: Re: updateTransform() not working
Post by: Alexey Pasumansky on June 08, 2022, 12:46:30 PM
Hello stephhstuff,

Does it help, if you put chunk.updateTransform() line after the part with the chunk.transform.matrix manipulation?
Title: Re: updateTransform() not working
Post by: stephhstuff on June 10, 2022, 06:42:22 PM
That worked, thanks!