Forum

Author Topic: Issue of Python scrip for exporting Orthophoto  (Read 12153 times)

an198317

  • Newbie
  • *
  • Posts: 42
    • View Profile
Issue of Python scrip for exporting Orthophoto
« on: June 11, 2013, 07:20:59 PM »
Hi,

I am building a Python workflow for making models automatically. When I tried to add exportOrthopho in my code, there is a problem. It seems PhotoScan Pro was trying to build a orthophoto, but the info in PhotoScan Pro Console showed "Mosaic 0x0", and never saved the orthophoto.

My code is:
doc.activeChunk.exportOrthophoto(Path+"ortho.tif", format="tif", blending="average", blockw=4096, blockh=4096, write_kml=False, write_world=False)

Does anyone know what's wrong with my code?

And I also want to save the model as "From bottom XY" in Projection Plane, how can I set this up in my code?

Thanks a lot!
Nan

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Issue of Python scrip for exporting Orthophoto
« Reply #1 on: June 12, 2013, 01:29:15 PM »
Hello Nan,

I think that the problem is in fact that active chunk is unreferenced. So you need to assign an identity transformation matrix to chunk.transform to be able to export orthophoto or DEM. For referenced chunks there is already valid transformation matrix.

Here is a sample code that assigns to chunk.transform identity matrix and uses proj matrix to export orthophoto in "Top XY" projection plane:

Code: [Select]
import PhotoScan

doc = PhotoScan.app.document
chunk = doc.activeChunk

if not chunk.transform:
chunk.transform = PhotoScan.Matrix ([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]])

type = "tif"
path = "D:/orthophotoXY." + type

d_x = d_y = 0.01

proj = PhotoScan.Matrix ([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]])  #Top XY

chunk.exportOrthophoto(path, type, "mosaic", projection = proj, dx = d_x, dy = d_y)
« Last Edit: June 12, 2013, 01:32:11 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

an198317

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Issue of Python scrip for exporting Orthophoto
« Reply #2 on: June 14, 2013, 01:20:45 AM »
Hi Alexey,

Thank you so much about your fast response! You code is sort of working for me, but there are some small problems I still need to fix.

Question 1: I have noticed this since Day I started using PhotoScan Pro. When I do manual control Photoscan pro for exporting orthophoto, if I choose Top XY for Projection Plane, the orthophoto is not the view from the camera (above ground) shooting down, but the view seems like looking at the orthophoto from beneath the ground surface. So when I choose "Bottom XY", the orthophoto is shooting down from the air.

Do I misunderstand something here? What's the transformation matrix for "bottom XY"?

Question 2: I was using 4096 as buildTexture height and width. And I also used 4096 as exportOrthophoto, the saved orthophoto is 8 pieces. Then I changed exportOrthophoto  blockw and blockh from 4096 to 16384, the saved orthophoto is one piece with higher resolution.

So I was wondering is there no relationship between texture dimension and orthophoto dimension? And if I use 16384 as my exportOrthophoto blockw and blockh, will this give me the highest resolution.

And I am not sure how to use dx and dy settings here. What is 0.01 for?

Question 3: Also when I manually export orthophoto and use 16384 as "Max Dimension", the saved orthophoto is cropped. So how could I have this function in my code so I can crop the blank area?

Here is my code for buildTesture and exportOrthophoto:

#Building the texture of the model.
doc.activeChunk.buildTexture(mapping="adaptive", blending="average", width=4096, height=4096)

#export orthophoto.
        if not doc.activeChunk.transform:
            doc.activeChunk.transform=PhotoScan.Matrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]])

        proj=PhotoScan.Matrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]])
        doc.activeChunk.exportOrthophoto(Path+"ortho"+".tif", format="tif", blending="average", projection=proj, blockw=16384, blockh=16384, write_kml=False, write_world=False)


Thank you so much for your big help, Alexey!!
Nan


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Issue of Python scrip for exporting Orthophoto
« Reply #3 on: June 14, 2013, 12:14:54 PM »
Hello Nan,

1) You need to make sure Z axis is oriented correspondingly to the model. In most cases height field like processing results will have Z looking under the surface in case the chunk is unreferenced, so you'll need to select Bottom XY, as this projection planes (like "Bottom", "Top" and etc.) correspond to the chunk coordinate system and not to the reconstructed model (PhotoScan doesn't recognize where is Top or Bottom of the reconstructed model).

The transformation matrix for Bottom XY is the following:
bottomXY = PhotoScan.Matrix([[-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]])

2) Block size parameter of the .exportOrthophoto method has different meaning from Texture atlas size.In case you apply block size values that means PhotoScan will cut the resulting Orthophoto into tiles of the given size. It will not affect on the export resolution.
The resolution of the orthophoto is defined by dx and dy parameters - in case the chunk is referenced, these parameters should be specified in m/pix (or degrees/pix if WGS84 is used). But if your model is not referenced the scale of the model is arbitrary and dx, dy do not have anything with the real world scale, however, omitting this parameter will result in using the default value (the same you can see in the Export Orthophoto dialog).


3) You can use Region parameter in the .exportOrthophoto method to specify rectangular area for orthophoto export.
But actually Max Dimension specifies the scaling of the orthophoto, so that none of X and Y values of the resulting image are bigger then specified parameter value.
Best regards,
Alexey Pasumansky,
Agisoft LLC

marco

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Issue of Python scrip for exporting Orthophoto
« Reply #4 on: October 17, 2014, 02:17:54 PM »
Hi,
I'm trying for days to export some orthophotos in python analogues to GUI, but I don't get the transformation matrices
I wrote a part in python where a set of matrices is generated randomly (with random values of 1,0,-1) to understand how the values influences the orthophoto..but finally I don't get it :(

BottomXY = PhotoScan.Matrix([[-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]]) as in the topic here...PhotoScan.Matrix ([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) is Top XY

I want to build only the transformation matrices for exactly the same options in the GUI:
* Top XY (0,90, 180, 270)
* Bottom XY (0,90, 180, 270)
* Front XZ (0,90, 180, 270)
* Back XZ (0,90, 180, 270)
* Right YZ (0,90,180,270)
* Left YZ (0,90,180,270)

Maybe somebody could show me how this works  :-\

Thanks in advance

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Issue of Python scrip for exporting Orthophoto
« Reply #5 on: October 17, 2014, 03:32:16 PM »
Hello marco,

Unless I'm mistaken, the following matrices can be applied for planar projection export (assuming that the chunk is unreferenced, otherwise you need to use the matrices product):

TopXY
Matrix([[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]])


BottomXY
Matrix([[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]])


FrontXZ
Matrix([[1.0, 0.0, 0.0, 0.0],
       [0.0, 0.0, 1.0, 0.0],
       [0.0, -1.0, 0.0, 0.0],
       [0.0, 0.0, 0.0, 1.0]])


BackXZ
Matrix([[-1.0, -0.0, -0.0, 0.0],
       [0.0, 0.0, 1.0, 0.0],
       [0.0, 1.0, 0.0, 0.0],
       [0.0, 0.0, 0.0, 1.0]])


RightYZ
Matrix([[-0.0, -1.0, -0.0, 0.0],
       [0.0, 0.0, 1.0, 0.0],
       [-1.0, 0.0, 0.0, 0.0],
       [0.0, 0.0, 0.0, 1.0]])


LeftYZ
Matrix([[0.0, 1.0, 0.0, 0.0],
       [0.0, 0.0, 1.0, 0.0],
       [1.0, 0.0, 0.0, 0.0],
       [0.0, 0.0, 0.0, 1.0]])
Best regards,
Alexey Pasumansky,
Agisoft LLC

marco

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Issue of Python scrip for exporting Orthophoto
« Reply #6 on: October 21, 2014, 04:49:35 PM »
Hey Alexey,
thanks for your help :)
Looks good

Meric

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Issue of Python scrip for exporting Orthophoto
« Reply #7 on: July 14, 2020, 05:44:47 PM »
How to calculate matrices when our block is referenced?