Skip to content

Commit 27a32c5

Browse files
Copilotalexarje
andauthored
Clarify GPU GpuMat swap comments in flow.py
Agent-Logs-Url: https://github.com/fourMs/MGT-python/sessions/37e34660-f746-453a-b428-74fc3f53285f Co-authored-by: alexarje <114316+alexarje@users.noreply.github.com>
1 parent 841efa6 commit 27a32c5

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

musicalgestures/_flow.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ def dense(
167167
gpu_next_frame.upload(next_frame)
168168
gpu_flow_result = farneback_gpu.calc(gpu_prev_frame, gpu_next_frame, None)
169169
flow = gpu_flow_result.download()
170-
# Swap references so gpu_next_frame becomes the next prev without
171-
# allocating a new GpuMat object each frame
170+
# Swap references so gpu_next_frame becomes gpu_prev_frame for the
171+
# next iteration without allocating a new GpuMat object each frame
172172
gpu_prev_frame, gpu_next_frame = gpu_next_frame, gpu_prev_frame
173173
else:
174174
flow = cv2.calcOpticalFlowFarneback(prev_frame, next_frame, None, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags)
@@ -442,7 +442,8 @@ def sparse(
442442
gpu_p1, gpu_st = lk_gpu.calc(gpu_old_gray, gpu_frame_gray, gpu_p0, None, None)
443443
p1 = gpu_p1.download()
444444
st = gpu_st.download()
445-
# Swap references to avoid allocating a new GpuMat each frame
445+
# Swap references so current frame becomes old frame for next
446+
# iteration, avoiding new GpuMat allocation each frame
446447
gpu_old_gray, gpu_frame_gray = gpu_frame_gray, gpu_old_gray
447448
else:
448449
p1, st, err = cv2.calcOpticalFlowPyrLK(

0 commit comments

Comments
 (0)