Community Forum

Author Topic: batch python script  (Read 586 times)

rananna

  • Newbie
  • *
  • Posts: 7
    • View Profile
batch python script
« on: December 03, 2017, 04:57:03 PM »
my batch script keeps failing with "Error: module 'PySide2.QtGui' has no attribute 'QApplication'"
How can I fix this?
Here is the script:

import os,re,sys
import PhotoScan
from PySide2 import QtWidgets
from PySide2 import QtGui




def main():

   global doc
   doc = PhotoScan.app.document

   app = QtGui.QApplication.instance()
   parent = app.activeWindow()
   
   #prompting for path to photos
   path_photos = PhotoScan.app.getExistingDirectory("Specify input photo folder:")
   path_export = PhotoScan.app.getExistingDirectory("Specify EXPORT folder:")
   
   #processing parameters
   accuracy = PhotoScan.Accuracy.HighAccuracy  #align photos accuracy
   preselection = PhotoScan.Preselection.NoPreselection
   keypoints = 0 #align photos key point limit
   tiepoints = 0 #align photos tie point limit
   source = PhotoScan.PointsSource.DensePoints #build mesh source
   surface = PhotoScan.SurfaceType.Arbitrary #build mesh surface type
   quality = PhotoScan.Quality.HighQuality #build dense cloud quality
   filtering = PhotoScan.FilterMode.ModerateFiltering #depth filtering
   interpolation = PhotoScan.Interpolation.EnabledInterpolation #build mesh interpolation
   face_num = PhotoScan.FaceCount.HighFaceCount #build mesh polygon count
   mapping = PhotoScan.MappingMode.GenericMapping #build texture mapping
   atlas_size = 8196
   blending = PhotoScan.BlendingMode.MosaicBlending #blending mode
   color_corr = False


   print("Script started")

   #creating new chunk
   doc.addChunk()
   chunk = doc.chunks[-1]
   chunk.label = "New Chunk"

   #loading images
   image_list = os.listdir(path_photos)
   photo_list = list()
   for photo in image_list:
      if ("jpg" or "jpeg" or "JPG" or "JPEG") in photo.lower():
         photo_list.append(path_photos + "\\" + photo)
   chunk.addPhotos(photo_list)

   #align photos
   chunk.matchPhotos(accuracy = accuracy, preselection = preselection, filter_mask = False, keypoint_limit = keypoints,    tiepoint_limit = tiepoints)
   chunk.alignCameras()
   
   chunk.optimizeCameras()
   doc.save()

   #building dense cloud
   #PhotoScan.app.gpu_mask = 1  #GPU devices binary mask
   PhotoScan.app.cpu_enable = True  #CPU enable
   chunk.buildDenseCloud(quality = quality, filter = filtering)
   doc.save()

   #building mesh
   chunk.buildModel(surface = surface, source = source, interpolation = interpolation, face_count = face_num)
   doc.save()

   #build texture
   chunk.buildUV(mapping = mapping, count = 2)
   chunk.buildTexture(blending = blending , color_correction = color_corr, size = atlas_size)
   doc.save()

   PhotoScan.app.update()

   #export
   
   chunk.exportModel(path_export + "\\model.obj", format = "obj", texture_format='jpg')

   print("Script finished")


PhotoScan.app.addMenuItem("Custom menu/batch process", main)   

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 8274
    • View Profile
Re: batch python script
« Reply #1 on: December 03, 2017, 05:51:38 PM »
Hello rananna,

QApplication should be accessed from QtWidgets:

Code: [Select]
app = QtWidgets.QApplication.instance()
Best regards,
Alexey Pasumansky,
AgiSoft LLC

rananna

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: batch python script
« Reply #2 on: December 03, 2017, 06:34:38 PM »
Great! Thanks for this.
The script start to run and loads the files.
However, I am now getting this error:
Error: module 'PhotoScan' has no attribute 'PointsSource'
Any ideas?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 8274
    • View Profile
Re: batch python script
« Reply #3 on: December 03, 2017, 06:39:09 PM »
Hello rananna,

It should be source = PhotoScan.DataSource.DenseCloudData
Best regards,
Alexey Pasumansky,
AgiSoft LLC

rananna

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: batch python script
« Reply #4 on: December 03, 2017, 06:54:12 PM »
That was it!
Thank you for the prompt reply!