>  기사  >  백엔드 개발  >  SORT 추적 알고리즘과 Python 구현 예에 대한 간략한 소개

SORT 추적 알고리즘과 Python 구현 예에 대한 간략한 소개

WBOY
WBOY앞으로
2024-01-23 23:18:051175검색

SORT 추적 알고리즘과 Python 구현 예에 대한 간략한 소개

SORT(Simple Online and Realtime Tracking)는 Kalman 필터 기반의 표적 추적 알고리즘으로, 실시간 장면에서 움직이는 표적을 강력하게 추적할 수 있습니다. SORT 알고리즘은 원래 Alex Bewley 등이 2016년에 제안했습니다. 영상 감시, 자율 주행, 로봇 내비게이션 등과 같은 컴퓨터 비전 분야의 다양한 응용 분야에서 널리 사용되었습니다.

SORT 알고리즘은 주로 칼만 필터링과 헝가리어 알고리즘이라는 두 가지 핵심 아이디어를 기반으로 합니다. 칼만 필터는 시스템 상태를 추정하기 위한 알고리즘으로, 시스템의 동적 모델과 센서 측정을 사용하여 시스템 상태를 예측하고 업데이트함으로써 상태 추정의 정확도를 향상시킬 수 있습니다. 헝가리 알고리즘은 이분 그래프에서 최대 가중치 매칭 문제를 해결하는 데 사용되는 알고리즘입니다. 이 알고리즘은 주어진 이분 그래프에서 최대 가중치 매칭을 찾을 수 있습니다.

SORT 알고리즘의 주요 단계는 다음과 같습니다.

대상 탐지: 대상 탐지 알고리즘(예: YOLO, SSD 등)을 사용하여 현재 프레임에서 대상 정보를 추출합니다.

상태 예측: 추적된 각 대상에 대해 Kalman 필터를 사용하여 상태를 예측합니다.

데이터 연관: 현재 프레임의 예측 상태와 대상 정보를 기반으로 헝가리 알고리즘을 사용하여 데이터 연관을 수행하여 현재 프레임에서 추적된 각 대상에 해당하는 대상을 찾습니다.

상태 업데이트: 추적된 각 대상에 대해 Kalman 필터를 사용하여 상태를 업데이트합니다.

타겟 출력: 추적된 각 타겟의 상태 정보와 추적 결과를 출력합니다.

컴퓨터 비전에서 SORT 알고리즘은 다양한 표적 추적 시나리오에 적용될 수 있습니다. 예를 들어, 비디오 감시에서 SORT 알고리즘은 움직이는 대상을 실시간으로 추적할 수 있으므로 현장의 비정상적인 동작을 감지하고 조기 경고할 수 있습니다. 자율 주행 분야에서 SORT 알고리즘은 다른 차량, 보행자 및 기타 교통 참가자를 추적하여 차량의 자율 주행 및 장애물 회피를 달성할 수 있습니다. 로봇 탐색에서 SORT 알고리즘은 움직이는 목표를 추적하여 로봇의 자율 탐색 및 장애물 회피를 달성할 수 있습니다.

다음은 Python으로 구현한 간단한 예제 코드입니다.

#python
import numpy as np
from filterpy.kalman import KalmanFilter
from scipy.optimize import linear_sum_assignment

class Track:

def init(self,prediction,track_id,track_lifetime):
    self.prediction=np.atleast_2d(prediction)
    self.track_id=track_id
    self.track_lifetime=track_lifetime
    self.age=0
    self.total_visible_count=1
    self.consecutive_invisible_count=0

def predict(self, kf):
    self.prediction = kf.predict()
    self.age += 1

def update(self, detection, kf):
    self.prediction = kf.update(detection)
    self.total_visible_count += 1
    self.consecutive_invisible_count = 0

def mark_missed(self):
    self.consecutive_invisible_count += 1

def is_dead(self):
    return self.consecutive_invisible_count >= self.track_lifetime

class Tracker:

def init(self,track_lifetime,detection_variance,process_variance):
    self.next_track_id=0
    self.tracks=[]
    self.track_lifetime=track_lifetime
    self.detection_variance=detection_variance
    self.process_variance=process_variance
    self.kf=KalmanFilter(dim_x=4,dim_z=2)
    self.kf.F=np.array([[1,0,1,0],
                    [0,1,0,1],
                    [0,0,1,0],
                    [0,0,0,1]])
    self.kf.H=np.array([[1,0,0,0],
                    [0,1,0,0]])
    self.kf.R=np.array([[self.detection_variance,0],
                    [0,self.detection_variance]])
    self.kf.Q=np.array([[self.process_variance,0,0,0],
                    [0,self.process_variance,0,0],
                    [0,0,self.process_variance,0],
                    [0,0,0,self.process_variance]])

def update(self, detections):
    # predict track positions using Kalman filter
    for track in self.tracks:
        track.predict(self.kf)

    # associate detections with tracks using Hungarian algorithm
    if len(detections) > 0:
        num_tracks = len(self.tracks)
        num_detections = len(detections)
        cost_matrix = np.zeros((num_tracks, num_detections))
        for i, track in enumerate(self.tracks):
            for j, detection in enumerate(detections):
                diff = track.prediction - detection
                distance = np.sqrt(diff[0,0]**2 + diff[0,1]**2)
                cost_matrix[i,j] = distance
        row_indices, col_indices = linear_sum_assignment(cost_matrix)
        unassigned_tracks = set(range(num_tracks)) - set(row_indices)
        unassigned_detections = set(range(num_detections)) - set(col_indices)
        for i, j in zip(row_indices, col_indices):
            self.tracks[i].update(detections[j], self.kf)
        for i in unassigned_tracks:
            self.tracks[i].mark_missed()
        for j in unassigned_detections:
            new_track = Track(detections[j], self.next_track_id, self.track_lifetime)
            self.tracks.append(new_track)
            self.next_track_id += 1

    # remove dead tracks
    self.tracks = [track for track in self.tracks if not track.is_dead()]

    # return list of track positions
    return [track.prediction.tolist()[0] for track in self.tracks]

위 코드는 간단한 SORT 추적 알고리즘을 구현합니다. Kalman 필터를 사용하여 목표 위치와 속도를 예측하고 추정한 다음 헝가리 알고리즘을 사용하여 수행합니다. 표적을 추적하고, 표적의 연속 보이지 않는 횟수를 기반으로 표적의 사망 여부를 최종적으로 판단하고 죽은 표적을 제거합니다. 위의 코드는 간단한 SORT 추적 알고리즘을 구현하는데, 칼만 필터를 사용하여 표적의 위치와 속도를 예측하고 추정한 다음 헝가리 알고리즘을 사용하여 표적을 연관시키고 최종적으로 표적의 사망 여부를 판단하고 그 숫자를 기반으로 사망을 제거합니다. 연속된 목표의 보이지 않는 시간.

SORT 알고리즘 외에도 칼만 필터, 입자 필터, 다중 표적 추적 등 다양한 표적 추적 알고리즘이 있습니다. 각 알고리즘에는 적용 가능한 시나리오, 장점 및 단점이 있습니다. 실제 적용에서는 특정 시나리오와 요구 사항을 기반으로 표적 추적에 적합한 알고리즘을 선택해야 합니다.

위 내용은 SORT 추적 알고리즘과 Python 구현 예에 대한 간략한 소개의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 163.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제