import os
import glob
import csv
import rc # Reality Capture Python API
def load_gcps(gcp_file):
“”"
Load Ground Control Points (GCPs) from a CSV file.
Assumes the CSV file has columns: image_name, GCP_name, pixel_x, pixel_y, real_x, real_y, real_z
“”"
gcps =
with open(gcp_file, ‘r’) as f:
reader = csv.reader(f)
next(reader) # Skip header
for row in reader:
image_name = row[0] # This is the image name (e.g., DSC_0001)
pixel_x = float(row[2]) # Pixel X-coordinate
pixel_y = float(row[3]) # Pixel Y-coordinate
real_x = float(row[4]) # Real-world X-coordinate
real_y = float(row[5]) # Real-world Y-coordinate
real_z = float(row[6]) # Real-world Z-coordinate
gcps.append({
“image_name”: image_name,
“pixel_x”: pixel_x,
“pixel_y”: pixel_y,
“real_x”: real_x,
“real_y”: real_y,
“real_z”: real_z
})
return gcps
def add_gcps_to_project(project, gcps):
“”"
Add Ground Control Points (GCPs) to the Reality Capture project.
“”"
for gcp in gcps:
# Find the image by name and add GCP
image = project.getImageByName(gcp[“image_name”])
if image:
# Add GCPs (image pixel coordinates and real-world coordinates)
project.addGCP(
image,
gcp[“pixel_x”], gcp[“pixel_y”], # pixel coordinates
gcp[“real_x”], gcp[“real_y”], gcp[“real_z”] # real-world coordinates
)
def set_project_units_to_mm(project):
“”"
Set the project unit to millimetres (for laboratory coordinate system).
“”"
project.setUnit(rc.Unit.Millimeter) # Set unit to millimetres
def set_reconstruction_region(project):
“”"
Set a reconstruction region for the project. This ensures the model is built within a defined region.
“”"
# Define the bounding box for the reconstruction region
xmin, ymin, zmin = -100, -100, 0 # Example min coordinates
xmax, ymax, zmax = 100, 100, 100 # Example max coordinates
# Set the reconstruction region in Reality Capture
project.setReconstructionRegion(xmin, ymin, zmin, xmax, ymax, zmax)
def process_images(gcps):
“”"
Process the images in Reality Capture, applying GCPs, aligning images, building the model, and exporting the result.
“”"
# Start a new project in Reality Capture (use the existing one)
project = rc.Project()
# Set the project unit to millimetres (laboratory units)
set_project_units_to_mm(project)
# Add the GCPs to the project
add_gcps_to_project(project, gcps)
# Align the images (Structure from Motion step)
project.alignImages() # Align images using GCPs
# Set the reconstruction region (optional step, depending on your project)
set_reconstruction_region(project) # Define a reconstruction region
# Build the 3D model at normal detail
project.buildModel(detail=rc.ModelDetail.Normal) # Build at normal detail
# Add texture to the model
project.buildTexturing(textureResolution=rc.TextureResolution.Medium) # Texture at medium resolution
# Export the model as an XYZ file (point cloud format)
output_folder = r"E:\Analogue Experiments\Topography\Flat Extrusion\Models"
output_path = os.path.join(output_folder, "model.xyz") # Name the output file appropriately
project.export(output_path, exportType=rc.ExportType.PointCloudXYZ) # Export as XYZ file
print(f"Processed images, built model with texture, and saved to {output_path}")
def batch_process_images(image_folder, gcp_file):
“”"
Process all images and their GCPs for the project.
“”"
# Load GCPs from the file
gcps = load_gcps(gcp_file)
# Process the images with the related GCPs
process_images(gcps)
Specify the folder where your images are located and the GCP file path
image_folder = “E:\Analogue Experiments\Topography\Flat Extrusion” # Update with your images folder path
gcp_file = “E:\Analogue Experiments\Topography\Flat Extrusion\GCPs.csv” # GCPs CSV file (ensure it’s in millimetres)
Start the batch processing
batch_process_images(image_folder, gcp_file)