Forum

Author Topic: python scripting for new photoscan version  (Read 5478 times)

mfran2002

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
python scripting for new photoscan version
« on: May 11, 2016, 12:48:51 AM »
hello,
I've to adapt some python script written for the old photoscan version (1.0.4) to the new one, but I've some issues...

In a script I have some chunks and I have to merge them, but in the new python version I don't know how to reference the merged chunk

so, first of all I align the chunks:

doc.alignChunks(doc.chunks, doc.chunks[0], method="points", fix_scale=False, accuracy=PhotoScan.HighAccuracy, preselection=True, filter_mask=False, point_limit=80000)

then merge them:

doc.mergeChunks(doc.chunks, merge_dense_clouds=False, merge_models=True, merge_markers=False)

BUT NOW, HOW CAN I REFERENCE THE MERGED CHUNK? the following statements return me error:

doc.chunk.buildModel(surface=PhotoScan.HeightField, interpolation=PhotoScan.EnabledInterpolation, face_count=PhotoScan.MediumFaceCount, source=PhotoScan.DenseCloudData)

doc.chunk.buildTexture(blending=PhotoScan.MosaicBlending, color_correction=False, size=4096)


« Last Edit: May 11, 2016, 12:54:46 AM by mfran2002 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: python scripting for new photoscan version
« Reply #1 on: May 11, 2016, 12:24:10 PM »
Hello mfran2002,

What kind of data has been used in the original chunks for the model referencing?

Also you are not merging the dense cloud (not sure if they are present in the original chunks), but are trying to build the model from the dense cloud.
Best regards,
Alexey Pasumansky,
Agisoft LLC

mfran2002

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: python scripting for new photoscan version
« Reply #2 on: May 11, 2016, 10:41:24 PM »
What kind of data has been used in the original chunks for the model referencing?
:-[ sorry Alexey, may you please explain me the question?  :-[
I have 4 chunks and for each of them I simply put the photos (I used 4 chunks because of too many photos, almost 1000, to make the perform of photoscan faster)

Also you are not merging the dense cloud (not sure if they are present in the original chunks), but are trying to build the model from the dense cloud.
Hoping to have correctly understood the question, following my complete script:

import PhotoScan

MyPrj = PhotoScan.app.getOpenFileName()
doc = PhotoScan.app.document
doc.clear()
doc.open(MyPrj)

NrOfChunks = len(doc.chunks)
for chunk_name in range (0,NrOfChunks):
      curr_chunk = doc.chunks[chunk_name]

      curr_chunk.matchPhotos(accuracy = PhotoScan.HighAccuracy, preselection = PhotoScan.GenericPreselection, filter_mask = False, keypoint_limit = 40000, tiepoint_limit = 4000)
      curr_chunk.alignCameras()

      curr_chunk.optimizeCameras(fit_f=True, fit_cxcy=True, fit_aspect=True, fit_skew=True, fit_k1k2k3=True, fit_p1p2=True, fit_k4=True, fit_p3=True, fit_p4=True)

      curr_chunk.buildDenseCloud(quality = PhotoScan.HighQuality, filter = PhotoScan.ModerateFiltering)

      
doc.alignChunks(doc.chunks, doc.chunks[0], method="points", fix_scale=False, accuracy=PhotoScan.HighAccuracy, preselection=True, filter_mask=False, point_limit=80000)

doc.mergeChunks(doc.chunks, merge_dense_clouds=False, merge_models=True, merge_markers=False)

doc.chunk.buildModel(surface=PhotoScan.HeightField, interpolation=PhotoScan.EnabledInterpolation, face_count=PhotoScan.MediumFaceCount, source=PhotoScan.DenseCloudData)

doc.chunk.buildTexture(blending=PhotoScan.MosaicBlending, color_correction=False, size=4096)


but I receive an error in buildmodel and buildtexture: maybe because i don't refer correctly the merged chunk?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: python scripting for new photoscan version
« Reply #3 on: May 12, 2016, 12:03:32 PM »
Hello mfran2002,

In the mergeChunks() function you've got merge_dense_clouds set to False, it means that there will not be any dense cloud in the merged chunk, so building mesh based on the dense cloud in the merged chunk will fail, as there's no source data.
Best regards,
Alexey Pasumansky,
Agisoft LLC

mfran2002

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: python scripting for new photoscan version
« Reply #4 on: May 12, 2016, 12:34:37 PM »
ok, thanks, I will modify to True this parameter

how about the syntax of the buildmodel and buildtexture calls?
is it correct?

doc.chunk.buildModel

doc.chunk.buildTexture

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: python scripting for new photoscan version
« Reply #5 on: May 12, 2016, 05:12:50 PM »
buildModel and buildTexture look correct, but before building texture you need to parametrize texture atlas using .buildUV() function.
Best regards,
Alexey Pasumansky,
Agisoft LLC

mfran2002

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: python scripting for new photoscan version
« Reply #6 on: May 12, 2016, 05:38:37 PM »
ok, I will add, before texture, the following statement (I'm working in precision agriculture so I imagine to need parameter mapping=PhotoScan.OrthophotoMapping)

doc.chunk.buildUV(mapping=PhotoScan.OrthophotoMapping)

do you think it is right?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: python scripting for new photoscan version
« Reply #7 on: May 12, 2016, 05:40:49 PM »
Hello mfran2002,

Yes, that should work.

However, please note that texture is not required for orthomosaic generation.
Best regards,
Alexey Pasumansky,
Agisoft LLC

mfran2002

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: python scripting for new photoscan version
« Reply #8 on: May 13, 2016, 12:32:32 AM »
Hi again Alexey,

if I haven't georeferenced photos (I don't have any coordinate for them) I have to use buildUV anyway?

in case of not georeferenced photos, my script above is still valid?

may you please give me the modifications if something has to be changed?

PS: may also tell me the name of the buildUV function into the user interface? I don't find it

« Last Edit: May 13, 2016, 12:41:34 AM by mfran2002 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: python scripting for new photoscan version
« Reply #9 on: May 13, 2016, 11:51:07 PM »
Hello mfran2002,

buildUV and buildTexture Python functions are two steps of GUI command named Build Texture. So it is not possible to buidl texture without building UV. But it is not related anyhow to the chunk referencing, as the texture can be applied to unreferenced chunk.
Best regards,
Alexey Pasumansky,
Agisoft LLC

mfran2002

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: python scripting for new photoscan version
« Reply #10 on: May 14, 2016, 09:54:24 AM »
ok, thank you.
so in the GUI there is only one utility (buildTexture) while via scripting there are two functions (buildUV and buildTexture) to be called sequencially, right?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: python scripting for new photoscan version
« Reply #11 on: May 14, 2016, 10:13:53 AM »
Yes, exactly. Align Photos operation in Python is also split into two parts: matchPhotos() and alignCameras().
Best regards,
Alexey Pasumansky,
Agisoft LLC