Forum

Author Topic: Build Orthomosaic - create different projections  (Read 3132 times)

Beggiman

  • Newbie
  • *
  • Posts: 2
    • View Profile
Build Orthomosaic - create different projections
« on: October 20, 2020, 10:35:00 PM »
Hey guys

I'd like to export a orthophoto with e few different perspectives by python script. Like I can do manually with projecton plane " Current View, see atachment.  In the end i want that my code can create a custom projection.matrix. so that the view can rotate around the x and y-axis. 

I found multiple forumpost but they coudnt help me. for example: https://www.agisoft.com/forum/index.php?topic=11767.msg52733#msg52733


First, I tried to generate a "Planar FrontXZ" Orthomosaic but it resulted intro a "normal TopXY" . 
When I manually try it works well. (See attachment with top view (mady with script) and another with frontview (manually created)


Probably you can help me to buildOrthomosaic correctly.

I use : Agisoft Metashape Professional
Version 1.6.4 build 10928 (64bit) Ubuntu 18.04

Here my code:

I guess I make some mistake here but where?
Code: [Select]
                R = Metashape.Matrix( [[-1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0]] )#FrontXZ
projection= Metashape.OrthoProjection()
projection.type= Metashape.OrthoProjection.Type.Planar
projmatrix= Metashape.Matrix().Rotation(R)

projection.matrix= projmatrix

#build
chunk.buildOrthomosaic(surface_data=Metashape.DataSource.ModelData,blending_mode=Metashape.BlendingMode.MosaicBlending,projection=projection)
   


If you need the full code:


Code: [Select]
import Metashape
import os
import math
global doc
import numpy as np

project_name='test1'
def wholeprocess():

doc = Metashape.app.document
    print('project_path')
drive = '/home/linux-ben/Desktop/temp'
project_path = os.path.normpath(drive + "/" + project_name + "/" + project_name + ".psx")
output_path = os.path.normpath(drive + "/" + project_name + "/")

#While loop for multiple Orthophotos generation
i=0
while i < 1:
i+=1
doc.chunk = doc.chunks[0] #Use the models in the chunk
chunk = doc.chunk

if chunk.orthomosaic:
          chunk.orthomosaic = None #make orthomosaic not active and create a new one
R = Metashape.Matrix( [[-1.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, -1.0, 0.0]] )#FrontXZ
projection= Metashape.OrthoProjection()
projection.type= Metashape.OrthoProjection.Type.Planar
print("projnormal  =", projection.matrix )
projmatrix= Metashape.Matrix().Rotation(R)

projection.matrix= projmatrix
##Commented: Automatic change of viewpoint
#x=math.pi/i
#plane = np.array([[1.0, 0.0, 0.0, 0.0],[0.0, 1.0, 0.0, 0.0],[0.0, 0.0, 1.0, 0.0],[0.0, 0.0, 0.0, 1.0]])
#r_x = np.array([[1.0, 0.0, 0.0, 0.0],[0.0, math.cos(x), -math.sin(x), 0.0],[0.0, math.sin(x), math.cos(x), 0.0],[0.0, 0.0, 0.0, 1.0]])
#matrix=np.matmul(plane, r_x)
#projection.matrix= Metashape.Matrix(matrix1)

print("Round{}".format(i))
print("FrontXZ  =", projection.matrix )
print('Build Orthomosaic')

#build
chunk.buildOrthomosaic(surface_data=Metashape.DataSource.ModelData,blending_mode=Metashape.BlendingMode.MosaicBlending,projection=projection)
   
#export
chunk.exportRaster(path=output_path +'/ORTHO/'+ project_name + "_Ortho_NoFiltering_"+str(i)+".png",
    format=Metashape.RasterFormat.RasterFormatTiles,
    #image_format=Metashape.ImageFormat.ImageFormatNone,
    #raster_transform=RasterTransformNone [ ,
    projection=projection,
    # ][ , region ] , resolution=0,
    #resolution_x=0,
    #resolution_y=0,
    #block_width=10000,
    #block_height=10000,
    #split_in_blocks=False, width=0, height=0 [ , world_transform ] ,
    #nodata_value=32767,
    save_kml=True, save_world=True, save_scheme=False, save_alpha=True,
    image_description='automated export',
    #[ ,image_compression ] ,
    network_links=True,
    #min_zoom_level=-1,
    #max_zoom_level=-1,
    white_background=True,
    clip_to_boundary=True, title='Orthomosaic', description='Generated by Agisoft Metashape',
    source_data=Metashape.DataSource.OrthomosaicData, #north_up=True
    #tile_width=256,tile_height=256 [ , progress ]
    )

print('Export Report')
chunk.exportReport(output_path + project_name + "_ortho.pdf")

print('Save project')
doc.save()

label = "Custom menu/Exportdifferent Orthophotos"
Metashape.app.addMenuItem(label, wholeprocess)
print("To execute this script press {}".format(label))

Thank you for your help

Ben

Update:

got it run with adding worldcoordinate
Code: [Select]
crs = chunk.world_crs
projection.crs = crs

I am not sure why this was nesassary.
Probably somebody could explain?
« Last Edit: October 21, 2020, 12:17:18 PM by Beggiman »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14851
    • View Profile
Re: Build Orthomosaic - create different projections
« Reply #1 on: October 22, 2020, 11:26:41 PM »
Hello Ben,

Is your project referenced in geographic or local coordinates?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Beggiman

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Build Orthomosaic - create different projections
« Reply #2 on: October 23, 2020, 10:20:11 AM »
Hi
my Project contains different sources with images that contain GEO data and other they don't

In the end it would be nice to work with both sources.

However, my current dataset does not have GEO-Data so this project has only local coordinates.