Creating script to process RC for multiple folders in sequence

Hi there,

I’ve been creating batch scripts to automate the Reality Capture Process, and so far have a pre and post editing script to process a single image folder/model.

I’m now trying to find a script that would process the script for multiple image folders, one after another, and export into a Model folder, and I understand this could entail adding variables to the script, however, I’m not sure how to correctly apply this to get the desired result.

Here’s the initial script for processing one data set.

“C:\Program Files\Capturing Reality\RealityCapture\RealityCapture.exe” ^
-save “%~dp0Reality Capture\Project.rcproj” ^
-addFolder “%~dp0\Project\images” ^
-detectMarkers ^
-importGroundControlPoints “%~dp0DetectPositions.txt” ^
-align ^
-save ^
-selectMaximalComponent ^
-setReconstructionRegion “%~dp0forCut.rcbox” ^
-calculateHighModel ^
-save ^
-selectLargestModelComponent ^
-invertTrianglesSelection ^
-removeSelectedTriangles ^
-renameSelectedModel “Unedited” ^
-exportSelectedModel “%~dp0*\Models\Project_Unedited.obj” ^
-save

1 Like

Hi @GothicGreenhouse
This post can be helpful for you: Run CLI scripts through subfolders

Hi,

Yes, I did see that topic, and looking at topics similar to what I’m trying to achieve. I think that user is using different parameters and I would like to try and get a discussion for what I’m looking for, creating my script. I could offer more details if it would help make the intended result more specific. Thanks!

I suppose you just need to rewrite this loop command for your needs:

::Create loop on which to run RC for all subfolders
:: for /R %%f in (%RootFolder%\..) do >>runscriptrealitycapture

for /D %%f in ("%RootFolder%*") do (
        ::echo Processing folder: '%%f'^

        :: run RealityCapture
        %RealityCaptureExe% -newScene ^
                -addFolder "%%f\images" ^
                -align ^
                -selectMaximalComponent ^
                -setReconstructionRegionAuto ^
                -calculateHighModel ^
                -renameSelectedModel %HighPoly% ^
                -calculateTexture ^
                -simplify %SimplifyTo% ^
                -renameSelectedModel %LowPoly% ^
                -unwrap ^
                -reprojectTexture %HighPoly% %LowPoly% %TextureReproSettings% ^
                -selectModel %LowPoly% ^
                -exportModel %LowPoly% "%%f\%Model%.obj" ^
                -save "%%f\Project.rcproj" ^
                -quit
)

I have tried the script you suggested, with the changes pertaining to my own RC process. It looks like this:

for /D %%f in ("%RootFolder%*") do ^ (
::echo Processing folder:: '%%f'^
     
"C:\Program Files\Capturing Reality\RealityCapture\RealityCapture.exe" ^
-save "%~dp0Reality Capture\Project.rcproj" ^
-addFolder "%%f\Processing" ^
-detectMarkers ^
-importGroundControlPoints "%~dp0DetectPositions.txt" ^
-align ^
-save ^
-selectMaximalComponent ^
-setReconstructionRegion "%~dp0forCutFACS.rcbox" ^
-calculateHighModel ^
-save ^
-selectLargestModelComponent ^
-invertTrianglesSelection ^
-removeSelectedTriangles ^
-renameSelectedModel "Unedited" ^
-exportSelectedModel "%~dp0\Harlander\Harlander_Unedited.obj" ^
-save

)

Some immediate issues:

I have noticed in the command prompt window I am seeing this:

D:\Processing> (
’ ’ is not recognized as an internal or external command,
operable program or batch file.

In Reality Capture, the operation is failing on finding images.

Essentially, what I’d like the script to execute is to process the first folder in the list, and then process the same sequence on the second.

I am trying to understand the %%f function better, and how it executes in a Notepad ++ written batch file, in that I understand it is a for function and the variable for which allows a repeating sequence?

Hi,
there you need to consider different options.

RealityCapture’s CLI uses basic batch scripting, so it is a good way to start there and check some general workflows.

The mentioned %%f is basically a parameter for the loop (in this case it is a root to folder). Using the scripts like this it is needed to have the batch script in the same folder where you want to work. Also, you need to check the folder structure a prepare it properly for your needs.
For example, the folders FACS 02 and FACS 03 are just image folders? Also, don’t use spaces in your folder names, instead of that use underscores. And you need to remember on the application settings (GCPs, reconstruction region, XMLs). Are you using the same for all your images or each image set has its own?

So, I would use the folder structure:

FACS
	FACS_02
			Images
			Settings
			Project
			Outputs
	FACS_03
			Images
			Settings
			Project
			Outputs
	BAT_file

And for that structure the script could look like this:

:: root path to work folders where all the datasets are stored (%~dp0 means the folder in which this script is stored)
set RootFolder=%~dp0:: set the name for the high-poly model

:: path to RealityCapture application
set RealityCaptureExe="C:\Program Files\Capturing Reality\RealityCapture\RealityCapture.exe"

::Create loop on which to run RC for all subfolders
:: for /R %%f in (%RootFolder%\..) do >>runscriptrealitycapture

for /D %%f in ("%RootFolder%*") do (
        ::echo Processing folder: '%%f'^

        :: run RealityCapture
        %RealityCaptureExe% -newScene ^
                -addFolder "%%f\Images" ^
                -detectMarkers ^
				-importGroundControlPoints "%%f\Settings\DetectPositions.txt" ^ 
				-align ^
				-save "%%f\Project\Project.rcproj" ^
                -selectMaximalComponent "%%f\Project\Project.rcproj" ^
                -setReconstructionRegion "%%f\Settings\forCutFACS.rcbox" ^ 
				-calculateHighModel ^
				-save ^
				-selectLargestModelComponent ^
				-invertTrianglesSelection ^
				-removeSelectedTriangles ^
				-renameSelectedModel "Unedited" ^
				-exportSelectedModel "%%f\Outputs\Harlander_Unedited.obj" ^
				-save ^
                -quit
)

If you have general setting it can be set as direct path to those settings.
The script wasn’t tested, so maybe it will need some refinements. Good luck with your work!

Thanks for the help so far,

while your script update is launching Reality Capture, the operation is failing on finding images. I’m not sure why that’s the case. Also, under this line, I had I to remove the asterisk that was proceeding %RootFolder% in order for Reality Capture to launch :

for /D %%f in ("%RootFolder%") do (
        ::echo Processing folder: '%%f'^

This is the current state the script is looking:

:: root path to work folders where all the datasets are stored (%~dp0 means the folder in which this script is stored)
set RootFolder=%~dp0::

:: path to RealityCapture application
set RealityCaptureExe= "C:\Program Files\Capturing Reality\RealityCapture\RealityCapture.exe"

::Create loop on which to run RC for all subfolders
:: for /R %%f in (%RootFolder%\..) do >>runscriptrealitycapture

for /D %%f in ("%RootFolder%") do (
        ::echo Processing folder: '%%f'^

        :: run RealityCapture
        %RealityCaptureExe%  -newScene ^
                -addFolder "%%f\Images" ^
                -detectMarkers ^
				-importGroundControlPoints "%%f\Settings\DetectPositions.txt" ^ 
				-align ^
				-save "%%f\Project\FACS.rcproj" ^
                -selectMaximalComponent  ^
                -setReconstructionRegion "%%f\Settings\forCutFACS.rcbox" ^ 
				-calculateHighModel ^
				-save ^
				-selectLargestModelComponent ^
				-invertTrianglesSelection ^
				-removeSelectedTriangles ^
				-renameSelectedModel "Unedited" ^
				-exportSelectedModel "%%f\Outputs\Unedited.obj" ^
				-save ^
                -quit
)

Hi,
as I wrote you before, the script wasn’t refined.
It should work like this (this one was tested):

:: root path to work folders where all the datasets are stored (%~dp0 means the folder in which this script is stored)
set RootFolder=%~dp0

:: path to RealityCapture application
set RealityCaptureExe="C:\Program Files\Capturing Reality\RealityCapture\RealityCapture.exe"

::Create loop on which to run RC for all subfolders
:: for /R %%f in (%RootFolder%\..) do >>runscriptrealitycapture

for /D %%f in ("%RootFolder%*") do (
        ::echo Processing folder: '%%f'^

        :: run RealityCapture
        %RealityCaptureExe% ^
                -newScene ^
                -addFolder "%%f\Images" ^
                -detectMarkers ^
				-importGroundControlPoints "%%f\Settings\DetectPositions.txt" ^ 
				-align ^
				-save "%%f\Project\Project.rcproj" ^
                -selectMaximalComponent "%%f\Project\Project.rcproj" ^
                -setReconstructionRegion "%%f\Settings\forCutFACS.rcbox" ^ 
				-calculateHighModel ^
				-save ^
				-selectLargestModelComponent ^
				-invertTrianglesSelection ^
				-removeSelectedTriangles ^
				-renameSelectedModel "Unedited" ^
				-exportSelectedModel "%%f\Outputs\Harlander_Unedited.obj" ^
				-save ^
                -quit
)

But it is possible that in attached script are unnecessary spaces, so you will need check for that.

The loop seems to be working now, thank you for your help. Much appreciated.

One question I do have; for the naming of the export, how may I change the suffix of the path where it will be the name of the folder instead?

To give an example of what I mean; currently, I have:

-exportSelectedModel "%%f\Outputs\Harlander_Unedited.obj" ^

This will name all models that name, whereas, I’d like it be more like, “FACS_02_Unedited.obj, FACS_03_Unedited.obj…etc.”

Or would that need to be executed manually?

Hi,
you can try to add one command in your script, which will bee adding +1 each run it was ran.
Like sum numbers in for loop, batch file - Stack Overflow


Hi there,
It would help if you removed this “^” thing from your last line of the code. I don’t know why it works, but it worked for me.