This app uses YOLO to automatically detect cracks in images and applies image processing techniques to assess crack width. The entire workflow is packaged inside a VIKTOR web application.
Users upload an image using a drag-and-drop field. The app displays the uploaded image to confirm the action was successful, as shown below:
The image is sent to a YOLO model running locally through a Viktor Worker. The model detects cracks, segments them, and calculates crack widths using skeletonization. The processed result is sent back to the app, as shown below:
The app converts pixel measurements into millimeters using a known reference object in the image. It then plots a histogram to visualize the width distribution, as shown below:
Crack widths are compared with Eurocode, ACI, and BS standards. A table highlights acceptable and unacceptable values in green and red, making results easy to interpret, as shown below:
The following subsection outlines the required dependencies that your Python environment must have.
- Python: Version 3.11 or later.
- Operating System: Windows.
- GPU Support (Optional): CUDA-enabled GPU if you wish to use the PyTorch CUDA wheel.
The project depends on the following packages, you can create a requirements.txt
opencv-python>=4.11.0.86
torch>=2.6.0
torchaudio>=2.6.0
torchvision>=0.21.0
ultralytics>=8.3.102
scikit-image>=0.20.0
If you are using a CUDA-enabled GPU, install PyTorch and related packages from the CUDA-specific index before installing the remaining dependencies:
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txt
You can download the model weights by running this in a folder of your preference and in your Python development environment. The folder where the code below will be run should be added in the configuration file of the VIKTOR worker, as shown in the next section.
import os
import urllib.request
from ultralytics import YOLO
# Define the filename and the URL for the pretrained model
weight_filename = "crack_seg_yolov8n.pt"
pretrained_weights_url = "https://huggingface.co/OpenSistemas/YOLOv8-crack-seg/resolve/main/yolov8n/weights/best.pt"
# Download the model weights if the file does not already exist
if not os.path.exists(weight_filename):
print("Downloading pretrained crack segmentation model...")
urllib.request.urlretrieve(pretrained_weights_url, weight_filename)
print(f"Model downloaded and saved as '{weight_filename}'.")
else:
print(f"Model file '{weight_filename}' already exists; skipping download.")
# Load the downloaded model
model = YOLO(weight_filename)
print("Pretrained crack segmentation model loaded.")
The VIKTOR generic worker requires a config.yaml
file to be configured for this app to run properly. An example configuration is shown below:
executables:
run_model:
path: 'C:\PATH\TO\python.exe'
arguments:
- 'run_model.py'
workingDirectoryPath: 'C:\Path\TO\YOLO\MODEL\WEIGHTS'
maxParallelProcesses: 1
For more information, refer to the official documentation
This app is a demo showcasing the integration between VIKTOR and AI models such as YOLO. It demonstrates how image analysis and engineering logic can be combined in a single web application. If you plan to use it for real engineering applications, make sure to validate all results based on your own project needs and engineering judgment.