Forum

Author Topic: batch python script  (Read 731 times)

bennymicheal

  • Newbie
  • *
  • Posts: 1
    • View Profile
batch python script
« on: October 05, 2018, 06:01:20 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)   

steve.aldrich

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: batch python script
« Reply #1 on: November 14, 2018, 03:09:51 AM »
I'm just guessing here, but is PySide2 installed (or installed correctly) on your machine? What's the setup you're running this on?

I have to adjust your code to try to run it on a chunk on my machine (Windows 10 install) to see if I encounter any errors...

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 10294
    • View Profile
Re: batch python script
« Reply #2 on: November 14, 2018, 12:02:10 PM »
In PySide2 QApplication is available from QtWidgets. So the import and app assignment could be used in the following way:

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