Agisoft Metashape > Python and Java API

Render image constrained to bounding box

(1/4) > >>

DaveRig:
As part of a python batch script I'd like to render a image of the completed mesh with the camera facing down -X (Front) and -Z (Top) and zoomed in to the bounding box so the mesh is centered and fills the frame .

I'm using the "renderImage" command which works but am not sure how to figure out the camera transform to position the camera as described.

Does anyone know or can anyone point me at a example of how to  calculate the camera transform and sensor calibration?
My mesh is always centered at world 0 on X,Y. Z can vary with the object's height.

Alexey Pasumansky:
Hello DaveGig,

You can refer to the following script that makes the mesh render for each aligned camera:
https://github.com/agisoft-llc/photoscan-scripts/blob/master/src/render_photos_for_cameras.py

The parameters to renderImage() function should be passed in internal coordinate system, if your chunk if referenced or transformed.

DaveRig:
I found a script similar to this which got me to the point of rendering from a aligned camera, but my issue is that I want to render from a point in space which frames the bounding box in the frustum that isn't a aligned camera.

Is it possible to do this?

Alexey Pasumansky:
Hello DavidRig,

I think you can try something like the following (just a quick test for TopXY render for unreferenced models):


--- Code: ---chunk = PhotoScan.app.document.chunk
point = chunk.region.center + PhotoScan.Vector([0,0, chunk.region.size.z * 3])

T = PhotoScan.Matrix([[1,0,0, point.x], [0,-1,0, point.y], [0,0,-1, point.z], [0,0,0,1]])

image = chunk.model.renderImage(T, chunk.sensors[0].calibration)
image.save("D:/render.jpg")

--- End code ---

DaveRig:
Awesome !!!!
this does exactly that I needed. Now just fiddling with the parm's for different cam locations

Thanks :)

Navigation

[0] Message Index

[#] Next page

Go to full version