Skip to content

Developing a Low Cost 2D Smoke PIV setup for the WindAI lab

Notifications You must be signed in to change notification settings

rfgzuid/LowCostPIV

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LowCostPIV

Software for the use of low-cost PIV set-ups, based on TorchPIV. This code has been developed for the use case of Smoke Image Velocimetry (SIV), but can also be used in conventional PIV applications. All code is implemented using the PyTorch library, which enables Cuda GPU acceleration.

Currently implemented tracking methods are:

  • Template matching: cross-correlation and Sum of Absolute Difference (SAD)
  • Optical flow, based on the Horn-Schunck method

Both methods have a multipass mode for large displacements.

Example of usage

Running main.py

video_file = "Cilinder.MOV"
fn = video_file.split(".")[0]

# reference frame specified first, then the range we want to analyse with SIV
frames = [0, *(i for i in range(225, 325))]

vid = Video(rf"Test Data/{video_file}", df='.png', indices=frames)
vid.create_frames()

processor = Processor(rf"Test Data/{fn}", df='.png')
processor.postprocess()

device = "cuda" if torch.cuda.is_available() else "cpu"
print(device)

capture_fps = 240.
scale = 0.02

siv = SIV(
    folder=rf"Test Data/{fn}_PROCESSED",
    device=device,
    window_size=64,
    overlap=32,
    search_area=(20, 20, 20, 20)
)

if f"{fn}_RESULTS.npy" not in os.listdir(f"Test Data"):
    x, y, vx, vy = siv.run(mode=1)
    res = np.array((x.cpu(), y.cpu(), vx.cpu(), vy.cpu()))
    np.save(rf"Test Data/{fn}_RESULTS", res)
else:
    print("Loading results...")
    res = np.load(rf"Test Data/{fn}_RESULTS.npy")

viewer = Viewer(rf"Test Data/{fn}_PROCESSED", playback_fps=30., capture_fps=capture_fps)

# viewer.play_video()
viewer.vector_field(res, scale)
# viewer.velocity_field(res, scale, 30, 'cubic')

The script runs through the following steps:

  • Capture video frames from a specified path
  • Pre-process the video frames (background removal)
  • Run SIV algorithm
  • Plot resulting velocity field

The input of the script is a smoke plume simulation. The result is shown below ...