Explore how optical flow enables motion analysis in computer vision. Learn about sparse vs. dense flow, real-world applications, and integration with YOLO26.
Optical flow is the pattern of apparent motion of objects, surfaces, and edges in a visual scene caused by the relative motion between an observer and a scene. In the field of computer vision, this concept is fundamental for understanding temporal dynamics within video sequences. By analyzing the displacement of pixels between two consecutive frames, optical flow algorithms generate a vector field where each vector represents the direction and magnitude of movement for a specific point. This low-level visual cue enables artificial intelligence systems to perceive not just what is in an image, but how it is moving, bridging the gap between static image analysis and dynamic video understanding.
광학 흐름 계산은 일반적으로 밝기 불변성 가정에 의존하며, 이는 물체가 움직이는 동안에도 물체 상의 픽셀 강도가 프레임 간에 일정하게 유지된다는 것을 전제로 합니다. 알고리즘은 이 원리를 활용하여 두 가지 주요 접근법을 통해 운동 벡터를 구합니다:
While often used in tandem, it is vital to distinguish optical flow from object tracking. Optical flow is a low-level operation that describes instantaneous pixel motion; it does not inherently understand object identity or persistence.
In contrast, object tracking is a high-level task that locates specific entities and assigns them a consistent ID over time. Advanced trackers, such as those integrated into Ultralytics YOLO26, typically perform object detection to find the object and then use motion cues—sometimes derived from optical flow—to associate detections across frames. Optical flow answers "how fast are these pixels moving right now," whereas tracking answers "where did Car #5 go?"
픽셀 단위의 움직임 추정 능력은 다양한 정교한 기술의 기반이 됩니다:
The following example demonstrates how to compute dense optical flow using the OpenCV library, a standard tool in the computer vision ecosystem. This snippet uses the Farneback algorithm to generate a flow map between two consecutive frames.
import cv2
import numpy as np
# Simulate two consecutive frames (replace with actual image paths)
frame1 = np.zeros((100, 100, 3), dtype=np.uint8)
frame2 = np.zeros((100, 100, 3), dtype=np.uint8)
cv2.rectangle(frame1, (20, 20), (40, 40), (255, 255, 255), -1) # Object at pos 1
cv2.rectangle(frame2, (25, 25), (45, 45), (255, 255, 255), -1) # Object moved
# Convert to grayscale for flow calculation
prvs = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
next = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
# Calculate dense optical flow
flow = cv2.calcOpticalFlowFarneback(prvs, next, None, 0.5, 3, 15, 3, 5, 1.2, 0)
# Compute magnitude and angle of 2D vectors
mag, ang = cv2.cartToPolar(flow[..., 0], flow[..., 1])
print(f"Max motion detected: {np.max(mag):.2f} pixels")
For high-level applications requiring object persistence rather than raw pixel motion, users should consider the tracking modes available in Ultralytics YOLO11 and YOLO26. These models abstract the complexity of motion analysis, providing robust object IDs and trajectories out of the box for tasks ranging from traffic monitoring to retail analytics.