Agisoft Metashape > Python and Java API

resize bounding box to sparse point cloud

(1/4) > >>

Milderinne:
Hello everybody,
is there any solution to adjust/resize the bounding box to the complete extent of the sparse point cloud before caculation the dense point cloud?
Thanks for any help!
All the best,
Susann

Alexey Pasumansky:
Hello Susann,

It may be a not good idea, since there could be outlier points that are far away from the main point cloud.

However, for your task you can loop through all the points of the sparse cloud, check their coordinates and assign chunk.region size and origin to fit min and max values of the point coordinates.

It may be easier, if you set up the box sides orientation parallel to the coordinate system axis. (also note that the coordinates of the points and chunk region are in the internal coordinate system, so for the referenced chunks you may need to convert the coordinates to the real coordinate system values).

Milderinne:
Hello Alexey,
thank you for your fast reply (as always)!

I understand the problem of outliers, I also thought about that before.

I can imagine to loop through the sparse point cloud points, but how do I check their coordinates? How do I than assign chunk.region size and origin. Is there something like min max?

At this point or for this specific idea I am not able to assign coordinates at this moment. Am I still able to grow the the extent of the bounding box?

Thank you so much for your help!
Kind regrads.

Alexey Pasumansky:
Hello Susann,

You can use the following code as a reference (it should work for georeferenced chunks:


--- Code: ---import PhotoScan, math

doc = PhotoScan.app.document
chunk = doc.chunk
region = chunk.region
T = chunk.transform.matrix

m = PhotoScan.Vector([10E+10, 10E+10, 10E+10])
M = -m

for point in chunk.point_cloud.points:
if not point.valid:
continue
coord = T * point.coord
coord.size = 3
coord = chunk.crs.project(coord)
for i in range(3):
m[i] = min(m[i], coord[i])
M[i] = max(M[i], coord[i])

center = (M + m) / 2
size = M - m

region.center = T.inv().mulp(chunk.crs.unproject(center))
region.size = size * (1 / T.scale())

v_t = T * PhotoScan.Vector( [0,0,0,1] )
v_t.size = 3
R = chunk.crs.localframe(v_t) * T
region.rot = R.rotation().t()

chunk.region = region
print("Script finished.")
--- End code ---

Milderinne:
Hello Alexey,
thank you for your reply! Sorry for the late reply on my side.

You say the code work for georeferenced chunks? But my chunk is not yet georeferenced and might never be? Will it still work?

Best regards!

Navigation

[0] Message Index

[#] Next page

Go to full version