Blog
Batch Processing Blend Shapes – Stage 2 hero image
13 July 2017

Batch Processing Blend Shapes – Stage 2

Welcome to part 2 of the Batch processing blend shapes guide! In this section we’ll be going over setting up a batch process for all the processing commands needed to build a model inside of Photoscan. We are also supplying you a script to automate the one part of the pipeline that needs human input; gradual selection and camera calibration!

Our first step is to import all our images from each of the expression scans into a single project. Each expression will be it’s own chunk in our project and from there we can execute commands for each chunk in one go. First off, right click the work-space panel and select ‘Add chunk‘. Do this for each expression that will be processed and then drag a set of photos into each chunk.

 

 

Now, onto batch processing the scans. Start by selecting ‘Batch Process…‘ under the ‘Workflow‘ tab and hitting ‘Add‘.

The first job we want to add is the ‘Align photos‘ which is applied to ‘Selection‘; select all but our Neutral chunk and in the general settings we want to keep our ‘Accuracy‘ on high with ‘Generic preselection‘ and ‘Reference preselection‘ on Yes. For the advanced settings we want ‘Key point limit‘ set to 400,000, ‘Tie point limit‘ set to 10,000 and ‘Adaptive camera model fitting‘ set to yes. If you are using masks in your project, be sure to tick ‘Constrain features by mask‘.

Now we can use a little bit of Python script to automate the gradual selection and camera calibration process we applied to the master scan before. You can find the code below, simply copy and paste it into a notepad file and save the file out with the extension .PY at the end, then just drag it into your scripts folder for Photoscan (AppData/Local/Agisoft/PhotoScan Pro/scripts/) and it should appear in the ‘Custom menu‘ on the top toolbar.

————————————————————————————————————————————————————————————

import PhotoScan

 

chunk = PhotoScan.app.document.chunk
f = PhotoScan.PointCloud.Filter()
f.init(chunk, PhotoScan.PointCloud.Filter.ReconstructionUncertainty)
#f.selectPoints(12)
f.removePoints(12)# if you want to select the points while debugging, use: f.selectPoints(10)

for sensor in chunk.sensors:
calib = sensor.calibration
#calib.k4 = 0
# calib.p3 = 0
calib.p4 = 0
sensor.calibration = calib
chunk.optimizeCameras() #by default fit_p3, fit_p4 and fit_k4 are False

threshold = 1
f = PhotoScan.PointCloud.Filter()
f.init(chunk, criterion = PhotoScan.PointCloud.Filter.ReprojectionError)
f.removePoints(0.5) # if you want to select the points while debugging, use: f.selectPoints(threshold)

 

for sensor in chunk.sensors:
calib = sensor.calibration
#calib.k4 = 0
# calib.p3 = 0
calib.p4 = 0
sensor.calibration = calib
chunk.optimizeCameras() #by default fit_p3, fit_p4 and fit_k4 are False

 

f = PhotoScan.PointCloud.Filter()
f.init(chunk, criterion = PhotoScan.PointCloud.Filter.ProjectionAccuracy)
f.removePoints(15)

 

for sensor in chunk.sensors:
calib = sensor.calibration
#calib.k4 = 0
# calib.p3 = 0
calib.p4 = 0
sensor.calibration = calib
chunk.optimizeCameras() #by default fit_p3, fit_p4 and fit_k4 are False

————————————————————————————————————————————————————————————

After copying over the script; we want to click the ‘Add‘ button again in ‘Batch Process…’ and select ‘Run Script‘ as the job type and again apply this to all chunks but our neutral master chunk. Direct the path to our custom script and hit OK.

Note that the values in the script may need to change dependent on your project! I advice you to run the script on a single chunk first to see if the values are too high which will cause chunks of your model to be deleted. The ZIP folder containing the free script will have a few variations at different values; try them all out to see which one better suites your project.

Next up is adding the ‘Build Dense Cloud‘ Job. Same as before, hit ‘Add…‘, select ‘Build Dense Cloud‘ as the job type and apply this to all chunks but the neutral master chunk. Set the ‘Quality‘ to high and the ‘Depth filtering‘ to Aggressive.

After that we’ll add a ‘Build Mesh‘ command to the batch process. You know the score, Select ‘Add…‘ and choose ‘Build Mesh‘ to the job type and apply this to all chunks but the first Neutral master chunk. Keep all the general settings as is apart from the ‘Custom face count‘ which we’ll set to 5,000,000. Lastly, in the advanced settings turn off ‘Calculate vertex colors‘.

Now we’ll tell the batch process to build all the textures. Again, select ‘Add…‘ and change the job type to ‘Build Texture‘ and apply this to all chunks. We’ll leave all the settings as is apart from ‘Texture size‘ which we’ll change to 16384; again, you can change this as you need.

Nearly there… Now we’ll align all our chunks to our master chunk which we aligned at the start of this tutorial. Select ‘Add…‘ and set the ‘Job type‘ to ‘Align Chunks‘ and apply this to ‘All Chunks‘. In the general settings, change the ‘Method‘ to ‘Camera based‘ and set the ‘Reference chunk‘ to our neutral master chunk. In the ‘Image Matching’ settings; change the ‘point limit‘ to 400,000 and make sure the accuracy is set to at least ‘High‘. If you’re using masks in your project; make sure to change ‘Constrain features by mask‘ to Yes.

For our last command we’ll export out all the models to a separate folder. Select ‘Export model’ from the ‘Job type‘ and apply this to ‘All chunks‘. For the ‘Path‘, select where you want the files to be stored and use {chunklabel}.OBJ as the name. This will export the models individually and use the chunk’s name inside of Photoscan as the exported file name. Lastly, change the ‘Texture format‘ to PNG (Or whatever you need it exported as) and disable ‘Cameras’, ‘Markers’, and ‘Vertex Color’.

voilà! Our batch Process is ready to run!

In the next stage we’ll go through wrapping a base-mesh with clean topology and animation loops to all our processed scan data then baking down the color information.

Thanks for reading and if you have any problems then drop me an e-mail and I’d be happy to help!

 

Rashed Al-Metrami

Rashed@Metapixel.io