资源简介
目标跟踪CSK算法python实现,附带中文注释和两个视频数据,可直接运行。
代码片段和文件信息
#!/usr/bin/env python
# -*- coding: utf-8 -*-
“““
This is a python reimplementation of the open source tracker in
http://www2.isr.uc.pt/~henriques/circulant/index.html
Found http://wiki.scipy.org/NumPy_for_Matlab_Users very useful
based on the work of João F. Henriques 2012
http://www.isr.uc.pt/~henriques
Rodrigo Benenson MPI-Inf 2013
http://rodrigob.github.io
“““
from __future__ import print_function
import os
import os.path
import sys
import glob
import time
from optparse import OptionParser
import scipy.misc
import pylab
debug = False
class CirculantMatrixTracker:
def __init__(self object_example):
“““
object_example是显示要跟踪的对象的图像
“““
return
def find(self image):
“““
将返回找到对象的x/y坐标和分数
“““
return
def update_template(self new_example forget_factor=1):
“““
更新跟踪模板,
new_example应该与大小相匹配
提供给构造函数的示例
“““
return
def load_video_info(video_path):
“““
加载给定路径中视频的所有相关信息:
图像文件列表(字符串的单元格数组),
初始位置(1x2),目标大小(1x2),是否将视频大小调整为一半(boolean),
以及用于精确计算的ground truth信息(Nx2 for N frames)。
坐标的排序始终是[y,x]。
返回视频的路径,因为如果图像位于子文件夹中,它可能会改变(这是MILTrack视频的默认设置)。
“““
# 加载 ground truth(MILTrack的格式)
text_files = glob.glob(os.path.join(video_path “*_gt.txt“))
assert text_files \
“No initial position and ground truth (*_gt.txt) to load.“
first_file_path = os.path.join(video_path text_files[0])
#f = open(first_file_path “r“)
#ground_truth = textscan(f ‘%f%f%f%f‘) # [x y width height]
#ground_truth = cat(2 ground_truth{:})
ground_truth = pylab.loadtxt(first_file_path delimiter=““)
#f.close()
# 设置初始位置和大小
first_ground_truth = ground_truth[0 :]
# target_sz包含height width
target_sz = pylab.array([first_ground_truth[3] first_ground_truth[2]])
# pos 包含 y x center
pos = [first_ground_truth[1] first_ground_truth[0]] + pylab.floor(target_sz / 2)
#try:
if True:
# 插入缺失的注释
# 每5帧中有4帧用零填充
for i in range(4): # x y width height
xp = range(0 ground_truth.shape[0] 5)
fp = ground_truth[xp i]
x = range(ground_truth.shape[0])
ground_truth[: i] = pylab.interp(x xp fp)
# store positions instead of boxes
ground_truth = ground_truth[: [1 0]] + ground_truth[: [3 2]] / 2
#except Exception as e:
else:
print(“Failed to gather ground truth data“)
#print(“Error“ e)
# ok wrong format or we just don‘t have ground truth data.
ground_truth = []
#列出所有帧。 首先,尝试MILTrack的格式,其中的初始和最后帧号存储在文本文件中。 如果它不起作用,
#尝试加载文件夹中的所有png/jpg文件。
text_files = glob.glob(os.path.join(video_path “*_frames.txt“))
if text_files:
first_file_path = os.path.join(video_path text_files[0])
#f = open(first_file_path “r“)
#frames = textscan(f ‘%f%f‘)
frames = pylab.loadtxt(first_file_path delimiter=““ dtype=int
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 459 2018-11-12 20:18 CSK\.idea\CSK.iml
文件 233 2018-11-12 20:17 CSK\.idea\misc.xm
文件 258 2018-11-12 20:17 CSK\.idea\modules.xm
文件 13315 2018-11-12 21:37 CSK\.idea\workspace.xm
文件 319 2013-11-05 04:56 CSK\circulant_matrix_tracker-master\.gitignore
文件 17626 2018-11-12 21:36 CSK\circulant_matrix_tracker-master\circulant_matrix_tracker.py
文件 7 2008-06-20 13:43 CSK\circulant_matrix_tracker-master\data\david\david_fr
文件 4784 2008-06-20 13:43 CSK\circulant_matrix_tracker-master\data\david\david_gt.txt
文件 12847 2009-10-27 12:04 CSK\circulant_matrix_tracker-master\data\david\david_MIL_scale_TR001.txt
文件 12307 2009-10-27 12:05 CSK\circulant_matrix_tracker-master\data\david\david_MIL_scale_TR002.txt
文件 12711 2009-10-27 12:05 CSK\circulant_matrix_tracker-master\data\david\david_MIL_scale_TR003.txt
文件 13406 2009-10-27 12:05 CSK\circulant_matrix_tracker-master\data\david\david_MIL_scale_TR004.txt
文件 12955 2009-10-27 12:06 CSK\circulant_matrix_tracker-master\data\david\david_MIL_scale_TR005.txt
文件 6407 2009-03-24 00:08 CSK\circulant_matrix_tracker-master\data\david\david_MIL_TR001.txt
文件 6383 2009-03-24 00:09 CSK\circulant_matrix_tracker-master\data\david\david_MIL_TR002.txt
文件 6374 2009-03-24 00:10 CSK\circulant_matrix_tracker-master\data\david\david_MIL_TR003.txt
文件 6446 2009-03-24 00:11 CSK\circulant_matrix_tracker-master\data\david\david_MIL_TR004.txt
文件 6247 2009-03-24 00:12 CSK\circulant_matrix_tracker-master\data\david\david_MIL_TR005.txt
文件 28043 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00001.png
文件 28791 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00002.png
文件 29125 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00003.png
文件 28900 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00004.png
文件 29726 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00005.png
文件 30519 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00006.png
文件 31183 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00007.png
文件 30521 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00008.png
文件 29941 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00009.png
文件 29738 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00010.png
文件 30519 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00011.png
文件 30209 2008-03-13 14:25 CSK\circulant_matrix_tracker-master\data\david\imgs\img00012.png
............此处省略976个文件信息
评论
共有 条评论