주요 콘텐츠

opticalFlowRAFT

RAFT 딥러닝 알고리즘을 사용하여 광학 흐름 추정

R2024b 이후

    설명

    opticalFlowRAFT 객체를 사용하여 RAFT(Recurrent All-pairs Field Transforms) 알고리즘으로 이전 및 현재 비디오 프레임 간의 모션 방향과 속도를 추정합니다. 이 알고리즘은 Kubric[3] 데이터셋에서 훈련된 딥러닝 신경망을 사용합니다. RAFT 광학 흐름 추정 알고리즘은 특히 텍스처가 거의 없는 영역이나 모션 블러가 있는 영역, 그리고 카메라 움직임이 복잡한 경우에서도 정확도가 높아 Farneback과 같은 방식보다 더 뛰어난 성능을 보입니다. 이 알고리즘은 픽셀당 밀도가 높고 매우 정확한 추정값을 제공하지만 더 많은 시간과 메모리가 필요합니다. 더 빠르지만 정확도가 낮은 고밀도 광학 흐름 추정을 위해서는 딥러닝에 의존하지 않는 기존의 비전 알고리즘인 opticalFlowFarneback을 선택하십시오.

    참고

    이 기능을 사용하려면 Deep Learning Toolbox™와 Computer Vision Toolbox™ Model for RAFT Optical Flow Estimation이 필요합니다. 애드온 탐색기에서 Computer Vision Toolbox Model for RAFT Optical Flow Estimation을 설치할 수 있습니다. 애드온 설치에 대한 자세한 내용은 애드온을 받고 관리하기를 참조하십시오.

    생성

    설명

    flowModel = opticalFlowRAFT는 이전 및 현재 비디오 프레임 간의 모션 방향과 속도를 추정하는 optical flow 객체를 반환합니다.

    예제

    객체 함수

    estimateFlowEstimate optical flow between two frames
    resetReset the internal state of the optical flow estimation object

    예제

    모두 축소

    RAFT optical flow 객체를 만듭니다.

    flowModel = opticalFlowRAFT;

    입력 비디오 파일을 읽을 객체를 만듭니다.

    vidReader = VideoReader("visiontraffic.avi",CurrentTime=11);

    광학 흐름 벡터를 시각화하는 사용자 지정 Figure 창을 생성합니다.

    h = figure;
    movegui(h);
    hViewPanel = uipanel(h, Position=[0 0 1 1], Title="Plot of Optical Flow Vectors");
    hPlot = axes(hViewPanel);

    광학 흐름을 추정하기 위해 연속적인 영상 프레임을 읽습니다. 현재 프레임을 표시하고 퀴버 플롯을 사용하여 광학 흐름 벡터를 겹쳐 표시합니다. estimateFlow 함수는 연속적인 두 프레임 간의 광학 흐름을 계산합니다.

    이 함수는 내부적으로 이전 프레임을 저장하고 광학 흐름 추정에 묵시적으로 활용합니다. 따라서 프레임 시퀀스에서 이 함수를 처음 호출하면 흐름이 0으로 반환됩니다. 이는 실제 이전 프레임이 없기 때문에 초기 프레임이 현재 프레임과 이전 프레임 모두로 간주되며, 그 결과 두 프레임 사이에서 검출할 수 있는 모션이 없기 때문입니다. 이는 opticalFlowFarneback과 같은 기존 광학 흐름 추정 방법의 인수 구조체 및 동작과 일치합니다.

    while hasFrame(vidReader)
        frame = readFrame(vidReader);
        flow = estimateFlow(flowModel,frame);
    
        imshow(frame)
        hold on
        plot(flow,DecimationFactor=[10 10],ScaleFactor=0.45,Parent=hPlot,color="g");
        hold off
        pause(10^-3)
    end

    비디오 처리가 완료된 후 opticalFlowRAFT 객체를 재설정합니다. 이렇게 하면 저장된 이전 프레임을 포함하여 객체의 내부 상태가 삭제됩니다.

    reset(flowModel);

    참고 문헌

    [1] Teed, Zachary, and Jia Deng. RAFT: Recurrent All-Pairs Field Transforms for Optical Flow. Proceedings of the 16th European Conference on Computer Vision. 2020.

    [2] Shah, Neelay, Prajnan Goswami, and Huaizu Jiang. EzFlow: A modular PyTorch library for optical flow estimation using neural networks. 2021. Web. https://github.com/neu-vi/ezflow.

    [3] Greff, Klaus, Francois Belletti, Lucas Beyer, Carl Doersch, Yilun Du, Daniel Duckworth, David J. Fleet et al. Kubric: A scalable dataset generator. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition, pp. 3749-3761. 2022.

    버전 내역

    R2024b에 개발됨