目标跟踪——OTB平台的Python版tracker使用
生活随笔
收集整理的這篇文章主要介紹了
目标跟踪——OTB平台的Python版tracker使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
注意:由于OTB不像VOT那樣有Python代碼接口,所以我是用Pysot測試平臺實現OTB評測功能。
方法:先安裝Pysot在系統上,Windows和Linux(Ubuntu發行版)都可以,我是用Windows系統做的。然后在網上搜集其他trakcers的評測結果,由于都是.mat格式的文件,要在Pysot里使用就得轉化成.txt格式。本人方法如下:
1. .mat文件轉換成.txt文件
import scipy.io as scio import pandas as pd import numpy as np import os import h5py import hdf5storage# ------------------------------ # 1. .mat文件轉換成.txt文件 # ------------------------------ # 注意:下面的代碼根據不同類型的.mat有所不同 可輸出.mat中的keys查看 path_matfile = "E:\\0_OTB_benchmark\\SiamRPN\\SiamRPN_OTB100" outpath = "E:\\0_OTB_benchmark\\SiamRPN\\SiamRPN_OTB100_txt" all_matfile_list = os.listdir(path_matfile)each_matfile_path = [os.path.join(path_matfile, matfile) for matfile in all_matfile_list] videos_name_txt = [video_name.replace('_SIAMRPN', '').replace('.mat', '').capitalize() + '.txt' for video_name in all_matfile_list]for i, matfile_path in enumerate(each_matfile_path):# data = scio.loadmat(matfile_path) # 有些類型的mat文件不能讀取data = hdf5storage.loadmat(matfile_path) # 兼容mat文件類型較多# 下面兩行有些.mat不同track_result = data['results'] # 有些tracker的鍵值為'result'track_result = track_result[0][0][0][0][0] # 有些為track_result[0][0][0][1]print(videos_name_txt[i])np.savetxt(os.path.join(outpath, videos_name_txt[i]), track_result, delimiter=',', fmt='%d')# ----------------------- # 2. 文件重命名 # ----------------------- # 有些trackers在OTB100或OTB50中生成的是小寫字母開頭的跟蹤結果,需要把首字母轉化成大寫字母,以匹配otb100.json或otb50.json(因為我下載的.json文件視頻的首字母都是大寫的) # 代碼依實際情況變化 src_path = "E:\\0_OTB_benchmark\\Pysot\\pysot-toolkit\\result\\Results_OTB100\\DaSiamRPN" dst_path = "E:\\0_OTB_benchmark\\Pysot\\pysot-toolkit\\result\\Results_OTB100\\DaSiamRPN_upper" all_filename = os.listdir(src_path)all_filename_path_old = [os.path.join(src_path, filename) for filename in all_filename if '.txt' in filename] all_filename_path_new = [os.path.join(dst_path, filename.capitalize()) for filename in all_filename] # .capitalize()將字符串首字母變為大寫for (old_file, new_file) in zip(all_filename_path_old, all_filename_path_new):os.renames(old_file, new_file) # 好像把原來的文件夾覆蓋掉了,先拷貝一份,以防萬一# 從OTB100中轉移OTB50數據 src_otb100_path = "E:\\0_OTB_benchmark\\Pysot\\pysot-toolkit\\result\\Results_OTB100" dst_otb50_path = "E:\\0_OTB_benchmark\\Pysot\\pysot-toolkit\\result\\Results_OTB50"template_tracker = os.path.join(dst_otb50_path, 'Initial_Method') template_videos = os.listdir(template_tracker)all_trackername = os.listdir(src_otb100_path) src_trackers = [os.path.join(src_otb100_path, src_tracker) for src_tracker in all_trackername]for tracker_file in all_trackername:if tracker_file not in os.listdir(dst_otb50_path):os.mkdir(os.path.join(dst_otb50_path, tracker_file))print(template_videos) print(all_trackername)for i, tracker in enumerate(src_trackers):each_tracker_videos = os.listdir(tracker)for video in template_videos:shutil.copyfile(os.path.join(tracker, video), os.path.join(dst_otb50_path, all_trackername[i], video))我將一些轉化好的OTB.txt文件傳到百度云上了,還有json文件。
注意:OTB50有些問題,大家先用OTB100測試
https://pan.baidu.com/s/1cl_7KabuKSUqVIjHysgPJA
提取碼:5ic7
2. 使用過程
參考github上的倉庫:這個倉庫不是我的。
https://github.com/StrangerZhang/pysot-toolkit
- 下載后的文件夾下有這些文件
先按照README里面將的測試一些trackers
注意: 我只測試了OTB,其他的沒有測試,不敢保證可以用。
將從百度云里下載的OTB100_trackers放到一個文件夾里。
下面是我在windows下的執行命令:
2020.1.12更新
安裝latex軟件
注意:用conda或者pip安裝latex包沒有用,不知道為什么,需要額外安裝一個Tex
- (windows系統)
注意:以下本人安裝完latex軟件后,親測使用Matplotlib可以畫出OTB下的評測圖。
1. 下載MiKTeX
官網下載地址:https://miktex.org/download
按照正常軟件傻瓜式安裝就行了。
2. 下載TexMaker
官網下載地址:https://www.xm1math.net/texmaker/
按照正常軟甲傻瓜式安裝
稍微配置一下TexMaker軟件:
接下來重啟一下電腦,然后運行python程序看看有沒有畫出來圖。
顯示的圖形:
- Ubuntu系統
MikTex下載地址:https://miktex.org/download#unx
安裝步驟:
Install on Linux
MiKTeX is available for selected Linux distributions.
Installing MiKTeX on Linux involves these steps:
- Register the GPG key with which MiKTeX installation packages and metadata is signed. The key ID is: D6BC243565B2087BC3F897C9277A7293F59E4889
- Register the installation source which contains the MiKTeX installation package. The installation source depends on the Linux distribution version.
Ubuntu 18.04 LTS (Bionic Beaver):
echo "deb http://miktex.org/download/ubuntu bionic universe" | sudo tee /etc/apt/sources.list.d/miktex.listUbuntu 16.04 LTS (Xenial Xerus):
echo "deb http://miktex.org/download/ubuntu xenial universe" | sudo tee /etc/apt/sources.list.d/miktex.list- Use the package management system to install MiKTeX.
- Finish the setup.
Before you can use MiKTeX, you have to finish the setup. You can use MiKTeX Console or, if you prefer the command line, miktexsetup.
Start MiKTeX Console to finish the setup
Search&click the MiKTeX Console icon to start MiKTeX Console:
注意:下面的圖片是windows下面的和ubuntu中的類似
找到MikTex Console軟件,然后執行下面的設置:
- 友好鏈接:目標跟蹤不同算法跟蹤框可視化圖
總結
以上是生活随笔為你收集整理的目标跟踪——OTB平台的Python版tracker使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL 字符串截取操作
- 下一篇: Win10下安装SqlServer201