본문 바로가기

심화/영상 - 구현 및 OpenCV

Optical Flow

반응형

출처 : https://docs.opencv.org/master/d4/dee/tutorial_optical_flow.html

 

OpenCV: Optical Flow

Prev Tutorial: Meanshift and Camshift Next Tutorial: Cascade Classifier Goal In this chapter, We will understand the concepts of optical flow and its estimation using Lucas-Kanade method. We will use functions like cv.calcOpticalFlowPyrLK() to track featur

docs.opencv.org


1. 학습 목표

- Optical Flow 개념을 이해하고, Lucas-Kanade 방법을 파악한다.

- 비디오 상에서 특징점을 추척하기 위해 cv.calcOpticalFlowPyrLK() 사용법을 파악한다.

- Dense Optical Flow를 생성하기 위해 cv.calcOpticalFlowFarneback() 사용법을 파악한다.

 

2. Optical Flow 개념

- 광학 흐름(Optical Flow)는 연속된 프레임으로 표현되는 물체의 움직임(혹은 카메라 움직임)을 나타내는 패턴이다.

- 2D 변위 벡터 형태

3. 응용 분야

- Structure From Motion

- Video Compression

- Video Stabilization

 

4. Optical Flow의 가정(Assumption)

- 물체의 픽셀 강도는 연속된 프레임간 바뀌지 않는다.

- 이웃하는 픽셀은 유사 움직임을 갖는다.

 

5. Lucas-Kanade Optical Flow in OpenCV

- 입력 : 이전 프레임, 현재 프레임, 이전 특징점을 입력으로 받는다.

- 출력 : 이전 프레임에서의 특징점(p0)이, 현재 프레임에서도 추적될 경우 'st=1'을 반환한다.

           특징점이 이동한 새로운 위치(p1)도 반환한다.

# Example

while(1):

    # calculate optical flow
    p1, st, err = cv.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params)
    
    # Select good points
    if p1 is not None:
      good_new = p1[st==1]
      good_old = p0[st==1]
      
    # draw the tracks
    for i,(new,old) in enumerate(zip(good_new, good_old)):
        a,b = new.ravel()
        c,d = old.ravel()
        mask = cv.line(mask, (int(a),int(b)),(int(c),int(d)), color[i].tolist(), 2)
        frame = cv.circle(frame,(int(a),int(b)),5,color[i].tolist(),-1)
    img = cv.add(frame,mask)

 

Optical Flow 예시 in Video

 

Optical Flow in Single Image

※ 자세한 사용법은 링크를 참고한다.

 


 

반응형

'심화 > 영상 - 구현 및 OpenCV' 카테고리의 다른 글

erode & dilate  (2) 2022.10.29
ORB (Oriented FAST and Rotated BRIEF)  (0) 2022.03.15
Fast Algorithm for Corner Detection  (0) 2021.06.19
Pillow Utils  (0) 2021.02.21
[OpenCV + WebApp] 환경 Setting  (0) 2020.08.24