Agisoft Metashape > Python and Java API

How do I set output size of orthomosaic

(1/2) > >>

Samuel:
I have been developing some code to automatically process, save and export data. For part of the necessary use of the data I need the orthomosaic to be of a certain maximum dimension, using the gui I can just use the "Max. dimention (pix): " option to set the maximum size for the exported image.

My question is: How do I do that with python? the only options I have found in the API are dx, dy which the API makes sound to be the programmatic version of the gui's "Pixel size: "  option, or blockh, blockw which seem to relate to the "Split into blocks (pix):" option.

currently i am using some python code to resize the full sized orthomosaic down to what I need after exporting but every time it runs I get a "pixel count too large: could be a decompression bomb attack" warning.

PhotoScan Version: 1.3.2 build 4205 (64 bit)

mikeb:
I'm also very interested in a solution regarding this problem.
I'm also running into the same problem. And I also need the function to export the orthomosaic in a specific dimension in pix.

Hope someone got an answer for this.

Alexey Pasumansky:
Hello mikeb,

You can use the following methods related to orthomosaic to calculate the require export resolution:
chunk.orthomosaic.width
chunk.orthomosaic.height
chunk.orthomosaic.resolution

So if you need to export the orthomosaic using max-dimension = X, then I think you can use the following:


--- Code: ---dx = dy = max(chunk.orthomosaic.width, chunk.orthomosaic.height) * chunk.orthomosaic.resolution / X
--- End code ---

mikeb:
Thank you for your answer, but it still export a huge image.
I want the maximum size of the orthomosaic the same size as my exported DEM.
In the GUI I choose in the export window Max. dimension (pix) and choose 4122.
But if I do it in the python script the size is still the same. I think its not possible to use dx and dy the same so I just use one of it and still does not work. If I use dx and dy in the exportorthomosaic function it returns with an Runtime Error: Empty Raster.
Can you tell what I'm doing wrong. I want to use the same size as my DEM (max dimension = 4122)

Here is my codesnippet:


--- Code: ---dx = dy = max(chunk.orthomosaic.width, chunk.orthomosaic.height) * chunk.orthomosaic.resolution / 4122.0

chunk.exportOrthomosaic(project_path + project_name + ".tif", image_format=PhotoScan.ImageFormatTIFF, format = PhotoScan.RasterFormatTiles, dy=dy, raster_transform=PhotoScan.RasterTransformNone, write_kml=False, write_world=True)

--- End code ---

Alexey Pasumansky:
Hello mikeb,

Is your project referenced in WGS84?

If so, then you need to convert meters for dx and dy parameters to degrees.

Navigation

[0] Message Index

[#] Next page

Go to full version