diff --git a/.gitattributes b/.gitattributes index d35c378b579f0abfdace8902ec279f69d92750f9..3f2f3817db284d380637e0a9f8a401d255abd7ac 100644 --- a/.gitattributes +++ b/.gitattributes @@ -68,3 +68,22 @@ DETRAC/DETRAC-Test-Annotations-XML/DETRAC-Test-Annotations-XML/MVI_40855.xml fil DETRAC/DETRAC-Test-Annotations-XML/DETRAC-Test-Annotations-XML/MVI_40863.xml filter=lfs diff=lfs merge=lfs -text DETRAC/DETRAC-Test-Annotations-XML/DETRAC-Test-Annotations-XML/MVI_40864.xml filter=lfs diff=lfs merge=lfs -text DETRAC/DETRAC-Test-Annotations-XML/DETRAC-Test-Annotations-XML/MVI_40892.xml filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/AP_DET_EVAL.exe filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/CLEAR_MOT_EVAL.exe filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/DETRAC_DET_EVAL.exe filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/DETRAC_MOT_EVAL.exe filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexa64 filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexmaci filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexmaci64 filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker.exe filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker.pdb filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_core231.dll filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_highgui231.dll filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_imgproc231.dll filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/tbb.dll filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker.exe filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker.pdb filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_core231.dll filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_highgui231.dll filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_imgproc231.dll filter=lfs diff=lfs merge=lfs -text +DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/tbb.dll filter=lfs diff=lfs merge=lfs -text diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/DETRAC_experiment.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/DETRAC_experiment.m new file mode 100644 index 0000000000000000000000000000000000000000..81e5fe3e8579bceba7c4b4a8d7a7d9e164a3af18 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/DETRAC_experiment.m @@ -0,0 +1,28 @@ +% This script can be used to execute the tracking experiments or evaluate the detection results on the UA-DETRAC benchmark +% Copyright (C)2016 The UA-DETRAC Group + +% This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +% This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +% You should have received a copy of the GNU General Public License along with this program. If not, see . + +clear, clc, close all; +warning off all; +global options sequences tracker + +%% add the path of functions +addpath(genpath('utils')); +addpath(genpath('evaluation')); +addpath(genpath('display')); + +%% input the name of the tracker +tracker.trackerName = 'GOG'; % ignore this line when evaluating detection results +%% initialize the parameters for evalution +options = initialize_environment(); +%% load the dataset +sequences = load_datasets(); +%% evaluate the tracker +run_experiment(); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/README.md b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b5d78df817589f9c64d3fd56cc3621d82e2a6df7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/README.md @@ -0,0 +1,71 @@ +The DETRAC-MOT evaluation toolkit +====================== + +This is the official detection/tracking evaluation kit for the [DETection and tRACking (DETRAC) Benchmark](http://detrac-db.rit.albany.edu/), +which contains the actual evaluation toolkit as a set of Matlab (Octave compatible) scripts, a readme documentation and several state-of-the-art tracking algorithms. +You can find more informations from our paper: [arXiv](http://arxiv.org/abs/1511.04136). + +In addition, if you use the DETRAC benchmark or the evaluation toolkit, please cite the paper: +@article{DETRAC:CoRR:WenDCLCQLYL15, + author = {Longyin Wen and Dawei Du and Zhaowei Cai and Zhen Lei and Ming{-}Ching Chang and + Honggang Qi and Jongwoo Lim and Ming{-}Hsuan Yang and Siwei Lyu}, + title = { {DETRAC:} {A} New Benchmark and Protocol for Multi-Object Detection and Tracking}, + journal = {arXiv CoRR}, + volume = {abs/1511.04136}, + year = {2015} +} + +Enquiries, Questions and Comments +-------------------------------- + +If you have any further enquiries, questions, or comments, please find the information on the website: [DETRAC homepage](http://detrac-db.rit.albany.edu/), +or contact us: ua.detrack@gmail.com or lywen.cv.workbox@gmail.com. Besides, the QQ Group (387090533) is available to facilitate discussion. +If you find any bug in the toolkit, please inform us. + +You can also subscribe to the DETRAC [mailing list](http://detrac-db.rit.albany.edu/auth/register/) to receive news about the benchmark and important software updates. + +Platform Support +---------------- + +The toolkit is written in Matlab with executable binaries as well as support for multiple versions of Matlab (at the moment it was tested with versions from 2013 to 2015). + +The code should be run on Windows system. However, it is hard to verify this on all versions and system configurations. +If you find there exists some problems to run it on your computer, please contact us as soon as possible. + +Tracker Modules +------- + +The tracker module contains several tracking related functions. For the proposed tracker, you should create a main function like below: + +[stateInfo, speed] = run_tracker(curSequence, baselinedetections); + +**Input**: There are two input variables available for the tracker: + +* 'curSequence' - A cell containing the sequence information. + +* 'baselinedetections' - A matrix containing comma-separated values that denote the detection bounding box and the detection score of the object. + +**Output**: the results file will be produced after execution. + +* 'stateInfo' - A struct containing the trajectory positions of the tacker (i.e., LX, LY, W, H). + +* 'speed' - A variable indicating the running speed of the tracker. This is an additional measure. + +If you want to submit the tracking results for comparison, you should put the code of the tracker into the path 'trackers/' of the toolkit at first. + +How to run your code +------- + +1. Open the 'initialize_enviroment.m' function, and set the parameters as follows: + a) make sure the images, detections and annotations are in the right path. + b) select the evaluation type, i.e., Detection and Tracking. + c) select the sequences for evaluation, i.e., DETRAC-Train, DETRAC-Test, and DETRAC-Free. + d) if you chose 'DETRAC-Free', edit the 'sequences.txt' file to select the evaluated sequences you want. +2. Open the 'DETRAC_experiment.m' function, and input the name of the tracker if you chose 'Tracking'. +3. Run the 'DETRAC_experiment.m' function for evaluation. + +More details are presented on the website http://detrac-db.rit.albany.edu/instructions. + +To ease your first encounter with the code, we provide several source codes of state-of-the-art trackers in the toolkit, including CEM, CMOT, DCT, FH2T, GOG, H2T, IHTILS and RMOT. +Specifically, the FH2T and RMOT methods are not included in the arXiv paper due to the time issue. +If you have any further questions about the trackers, please contact to the original authors of the tracker. \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/AP_DET_EVAL.exe b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/AP_DET_EVAL.exe new file mode 100644 index 0000000000000000000000000000000000000000..2e26790282a73c8a83462c2819eebe258055105a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/AP_DET_EVAL.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:40d310fb9e8cac4fb85b58008a7680fc0ba56cd44b7b57b77519d4c4097f50d1 +size 310444032 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/CLEAR_MOT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/CLEAR_MOT.m new file mode 100644 index 0000000000000000000000000000000000000000..985d9cc68305e075023df1992c9b2f53d2e8f5c3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/CLEAR_MOT.m @@ -0,0 +1,281 @@ +function [metrics, metricsInfo] = CLEAR_MOT(gtInfo,stateInfo) +% compute CLEAR MOT and other metrics +% +% metrics contains the following +% [1] recall - recall = percentage of detected targets +% [2] precision - precision = percentage of correctly detected targets +% [3] FAR - number of false alarms per frame +% [4] GT - number of ground truth trajectories +% [5-7] MT, PT, ML - number of mostly tracked, partially tracked and mostly lost trajectories +% [8] falsepositives- number of false positives (FP) +% [9] missed - number of missed targets (FN) +% [10] idswitches - number of id switches (IDs) +% [11] FRA - number of fragmentations +% [12] MOTA - Multi-object tracking accuracy in [0,100] +% [13] MOTP - Multi-object tracking precision in [0,100] (3D) / [td,100] (2D) +% [14] MOTAL - Multi-object tracking accuracy in [0,100] with log10(idswitches) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% default options: 2D +options.eval3d = false; % only bounding box overlap +options.td = 0.7; % threshold 70% + +td = options.td; + +assert(length(gtInfo.frameNums)==length(stateInfo.frameNums), ... + 'Ground Truth and state must be of equal length'); +if(gtInfo.frameNums(1)~=stateInfo.frameNums(1)) + gtInfo.frameNums = gtInfo.frameNums + stateInfo.frameNums(1) - gtInfo.frameNums(1); +end +assert(all(gtInfo.frameNums==stateInfo.frameNums), ... + 'Ground Truth and state must contain equal frame numbers'); + +% check if all necessery info is available +if options.eval3d + assert(all(isfield(gtInfo,{'Xgp','Ygp'})), ... + 'Ground Truth Ground Plane coordinates needed for 3D evaluation'); + assert(all(isfield(stateInfo,{'Xgp','Ygp'})), ... + 'Ground Plane coordinates needed for 3D evaluation'); +else + assert(all(isfield(gtInfo,{'X','Y','W','H'})), ... + 'Ground Truth coordinates X,Y,W,H needed for 2D evaluation'); + assert(all(isfield(stateInfo,{'Xi','Yi','W','H'})), ... + 'State coordinates Xi,Yi,W,H needed for 2D evaluation'); + +end + +gtInd=~~gtInfo.X; +stInd=~~stateInfo.X; + +[Fgt, Ngt]=size(gtInfo.X); +[F, N]=size(stateInfo.X); + +aspectRatio=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); + + +metricsInfo.names.long = {'Recall','Precision','False Alarm Rate', ... + 'GT Tracks','Mostly Tracked','Partially Tracked','Mostly Lost', ... + 'False Positives', 'False Negatives', 'ID Switches', 'Fragmentations', ... + 'MOTA','MOTP', 'MOTA Log'}; + +metricsInfo.names.short = {'Rcll','Prcn','FAR', ... + 'GT','MT','PT','ML', ... + 'FP', 'FN', 'IDs', 'FM', ... + 'MOTA','MOTP', 'MOTAL'}; + +metricsInfo.widths.long = [6 9 16 9 14 17 11 15 15 11 14 5 5 8]; +metricsInfo.widths.short = [5 5 5 3 3 3 3 4 4 3 3 5 5 5]; + +metricsInfo.format.long = {'.1f','.1f','.2f', ... + 'i','i','i','i', ... + 'i','i','i','i', ... + '.1f','.1f','.1f'}; + +metricsInfo.format.short=metricsInfo.format.long; + + +metrics=zeros(1,14); +metrics(9)=numel(find(gtInd)); % False Negatives (missed) +metrics(7)=Ngt; % Mostly Lost + +% nothing to be done, if state is empty +if ~N, return; end + +% mapping +M=zeros(F,Ngt); + +mme=zeros(1,F); % ID Switchtes (mismatches) +c=zeros(1,F); % matches found +fp=zeros(1,F); % false positives +m=zeros(1,F); % misses = false negatives +g=zeros(1,F); +d=zeros(F,Ngt); % all distances; +ious=Inf*ones(F,Ngt); % all overlaps + +matched=@matched2d; +if options.eval3d, matched=@matched3d; end + +alltracked=zeros(F,Ngt); +allfalsepos=zeros(F,N); + +for t=1:F + g(t)=numel(find(gtInd(t,:))); + + % mapping for current frame + if t>1 + mappings=find(M(t-1,:)); + for map=mappings + if gtInd(t,map) && stInd(t,M(t-1,map)) && matched(gtInfo,stateInfo,t,map,M(t-1,map),td*0.8) + M(t,map)=M(t-1,map); + end + end + end + + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + + if options.eval3d + cost = zeros(numel(GTsNotMapped), numel(EsNotMapped)); + for o = 1:numel(GTsNotMapped) + GT = [gtInfo.Xgp(t,GTsNotMapped(o)), gtInfo.Ygp(t,GTsNotMapped(o))]; + for e = 1:numel(EsNotMapped) + E = [stateInfo.Xgp(t,EsNotMapped(e)), stateInfo.Ygp(t,EsNotMapped(e))]; + cost(o,e)=norm(GT-E); + end + end + cost(cost > td) = Inf; + assignLabel = munkres(cost); + for i = 1:numel(assignLabel) + if(assignLabel(i)) + M(t, GTsNotMapped(i)) = EsNotMapped(assignLabel(i)); + end + end + + else + allisects=zeros(Ngt,N); maxisect=Inf; + while maxisect > td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 + for o=GTsNotMapped + GT=[gtInfo.X(t,o)-gtInfo.W(t,o)/2 ... + gtInfo.Y(t,o)-gtInfo.H(t,o) ... + gtInfo.W(t,o) gtInfo.H(t,o) ]; + for e=EsNotMapped + E=[stateInfo.Xi(t,e)-stateInfo.W(t,e)/2 ... + stateInfo.Yi(t,e)-stateInfo.H(t,e) ... + stateInfo.W(t,e) stateInfo.H(t,e) ]; + allisects(o,e)=boxiou(GT(1),GT(2),GT(3),GT(4),E(1),E(2),E(3),E(4)); + end + end + [maxisect, cind]=max(allisects(:)); + + if maxisect >= td + [u, v]=ind2sub(size(allisects),cind); + M(t,u)=v; + allisects(:,v)=0; + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + end + + end + end + + curtracked=find(M(t,:)); + + + alltrackers=find(stInd(t,:)); + mappedtrackers=intersect(M(t,find(M(t,:))),alltrackers); + falsepositives=setdiff(alltrackers,mappedtrackers); + + alltracked(t,:)=M(t,:); + allfalsepos(t,1:length(falsepositives))=falsepositives; + + %% mismatch errors + if t>1 + for ct=curtracked + lastnotempty=find(M(1:t-1,ct),1,'last'); + if gtInd(t-1,ct) && ~isempty(lastnotempty) && M(t,ct)~=M(lastnotempty,ct) + mme(t)=mme(t)+1; + end + end + end + + c(t)=numel(curtracked); + for ct=curtracked + eid=M(t,ct); + if options.eval3d + d(t,ct)=norm([gtInfo.Xgp(t,ct) gtInfo.Ygp(t,ct)] - ... + [stateInfo.Xgp(t,eid) stateInfo.Ygp(t,eid)]); + else + gtLeft=gtInfo.X(t,ct)-gtInfo.W(t,ct)/2; + gtTop=gtInfo.Y(t,ct)-gtInfo.H(t,ct); + gtWidth=gtInfo.W(t,ct); gtHeight=gtInfo.H(t,ct); + + stLeft=stateInfo.Xi(t,eid)-stateInfo.W(t,eid)/2; + stTop=stateInfo.Yi(t,eid)-stateInfo.H(t,eid); + stWidth=stateInfo.W(t,eid); stHeight=stateInfo.H(t,eid); + ious(t,ct)=boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight); + end + end + + + fp(t)=numel(find(stInd(t,:)))-c(t); + m(t)=g(t)-c(t); + + +end + +missed=sum(m); +falsepositives=sum(fp); +idswitches=sum(mme); + +if options.eval3d + MOTP=(1-sum(sum(d))/sum(c)/td) * 100; % avg distance to [0,100] +else + MOTP=sum(ious(ious>=td & ious0)); + if(gtlength/gttotallength >= 0.8 && trlengtha/gttotallength < 0.2) + MTstatsa(i)=3; + elseif(t>=find(gtInd(:,i),1,'last') && trlengtha/gttotallength <= 0.8) + MTstatsa(i)=2; + elseif trlengtha/gttotallength >= 0.8 + MTstatsa(i)=1; + end +end +% MTstatsa +MT=numel(find(MTstatsa==1));PT=numel(find(MTstatsa==2));ML=numel(find(MTstatsa==3)); + +%% fragments +fr=zeros(1,Ngt); +for i=1:Ngt + b=alltracked(find(alltracked(:,i),1,'first'):find(alltracked(:,i),1,'last'),i); + b(~~b)=1; + fr(i)=numel(find(diff(b)==-1)); +end +FRA=sum(fr); + +assert(Ngt==MT+PT+ML,'Hmm... Not all tracks classified correctly.'); +metrics=[recall, precision, FAR, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FRA, MOTA, MOTP, MOTAL]; +end + +function ret=matched2d(gtInfo,stateInfo,t,map,mID,td) + gtLeft=gtInfo.X(t,map)-gtInfo.W(t,map)/2; + gtTop=gtInfo.Y(t,map)-gtInfo.H(t,map); + gtWidth=gtInfo.W(t,map); gtHeight=gtInfo.H(t,map); + + stLeft=stateInfo.Xi(t,mID)-stateInfo.W(t,mID)/2; + stTop=stateInfo.Yi(t,mID)-stateInfo.H(t,mID); + stWidth=stateInfo.W(t,mID); stHeight=stateInfo.H(t,mID); + + ret = boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight) >= td; +end + + +function ret=matched3d(gtInfo,stateInfo,t,map,mID,td) + Xgt=gtInfo.Xgp(t,map); Ygt=gtInfo.Ygp(t,map); + X=stateInfo.Xgp(t,mID); Y=stateInfo.Ygp(t,mID); + ret=norm([Xgt Ygt]-[X Y])<=td; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/CLEAR_MOT_EVAL.exe b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/CLEAR_MOT_EVAL.exe new file mode 100644 index 0000000000000000000000000000000000000000..83f4a7ffd07811e22f53e42b65cff44214894ccd --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/CLEAR_MOT_EVAL.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:116e6ff15e8f438d7bf7c10652e29bc7e65f4457faa17b1896e12ceb3bb44d34 +size 310567424 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/DETRAC_DET_EVAL.exe b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/DETRAC_DET_EVAL.exe new file mode 100644 index 0000000000000000000000000000000000000000..b5723339a05a34319f3f17d0f6362e3f9563f005 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/DETRAC_DET_EVAL.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a21b9611ed7aa4ceb89afc831d7d5935d9d77027bffae9cd63deff01e4cedfce +size 310440448 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/DETRAC_MOT_EVAL.exe b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/DETRAC_MOT_EVAL.exe new file mode 100644 index 0000000000000000000000000000000000000000..3f0974ae8e8c30d3d70ae594a4064c0d1bcc51f6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/DETRAC_MOT_EVAL.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abb2e0c81c923a5fbd2709e218a5ce0a52a2e250c66d37aae56ef058f5da3e9f +size 310592000 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/README_evaluation.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/README_evaluation.txt new file mode 100644 index 0000000000000000000000000000000000000000..ad6b5b1c4b7ce70a2b3bf843c935666be62a5648 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/README_evaluation.txt @@ -0,0 +1,238 @@ +============================================== + trainlist (60 sequences) Detection evaluation to calculate AP score + reference: M. Everingham, S. M. A. Eslami, L. J. V. Gool, C. K. I. Williams, J. M. Winn, and A. Zisserman. The pascal visual object classes challenge: A retrospective. IJCV, 111(1):98¨C136, 2015. +============================================== + +Command parameters: + +Input_1: Detector name + +Input_2: Detection result folder Path + Detection file is named as "SequenceName_Det_DetectorName.txt" + +Input_3: path of a txt file contains which sequences will be evaluated. + For example: + ******************* + MVI_39501 + MVI_39511 + ******************* + +Input_4: Output Path + + +For example: + - Command line: AP_DET_EVAL.exe name C:/Detections/ C:/sqList.txt C:/PRCurve/ + + The output file is named as "name_detection_PR.txt" + The format of this file is as following: + + *************************************** + // left is recall, right is precision + 0.000001581602796 1.000000000000000 + 0.000003163205593 1.000000000000000 + 0.000004744808389 1.000000000000000 + 0.000006326411185 1.000000000000000 + 0.000007908013981 1.000000000000000 + 0.000009489616778 1.000000000000000 + 0.000011071219574 1.000000000000000 + 0.000012652822370 1.000000000000000 + 0.000014234425166 1.000000000000000 + 0.000015816027963 1.000000000000000 + 0.000017397630759 1.000000000000000 + 0.000018979233555 1.000000000000000 + 0.000020560836352 1.000000000000000 + 0.000022142439148 1.000000000000000 + 0.000023724041944 1.000000000000000 + 0.000025305644740 1.000000000000000 + 0.000026887247537 1.000000000000000 + 0.000026887247537 0.944444444444444 + 0.000026887247537 0.894736842105263 + 0.000028468850333 0.900000000000000 + ...... + ***************************************** + +============================================== + trainlist (60 sequences) CLEAR MOT evaluation +============================================== + +threshold = 0:0.1:1 + +Command parameters: + +Input_1: tracker name + +Input_2: detector name + +Input_3: Tracking result folder Path + There are N <= 11 folders under Input_1 path, which takes threshold value as name + ***** + 0.0 + 0.1 + 0.2 + ... + 1.0 + ***** + Tracking file under each threshold folder is named as + "SequenceName_LX.txt" + "SequenceName_LY.txt" + "SequenceName_H.txt" + "SequenceName_W.txt" + +Input_4: path of a txt file contains which threshold will be evaluated + For example: + ******************* + 0.0 + 0.3 + 0.6 + 1.0 + ******************* + +Input_5: path of a txt file contains which sequences will be evaluated. + For example: + ******************* + MVI_39501 + MVI_39511 + ******************* + +Input_6: Output Path + tracking indicators of each threshold in one file named as "DETRAC_MOT_Result.txt" + ******** + metrics contains the following + [1] recall - recall = percentage of detected targets + [2] precision - precision = percentage of correctly detected targets + [3] FAR - number of false alarms per frame + [4] GT - number of ground truth trajectories + [5-7] MT, PT, ML - number of mostly tracked, partially tracked and mostly lost trajectories (*100) + [8] falsepositives- number of false positives (FP) + [9] missed - number of missed targets (FN) + [10] idswitches - number of id switches (IDs) + [11] FRA - number of fragmentations + [12] MOTA - Multi-object tracking accuracy in [0,100] + [13] MOTP - Multi-object tracking precision in [0,100] (3D) / [td,100] (2D) + [14] MOTAL - Multi-object tracking accuracy in [0,100] with log10(idswitches) + ******** + +For example: + - Command line: exeName.exe CEM ACF C:/TrackerResult/ C:/thresh.txt C:/sequences.txt C:/output/ + + +============================================== + trainlist (60 sequences) Detection evaluation +============================================== + +threshold = 0:step:1 + +Command parameters: + +Input_1: Detector name + +Input_2: Detection result folder Path + Detection file is named as "SequenceName_Det_DetectorName.txt" + +Input_3: path of a txt file contains which sequences will be evaluated. + For example: + ******************* + MVI_39501 + MVI_39511 + ******************* +Input_4: score step + For example: 0.1 + +Input_5: Output Path + + +For example: + - Command line: DETRAC_DET_EVAL.exe name C:/Detections/ C:/sqList.txt 0.1 C:/PRCurve/ + + The output file is named as "name_detection_PR.txt" + The format of this file is as following: + + *************************************** + // left is recall, right is precision + 0.5672 0.2926 + 0.5672 0.2926 + 0.5672 0.2927 + 0.5672 0.2944 + 0.5672 0.3094 + 0.5666 0.3752 + 0.5573 0.5571 + 0.4644 0.7976 + 0.1008 0.9430 + ***************************************** + + The other output file is named as "name_thres.txt" + Since the maximal score value may be less than 1, we create this file to record what the actual scores are used. The next TRACK SYSTEM evaluation phase will reply on this file. + For example: + ************ + 0.0 + 0.1 + 0.2 + 0.3 + 0.4 + 0.5 + 0.6 + 0.7 + 0.8 + ************ + +============================================== + trainlist (60 sequences) DETRAC MOT evaluation +============================================== + +Command parameters: + +Input_1: tracker name + +Input_2: detector name + +Input_3: "detectorname_thres.txt" file which is generated by detection evaluation phase. + +Input_4: detectorName_detection_PR.txt path + +Input_5: path of a txt file contains which sequences will be evaluated. + For example: + ******************* + MVI_39501 + MVI_39511 + ******************* + +Input_6: Tracking result folder Path + There are N folders under Input_1 path, which takes threshold value as name. + These names should be consistent with "detectorname_thres.txt" file + ***** + 0.0 + 0.2 + 0.4 + ... + 1.0 + ***** + Tracking file under each threshold folder is named as + "SequenceName_LX.txt" + "SequenceName_LY.txt" + "SequenceName_H.txt" + "SequenceName_W.txt" + +Input_7: Output Path + + final average score (13 indicators) in one file named as "trackerName_detectorName_averageScore.txt" + ******** + scoreRECALL + scorePRECISION + scoreFAR + scoreMT + scorePT + scoreML + scoreFP + scoreFN + scoreIDS + scoreFM + scoreMOTA + scoreMOTP + scoreMOTAL + ********* + +For example: + - Command line: exeName.exe TrackerName detectorName C:/detectorname_thres.txt C:/detectorname_detection_PR.txt C:/seqList.txt C:/TrackerName/ C:/output/ + + + \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/VOCap.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/VOCap.m new file mode 100644 index 0000000000000000000000000000000000000000..0678c695d336352943185585940262060b27145d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/VOCap.m @@ -0,0 +1,9 @@ +function ap = VOCap(rec,prec) + mrec=[0 ; rec ; 1]; + mpre=[0 ; prec ; 0]; + for i=numel(mpre)-1:-1:1 + mpre(i)=max(mpre(i),mpre(i+1)); + end + i=find(mrec(2:end)~=mrec(1:end-1))+1; + ap=sum((mrec(i)-mrec(i-1)).*mpre(i)); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/boxIntersect.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/boxIntersect.m new file mode 100644 index 0000000000000000000000000000000000000000..5a55b45131c36980ad641f838452967a12bf300b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/boxIntersect.m @@ -0,0 +1,24 @@ +function isect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2) +% A=[bboxleft1 bboxbottom1 abs(bboxright1-bboxleft1) abs(bboxbottom1-bboxup1)]; +% B=[bboxleft2 bboxbottom2 abs(bboxright2-bboxleft2) abs(bboxbottom2-bboxup2)]; +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% isect=rectint(A,B); +isect=0; + +hor= max(0,min(bboxright1,bboxright2) - max(bboxleft1,bboxleft2)); + +if ~hor, return; end +ver= max(0,min(bboxbottom1,bboxbottom2) - max(bboxup1,bboxup2)); +if ~ver, return; end + +isect = hor*ver; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/boxUnion.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/boxUnion.m new file mode 100644 index 0000000000000000000000000000000000000000..c5b8e06c5ea242199dbffa15e553ec07b626fab9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/boxUnion.m @@ -0,0 +1,24 @@ +function union=boxUnion(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2,isect) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +a1=bboxright1-bboxleft1; +b1=bboxbottom1-bboxup1; +a2=bboxright2-bboxleft2; +b2=bboxbottom2-bboxup2; +union=a1*b1+a2*b2; +if nargin>8 + bisect=isect; +else + bisect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2); +end +union=union-bisect; + + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/boxiou.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/boxiou.m new file mode 100644 index 0000000000000000000000000000000000000000..395e5dc90d032ee2d7f3c9554148e56f908eeab5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/boxiou.m @@ -0,0 +1,21 @@ +function iou=boxiou(x1,y1,w1,h1,x2,y2,w2,h2) +% compute intersection over union of two bboxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + bisect=boxIntersect(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2); + iou=0; + if ~bisect, return; end + + bunion=boxUnion(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2,bisect); + + assert(bunion>0,'something wrong with union computation'); + iou=bisect/bunion; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/checkResultFormat.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/checkResultFormat.m new file mode 100644 index 0000000000000000000000000000000000000000..54912e500702190dd0678cb16f7a2cac0cf03e9d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/checkResultFormat.m @@ -0,0 +1,90 @@ +function [errorMsg, realList] = checkResultFormat(unzipPath, detectorName) +%% Check detection format +global options + +errorMsg = []; +HEIGHT = 540; +WIDTH = 960; + +resList = dir(fullfile(unzipPath, '*.txt')); +optionID = find(ismember({'DETRAC-Test','DETRAC-Train','DETRAC-Free','DETRAC-Test-Beginner','DETRAC-Test-Experienced'},options.evaluateSeqs)); +if(optionID == 1) + listPath = 'seqs/testlist-full.txt'; +elseif(optionID == 2) + listPath = 'seqs/trainlist-full.txt'; +elseif(optionID == 3) + listPath = '../sequences.txt'; +elseif(optionID == 4) + listPath = 'seqs/testlist-det-beginner.txt'; +elseif(optionID == 5) + listPath = 'seqs/testlist-det-experienced.txt'; +else + error('error in sequences for evaluation!'); +end +realList = importdata(listPath); + +%% Check number +if(length(resList) < length(realList)) + errorMsg = sprintf('Results must be %d txt files!', length(realList)); + return; +end + +%% Check list +for i = 1:length(realList) + fprintf('Checking %d/%d\n', i, length(realList)); + resName = [realList{i} '_Det_' detectorName '.txt']; + if(~exist([unzipPath resName], 'file')) + errorMsg = sprintf('Sequence %s is not valid', resName); + end + %% Check ext + [~, namePart, nameExt] = fileparts(resName); + if(~strcmp(nameExt, '.txt')) + errorMsg = sprintf('%s must be txt file', resName); + return; + end + %% Check resName format + pos = strfind(namePart, '_'); + if(length(pos) ~= 3) + errorMsg = sprintf('%s must be MVI_XXX_Det_DetectorName.txt', resName); + return; + end + midName = namePart(pos(2)+1:pos(3)-1); + if(~strcmp(midName, 'Det')) + errorMsg = sprintf('%s must be MVI_XXX_Det_DetectorName.txt', resName); + return; + end + + %% Check content + detections = load(fullfile(unzipPath, resName)); + lineCnt = 1; + while(lineCnt <= size(detections, 1)) + content = detections(lineCnt, :); + % each line of the file should be set as [Frame, Number, Left, Top, Width, Height, Score] + if(length(content) ~= 7) + errorMsg = sprintf('Content must be [Frame, Number, Left, Top, Width, Height, Score] (Line %d in %s)', lineCnt, resName); + return; + end + frame = content(1); + number = content(2); + left = min(max(content(3), 1), WIDTH); + top = min(max(content(4), 1), HEIGHT); + width = min(content(5), WIDTH - left + 1); + height = min(content(6), HEIGHT - top + 1); + score = content(7); + if (score < 0 || score > 1) + errorMsg = sprintf('Score must be in [0, 1] (Line %d in %s)', lineCnt, resName); + return; + end + if(height <= 0) + errorMsg = sprintf('Height must be postive (Line %d in %s)', lineCnt, resName); + return; + end + if(width <= 0) + errorMsg = sprintf('Width must be positive (Line %d in %s)', lineCnt, resName); + return; + end + detections(lineCnt, :) = [frame, number, left, top, width, height, score]; + lineCnt = lineCnt + 1; + end + dlmwrite(fullfile(unzipPath, resName), detections); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/createIntImg.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/createIntImg.m new file mode 100644 index 0000000000000000000000000000000000000000..cf45b3b84b0123f5d386132701dd82a5defe752d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/createIntImg.m @@ -0,0 +1,16 @@ +function intImg = createIntImg(img) + +[height, width] = size(img); +intImg = img; +for i = 2:height + intImg(i, 1) = intImg(i, 1) + intImg(i-1, 1); +end +for j = 2:width + intImg(1, j) = intImg(1, j) + intImg(1, j-1); +end + +for i = 2:height + for j = 2:width + intImg(i, j) = intImg(i, j) + intImg(i-1, j) + intImg(i, j-1) - intImg(i-1, j-1); + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/createNewPath.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/createNewPath.m new file mode 100644 index 0000000000000000000000000000000000000000..849616262ca9a29944c648760bdae453bd2ae382 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/createNewPath.m @@ -0,0 +1,16 @@ +function createNewPath(filePath) +% create new folder for saving results +if(~isdir(filePath)) + mkdir(filePath); +elseif(isdir(filePath)) + Dirs = dir(filePath); + for i = 1:length(Dirs) + % remove directory and all contents + if(Dirs(i).isdir && ~strcmp(Dirs(i).name,'.') && ~strcmp(Dirs(i).name,'..')) + rmdir([filePath Dirs(i).name],'s'); + % delete the files in corresponding directory + elseif(~strcmp(Dirs(i).name,'.') && ~strcmp(Dirs(i).name,'..')) + delete([filePath Dirs(i).name]); + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/createPath.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/createPath.m new file mode 100644 index 0000000000000000000000000000000000000000..db4798e256406f986881fc0b4f688f690508a05f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/createPath.m @@ -0,0 +1,5 @@ +function createPath(newPath) + +if(~isdir(newPath)) + mkdir(newPath); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/ACF_detection_PR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/ACF_detection_PR.txt new file mode 100644 index 0000000000000000000000000000000000000000..7d577ff8fb9ceaafa88068ee0d02cbf3ca1a550b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/ACF_detection_PR.txt @@ -0,0 +1,21 @@ +0.567181741977320,0.292586135014274 +0.562226580416594,0.345369012885794 +0.548566277065178,0.444164705219456 +0.522548911066475,0.553060066388902 +0.484410141237130,0.647648168354098 +0.437192971357173,0.728205776667826 +0.378966264412355,0.795026295270169 +0.312682872823319,0.851369857114558 +0.244322836762775,0.893871622911833 +0.185887358248849,0.920721341783456 +0.134227466114160,0.941628110818937 +0.091119300298923,0.954520602415627 +0.058218798930837,0.958568787271165 +0.031815521849843,0.953093906945892 +0.016206683853417,0.962792445738983 +0.007136191816787,0.989256741942556 +0.002103531719044,0.994764397905759 +0.000434940768975,0.996376811594203 +0.000080661742610,1.000000000000000 +0.000017397630759,1.000000000000000 +0.000001581602796,1.000000000000000 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/DPM_detection_PR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/DPM_detection_PR.txt new file mode 100644 index 0000000000000000000000000000000000000000..2acc5f6f95a799ebbe9b31afb847a8b3791268bb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/DPM_detection_PR.txt @@ -0,0 +1,21 @@ +0.422645388837047,0.171554399987160 +0.415246650956079,0.237891713367976 +0.394445410979487,0.302024712169708 +0.370944375029655,0.367771374808891 +0.341437993262372,0.433240215615681 +0.311128157274582,0.498839860123900 +0.272609802774131,0.560962432834412 +0.229414648805099,0.622853535895707 +0.182589716418619,0.674086054781243 +0.139011814572888,0.716406109906591 +0.101371249624369,0.747025023601674 +0.067721068530849,0.787254775781868 +0.039087731507109,0.810162268480577 +0.021044806807218,0.845147357723577 +0.009922975943821,0.871509931934991 +0.003791101902668,0.882872928176796 +0.001129264396539,0.871794871794872 +0.000355860629162,0.925925925925926 +0.000093314564980,0.921875000000000 +0.000014234425166,1.000000000000000 +0.000001581602796,1.000000000000000 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/R-CNN_detection_PR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/R-CNN_detection_PR.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b9e68c36814e11816f1d4ca11ab8312d474ed30 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/R-CNN_detection_PR.txt @@ -0,0 +1,21 @@ +0.566832207759343,0.292402245940614 +0.566832207759343,0.292403677329661 +0.566832207759343,0.292412981700068 +0.566832207759343,0.292437557628128 +0.566832207759343,0.292531127105681 +0.566832207759343,0.292874408965581 +0.566832207759343,0.294199591196776 +0.566832207759343,0.298166198551728 +0.566825881348158,0.309192601884556 +0.566723077166400,0.332688979506949 +0.566239106710741,0.374961641462620 +0.563869865721923,0.450425956364583 +0.557034178436427,0.556861554613212 +0.534999288278742,0.680253065788257 +0.464336438546823,0.797504149338143 +0.296091859490408,0.897902607711382 +0.100811362234488,0.942927305541584 +0.014395748651684,0.969638862256312 +0.000778148575767,0.984000000000000 +0.000074335331425,0.979166666666667 +0.000001581602796,1.000000000000000 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/README_curve.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/README_curve.txt new file mode 100644 index 0000000000000000000000000000000000000000..b3b2e42600c20fedf57d3243e6132fe994316dc2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/README_curve.txt @@ -0,0 +1,3 @@ +The Precision-Recall curve is generated by tuning the threshold (i.e., 0:0.05:1) of an detector to generate different precision and recall values. +In the Precision-Recall result file, the first column is for recall and the second column is for precision. +The raw result is interpolated linearly with the step 0.0001 to calculate the corresponding AP score. \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/compACT_detection_PR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/compACT_detection_PR.txt new file mode 100644 index 0000000000000000000000000000000000000000..9ca1d6e7afc890faf66193a23ab165f63fa59f06 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/curve_results/compACT_detection_PR.txt @@ -0,0 +1,21 @@ +0.614658294715865,0.390629633091797 +0.607433533142487,0.486536885323780 +0.590255745172158,0.599103915034065 +0.559412909042023,0.686765445426709 +0.514572888164866,0.755913616245164 +0.461563888844955,0.816227040966160 +0.402962342037421,0.859089391747676 +0.340245464753982,0.891378210174773 +0.272722096572667,0.918457678848213 +0.209563952109067,0.935946428949841 +0.156056747908330,0.950339991909541 +0.110348427096019,0.967080185737057 +0.073598304521802,0.976149021417633 +0.044696095022696,0.978633514561762 +0.024926060069274,0.982911313458900 +0.011613709333038,0.995391080384980 +0.003974567827036,0.997618102421596 +0.000971104116912,0.996753246753247 +0.000185047527164,1.000000000000000 +0.000037958467111,1.000000000000000 +0.000001581602796,1.000000000000000 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/detectionEvaluation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/detectionEvaluation.m new file mode 100644 index 0000000000000000000000000000000000000000..23c180354838011c68fafb497eef62ad32e28984 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/detectionEvaluation.m @@ -0,0 +1,41 @@ +function detectionEvaluation() + +global options + +detectorSet = options.detectorSet; % the detector set + +% Debug Logs +curPath = pwd; +log_path = [curPath '/logs/']; +createPath(log_path); + +cd('./evaluation'); +addpath(genpath('.')); +for idDet = 1:length(detectorSet) + detectorName = detectorSet{idDet}; + diary([log_path 'DETRAC_' detectorName '_detection_logs.txt']); + % Check formats + detPath = [options.detPath detectorName '/']; + [errorMsg, realList] = checkResultFormat(detPath, detectorName); + if(~isempty(errorMsg)) + error(errorMsg); + end + % pre-processing the detection results + preProcessDetectionResults(detectorName); + % obtain detection PR scores + if(options.printDetectionEval) + detprFile = [options.detPath detectorName '/' detectorName '_detection_PR.txt']; + detprLine = ['AP_DET_EVAL.exe ' detectorName ' ' detPath ' ' curPath '/sequences.txt ' detPath]; + evalexe(detprLine); + if(exist(detprFile, 'file')) + APscore = showDetectionPRCurve(detprFile, detectorName); + disp(['The AP score of the detector ' detectorName ' is ' num2str(roundn(APscore,-2)) '%.']); + else + error('no detection results!'); + end + end +end +cd('../'); + +%% zip the detection results for DETRAC-Test +zipDetectionResults(detectorSet, realList); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/clampBBox.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/clampBBox.m new file mode 100644 index 0000000000000000000000000000000000000000..9bf4e860814575ff589ac17e708d8ec5c2db989d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/clampBBox.m @@ -0,0 +1,19 @@ +function [bleft bright btop bbottom]= clampBBox(bleft, bright, btop, bbottom, imgWidth, imHeight) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% clamp bounding box to [1, imageDim] + +bleft=max(1,bleft); bleft=min(imgWidth,bleft); +bright=max(1,bright); bright=min(imgWidth,bright); +btop=max(1,btop); btop=min(imHeight,btop); +bbottom=max(1,bbottom); bbottom=min(imHeight,bbottom); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/displayBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/displayBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..f53590e75a55df774d8057f40343d72960e2f53a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/displayBBoxes.m @@ -0,0 +1,123 @@ +function displayBBoxes(sceneInfo, X, Y, W, H) +% Draw bounding boxes on top of images +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% +[F, numObjs] = size(X); +if(F == 0) + disp('no tracking results!'); +end +ind=find(W); +aspectRatio=mean(H(ind)./W(ind)); +frameNums = sceneInfo.frameNums; + +for t = 1:F + clf + im = imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]); + im = double(im)/255; + imshow(im,'Border','tight'), hold on; + + % frame number + text(10,20,sprintf('#%04d',t),'FontSize',30,'color','r'); + + extar=find(X(t,:)); + % foot position + if(sceneInfo.displayDots) + for id=extar + plot(X(t,id),Y(t,id),'.','color',getColorFromID(id, numObjs),'MarkerSize',sceneInfo.dotSize); + end + end + + % box + if(sceneInfo.displayBoxes) + for id=extar + bleft=X(t,id)-W(t,id)/2; + btop=Y(t,id)-H(t,id); + rectangle('Position',[bleft,btop,W(t,id),H(t,id)],'Curvature',[.1,.2*(W(t,id)/H(t,id))],'EdgeColor',getColorFromID(id, numObjs),'linewidth',sceneInfo.boxLineWidth); + end + end + + % ID + if sceneInfo.displayID + for id=extar + tx=X(t,id)-W(t,id)/2; + ty=Y(t,id)-H(t,id)*0.8; % on top + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id, numObjs), 'HorizontalAlignment','left', 'FontSize',W(t,id)/5, 'FontUnits','pixels','FontWeight','bold'); + end + end + + % cropouts + if(sceneInfo.displayCropouts) + bw=2; %border cropouts + + %% crop outs var sized + maxTar=30; + extarRed=extar(extar<=maxTar); % reducde + + %% crop outs fixed sized + uniH=min(60,round(sceneInfo.imgHeight/10)); uniW=round(uniH/aspectRatio); + mxfac=.5; + crpImg=im(1:uniH,1:min(sceneInfo.imgWidth,round(uniW*size(W,2)+bw*size(W,2))),:)*mxfac; + crpImg=crpImg + (1-mxfac)*ones(size(crpImg)); % bleeched + for id=extarRed + offset=(id-1)*uniW + (id-1)*bw+1; + bleft=round(X(t,id)-W(t,id)/2); + bright=round(X(t,id)+W(t,id)/2); + btop=round(Y(t,id)-H(t,id)); + bbottom=round(Y(t,id)); + + [bleft, bright, btop, bbottom] = clampBBox(bleft, bright, btop, bbottom, sceneInfo.imgWidth, sceneInfo.imgHeight); + ht=uniH; + imres=imresize(im(btop:bbottom,bleft:bright,:),[uniH uniW]); + crpImg(1:ht,offset:offset+uniW-1,:)=imres; + + end + imshow(crpImg); + + for id=extarRed + tx = id*uniW-uniW/2 + id*bw; + ty = 30; % top + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id, numObjs), 'HorizontalAlignment','center', ... + 'FontSize',uniW/4, 'FontUnits','pixels','FontWeight','bold'); % fixed size + end + if(sceneInfo.displayConnections) + for id=extarRed + if(t-find(X(:,id),1,'first')<5) + btop=round(Y(t,id)-H(t,id)); + offset=(id-1)*uniW + (id-1)*bw+1 + uniW/2; + line([X(t,id) offset],[btop uniH],'color',getColorFromID(id, numObjs),'linestyle','-'); + end + end + end + end + + % show trace + if(sceneInfo.traceLength) + for tracet=max(1,t-sceneInfo.traceLength):max(1,t-1) + ipolpar=(t-tracet)/sceneInfo.traceLength; % parameter [0,1] for color adjustment + + extarpast=find(X(tracet,:)); + % foot position + for id=extarpast + if(W(tracet+1,id)) + endcol=sceneInfo.grey; + line(X(tracet:tracet+1,id) ,Y(tracet:tracet+1,id), 'color',ipolpar*endcol + (1-ipolpar)*getColorFromID(id, numObjs),'linewidth',(1-ipolpar)*sceneInfo.traceWidth+1); + end + end + end + end + pause(sceneInfo.framePause); + + % save + if(~isempty(sceneInfo.outFolder)) + im2save=getframe(gcf); + im2save=im2save.cdata; + imwrite(im2save, [sceneInfo.outFolder sprintf('_frame_%04d.jpg',frameNums(t))]); + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/displayTrackingResult.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/displayTrackingResult.m new file mode 100644 index 0000000000000000000000000000000000000000..d49bef9487076de7b4a4d5bce08c0ebc28510ac9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/displayTrackingResult.m @@ -0,0 +1,22 @@ +function displayTrackingResult(sceneInfo, stateInfo, seqName) +% Display Tracking Result +% +% Take scene information sceneInfo and +% the tracking result from stateInfo +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +W = stateInfo.W; +H = stateInfo.H; +Xi = stateInfo.Xi; +Yi = stateInfo.Yi; + +reopenFig(['Tracking Results of Sequence ' seqName]); +displayBBoxes(sceneInfo, Xi, Yi, W, H); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/getColorFromID.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/getColorFromID.m new file mode 100644 index 0000000000000000000000000000000000000000..5e3e4d980afe41a7ba27f37231597cdb676648e6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/getColorFromID.m @@ -0,0 +1,24 @@ +function col=getColorFromID(id, numObjs) +% get rgb [0,1] values from id +global options + if(~isfield(options,'colors')) + options.colors = rand(max(1,numObjs-13), 3); + colors=[ + 128 255 255; % + 255 0 0; % red 1 + 0 255 0; % green 2 + 0 0 255; % blue 3 + 0 255 255; % cyan 4 + 255 0 255; % magenta 5 + 212 212 0; % yellow 6 + 25 25 25; % black 7 + 34,139,34; % forestgreen 8 + 0,191,255; % deepskyblue 9 + 139,0,0 ; % darkred 10 + 218,112,214; % orchid 11 + 244,164,96 ;]/255; % sandybrown 12 + colors = colors / 255; + options.colors = cat(1,colors,options.colors); + end + col = options.colors(id,:); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/reopenFig.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/reopenFig.m new file mode 100644 index 0000000000000000000000000000000000000000..dcfc4b09cfad39ea91e1f6a9dae423f639d08a35 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/reopenFig.m @@ -0,0 +1,14 @@ +function reopenFig(figname) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +close(findobj('type','figure','name',figname)) +figure('name',figname); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/showDetectionPRCurve.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/showDetectionPRCurve.m new file mode 100644 index 0000000000000000000000000000000000000000..66d465ea7425159e7bfa926e50cfde3b4be1511b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/showDetectionPRCurve.m @@ -0,0 +1,27 @@ +function AP = showDetectionPRCurve(detprFile, detectorName) + +global options + +% load the PR file +detResult = load(detprFile); +rec = detResult(:,1); +prec = detResult(:,2); +AP = roundn(VOCap(rec,prec)*100,-2); + +if(options.showDetectionCurve) + fontSizeLegend = 14; + fontSize = 14; + curFig = figure(1); + curAxes = axes('Parent',curFig,'FontSize',14); + if(numel(rec)<100) + legendName = detectorName; + else + legendName = [detectorName ' (' num2str(roundn(AP,-2)) '%)']; + end + plot(detResult(:,1),detResult(:,2),'color','r','lineStyle','-','lineWidth',5,'Parent',curAxes);grid on;hold on; + title(['Detection Curve of ' detectorName],'fontsize',fontSize); + xlabel('Recall','fontsize',fontSize); + ylabel('Precision','fontsize',fontSize); + axis([0 1 0 1]); + legend(legendName,'Interpreter','none','fontsize',fontSizeLegend,'Location','SouthEast'); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/showResults.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/showResults.m new file mode 100644 index 0000000000000000000000000000000000000000..77ec42ea3494c7910816d5177ff700bb8445389b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/display/showResults.m @@ -0,0 +1,36 @@ +function showResults(stateInfo, curSequence, resultSavePath) + +global options + +if(options.showVisualResults) + sceneInfo.imgFolder = curSequence.imgFolder; + sceneInfo.imgFileFormat = 'img%05d.jpg'; + if(options.saveVisualResults) + sceneInfo.outFolder = ['visual' resultSavePath '/' curSequence.seqName]; % tracking results saving path + createPath(['visual' resultSavePath '/']); + else + sceneInfo.outFolder = []; + end + sceneInfo.frameNums = stateInfo.frameNums; + sceneInfo.imgHeight = curSequence.imgHeight; + sceneInfo.imgWidth = curSequence.imgWidth; + + %% Display parameters + sceneInfo.defaultColor = [.1 .2 .9]; + sceneInfo.grey = 0.7*ones(1,3); + sceneInfo.framePause = 0.001; % pause between frames + + sceneInfo.traceLength = 20; % overlay track from past n frames + sceneInfo.dotSize = 20; + sceneInfo.boxLineWidth = 3; + sceneInfo.traceWidth = 2; + + % what to display + sceneInfo.displayDots = options.displayDots; + sceneInfo.displayBoxes = options.displayBoxes; + sceneInfo.displayID = options.displayID; + sceneInfo.displayCropouts = options.displayCropouts; + sceneInfo.displayConnections = options.displayConnections; + + displayTrackingResult(sceneInfo, stateInfo, curSequence.seqName); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/dropDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/dropDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..a82ce42c44227db6098c1bf80ec65e1e1fb5b216 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/dropDetections.m @@ -0,0 +1,29 @@ +function detections = dropDetections(detections, ignoreFile, imgHeight, imgWidth) + +% drop detections in ignore region +ignoreRegion = load(ignoreFile); +if(~isempty(ignoreRegion)) + igrMap = zeros(imgHeight, imgWidth); + numIgnore = size(ignoreRegion,1); + for j = 1:numIgnore + igrMap(ignoreRegion(j,2):min(imgHeight,ignoreRegion(j,2)+ignoreRegion(j,4)),ignoreRegion(j,1):min(imgWidth,ignoreRegion(j,1)+ignoreRegion(j,3))) = 1; + end + intIgrMap = createIntImg(double(igrMap)); + idxIgnoreLeft = []; + for i = 1:size(detections, 1) + curDet = max(1,round(detections(i,3:6))); + x = max(1, min(imgWidth, curDet(1))); + y = max(1, min(imgHeight, curDet(2))); + w = curDet(3); + h = curDet(4); + tl = intIgrMap(y, x); + tr = intIgrMap(y, min(imgWidth,x+w)); + bl = intIgrMap(max(1,min(imgHeight,y+h)), x); + br = intIgrMap(max(1,min(imgHeight,y+h)), min(imgWidth,x+w)); + ignoreValue = tl + br - tr - bl; + if(ignoreValue/(h*w)<0.5) + idxIgnoreLeft = cat(1, idxIgnoreLeft, i); + end + end + detections = detections(idxIgnoreLeft, :); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/dropTracks.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/dropTracks.m new file mode 100644 index 0000000000000000000000000000000000000000..a6402bfbcc7d5b9d56d0d2d4fcf14eaab09f4246 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/dropTracks.m @@ -0,0 +1,83 @@ +function stateInfo = dropTracks(stateInfo, curSequence) +%% Thank Victor Stamatescu for his valuable comment to add this function + +global options + +% drop system tracks in ignored regions +ignoreRegion = curSequence.ignoreRegion; +imgHeight = curSequence.imgHeight; +imgWidth = curSequence.imgWidth; + +dropBoxes = 0; +totalBoxes = 0; + +if(~isempty(ignoreRegion)) + igrMap = zeros(imgHeight, imgWidth); + numIgnore = size(ignoreRegion, 1); + for j = 1:numIgnore + igrMap(ignoreRegion(j,2):min(imgHeight,ignoreRegion(j,2)+ignoreRegion(j,4)),ignoreRegion(j,1):min(imgWidth,ignoreRegion(j,1)+ignoreRegion(j,3))) = 1; + end + intIgrMap = createIntImg(double(igrMap)); + if(options.showRemoveResults) + figure(10); imagesc(igrMap); colormap bone; colorbar; + title('tracks: blue-drop red-keep, ignore region: white'); + end + for i = 1:size(stateInfo.W,2)% tracks + for j = 1:size(stateInfo.W,1)% frames + h = round(stateInfo.H(j,i)); + w = round(stateInfo.W(j,i)); + if(w==0 || h==0) + continue; + end + totalBoxes = totalBoxes + 1; + + xc = stateInfo.X(j,i); + yc = stateInfo.Y(j,i) - h/2; + x = round(xc - w/2); + y = round(yc - h/2); + if(options.showRemoveResults) + Left = x; + Top = y; + BoundingBox_X1 = Left; + BoundingBox_Y1 = Top + h; + BoundingBox_X2 = Left; + BoundingBox_Y2 = Top; + BoundingBox_X3 = Left + w; + BoundingBox_Y3 = Top; + BoundingBox_X4 = Left + w; + BoundingBox_Y4 = Top + h; + end + tl = intIgrMap(max(1,min(imgHeight,y)), max(1,min(imgWidth,x))); + tr = intIgrMap(max(1,min(imgHeight,y)), max(1,min(imgWidth,x+w))); + bl = intIgrMap(max(1,min(imgHeight,y+h)), max(1,min(imgWidth,x))); + br = intIgrMap(max(1,min(imgHeight,y+h)), max(1,min(imgWidth,x+w))); + ignoreValue = tl + br - tr - bl; + if(ignoreValue/(h*w)>=0.5) + dropBoxes = dropBoxes +1; + stateInfo.W(j,i) = 0; + stateInfo.H(j,i) = 0; + stateInfo.X(j,i) = 0; + stateInfo.Y(j,i) = 0; + stateInfo.Xi(j,i) = 0; + stateInfo.Yi(j,i) = 0; + if(options.showRemoveResults) + rect.vertices = [BoundingBox_X1 BoundingBox_Y1; BoundingBox_X2 BoundingBox_Y2;... + BoundingBox_X3 BoundingBox_Y3; BoundingBox_X4 BoundingBox_Y4; BoundingBox_X1 BoundingBox_Y1]; + rect.faces = [1 2 3 4]; + hold on; patch(rect,'Vertices',rect.vertices,'FaceColor',[0 0 1],'FaceAlpha',0.1); hold off; pause(0.1); + end + else + if(options.showRemoveResults) + rect.vertices = [BoundingBox_X1 BoundingBox_Y1; BoundingBox_X2 BoundingBox_Y2;... + BoundingBox_X3 BoundingBox_Y3; BoundingBox_X4 BoundingBox_Y4; BoundingBox_X1 BoundingBox_Y1]; + rect.faces = [1 2 3 4]; + hold on; patch(rect,'Vertices',rect.vertices,'FaceColor',[1 0 0],'FaceAlpha',0.1); hold off; pause(0.1); + end + end + end + end +end + +if(dropBoxes) + disp(['Ignored Regions ---> dropped ' num2str(dropBoxes) ' out of ' num2str(totalBoxes) ' boxes']); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/evalexe.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/evalexe.m new file mode 100644 index 0000000000000000000000000000000000000000..cbb6aff2aa9182fa1ff01075b705e638dc84c9b2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/evalexe.m @@ -0,0 +1,7 @@ +function evalexe(commandline) + +if(verLessThan('matlab', '7.14.0')) + [status, b] = system(commandline); +else + [status,b] = system(commandline, ''); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/getMetricInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/getMetricInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..16fd5865ff957c710cc2897580eb14cd48076371 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/getMetricInfo.m @@ -0,0 +1,21 @@ +function metricsInfo = getMetricInfo() + +metricsInfo.names.long = {'Recall','Precision','False Alarm Rate', ... + 'GT Tracks','Mostly Tracked','Partially Tracked','Mostly Lost', ... + 'False Positives', 'False Negatives', 'ID Switches', 'Fragmentations', ... + 'MOTA','MOTP', 'MOTA Log'}; + +metricsInfo.names.short = {'Rcll','Prcn','FAR', ... + 'GT','MT','PT','ML', ... + 'FP', 'FN', 'IDs', 'FM', ... + 'MOTA','MOTP', 'MOTAL'}; + +metricsInfo.widths.long = [6 9 16 9 14 17 11 15 15 11 14 5 5 8]; +metricsInfo.widths.short = [5 5 5 3 3 3 3 4 4 3 3 5 5 5]; + +metricsInfo.format.long = {'.1f','.1f','.2f', ... + 'i','.1f%%','.1f%%','.1f%%', ... + 'i','i','i','i', ... + '.1f','.1f','.1f'}; + +metricsInfo.format.short=metricsInfo.format.long; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/getPRMetricInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/getPRMetricInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..9790224e81218a644cd612cead4c5c5145bac670 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/getPRMetricInfo.m @@ -0,0 +1,21 @@ +function metricsInfo = getPRMetricInfo() + +metricsInfo.names.long = {'Recall','Precision','False Alarm Rate', ... + 'Mostly Tracked','Partially Tracked','Mostly Lost', ... + 'False Positives', 'False Negatives', 'ID Switches', 'Fragmentations', ... + 'MOTA','MOTP', 'MOTA Log'}; + +metricsInfo.names.short = {'PR-Rcll','PR-Prcn','PR-FAR', ... + 'PR-MT','PR-PT','PR-ML', ... + 'PR-FP', 'PR-FN', 'PR-IDs', 'PR-FM', ... + 'PR-MOTA','PR-MOTP', 'PR-MOTAL'}; + +metricsInfo.widths.long = [6 9 16 14 17 11 15 15 11 14 5 5 8]; +metricsInfo.widths.short = [5 5 5 3 3 3 4 4 3 3 5 5 5]; + +metricsInfo.format.long = {'.1f','.1f','.2f', ... + '.1f%%','.1f%%','.1f%%', ... + '.1f','.1f','.1f','.1f', ... + '.1f','.1f','.1f'}; + +metricsInfo.format.short=metricsInfo.format.long; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20011_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20011_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..d4f80169c961100695a20a4802969d291b88234f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20011_IgR.txt @@ -0,0 +1,7 @@ +778.75,24.75,181.75,63.5 +930.75,94.75,29.75,33.5 +523.75,13.75,178.5,37.5 +207.75,34.75,270.5,94.5 +182.75,131.75,145.5,117.5 +0.5,231.75,88.75,121.5 +123.75,151.75,57.5,97.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20012_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20012_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..a9b99cf3cd9763ab84d65cd2efdbe1ced0b745a2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20012_IgR.txt @@ -0,0 +1,6 @@ +497.75,0.5,462.75,22.75 +820.75,28.75,139.75,50.5 +190.75,48.75,269.5,46.5 +356.75,0.5,78.5,45.75 +0.5,216.75,70.75,112.5 +106.75,98.75,191.5,120.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20032_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20032_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..6c7b35166226ea4ac50ab05d0cf22165047e3de0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20032_IgR.txt @@ -0,0 +1,5 @@ +716.75,55.75,243.75,64.5 +877.75,123.75,82.75,55.5 +455.75,31.75,155.5,53.5 +120.75,62.75,227.5,101.5 +46.75,166.75,102.5,80.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20033_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20033_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..86a66ee1168b33763bf6b7a000633e19ae37428d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20033_IgR.txt @@ -0,0 +1,5 @@ +458.75,0.5,159.5,53.75 +710.75,29.75,239.5,69.5 +824.75,101.75,129.5,55.5 +126.75,39.75,223.5,86.5 +38.75,126.75,186.5,111.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20034_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20034_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..a05f5f289e001d3e4e4a84aa3c5d42f2d4ab41a1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20034_IgR.txt @@ -0,0 +1,5 @@ +455.75,0.5,189.5,55.75 +718.75,32.75,241.75,60.5 +874.75,97.75,85.75,42.5 +133.75,37.75,219.5,94.5 +45.75,134.75,165.5,112.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20035_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20035_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ee5d49db92eec9164ee4d8291f82c58afc3b34c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20035_IgR.txt @@ -0,0 +1,7 @@ +450.75,0.5,183.5,60 +716.75,26.75,243.75,57.5 +877.75,87.75,82.75,51.5 +0.5,123.75,141.75,152.5 +144.75,85.75,97.5,114.5 +244.75,42.75,102.5,65.5 +0.5,279.75,27.75,25.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20051_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20051_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..f4dfa91a0ffb4ec068f7afc6ead3bfd1769fefc9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20051_IgR.txt @@ -0,0 +1,5 @@ +807.75,0.5,146.5,92.75 +543.75,0.5,173.5,58.75 +0.5,180.75,160.75,100.5 +122.75,116.75,266.5,74.5 +322.75,60.75,107.5,48.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20052_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20052_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..b117a195eaa303d024b3078ed7fd85f529139164 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20052_IgR.txt @@ -0,0 +1,6 @@ +542.75,0.5,194.5,27.75 +832.75,0.5,127.75,53.75 +256.75,42.75,155.5,75.5 +135.75,88.75,120.5,132.5 +259.75,123.75,109.5,71.5 +0.5,166.75,131.75,107.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20061_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20061_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..4bf4e074339a83bca2c18734f1359be4df9781ee --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20061_IgR.txt @@ -0,0 +1,6 @@ +513.75,13.75,185.5,46.5 +839.75,46.75,114.5,62.5 +298.75,59.75,112.5,121.5 +92.75,94.75,203.5,171.5 +0.5,246.75,90.75,282.5 +93.75,270.75,136.5,108.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20062_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20062_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..8d011d9bd90d6d43391bb4ec84fe64447c3caa16 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20062_IgR.txt @@ -0,0 +1,6 @@ +517.75,0.5,165,33.75 +824.75,30.75,135.75,54.5 +323.75,36.75,107.5,76.5 +97.75,107.75,336.5,56.5 +86.75,167.75,153.5,65.5 +0.5,234.75,155.75,103.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20063_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20063_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..86af94615a13e283ee5e4549fc36bca117ca7ec4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20063_IgR.txt @@ -0,0 +1,6 @@ +851.75,14.75,108.75,48.5 +86.75,82.75,295.5,44.5 +316.75,20.75,111.5,60.5 +135.75,130.75,119.5,84.5 +85.75,183.75,47.5,69.5 +0.5,214.75,84.75,139.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20064_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20064_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..6b3a5d75c560626fba4ea4cf6ee92254b9ac5d0c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20064_IgR.txt @@ -0,0 +1,9 @@ +511.75,0.5,269.5,27.75 +852.75,27.75,101.5,23.5 +895.75,54.75,64.75,20.5 +0.5,215.75,101.75,97.5 +106.75,89.75,56.5,156.5 +166.75,137.75,49.5,70.5 +218.75,90.75,35.5,88.5 +257.75,71.75,87.5,54.5 +347.75,21.75,77.5,68.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20065_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20065_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..4fe7856f1be15d6c133cee5a7f4bef3b8438781f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_20065_IgR.txt @@ -0,0 +1,6 @@ +513.75,0.5,238.5,23.75 +857.75,15.75,102.75,46.5 +167.75,77.75,275.5,74.5 +329.75,10.75,104.5,64.5 +0.5,207.75,102.75,263.5 +104.75,155.75,155.5,147.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39031_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39031_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..050ae18bea03c5aa8f0b7d3312fb6859b2eb9a78 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39031_IgR.txt @@ -0,0 +1,3 @@ +335.75,52.75,256.5,117.5 +0.5,296.75,223.75,120.5 +690.75,116.75,269.75,94.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39051_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39051_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..f69bd96cee6ee9168513331c03bbf46acbef958d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39051_IgR.txt @@ -0,0 +1,2 @@ +916.75,283.75,43.75,41.5 +853.75,443.75,99.5,91.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39211_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39211_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..cc0e5bad5323d5e1b2421cad6d7c169e795f0429 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39211_IgR.txt @@ -0,0 +1 @@ +380.75,0.5,579.75,96.75 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39271_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39271_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..e5c65bf6d5b41a79da6e9a3c6787ad1a0d18b005 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39271_IgR.txt @@ -0,0 +1,4 @@ +742.75,349.75,217.75,190.75 +856.75,159.75,103.75,63.5 +567.75,200.75,160.5,44.5 +73.75,233.75,99.5,95.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39311_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39311_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..680f501e3dc2407c561cbe3c2e7f3d5f0a84c7b6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39311_IgR.txt @@ -0,0 +1,7 @@ +0.5,218.75,336.75,65.5 +0.5,283.75,252.75,75 +0.5,358.75,200,50 +0.5,408.75,150,50 +487.75,125.75,472.75,94.5 +763.75,232.75,196.75,114.5 +818.75,350.75,141.75,45.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39361_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39361_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..3a2d34399d0d1c429ae1edc2c793ea6b3a4810d6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39361_IgR.txt @@ -0,0 +1,6 @@ +0.5,71.75,903.75,107.5 +793.75,182.75,166.75,50.5 +862.75,232.75,97.75,94.5 +0.5,185.75,175.75,44.5 +0.5,234.75,112.75,46.5 +0.5,287.75,58.75,43.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39371_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39371_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..17de11e8f4568199bb95a78df445c8604518672d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39371_IgR.txt @@ -0,0 +1,2 @@ +0.5,332.75,130.75,47.5 +755.75,231.75,204.75,51.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39401_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39401_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..2cf27894c161c09fe0420165258081b399414e00 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39401_IgR.txt @@ -0,0 +1,4 @@ +142.75,64.75,817.75,111.5 +829.75,176.75,130.75,55.5 +0.5,179.75,169.75,66.5 +0.5,251.75,106.75,117.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39501_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39501_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..20d9ac554ddca9a94416e7f9ff3b58f4a6917e58 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39501_IgR.txt @@ -0,0 +1,10 @@ +349.75,138.75,381.5,42.5 +623.75,185.75,306.5,56.5 +730.75,245.75,229.75,58.5 +808.75,308.75,151.75,44.5 +904.75,355.75,55.75,71.5 +295.75,183.75,81.5,100.5 +143.75,219.75,153.5,110.5 +0.5,333.75,232.75,56.5 +58.75,280.75,84.5,50.5 +0.5,394.75,153.75,67.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39511_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39511_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..585cfe51fb3408cdda1a80cc292ec9fda012f3fb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39511_IgR.txt @@ -0,0 +1,8 @@ +357.75,172.75,354.5,31.5 +600.75,205.75,270.5,38.5 +660.75,246.75,299.75,52.5 +761.75,302.75,198.75,59.5 +867.75,365.75,92.75,73.5 +302.75,206.75,118.5,45.5 +207.75,255.75,104.5,134.5 +0.5,301.75,203.75,134.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39761_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39761_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..3aa24c8134ab0342084198d1a071214523ad09ee --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39761_IgR.txt @@ -0,0 +1,6 @@ +0.5,209.75,59.75,61.5 +201.75,167.75,42.5,35.5 +445.75,100.75,220.5,51.5 +746.75,124.75,72.5,80.5 +822.75,157.75,71.5,86.5 +897.75,189.75,57.5,92.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39771_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39771_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f3dc507c27883d5cca4ad143a5a425ed716eb65 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39771_IgR.txt @@ -0,0 +1,5 @@ +413.75,88.75,210.5,46.5 +672.75,105.75,169.5,41.5 +829.75,156.75,65.5,88.5 +298.75,102.75,45.5,53.5 +218.75,123.75,79.5,69.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39781_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39781_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..150f4179082740b98225fcf978720b0513df790e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39781_IgR.txt @@ -0,0 +1,5 @@ +0.5,0.5,436.75,43.75 +0.5,47.75,164.75,31.5 +428.75,45.75,66.5,31.5 +546.75,65.75,87.5,51.5 +709.75,89.75,250.75,91.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39801_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39801_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..59b9ab57369eaacb47a4c3971aa9e02268c2b843 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39801_IgR.txt @@ -0,0 +1,7 @@ +17.75,101.75,187.5,34.5 +19.75,139.75,98.5,20.5 +270.75,100.75,41.5,37.5 +829.75,159.75,130.75,62.5 +642.75,136.75,158.5,50.5 +371.75,104.75,113.5,45.5 +487.75,116.75,128.5,47.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39811_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39811_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..c5f3c77d0d2f0c4fe2ce09501416a2687ea4c7a4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39811_IgR.txt @@ -0,0 +1,5 @@ +73.75,71.75,299.5,46.5 +102.75,124.75,145.5,30.5 +435.75,91.75,201.5,48.5 +685.75,121.75,158.5,50.5 +865.75,142.75,89.5,49.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39821_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39821_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..0692db6f0166d4477abe352944d647abd6d7864f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39821_IgR.txt @@ -0,0 +1,10 @@ +0.5,83.75,74.75,138.5 +166.75,52.75,165.5,41.5 +163.75,96.75,102.5,28.5 +870.75,129.75,79.5,65.5 +785.75,119.75,81.5,58.5 +668.75,96.75,65.5,54.5 +620.75,92.75,45.5,41.5 +577.75,88.75,40.5,37.5 +532.75,83.75,42.5,34.5 +498.75,80.75,31.5,31.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39851_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39851_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e77484220da6f6b1d3cdf002a4d40f7cc44e352 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39851_IgR.txt @@ -0,0 +1,4 @@ +391.75,0.5,351.5,44.75 +806.75,61.75,56.5,80.5 +176.75,27.75,215.5,26.5 +181.75,58.75,88.5,44.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39861_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39861_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..8f629cddd4435daf04fb345f04e04db5b3b70a56 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39861_IgR.txt @@ -0,0 +1,4 @@ +64.75,103.75,84.5,138.5 +243.75,67.75,107.5,37.5 +646.75,92.75,99.5,37.5 +862.75,116.75,83.5,55.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39931_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39931_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a066d822451fcad0e90540201abe8916c3b31ff --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_39931_IgR.txt @@ -0,0 +1,2 @@ +0.5,0.5,245.75,56.75 +0.5,61.75,145.75,28.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40131_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40131_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..6dc8a6e5bc348856585a44ac6ca1a20c710578df --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40131_IgR.txt @@ -0,0 +1,6 @@ +0.5,74.75,144.75,93.5 +349.75,0.5,296.5,81.75 +745.75,42.75,214.75,95.5 +5.75,169.75,76.5,29.5 +147.75,18.75,125.5,67.5 +147.75,88.75,79.5,20.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40141_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40141_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..51322e490434c01e5f6cb5dc14ab48c8de107b75 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40141_IgR.txt @@ -0,0 +1,7 @@ +438.75,82.75,140.5,48.5 +656.75,134.75,148.5,66.5 +753.75,201.75,206.75,56.5 +848.75,257.75,111.75,72.5 +0.5,188.75,142.75,108.5 +176.75,152.75,96.5,50.5 +275.75,123.75,64.5,43.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40152_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40152_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..e9037a4c290ef45a57f839706c5dd9e747521c5c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40152_IgR.txt @@ -0,0 +1,6 @@ +741.75,87.75,212.5,62.5 +0.5,211.75,125.75,114.5 +127.75,194.75,59.5,84.5 +187.75,170.75,165.5,67.5 +354.75,159.75,66.5,42.5 +478.75,126.75,181.5,37.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40161_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40161_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..6761091bf5e8395f00134ad4b145c451d585f3c9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40161_IgR.txt @@ -0,0 +1,5 @@ +0.5,0.5,905.75,67.75 +566.75,70.75,388.5,72.5 +5.75,72.75,162.5,26.5 +0.5,106.75,76.75,21.5 +452.75,68.75,117.5,31.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40162_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40162_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..1bae52c21314b63ee5e2ee2a878e1ff97221fea6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40162_IgR.txt @@ -0,0 +1,8 @@ +0.5,41.75,293.75,43.5 +0.5,88.75,210,27.5 +0.5,120.75,94.75,21.5 +298.75,51.75,167.5,43.5 +509.75,68.75,90.5,38.5 +672.75,80.75,282.5,76.5 +702.75,36.75,257.75,42.5 +384.75,27.75,281.5,26.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40171_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40171_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..5db03bbcb3fb2dd407c92077951c7f463c16b837 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40171_IgR.txt @@ -0,0 +1 @@ +593.75,0.5,366.75,42.75 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40172_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40172_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..71408416555c62603ccc9075b0134deac287f439 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40172_IgR.txt @@ -0,0 +1,3 @@ +54.75,60.75,119.5,37.5 +768.75,0.5,191.75,71.75 +365.75,14.75,233.5,39.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40181_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40181_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40191_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40191_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..097ff1af71b69691d9091751242b41bc2b59b3c4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40191_IgR.txt @@ -0,0 +1,3 @@ +0.5,0.5,251.75,31.75 +401.75,17.75,282.5,44.5 +327.75,63.75,414.5,32.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40192_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40192_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..82e6ca370d1e4995d478225162f6e3b40ce38013 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40192_IgR.txt @@ -0,0 +1,3 @@ +0.5,0.5,221.75,34.75 +407.75,19.75,311.5,29.5 +310.75,52.75,489.5,40.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40201_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40201_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..0af6030f26e4851e81f642d98152007deb7e11b2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40201_IgR.txt @@ -0,0 +1,3 @@ +0.5,0.5,426.75,53.75 +0.5,57.75,213.75,23.5 +0.5,84.75,85.75,15.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40204_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40204_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..ee9165fdadea4440d733d870b0c44d9940ba3d00 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40204_IgR.txt @@ -0,0 +1,2 @@ +0.5,0.5,247.75,13.75 +0.5,17.75,157.75,19.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40211_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40211_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40212_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40212_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40213_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40213_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40241_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40241_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..bd417f4f0caef03048c830f7afdeda5bab10b6d1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40241_IgR.txt @@ -0,0 +1,2 @@ +606.75,0.5,353.75,32.75 +427.75,35.75,532.75,50.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40243_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40243_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e662efa3fa1833903fcd0bf032aaf7261518792 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40243_IgR.txt @@ -0,0 +1,3 @@ +0.5,0.5,523.75,65.75 +671.75,26.75,288.75,45.5 +512.75,73.75,447.75,46.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40244_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40244_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..3cc0523176f6c565375b77b47012b65efab52b6a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40244_IgR.txt @@ -0,0 +1,4 @@ +0.5,0.5,426.75,57.75 +599.75,0.5,360.75,73.75 +460.75,75.75,499.75,45.5 +0.5,220,50,250 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40701_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40701_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..da95507ad8cbef229e8c60e1413698fcc8a5b3d5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40701_IgR.txt @@ -0,0 +1,2 @@ +0.5,0.5,960,95.75 +0.5,102.75,123.75,62.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40711_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40711_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..bbb21aafdf9e27720e42051197a07cfd247724db --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40711_IgR.txt @@ -0,0 +1,3 @@ +414.75,27.75,285.5,63.5 +204.75,62.75,206.5,85.5 +415.75,93.75,544.75,65.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40712_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40712_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..cd5837999b2a9784029b9ad6885f12b0f4e69c4d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40712_IgR.txt @@ -0,0 +1,5 @@ +407.75,9.75,325.5,67.5 +143.75,50.75,263.5,78.5 +410.75,80.75,549.75,49.5 +78.75,107.75,61.5,47.5 +0.5,146.75,74.75,56.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40714_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40714_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..3d4a71d2bb40a26be1f555f73cd4d128292e6040 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40714_IgR.txt @@ -0,0 +1,3 @@ +342.75,48.75,382.5,50.5 +903.75,127.75,56.75,41.5 +64.75,90.75,213.5,33.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40732_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40732_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40742_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40742_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..35c5ddffc447fb3395d5809c9ed570ad6191f428 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40742_IgR.txt @@ -0,0 +1,5 @@ +9.75,81.75,541.5,45.5 +446.75,130.75,513.75,28.5 +644.75,160.75,315.75,28.5 +0.5,131.75,216.75,17.5 +0.5,152.75,115.75,28.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40743_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40743_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..7249084ae885f8dd67edac79205aefcbf4ca943b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40743_IgR.txt @@ -0,0 +1,6 @@ +0.5,76.75,960,35.5 +0.5,115.75,257.75,39.5 +0.5,160.75,182.75,21.5 +0.5,188.75,137.75,20.5 +0.5,216.75,91.75,17.5 +0.5,239.75,51.75,27.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40751_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40751_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..c86d1d355fdd168eade6f978faaef4eb177ad83c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40751_IgR.txt @@ -0,0 +1 @@ +874.75,253.75,85.75,52.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40752_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40752_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b2197c51102b06dbd6799effd446003d5d0a0a2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40752_IgR.txt @@ -0,0 +1,5 @@ +653.75,0.5,306.75,58.75 +895.75,61.75,57.5,49.5 +0.5,47.75,186.75,76.5 +191.75,25.75,161.5,59.5 +355.75,0.5,223.5,44.75 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40761_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40761_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..7776815df61293c8c03dc494c99cf153bc8f69ba --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40761_IgR.txt @@ -0,0 +1,2 @@ +0.5,486.75,960,53.75 +711.75,49.75,210.5,77.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40762_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40762_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..f855b60420ba8c945d96709bff01251ad55e4ed0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40762_IgR.txt @@ -0,0 +1,2 @@ +0.5,146.75,36.75,225.5 +686.75,105.75,273.75,66.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40763_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40763_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..02f35ff9db4fe74f3df707701581e2bea493f7c2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40763_IgR.txt @@ -0,0 +1,2 @@ +0.5,148.75,35.75,391.75 +670.75,131.75,284.5,55.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40771_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40771_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..a9252dfe16653dfaca6706a8eeee9344682ef0e9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40771_IgR.txt @@ -0,0 +1,5 @@ +93.75,0.5,866.75,62.75 +779.75,65.75,180.75,38.5 +862.75,108.75,97.75,44.5 +0.5,65.75,161.75,29.5 +0.5,99.75,98.75,30.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40772_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40772_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..0835334382ceadd3162bda4a224fe20e344e6952 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40772_IgR.txt @@ -0,0 +1,2 @@ +102.75,0.5,857.75,57.75 +0.5,60.75,120.75,52.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40773_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40773_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..22ab3d07e206530ece863185c8336c9cb6ac64bd --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40773_IgR.txt @@ -0,0 +1,5 @@ +249.75,0.5,710.75,22.75 +762.75,25.75,197.75,50.5 +864.75,80.75,95.75,69.5 +0.5,41.75,187.75,36.5 +0.5,85.75,130.75,47.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40774_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40774_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..c18298e042dd88335cc76ae6eba69f715715f2c9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40774_IgR.txt @@ -0,0 +1,4 @@ +185.75,5.75,774.75,40.5 +761.75,49.75,198.75,45.5 +839.75,100.75,120.75,46.5 +0.5,46.75,99.75,42.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40775_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40775_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..f8c5166605dad79cb7d74c468aa1a0caca91b548 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40775_IgR.txt @@ -0,0 +1,6 @@ +192.75,0.5,767.75,37.75 +763.75,41.75,196.75,34.5 +819.75,78.75,140.75,35.5 +891.75,118.75,68.75,63.5 +0.5,38.75,188.75,28.5 +0.5,72.75,110.75,51.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40792_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40792_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..709cb0c87fe4cd95eccd3980b5faf8cbfff3f517 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40792_IgR.txt @@ -0,0 +1,4 @@ +373.75,0.5,586.75,56.75 +522.75,61.75,437.75,32.5 +0.5,56.75,324.75,28.5 +0.5,90.75,161.75,30.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40793_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40793_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..7d3fbc1e89df78fa7b6f941cc355bacbf62ccb9e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40793_IgR.txt @@ -0,0 +1,3 @@ +289.75,0.5,670.75,93.75 +0.5,96.75,357.75,23.5 +0.5,125.75,158.75,35.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40851_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40851_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..c834f01590e209ac297f3a94a874572e7d1e71d5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40851_IgR.txt @@ -0,0 +1,2 @@ +0.5,47.75,960,72.5 +870.75,124.75,89.75,71.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40852_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40852_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..54d5db8406df6f1f3640ba58446d24e204e086fa --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40852_IgR.txt @@ -0,0 +1,2 @@ +0.5,45.75,960,80.5 +897.75,130.75,62.75,66.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40853_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40853_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..a6107862839a5b090ac18ceb257cc916f2590730 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40853_IgR.txt @@ -0,0 +1,2 @@ +0.5,49.75,960,73.5 +917.75,127.75,42.75,71.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40854_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40854_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..de813405059383fca80a08512a6f63071d35f8a3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40854_IgR.txt @@ -0,0 +1,3 @@ +0.5,69.75,217.75,59.5 +222.75,40.75,737.75,62.5 +890.75,105.75,69.75,89.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40855_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40855_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..3dcd81112c100b88d8d0291fb6cff551f6ba573d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40855_IgR.txt @@ -0,0 +1,3 @@ +0.5,63.75,221.75,60.5 +223.75,27.75,736.75,84.5 +883.75,113.75,76.75,79.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40863_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40863_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..56a00a4be97fa2c64420cdc3fe701de314bfa94e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40863_IgR.txt @@ -0,0 +1,5 @@ +0.5,0.5,960,51.75 +0.5,56.75,168.75,23.5 +0.5,84.75,81.75,29.5 +401.75,54.75,558.75,29.5 +711.75,84.75,248.75,42.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40864_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40864_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..966d17cbc6b9c2b3f44bd11c152a4970396b131d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40864_IgR.txt @@ -0,0 +1,3 @@ +0.5,0.5,960,65.75 +0.5,71.75,167.75,22.5 +0.5,98.75,74.75,25.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40871_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40871_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..56b3fd6d4a732696443d21447ac96e63ddb34c6e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40871_IgR.txt @@ -0,0 +1,5 @@ +0.5,0.5,960,92.75 +0.5,97.75,380.75,13.5 +81.75,113.75,185.5,33.5 +516.75,98.75,443.75,33.5 +731.75,136.75,228.75,38.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40891_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40891_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..dfaae12ae7fb82a7edfe218439b988a5da8c7efc --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40891_IgR.txt @@ -0,0 +1,3 @@ +25.75,13.75,934.75,64.5 +817.75,79.75,142.75,220.5 +39.75,80.75,198.5,25.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40892_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40892_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..5c47fbb5cd9559284201c2de0e4b66ea3ecb4cf3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40892_IgR.txt @@ -0,0 +1,3 @@ +293.75,12.75,666.75,70.5 +899.75,86.75,60.75,453.75 +25.75,55.75,268.5,27.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40901_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40901_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..d2abfbf5d58b85b6c3526bc3769ff570251eaf2f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40901_IgR.txt @@ -0,0 +1,5 @@ +826.75,0.5,133.75,34.75 +874.75,39.75,85.75,38.5 +0.5,0.5,362.75,36.75 +0.5,41.75,267.75,55.5 +0.5,102.75,131.75,75.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40902_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40902_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..d6d69de9ffb8a582c1cf42d5675f2fa4768f2a4e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40902_IgR.txt @@ -0,0 +1,6 @@ +0.5,300.75,960,239.75 +812.75,0.5,147.75,40.75 +878.75,45.75,81.75,40.5 +148.75,0.5,204.5,38.75 +0.5,43.75,143.75,151.5 +148.75,40.75,132.5,83.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40903_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40903_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..f77b8d3053217dc378cb00b6765c21fa4eb131ba --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40903_IgR.txt @@ -0,0 +1,5 @@ +805.75,0.5,154.75,44.75 +871.75,49.75,88.75,65.5 +200.75,0.5,187.5,40.75 +0.5,45.75,195.75,41.5 +0.5,91.75,99.75,44.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40904_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40904_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..222f87df4f8e28cc1db4f8db346ba8d355dfe666 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40904_IgR.txt @@ -0,0 +1,8 @@ +0.5,441.75,960,98.75 +750.75,0.5,209.75,40.75 +835.75,45.75,124.75,30.5 +475.75,0.5,183.5,40.75 +124.75,0.5,272.5,57.75 +0.5,64.75,271.75,39.5 +0.5,110.75,215.75,44.5 +0.5,158.75,132.75,61.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40905_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40905_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..6337875a1785590c9eb2369bbe5871a562fb9cb8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40905_IgR.txt @@ -0,0 +1,7 @@ +479.75,0.5,193.5,41.75 +728.75,0.5,231.75,48.75 +850.75,53.75,109.75,55.5 +221.75,0.5,177.5,65.75 +107.75,31.75,111.5,94.5 +0.5,55.75,103.75,178.5 +106.75,129.75,74.5,46.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40962_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40962_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..b2fd961c56e867c78d10e8e4c24653b9c05864a2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40962_IgR.txt @@ -0,0 +1,5 @@ +393.75,0.5,263.5,13.75 +0.5,0.5,215.75,81.75 +690.75,0.5,269.75,65.75 +790.75,70.75,169.75,115.5 +868.75,189.75,91.75,119.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40963_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40963_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..0c5664a3b8131fb9e96dcbb925cc3ddac73df2b9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40963_IgR.txt @@ -0,0 +1,2 @@ +6.75,8.75,159.5,56.5 +924.75,0.5,35.75,23.75 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40981_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40981_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2c5e4d2998e874fa54e6714ded35543b89fb530 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40981_IgR.txt @@ -0,0 +1,2 @@ +6.75,6.75,246.5,43.5 +9.75,55.75,174.5,50.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40991_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40991_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..010e51947d6f1b6120a654ad68f27dff5facf05c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40991_IgR.txt @@ -0,0 +1,3 @@ +0.5,67.75,247.75,34.5 +0.5,106.75,141.75,29.5 +0.5,417.75,236.75,122.75 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40992_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40992_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..bacf3e655f276370fe9ab5fa53d15bd3e6f6cc8d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_40992_IgR.txt @@ -0,0 +1,3 @@ +0.5,417.75,236.75,122.75 +0.5,78.75,352.75,50.5 +0.5,134.75,231.75,23.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_41063_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_41063_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..1a8eb9f39ff412a7214221042ba234e9b47e0711 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_41063_IgR.txt @@ -0,0 +1,3 @@ +0.5,63.75,106.75,43.5 +0.5,362.75,123.75,177.75 +127.75,434.75,194.5,105.75 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_41073_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_41073_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..cd481d1fa9863a9b3e3ba31f499720244bec2dd6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_41073_IgR.txt @@ -0,0 +1,3 @@ +901.75,29.75,58.75,52.5 +879.75,395.75,80.75,144.75 +749.75,452.75,126.5,87.75 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63521_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63521_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..106dcfd26f487a6e76c3eca95b20a869c0c1c5c0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63521_IgR.txt @@ -0,0 +1,2 @@ +91.75,0.5,108.5,58.75 +5.75,33.75,60.5,73.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63525_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63525_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..a3f9e1f40f3150c8b898ea1be1fb1e319b64f2de --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63525_IgR.txt @@ -0,0 +1,2 @@ +0.5,16.75,48.75,33.5 +77.75,0.5,70.5,42.75 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63544_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63544_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7734a42a9ca75bd9d559975a716bd38a6f5dc39 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63544_IgR.txt @@ -0,0 +1,9 @@ +708.75,0.5,251.75,19.75 +0.5,172.75,65.75,47.5 +71.75,141.75,99.5,50.5 +175.75,112.75,91.5,42.5 +384.75,64.75,47.5,33.5 +435.75,43.75,45.5,34.5 +483.75,32.75,40.5,26.5 +528.75,19.75,43.5,22.5 +575.75,0.5,41.5,29.75 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63552_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63552_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..b26bb71c932d127b8d9b444c8b80b32870c5695e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63552_IgR.txt @@ -0,0 +1,3 @@ +0.5,12.75,960,33.5 +0.5,50.75,85.75,128.5 +88.75,77.75,106.5,87.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63553_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63553_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..77090ee817854942dd73962b5747acf1716773cd --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63553_IgR.txt @@ -0,0 +1,2 @@ +0.5,71.75,90.75,45.5 +889.75,390.75,70.75,143.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63554_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63554_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb4137b187beddc74f2aa51f7ce3dd2f9982d5e6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63554_IgR.txt @@ -0,0 +1 @@ +0.5,63.75,108.75,67.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63561_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63561_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..6432f7f36a642ae99994f2ba053e8c16be1f032f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63561_IgR.txt @@ -0,0 +1,3 @@ +885.75,391.75,74.75,143.5 +700.75,0.5,259.75,52.75 +518.75,38.75,180.5,33.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63562_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63562_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..bdbef8e587e84cd9a0f6eb37e910f8ddfc7877f9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63562_IgR.txt @@ -0,0 +1,4 @@ +784.75,483.75,175.75,56.75 +871.75,395.75,88.75,81.5 +792.75,9.75,167.75,46.5 +903.75,79.75,56.75,52.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63563_IgR.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63563_IgR.txt new file mode 100644 index 0000000000000000000000000000000000000000..5752bf5af5275ef0cb910bcc2f76654610980037 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/igrs/MVI_63563_IgR.txt @@ -0,0 +1,3 @@ +805.25,11.75,155.25,30.5 +865.75,46.75,94.75,27.5 +917.75,77.75,42.75,33.5 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/preProcessDetectionResults.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/preProcessDetectionResults.m new file mode 100644 index 0000000000000000000000000000000000000000..3837580738bfc0d72f8fdbc6ee5c8c184e1eb09a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/preProcessDetectionResults.m @@ -0,0 +1,70 @@ +function preProcessDetectionResults(detectorName) + +global options sequences + +optionID = find(ismember({'DETRAC-Test','DETRAC-Train','DETRAC-Free','DETRAC-Test-Beginner','DETRAC-Test-Experienced'},options.evaluateSeqs)); +if(optionID == 1) + listPath = 'seqs/testlist-full.txt'; +elseif(optionID == 2) + listPath = 'seqs/trainlist-full.txt'; +elseif(optionID == 3) + listPath = '../sequences.txt'; +elseif(optionID == 4) + listPath = 'seqs/testlist-det-beginner.txt'; +elseif(optionID == 5) + listPath = 'seqs/testlist-det-experienced.txt'; +else + error('error in sequences for evaluation!'); +end + +%% calculate the minimal and maximal detection scores +disp('pre-processing the detection results...'); +createNewPath([options.detPath 'tmps\' ]); +fidSeq = fopen(listPath); +idSeq = 0; +scores = []; +while(~feof(fidSeq)) + idSeq = idSeq + 1; + % Data sequence + seqName = fgetl(fidSeq); + oldPath = [options.detPath detectorName '\' seqName '_Det_' detectorName '.txt']; + tmpPath = [options.detPath 'tmps\' seqName '_Det_' detectorName '.txt']; + if(~exist(oldPath, 'file')) + disp(['missing detection result for sequence' seqName '!']); + end + detections = load(oldPath); + scores = cat(1,scores,detections(:,end)); + movefile(oldPath,tmpPath); +end +fclose(fidSeq); + +minScore = min(scores); +maxScore = max(scores); + +%% normlized the detection scores and move the invalid detections +createPath([options.detPath detectorName '\']); +fidSeq = fopen(listPath); +idSeq = 0; +while(~feof(fidSeq)) + idSeq = idSeq + 1; + % Data sequence + seqID = fgetl(fidSeq); + seqName = seqID(end-8:end); + oldPath = [options.detPath 'tmps\' seqName '_Det_' detectorName '.txt']; + newPath = [options.detPath detectorName '\' seqName '_Det_' detectorName '.txt']; + detections = load(oldPath); + norm_detections = detections; + scores_ = (detections(:,end)-minScore)/(maxScore-minScore); + norm_detections = cat(2, norm_detections(:,1:end-1), scores_); + + ignoreFile = ['igrs/' seqID '_IgR.txt']; + imgHeight = sequences{idSeq}.imgHeight; + imgWidth = sequences{idSeq}.imgWidth; + cutdetections = dropDetections(norm_detections, ignoreFile, imgHeight, imgWidth); + fr = unique(cutdetections(:,1)); + for k = 1:numel(fr) + curLine = find(cutdetections(:,1) == fr(k)); + cutdetections(curLine,2) = 1:numel(curLine); + end + dlmwrite(newPath, cutdetections); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/printFinalEvaluation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/printFinalEvaluation.m new file mode 100644 index 0000000000000000000000000000000000000000..73cd95a412cbbf2c98c6c989f5903f33a4dd509d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/printFinalEvaluation.m @@ -0,0 +1,55 @@ +function printFinalEvaluation(res_path, detectorSet, folderName) + +global options tracker + +if(options.printEvaluationForWholeSet) + trackerName = tracker.trackerName; + metricsInfo = getMetricInfo(); + curPath = pwd; + cd('./evaluation'); + addpath(genpath('.')); + for idDet = 1:length(detectorSet) + detectorName = detectorSet{idDet}; + if(strcmp(options.motmetric, 'CLEAR-MOT')) + % obtain CLEAR-MOT scores + clearmotLine = ['CLEAR_MOT_EVAL.exe ' trackerName ' ' detectorName ' ' curPath '/' res_path detectorName '/ ' ... + curPath '/thresh.txt ' curPath '/sequences.txt ' curPath '/' res_path detectorName '/']; + evalexe(clearmotLine); + % print CLEAR-MOT scores + for idThre = 1:length(folderName) + motFile = [curPath '/' res_path detectorName '/' trackerName '_' detectorName '_CLEAR-MOT_results.txt']; + metricsAll = load(motFile); + disp(['Tracker ' trackerName ' + Detector ' detectorName ' (Detection Score Threshold=' folderName{idThre} ') by CLEAR-MOT Evaluation:']); + metrics = metricsAll(idThre, :); + printMetrics(metrics, metricsInfo, 1); + end + elseif(strcmp(options.motmetric, 'DETRAC-MOT')) + % obtain detection PR scores + detprFile = [options.detPath detectorName '/' detectorName '_detection_PR.txt']; + detprLine = ['DETRAC_DET_EVAL.exe ' detectorName ' ' options.detPath detectorName '/ ' curPath '/sequences.txt ' num2str(options.trackingThreStep) ' ' options.detPath detectorName '/']; + evalexe(detprLine); + if(exist(detprFile, 'file')) + showDetectionPRCurve(detprFile, detectorName); + else + error('no detection results!'); + end + % obtain DETRAC-MOT scores + detracmotLine = ['DETRAC_MOT_EVAL.exe ' trackerName ' ' detectorName ' ' options.detPath detectorName '/' detectorName '_thres.txt '... + detprFile ' ' curPath '/sequences.txt ' ... + curPath '/' res_path detectorName '/ ' curPath '/' res_path detectorName '/']; + evalexe(detracmotLine); + motFile = [curPath '/' res_path detectorName '/' trackerName '_' detectorName '_DETRAC-MOT_results.txt']; + if(exist(motFile, 'file')) + temp = load(motFile); + metrics = temp(temp(:,1) == -1, 2:end); + metricsInfo = getPRMetricInfo(); + disp(['Tracker ' trackerName ' + Detector ' detectorName ' by DETRAC-MOT Evaluation:']); + padChar={' ',' ','|',' ',' ','|',' ',' ',' ','| ',' ',' ',' '}; + printMetrics(metrics, metricsInfo, 1, padChar); + else + error('no tracking results!'); + end + end + end + cd('../'); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/printMetrics.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/printMetrics.m new file mode 100644 index 0000000000000000000000000000000000000000..2f15323d6aa64aa9b7dc1c25e742764e4244c20e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/printMetrics.m @@ -0,0 +1,38 @@ +function printMetrics(metrics, metricsInfo, dispHeader, padChar) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +namesToDisplay=metricsInfo.names.long; +widthsToDisplay=metricsInfo.widths.long; +formatToDisplay=metricsInfo.format.long; + +namesToDisplay=metricsInfo.names.short; +widthsToDisplay=metricsInfo.widths.short; +formatToDisplay=metricsInfo.format.short; + +if nargin<3, dispHeader=1; end +dispMetrics=1:length(metrics); +if nargin<4 + padChar={' ',' ','|',' ',' ',' ','|',' ',' ',' ','| ',' ',' ',' '}; +end + +if dispHeader + for m=dispMetrics + printString=sprintf('fprintf(''%%%is%s'',char(namesToDisplay(m)))',widthsToDisplay(m),char(padChar(m))); + eval(printString) + end + fprintf('\n'); +end + +for m=dispMetrics + printString=sprintf('fprintf(''%%%i%s%s'',metrics(m))',widthsToDisplay(m),char(formatToDisplay(m)),char(padChar(m))); + eval(printString) +end + +fprintf('\n'); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/printSeqEvaluation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/printSeqEvaluation.m new file mode 100644 index 0000000000000000000000000000000000000000..64ad9b7b755dcc2166a347f47c9bdf15ed012647 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/printSeqEvaluation.m @@ -0,0 +1,11 @@ +function metrics = printSeqEvaluation(seqName, gtInfo, stateInfo, folder) + +global options + +metrics = []; + +if(options.printEvaluationForEachSeq) + [metrics, metricsInfo] = CLEAR_MOT(gtInfo, stateInfo); + disp(['2D Evaluation of Sequence ' seqName ' (Detection Score Threshold=' folder '):']); + printMetrics(metrics, metricsInfo, 1); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-det-beginner.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-det-beginner.txt new file mode 100644 index 0000000000000000000000000000000000000000..d8f1408058ae0bf85d7127ac722c2c9533823d6c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-det-beginner.txt @@ -0,0 +1,10 @@ +MVI_40712 +MVI_40774 +MVI_40773 +MVI_40772 +MVI_40711 +MVI_40771 +MVI_40792 +MVI_40775 +MVI_39361 +MVI_40901 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-det-experienced.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-det-experienced.txt new file mode 100644 index 0000000000000000000000000000000000000000..98f7eb8fc7335a49916563740500076e328b5551 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-det-experienced.txt @@ -0,0 +1,40 @@ +MVI_39501 +MVI_39511 +MVI_40701 +MVI_40851 +MVI_40852 +MVI_40853 +MVI_40854 +MVI_40855 +MVI_40711 +MVI_40712 +MVI_40714 +MVI_40742 +MVI_40743 +MVI_40761 +MVI_40762 +MVI_40763 +MVI_40771 +MVI_40772 +MVI_40773 +MVI_40774 +MVI_40775 +MVI_40792 +MVI_40793 +MVI_40863 +MVI_40864 +MVI_40891 +MVI_40892 +MVI_40901 +MVI_40902 +MVI_40903 +MVI_40904 +MVI_40905 +MVI_39031 +MVI_39211 +MVI_39051 +MVI_39271 +MVI_39311 +MVI_39361 +MVI_39371 +MVI_39401 \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-full.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-full.txt new file mode 100644 index 0000000000000000000000000000000000000000..98f7eb8fc7335a49916563740500076e328b5551 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-full.txt @@ -0,0 +1,40 @@ +MVI_39501 +MVI_39511 +MVI_40701 +MVI_40851 +MVI_40852 +MVI_40853 +MVI_40854 +MVI_40855 +MVI_40711 +MVI_40712 +MVI_40714 +MVI_40742 +MVI_40743 +MVI_40761 +MVI_40762 +MVI_40763 +MVI_40771 +MVI_40772 +MVI_40773 +MVI_40774 +MVI_40775 +MVI_40792 +MVI_40793 +MVI_40863 +MVI_40864 +MVI_40891 +MVI_40892 +MVI_40901 +MVI_40902 +MVI_40903 +MVI_40904 +MVI_40905 +MVI_39031 +MVI_39211 +MVI_39051 +MVI_39271 +MVI_39311 +MVI_39361 +MVI_39371 +MVI_39401 \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-trk-beginner.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-trk-beginner.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7bc5a05281545e81609faa981619892a5c9f154 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-trk-beginner.txt @@ -0,0 +1,10 @@ +MVI_39211 +MVI_39031 +MVI_40712 +MVI_40854 +MVI_40701 +MVI_40852 +MVI_39401 +MVI_40743 +MVI_39361 +MVI_39051 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-trk-experienced.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-trk-experienced.txt new file mode 100644 index 0000000000000000000000000000000000000000..dca63103607bf12548f34200f4fff598cd8fba32 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/testlist-trk-experienced.txt @@ -0,0 +1,30 @@ +MVI_39501 +MVI_39511 +MVI_40851 +MVI_40853 +MVI_40855 +MVI_40711 +MVI_40714 +MVI_40742 +MVI_40761 +MVI_40762 +MVI_40763 +MVI_40771 +MVI_40772 +MVI_40773 +MVI_40774 +MVI_40775 +MVI_40792 +MVI_40793 +MVI_40863 +MVI_40864 +MVI_40891 +MVI_40892 +MVI_40901 +MVI_40902 +MVI_40903 +MVI_40904 +MVI_40905 +MVI_39271 +MVI_39311 +MVI_39371 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/trainlist-full.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/trainlist-full.txt new file mode 100644 index 0000000000000000000000000000000000000000..39e40cb9aae3cdea5d5aa8f7b0228d5dfa129576 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/seqs/trainlist-full.txt @@ -0,0 +1,60 @@ +MVI_39931 +MVI_40131 +MVI_40141 +MVI_40152 +MVI_40161 +MVI_40162 +MVI_40181 +MVI_40171 +MVI_40172 +MVI_40191 +MVI_40192 +MVI_40201 +MVI_40204 +MVI_40211 +MVI_40212 +MVI_40213 +MVI_40241 +MVI_40243 +MVI_40244 +MVI_39761 +MVI_39771 +MVI_39781 +MVI_39801 +MVI_39811 +MVI_39821 +MVI_39851 +MVI_39861 +MVI_40732 +MVI_40751 +MVI_40752 +MVI_40962 +MVI_40963 +MVI_40981 +MVI_40991 +MVI_40992 +MVI_40871 +MVI_63521 +MVI_63525 +MVI_63544 +MVI_63552 +MVI_63553 +MVI_63554 +MVI_63561 +MVI_63562 +MVI_63563 +MVI_20011 +MVI_20012 +MVI_20032 +MVI_20033 +MVI_20034 +MVI_20035 +MVI_20051 +MVI_20052 +MVI_20061 +MVI_20062 +MVI_20063 +MVI_20064 +MVI_20065 +MVI_41063 +MVI_41073 \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/trackingEvaluation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/trackingEvaluation.m new file mode 100644 index 0000000000000000000000000000000000000000..c974b9c1ac80e10b872d1c4e7dfcf79c392daa87 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/trackingEvaluation.m @@ -0,0 +1,105 @@ +function trackingEvaluation() + +global options sequences tracker + +trackerName = tracker.trackerName; % the tracker name +detectorSet = options.detectorSet; % the detector set +detPath = options.detPath; % detection path +if(strcmp(options.motmetric, 'DETRAC-MOT')) + scoreSet = 0:options.trackingThreStep:1; % threshold of detection scores +else + scoreSet = options.detectionThreshold; % threshold of detection scores +end +folderName = parseFolderName(scoreSet); % folders of tracking results in different detectionThreshold + +res_path = ['results/' trackerName '/']; % tracking results saving path +createPath(res_path); + +% Debug Logs +log_path = './logs/'; +createPath(log_path); +diary([log_path 'DETRAC_' trackerName '_tracking_logs.txt']); + +for idDet = 1:length(detectorSet) + detectorName = detectorSet{idDet}; + allSpeed = []; + for idSeq = 1:length(sequences) + % Sequence Info + seqName = sequences{idSeq}.seqName; + curSequence = sequences{idSeq}; + gtInfo = curSequence.gtInfo; + allMetrics = []; + + disp(['Tracker ' trackerName ' + Detector ' detectorName '-->processing sequence ' num2str(idSeq) '/' num2str(length(sequences)) '...']); + detFile = [detPath detectorName '/' seqName '_Det_' detectorName '.txt']; % detection file + detections = loadDetections(detFile); % load detections + %% evaluate the tracker under each detections configuration + for idThre = 1:length(scoreSet) + %% parse detection + trackingResultSavePath = [res_path detectorName '/' folderName{idThre} '/'] ; % the path of tracking results + createPath(trackingResultSavePath); + resultSavePath = [trackingResultSavePath seqName]; + if(exist([resultSavePath '_LX.txt'], 'file') && exist([resultSavePath '_LY.txt'], 'file')&&... + exist([resultSavePath '_W.txt'], 'file') && exist([resultSavePath '_H.txt'], 'file') && exist([resultSavePath '_speed.txt'], 'file')) + stateInfo = txt2stateInfo(resultSavePath, curSequence.frameNums); % geneate the state info + stateInfo = dropTracks(stateInfo, curSequence); % drop the trajectories in the ignored regions + metrics = printSeqEvaluation(seqName, gtInfo, stateInfo, folderName{idThre}); % print evaluation for each sequence + showResults(stateInfo, curSequence, resultSavePath); % display visual results for each sequence + allMetrics = cat(1, allMetrics, [scoreSet(idThre), metrics]); + speed = load([resultSavePath '_speed.txt']); + if(~isempty(speed)) + allSpeed = cat(1,allSpeed, speed); + end + continue; + end + idxDetections = find(detections(:,7) >= scoreSet(idThre)); + if(~isempty(idxDetections)) + baselinedetections = genCutDetections(detections, idxDetections); + else + saveEmptyResults(resultSavePath); + continue; + end + + %% run the tracker + try + % add the toolbox path + cd(['./trackers/' trackerName]); + addpath(genpath('.')); + % run the tracker + [stateInfo, speed] = run_tracker(curSequence, baselinedetections); + % remove the toolbox path + rmpath(genpath('.')); + cd('../../'); + catch err + % remove the toolbox path + rmpath(genpath('./')); + cd('../../'); + error('error in running the tracking method!'); + end + stateInfo = dropTracks(stateInfo, curSequence); % drop the trajectories in the ignored regions + metrics = printSeqEvaluation(seqName, gtInfo, stateInfo, folderName{idThre}); % print evaluation for each sequence + showResults(stateInfo, curSequence, resultSavePath); % display visual results for each sequence + saveResults(resultSavePath, stateInfo, speed); % save tracking results for each sequence + allMetrics = cat(1, allMetrics, [scoreSet(idThre), metrics]); + speed = load([resultSavePath '_speed.txt']); + if(~isempty(speed)) + allSpeed = cat(1,allSpeed, speed); + end + end % end for detection score thresholds + if(options.printEvaluationForEachSeq) + dlmwrite([res_path detectorName '/' seqName '_mot_result.txt'], allMetrics); + end + end % end for sequences + if(options.printEvaluationForEachSeq) + dlmwrite([res_path detectorName '/' trackerName '_speed.txt'], mean(allSpeed)); + end +end % end for detectors + +%% print final evaluation for all the selected sequences +printFinalEvaluation(res_path, detectorSet, folderName); + +%% zip the tracking results for DETRAC-Test +for idDet = 1:length(detectorSet) + detectorName = detectorSet{idDet}; + zipTrackingResults(tracker.trackerName, detectorName); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/txt2stateInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/txt2stateInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..9643b77c39da49051c7f376d1ffcbf0837712e60 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/evaluation/txt2stateInfo.m @@ -0,0 +1,19 @@ +function stateInfo = txt2stateInfo(resultSavePath, frameNums) + +stateInfo.F = numel(frameNums); +stateInfo.frameNums = frameNums; + +left = load([resultSavePath '_LX.txt']); +top = load([resultSavePath '_LY.txt']); +w = load([resultSavePath '_W.txt']); +h = load([resultSavePath '_H.txt']); +xc = left + w/2; +yc = top + h/2; + +% foot position +stateInfo.X = xc; +stateInfo.Xi = xc; +stateInfo.Y = yc+h/2; +stateInfo.Yi = yc+h/2; +stateInfo.H = h; +stateInfo.W = w; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/initialize_environment.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/initialize_environment.m new file mode 100644 index 0000000000000000000000000000000000000000..23b73264da23d4aa89817b56d89e564522da9318 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/initialize_environment.m @@ -0,0 +1,106 @@ +function options = initialize_environment() +%% initialize the parameters for MOT evaluation +% If you do not download the MAT annotation, you can generate them based on the XML annotation. +% To avoid the "OutOfMemory" error, please set the Java memory as 1 GB in the path +% "home>preferences>general>java heap memory>" of the Matlab software before running. +% Note that each XML2MAT transformation spends tens of seconds. + +%% input the path of the DETRAC benchmark +options.imgPath = './DETRAC-Images/'; % the path of images +options.detPath = './DETRAC-Train-Detections/'; % the path of detections +options.gtPath = './DETRAC-Train-Annotations-MAT/'; % the path of annotations (e.g., XML, MAT) +options.seqPath = 'sequences.txt'; % the path of evaluated sequences + +%% select the evaluation mode +% select the type of evaluation, i.e., Detection and Tracking +% If you select the 'Detection' type, the toolkit can show the detection curve and save the precision-recall result for the sequences in the DETRAC-Train set. +% If you select the 'Tracking' type, the toolkit can evaluate the tracker and save the tracking results for the sequences in the DETRAC-Train set. +options.evaluateType = 'Detection'; +% select the sequences for evaluation, i.e., DETRAC-Train, DETRAC-Test (DETRAC-Test-Beginner and DETRAC-Test-Experienced for AVSS2017 Challenge) and DETRAC-Free +options.evaluateSeqs = 'DETRAC-Train'; +% select the type of detector, i.e., DPM, ACF, R-CNN and CompACT. Multiple detectors are welcomed. +options.detectorSet = {'DPM'}; +% we conduct 2d evaluation for the DETRAC benchmark +options.track3d = false; + +% for "DETRAC-Free", detectionThreshold can be set as several thresholds, e.g, [0.1 0.2 0.5] +% or detectionThreshold should be set as 0:options.trackingThreStep:1. +options.trackingThreStep = 0.1; +options.detectionThreshold = 0:options.trackingThreStep:1; % the threshold of detection scores + +% the tracking metric: CLEAR-MOT or DETRAC-MOT +% For AVSS2017 Challenge, DETRAC-MOT is the only evaluation measure. +options.motmetric = 'DETRAC-MOT'; + +% evaluate the sequences in the whole DETRAC-train set +% Since the annotations of the DETRAC-train set are avaliable, you can print the evaluation results immediately. +if(strcmp(options.evaluateSeqs, 'DETRAC-Train')) + copyfile('evaluation/seqs/trainlist-full.txt','sequences.txt'); % modify the evaluated sequences + options.printEvaluationForEachSeq = true; % if the groundtruh files are avalible, print the evaluation result for each sequence calculated by the CLEAR-MOT measure + options.printEvaluationForWholeSet = true; % if the groundtruh files are avalible, print the evaluation result for all the evaluated sequences calculated by options.motmetric + options.printDetectionEval = true; % if the groundtruh files are avalible, print the evaluation result for detection + options.showDetectionCurve = true; % show the detection PR curve when using DETRAC-MOT measure + +% evaluate the sequences in the whole DETRAC-test set +% Since the annotations of the DETRAC-test set are not avaliable, we should comment the corresponding evaluation functions. +elseif(strcmp(options.evaluateSeqs, 'DETRAC-Test')) + copyfile('evaluation/seqs/testlist-full.txt','sequences.txt'); % modify the evaluated sequences + options.printEvaluationForEachSeq = false; % if the groundtruh files are avalible, print the evaluation result for each sequence calculated by the CLEAR-MOT measure + options.printEvaluationForWholeSet = false; % if the groundtruh files are avalible, print the evaluation result for all the evaluated sequences calculated by options.motmetric + options.printDetectionEval = false; % if the groundtruh files are avalible, print the evaluation result for detection + options.showDetectionCurve = false; % show the detection PR curve when using DETRAC-MOT measure + +% evaluate the "beginner" sequences in the DETRAC-test set +% Since the annotations of the DETRAC-test set are not avaliable, we should comment the corresponding evaluation functions. +elseif(strcmp(options.evaluateSeqs, 'DETRAC-Test-Beginner')) + if(strcmp(options.evaluateType, 'Detection')) + copyfile('evaluation/seqs/testlist-det-beginner.txt','sequences.txt'); % modify the evaluated sequences + else + copyfile('evaluation/seqs/testlist-trk-beginner.txt','sequences.txt'); % modify the evaluated sequences + end + options.printEvaluationForEachSeq = false; % if the groundtruh files are avalible, print the evaluation result for each sequence calculated by the CLEAR-MOT measure + options.printEvaluationForWholeSet = false; % if the groundtruh files are avalible, print the evaluation result for all the evaluated sequences calculated by options.motmetric + options.printDetectionEval = false; % if the groundtruh files are avalible, print the evaluation result for detection + options.showDetectionCurve = false; % show the detection PR curve when using DETRAC-MOT measure + +% evaluate the "experienced" sequences in the DETRAC-test set +% Since the annotations of the DETRAC-test set are not avaliable, we should comment the corresponding evaluation functions. +elseif(strcmp(options.evaluateSeqs, 'DETRAC-Test-Experienced')) + if(strcmp(options.evaluateType, 'Detection')) + copyfile('evaluation/seqs/testlist-det-experienced.txt','sequences.txt'); % modify the evaluated sequences + else + copyfile('evaluation/seqs/testlist-trk-experienced.txt','sequences.txt'); % modify the evaluated sequences + end + options.printEvaluationForEachSeq = false; % if the groundtruh files are avalible, print the evaluation result for each sequence calculated by the CLEAR-MOT measure + options.printEvaluationForWholeSet = false; % if the groundtruh files are avalible, print the evaluation result for all the evaluated sequences calculated by options.motmetric + options.printDetectionEval = false; % if the groundtruh files are avalible, print the evaluation result for detection + options.showDetectionCurve = false; % show the detection PR curve when using DETRAC-MOT measure + +% evaluate the sequences in the custom set +% If the user selects just one threshold of detection scores, the tracking metric should be CLEAR-MOT. +elseif(strcmp(options.evaluateSeqs, 'DETRAC-Free')) + % the tracking metric: CLEAR-MOT or DETRAC-MOT + % if only one detectionThreshold is selected, DETRAC-MOT is not avalible. + if(length(options.detectionThreshold) == 1) + disp('Waring: If only one detection score threshold is selected, the DETRAC-MOT measure is not avalible. We should employ the CLEAR-MOT measure.'); + options.motmetric = 'CLEAR-MOT'; + end + options.printEvaluationForEachSeq = true; % if the groundtruh files are avalible, print the evaluation result for each sequence calculated by the CLEAR-MOT measure + options.printEvaluationForWholeSet = true; % if the groundtruh files are avalible, print the evaluation result for all the evaluated sequences calculated by options.motmetric + options.printDetectionEval = true; % if the groundtruh files are avalible, print the evaluation result for detection + options.showDetectionCurve = true; % show the detection PR curve when using DETRAC-MOT measure +end + +%% parameters for displaying visual results +options.showVisualResults = false; % show the visual tracking results +options.saveVisualResults = false; % save the visual tracking results +options.showRemoveResults = false; % show the removed tracking results in the ignored regions + +options.displayDots = true; % display the trajectory dots +options.displayBoxes = true; % display the bounding box of the target +options.displayID = true; % display the ID of the target +options.displayCropouts = false; % display the border cropouts +options.displayConnections = false; % display the connection of the sample target + +%% verify the legitimacy of the parameters +options = checkOptions(options); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/load_datasets.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/load_datasets.m new file mode 100644 index 0000000000000000000000000000000000000000..4d31f5b6eb4f5d7b090d4f798380e811ef9fa006 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/load_datasets.m @@ -0,0 +1,30 @@ +function sequences = load_datasets() + +global options + +fidSeq = importdata(options.seqPath); +sequences = cell(1, length(fidSeq)); +for idSeq = 1:length(fidSeq) + % sequence name + seqName = fidSeq{idSeq}; + % load images + sequences{idSeq}.seqName = seqName; + sequences{idSeq}.imgFolder = [options.imgPath seqName '\']; + sequences{idSeq}.imgFileFormat = 'img%05d.jpg'; + sequences{idSeq}.dataset = dir([sequences{idSeq}.imgFolder '*.jpg']); % the folder in which ur images exists + if(isempty(sequences{idSeq}.dataset)) + error('error in loading images!'); + end + sequences{idSeq}.frameNums = 1:length(sequences{idSeq}.dataset); + [sequences{idSeq}.imgHeight, sequences{idSeq}.imgWidth, ~] = size(imread([sequences{idSeq}.imgFolder,sprintf(sequences{idSeq}.imgFileFormat,sequences{idSeq}.frameNums(1))])); + sequences{idSeq}.camFile = []; + % load groundtruth + sequences{idSeq}.gtFolder = options.gtPath; + if(~strcmp(options.evaluateSeqs, {'DETRAC-Test', 'DETRAC-Test-Beginner', 'DETRAC-Test-Experienced'})) + sequences{idSeq}.gtInfo = parseGT([sequences{idSeq}.gtFolder seqName '.xml'], sequences{idSeq}.imgHeight, sequences{idSeq}.imgWidth, sequences{idSeq}.frameNums); + else + sequences{idSeq}.gtInfo = []; + end + % load ignore regions + sequences{idSeq}.ignoreRegion = load(['evaluation/igrs/' seqName '_IgR.txt']); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/run_experiment.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/run_experiment.m new file mode 100644 index 0000000000000000000000000000000000000000..1686da9b4af2033ca28a0780fee373fbbfaec8aa --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/run_experiment.m @@ -0,0 +1,15 @@ +function run_experiment() + +global options + +%% evaluation for detection +if(strcmp(options.evaluateType, 'Detection')) + disp('**************************EVALUATION FOR DETECTION**************************'); + detectionEvaluation(); +end + +%% evaluation for tracking +if(strcmp(options.evaluateType, 'Tracking')) + disp('**************************EVALUATION FOR TRACKING***************************'); + trackingEvaluation(); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/sequences.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/sequences.txt new file mode 100644 index 0000000000000000000000000000000000000000..39e40cb9aae3cdea5d5aa8f7b0228d5dfa129576 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/sequences.txt @@ -0,0 +1,60 @@ +MVI_39931 +MVI_40131 +MVI_40141 +MVI_40152 +MVI_40161 +MVI_40162 +MVI_40181 +MVI_40171 +MVI_40172 +MVI_40191 +MVI_40192 +MVI_40201 +MVI_40204 +MVI_40211 +MVI_40212 +MVI_40213 +MVI_40241 +MVI_40243 +MVI_40244 +MVI_39761 +MVI_39771 +MVI_39781 +MVI_39801 +MVI_39811 +MVI_39821 +MVI_39851 +MVI_39861 +MVI_40732 +MVI_40751 +MVI_40752 +MVI_40962 +MVI_40963 +MVI_40981 +MVI_40991 +MVI_40992 +MVI_40871 +MVI_63521 +MVI_63525 +MVI_63544 +MVI_63552 +MVI_63553 +MVI_63554 +MVI_63561 +MVI_63562 +MVI_63563 +MVI_20011 +MVI_20012 +MVI_20032 +MVI_20033 +MVI_20034 +MVI_20035 +MVI_20051 +MVI_20052 +MVI_20061 +MVI_20062 +MVI_20063 +MVI_20064 +MVI_20065 +MVI_41063 +MVI_41073 \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/thresh.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/thresh.txt new file mode 100644 index 0000000000000000000000000000000000000000..7188a5e71ff74ea82b3e509a280799f1e5c79231 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/thresh.txt @@ -0,0 +1,11 @@ +0.0 +0.1 +0.2 +0.3 +0.4 +0.5 +0.6 +0.7 +0.8 +0.9 +1.0 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/E.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/E.m new file mode 100644 index 0000000000000000000000000000000000000000..cf81bced57a24933210d8b76cf5aa384b8cc90f3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/E.m @@ -0,0 +1,185 @@ +function [fx dfx EdetValue EdynValue EexcValue EappValue EperValue EregValue] = E(stateVec, stateInfo) +% the objective function E +% +% inputs: +% state vector, state info and scene info and options and detections +% +% outputs +% Energy value and its derivative vector +% and optionally all individual (not weighted) energy components +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +global sceneInfo opt; + +F=stateInfo.F; N=stateInfo.N; +targetsExist=stateInfo.targetsExist; +tiToInd=stateInfo.tiToInd; +% stateVec=stateInfo.stateVec; + +% if no targets present, E=0 and return +if ~N + fx=0; dfx=0; + EdetValue=0; EdynValue =0; EexcValue=0; EappValue=0; EperValue=0; EregValue=0; + return; +end + + +targetSize=sceneInfo.targetSize; +areaLimits=sceneInfo.trackingArea; + +% params=getOptimParameters; +% global params; +% global gridStep itToInd Xd Yd Sd; +% global areaLimits; +% [X,Y]=vectorToMatrices(stateVec,stateInfo); +[X, Y]=vectorToMatrices_mex(stateVec,stateInfo.tiToInd,stateInfo.F,stateInfo.N); +% global Xgt Ygt; + +% detections +global detMatrices; + + + +% %%%%%%%%%%%%%% +% % Detections % +% %%%%%%%%%%%%%% +EdetValue=0; +dEdet=zeros(length(stateVec),1); +% EdetValue=Edet(x); +% if params.alpha>0 +% if params.det3d + if opt.mex + % vis needed for Eapp!!! + if nargout>1 + [EdetValue dEdet visv vis visx visy ddvix ddviy]= ... + Edet_mex(X,Y,detMatrices.Xd,detMatrices.Yd,detMatrices.Sd, ... + sceneInfo.targetSize,opt.lambda,stateInfo.targetsExist,length(stateVec),opt.occ); + else + EdetValue=Edet_mex(X,Y,detMatrices.Xd,detMatrices.Yd,detMatrices.Sd, ... + sceneInfo.targetSize,opt.lambda,stateInfo.targetsExist,length(stateVec),opt.occ); + end + else + if nargout>1, %[EdetValue dEdet ds VIS]=Edet(x); + [EdetValue dEdet]=Edet(stateVec,stateInfo); + else EdetValue=Edet(stateVec,stateInfo); + end + end + + +% else +% if nargout>1, %[EdetValue dEdet ds VIS]=Edet(x); +% [EdetValue dEdet visv visx visy ddvix ddviy]=Edet2D(x); +% else EdetValue=Edet2D(x); +% end +% end +% end +% [EdetValue dEdet visv visx visy ddvix ddviy ds]=Edet(x); +% +% % pause +% stateInfo.X=X; stateInfo.Y=Y; +% stateInfo.Xgp=stateInfo.X; stateInfo.Ygp=stateInfo.Y; +% [stateInfo.Xi stateInfo.Yi]=projectToImage(stateInfo.X,stateInfo.Y,sceneInfo); +% a=getBBoxesFromPrior(stateInfo); +% +% %%%%%%%%%%%%%% +% % appearance % +% %%%%%%%%%%%%%% +EappValue = 0; dEapp=zeros(length(stateVec),1); +% if params.alpha>0 && doeapp +% if nargout>1, [Eappearance dEappearance]=Eapp(x, ddvix, ddviy); +% else +% Eappearance=Eapp(x); +% end +% end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Edyn - constant velocity % +%%%%%%%%%%%%%%%%%%%%%%%%%%%% +EdynValue=0; dEdyn=zeros(length(stateVec),1); +if opt.weightEdyn>0 + if opt.mex + [EdynValue dEdyn]=Edyn_mex(X,Y,targetSize,stateInfo.targetsExist,length(stateVec)); + else + if nargout>1, [EdynValue dEdyn]=Edyn(stateVec,stateInfo); + else EdynValue=Edyn(stateVec,stateInfo); + end + end + +end + +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % Eexc - distance between objects % +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +EexcValue = 0; dEexc=zeros(length(stateVec),1); + +% [size(X) size(itToInd)] +% itToInd +if N>1 && opt.weightEexc>0 + if opt.mex + if nargout>1 + [EexcValue dEexc]=Eexc_mex(X,Y,targetSize,tiToInd,length(stateVec)); + else + EexcValue=Eexc_mex(X,Y,targetSize,tiToInd,length(stateVec)); + end + else + if nargout>1, [EexcValue dEexc]=Eexc(stateVec,stateInfo); + else EexcValue=Eexc(stateVec, stateInfo); + end + end + +end +% +% +% %%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % Eper - persistent tracks % +% %%%%%%%%%%%%%%%%%%%%%%%%%%%% +EperValue = 0; dEper=zeros(length(stateVec),1); + +if opt.weightEper>0 + if opt.mex + [EperValue dEper]=Eper_mex(X,Y,areaLimits,targetSize,targetsExist,length(stateVec)); + else + if nargout>1, [EperValue dEper]=Eper(stateVec,stateInfo); + else EperValue=Eper(stateVec, stateInfo); + end + end +end + + +%%%%%%%%%%%%%%%%%% +% regularization % +%%%%%%%%%%%%%%%%%% +Eregularization1=N; +% Eregularization1=(N-4)^2; +% Eregularization2=-sum(sqrt(diff(targetsExist,[],2)+1)); +Eregularization2=sum(1./(diff(targetsExist,[],2)+1)); +EregValue=Eregularization1+1*Eregularization2; + +% Ndev=sum((sum(~~X,2)-sum(~~Xgt,2)).^2); + +% final value is a linear combination of all terms +fx= opt.weightEdet*EdetValue + ... + opt.weightEdyn*EdynValue + ... + opt.weightEexc*EexcValue + ... + opt.weightEper*EperValue + ... + opt.weightEreg*EregValue; + +% and the gradient +if nargout>1 + dfx = ... + opt.weightEdet*dEdet + ... + opt.weightEdyn*dEdyn + ... + opt.weightEexc*dEexc + ... + opt.weightEper*dEper; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Edet.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Edet.m new file mode 100644 index 0000000000000000000000000000000000000000..4a2a327926e37f5a0ec85a9a8fdc66dd5e6b98b6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Edet.m @@ -0,0 +1,105 @@ +function [fx dfx]=Edet(x,stateInfo) + +% The Detection Energy Term +% +% The energy should be minimized when the targets pass through +% detections [Xd Yd] +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global detections sceneInfo opt; + +N=stateInfo.N; +F=stateInfo.F; +targetsExist=stateInfo.targetsExist; +gridStep=sceneInfo.targetSize; +% x=stateInfo.stateVec; + +% convert state vector to matrix representation +[X Y]=vectorToMatrices(x,stateInfo); + +% initialize return values with 0 +fx=0; +dfx=zeros(length(x),1); + + +% if no targets are present, return 0 +if isempty(x) || ~N + return; +end + +% otherwise compute the actual Edet-value +dfxind=0; + + +csig=gridStep*gridStep; +lambda=opt.lambda; + +occ=ones(F,N); +occx=zeros(F,N); +occy=zeros(F,N); +GG=zeros(F,N); +GGx=zeros(F,N); +GGy=zeros(F,N); +if opt.occ && nargout > 1 + [occ vis occx occy ddvix ddviy]=computeOcclusions2(X,Y); +elseif opt.occ + [occ vis]=computeOcclusions2(X,Y); +end + +for id=1:N + for t=targetsExist(id,1):targetsExist(id,2) + + % current x,y position + x=X(t,id); y=Y(t,id); + + % v * lambda + d=occ(t,id)*lambda; + + % matrix implementation + XXd=detections(t).xp-x; + YYd=detections(t).yp-y; + SSd=detections(t).sc; + + XXdsq=XXd.^2; YYdsq=YYd.^2; + + GG(t,id)=-sum((csig*SSd) ./ ((XXdsq + YYdsq) + csig)); + + % add current value to total energy + fx=fx+d+GG(t,id); + + + % if derivative requested + if nargout>1 + ddfx=occx(t,id)*lambda; + ddfy=occy(t,id)*lambda; + + GGx(t,id)=-sum(2*csig*SSd.*XXd ./ ((XXdsq + YYdsq) + csig).^2); + GGy(t,id)=-sum(2*csig*SSd.*YYd ./ ((XXdsq + YYdsq) + csig).^2); + + ddfx=ddfx+GGx(t,id); + ddfy=ddfy+GGy(t,id); + + + dfxind=dfxind+1; + dfx(dfxind)=dfx(dfxind)+ddfx; + dfxind=dfxind+1; + dfx(dfxind)=dfx(dfxind)+ddfy; + + end + + end +end + +end + + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Edyn.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Edyn.m new file mode 100644 index 0000000000000000000000000000000000000000..6c2bad556d9c0a9cbfeaf2050215a191f1df5064 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Edyn.m @@ -0,0 +1,79 @@ +function [fx dfx ds]=Edyn(x,stateInfo) + +% The dynamic model +% This is a simple constant velocity model +% that is minimized when succesive velocity vectors +% of the same target are the same +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global sceneInfo; + +N=stateInfo.N; +targetsExist=stateInfo.targetsExist; +gridStep=sceneInfo.targetSize; +% x=stateInfo.stateVec; + +% convert state vector to matrix representation +[X Y]=vectorToMatrices(x, stateInfo); + + +fx=0; +dfx=zeros(length(x),1); +ds=zeros(size(X)); +cnt=0; +xind=1; +for i=1:N + tlength=diff(targetsExist(i,:))+1; + + xind=xind+2; + yind=xind+1; + + + % Edyn is 0 for first and last frame + for t=targetsExist(i,1)+1:targetsExist(i,2)-1 + % (a,b) = past frame position + % (c,d) = current frame position + % (e,f) = next frame position + a=X(t-1,i); + b=Y(t-1,i); + c=X(t,i); + d=Y(t,i); + e=X(t+1,i); + f=Y(t+1,i); + + % squared norm of the two succesive vectors + diffterm= a^2 + a*(2*e - 4*c) + b^2 + b*(2*f - 4*d) + 4*c^2 - 4*c*e + 4*d^2 - 4*d*f + e^2 + f^2; + cnt=cnt+1;ds(t,i)=diffterm; + fx=fx+diffterm; + + % derivative + if nargout>1 + dfx(xind-2)=dfx(xind-2) + (2*a-4*c+2*e); + dfx(yind-2)=dfx(yind-2) + (2*b-4*d+2*f); + dfx(xind)=dfx(xind) + (-4*a+8*c-4*e); + dfx(yind)=dfx(yind) + (-4*b+8*d-4*f); + dfx(xind+2)=dfx(xind+2) + (2*a-4*c+2*e); + dfx(yind+2)=dfx(yind+2) + (2*b-4*d+2*f); + end + + xind=xind+2; + yind=xind+1; + + end + if tlength>1 + xind=xind+2; + end +end + +fx=fx/gridStep; % normalize +dfx=dfx/gridStep; % normalize +ds=ds/gridStep; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Eexc.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Eexc.m new file mode 100644 index 0000000000000000000000000000000000000000..cdbfda4ad3223f04713e2c39ad2872cb84cbf2d3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Eexc.m @@ -0,0 +1,83 @@ +function [fx dfx ds]=Eexc(x,stateInfo) + +% Exclusion (collision avoidance) term. +% pairwise distances between all targets in all frames +% are penalized according to 1/distance^2 and scaled with +% target size (usually 350) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global sceneInfo; + + +F=stateInfo.F; +tiToInd=stateInfo.tiToInd; +gridStep=sceneInfo.targetSize; +% x=stateInfo.stateVec; + +% grab state vector +[X Y]=vectorToMatrices(x,stateInfo); + +% initialize with 0 +fx=0; +dfx=zeros(length(x),1); +ds=zeros(size(X)); +gs_squared=gridStep*gridStep; + +% if ~all(size(X)==size(tiToInd)), pause; end + +cnt=0; +% in each frame +for t=1:F + + % for each existing target + targets=find(X(t,:)); + for i1=1:numel(targets) + i=targets(i1); + xind=tiToInd(t,i); + yind=xind+1; + + cnt=cnt+1; + tmpds=0; + % for all other targets j ~= i + otheri=[targets(1:i1-1) targets(i1+1:end)]; + for j=otheri + + % target i = (a,b) + % target j = (c,d) + a=X(t,i); b=Y(t,i); + c=X(t,j); d=Y(t,j); + + % exclusion term + term = gs_squared / (a^2 + b^2 + c^2 + d^2 -2*a*c - 2*b*d); % gs^2 / |Xi-Xj|^2 + + % add to energy + fx=fx+term; + tmpds=tmpds+term; + + % compute gradient if needed + if nargout > 1 + denom=(a^2-2*a*c+b^2-2*b*d+c^2+d^2)^2; + tmp=gs_squared/denom; + dda=-(2*a-2*c)*tmp; + ddb=-(2*b-2*d)*tmp; +% [length(x) xind] +% pause + dfx(xind)=dfx(xind)+dda+dda; + dfx(yind)=dfx(yind)+ddb+ddb; + end + + end + ds(t,i)=tmpds; + + end +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Eper.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Eper.m new file mode 100644 index 0000000000000000000000000000000000000000..ef3dcfc2d926935f5e57eafc132cf42ad0a0c8e4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/Eper.m @@ -0,0 +1,120 @@ +%%%% WRONG GRADIENT !!!! %%%% + +function [fx dfx ds]=Eper(x,stateInfo) + +% The persistence term +% it calculates the distance of the +% start and end point of each trajectory +% to the closest border (image or tracking +% area) and penalizes with a sigmoid +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +global sceneInfo; + +% get state info +[~, N F targetsExist X Y]=getStateInfo(stateInfo); +gridStep=sceneInfo.targetSize; + + +fx=0; +dfx=zeros(length(x),1); +dfxind=0; + +itToInd=stateInfo.tiToInd; +areaLimits=sceneInfo.trackingArea; + +minX=areaLimits(1); +maxX=areaLimits(2); +minY=areaLimits(3); +maxY=areaLimits(4); + +A=1*gridStep; %% offset +B=1/gridStep; %% scale +AB=A*B; + + + +ds=zeros(size(X)); +cnt=0; +for i=1:N + + st=targetsExist(i,1); + en=targetsExist(i,2); + + if st>1 + + x=X(st,i); + y=Y(st,i); + + % dist left + + dl=abs(minX-x); + % dist right + dr=abs(maxX-x); + % dist up + du=abs(minY-y); + % dist down + dd=abs(maxY-y); + distances=[dl dr du dd]; + + [dm ci]=min(distances); + d=1/(1+exp(AB-B*dm)); + + ds(st,i)=d; + + fx=fx+d; + if nargout>1 + if ci<=2 % x + dfx(itToInd(st,i))=B*exp(AB-B*dm)/((exp(AB-B*dm)+1)^2); + else % y + dfx(itToInd(st,i)+1)=B*exp(AB-B*dm)/((exp(AB-B*dm)+1)^2); + end + end + + end + + + if en1 + if ci<=2 % x + dfx(itToInd(en,i))=B*exp(AB-B*dm)/((exp(AB-B*dm)+1)^2); + else % y + dfx(itToInd(en,i)+1)=B*exp(AB-B*dm)/((exp(AB-B*dm)+1)^2); + end + end + end + + + cnt=cnt+1; + % ds(cnt)=d; +end + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/LICENSE.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..9cb2091e6da4357e3ed2a4a47f2817a755293af1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/LICENSE.txt @@ -0,0 +1,15 @@ +Copyright (c) 2012, Anton Andriyenko + +The code may be used free of charge for non-commercial and +educational purposes, the only requirement is that this text is +preserved within the derivative work. For any other purpose you +must contact the authors for permission. This code may not be +redistributed without written permission from the authors. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE +FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/README.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..4e7215b471c7a31c4ec53f36568b9cecf37f844e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/README.txt @@ -0,0 +1,54 @@ +################################################################### +# # +# Multi-Target Tracking by Continuous Energy Minimization # +# Anton Andriyenko and Konrad Schindler # +# # +# Copyright 2012 Anton Andriyenko # +# # +################################################################### + + + +ABOUT: +This software implements our approach to multi-target tracking +using continuous energy minimization [1]. + +The additional packages + - minimize.m + - splinefit +are released under a different license and are included for your convenience. + + + +========================================================================== +DISCLAIMER: +This demo software has been rewritten for the sake of simplifying the +implementation. Therefore, the results produced by the code may differ +from those presented in the paper [1]. +========================================================================== + + +IMPORTANT: +To use this software, you should cite the following in any resulting publication: + [1] Multi-target Tracking by Continuous Energy Minimization + A. Andriyenko and K. Schindler. + In CVPR, Colorado Springs, USA, June 2011 + +Furthermore, if you use occlusion reasoning, you should cite + [2] An Analytical Formulation of Global Occlusion Reasoning for Multi-Target Tracking + A. Andriyenko, S. Roth, and K. Schindler. + In IEEE International Workshop on Visual Surveillance (in conjunction with ICCV), Barcelona, Spain, November 2011 + + +INSTALLING & RUNNING +1. Unpack contracker-v1.0.zip + +2. Start MATLAB and run compileMex.m to build the utilities binaries. + (This step can be omitted if you are using MacOSX 32/64 bit, Windows 32/64 bit or Linux 64 bit.) + +3. run cemTrackerDemo.m + + + +CHANGES + May 25, 2012 Initial public release \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/bgdetToXML.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/bgdetToXML.m new file mode 100644 index 0000000000000000000000000000000000000000..f5964f1a88d78d39996b82306a3dd41e5be4c812 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/bgdetToXML.m @@ -0,0 +1,35 @@ +% function bgdetToXML(folder) +folder='D:\visinf\projects\ongoing\baark-praktikum\opencv-gpu\background_subtraction\Release\det\'; + +folderlisting=dir([folder '*.det']); + +detections=[]; +for f=1:length(folderlisting) + fname=[folder folderlisting(f).name]; + alldets=load(fname); + alldets=alldets'; + ndets=size(alldets,2); + + if ndets + detections(f).bx=alldets(1,:); + detections(f).by=alldets(2,:); + detections(f).wd=alldets(3,:); + detections(f).ht=alldets(4,:); + + detections(f).sc=ones(1,ndets); + + detections(f).xi=detections(f).bx+detections(f).wd/2; + detections(f).yi=detections(f).by+detections(f).ht; + + detections(f).xp=detections(f).xi;detections(f).yp=detections(f).yi; + end +end + +if ~ndets + detections(f).bx=[];detections(f).by=[]; + detections(f).wd=[];detections(f).ht=[]; + detections(f).yi=[];detections(f).xi=[]; + detections(f).yp=[];detections(f).xp=[]; +end +save('D:\diss\detections\hog-hof-linsvm\DA-ELS\s01\detections.mat','detections') +% end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/cemTracker.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/cemTracker.m new file mode 100644 index 0000000000000000000000000000000000000000..a04e257e456e2a144710b59629e1d4d45e4e0d3d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/cemTracker.m @@ -0,0 +1,196 @@ +% function cemTracker(detfile, opt) +% Multi-Target Tracking by Continuous Energy Minimization +% +% +% +% STATE VECTOR +% There are two ways in which the state is represented. +% (1) compact +% One is a d-x-1 vector, containing x,y coordinates in +% the order +% +% Target 1 Target 2 Target N +% x1,y1,x2,y2,...,x1,y1,x2,y2,...,xN,yN +% +% (2) visual +% The other representation consists of two matrices +% for x and y locations respectively +% row i column j corresponds to target j at frame i +% +% +% +% This code contains modifications compared +% to the one that was used +% to produce results for our CVPR 2011 and VS 2011 +% papers +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +clear all; clear global +% set start time + +global cemStartTime +cemStartTime=tic; + +addpath(genpath('.')) +% addpath('../dctracking') +% addpath('../dctracking/splinefit') +%% declare global variables +global detMatrices detections sceneInfo opt globiter gtInfo +globiter=0; + +global LOG_allens LOG_allmets2d LOG_allmets3d %for debug output + +%% setup options and scene +% fill options struct +opt=getOptions; + +% fill scene info +scenario=25; +sceneInfo=getSceneInfo(scenario); + +%% cut ground truth +if sceneInfo.gtAvailable && opt.track3d + gtInfo=cutGTToTrackingArea(gtInfo); +end +%% load detections +[detections nDets]=parseDetections(sceneInfo); fr=1:length(detections); +% fr=1:50; detections=detections(fr); % !!!!!!! REMOVE +% for t=1:length(detections), detections(t).sc=1; end + +% load('/home/aanton/diss/others/yangbo/TUD/TUD_Stadtmitte.avi.detection.mat') +% load('/home/aanton/diss/others/yangbo/PETS09/PETS09_View001_S2_L1_000to794.avi.detection.mat'); +F=size(detections,2); +stateInfo.F=F; % number of frames + +% cut detections to tracking area if needed +[detections nDets]=cutDetections(detections,nDets); +detMatrices=getDetectionMatrices(detections); + +% evaluate detections +% evaluateDetections(detMatrices,gtInfo); + +%% init solution +% ... +% initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output','s0080','e00012d.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output','s0080','e0003.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output','s0023','e0003.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output','s0042','e0003.mat'); + +X=[]; Y=[]; + +initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output',sprintf('s%04d',scenario),'e0001.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','others','okuma','BPF','myresult.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','others','okuma','BPF',sprintf('myresult-s%04d.mat',scenario)); +% initsolfile='tmp.mat'; + +% sampling +% alldpoints=createAllDetPoints; +% nInit=round(nDets/F); +% mhs=getSplineProposals(alldpoints,nInit,F); +% for id=1:length(mhs) +% tt=mhs(id).start:mhs(id).end; +% allvals=ppval(mhs(id),tt); +% X(tt',id)=allvals(1,:)';Y(tt',id)=allvals(2,:)'; +% end +% [X, Y, stateInfo]=cleanState(X, Y, stateInfo); +% [X Y]=checkInitSolution(X,Y,stateInfo.F); + + + +if 0%exist(initsolfile,'file') +load(initsolfile); + +% X=X(fr,:);Y=Y(fr,:);H=H(fr,:); % !!!!!! REMOVE +[X, Y, stateInfo]=cleanState(X, Y, stateInfo); +[X Y]=checkInitSolution(X,Y,stateInfo.F); +end + +% global gtInfo +% X=gtInfo.X; Y=gtInfo.Y; + +stateInfo.N=size(X,2); +stateInfo.targetsExist=getTracksLifeSpans(X); +stateInfo.frameNums=sceneInfo.frameNums; +stateInfo=matricesToVector(X,Y,stateInfo); +[stateVec N F targetsExist stateInfo.X stateInfo.Y]=getStateInfo(stateInfo); + +assert(isempty(X) || size(X,1)==length(detections),'Initial Solution must be full length'); + +printSceneInfo; + +%% initial gradient descent (if initial solution available) +if ~isempty(stateInfo.stateVec) + [stateInfo.stateVec Evalue nIterations]=minimize(stateInfo.stateVec,'E',opt.maxIterCGD,stateInfo); +end + +%% now do main optimization +converged=false; +epoch=0; +while ~converged && epoch=opt.maxEpochs + printMessage(1,'Max number of rounds reached.\n'); + end +end % converged +% basically we are done +printMessage(1,'All done (%.2f min = %.2fh = %.2f sec per frame)\n',toc(cemStartTime)/60,toc(cemStartTime)/3600,toc(cemStartTime)/F); + + + + +%% post processing +% get X Y matrices +[stateVec N F targetsExist stateInfo.X stateInfo.Y]=getStateInfo(stateInfo); +stateInfo=postProcessState(stateInfo); + + + +%% if we have ground truth, evaluate results +printFinalEvaluation(stateInfo) + +%% clean up (remove zero rows from logs) +itinfo=find(sum(LOG_allens,2)); +LOG_allmets2d=LOG_allmets2d(~~sum(LOG_allmets2d,2),:); +LOG_allmets3d=LOG_allmets3d(~~sum(LOG_allmets3d,2),:); +LOG_allens=LOG_allens(~~sum(LOG_allens,2),:); + + +% you can display the results with +% displayTrackingResult(sceneInfo,stateInfo) + +% end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/cemTrackerDemo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/cemTrackerDemo.m new file mode 100644 index 0000000000000000000000000000000000000000..f6ed4c6522e8e6820771b274f11dc24bba1b7e23 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/cemTrackerDemo.m @@ -0,0 +1,152 @@ +% function cemTracker(detfile, opt) +% Multi-Target Tracking by Continuous Energy Minimization +% +% +% +% STATE VECTOR +% There are two ways in which the state is represented. +% (1) compact +% One is a d-x-1 vector, containing x,y coordinates in +% the order +% +% Target 1 Target 2 Target N +% x1,y1,x2,y2,...,x1,y1,x2,y2,...,xN,yN +% +% (2) visual +% The other representation consists of two matrices +% for x and y locations respectively +% row i column j corresponds to target j at frame i +% +% +% +% This code contains modifications compared +% to the one that was used +% to produce results for our CVPR 2011 and VS 2011 +% papers +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +clear all; clear global +warning off; +% set start time + +global cemStartTime + + +addpath(genpath('.')) +%% declare global variables +global detMatrices detections sceneInfo opt globiter gtInfo +globiter=0; + +global LOG_allens LOG_allmets2d LOG_allmets3d %for debug output +savePath = 'E:\ComputerVision\Multi-target Tracking\experiment code\tracking_results\S2_L2\CEM\'; + +%% setup options and scene +% fill options struct +% µ÷Ч¹ûË㷨ʱ£¬ÐèÒª¸Ä±ägetDCOptionsDemoµÄ3D²ÎÊý +opt=getConOptionsDemo; + +% fill scene info +% ¸ü»»Êý¾Ý¼¯Ê±£¬ÐèÒª¸Ä±ägetSceneInfoDCDemoµÄÅäÖòÎÊý +addpath('input_trans'); +sceneInfo=getSceneInfoConDemo; + +%% cut ground truth +gtInfo=cutGTToTrackingArea(gtInfo); + +%% load detections +[detections, nDets]=parseDetectionsFace(sceneInfo); fr=1:length(detections); +stateInfo.F=size(detections,2); + +% cut detections to tracking area if needed +[detections, nDets]=cutDetections(detections,nDets); +detMatrices=getDetectionMatrices(detections); + +cemStartTime=tic; + +%% init solution +X=[]; Y=[]; +initsolfile=fullfile('demo','ekf','e0001.mat'); +load(initsolfile); +[X, Y, stateInfo]=cleanState(X, Y, stateInfo); +[X, Y]=checkInitSolution(X,Y,stateInfo.F); + +stateInfo.N=size(X,2); +stateInfo.targetsExist=getTracksLifeSpans(X); +stateInfo.frameNums=sceneInfo.frameNums; +stateInfo=matricesToVector(X,Y,stateInfo); +[stateVec, N, F, targetsExist, stateInfo.X, stateInfo.Y]=getStateInfo(stateInfo); + +% assert(size(X,1)==length(detections),'Initial Solution must be full length'); +% printSceneInfo; +%% initial gradient descent (if initial solution available) +if ~isempty(stateInfo.stateVec) + [stateInfo.stateVec, Evalue, nIterations]=minimize(stateInfo.stateVec,'E',opt.maxIterCGD,stateInfo); +end + +%% now do main optimization +converged=false; +epoch=0; +while ~converged && epoch=opt.maxEpochs + printMessage(1,'Max number of rounds reached.\n'); + end +end % converged + +% basically we are done +printMessage(0,'All done (%.2f min = %.2fh = %.2f sec per frame)\n',toc(cemStartTime)/60,toc(cemStartTime)/3600,toc(cemStartTime)/F); +F/toc(cemStartTime) +%% post processing +% get X Y matrices +[stateVec, N, F, targetsExist, stateInfo.X, stateInfo.Y]=getStateInfo(stateInfo); +stateInfo=postProcessState(stateInfo); + +%% if we have ground truth, evaluate results +printFinalEvaluation(stateInfo); + +%% clean up (remove zero rows from logs) +itinfo=find(sum(LOG_allens,2)); +LOG_allmets2d=LOG_allmets2d(~~sum(LOG_allmets2d,2),:); +LOG_allmets3d=LOG_allmets3d(~~sum(LOG_allmets3d,2),:); +LOG_allens=LOG_allens(~~sum(LOG_allens,2),:); + +% you can display the results with +% displayTrackingResult(sceneInfo,stateInfo) +if(~isdir(savePath)) + mkdir(savePath); +end +save([savePath 'CEM_result.mat'], 'gtInfo', 'stateInfo', 'opt'); +% end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/cemTrackerSearch.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/cemTrackerSearch.m new file mode 100644 index 0000000000000000000000000000000000000000..9c6e53c41fe4a9d8f09f7e52e6614facb0f31dce --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/cemTrackerSearch.m @@ -0,0 +1,216 @@ +function [metrics2d metrics3d]=cemTrackerSearch(scenario,options) +% Multi-Target Tracking by Continuous Energy Minimization +% +% +% +% STATE VECTOR +% There are two ways in which the state is represented. +% (1) compact +% One is a d-x-1 vector, containing x,y coordinates in +% the order +% +% Target 1 Target 2 Target N +% x1,y1,x2,y2,...,x1,y1,x2,y2,...,xN,yN +% +% (2) visual +% The other representation consists of two matrices +% for x and y locations respectively +% row i column j corresponds to target j at frame i +% +% +% +% This code contains modifications compared +% to the one that was used +% to produce results for our CVPR 2011 and VS 2011 +% papers +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +% clear all +cemStartTime=tic; + +addpath(genpath('.')) + +%% declare global variables +global detMatrices detections sceneInfo opt globiter; +globiter=0; + +% fill options struct +opt=getOptions(options); + +% fill scene info +% scenario=23; +sceneInfo=getSceneInfo(scenario); + + +%% load detections +detections=parseDetections(sceneInfo); fr=1:length(detections); +% fr=1:50; detections=detections(fr); % !!!!!!! REMOVE +% for t=1:length(detections), detections(t).sc=1; end + +% load('/home/aanton/diss/others/yangbo/TUD/TUD_Stadtmitte.avi.detection.mat') +% load('/home/aanton/diss/others/yangbo/PETS09/PETS09_View001_S2_L1_000to794.avi.detection.mat'); +F=size(detections,2); +stateInfo.F=F; % number of frames + +% do 2d +% for t=1:F +% detections(t).xp=detections(t).xi; +% detections(t).yp=detections(t).yi; +% end + +% for t=1:F +% detections(t).sc(:)=1; +% end + +detMatrices=getDetectionMatrices(detections); + +%% init solution +% ... +% initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output','s0080','e00012d.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output','s0080','e0003.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output','s0023','e0003.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output','s0042','e0003.mat'); + +X=[]; Y=[]; + +initsolfile=fullfile(getHomeFolder,'diss','ekftracking','output',sprintf('s%04d',scenario),'e0003.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','others','okuma','BPF','myresult.mat'); +% initsolfile=fullfile(getHomeFolder,'diss','others','okuma','BPF',sprintf('myresult-s%04d.mat',scenario)); +% initsolfile='tmp.mat'; +if 1%exist(initsolfile,'file') +load(initsolfile); + +% X=X(fr,:);Y=Y(fr,:);H=H(fr,:); % !!!!!! REMOVE +[X, Y, stateInfo]=cleanState(X, Y, stateInfo); +[X Y]=checkInitSolution(X,Y,stateInfo.F); +end + +% global gtInfo +% X=gtInfo.X; Y=gtInfo.Y; + +stateInfo.N=size(X,2); +stateInfo.targetsExist=getTracksLifeSpans(X); +stateInfo.frameNums=sceneInfo.frameNums; + +stateInfo=matricesToVector(X,Y,stateInfo); +[stateVec N F targetsExist stateInfo.X stateInfo.Y]=getStateInfo(stateInfo); + +% pause + +%% do we have ground truth? +% ... +% global gtInfo +% gtInfo=parseGT('/storage/databases/PETS2009/Crowd_PETS09/S3/Multiple_Flow/Time_12-43/View_001/GT2d_full.xml'); +% sceneInfo.gtAvailable=1; + + + + + +% printSceneInfo; + +%% initial gradient descent +stateVec=stateInfo.stateVec; +[stateVec Evalue nIterations]=minimize(stateVec,'E',opt.maxIterCGD,stateInfo); +stateInfo.stateVec=stateVec; + +%% now do main optimization +converged=false; +epoch=0; +while ~converged && epoch=opt.maxEpochs + printMessage(1,'Max number of rounds reached.\n'); + end +end % converged +% basically we are done +printMessage(1,'All done (%.2f min = %.2fh = %.2f sec per frame)\n',toc(cemStartTime)/60,toc(cemStartTime)/3600,toc(cemStartTime)/F); + +%% cut ground truth +if sceneInfo.gtAvailable + if opt.track3d + cutGTToTrackingArea; + end +end + + +%% post processing +% get X Y matrices +[stateVec N F targetsExist stateInfo.X stateInfo.Y]=getStateInfo(stateInfo); + +if opt.track3d + stateInfo=cutStateToTrackingArea(stateInfo); +end + +% if we tracked on image, Xi = X +if ~opt.track3d + stateInfo.Xi=stateInfo.X; stateInfo.Yi=stateInfo.Y; +% otherwise project back +else + stateInfo.Xgp=stateInfo.X; stateInfo.Ygp=stateInfo.Y; + [stateInfo.Xi stateInfo.Yi]=projectToImage(stateInfo.X,stateInfo.Y,sceneInfo); +end + +%% get bounding boxes from corresponding detections +stateInfo=getBBoxesFromState(stateInfo); + +% if we have ground truth, evaluate results +if sceneInfo.gtAvailable + global gtInfo + printMessage(1,'\nEvaluation 2D:\n'); + [metrics2d metricsInfo2d]=CLEAR_MOT(gtInfo,stateInfo); + printMetrics(metrics2d,metricsInfo2d,1); + + if opt.track3d + printMessage(1,'\nEvaluation 3D:\n'); + evopt.eval3d=1; + [metrics3d metricsInfo3d]=CLEAR_MOT(gtInfo,stateInfo,evopt); + printMetrics(metrics3d,metricsInfo3d,1); + + end +end + + +% you can display the results with +% displayTrackingResult(sceneInfo,stateInfo) + +% end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/checkgrad.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/checkgrad.m new file mode 100644 index 0000000000000000000000000000000000000000..60001c328b6a1f8a4c550cd50779bd42185f70ba --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/checkgrad.m @@ -0,0 +1,59 @@ +function d = check(f, X, e, P1, P2, P3, P4, P5); + +% checkgrad checks the derivatives in a function, by comparing them to finite +% differences approximations. The partial derivatives and the approximation +% are printed and the norm of the diffrence divided by the norm of the sum is +% returned as an indication of accuracy. +% +% usage: checkgrad('f', X, e, P1, P2, ...) +% +% where X is the argument and e is the small perturbation used for the finite +% differences. and the P1, P2, ... are optional additional parameters which +% get passed to f. The function f should be of the type +% +% [fX, dfX] = f(X, P1, P2, ...) +% +% where fX is the function value and dfX is a vector of partial derivatives. +% +% Carl Edward Rasmussen, 2001-08-01. + +argstr = [f, '(X']; % assemble function call strings +argstrd = [f, '(X+dx']; +for i = 1:(nargin - 3) + argstr = [argstr, ',P', int2str(i)]; + argstrd = [argstrd, ',P', int2str(i)]; +end +argstr = [argstr, ')']; +argstrd = [argstrd, ')']; + +[y dy] = eval(argstr); % get the partial derivatives dy + +dh = zeros(length(X),1) ; +for j = 1:length(X) + dx = zeros(length(X),1); + dx(j) = dx(j) + e; % perturb a single dimension + y2 = eval(argstrd); + dx = -dx; + y1 = eval(argstrd); + + dh(j) = (y2 - y1)/(2*e); + +end + +% disp([dy(1:3) dh(1:3)]) % print the two vectors +% global itToInd +% u=zeros(length(dy),1); +% v=zeros(length(dy),1); +% for l=1:length(dy) +% if mod(l,2) +% [x y]=find(itToInd==l); +% u(l)=x; v(l)=y; +% else +% u(l)=u(l-1); +% v(l)=v(l-1); +% end +% end +% dy = analytical +% dh = numeric +disp([dy*1000 dh*1000 (dh-dy)*1000]) % print the two vectors +d = norm(dh-dy)/norm(dh+dy); % return norm of diff divided by norm of sum diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/compileMex.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/compileMex.m new file mode 100644 index 0000000000000000000000000000000000000000..ab2c4a8cacb260cdf17636c8c3df5bf8a017bbb9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/compileMex.m @@ -0,0 +1,34 @@ +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% compile mex files + +srcFiles={'Edet_mex','Edyn_mex','Eexc_mex','Eper_mex','CLEAR_MOT_mex','vectorToMatrices_mex','computeOcclusions2new_mex'}; +srcExt='c'; +srcdir=fullfile('mex','src'); +outdir=fullfile('mex','bin'); + +if ~exist(outdir,'dir'), mkdir(outdir); end + +for k=1:length(srcFiles) + eval(sprintf('mex -outdir %s %s.%s',outdir,fullfile(srcdir,char(srcFiles(k))),srcExt)); +end + +%% compile utils +utildir=fullfile('utils'); +srcFiles={'allWorldToImage_mex'}; +srcExt='c'; +srcdir=fullfile(utildir,'mex','src'); +outdir=fullfile(utildir,'mex','bin'); + +if ~exist(outdir,'dir'), mkdir(outdir); end +for k=1:length(srcFiles) + eval(sprintf('mex -outdir %s %s.%s',outdir,fullfile(srcdir,char(srcFiles(k))),srcExt)); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/computeOcclusions2.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/computeOcclusions2.m new file mode 100644 index 0000000000000000000000000000000000000000..4fcff7899b7924aaf267f39f2c799112f78ae15b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/computeOcclusions2.m @@ -0,0 +1,291 @@ +function [v tvis occx occy ddvix ddviy]=computeOcclusions2(X,Y) + +% compute all mutual occlusions between all targets +% +% For details see: +% An Analytical Formulation of Global Occlusion Reasoning for Multi-Target Tracking +% A. Andriyenko, S. Roth, and K. Schindler. +% In IEEE International Workshop on Visual Surveillance (in conjunction with ICCV), Barcelona, Spain, November 2011 +% +% input +% X,Y is the current state vector in matrix form +% +% output +% v - a FxN matrix, containing the rho-adjusted visibility portion of each target in each frame +% tvis - same as v, but not adjusted with rho. Could potentially be > 1 +% occx - x-derivative of each v +% occy - y-derivative of each v +% ddvix - x-derivative of visibility between each pair of targets +% ddviy - y-derivative of visibility between each pair of targets +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +% global N F; +[F N]=size(X); +global sceneInfo opt; + +camPar=sceneInfo.camPar; + + +% camPar=getCameraParameters(getCameraCalibrationFile(scenario,cam)); +[mR mT]=getRotTrans(camPar); +imSizeY=sceneInfo.imgHeight;imSizeX=sceneInfo.imgWidth; +scaleX=camPar.mGeo.mImgWidth/imSizeX; +scaleY=camPar.mGeo.mImgHeight/imSizeY; + + +rx=camPar.mExt.mRx;ry=camPar.mExt.mRy;rz=camPar.mExt.mRz; +tx=camPar.mExt.mTx;ty=camPar.mExt.mTy;tz=camPar.mExt.mTz; +txi=camPar.mExt.mTxi;tyi=camPar.mExt.mTyi;tzi=camPar.mExt.mTzi; +kappa=camPar.mInt.mKappa1; focal=camPar.mInt.mFocal;Sx=camPar.mInt.mSx; +Dpx=camPar.mGeo.mDpx;Dpy=camPar.mGeo.mDpy; + +sinrx=sin(rx); +cosrx=cos(rx); +sinry=sin(ry); +cosry=cos(ry); +sinrz=sin(rz); +cosrz=cos(rz); + + +mR11 = cosry * cosrz; +mR12 = cosrz * sinrx * sinry - cosrx * sinrz; +mR13 = sinrx * sinrz + cosrx * cosrz * sinry; +mR21 = cosry * sinrz; +mR22 = sinrx * sinry * sinrz + cosrx * cosrz; +mR23 = cosrx * sinry * sinrz - cosrz * sinrx; +mR31 = -sinry; +mR32 = cosry * sinrx; +mR33 = cosrx * cosry; + +% global params; +% p=params; +% rho=p.rho; %exp(-rho sum(...)) +rho=1; + +% convert all to image +Xi=zeros(size(X));Yi=zeros(size(Y)); + +zw=900; % height at which to center the gaussian +Z=zw*ones(size(X)); +% Z=0*Z; + +% allCT=zeros(2,2,F,N); +% for t=1:F +% existobj=find(X(t,:)); +% for i=existobj +% xw=X(t,i); yw=Y(t,i); +% [Xi2(t,i) Yi2(t,i)]=worldToImage(xw,yw,zw,mR,mT,camPar.mInt,camPar.mGeo); +% % [Xi(t,i) Yi(t,i)]=worldToImageNRD(xw,yw,zw,mR,mT,camPar.mInt,camPar.mGeo); +% end +% end + +% [Xi Yi ]=worldToImageNRD_mex(X,Y,Z, ... +% camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... +% camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1, ... +% mR,mT); + +[Xi Yi]=allWorldToImage_mex(X,Y,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + mR,mT); + +%%% !!!!!!!!!! TAKE CARE OF IMAGE SCALE!!! +Xi=Xi/scaleX; Yi=Yi/scaleY; +% Xit=Xit/scaleX; Yit=Yit/scaleY; + + +% Xi=X; +% Yi=Y; +% sum(sum(abs([Xi;Yi]-[Xi2;Yi2]))) +ol=zeros(N); +v=zeros(F,N); +tvis=zeros(F,N); +occx=zeros(F,N); +occy=zeros(F,N); +ddvix=zeros(F,N,N); +ddviy=zeros(F,N,N); +sf=zeros(N,N); +% size(X) +% p.mex=0; +if opt.mex +% if cexperiment==11 || cexperiment==12 || cexperiment == 13 +% [v tvis occx occy ddvix ddviy]=computeOcclusions2new_mex(X,Y,Xi,Yi,Dpx,Dpy,Sx,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz,txi,tyi,tzi,rho); +% else +% [v tvis occx occy ddvix ddviy]=computeOcclusions2_mex(X,Y,Xi,Yi,Dpx,Dpy,Sx,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz,rho); +% end + [v tvis occx occy ddvix ddviy]=computeOcclusions2new_mex(X,Y,Xi,Yi,Dpx,Dpy,Sx,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz,txi,tyi,tzi,rho); +else + for t=1:F + exobj=find(X(t,:)); + + icnt=0; + occmat=zeros(N); + occmatdX=zeros(N); + occmatdY=zeros(N); + occmatdX2=zeros(N); + occmatdY2=zeros(N); + ol=zeros(N); + + + for i=exobj + + icnt=icnt+1; + + a=[Xi(t,i) Yi(t,i)]; + Xwa=X(t,i); Ywa=Y(t,i); + Zwa=900; Zwb=900; + + +% if cexperiment==11 || cexperiment==12 || cexperiment == 13 +% Za=sqrt((txi-Xwa)^2 + (tyi-Ywa)^2 +(tzi-Zwa)^2); +% else +% Za=sqrt((tx-Xwa)^2 + (ty-Ywa)^2 +(tz-Zwa)^2); +% end + Za=sqrt((txi-Xwa)^2 + (tyi-Ywa)^2 +(tzi-Zwa)^2); + sizeOnImagea=1800*focal/Za/Dpy; +% figure(2) +% clf +% global frameNums; +% [frameNums(t) t i] +% im=imread(getImageFile(scenario,1,frameNums(t))); +% aa=round(a); +% x1=max(1,aa(1)-30); +% x2=min(768,aa(1)+30); +% x2=min(640,aa(1)+30); +% +% a +% sizeOnImagea +% y2=aa(2); y1=y2-round(sizeOnImagea); +% [x1 x2 y1 y2] +% im=im(y1:y2,x1:x2,:); +% imshow(im); +% +% pause + A=[(sizeOnImagea/2)^2/4 0; 0 (sizeOnImagea/2)^2]; + + for j=exobj + if j>i + Xwb=X(t,j); Ywb=Y(t,j); + b=[Xi(t,j) Yi(t,j)]; + +% if cexperiment==11 || cexperiment==12 +% Zb=sqrt((txi-Xwb)^2 + (tyi-Ywb)^2 +(tzi-Zwb)^2); +% else +% Zb=sqrt((tx-Xwb)^2 + (ty-Ywb)^2 +(tz-Zwb)^2); +% end + Zb=sqrt((txi-Xwb)^2 + (tyi-Ywb)^2 +(tzi-Zwb)^2); + sizeOnImageb=1800*focal/Zb/Dpy; + + B=[(sizeOnImageb/2)^2/4 0; 0 (sizeOnImageb/2)^2]; + + C=A+B; + alessb=a-b; + ol(i,j)=exp(-.5*(alessb * (C \ alessb'))); + end + end + + + for j=exobj + if j0.0001 && nargout > 1 %% source for inexact gradient !!! +% occmatdX(i,j)=dfdXwa(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,kappa,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdY(i,j)=dfdYwa(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,kappa,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdX2(i,j)=dfdXwb(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,kappa,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdY2(i,j)=dfdYwb(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,kappa,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdX(i,j)=dfnddXwa(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdY(i,j)=dfnddYwa(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdX2(i,j)=dfnddXwb(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdY2(i,j)=dfnddYwb(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdX(i,j)=dfnddXwa_new(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,txi,ty,tyi,tz,tzi); +% occmatdY(i,j)=dfnddYwa_new(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,txi,ty,tyi,tz,tzi); +% occmatdX2(i,j)=dfnddXwb_new(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,txi,ty,tyi,tz,tzi); +% occmatdY2(i,j)=dfnddYwb_new(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,txi,ty,tyi,tz,tzi); + % [dfndXa dfndYa dfndXb dfndYb]=dfnddALL(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); + + [dfndXa dfndYa dfndXb dfndYb]=dfnddALL_mex(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% [dfndXa dfndYa dfndXb dfndYb]=dfnddALLnew_mex(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz,txi,tyi,tzi); + occmatdX(i,j)=dfndXa; + occmatdY(i,j)=dfndYa; + occmatdX2(i,j)=dfndXb; + occmatdY2(i,j)=dfndYb; + + end + + end + end + + + end + + if nargout > 2 + for i=exobj + sumdx=0; + sumdy=0; + for j=exobj + + if j~=i + sumdx=sumdx-rho*exp(-rho*sum(occmat(j,:)))*(occmatdX2(j,i)); + ddvix(t,i,j) = -rho*exp(-rho*sum(occmat(j,:)))*(occmatdX2(j,i)); + + sumdy=sumdy-rho*exp(-rho*sum(occmat(j,:)))*(occmatdY2(j,i)); + ddviy(t,i,j) = -rho*exp(-rho*sum(occmat(j,:)))*(occmatdY2(j,i)); + else + sumdx=sumdx-rho*exp(-rho*sum(occmat(i,:)))*(sum(occmatdX(i,:))); + ddvix(t,i,j) = -rho*exp(-rho*sum(occmat(i,:)))*(sum(occmatdX(i,:))); + + sumdy=sumdy-rho*exp(-rho*sum(occmat(i,:)))*(sum(occmatdY(i,:))); + ddviy(t,i,j) = -rho*exp(-rho*sum(occmat(i,:)))*(sum(occmatdY(i,:))); + end + end + occx(t,i)=sumdx; + occy(t,i)=sumdy; + % if t==15 + % [t i] + % [sumdx sumdy] + % end + end + end + v(t,:)=exp(-rho*sum(occmat,2)'); + tvis(t,:)=exp(-sum(occmat,2)'); + % t + % [occmat 1-sum(occmat,2) exp(-rho*sum(occmat,2))] + % pause + end + + +end +% a=sum(sum(abs(v-v2))); +% b=sum(sum(abs(tvis-tvis2))); +% c=sum(sum(abs(occx-occx2))); +% % occx +% % occx2 +% d=sum(sum(abs(occy-occy2))); +% e=sum(sum(abs(sum(ddvix-ddvix2)))); +% f=sum(sum(abs(sum(ddviy-ddviy2)))); +% % [a b c d e f] +% if sum([a b c d e f]) > 1e-5 +% [a b c d e f] +% pause +% end +% sf +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/computeOcclusions2d.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/computeOcclusions2d.m new file mode 100644 index 0000000000000000000000000000000000000000..8d77714361d66692896ec564f075785f3e9c7311 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/computeOcclusions2d.m @@ -0,0 +1,258 @@ +function [v tvis occx occy ddvix ddviy]=computeOcclusions2d(X,Y) + +% NOT YET IMPLEMENTED !!! +% +% compute all mutual occlusions between all targets (on image) +% +% input +% X,Y is the current state vector in matrix form +% +% output +% v - a FxN matrix, containing the rho-adjusted visibility portion of each target in each frame +% tvis - same as v, but not adjusted with rho. Could potentially be > 1 +% occx - x-derivative of each v +% occy - y-derivative of each v +% ddvix - x-derivative of visibility between each pair of targets +% ddviy - y-derivative of visibility between each pair of targets +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% global N F; +[F N]=size(X); +global sceneInfo opt; + +htobj=sceneInfo.htobj; + +rho=1; + +% convert all to image +Xi=X; Yi=Y; + +extar=find(Xi); +heights=feval(htobj,Xi(extar),Yi(extar)); + +Z=zeros(size(X)); +Z(extar)=heights); +Xi +Z +pause +% Z=0*Z; + +% allCT=zeros(2,2,F,N); +% for t=1:F +% existobj=find(X(t,:)); +% for i=existobj +% xw=X(t,i); yw=Y(t,i); +% [Xi2(t,i) Yi2(t,i)]=worldToImage(xw,yw,zw,mR,mT,camPar.mInt,camPar.mGeo); +% % [Xi(t,i) Yi(t,i)]=worldToImageNRD(xw,yw,zw,mR,mT,camPar.mInt,camPar.mGeo); +% end +% end + +% [Xi Yi ]=worldToImageNRD_mex(X,Y,Z, ... +% camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... +% camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1, ... +% mR,mT); + +[Xi Yi]=allWorldToImage_mex(X,Y,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + mR,mT); + +%%% !!!!!!!!!! TAKE CARE OF IMAGE SCALE!!! +Xi=Xi/scaleX; Yi=Yi/scaleY; +% Xit=Xit/scaleX; Yit=Yit/scaleY; + + +% Xi=X; +% Yi=Y; +% sum(sum(abs([Xi;Yi]-[Xi2;Yi2]))) +ol=zeros(N); +v=zeros(F,N); +tvis=zeros(F,N); +occx=zeros(F,N); +occy=zeros(F,N); +ddvix=zeros(F,N,N); +ddviy=zeros(F,N,N); +sf=zeros(N,N); +% size(X) +% p.mex=0; +if opt.mex +% if cexperiment==11 || cexperiment==12 || cexperiment == 13 +% [v tvis occx occy ddvix ddviy]=computeOcclusions2new_mex(X,Y,Xi,Yi,Dpx,Dpy,Sx,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz,txi,tyi,tzi,rho); +% else +% [v tvis occx occy ddvix ddviy]=computeOcclusions2_mex(X,Y,Xi,Yi,Dpx,Dpy,Sx,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz,rho); +% end + [v tvis occx occy ddvix ddviy]=computeOcclusions2new_mex(X,Y,Xi,Yi,Dpx,Dpy,Sx,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz,txi,tyi,tzi,rho); +else + for t=1:F + exobj=find(X(t,:)); + + icnt=0; + occmat=zeros(N); + occmatdX=zeros(N); + occmatdY=zeros(N); + occmatdX2=zeros(N); + occmatdY2=zeros(N); + ol=zeros(N); + + + for i=exobj + + icnt=icnt+1; + + a=[Xi(t,i) Yi(t,i)]; + Xwa=X(t,i); Ywa=Y(t,i); + Zwa=900; Zwb=900; + + +% if cexperiment==11 || cexperiment==12 || cexperiment == 13 +% Za=sqrt((txi-Xwa)^2 + (tyi-Ywa)^2 +(tzi-Zwa)^2); +% else +% Za=sqrt((tx-Xwa)^2 + (ty-Ywa)^2 +(tz-Zwa)^2); +% end + Za=sqrt((txi-Xwa)^2 + (tyi-Ywa)^2 +(tzi-Zwa)^2); + sizeOnImagea=1800*focal/Za/Dpy; +% figure(2) +% clf +% global frameNums; +% [frameNums(t) t i] +% im=imread(getImageFile(scenario,1,frameNums(t))); +% aa=round(a); +% x1=max(1,aa(1)-30); +% x2=min(768,aa(1)+30); +% x2=min(640,aa(1)+30); +% +% a +% sizeOnImagea +% y2=aa(2); y1=y2-round(sizeOnImagea); +% [x1 x2 y1 y2] +% im=im(y1:y2,x1:x2,:); +% imshow(im); +% +% pause + A=[(sizeOnImagea/2)^2/4 0; 0 (sizeOnImagea/2)^2]; + + for j=exobj + if j>i + Xwb=X(t,j); Ywb=Y(t,j); + b=[Xi(t,j) Yi(t,j)]; + +% if cexperiment==11 || cexperiment==12 +% Zb=sqrt((txi-Xwb)^2 + (tyi-Ywb)^2 +(tzi-Zwb)^2); +% else +% Zb=sqrt((tx-Xwb)^2 + (ty-Ywb)^2 +(tz-Zwb)^2); +% end + Zb=sqrt((txi-Xwb)^2 + (tyi-Ywb)^2 +(tzi-Zwb)^2); + sizeOnImageb=1800*focal/Zb/Dpy; + + B=[(sizeOnImageb/2)^2/4 0; 0 (sizeOnImageb/2)^2]; + + C=A+B; + alessb=a-b; + ol(i,j)=exp(-.5*(alessb * (C \ alessb'))); + end + end + + + for j=exobj + if j0.0001 && nargout > 1 %% source for inexact gradient !!! +% occmatdX(i,j)=dfdXwa(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,kappa,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdY(i,j)=dfdYwa(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,kappa,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdX2(i,j)=dfdXwb(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,kappa,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdY2(i,j)=dfdYwb(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,kappa,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdX(i,j)=dfnddXwa(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdY(i,j)=dfnddYwa(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdX2(i,j)=dfnddXwb(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdY2(i,j)=dfnddYwb(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% occmatdX(i,j)=dfnddXwa_new(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,txi,ty,tyi,tz,tzi); +% occmatdY(i,j)=dfnddYwa_new(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,txi,ty,tyi,tz,tzi); +% occmatdX2(i,j)=dfnddXwb_new(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,txi,ty,tyi,tz,tzi); +% occmatdY2(i,j)=dfnddYwb_new(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,txi,ty,tyi,tz,tzi); + % [dfndXa dfndYa dfndXb dfndYb]=dfnddALL(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); + + [dfndXa dfndYa dfndXb dfndYb]=dfnddALL_mex(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz); +% [dfndXa dfndYa dfndXb dfndYb]=dfnddALLnew_mex(Dpx,Dpy,Sx,Xwa,Xwb,Ywa,Ywb,Zwa,Zwb,focal,mR11,mR12,mR13,mR21,mR22,mR23,mR31,mR32,mR33,tx,ty,tz,txi,tyi,tzi); + occmatdX(i,j)=dfndXa; + occmatdY(i,j)=dfndYa; + occmatdX2(i,j)=dfndXb; + occmatdY2(i,j)=dfndYb; + + end + + end + end + + + end + + if nargout > 2 + for i=exobj + sumdx=0; + sumdy=0; + for j=exobj + + if j~=i + sumdx=sumdx-rho*exp(-rho*sum(occmat(j,:)))*(occmatdX2(j,i)); + ddvix(t,i,j) = -rho*exp(-rho*sum(occmat(j,:)))*(occmatdX2(j,i)); + + sumdy=sumdy-rho*exp(-rho*sum(occmat(j,:)))*(occmatdY2(j,i)); + ddviy(t,i,j) = -rho*exp(-rho*sum(occmat(j,:)))*(occmatdY2(j,i)); + else + sumdx=sumdx-rho*exp(-rho*sum(occmat(i,:)))*(sum(occmatdX(i,:))); + ddvix(t,i,j) = -rho*exp(-rho*sum(occmat(i,:)))*(sum(occmatdX(i,:))); + + sumdy=sumdy-rho*exp(-rho*sum(occmat(i,:)))*(sum(occmatdY(i,:))); + ddviy(t,i,j) = -rho*exp(-rho*sum(occmat(i,:)))*(sum(occmatdY(i,:))); + end + end + occx(t,i)=sumdx; + occy(t,i)=sumdy; + % if t==15 + % [t i] + % [sumdx sumdy] + % end + end + end + v(t,:)=exp(-rho*sum(occmat,2)'); + tvis(t,:)=exp(-sum(occmat,2)'); + % t + % [occmat 1-sum(occmat,2) exp(-rho*sum(occmat,2))] + % pause + end + + +end +% a=sum(sum(abs(v-v2))); +% b=sum(sum(abs(tvis-tvis2))); +% c=sum(sum(abs(occx-occx2))); +% % occx +% % occx2 +% d=sum(sum(abs(occy-occy2))); +% e=sum(sum(abs(sum(ddvix-ddvix2)))); +% f=sum(sum(abs(sum(ddviy-ddviy2)))); +% % [a b c d e f] +% if sum([a b c d e f]) > 1e-5 +% [a b c d e f] +% pause +% end +% sf +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/demo/ekf/e0001.mat b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/demo/ekf/e0001.mat new file mode 100644 index 0000000000000000000000000000000000000000..9220a55d7354a04d65c89ebab1e43215fc35c797 Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/demo/ekf/e0001.mat differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getConOptionsDemo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getConOptionsDemo.m new file mode 100644 index 0000000000000000000000000000000000000000..aadefad31de3a16a0309cb0371476c9786ae0c82 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getConOptionsDemo.m @@ -0,0 +1,45 @@ +function opt=getConOptionsDemo(w) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% general +opt.track3d=0; % set to 1 for track estimation on ground plane +opt.verbosity=1; % 0=silent, 1=short info, 2=long info, 3=all +opt.mex=1; % use mex +opt.visOptim=0; % visualize optimization +opt.occ=0; % compute occlusions [Andriyenko et al. ICCV VS Workshop 2011] + % only works for 3d tracking for now! +opt.cutToTA=0; % cut detections, ground truth and result to tracking area + +% optimization +opt.jumpsOrder = [1 3 4 2 6 5]; % standard: merge grow shrink split add remove +opt.maxEpochs = 15; % max global iterations (rounds) +opt.maxIterCGD = 30; % max iterations for each gradient descent + +% energy weights (default 2d) +opt.weightEdet=1; % should be kept at 1 +opt.weightEdyn=0.0; +opt.weightEexc=0.52; +opt.weightEper=0.5; +opt.weightEreg=0.6; +opt.weightEapp=0.; + +% other parameters +opt.lambda=0.125; + +if nargin==1 + opt.weightEdet=w(1); % should be kept at 1 + opt.weightEdyn=w(2); + opt.weightEexc=w(3); + opt.weightEper=w(4); + opt.weightEreg=w(5); + opt.weightEreg=w(6); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getJumpMoveFunction.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getJumpMoveFunction.m new file mode 100644 index 0000000000000000000000000000000000000000..836225fb916d449d8304e200002c41d625d806af --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getJumpMoveFunction.m @@ -0,0 +1,28 @@ +function moveFct=getJumpMoveFunction(m) +% returns the name of the function +% corresponding to jump move m +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +switch(m) + case 1 + moveFct='makeMergeMove'; + case 2 + moveFct='makeSplitMove'; + case 3 + moveFct='makeGrowMove'; + case 4 + moveFct='makeShrinkMove'; + case 5 + moveFct='makeRemoveMove'; + case 6 + moveFct='makeAddMove'; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getMetricsFromDiary.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getMetricsFromDiary.m new file mode 100644 index 0000000000000000000000000000000000000000..c324d4cad3f4c6ccbfd855cb915e4939be9ec15e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getMetricsFromDiary.m @@ -0,0 +1,16 @@ +%% +fid = fopen('testingparams.txt'); +lncnt=0; +tline = fgets(fid); +allmets=[]; +while ischar(tline) && lncnt<2447 + lncnt=lncnt+1; + tline = fgets(fid); + if ~mod(lncnt+1,6) +% disp(tline) + rdline=sscanf(tline,' %f %f %f| %d %d %d %d| %d %d %d %d| %f %f %f'); + allmets=[allmets; rdline']; + end +end + +fclose(fid); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getOptions.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getOptions.m new file mode 100644 index 0000000000000000000000000000000000000000..f72ad56dac2d7066eb841e3639d95d6c8757b314 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getOptions.m @@ -0,0 +1,57 @@ +function opt=getOptions(w) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% general +opt.track3d=0; % set to 1 for track estimation on ground plane +opt.verbosity=2; % 0=silent, 1=short info, 2=long info, 3=all +opt.mex=1; % use mex +opt.visOptim=1; % visualize optimization +opt.occ=0; % compute occlusions [Andriyenko et al. ICCV VS Workshop 2011] + % only works for 3d tracking for now! +opt.cutToTA=0; % cut detections, ground truth and result to tracking area + + +% optimization +opt.jumpsOrder=[1 3 4 2 6 5]; % standard: merge grow shrink split add remove +opt.maxEpochs=15; % max global iterations (rounds) +opt.maxIterCGD=30; % max iterations for each gradient descent + +% energy weights (default 2d) +opt.weightEdet=1; % should be kept at 1 +opt.weightEdyn=1; +opt.weightEexc=1; +opt.weightEper=.5; +opt.weightEreg=1; +opt.weightEapp=0; + +% energy weights (default 3d) +if opt.track3d + opt.weightEdet=1; % should be kept at 1 + opt.weightEdyn=.02; + opt.weightEexc=.5; + opt.weightEper=.5; + opt.weightEreg=1; +end + +% other parameters +opt.lambda=0.125; + +if nargin==1 + opt.weightEdet=w(1); % should be kept at 1 + opt.weightEdyn=w(2); + opt.weightEexc=w(3); + opt.weightEper=w(4); + opt.weightEreg=w(5); + opt.weightEreg=w(6); + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getSceneInfoConDemo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getSceneInfoConDemo.m new file mode 100644 index 0000000000000000000000000000000000000000..81d1f0ed7dce29495504c27de7768b8d81aa20d2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getSceneInfoConDemo.m @@ -0,0 +1,25 @@ +function sceneInfo = getSceneInfoConDemo(curSequence) + +sceneInfo.imgFolder = curSequence.imgFolder; +sceneInfo.frameNums = curSequence.frameNums; +sceneInfo.imgFileFormat = curSequence.imgFileFormat; + +% image dimensions +sceneInfo.imgHeight = curSequence.imgHeight; +sceneInfo.imgWidth = curSequence.imgWidth; + +%% tracking area +% if we are tracking on the ground plane +% we need to explicitly secify the tracking area +% otherwise image = tracking area +sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area + +%% camera +cameraconffile=[]; +sceneInfo.camFile=cameraconffile; + +%% target size +sceneInfo.targetSize=sceneInfo.imgWidth/30; + +%% ground truth +sceneInfo.gtAvailable=0; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getStateInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getStateInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..5a6123b04984baf92636a1f8766969288ee7985d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/getStateInfo.m @@ -0,0 +1,19 @@ +function [stateVec, N, F, targetsExist, X, Y]=getStateInfo(stateInfo) +% unmake stateInfo +% get number of targets, number of frames +% state vector, mapping and matrices +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +stateVec=stateInfo.stateVec; +N=stateInfo.N;F=stateInfo.F; +targetsExist=stateInfo.targetsExist; + +[X, Y]=vectorToMatrices(stateVec,stateInfo); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeAddMove.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeAddMove.m new file mode 100644 index 0000000000000000000000000000000000000000..69e41ab27e730541e51a4f07c6e139784179eb5a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeAddMove.m @@ -0,0 +1,365 @@ +function [stateInfo alladdenergy]=makeAddMove(stateInfo,createN) +%% add move +% add new targets at unused detections +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global detMatrices; +global sceneInfo; + +% get state info +[~, N F targetsExist X Y]=getStateInfo(stateInfo); + +% global scene info and detections +gridStep=sceneInfo.targetSize; +Xd=detMatrices.Xd; Yd=detMatrices.Yd; Sd=detMatrices.Sd; + +% original state +Xold=X; Yold=Y;Nold=N; + + +MAXNEW=8; % maximum number of targets to be added +printMessage(2,'creating targets...'); + +if exist('createN','var') + MAXNEW=createN; +end +alladdenergy=zeros(1,MAXNEW); + +for j=1:MAXNEW + printMessage(2,'.'); + + best=[]; + cntbest=0; + bestgain=Inf; + + % in each frame... + for t=1:F + + % memorize current configuration + X=Xold; Y=Yold; + stateInfoOld=stateInfo; + te=targetsExist; + + % first of all, find out, which detections are still 'free' + exdet=find(Xd(t,:)); + potdet=~~Xd(t,:); + % get rid of the ones occupied + extar=find(X(t,:)); + for d=exdet + for i=extar + if norm([X(t,i) Y(t,i)]-[Xd(t,d) Yd(t,d)])newframes(3))); % all that start after newframes +% importanti=setdiff(1:Nold,notimportanti); % all important ones + allOld=true(1,Nold); + allOld(notimportanti)=0; + importanti=find(allOld); +% importanti +% importanti2 +% pause + + targetsExist=targetsExist(importanti,:); % keep important + targetsExist(:,1)=max(targetsExist(:,1),newframes(1)); % shorten from past + + targetsExist(:,1)=targetsExist(:,2)-max(2,diff(targetsExist,[],2)); % take care of special case + + targetsExist(:,2)=min(targetsExist(:,2),newframes(2)); % shorten future + targetsExist(:,2)=targetsExist(:,1)+max(2,diff(targetsExist,[],2)); % take care of special case + + Xt=X(:,importanti);Yt=Y(:,importanti); + + N=size(targetsExist,1); + % printMessage(2,'oldc %i\n',size(targetsExist,1)); + + for ii=1:N % fill rest of frames with zeros + Xt(1:targetsExist(ii,1)-1,ii)=0; Yt(1:targetsExist(ii,1)-1,ii)=0; + Xt(targetsExist(ii,2)+1:end,ii)=0; Yt(targetsExist(ii,2)+1:end,ii)=0; + end + + % what is the old energy + stateInfo.targetsExist=targetsExist; + stateInfo.N=N; + + if N + stateInfo=matricesToVector(Xt,Yt,stateInfo); + x=stateInfo.stateVec; + origenergy=E(x,stateInfo); + else + origenergy=0; + end + + minbest=origenergy; +% [Edet(x) Eexc(x) Edyn(x) Econ(x)] + + %try to insert target on current detection + N=N+1; + targetsExist(N,:)=[newframes(1) newframes(end)]; + + for d=exdet + for trytrick=[1] + Xt(newframes,N)=Xd(t,d);Yt(newframes,N)=Yd(t,d); + %% try some trick here + %find closest forward and backward + usedtrick=0; + if trytrick + if t==1 + exxdn=find(Xd(t+1,:)); + exxdnn=find(Xd(t+2,:)); + mindist=Inf; + closestn=[]; + closestnn=[]; + for n=exxdn + thisdist=norm([Xd(t,d) Yd(t,d)]-[Xd(t+1,n) Yd(t+1,n)]); + if thisdist-1e5 % numerical issue + minbest=newenergy; + best=[t d cf]; + bestX=Xt(newframes,N); + bestY=Yt(newframes,N); + bestnewframes=newframes; + cntbest=cntbest+1; + bestgain=newenergy-origenergy; + bestnewgain=newenergy; + bestoriggain=origenergy; + bestimportanti=importanti; + woohoo=0; + if usedtrick + woohoo=1; + end + end + % printMessage(2,'new2 %i\n',N); + end + end + % printMessage(2,'old? %i\n',N); + targetsExist=te; + stateInfo=stateInfoOld; + end + + if cntbest>5 + break; + + + % N=size(te,1); + % printMessage(2,'break old %i\n',N); + end + end + N=Nold; + targetsExist=te; + stateInfo=stateInfoOld; + + % there is a bug, sometimes... + alladdenergy(j)=bestgain; + + if bestgain<-1000000 + printMessage(2,'something wrong. bg: %f, best: %i %i %i\n',bestgain, best); + + elseif bestgain<0 + + N=N+1; + stateInfo.N=N; + + d=best(2); + cf=best(3); + t=best(1); +% printMessage(2,'add target %i around frame %i. Energy gain: %f (%f %f). Trick: %i\n',N,cf,bestgain,bestnewgain,bestoriggain,woohoo); +% printMessage(2,', %i (%i,%i, %.2f|%.2f)',N,cf,woohoo,bestX(2),bestY(2)); + printMessage(3,', %i',N); + newframes=cf-1:cf+1; + X(newframes,N)=bestX;Y(newframes,N)=bestY; + targetsExist(N,:)=[newframes(1) newframes(end)]; + stateInfo.targetsExist=targetsExist; + + Xold=X; Yold=Y; % replace X Y + Nold=N; + stateInfoOld=stateInfo; + else +% printMessage(2,'do not add target %i around frame %i. Energy gain: %f \n',N+1,cf,bestgain); + break; + end + +end + +stateInfo=matricesToVector(X,Y,stateInfo); +% toc +printMessage(2,'...done\n'); +% [Xold X] +% pause +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeGrowMove.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeGrowMove.m new file mode 100644 index 0000000000000000000000000000000000000000..eda444fc6dfb759068efc29ad4d82a32225d6c9d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeGrowMove.m @@ -0,0 +1,326 @@ +function [stateInfo allgrowenergy]=makeGrowMove(stateInfo, doTargetN, doTargetN2) +%% extension move +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +% get state info +[~, N F targetsExist X Y]=getStateInfo(stateInfo); + +% original state +Xold=X; Yold=Y;Nold=N; +stateInfoOld=stateInfo; + +global opt % we need Eper weight + +% how do we extrapolate? +% extrapmeth='spline'; +extrapmeth='linear'; + +% how many frames to extend max? +MAXEXT=50; + +allgrowenergy=zeros(2,Nold); + +% params=getOptimParameters(); + +% in which order should we process? +% tarorderbck=randperm(Nold); +% tarorderfrw=randperm(Nold); +tarorderbck=1:Nold; +tarorderfrw=1:Nold; + +if nargin==2 + tarorderbck=doTargetN; + tarorderfrw=doTargetN; +elseif nargin==3 + tarorderbck=doTargetN; + tarorderfrw=doTargetN2; +end + +% save info about growth of each trajectory +targrownbck=zeros(1,Nold); +targrownfrw=zeros(1,Nold); + +if nargin==1 + printMessage(2,'Target: ') + printMessage(2,'%4i',tarorderbck); + printMessage(2,' Tars Frms'); + printMessage(2,'\ngrow bck:'); +end + +for id=tarorderbck + % printMessage(2,'.'); + te=targetsExist; + X=Xold; Y=Yold; + + + existframes=targetsExist(id,1):targetsExist(id,2); + if existframes(1) > 1 + % plot3(X(targetsExist(id,1):targetsExist(id,2),id),Y(targetsExist(id,1):targetsExist(id,2),id),targetsExist(id,1):targetsExist(id,2),'color',getColorFromID(id)); + % pause + % Remove targets with no influence + notimportanti=find(targetsExist(:,1)>=existframes(1)); % all that start after current begins + notimportanti=union(notimportanti,find(targetsExist(:,2)existframes(end)+MAXEXT)); % all that end MAXEXT before current begins + + newid=id-length(find(notimportanti+%if',id,bestmove(end)-bestmove(1)+1); + + targrownfrw(id)=bestmove(end)-bestmove(1)+1; + printMessage(2,'%4i',targrownfrw(id)) + + X(bestmove,id)=interp1(existframes,Xi(existframes),bestmove,extrapmeth,'extrap'); + Y(bestmove,id)=interp1(existframes,Yi(existframes),bestmove,extrapmeth,'extrap'); + targetsExist(id,2)=bestmove(end); + targetsExist(id,1)=te(id,1); + Xold=X; Yold=Y; + stateInfo.targetsExist=targetsExist; + stateInfo=matricesToVector(X,Y,stateInfo); + stateInfoOld=stateInfo; + + xt=stateInfo.stateVec; + + else + printMessage(2,' -'); + end + else + printMessage(2,' -'); + end +end +printMessage(2,'%5i%5i',numel(find(targrownfrw)),sum(targrownfrw)); + +stateInfo=matricesToVector(X,Y,stateInfo); + +printMessage(2,'...done\n'); +% printMessage(2,'Trajectory length'); +% printMessage(2,'%4i',diff(targetsExist,[],2)') +% [Xold X] +% pause +% toc; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeMergeMove.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeMergeMove.m new file mode 100644 index 0000000000000000000000000000000000000000..2f5872506c8837f839bfca1ef6bbaf1de9f15602 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeMergeMove.m @@ -0,0 +1,199 @@ +function [stateInfo allmergeenergy]=makeMergeMove(stateInfo) +% merge two trajectories if possible +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% tic; + +% how do we interpolate? +% interpmeth='spline'; +interpmeth='linear'; + +global sceneInfo; + +stateVecOld=stateInfo.stateVec; +N=stateInfo.N;F=stateInfo.F; +targetsExist=stateInfo.targetsExist; +gridStep=sceneInfo.targetSize; + + +[X Y]=vectorToMatrices(stateVecOld,stateInfo); + +x=stateVecOld; +origenergy=E(x,stateInfo); + + +allmergeenergy=zeros(N); + + +printMessage(2,'merging...'); +itcnt=0; +while 1 && N +% fprintf('.'); + itcnt=itcnt+1; + te=targetsExist; + stateInfoOld=stateInfo; + + mergeCost=Inf*ones(N); + + %% look for potential connections first (speedlimit) + potentialConnections=false(N,N); + for id=1:N + otheri=setdiff(1:N,id); + for id2=otheri + tend=targetsExist(id,2); + tsta=targetsExist(id2,1); + if tend=0 +% fprintf('best %id and %id. Energy gain: %f\n',id,id2,c); + printMessage(2,'...done\n'); + break; + else +% c + + [id id2]=ind2sub([N N],mi); + if id==id2 + printMessage(2,'...done\n'); + break; + end + + fromframe1=targetsExist(id,1); + toframe1=targetsExist(id,2); + fromframe2=targetsExist(id2,1); + toframe2=targetsExist(id2,2); + + + newframes=[fromframe1:toframe1 fromframe2:toframe2]; + printMessage(3,' %id+%id (%id)',id,id2,fromframe2-toframe1-1); +% fprintf('merging %id and %id over %id frames. Energy gain: %f\n',id,id2,fromframe2-toframe1-1,c); + onecolX=[X(fromframe1:toframe1,id);X(fromframe2:toframe2,id2)]; + onecolY=[Y(fromframe1:toframe1,id);Y(fromframe2:toframe2,id2)]; + + onecolX=interp1(newframes,onecolX,newframes(1):newframes(end),interpmeth); + onecolY=interp1(newframes,onecolY,newframes(1):newframes(end),interpmeth); + onecolX=onecolX'; onecolY=onecolY'; + + + +% X(fromframe1:toframe2,id)=onecolX;Y(fromframe1:toframe2,id)=onecolY; +% otheri=setdiff(1:N,id2); +% X=X(:,otheri);Y=Y(:,otheri); +% +% targetsExist(id,1)=fromframe1;targetsExist(id,2)=toframe2; +% targetsExist=targetsExist(otheri,:); +% +% N=N-1; + + %%% SMOOTH HERE AS WELL + + X(fromframe1:toframe2,id)=onecolX;Y(fromframe1:toframe2,id)=onecolY; + + % try to smooth + sw=[0.2 0.3 0.3 0.2]; % smoothing weights +% sw=[0 1 0 0]; % smoothing weights + X(toframe1+1,id)=sw(1)*X(toframe1-1,id)+sw(2)*X(toframe1,id)+sw(3)*X(toframe1+2,id)+sw(4)*X(toframe1+3,id); + Y(toframe1+1,id)=sw(1)*Y(toframe1-1,id)+sw(2)*Y(toframe1,id)+sw(3)*Y(toframe1+2,id)+sw(4)*Y(toframe1+3,id); + X(fromframe2-1,id)=sw(1)*X(fromframe2-3,id)+sw(2)*X(fromframe2-2,id)+sw(3)*X(fromframe2,id)+sw(4)*X(fromframe2+1,id); + Y(fromframe2-1,id)=sw(1)*Y(fromframe2-3,id)+sw(2)*Y(fromframe2-2,id)+sw(3)*Y(fromframe2,id)+sw(4)*Y(fromframe2+1,id); + + otheri=setdiff(1:N,id2); + X=X(:,otheri);Y=Y(:,otheri); + + targetsExist(id,1)=fromframe1;targetsExist(id,2)=toframe2; + targetsExist=targetsExist(otheri,:); + + N=N-1; + stateInfo.N=N; stateInfo.targetsExist=targetsExist; + + + end +end +stateInfo=matricesToVector(X,Y,stateInfo); + +% toc; +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeRemoveMove.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeRemoveMove.m new file mode 100644 index 0000000000000000000000000000000000000000..b6550670e29a397b926d2603040d7226b9d5d957 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeRemoveMove.m @@ -0,0 +1,79 @@ + +function [stateInfo allpurgeenergy]=makeRemoveMove(stateInfo, doTargetN) +%% removal move +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +% get state info +[~, N, ~, targetsExist, X, Y]=getStateInfo(stateInfo); + +% original state +Nold=N; +stateInfoOld=stateInfo; + +allpurgeenergy=zeros(1,N); + +x=stateInfo.stateVec; +origenergy=E(x,stateInfo); % current energy with removed frames + +% in which order should we process? +% tarorder=randperm(Nold); +tarorder=1:Nold; + +if nargin>1 + tarorder=doTargetN; +end + +printMessage(2,'removing targets...'); +for i=tarorder + if i>N, break; end; + + printMessage(2,'.'); + te=targetsExist; + Xt=X;Yt=Y; + + %what would the world look like without target i + otheris=setdiff(1:N,i); + + Xt=Xt(:,otheris);Yt=Yt(:,otheris); + targetsExist=targetsExist(otheris,:); + + N=N-1; + + stateInfo.N=N; + stateInfo.targetsExist=targetsExist; + stateInfo=matricesToVector(Xt,Yt,stateInfo); + xt=stateInfo.stateVec; + newenergy=E(xt,stateInfo); % what is the new energy + + allpurgeenergy(i)=newenergy-origenergy; + if newenergyexistframes(1)+MAXSHR); % all that start MAXSHR after current begins + notimportanti=union(notimportanti,find(targetsExist(:,2)existframes(end)); % all that start after current ends + notimportanti=union(notimportanti,find(targetsExist(:,2)<=existframes(end)-MAXSHR)); % all that end MAXSHR before current begins + + newid=id-length(find(notimportanti-%if',length(bestmove),id); + X(bestmove,id)=0; + Y(bestmove,id)=0; + targetsExist(id,2)=bestmove(1)-1; + Xold=X; Yold=Y; % replace X Y + stateInfo.targetsExist=targetsExist; + stateInfo=matricesToVector(X,Y,stateInfo); + stateInfoOld=stateInfo; + + xt=stateInfo.stateVec; + else + printMessage(2,' -'); + end +end +printMessage(2,'%5i%5i',numel(find(tarshrnkfrw)),sum(tarshrnkfrw)); + +stateInfo=matricesToVector(X,Y,stateInfo); + +printMessage(2,'...done\n'); +% toc +% [Xold X] +% pause +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeSplitMove.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeSplitMove.m new file mode 100644 index 0000000000000000000000000000000000000000..69e9072c34cef2ac44bfa865701edc73898ab124 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/makeSplitMove.m @@ -0,0 +1,132 @@ +function [stateInfo, allsplitenergy]=makeSplitMove(stateInfo, doTargetN) +% checks for each location, whether a split of +% the trajectory yields lower energy +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% get state info +[~,N, F, targetsExist, X, Y]=getStateInfo(stateInfo); + +% original state +Xold=X; Yold=Y;Nold=N; +stateInfoOld=stateInfo; + +global opt % we need Eper weight + +allsplitenergy=zeros(1,N); + +Nold=N; % remember original number of targets + +%tarorder=randperm(Nold); +tarorder=1:Nold; + +if nargin>1 + tarorder=doTargetN; +end + +printMessage(2,'splitting...'); + +% for each target... +for i=tarorder + printMessage(2,'.'); + + % copy current configuration + te=targetsExist; + X=Xold; Y=Yold; + + % where in time does this target exist? + existframes=targetsExist(i,1):targetsExist(i,2); + fromframe=existframes(1); + toframe=existframes(end); + + % if length < 6 then no split possible + if length(existframes)>=6 + + N=1; % global N, needed for evaluation + X=X(:,i); Y=Y(:,i); + targetsExist=targetsExist(i,:); + + % what is the energy of this target? + stateInfo.N=N; stateInfo.targetsExist=targetsExist; + stateInfo=matricesToVector(X,Y,stateInfo); + x=stateInfo.stateVec; + origenergy=E(x,stateInfo); + + + minenergy=origenergy; + bestmove=0; + + + N=2; % global N, needed for evaluation + + % now check for all frames, where a split makes most sense + for ft=fromframe+3:toframe-2 % ft = new targets' start frame + + % shift part of first column of X,Y to the second + Xt=X; Yt=Y; + Xt(ft:toframe,2)=X(ft:toframe,1); + Yt(ft:toframe,2)=Y(ft:toframe,1); + Xt(ft:end,1)=0;Yt(ft:end,1)=0; + + + targetsExist(1,2)=ft-1; + targetsExist(2,1:2)=[ft toframe]; + + % what is the new energy? + stateInfo.targetsExist=targetsExist; + stateInfo=matricesToVector(Xt,Yt,stateInfo); + xt=stateInfo.stateVec; + newenergy=E(xt,stateInfo); % what is the new energy + + % if best, save + if newenergy +#include +#include + +#define HUGE 1000000 + +const short kInvalidIndex = -1; + +/*squared 2d norm (so in the end its just x^2+y^2, which is faster than also taking the squareroot and enough for comparisons)*/ +double norm2dSqr(double x, double y) { + return x * x + y * y; +} + +/*2d norm*/ +double norm2d(double x, double y) { + return sqrt(x * x + y * y); +} + +/*counts the amount of nonzero elements in a*/ +int countNonZero(int length, const double* const a) { + int i, nz; + nz = 0; + + for (i = 0; i < length; i++) { + if (a[i] != 0) { + nz++; + } + } + return nz; + +} + +/*finds all values in a != valueToIgnore and returns there indices in res*/ +void find(int length, const short * const a, int* const foundCount, short * const res, short valueToIgnore){ + int i; + *foundCount = 0; + + for (i = 0; i < length; i++) { + if (a[i] != valueToIgnore) { + res[(*foundCount)++] = i; + } + } +} + +/*finds all values in a != 0 and returns there indices in res*/ +void findD(int length, const double * const a, int* const foundCount, short * const res){ + int i; + *foundCount = 0; + + for (i = 0; i < length; i++) { + if (a[i] != 0) { + res[(*foundCount)++] = i; + } + } +} + +/*executes find(~M(t,:) & Xgt(t,:)); in c*/ +void findNotMbutXgt(double* const Xgt, short* const M, int Ngt, short* const GTsNotMapped, int* const GTsNotMappedCount){ + int i; + *GTsNotMappedCount = 0; + for(i = 0; i < Ngt; i++){ + if((M[i] == kInvalidIndex) && Xgt[i]) + GTsNotMapped[(*GTsNotMappedCount)++] = i; + } +} + +/*executes setdiff(find(X(t,:)),M(t,:)); in c (well the "(t," needs to be already factored into X/M)*/ +void setDiffFind(double* const X, int N, short* const M, int Ngt, short* const EsNotMapped, int* const EsNotMappedCount){ + int i; + char* temp = (char*) calloc(N, sizeof(char)); + *EsNotMappedCount = 0; + /*first get a boolean map of X, true == x at i was in M, otherwise false*/ + for(i = 0; i < Ngt; i++){ + if(M[i] != kInvalidIndex) + temp[M[i]] = true; + } + /*now we only need to check if there is a X[i] for a false temp[i] + well this isn't really correct because the matlab code would also find stuff that is in M but not in X, however I just assume that never happens :)*/ + *EsNotMappedCount = 0; + for(i = 0; i < N; i++){ + if(X[i] && !temp[i]){ + EsNotMapped[(*EsNotMappedCount)++] = i; + } + } + free(temp); +} + +double sum(short* a, int len){ + double sum = 0.0; + int i; + for ( i = 0; i < len; i++){ + sum += a[i]; + } + return sum; +} + +double sumD(double* a, int len){ + double sum = 0.0; + int i; + for ( i = 0; i < len; i++){ + sum += a[i]; + } + return sum; +} + +void setDiff(const short* const a, const int aLength, const short* const b, const int bLength, short* const out, int* const outLength){ + int i,j; + bool contains; + *outLength = 0; + for(i = 0; i < aLength; i++){ + contains = false; + for(j = 0; j < bLength; j++){ + if(a[i] == b[j]) { + contains = true; + break; + } + } + if(!contains) + out[(*outLength)++] = a[i]; + } +} + +/*intersect for two sorted lists*/ +void intersectSorted(const short* const a, const int aLength, const short* const b, const int bLength, short* const out, int* const outLength){ + int i,j; + i = j = 0; + *outLength = 0; + while(i < aLength){ + if(a[i] == b[j]) { + out[(*outLength)++] = a[i]; + /*only increase if we found it in b*/ + i++; + } + else { + /*only increase j if we couldn't find it at the current b*/ + j++; + } + } +} + +/*intersect for two lists */ +void intersect(const short* const a, const int aLength, const short* const b, const int bLength, short* const out, int* const outLength){ + int i,j; + *outLength = 0; + for(i = 0; i < aLength; i++){ + for(j = 0; j < bLength; j++){ + if(a[i] == b[j]) { + out[(*outLength)++] = a[i]; + break; + } + } + } +} + +/* +computes stuff +input: +0 Xgt +1 Ygt +2 X +3 Y +4 td + +output: +0 MOTA +1 MOTP +2 ma +3 fpa +4 mmea +5 idsw +6 missed +7 falsepositives +8 idswitches +9 alltracked +10 allfalsepos +11 MT +12 PT +13 ML +14 recall +15 precision +16 fafrm +17 FRA +18 MOTAL +19 alld +*/ +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { + + /* /Declarations */ + /* in vars*/ + const mxArray *XgtMtx, *YgtMtx, *XMtx, *YMtx, *tdata; + double *Xgt, *Ygt, *X, *Y, td; + int F, N, Fgt, Ngt; + + /* out vars*/ + double *MOTA, *MOTP, *ma, *fpa, *mmea, *idsw, *missed, *falsepositives, *idswitches, *alltracked, *allfalsepos, *MT, *PT, *ML, *recall, *precision, *fafrm, *FRA, *MOTAL, *alld; + + /* temp*/ + int i, t, foundCount, map, GTsNotMappedCount, EsNotMappedCount, j, lastNotEmpty; + int minDistIndexGT, minDistIndexE,trlengtha; + short *mme, *allCurTrackedCount; + int tNgtOffset, tMinus1NgtOffset, tNOffset, NgtCurMapOffset, NLastMapOffset, XFoundCount, gtOffset, allTrackersCount, mappedTrackersCount, curMFoundCount, tempCount, curTrackedCount, gtFramesCount; + short *g, *GTsNotMapped, *EsNotMapped, *curTracked, *M, *mappings, *XFound, *mappedTrackers, *curMFound, *temp, *fp, *m, *gtFrames; + short eid; + const short *allTrackers; + double mindist, dist, res; + double *alldist, *allTrackedDist; + + /*Copy input pointer x */ + XgtMtx = prhs[0]; + YgtMtx = prhs[1]; + XMtx = prhs[2]; + YMtx = prhs[3]; + tdata = prhs[4]; + + /*Get input matrices*/ + Xgt = mxGetPr(XgtMtx); + Ygt = mxGetPr(YgtMtx); + /*F and N are switched because we expect the matrices transposed*/ + Fgt = mxGetN(XgtMtx); + Ngt = mxGetM(XgtMtx); + + X = mxGetPr(XMtx); + Y = mxGetPr(YMtx); + F = mxGetN(XMtx); + N = mxGetM(XMtx); + + assert(F==Fgt); + + td = mxGetScalar(tdata); + + /*init scalar outputs (everything but alld, allfalsepos, alltracked)*/ + for(i = 0; i <= 8; i++) { + plhs[i] = mxCreateDoubleMatrix(1, 1, mxREAL); + } + for(i = 11; i <= 18; i++) { + plhs[i] = mxCreateDoubleMatrix(1, 1, mxREAL); + } + + /*init multi dim output*/ + plhs[9] = mxCreateDoubleMatrix(Ngt, F, mxREAL); + plhs[10] = mxCreateDoubleMatrix(N, F, mxREAL); + plhs[19] = mxCreateDoubleMatrix(Ngt, F, mxREAL); + + /*get output pointer*/ + MOTA = mxGetPr(plhs[0]); + MOTP = mxGetPr(plhs[1]); + ma = mxGetPr(plhs[2]); + fpa = mxGetPr(plhs[3]); + mmea = mxGetPr(plhs[4]); + idsw = mxGetPr(plhs[5]); + missed = mxGetPr(plhs[6]); + falsepositives = mxGetPr(plhs[7]); + idswitches = mxGetPr(plhs[8]); + alltracked = mxGetPr(plhs[9]); + allfalsepos = mxGetPr(plhs[10]); + MT = mxGetPr(plhs[11]); + PT = mxGetPr(plhs[12]); + ML = mxGetPr(plhs[13]); + recall = mxGetPr(plhs[14]); + precision = mxGetPr(plhs[15]); + fafrm = mxGetPr(plhs[16]); + FRA = mxGetPr(plhs[17]); + MOTAL = mxGetPr(plhs[18]); + alld = mxGetPr(plhs[19]); + + /*init temp vars*/ + M = (short*) malloc(sizeof(short) * F * Ngt); + mappings = (short*) malloc(sizeof(short) * Ngt); + g = (short*) malloc(sizeof(short) * F); + GTsNotMapped = (short*) malloc(sizeof(short) * Ngt); + EsNotMapped = (short*) malloc(sizeof(short) * Ngt); + XFound = (short*) malloc(sizeof(short) * N); + curMFound = (short*) malloc(sizeof(short) * N); + temp = (short*) malloc(sizeof(short) * N); + curTracked = (short*) malloc(sizeof(short) * Ngt); + mme = (short*) malloc(sizeof(int) * F); + alldist = (double*) malloc(sizeof(double) * Ngt * N); + allCurTrackedCount = (short*) malloc(sizeof(short) * F); + allTrackedDist = (double*) malloc(sizeof(double) *F * Ngt); + fp = (short*) malloc(sizeof(short) * F); + m = (short*) malloc(sizeof(short) * F); + gtFrames = (short*) malloc(sizeof(short) * F); + mappedTrackers = (short*) malloc(sizeof(short) * Ngt); + + /*init M to -1s (because 0s are people(aka indices) too)*/ + for(i = 0; i < F * Ngt; i++){ + M[i] = kInvalidIndex; + } + + for(i = 0; i < F * N; i++){ + allfalsepos[i] = 0; + } + + for(i = 0; i < F* Ngt; i++) { + allTrackedDist[i] = 0.0; + } + + /*now to the work part*/ + for(t = 0; t < F; t++){ + + /*how many gt targets are there? + also compute the offset for arrays of F*Ngt for the current t*/ + tNgtOffset = Ngt * t; + g[t] = countNonZero(Ngt, Xgt + tNgtOffset); + + /*some indices precomputation because we will need it later anyway*/ + tNOffset = N * t; + tMinus1NgtOffset = Ngt * (t - 1); + + if(t > 0){ + /*do some stuff + find all non 0 M values of the last iteration and store them in mappings*/ + find(Ngt, M + tMinus1NgtOffset, &foundCount, mappings, kInvalidIndex); + + /*now take the last mappings if they are close enough to the ground truth*/ + for(i = 0; i < foundCount; i++){ + map = mappings[i]; + + /*get offsets for the current time plus the current map and + the current timestep plus the last M*/ + NgtCurMapOffset = tNgtOffset + map; + NLastMapOffset = tNOffset + M[tMinus1NgtOffset + map]; + + /*if both X[bla] and Xgt[bla] are nonZero + and they are close enough to each other, set the old map as the new one*/ + if( Xgt[NgtCurMapOffset] + && X[NLastMapOffset] + && norm2dSqr(Xgt[NgtCurMapOffset] - X[NLastMapOffset], + Ygt[NgtCurMapOffset] - Y[NLastMapOffset]) <= td*td) { + M[NgtCurMapOffset] = M[tMinus1NgtOffset + map]; + } + } + } + + /*setup alldist to infinity(== HUGE_VAL)*/ + for(i = 0; i < Ngt * N; i++){ + alldist[i] = HUGE_VAL; + } + + /*find all gt for which there is no entry in M*/ + findNotMbutXgt(Xgt + tNgtOffset, M + tNgtOffset, Ngt, GTsNotMapped, >sNotMappedCount); + + /*find all X != 0 (TODO: change setdifffind so it uses this result)*/ + findD(N, X + tNOffset, &XFoundCount, XFound); + + /*find all x for which there is no entry in M*/ + setDiffFind(X + tNOffset, N, M + tNgtOffset, Ngt, EsNotMapped, &EsNotMappedCount); + + mindist = 0; + minDistIndexGT = kInvalidIndex; + minDistIndexE = kInvalidIndex; + + /*compute distances*/ + while (mindist < td && GTsNotMappedCount > 0 && EsNotMappedCount > 0) { + /*compute distances for all not yet mapped GTs and Es and also find the closest x and gt*/ + mindist = HUGE; + for (i = 0; i < GTsNotMappedCount; i++){ /*Ngt + gtOffset = i * N; + for(j = 0; j < EsNotMappedCount; j++){ /*N + dist = norm2dSqr(Xgt[tNgtOffset + GTsNotMapped[i]] - X[tNOffset + EsNotMapped[j]], + Ygt[tNgtOffset +GTsNotMapped[i]] - Y[tNOffset + EsNotMapped[j]]); + alldist[gtOffset + j] = dist; + if(dist < mindist){ + mindist = dist; + minDistIndexE = j; + minDistIndexGT = i; + } + } + } + + if (mindist <= td*td){ + /*add the mapping to M*/ + M[tNgtOffset + GTsNotMapped[minDistIndexGT]] = EsNotMapped[minDistIndexE]; + /*set all distances for the current gt to Inf*/ + gtOffset = minDistIndexGT * N; + for(i = 0; i < EsNotMappedCount; i++){ + alldist[gtOffset + i] = HUGE; + } + /*remove the mapped gt and e from the notMapped arrays (should be changed later for now this is the simplest impl.)*/ + findNotMbutXgt(Xgt + tNgtOffset, M + tNgtOffset, Ngt, GTsNotMapped, >sNotMappedCount); + setDiffFind(X + tNOffset, N, M + tNgtOffset, Ngt, EsNotMapped, &EsNotMappedCount); + } + } + + find(Ngt, M + tNgtOffset, &curTrackedCount, curTracked, kInvalidIndex); + + /*since alltrackers == Xfound we can just write it as follows*/ + allTrackers = XFound; + allTrackersCount = XFoundCount; + + /*find mapped trackers + TODO: replace find by assigning to curMfound already above, however for now this is good enough + find currently assigned Xgts*/ + find(Ngt, M + tNgtOffset, &curMFoundCount, curMFound, kInvalidIndex); + /*change each Xgt position to its respective value*/ + for(i = 0; i < curMFoundCount; i++){ + curMFound[i] = M[tNgtOffset + curMFound[i]]; + } + intersect(curMFound, curMFoundCount, allTrackers, allTrackersCount, mappedTrackers, &mappedTrackersCount); + + /*find falsepositives*/ + setDiff(allTrackers, allTrackersCount, mappedTrackers, mappedTrackersCount, temp, &tempCount); + /*convert them to double and store them in allfalsepos*/ + for(i = 0; i < tempCount; i++){ + /*temp+1 because -1 == invalid index in c however 0 == invalid index in matlab*/ + allfalsepos[tNOffset + i] = (double)(temp[i] + 1); + } + + /*compute mismatch errors*/ + mme[t] = 0; + if (t > 1){ + for(i = 0; i < curTrackedCount; i++){ + /*find last not empty ct*/ + lastNotEmpty = kInvalidIndex; + j = t; + while(j --> 0){ + if(M[j * Ngt + curTracked[i]] != kInvalidIndex) { + lastNotEmpty = j; + break; + } + } + + /*if we don't match increase mismatch*/ + if(Xgt[tMinus1NgtOffset + curTracked[i]] != 0 + && lastNotEmpty != kInvalidIndex + && M[tNgtOffset + curTracked[i]] != M[lastNotEmpty * Ngt + curTracked[i]]){ + mme[t] += 1; + } + } + } + + allCurTrackedCount[t] = curTrackedCount; + + /*compute distances for all currently tracked Xs*/ + for(i = 0; i < curTrackedCount; i++){ + eid = M[tNgtOffset + curTracked[i]]; + allTrackedDist[tNgtOffset + i] = norm2d( + Xgt[tNgtOffset + curTracked[i]] - X[tNOffset + eid], + Ygt[tNgtOffset + curTracked[i]] - Y[tNOffset + eid]); + } + + fp[t] = XFoundCount - curTrackedCount; + + m[t] = g[t] - curTrackedCount; + } + + /*copy alltrackedDist to alld*/ + for(i = 0; i < F * Ngt; i++){ + alld[i] = allTrackedDist[i]; + } + + /*copy M to alltracked*/ + for(i = 0; i < F * Ngt; i++){ + alltracked[i] = M[i] + 1; + } + + *missed = sum(m, F); + *falsepositives = sum(fp, F); + *idswitches = sum(mme, F); + + /*compute average ditance to [0,1]*/ + *MOTP = 1 - sumD(allTrackedDist, F * Ngt) / sum(allCurTrackedCount, F) / td; + + *MOTAL = 1 - ( ( *missed + *falsepositives + log10(*idswitches + 1) ) / sum(g, F) ); + *MOTA = 1 - ( ( *missed + *falsepositives + *idswitches ) / sum(g, F) ); + *ma = *missed / sum(g, F); + *fpa = *falsepositives / sum(g, F); + *mmea = *idswitches / sum(g, F); + *idsw = *idswitches / Ngt / Fgt; + + res = sum(allCurTrackedCount, F); + *recall = sum(allCurTrackedCount, F) / sum(g, F); + *precision = sum(allCurTrackedCount, F) / (*falsepositives + sum(allCurTrackedCount, F)); + *fafrm = *falsepositives / Fgt; + + /* MT PT ML*/ + *MT = *PT = *ML = 0; + for(i = 0; i < Ngt; i++){ + gtFramesCount = 0; + /*first get a bitmask of values in the column*/ + for(j = 0; j < F; j++) { + gtFrames[j] = Xgt[j * Ngt + i] != 0; + } + /*Nowget their indices*/ + find(F, gtFrames, >FramesCount, gtFrames, 0); + + trlengtha = 0; + for(j = 0; j < gtFramesCount; j++){ + if(alltracked[gtFrames[j] * Ngt + i] > 0) + trlengtha += 1; + } + + res = trlengtha/(double)gtFramesCount; + if(res < 0.2){ + (*ML)++; + } + else if( t >= gtFrames[gtFramesCount - 1] && res <= 0.8){ + (*PT)++; + } + else if(res >= 0.8){ + (*MT)++; + } + } + + /*count fragments*/ + FRA = 0; + for(i = 0; i < Ngt; i++){ + + FRA += 0; + } + + /*free temp variables*/ + free(mappedTrackers); + free(gtFrames); + free(m); + free(fp); + free(allCurTrackedCount); + free(allTrackedDist); + free(alldist); + free(mme); + free(curTracked); + free(temp); + free(curMFound); + free(XFound); + free(EsNotMapped); + free(GTsNotMapped); + free(g); + free(mappings); + free(M); +} \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Edet_mex.c b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Edet_mex.c new file mode 100644 index 0000000000000000000000000000000000000000..ebafc70efa5ea32d77f961a7befc82345c023644 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Edet_mex.c @@ -0,0 +1,239 @@ +/* (C) Anton Andriyenko, 2012 */ +#include "mex.h" + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { + + + /* /Declarations */ + const mxArray *Xmtx, *Ymtx, *Xdmtx, *Ydmtx, *Sdmtx, *gridStepdata, *lambdadata, *tEdata, *xldata, *poccdata; + + double *X, *Y, *Xd, *Yd, *Sd, *occ, *tvis, *occx, *occy, *ddvix, *ddviy, *targetsExist, gridStep, lambda, pocc; + + + int i,j,t; + int F,N,Ndet,Fdet,FN; + + double *f; + double *df; + + double d, ddfx, ddfy; + + double csig; + int ind, indj, dfxind, xl, icnt, jcnt; + int dims[3]; + + double xdet, ydet, sdet, xxd, yyd, xxdsq, yydsq; + double xxyycsig, xxyycsigsq; + double xpos, ypos; + double gg; + + /* //Copy input pointer x */ + Xmtx = prhs[0]; + Ymtx = prhs[1]; + Xdmtx = prhs[2]; + Ydmtx = prhs[3]; + Sdmtx = prhs[4]; + gridStepdata = prhs[5]; + lambdadata = prhs[6]; + tEdata = prhs[7]; + xldata = prhs[8]; + poccdata = prhs[9]; + + /* //Get matrix x */ + X = mxGetPr(Xmtx); + Y = mxGetPr(Ymtx); + Xd = mxGetPr(Xdmtx); + Yd = mxGetPr(Ydmtx); + Sd = mxGetPr(Sdmtx); + targetsExist = mxGetPr(tEdata); + N = mxGetN(Xmtx); + F = mxGetM(Xmtx); + FN=F*N; + Ndet = mxGetN(Xdmtx); + Fdet = mxGetM(Xdmtx); + + gridStep = (double)(mxGetScalar(gridStepdata)); + lambda = (double)(mxGetScalar(lambdadata)); + xl = (int)(mxGetScalar(xldata)); + pocc = (int)(mxGetScalar(poccdata)); + + + + dims[0]=F;dims[1]=N;dims[2]=N; + + /* // Allocate memory and assign output pointer */ + plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); + plhs[1] = mxCreateDoubleMatrix(xl, 1, mxREAL); + + /* +// // plhs[2] = mxCreateDoubleMatrix(F, N, mxREAL); +// plhs[3] = mxCreateDoubleMatrix(F, N, mxREAL); +// plhs[4] = mxCreateDoubleMatrix(F, N, mxREAL); +// plhs[5] = mxCreateNumericArray(3, dims,mxDOUBLE_CLASS, mxREAL); +// plhs[6] = mxCreateNumericArray(3, dims,mxDOUBLE_CLASS, mxREAL); +// */ + + + /* + //Get a pointer to the data space in our newly allocated memory + */ + f = mxGetPr(plhs[0]); + df = mxGetPr(plhs[1]); + +/* occ=mxGetPr(plhs[2]); + occx=mxGetPr(plhs[3]); + occy=mxGetPr(plhs[4]); + ddvix=mxGetPr(plhs[5]); + ddviy=mxGetPr(plhs[6]); */ + *f=0; + for (i=0; i1) { + xxyycsig = xxdsq + yydsq + csig; + xxyycsigsq = xxyycsig * xxyycsig; + + df[dfxind] -= 2*csig*sdet * xxd / xxyycsigsq; + df[dfxind+1] -= 2*csig*sdet * yyd / xxyycsigsq; + } + + + } + } + + *f+=(d+gg); + + df[dfxind]+=ddfx; + df[dfxind+1]+=ddfy; + dfxind+=2; + + } + } + + + +} \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Edyn_mex.c b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Edyn_mex.c new file mode 100644 index 0000000000000000000000000000000000000000..6a71cbce59a95544428a210abacee2f3a2aa63a0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Edyn_mex.c @@ -0,0 +1,97 @@ +/* (C) Anton Andriyenko, 2012 */ + +#include "mex.h" + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { + + + /* Declarations */ + const mxArray *Xmtx, *Ymtx, *targetSizedata, *tEdata, *xldata; + + double *X, *Y, targetSize, *targetsExist, xl; + + int i,t; + int F,N; + + double *fx; + double *df; + + int ind, indp, indn, xind, yind; + + /* //Copy input pointer x */ + Xmtx = prhs[0]; + Ymtx = prhs[1]; + targetSizedata = prhs[2]; + tEdata = prhs[3]; + xldata = prhs[4]; + + /* //Get matrix x */ + X = mxGetPr(Xmtx); + Y = mxGetPr(Ymtx); + N = mxGetN(Xmtx); + F = mxGetM(Xmtx); + + targetSize = (double)(mxGetScalar(targetSizedata)); + targetsExist = mxGetPr(tEdata); + xl = (int)(mxGetScalar(xldata)); + + + /* // Allocate memory and assign output pointer */ + plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); + plhs[1] = mxCreateDoubleMatrix(xl, 1, mxREAL); + + /* //Get a pointer to the data space in our newly allocated memory */ + fx = mxGetPr(plhs[0]); + df = mxGetPr(plhs[1]); + + xind=0; yind=0; + + /* for each target */ + for (i = 0; i < N; i++) + { + + int from = (int) targetsExist[i]; + int to = (int) targetsExist[i+N]; + int tlength=to-from+1; + xind += 2; + yind = xind+1; + + for (t = from; t < to-1; t++) + { + double a,b,c,d,e,f; + double diff; + indp=(i*F)+t-1; + ind=(i*F)+t; + indn=(i*F)+t+1; + a = X[indp]; b = Y[indp]; + c = X[ind]; d = Y[ind]; + e = X[indn]; f = Y[indn]; + + diff = a*a + a*(2*e - 4*c) + b*b + b*(2*f - 4*d) + 4*c*c - 4*c*e + 4*d*d - 4*d*f + e*e + f*f; + *fx += diff; + + if (nlhs>1) + { + df[xind-2] += (2*a-4*c+2*e); + df[yind-2] += (2*b-4*d+2*f); + df[xind] += (-4*a+8*c-4*e); + df[yind] += (-4*b+8*d-4*f); + df[xind+2] += (2*a-4*c+2*e); + df[yind+2] += (2*b-4*d+2*f); + } + + xind += 2; + yind = xind+1; + } + if (tlength>1) { + xind += 2; + } + } + + /* normalize with target Size */ + *fx = *fx / targetSize; + for (i = 0; i < xl; ++i) + { + df[i] = df[i] / targetSize; + } +} \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Eexc_mex.c b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Eexc_mex.c new file mode 100644 index 0000000000000000000000000000000000000000..3f342aa2071e1121af98e1a467d469c7b7c9c226 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Eexc_mex.c @@ -0,0 +1,102 @@ +/* (C) Anton Andriyenko, 2012 */ + +#include "mex.h" + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { + + + /* /Declarations */ + const mxArray *Xmtx, *Ymtx, *gridStepdata, *itToInddata, *xldata; + + double *X, *Y, gridStep; + double *itToInd; + + int i,j,t, xl; + int F,N; + int F1,N1; + + double *f; + double *df; + + double gs_squared; + int ind, indj, xind, yind; + + /* //Copy input pointer x */ + Xmtx = prhs[0]; + Ymtx = prhs[1]; + gridStepdata = prhs[2]; + itToInddata = prhs[3]; + xldata = prhs[4]; + + /* //Get matrix x */ + X = mxGetPr(Xmtx); + Y = mxGetPr(Ymtx); + N = mxGetN(Xmtx); + F = mxGetM(Xmtx); + N1 = mxGetN(itToInddata); + F1 = mxGetM(itToInddata); + + gridStep = (double)(mxGetScalar(gridStepdata)); + itToInd = mxGetPr(itToInddata); + xl = (int)(mxGetScalar(xldata)); + + /* Allocate memory and assign output pointer */ + plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); + plhs[1] = mxCreateDoubleMatrix(xl, 1, mxREAL); + + /* Get a pointer to the data space in our newly allocated memory */ + f = mxGetPr(plhs[0]); + df = mxGetPr(plhs[1]); + + + gs_squared=gridStep*gridStep; + xind=0; + yind=0; + + + +/* for each frame */ +for(t=0;t1) { + + denom *= denom; + tmp = gs_squared / denom; + dda = -(2*a-2*c)*tmp; + ddb = -(2*b-2*d)*tmp; + + xind=(int)itToInd[ind]-1; + df[xind] += dda + dda; + df[xind+1] += ddb + ddb; + + } + + + } + } + } + } +} +} \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Eper_mex.c b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Eper_mex.c new file mode 100644 index 0000000000000000000000000000000000000000..8d8c9568aee0914766171e8fef795c1fd996e672 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/Eper_mex.c @@ -0,0 +1,146 @@ +/* (C) Anton Andriyenko, 2012 */ + +#include "mex.h" +#include + +/* // WRONG GRADIENT !!! if (ci==1 || ci==3) { si*=-1;}*/ +void min_distances(const double *areaLimits, double x, double y, double* dm, double* ci, int* si) +{ + const double dl = fabs(areaLimits[0] - x); + const double dr = fabs(areaLimits[1] - x); + const double du = fabs(areaLimits[2] - y); + const double dd = fabs(areaLimits[3] - y); + + double dm1 = (dl < dr) ? dl : dr; + double dm2 = (du < dd) ? du : dd; + double ci1 = (dl < dr) ? 0 : 1; + double ci2 = (du < dd) ? 2 : 3; + + *dm = (dm1 < dm2) ? dm1 : dm2; + *ci = (dm1 < dm2) ? ci1 : ci2; + + *si=1; + if (xareaLimits[1] || yareaLimits[3]) { + *si=-1; + } + +} + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { + + + /* /Declarations */ + const mxArray *Xmtx, *Ymtx, *areaLimitsdata, *gridStepdata, *tEdata, *xldata; + + double *X, *Y, *areaLimits, gridStep, *targetsExist, xl; + + int i,t; + int F,N; + + double *fx; + double *dfx; + double scale; + + int st, en, xind, yind, ind; + + /* //Copy input pointer x */ + Xmtx = prhs[0]; + Ymtx = prhs[1]; + areaLimitsdata = prhs[2]; + gridStepdata = prhs[3]; + tEdata = prhs[4]; + xldata = prhs[5]; + + /* //Get matrix x */ + X = mxGetPr(Xmtx); + Y = mxGetPr(Ymtx); + N = mxGetN(Xmtx); + F = mxGetM(Xmtx); + + areaLimits = mxGetPr(areaLimitsdata); + gridStep = (double)(mxGetScalar(gridStepdata)); + targetsExist = mxGetPr(tEdata); + xl = (int)(mxGetScalar(xldata)); + + + /* Allocate memory and assign output pointer */ + plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); + plhs[1] = mxCreateDoubleMatrix(xl, 1, mxREAL); + + /* Get a pointer to the data space in our newly allocated memory */ + fx = mxGetPr(plhs[0]); + dfx = mxGetPr(plhs[1]); + *fx = 0; + scale = 1.0 / gridStep; + + xind=0; + yind=0; + +/* for each target */ + for (i = 0; i < N; i++) + { + int st = (int) targetsExist[i]-1; + int en = (int) targetsExist[i+N]-1; + + if (st > 0) + { + double xp,yp,dm,ci; + double d,tmp,val; + int si; + ind=(i*F)+st; + xp = X[ind]; + yp = Y[ind]; + dm = 0; + ci = 0; + si = 1; + min_distances(areaLimits, xp, yp, &dm, &ci, &si); + if (ci==1 || ci==3) { si*=-1;} + d = 1.0 / (1 + exp(1 - scale*dm)); + *fx = *fx + d; + tmp = exp(1 - scale * dm) + 1; + tmp *= tmp; + val = si*scale * exp(1 - scale * dm) / tmp; + + if (ci < 2) + { + dfx[xind] = val; + } + else + { + dfx[xind+1] = val; + } + } + xind+=(en-st)*2; + + if (en < F-1) + { + double xp,yp,dm,ci; + double d,tmp,val; + int si; + + ind=(i*F)+en; + xp = X[ind]; + yp = Y[ind]; + dm = 0; + ci = 0; + si = 1; + min_distances(areaLimits, xp, yp, &dm, &ci,&si); + if (ci==1 || ci==3) { si*=-1;} + d = 1.0 / (1 + exp(1 - scale*dm)); + *fx = *fx + d; + tmp = exp(1 - scale * dm) + 1; + tmp *= tmp; + val = si*scale * exp(1 - scale * dm) / tmp; + if (ci < 2) + { + dfx[xind] = val; + } + else + { + dfx[xind+1] = val; + } + } + xind += 2; + } + +} \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/computeOcclusions2new_mex.c b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/computeOcclusions2new_mex.c new file mode 100644 index 0000000000000000000000000000000000000000..eb7eaba0f00b5d936cee6121a48e21e152dc13c2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/mex/src/computeOcclusions2new_mex.c @@ -0,0 +1,725 @@ +/* (C) Anton Andriyenko, 2012 + + The code may be used free of charge for non-commercial and + educational purposes, the only requirement is that this text is + preserved within the derivative work. For any other purpose you + must contact the authors for permission. This code may not be + redistributed without written permission from the authors. +*/ + +#include "mex.h" +#include + +void dfnddALL(double *prhs, double *plhs) { + + + /* /Declarations */ + const mxArray *Dpxdata, *Dpydata, *Sxdata, *Xwadata, *Xwbdata, *Ywadata, *Ywbdata, *Zwadata, *Zwbdata, *focaldata, \ + *mR11data, *mR12data, *mR13data, *mR21data, *mR22data, *mR23data, *mR31data, *mR32data, *mR33data, \ + *txdata, *tydata, *tzdata, *txidata, *tyidata, *tzidata; + + + double Dpx, Dpy, Sx, Xwa, Xwb, Ywa, Ywb, Zwa, Zwb, focal, \ + mR11, mR12, mR13, mR21, mR22, mR23, mR31, mR32, mR33, \ + tx, ty, tz, txi, tyi, tzi; + + double Xa, Ya, Xb, Yb; + +double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10,\ + t11, t12, t13, t14, t15, t16, t17, t18, t19, t20,\ + t21, t22, t23, t24, t25, t26, t27, t28, t29, t30,\ + t31, t32, t33, t34, t35, t36, t37, t38, t39, t40,\ + t41, t42, t43, t44, t45, t46, t47, t48, t49, t50,\ + t51, t52, t53, t54, t55, t56, t57, t58, t59, t60,\ + t61, t62, t63, t64, t65, t66, t67, t68, t69, t70,\ + t71, t72, t73, t74, t75, t76, t77, t78, t79, t80,\ + t81, t82, t83, t84, t85, t86, t87, t88, t89, t90,\ + t91, t92, t93, t94, t95, t96, t97, t98, t99, t100,\ + t101, t102, t103, t104, t105, t106, t107, t108, t109, t110,\ + t111, t112, t113, t114, t115, t116, t117, t118, t119, t120,\ + t121, t122, t123, t124, t125, t126, t127, t128, t129, t130,\ + t131, t132, t133, t134, t135, t136, t137, t138, t139, t140,\ + t141, t142, t143, t144, t145, t146, t147, t148, t149, t150,\ + t151, t152, t153, t154, t155, t156, t157, t158, t159, t160,\ + t161, t162, t163, t164, t165, t166, t167, t168, t169, t170,\ + t171, t172, t173, t174, t175, t176, t177, t178, t179, t180,\ + t181; + + /* //Copy input pointer x */ + Dpx= prhs[0]; + Dpy= prhs[1]; + Sx= prhs[2]; + Xwa= prhs[3]; + Xwb= prhs[4]; + Ywa= prhs[5]; + Ywb= prhs[6]; + Zwa= prhs[7]; + Zwb= prhs[8]; + focal= prhs[9]; + mR11= prhs[10]; + mR12= prhs[11]; + mR13= prhs[12]; + mR21= prhs[13]; + mR22= prhs[14]; + mR23= prhs[15]; + mR31= prhs[16]; + mR32= prhs[17]; + mR33= prhs[18]; + tx= prhs[19]; + ty= prhs[20]; + tz= prhs[21]; + txi = prhs[22]; + tyi = prhs[23]; + tzi = prhs[24]; + + + + +t2 = 1/Dpx; +t15 = Xwa*mR31; +t16 = Ywa*mR32; +t17 = Zwa*mR33; +t18 = t15+t16+t17+tz; +t19 = 1/t18; +t21 = Xwb*mR31; +t22 = Ywb*mR32; +t23 = Zwb*mR33; +t24 = t21+t22+t23+tz; +t25 = 1/t24; +t83 = Xwa*mR11; +t84 = Ywa*mR12; +t85 = Zwa*mR13; +t86 = t83+t84+t85+tx; +t87 = Sx*focal*t19*t2*t86; +t88 = Xwb*mR11; +t89 = Ywb*mR12; +t90 = Zwb*mR13; +t91 = t88+t89+t90+tx; +t92 = Sx*focal*t2*t25*t91; +t3 = t87-t92; +t4 = pow(focal,2); +t5 = pow(txi,2); +t6 = pow(Dpy,2); +t7 = pow(tyi,2); +t8 = pow(tzi,2); +t9 = pow(Xwa,2); +t10 = pow(Xwb,2); +t11 = pow(Ywb,2); +t12 = pow(Ywa,2); +t13 = pow(Zwb,2); +t14 = pow(Zwa,2); +t20 = 1/Dpy; +t73 = Xwa*mR21; +t74 = Ywa*mR22; +t75 = Zwa*mR23; +t76 = t73+t74+t75+ty; +t77 = focal*t19*t20*t76; +t78 = Xwb*mR21; +t79 = Ywb*mR22; +t80 = Zwb*mR23; +t81 = t78+t79+t80+ty; +t82 = focal*t20*t25*t81; +t26 = t77-t82; +t27 = pow(t5,2); +t28 = t27*t6; +t29 = pow(t7,2); +t30 = t29*t6; +t31 = pow(t8,2); +t32 = t31*t6; +t33 = t10*t6*t9; +t34 = t11*t6*t9; +t35 = t10*t12*t6; +t36 = t13*t6*t9; +t37 = t10*t14*t6; +t38 = t11*t12*t6; +t39 = t12*t13*t6; +t40 = t11*t14*t6; +t41 = t13*t14*t6; +t42 = t5*t6*t9; +t43 = t10*t5*t6; +t44 = t6*t7*t9; +t45 = t10*t6*t7; +t46 = t6*t8*t9; +t47 = t10*t6*t8; +t48 = t12*t5*t6; +t49 = t11*t5*t6; +t50 = t12*t6*t7; +t51 = t11*t6*t7; +t52 = t12*t6*t8; +t53 = t11*t6*t8; +t54 = t14*t5*t6; +t55 = t13*t5*t6; +t56 = t14*t6*t7; +t57 = t13*t6*t7; +t58 = t14*t6*t8; +t59 = t13*t6*t8; +t60 = t5*t6*t7*2.0; +t61 = t5*t6*t8*2.0; +t62 = t6*t7*t8*2.0; +t63 = Xwa*Xwb*t5*t6*4.0; +t64 = Ywa*Ywb*t6*t7*4.0; +t65 = Zwa*Zwb*t6*t8*4.0; +t66 = Xwa*Ywb*t6*txi*tyi*4.0; +t67 = Xwb*Ywa*t6*txi*tyi*4.0; +t68 = Xwa*Zwb*t6*txi*tzi*4.0; +t69 = Xwb*Zwa*t6*txi*tzi*4.0; +t70 = Ywa*Zwb*t6*tyi*tzi*4.0; +t71 = Ywb*Zwa*t6*tyi*tzi*4.0; +t133 = Xwa*t5*t6*txi*2.0; +t134 = Xwb*t5*t6*txi*2.0; +t135 = Ywa*t6*t7*tyi*2.0; +t136 = Ywb*t6*t7*tyi*2.0; +t137 = Zwa*t6*t8*tzi*2.0; +t138 = Zwb*t6*t8*tzi*2.0; +t139 = Xwa*t10*t6*txi*2.0; +t140 = Xwb*t6*t9*txi*2.0; +t141 = Xwa*t11*t6*txi*2.0; +t142 = Xwb*t12*t6*txi*2.0; +t143 = Ywb*t6*t9*tyi*2.0; +t144 = Ywa*t10*t6*tyi*2.0; +t145 = Xwa*t13*t6*txi*2.0; +t146 = Xwb*t14*t6*txi*2.0; +t147 = Ywa*t11*t6*tyi*2.0; +t148 = Ywb*t12*t6*tyi*2.0; +t149 = Zwb*t6*t9*tzi*2.0; +t150 = Zwa*t10*t6*tzi*2.0; +t151 = Ywa*t13*t6*tyi*2.0; +t152 = Ywb*t14*t6*tyi*2.0; +t153 = Zwb*t12*t6*tzi*2.0; +t154 = Zwa*t11*t6*tzi*2.0; +t155 = Zwa*t13*t6*tzi*2.0; +t156 = Zwb*t14*t6*tzi*2.0; +t157 = Xwa*t6*t7*txi*2.0; +t158 = Xwb*t6*t7*txi*2.0; +t159 = Xwa*t6*t8*txi*2.0; +t160 = Xwb*t6*t8*txi*2.0; +t161 = Ywa*t5*t6*tyi*2.0; +t162 = Ywb*t5*t6*tyi*2.0; +t163 = Ywa*t6*t8*tyi*2.0; +t164 = Ywb*t6*t8*tyi*2.0; +t165 = Zwa*t5*t6*tzi*2.0; +t166 = Zwb*t5*t6*tzi*2.0; +t167 = Zwa*t6*t7*tzi*2.0; +t168 = Zwb*t6*t7*tzi*2.0; +t72 = -t133-t134-t135-t136-t137-t138-t139-t140-t141-t142-t143-t144-t145-t146-t147-t148-t149-t150-t151-t152-t153-t154-t155-t156-t157-t158-t159-t160-t161-t162-t163-t164-t165-t166-t167-t168+t28+t30+t32+t33+t34+t35+t36+t37+t38+t39+t40+t41+t42+t43+t44+t45+t46+t47+t48+t49+t50+t51+t52+t53+t54+t55+t56+t57+t58+t59+t60+t61+t62+t63+t64+t65+t66+t67+t68+t69+t70+t71; +t93 = pow(t3,2); +t94 = t4*t9*2.025e5; +t95 = t10*t4*2.025e5; +t96 = t12*t4*2.025e5; +t97 = t11*t4*2.025e5; +t98 = t14*t4*2.025e5; +t99 = t13*t4*2.025e5; +t100 = t4*t5*4.05e5; +t101 = t4*t7*4.05e5; +t102 = t4*t8*4.05e5; +t127 = Xwa*t4*txi*4.05e5; +t128 = Xwb*t4*txi*4.05e5; +t129 = Ywa*t4*tyi*4.05e5; +t130 = Ywb*t4*tyi*4.05e5; +t131 = Zwa*t4*tzi*4.05e5; +t132 = Zwb*t4*tzi*4.05e5; +t103 = t100+t101+t102-t127-t128-t129-t130-t131-t132+t94+t95+t96+t97+t98+t99; +t104 = 1/t103; +t105 = pow(t26,2); +t106 = t4*t9*8.1e5; +t107 = t10*t4*8.1e5; +t108 = t12*t4*8.1e5; +t109 = t11*t4*8.1e5; +t110 = t14*t4*8.1e5; +t111 = t13*t4*8.1e5; +t112 = t4*t5*1.62e6; +t113 = t4*t7*1.62e6; +t114 = t4*t8*1.62e6; +t170 = Xwa*t4*txi*1.62e6; +t171 = Xwb*t4*txi*1.62e6; +t172 = Ywa*t4*tyi*1.62e6; +t173 = Ywb*t4*tyi*1.62e6; +t174 = Zwa*t4*tzi*1.62e6; +t175 = Zwb*t4*tzi*1.62e6; +t115 = t106+t107+t108+t109+t110+t111+t112+t113+t114-t170-t171-t172-t173-t174-t175; +t116 = 1/t115; +/* */ +/* Xa */ +t117 = Xwa*t10*t6*2.0; +t118 = Xwa*t11*t6*2.0; +t119 = Xwa*t13*t6*2.0; +t120 = Xwa*t5*t6*2.0; +t121 = Xwb*t5*t6*4.0; +t122 = Xwa*t6*t7*2.0; +t123 = Xwa*t6*t8*2.0; +t124 = Ywb*t6*txi*tyi*4.0; +t125 = Zwb*t6*txi*tzi*4.0; +t126 = t117+t118+t119+t120+t121+t122+t123+t124+t125-t10*t6*txi*2.0-t11*t6*txi*2.0-t13*t6*txi*2.0-t5*t6*txi*2.0-t6*t7*txi*2.0-t6*t8*txi*2.0-Xwa*Xwb*t6*txi*4.0-Xwa*Ywb*t6*tyi*4.0-Xwa*Zwb*t6*tzi*4.0; +t169 = 1/pow(t18,2); +t176 = exp(t26); +t177 = t105*t116*t72*(-1.0/2.0)-t104*t72*t93*(1.0/2.0); +t178 = exp(t177); +t179 = focal*mR21*t19*t20; +t180 = t179-focal*mR31*t169*t20*t76; +t181 = t176+1.0; +Xa = -(t178*(t105*t116*t126*(1.0/2.0)+t104*t126*t93*(1.0/2.0)+t116*t180*t26*t72+t104*t3*t72*(Sx*focal*mR11*t19*t2-Sx*focal*mR31*t169*t2*t86)-1/pow(t103,2)*t72*t93*(Xwa*t4*4.05e5-t4*txi*4.05e5)*(1.0/2.0)-t105*1/pow(t115,2)*t72*(Xwa*t4*1.62e6-t4*txi*1.62e6)*(1.0/2.0)))/t181-t176*t178*t180*1/pow(t181,2); + +/* Ya */ +t117 = Ywa*t10*t6*2.0; +t118 = Ywa*t11*t6*2.0; +t119 = Ywa*t13*t6*2.0; +t120 = Ywa*t5*t6*2.0; +t121 = Ywa*t6*t7*2.0; +t122 = Ywb*t6*t7*4.0; +t123 = Ywa*t6*t8*2.0; +t124 = Xwb*t6*txi*tyi*4.0; +t125 = Zwb*t6*tyi*tzi*4.0; +t126 = t117+t118+t119+t120+t121+t122+t123+t124+t125-t10*t6*tyi*2.0-t11*t6*tyi*2.0-t13*t6*tyi*2.0-t5*t6*tyi*2.0-t6*t7*tyi*2.0-t6*t8*tyi*2.0-Xwb*Ywa*t6*txi*4.0-Ywa*Ywb*t6*tyi*4.0-Ywa*Zwb*t6*tzi*4.0; +t169 = 1/pow(t18,2); +t176 = exp(t26); +t177 = t105*t116*t72*(-1.0/2.0)-t104*t72*t93*(1.0/2.0); +t178 = exp(t177); +t179 = focal*mR22*t19*t20; +t180 = t179-focal*mR32*t169*t20*t76; +t181 = t176+1.0; +Ya = -(t178*(t105*t116*t126*(1.0/2.0)+t104*t126*t93*(1.0/2.0)+t116*t180*t26*t72+t104*t3*t72*(Sx*focal*mR12*t19*t2-Sx*focal*mR32*t169*t2*t86)-1/pow(t103,2)*t72*t93*(Ywa*t4*4.05e5-t4*tyi*4.05e5)*(1.0/2.0)-t105*1/pow(t115,2)*t72*(Ywa*t4*1.62e6-t4*tyi*1.62e6)*(1.0/2.0)))/t181-t176*t178*t180*1/pow(t181,2); + +/* Xb */ +t117 = Xwb*t6*t9*2.0; +t118 = Xwb*t12*t6*2.0; +t119 = Xwb*t14*t6*2.0; +t120 = Xwa*t5*t6*4.0; +t121 = Xwb*t5*t6*2.0; +t122 = Xwb*t6*t7*2.0; +t123 = Xwb*t6*t8*2.0; +t124 = Ywa*t6*txi*tyi*4.0; +t125 = Zwa*t6*txi*tzi*4.0; +t126 = t117+t118+t119+t120+t121+t122+t123+t124+t125-t12*t6*txi*2.0-t14*t6*txi*2.0-t5*t6*txi*2.0-t6*t7*txi*2.0-t6*t8*txi*2.0-t6*t9*txi*2.0-Xwa*Xwb*t6*txi*4.0-Xwb*Ywa*t6*tyi*4.0-Xwb*Zwa*t6*tzi*4.0; +t169 = 1/pow(t24,2); +t176 = exp(t26); +t177 = t105*t116*t72*(-1.0/2.0)-t104*t72*t93*(1.0/2.0); +t178 = exp(t177); +t179 = focal*mR21*t20*t25; +t180 = t179-focal*mR31*t169*t20*t81; +t181 = t176+1.0; +Xb = (t178*(t105*t116*t126*(-1.0/2.0)-t104*t126*t93*(1.0/2.0)+t116*t180*t26*t72+t104*t3*t72*(Sx*focal*mR11*t2*t25-Sx*focal*mR31*t169*t2*t91)+1/pow(t103,2)*t72*t93*(Xwb*t4*4.05e5-t4*txi*4.05e5)*(1.0/2.0)+t105*1/pow(t115,2)*t72*(Xwb*t4*1.62e6-t4*txi*1.62e6)*(1.0/2.0)))/t181+t176*t178*t180*1/pow(t181,2); + +/* Yb */ +t117 = Ywb*t6*t9*2.0; +t118 = Ywb*t12*t6*2.0; +t119 = Ywb*t14*t6*2.0; +t120 = Ywb*t5*t6*2.0; +t121 = Ywa*t6*t7*4.0; +t122 = Ywb*t6*t7*2.0; +t123 = Ywb*t6*t8*2.0; +t124 = Xwa*t6*txi*tyi*4.0; +t125 = Zwa*t6*tyi*tzi*4.0; +t126 = t117+t118+t119+t120+t121+t122+t123+t124+t125-t12*t6*tyi*2.0-t14*t6*tyi*2.0-t5*t6*tyi*2.0-t6*t7*tyi*2.0-t6*t8*tyi*2.0-t6*t9*tyi*2.0-Xwa*Ywb*t6*txi*4.0-Ywa*Ywb*t6*tyi*4.0-Ywb*Zwa*t6*tzi*4.0; +t169 = 1/pow(t24,2); +t176 = exp(t26); +t177 = t105*t116*t72*(-1.0/2.0)-t104*t72*t93*(1.0/2.0); +t178 = exp(t177); +t179 = focal*mR22*t20*t25; +t180 = t179-focal*mR32*t169*t20*t81; +t181 = t176+1.0; +Yb = (t178*(t105*t116*t126*(-1.0/2.0)-t104*t126*t93*(1.0/2.0)+t116*t180*t26*t72+t104*t3*t72*(Sx*focal*mR12*t2*t25-Sx*focal*mR32*t169*t2*t91)+1/pow(t103,2)*t72*t93*(Ywb*t4*4.05e5-t4*tyi*4.05e5)*(1.0/2.0)+t105*1/pow(t115,2)*t72*(Ywb*t4*1.62e6-t4*tyi*1.62e6)*(1.0/2.0)))/t181+t176*t178*t180*1/pow(t181,2); + + plhs[0]=Xa; + plhs[1]=Ya; + plhs[2]=Xb; + plhs[3]=Yb; + + +} + + + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { + + + /* /Declarations */ + const mxArray *Dpxdata, *Dpydata, *Sxdata, *focaldata, \ + *mR11data, *mR12data, *mR13data, *mR21data, *mR22data, *mR23data, *mR31data, *mR32data, *mR33data, \ + *txdata, *tydata, *tzdata, *Xmtx, *Ymtx, *Ximtx, *Yimtx, *rhodata, *txidata, *tyidata, *tzidata; + + double Dpx, Dpy, Sx, Xwa, Xwb, Ywa, Ywb, Zwa, Zwb, focal, \ + mR11, mR12, mR13, mR21, mR22, mR23, mR31, mR32, mR33, \ + tx, ty, tz, *X, *Y, *Xi, *Yi, rho, txi, tyi, tzi; + + double Za, Zb; + double sizeOnImagea, sizeOnImageb; + double tmpdouble; + double tmp, tmp2, tmp2x, tmp2y, tmpx, tmpy; + double sigfac; + + + int i,j,k,t, ind, ind2, ind3, ind4,icnt,jcnt; + double B[4], C[4]; +double *v; +double *tvis; +double *occx; +double *occy; +double *ddvix; +double *ddviy; + + unsigned int N; + unsigned int F; + int dims[3]; + + double camPar[25]; + double dX[4]; + double *sf; + + double *occmat; + double *occmatdX; + double *occmatdY; + double *occmatdX2; + double *occmatdY2; + double *ol; + + /* //Copy input pointer x */ + Xmtx = prhs[0]; Ymtx = prhs[1]; Ximtx = prhs[2]; Yimtx = prhs[3]; + Dpxdata = prhs[4]; Dpydata = prhs[5]; Sxdata = prhs[6]; + + focaldata = prhs[7]; + mR11data = prhs[8]; mR12data = prhs[9]; mR13data = prhs[10]; + mR21data = prhs[11]; mR22data = prhs[12]; mR23data = prhs[13]; + mR31data = prhs[14]; mR32data = prhs[15]; mR33data = prhs[16]; + txdata = prhs[17]; tydata = prhs[18]; tzdata = prhs[19]; + txidata = prhs[20]; tyidata = prhs[21]; tzidata = prhs[22]; + rhodata = prhs[23]; + + + Dpx = (double)(mxGetScalar(Dpxdata)); Dpy = (double)(mxGetScalar(Dpydata)); + Sx = (double)(mxGetScalar(Sxdata)); + /* +// Xwa = (double)(mxGetScalar(Xwadata)); Xwb = (double)(mxGetScalar(Xwbdata)); +// Ywa = (double)(mxGetScalar(Ywadata)); Ywb = (double)(mxGetScalar(Ywbdata)); +// Zwa = (double)(mxGetScalar(Zwadata)); Zwb = (double)(mxGetScalar(Zwbdata)); + */ + focal = (double)(mxGetScalar(focaldata)); + mR11 = (double)(mxGetScalar(mR11data)); mR12 = (double)(mxGetScalar(mR12data)); mR13 = (double)(mxGetScalar(mR13data)); + mR21 = (double)(mxGetScalar(mR21data)); mR22 = (double)(mxGetScalar(mR22data)); mR23 = (double)(mxGetScalar(mR23data)); + mR31 = (double)(mxGetScalar(mR31data)); mR32 = (double)(mxGetScalar(mR32data)); mR33 = (double)(mxGetScalar(mR33data)); + tx = (double)(mxGetScalar(txdata)); ty = (double)(mxGetScalar(tydata)); tz = (double)(mxGetScalar(tzdata)); + txi = (double)(mxGetScalar(txidata)); tyi = (double)(mxGetScalar(tyidata)); tzi = (double)(mxGetScalar(tzidata)); + X = mxGetPr(Xmtx); Y = mxGetPr(Ymtx); Xi = mxGetPr(Ximtx); Yi = mxGetPr(Yimtx); rho=(double)(mxGetScalar(rhodata)); + + + + + + N = mxGetN(Xmtx); + F = mxGetM(Xmtx); +/*// mexPrintf("%i %i\n",F,N);*/ + + + dims[0]=F;dims[1]=N;dims[2]=N; + + plhs[0] = mxCreateDoubleMatrix(F, N, mxREAL); + plhs[1] = mxCreateDoubleMatrix(F, N, mxREAL); + plhs[2] = mxCreateDoubleMatrix(F, N, mxREAL); + plhs[3] = mxCreateDoubleMatrix(F, N, mxREAL); + plhs[4] = mxCreateNumericArray(3, dims,mxDOUBLE_CLASS, mxREAL); + plhs[5] = mxCreateNumericArray(3, dims,mxDOUBLE_CLASS, mxREAL); + + v = mxGetPr(plhs[0]); + tvis = mxGetPr(plhs[1]); + occx = mxGetPr(plhs[2]); + occy = mxGetPr(plhs[3]); + ddvix = mxGetPr(plhs[4]); + ddviy = mxGetPr(plhs[5]); + + icnt=0; +/* +// for (t=0; ti) { + double b[2]; + double B[2], C[2]; + double alessb[2]; + ind3=i*N+j; + Ywb=Y[ind2]; + +/*// Zb=sqrt((tx-Xwb)*(tx-Xwb) + (ty-Ywb)*(ty-Ywb) +(tz-Zwb)*(tz-Zwb));*/ + Zb=sqrt((txi-Xwb)*(txi-Xwb) + (tyi-Ywb)*(tyi-Ywb) +(tzi-Zwb)*(tzi-Zwb)); + sizeOnImageb=1800*focal/Zb/Dpy; + tmpdouble=(sizeOnImageb/2)*(sizeOnImageb/2); + B[0]=tmpdouble/4; B[1]=tmpdouble; + C[0]=1/(A[0]+B[0]); C[1]=1/(A[1]+B[1]); + + a[0]=Xi[ind]; a[1]=Yi[ind]; + b[0]=Xi[ind2]; b[1]=Yi[ind2]; + alessb[0]=a[0]-b[0]; alessb[1]=a[1]-b[1]; + tmpdouble=alessb[0]*alessb[0]*C[0]+alessb[1]*alessb[1]*C[1]; + + ol[ind3]=exp(-.5 * tmpdouble); +/*// mexPrintf("%i %i %f %f %f %f %f\n",i,j,alessb[0],alessb[1],C[0],C[1],ol[i][j]);*/ + } + } + } + + + for (j=0; j 0.0001){ + + camPar[3]=Xwa;camPar[4]=Xwb; + camPar[5]=Ywa;camPar[6]=Ywb; + camPar[7]=Zwa;camPar[8]=Zwb; + dX[0]=0;dX[1]=0;dX[2]=0;dX[3]=0; + + dfnddALL(camPar,dX); + + occmatdX[ind3]=dX[0]; + occmatdY[ind3]=dX[1]; + occmatdX2[ind3]=dX[2]; + occmatdY2[ind3]=dX[3]; + //if (isnan(dX[0])) { + // mexPrintf("lalala %i %i %f \n ",i,j,dX[0]); + //} + + } + + } + } + } + } + } + /* +// if (t==0) { +// for (k=0; k 1 + */ + for (i=0; i0, S=['Linesearch']; else S=['Function evaluation']; end + +stateInfo=P1; +i = 0; % zero the run length counter +ls_failed = 0; % no previous line search has failed +fX = []; +XX = []; +[f1 df1] = eval(argstr); % get function value and gradient +XX=vertcat(XX,[1,-f1]); %by Russ, get first value +i = i + (length<0); % count epochs?! +s = -df1; % search direction is steepest +d1 = -s'*s; % this is the slope +z1 = 1/(1-d1); % initial step is 1/(|s|+1) + +while i < abs(length) % while not finished + i = i + (length>0); % count iterations?! + globiter=globiter+1; + + X0 = X; f0 = f1; df0 = df1; % make a copy of current values + X = X + z1*s; % begin line search + [f2 df2] = eval(argstr); + i = i + (length<0); % count epochs?! + d2 = df2'*s; + f3 = f1; d3 = d1; z3 = -z1; % initialize point 3 equal to point 1 + if length>0, M = MAX; else M = min(MAX, -length-i); end + success = 0; limit = -1; % initialize quanteties + while 1 + while ((f2 > f1+z1*RHO*d1) || (d2 > -SIG*d1)) && (M > 0) + limit = z1; % tighten the bracket + if f2 > f1 + z2 = z3 - (0.5*d3*z3*z3)/(d3*z3+f2-f3); % quadratic fit + else + A = 6*(f2-f3)/z3+3*(d2+d3); % cubic fit + B = 3*(f3-f2)-z3*(d3+2*d2); + z2 = (sqrt(B*B-A*d2*z3*z3)-B)/A; % numerical error possible - ok! + end + if isnan(z2) || isinf(z2) + z2 = z3/2; % if we had a numerical problem then bisect + end + z2 = max(min(z2, INT*z3),(1-INT)*z3); % don't accept too close to limits + z1 = z1 + z2; % update the step + X = X + z2*s; + [f2 df2] = eval(argstr); + M = M - 1; i = i + (length<0); % count epochs?! + d2 = df2'*s; + z3 = z3-z2; % z3 is now relative to the location of z2 + end + if f2 > f1+z1*RHO*d1 || d2 > -SIG*d1 + break; % this is a failure + elseif d2 > SIG*d1 + success = 1; break; % success + elseif M == 0 + break; % failure + end + A = 6*(f2-f3)/z3+3*(d2+d3); % make cubic extrapolation + B = 3*(f3-f2)-z3*(d3+2*d2); + z2 = -d2*z3*z3/(B+sqrt(B*B-A*d2*z3*z3)); % num. error possible - ok! + if ~isreal(z2) || isnan(z2) || isinf(z2) || z2 < 0 % num prob or wrong sign? + if limit < -0.5 % if we have no upper limit + z2 = z1 * (EXT-1); % the extrapolate the maximum amount + else + z2 = (limit-z1)/2; % otherwise bisect + end + elseif (limit > -0.5) && (z2+z1 > limit) % extraplation beyond max? + z2 = (limit-z1)/2; % bisect + elseif (limit < -0.5) && (z2+z1 > z1*EXT) % extrapolation beyond limit + z2 = z1*(EXT-1.0); % set to extrapolation limit + elseif z2 < -z3*INT + z2 = -z3*INT; + elseif (limit > -0.5) && (z2 < (limit-z1)*(1.0-INT)) % too close to limit? + z2 = (limit-z1)*(1.0-INT); + end + f3 = f2; d3 = d2; z3 = -z2; % set point 3 equal to point 2 + z1 = z1 + z2; X = X + z2*s; % update current estimates + [f2 df2] = eval(argstr); + M = M - 1; i = i + (length<0); % count epochs?! + d2 = df2'*s; + end % end of line search + + if success % if line search succeeded + f1 = f2; fX = [fX' f1]'; + + %%%%%%%%%%%%%%%%%%% + % O U T P U T % + %%%%%%%%%%%%%%%%%%% + if ~mod(i,updOutput) || i==1 + + + if opt.visOptim + prepFigure(); + plotDetections(1); + plotTrajectories(X,P1,1); pause(.001); +% saveas(gcf,sprintf('tmp/contoptim_%04d.png',globiter)); + end + + +% fprintf('%s %6i; Value %4.6e\r', S, i, f1); + + if opt.verbosity>=3 + [fx, ~, EdetValue EdynValue EexcValue EappValue EperValue EregValue] = eval(argstr); + % weight energy values + EdetValue=EdetValue*opt.weightEdet; + EdynValue=EdynValue*opt.weightEdyn; + EexcValue=EexcValue*opt.weightEexc; + EappValue=EappValue*opt.weightEapp; + EperValue=EperValue*opt.weightEper; + EregValue=EregValue*opt.weightEreg; + + printMessage(3,'%4i|%3i|%6.1f|%8.1f|%8.1f|%6.1f|%6.1f|%6.1f|%6.1f|%6.1f|||', ... + globiter,i, toc(cemStartTime)/60,fx,EdetValue,EdynValue,EexcValue,EappValue,EperValue,EregValue); + allens(globiter,:)=[EdetValue EdynValue EexcValue EappValue EperValue EregValue]; + end + + if opt.verbosity >= 3 && sceneInfo.gtAvailable + + stateInfo=P1; + stateInfo.stateVec=X; + [~,~,~,~, stateInfo.X stateInfo.Y]=getStateInfo(stateInfo); + + % set state struct + if opt.track3d + stateInfo=cutStateToTrackingArea(stateInfo); + end +% [Xm Ym]=vectorToMatrices(X,stateInfo); +% stateInfo.X=Xm; stateInfo.Y=Ym; + if opt.track3d + stateInfo.Xgp=stateInfo.X; stateInfo.Ygp=stateInfo.Y; + [stateInfo.Xi stateInfo.Yi]=projectToImage(stateInfo.Xgp,stateInfo.Ygp,sceneInfo); + else + stateInfo.Xi=stateInfo.X; stateInfo.Yi=stateInfo.Y; + end + + + % evaluate 3D CLEAR MOT + if opt.track3d + evopt.eval3d=1; + [metrics3d metricsInfo3d]=CLEAR_MOT(gtInfo,stateInfo,evopt); + printMetrics(metrics3d,metricsInfo3d,0,[12 13 4 5 7:11]); + allmets3d(globiter,:)=metrics3d; + end + + % evaluate 2D CLEAR MOT + % get bounding boxes from corresponding detections + stateInfo=getBBoxesFromState(stateInfo); + + evopt.eval3d=0; + [metrics2d metricsInfo2d]=CLEAR_MOT(gtInfo,stateInfo,evopt); +% printMetrics(metrics,metricsInfo,i==1); + printMessage(3,'|||'); + printMetrics(metrics2d,metricsInfo2d,0,[12 13 4 5 7:11]); + allmets2d(globiter,:)=metrics2d; + + printMessage(3,'\n'); + else + printMessage(3,'\n'); + end + + + end + +% XX=vertcat(XX,[i,-f1]); %minus here for our purpuses only + s = (df2'*df2-df1'*df2)/(df1'*df1)*s - df2; % Polack-Ribiere direction + tmp = df1; df1 = df2; df2 = tmp; % swap derivatives + d2 = df1'*s; + if d2 > 0 % new slope must be negative + s = -df1; % otherwise use steepest direction + d2 = -s'*s; + end + z1 = z1 * min(RATIO, d1/(d2-realmin)); % slope ratio but max RATIO + d1 = d2; + ls_failed = 0; % this line search did not fail + else + X = X0; f1 = f0; df1 = df0; % restore point from before failed line search + if ls_failed || i > abs(length) % line search failed twice in a row + break; % or we ran out of time, so we give up + end + tmp = df1; df1 = df2; df2 = tmp; % swap derivatives + s = -df1; % try steepest + d1 = -s'*s; + z1 = 1/(1-d1); + ls_failed = 1; % this line search failed + end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/plotTrajectories.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/plotTrajectories.m new file mode 100644 index 0000000000000000000000000000000000000000..8a7f393871717a38d0ef3231fff9c8f84cb0c614 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/plotTrajectories.m @@ -0,0 +1,42 @@ +function plotTrajectories(stateVec,stateInfo,plot3d) +% plot trajectories +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +hold on + +% plot3d=1; +if ~exist('plot3d','var') + plot3d=0; +end + +lw=2; + +N=stateInfo.N; +targetsExist=stateInfo.targetsExist; +[X Y]=vectorToMatrices(stateVec,stateInfo); + +if plot3d + for id=1:N + tarFrames=(targetsExist(id,1):targetsExist(id,2))'; +% tarFrames=tarFrames(tarFrames<=50); + plot3(X(tarFrames,id),Y(tarFrames,id),tarFrames, ... + 'color',getColorFromID(id),'linewidth',lw); + end + +else + for id=1:N + tarFrames=(targetsExist(id,1):targetsExist(id,2))'; + plot(X(tarFrames,id),Y(tarFrames,id), ... + 'color',getColorFromID(id),'linewidth',lw); + end +end +drawnow +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/printMoveFailure.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/printMoveFailure.m new file mode 100644 index 0000000000000000000000000000000000000000..966611dfe2a30fe1d1d2fd42444ee6d1af59ba91 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/printMoveFailure.m @@ -0,0 +1,28 @@ +function printMoveFailure(m) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +failstr='unknown move'; + switch(m) + case 1 + failstr='merging does no good!'; + case 2 + failstr='split does no good!'; + case 3 + failstr='growing does no good!'; + case 4 + failstr='shrinking does no good!'; + case 5 + failstr='purge does no good!'; + case 6 + failstr='adding does no good!'; + end + printMessage(2,'%s\n',failstr); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/randomParamSearch.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/randomParamSearch.m new file mode 100644 index 0000000000000000000000000000000000000000..fa73dde77f67519b17d8d08422497ee2a0eff06a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/randomParamSearch.m @@ -0,0 +1,30 @@ +allscen=[23 42 80 25 27 71 72]; + +allmets2d=zeros(max(allscen),14,100); +allmets3d=zeros(max(allscen),14,100); +allopts=[]; + +for exprun=1:100 + % random sample + rnmeans=[1 .1 .5 .5 .5 .1]; + rmvars=[.1 .1 .1 .1 .1 .01]; + randopts=rnmeans + rmvars.*randn(1,6); + opt.weightEdet=randopts(1); + opt.weightEdyn=randopts(2); + opt.weightEexc=randopts(3); + opt.weightEper=randopts(4); + opt.weightEreg=randopts(5); + allopts=[allopts; randopts]; + + for scenario=allscen + randopts + scenario + [metrics2d metrics3d]=cemTrackerSearch(scenario,randopts); + allmets2d(scenario,:,exprun)=metrics2d; + allmets3d(scenario,:,exprun)=metrics3d; + end + + save('testrun.mat','LOG_*'); +end + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/run_tracker.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/run_tracker.m new file mode 100644 index 0000000000000000000000000000000000000000..4c296c7a10a0e6ef66abe2e4c97719645064378f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/run_tracker.m @@ -0,0 +1,86 @@ +function [stateInfo, speed] = run_tracker(curSequence, baselinedetections) +%% Multi-Target Tracking by Continuous Energy Minimization + +%% declare global variables +global cemStartTime detMatrices detections sceneInfo opt globiter +globiter=0; + +%% setup options and scene +% fill options struct +opt = getConOptionsDemo(); +opt.print = 0; +opt.display = 0; +% energy weights (default 2d) + +opt.weightEdet=1; % should be kept at 1 +opt.weightEdyn=0.03; +opt.weightEexc=0.5; +opt.weightEper=0.3; +opt.weightEreg=0.1; +opt.weightEapp=0.; + + +% fill scene info +sceneInfo = getSceneInfoConDemo(curSequence); +%% load detections +detections = parseDetections(baselinedetections, sceneInfo); +stateInfo.F = size(detections,2); +detMatrices = getDetectionMatrices(detections); +cemStartTime = tic; +%% init solution +X=[]; Y=[]; +initsolfile = fullfile('demo','ekf','e0001.mat'); +load(initsolfile); +[X, Y] = checkInitSolution(X,Y,stateInfo.F); + +stateInfo.N = size(X,2); +stateInfo.targetsExist = getTracksLifeSpans(X); +stateInfo.frameNums = sceneInfo.frameNums; +stateInfo = matricesToVector(X,Y,stateInfo); +[~, ~, F, ~, stateInfo.X, stateInfo.Y] = getStateInfo(stateInfo); + +%% initial gradient descent (if initial solution available) +if(~isempty(stateInfo.stateVec)) + [stateInfo.stateVec, Evalue, nIterations] = minimize(stateInfo.stateVec,'E',opt.maxIterCGD,stateInfo); +end + +%% now do main optimization +converged = false; +epoch = 0; +while(~converged && epoch= opt.maxEpochs) +% printMessage(1,'Max number of rounds reached.\n'); + end +end % converged + +% basically we are done +speed = F/toc(cemStartTime); +%% post processing +% get X Y matrices +[stateVec, N, F, targetsExist, stateInfo.X, stateInfo.Y] = getStateInfo(stateInfo); +stateInfo = postProcessState(stateInfo); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/CLEAR_MOT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/CLEAR_MOT.m new file mode 100644 index 0000000000000000000000000000000000000000..9c369160aef959dd8892190dfc0bf5201f9e8117 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/CLEAR_MOT.m @@ -0,0 +1,320 @@ +function [metrics metricsInfo]=CLEAR_MOT(gtInfo,stateInfo,options) +% compute CLEAR MOT and other metrics +% +% metrics contains the following +% [1] recall - recall = percentage of detected targets +% [2] precision - precision = percentage of correctly detected targets +% [3] FAR - number of false alarms per frame +% [4] GT - number of ground truth trajectories +% [5-7] MT, PT, ML - number of mostly tracked, partially tracked and mostly lost trajectories +% [8] falsepositives- number of false positives (FP) +% [9] missed - number of missed targets (FN) +% [10] idswitches - number of id switches (IDs) +% [11] FRA - number of fragmentations +% [12] MOTA - Multi-object tracking accuracy in [0,100] +% [13] MOTP - Multi-object tracking precision in [0,100] (3D) / [td,100] (2D) +% [14] MOTAL - Multi-object tracking accuracy in [0,100] with log10(idswitches) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% default options: 2D +if nargin<3 + options.eval3d=0; % only bounding box overlap + options.td=.5; % threshold 50% +end + +if ~isfield(options,'td') + if options.eval3d + options.td=1000; + else + options.td=0.5; + end +end + +td=options.td; + +assert(length(gtInfo.frameNums)==length(stateInfo.frameNums), ... + 'Ground Truth and state must be of equal length'); +if(gtInfo.frameNums(1)~=stateInfo.frameNums(1)) + gtInfo.frameNums = gtInfo.frameNums + stateInfo.frameNums(1) - gtInfo.frameNums(1); +end +assert(all(gtInfo.frameNums==stateInfo.frameNums), ... + 'Ground Truth and state must contain equal frame numbers'); + +% check if all necessery info is available +if options.eval3d + assert(all(isfield(gtInfo,{'Xgp','Ygp'})), ... + 'Ground Truth Ground Plane coordinates needed for 3D evaluation'); + assert(all(isfield(stateInfo,{'Xgp','Ygp'})), ... + 'Ground Plane coordinates needed for 3D evaluation'); +else + assert(all(isfield(gtInfo,{'X','Y','W','H'})), ... + 'Ground Truth coordinates X,Y,W,H needed for 2D evaluation'); + assert(all(isfield(stateInfo,{'Xi','Yi','W','H'})), ... + 'State coordinates Xi,Yi,W,H needed for 2D evaluation'); + +end + +gtInd=~~gtInfo.X; +stInd=~~stateInfo.X; + +[Fgt Ngt]=size(gtInfo.X); +[F N]=size(stateInfo.X); + +aspectRatio=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% gtInfo.W=gtInfo.H*aspectRatio; + + +metricsInfo.names.long = {'Recall','Precision','False Alarm Rate', ... + 'GT Tracks','Mostly Tracked','Partially Tracked','Mostly Lost', ... + 'False Positives', 'False Negatives', 'ID Switches', 'Fragmentations', ... + 'MOTA','MOTP', 'MOTA Log'}; + +metricsInfo.names.short = {'Rcll','Prcn','FAR', ... + 'GT','MT','PT','ML', ... + 'FP', 'FN', 'IDs', 'FM', ... + 'MOTA','MOTP', 'MOTAL'}; + +metricsInfo.widths.long = [6 9 16 9 14 17 11 15 15 11 14 5 5 8]; +metricsInfo.widths.short = [5 5 5 3 3 3 3 4 4 3 3 5 5 5]; + +metricsInfo.format.long = {'.1f','.1f','.2f', ... + 'i','i','i','i', ... + 'i','i','i','i', ... + '.1f','.1f','.1f'}; + +metricsInfo.format.short=metricsInfo.format.long; + + +metrics=zeros(1,14); +metrics(9)=numel(find(gtInd)); % False Negatives (missed) +metrics(7)=Ngt; % Mostly Lost + +% nothing to be done, if state is empty +if ~N, return; end + +% global opt +% if options.eval3d && opt.mex +% [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% CLEAR_MOT_mex(gtInfo.Xgp', gtInfo.Ygp', stateInfo.Xgp', stateInfo.Ygp',options.td); +% +% % cd /home/aanton/diss/utils +% % [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% % CLEAR_MOT(gtInfo.Xgp, gtInfo.Ygp, stateInfo.Xgp, stateInfo.Ygp,options.td); +% % cd /home/aanton/visinf/projects/ongoing/contracking +% metrics=[rc*100, pc*100, faf, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FM, MOTA*100, MOTP*100, MOTAL*100]; +% metrics +% global gsi +% gsi=stateInfo; +% pause +% return; +% end + + +% mapping +M=zeros(F,Ngt); + +mme=zeros(1,F); % ID Switchtes (mismatches) +c=zeros(1,F); % matches found +fp=zeros(1,F); % false positives +m=zeros(1,F); % misses = false negatives +g=zeros(1,F); +d=zeros(F,Ngt); % all distances; +ious=Inf*ones(F,Ngt); % all overlaps + +matched=@matched2d; +if options.eval3d, matched=@matched3d; end + +alltracked=zeros(F,Ngt); +allfalsepos=zeros(F,N); + +for t=1:F + g(t)=numel(find(gtInd(t,:))); + + % mapping for current frame + if t>1 + mappings=find(M(t-1,:)); + for map=mappings + if gtInd(t,map) && stInd(t,M(t-1,map)) && matched(gtInfo,stateInfo,t,map,M(t-1,map),td) + M(t,map)=M(t-1,map); + end + end + end + + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + + if options.eval3d + alldist=Inf*ones(Ngt,N); + + mindist=0; + while mindist < td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 + for o=GTsNotMapped + GT=[gtInfo.Xgp(t,o) gtInfo.Ygp(t,o)]; + for e=EsNotMapped + E=[stateInfo.Xgp(t,e) stateInfo.Ygp(t,e)]; + alldist(o,e)=norm(GT-E); + end + end + [mindist cind]=min(alldist(:)); + + if mindist <= td + [u v]=ind2sub(size(alldist),cind); + M(t,u)=v; + alldist(:,v)=Inf; + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + end + end + + else + allisects=zeros(Ngt,N); maxisect=Inf; + + while maxisect > td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 + for o=GTsNotMapped + GT=[gtInfo.X(t,o)-gtInfo.W(t,o)/2 ... + gtInfo.Y(t,o)-gtInfo.H(t,o) ... + gtInfo.W(t,o) gtInfo.H(t,o) ]; + for e=EsNotMapped + E=[stateInfo.Xi(t,e)-stateInfo.W(t,e)/2 ... + stateInfo.Yi(t,e)-stateInfo.H(t,e) ... + stateInfo.W(t,e) stateInfo.H(t,e) ]; + allisects(o,e)=boxiou(GT(1),GT(2),GT(3),GT(4),E(1),E(2),E(3),E(4)); + end + end + [maxisect cind]=max(allisects(:)); + + if maxisect >= td + [u v]=ind2sub(size(allisects),cind); + M(t,u)=v; + allisects(:,v)=0; + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + end + + end + end + + curtracked=find(M(t,:)); + + + alltrackers=find(stInd(t,:)); + mappedtrackers=intersect(M(t,find(M(t,:))),alltrackers); + falsepositives=setdiff(alltrackers,mappedtrackers); + + alltracked(t,:)=M(t,:); + allfalsepos(t,1:length(falsepositives))=falsepositives; + + %% mismatch errors + if t>1 + for ct=curtracked + lastnotempty=find(M(1:t-1,ct),1,'last'); + if gtInd(t-1,ct) && ~isempty(lastnotempty) && M(t,ct)~=M(lastnotempty,ct) + mme(t)=mme(t)+1; + end + end + end + + c(t)=numel(curtracked); + for ct=curtracked + eid=M(t,ct); + if options.eval3d + d(t,ct)=norm([gtInfo.Xgp(t,ct) gtInfo.Ygp(t,ct)] - ... + [stateInfo.Xgp(t,eid) stateInfo.Ygp(t,eid)]); + else + gtLeft=gtInfo.X(t,ct)-gtInfo.W(t,ct)/2; + gtTop=gtInfo.Y(t,ct)-gtInfo.H(t,ct); + gtWidth=gtInfo.W(t,ct); gtHeight=gtInfo.H(t,ct); + + stLeft=stateInfo.Xi(t,eid)-stateInfo.W(t,eid)/2; + stTop=stateInfo.Yi(t,eid)-stateInfo.H(t,eid); + stWidth=stateInfo.W(t,eid); stHeight=stateInfo.H(t,eid); + ious(t,ct)=boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight); + end + end + + + fp(t)=numel(find(stInd(t,:)))-c(t); + m(t)=g(t)-c(t); + + +end + +missed=sum(m); +falsepositives=sum(fp); +idswitches=sum(mme); + +if options.eval3d + MOTP=(1-sum(sum(d))/sum(c)/td) * 100; % avg distance to [0,100] +else + MOTP=sum(ious(ious>=td & ious0)); + if gtlength/gttotallength >= 0.8 && trlengtha/gttotallength < 0.2 + MTstatsa(i)=3; + elseif t>=find(gtInd(:,i),1,'last') && trlengtha/gttotallength <= 0.8 + MTstatsa(i)=2; + elseif trlengtha/gttotallength >= 0.8 + MTstatsa(i)=1; + end +end +% MTstatsa +MT=numel(find(MTstatsa==1));PT=numel(find(MTstatsa==2));ML=numel(find(MTstatsa==3)); + +%% fragments +fr=zeros(1,Ngt); +for i=1:Ngt + b=alltracked(find(alltracked(:,i),1,'first'):find(alltracked(:,i),1,'last'),i); + b(~~b)=1; + fr(i)=numel(find(diff(b)==-1)); +end +FRA=sum(fr); + +assert(Ngt==MT+PT+ML,'Hmm... Not all tracks classified correctly.'); +metrics=[recall, precision, FAR, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FRA, MOTA, MOTP, MOTAL]; +end + + + + +function ret=matched2d(gtInfo,stateInfo,t,map,mID,td) + gtLeft=gtInfo.X(t,map)-gtInfo.W(t,map)/2; + gtTop=gtInfo.Y(t,map)-gtInfo.H(t,map); + gtWidth=gtInfo.W(t,map); gtHeight=gtInfo.H(t,map); + + stLeft=stateInfo.Xi(t,mID)-stateInfo.W(t,mID)/2; + stTop=stateInfo.Yi(t,mID)-stateInfo.H(t,mID); + stWidth=stateInfo.W(t,mID); stHeight=stateInfo.H(t,mID); + + ret = boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight) >= td; +end + + +function ret=matched3d(gtInfo,stateInfo,t,map,mID,td) + Xgt=gtInfo.Xgp(t,map); Ygt=gtInfo.Ygp(t,map); + X=stateInfo.Xgp(t,mID); Y=stateInfo.Ygp(t,mID); + ret=norm([Xgt Ygt]-[X Y])<=td; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/boxIntersect.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/boxIntersect.m new file mode 100644 index 0000000000000000000000000000000000000000..5a55b45131c36980ad641f838452967a12bf300b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/boxIntersect.m @@ -0,0 +1,24 @@ +function isect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2) +% A=[bboxleft1 bboxbottom1 abs(bboxright1-bboxleft1) abs(bboxbottom1-bboxup1)]; +% B=[bboxleft2 bboxbottom2 abs(bboxright2-bboxleft2) abs(bboxbottom2-bboxup2)]; +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% isect=rectint(A,B); +isect=0; + +hor= max(0,min(bboxright1,bboxright2) - max(bboxleft1,bboxleft2)); + +if ~hor, return; end +ver= max(0,min(bboxbottom1,bboxbottom2) - max(bboxup1,bboxup2)); +if ~ver, return; end + +isect = hor*ver; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/boxUnion.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/boxUnion.m new file mode 100644 index 0000000000000000000000000000000000000000..c5b8e06c5ea242199dbffa15e553ec07b626fab9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/boxUnion.m @@ -0,0 +1,24 @@ +function union=boxUnion(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2,isect) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +a1=bboxright1-bboxleft1; +b1=bboxbottom1-bboxup1; +a2=bboxright2-bboxleft2; +b2=bboxbottom2-bboxup2; +union=a1*b1+a2*b2; +if nargin>8 + bisect=isect; +else + bisect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2); +end +union=union-bisect; + + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/boxiou.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/boxiou.m new file mode 100644 index 0000000000000000000000000000000000000000..395e5dc90d032ee2d7f3c9554148e56f908eeab5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/boxiou.m @@ -0,0 +1,21 @@ +function iou=boxiou(x1,y1,w1,h1,x2,y2,w2,h2) +% compute intersection over union of two bboxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + bisect=boxIntersect(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2); + iou=0; + if ~bisect, return; end + + bunion=boxUnion(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2,bisect); + + assert(bunion>0,'something wrong with union computation'); + iou=bisect/bunion; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/distortedToUndistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/distortedToUndistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..6e62dfbd4271580faef309647e42784c11964e31 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/distortedToUndistortedImageCoord.m @@ -0,0 +1,15 @@ +function [Xfu Yfu]=distortedToUndistortedImageCoord (Xfd, Yfd, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xd = mDpx * (Xfd - mCx) / mSx; + Yd = mDpy * (Yfd - mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ + [Xu Yu]=distortedToUndistortedSensorCoord(Xd, Yd, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfu = Xu * mSx / mDpx + mCx; + Yfu = Yu / mDpy + mCy; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/distortedToUndistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/distortedToUndistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..14158bd36e686650ae77a8621b1ed3c4d56e298a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/distortedToUndistortedSensorCoord.m @@ -0,0 +1,6 @@ +function [Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mKappa1) +% /* convert from distorted to undistorted sensor plane coordinates */ + distortion_factor = 1 + mKappa1 * (Xd*Xd + Yd*Yd); + Xu = Xd * distortion_factor; + Yu = Yd * distortion_factor; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/getRotTrans.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/getRotTrans.m new file mode 100644 index 0000000000000000000000000000000000000000..725097d307f8d0b7a1d211e756f99d82d45ebe1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/getRotTrans.m @@ -0,0 +1,34 @@ +function [mR mT]=getRotTrans(camPar) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + %%% Rotation Translation %%% + mT=[camPar.mExt.mTx;camPar.mExt.mTy;camPar.mExt.mTz]; + sa = sin(camPar.mExt.mRx); + ca = cos(camPar.mExt.mRx); + sb = sin(camPar.mExt.mRy); + cb = cos(camPar.mExt.mRy); + sg = sin(camPar.mExt.mRz); + cg = cos(camPar.mExt.mRz); + + mR11 = cb * cg; + mR12 = cg * sa * sb - ca * sg; + mR13 = sa * sg + ca * cg * sb; + mR21 = cb * sg; + mR22 = sa * sb * sg + ca * cg; + mR23 = ca * sb * sg - cg * sa; + mR31 = -sb; + mR32 = cb * sa; + mR33 = ca * cb; + + mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/imageToWorld.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/imageToWorld.m new file mode 100644 index 0000000000000000000000000000000000000000..3919cb798acbbeec7f826c6ea524dee3c3035476 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/imageToWorld.m @@ -0,0 +1,62 @@ +function [Xw Yw Zw]=imageToWorld(Xi, Yi, camPar) + +mGeo=camPar.mGeo; +mExt=camPar.mExt; +mInt=camPar.mInt; + +mTx=mExt.mTx; +mTy=mExt.mTy; +mTz=mExt.mTz; + +mT=[mExt.mTx;mExt.mTy;mExt.mTz]; + +%% internal init +sa = sin(mExt.mRx); +ca = cos(mExt.mRx); +sb = sin(mExt.mRy); +cb = cos(mExt.mRy); +sg = sin(mExt.mRz); +cg = cos(mExt.mRz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + + + +% /* convert from image to distorted sensor coordinates */ +Xd = mGeo.mDpx * (Xi - mInt.mCx) / mInt.mSx; +Yd = mGeo.mDpy * (Yi - mInt.mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ +[Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mInt.mKappa1); + +% /* calculate the corresponding xw and yw world coordinates */ +% /* (these equations were derived by simply inverting */ +% /* the perspective projection equations using Macsyma) */ +Zw=0; +common_denominator = ((mR11 * mR32 - mR12 * mR31) * Yu + ... + (mR22 * mR31 - mR21 * mR32) * Xu - ... + mInt.mFocal * mR11 * mR22 + mInt.mFocal * mR12 * mR21); + +Xw = (((mR12 * mR33 - mR13 * mR32) * Yu + ... + (mR23 * mR32 - mR22 * mR33) * Xu - ... + mInt.mFocal * mR12 * mR23 + mInt.mFocal * mR13 * mR22) * Zw + ... + (mR12 * mTz - mR32 * mTx) * Yu + ... + (mR32 * mTy - mR22 * mTz) * Xu - ... + mInt.mFocal * mR12 * mTy + mInt.mFocal * mR22 * mTx) / common_denominator; + +Yw = -(((mR11 * mR33 - mR13 * mR31) * Yu + ... + (mR23 * mR31 - mR21 * mR33) * Xu - ... + mInt.mFocal * mR11 * mR23 + mInt.mFocal * mR13 * mR21) * Zw + ... + (mR11 * mTz - mR31 * mTx) * Yu + ... + (mR31 * mTy - mR21 * mTz) * Xu - ... + mInt.mFocal * mR11 * mTy + mInt.mFocal * mR21 * mTx) / common_denominator; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/parseCameraParameters.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/parseCameraParameters.m new file mode 100644 index 0000000000000000000000000000000000000000..10baec4a50e7d06334ec9a16693a4ce178845580 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/parseCameraParameters.m @@ -0,0 +1,104 @@ +function camPar=parseCameraParameters(camconffile) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +xDoc=xmlread(fullfile(camconffile)); + +width=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('width')); +height=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('height')); + +ncx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('ncx')); +nfx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('nfx')); +dx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dx')); +dy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dy')); +dpx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpx')); +dpy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpy')); + +focal=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('focal')); +kappa1=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('kappa1')); +cx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cx')); +cy=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cy')); +sx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('sx')); + +tx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tx')); +ty=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ty')); +tz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tz')); +rx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rx')); +ry=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ry')); +rz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rz')); + +mGeo.mImgWidth = width; +mGeo.mImgHeight = height; +mGeo.mNcx = ncx; +mGeo.mNfx = nfx; +mGeo.mDx = dx; +mGeo.mDy = dy; +mGeo.mDpx = dpx; +mGeo.mDpy = dpy; + + +%% intrinsic +mInt.mFocal = focal; +mInt.mKappa1 = kappa1; +mInt.mCx = cx; +mInt.mCy = cy; +mInt.mSx = sx; + +%% extrinsic +mExt.mTx = tx; +mExt.mTy = ty; +mExt.mTz = tz; +mExt.mRx = rx; +mExt.mRy = ry; +mExt.mRz = rz; + +%% inverted +mT=[tx;ty;tz]; +sa = sin(rx); +ca = cos(rx); +sb = sin(ry); +cb = cos(ry); +sg = sin(rz); +cg = cos(rz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + +mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; + +transform=[mR mT;[0 0 0 1]]; +invtrans=inv(transform); +tx=invtrans(1,4);ty=invtrans(2,4);tz=invtrans(3,4); + +mExt.mTxi = tx; +mExt.mTyi = ty; +mExt.mTzi = tz; + +camPar.mExt=mExt; +camPar.mInt=mInt; +camPar.mGeo=mGeo; + +%% mkappa<0 +if kappa1<0 + warning('CAREFUL! kappa1 < 0, cam derivates are wrong!'); +end + +[camPar.mR camPar.mT]=getRotTrans(camPar); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/undistortedToDistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/undistortedToDistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..9c9f9a1382cfcbf25407f159a06cc73d4440c9a1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/undistortedToDistortedImageCoord.m @@ -0,0 +1,14 @@ +function [Xfd Yfd]=undistortedToDistortedImageCoord (Xfu, Yfu, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xu = mDpx * (Xfu - mCx) / mSx; + Yu = mDpy * (Yfu - mCy); + +% /* convert from undistorted sensor to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord(Xu, Yu, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfd = Xd * mSx / mDpx + mCx; + Yfd = Yd / mDpy + mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/undistortedToDistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/undistortedToDistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..b689d695a1a98a28a8ba414a7661fe9658d24403 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/undistortedToDistortedSensorCoord.m @@ -0,0 +1,67 @@ +function [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mKappa1) + +% global ifs elses + +if ((~Xu && ~Yu) || ~mKappa1) +% ifs(1)=ifs(1)+1; + Xd = Xu; + Yd = Yu; +else %% THIS ONE %% +% elses(1)=elses(1)+1; + Ru = sqrt(Xu*Xu + Yu*Yu); + + c = 1.0 / mKappa1; + d = -c * Ru; + + Q = c / 3; + R = -d / 2; + D = Q*Q*Q + R*R; + + if (D >= 0) %% THIS ONE %% +% ifs(2)=ifs(2)+1; + %/* one real root */ + D = sqrt(D); + if (R + D > 0) %% THIS ONE %% +% ifs(3)=ifs(3)+1; + S = (R + D)^ (1.0/3.0); + else +% elses(3)=elses(3)+1; + S = -(-R - D)^ (1.0/3.0); + end + if (R - D > 0) +% ifs(4)=ifs(4)+1; + T = (R - D)^(1.0/3.0); + else %% THIS ONE %% +% elses(4)=elses(4)+1; + T = -(D - R)^(1.0/3.0); + end + Rd = S + T; + + if (Rd < 0) + Rd = sqrt(-1.0 / (3 * mKappa1)); + % /*fprintf (stderr, "\nWarning: undistorted image point to distorted image point mapping limited by\n"); + % fprintf (stderr, " maximum barrel distortion radius of %lf\n", Rd); + % fprintf (stderr, " (Xu = %lf, Yu = %lf) -> (Xd = %lf, Yd = %lf)\n\n", Xu, Yu, Xu * Rd / Ru, Yu * Rd / Ru);*/ + end + else +% elses(2)=elses(2)+1; + % /* three real roots */ + D = sqrt(-D); + S = ( sqrt(R*R + D*D))^(1.0/3.0 ); + T = atan2(D, R) / 3; + sinT = sin(T); + cosT = cos(T); + + % /* the larger positive root is 2*S*cos(T) */ + % /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ + % /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ + + Rd = -S * cosT + sqrt(3.0) * S * sinT; % /* use the smaller positive root */ + end + + lambda = Rd / Ru; + + Xd = Xu * lambda; + Yd = Yu * lambda; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/worldToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/worldToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..8bb11eb8cfff82e0e805c07f7f22d5e81042b241 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/camera/worldToImage.m @@ -0,0 +1,28 @@ +function [Xi Yi]=worldToImage(Xw,Yw,Zw,mR,mT,mInt,mGeo) + + + % /* convert from world coordinates to camera coordinates */ + x=[mR mT]*[Xw;Yw;Zw;1]; + xc = x(1); + yc = x(2); + zc = x(3); + + % /* convert from camera coordinates to undistorted sensor plane coordinates */ + Xu = mInt.mFocal * xc / zc; + Yu = mInt.mFocal * yc / zc; + + % /* convert from undistorted to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mInt.mKappa1); + % Xd=Xu; + % Yd=Yu; + + % Rusq=Xu*Xu+Yu*Yu; + % Ru=sqrt(Xu*Xu+Yu*Yu); + % Xd=Xu*(1+mInt.mKappa1*Rusq); + % Yd=Yu*(1+mInt.mKappa1*Rusq); + + + % /* convert from distorted sensor plane coordinates to image coordinates */ + Xi = Xd * mInt.mSx / mGeo.mDpx + mInt.mCx; + Yi = Yd / mGeo.mDpy + mInt.mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/checkInitSolution.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/checkInitSolution.m new file mode 100644 index 0000000000000000000000000000000000000000..2c804a3311ac0367686b89db9d6c9864a4856c0c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/checkInitSolution.m @@ -0,0 +1,22 @@ +function [Xinit Yinit]=checkInitSolution(Xinit,Yinit,F) +% check if initial solution is correct +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + assert(all(size(Xinit)==size(Yinit)), ... + 'X and Y are of different size in initial solution'); + + % pad with zeros if not enough frames + Finit=size(Xinit,1); + if Finit=sceneInfo.trackingArea(1) & ... + detections(t).xw<=sceneInfo.trackingArea(2) & ... + detections(t).yw>=sceneInfo.trackingArea(3) & ... + detections(t).yw<=sceneInfo.trackingArea(4)); + + nDets=nDets+length(tokeep); + + for iField = 1:length(Field) + fcontent=detections(t).(char(Field(iField))); + fcontent=fcontent(tokeep); + detections(t).(char(Field(iField)))=fcontent; + end + end +end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/cutGTToTrackingArea.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/cutGTToTrackingArea.m new file mode 100644 index 0000000000000000000000000000000000000000..5ad3c93a92a8bd9dbe5bbf3b149d10351d2f07cf --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/cutGTToTrackingArea.m @@ -0,0 +1,31 @@ +function gtInfo=cutGTToTrackingArea(gtInfo) +% if we are tracking on ground plane +% remove all track segments outside tracking area +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt sceneInfo + +if(opt.cutToTA) + Xgp=gtInfo.Xgp; Ygp=gtInfo.Ygp; + areaLimits=sceneInfo.trackingArea; + + Xgp(XgpareaLimits(2))=0;Ygp(Ygp>areaLimits(4))=0; + Ygp(Xgp==0)=0; Xgp(Ygp==0)=0; + + allzeros=(Xgp == 0 | Ygp ==0); + gtInfo.X(allzeros)=0;gtInfo.Y(allzeros)=0; + gtInfo.W(allzeros)=0;gtInfo.H(allzeros)=0; + gtInfo.Xgp(allzeros)=0;gtInfo.Ygp(allzeros)=0; + + % now clean up zero columns + gtInfo=cleanGT(gtInfo); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/cutStateToTrackingArea.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/cutStateToTrackingArea.m new file mode 100644 index 0000000000000000000000000000000000000000..977d2e957af687926552ce27c94bcb207992f6b8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/cutStateToTrackingArea.m @@ -0,0 +1,28 @@ +function stateInfo=cutStateToTrackingArea(stateInfo) +% if we are tracking on ground plane +% remove all track segments outside tracking area +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo; + +X=stateInfo.X; Y=stateInfo.Y; +areaLimits=sceneInfo.trackingArea; + +X(XareaLimits(2))=0;Y(Y>areaLimits(4))=0; +Y(X==0)=0; X(Y==0)=0; + +% now clean up zero columns +[X Y stateInfo]=cleanState(X,Y,stateInfo); + +stateInfo.X=X; stateInfo.Y=Y; + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..5659abdb33d47429791dfc94c48964fc1acc7a0e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayBBoxes.m @@ -0,0 +1,204 @@ +function displayBBoxes(sceneInfo,frameNums,X,Y,W,H,options) +% Draw bounding boxes on top of images +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% +[F,~]=size(X); + +ind=find(W); +aspectRatio=mean(H(ind)./W(ind)); + +%% if we want to display traces, lets compute average image +% or let's not... Doesn't look good, anyway + +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(1))]); +% avim=zeros(size(im)); +% avgF=1:5:min(500,F); +% avgnF=length(avgF); +% for t=avgF +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]); +% avim=avim+double(im)/avgnF; +% end +% avim=avim/255; + +global opt; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + al=0.5; + load(sceneInfo.bgMask); + immask=cat(3,bgmask,bgmask,bgmask); + + end + +for t=1:F + clf + im=double(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]))/255; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + imgray=rgb2gray(im); imgray=imgray+0.5; + imgray=cat(3,imgray,imgray,imgray); + im(immask)=al*im(immask)+(1-al)*(imgray(immask)); + end + + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % tracking area + if opt.track3d && opt.cutToTA + drawTALimits; + end + + + extar=find(W(t,:)); + % foot position + if options.displayDots + for id=extar + plot(X(t,id),Y(t,id),'.','color',getColorFromID(id),'MarkerSize',options.dotSize); + end + end + + % box + if options.displayBoxes + for id=extar + bleft=X(t,id)-W(t,id)/2; + bright=X(t,id)+W(t,id)/2; + btop=Y(t,id)-H(t,id); + bbottom=Y(t,id); + rectangle('Position',[bleft,btop,W(t,id),H(t,id)],'Curvature',[.3,max(0,min(1,.3*(W(t,id)/H(t,id))))],'EdgeColor',getColorFromID(id),'linewidth',options.boxLineWidth); + end + end + + % ID + if options.displayID + for id=extar + tx=X(t,id); + ty=Y(t,id)-H(t,id)*2/3; % inside +% ty=Y(t,id)-H(t,id)-10; % on top + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',W(t,id)/2, 'FontUnits','pixels','FontWeight','bold'); + end + end + + % cropouts + if options.displayCropouts + bw=2; %border cropouts + + %% crop outs var sized + maxTar=30; + extarRed=extar(extar<=maxTar); % reducde +% crpImg=zeros(round(max(max(H))+5),round(sum(max(W))+5*bw),3); +% offset=1; +% offsets=round([1 cumsum(max(W))]); +% for id=extarRed +% % offsets(id)=offset; +% offset=offsets(id); +% bleft=round(X(t,id)-W(t,id)/2); +% bright=round(X(t,id)+W(t,id)/2); +% btop=round(Y(t,id)-H(t,id)); +% bbottom=round(Y(t,id)); +% +% ht=(bbottom-btop)+1;wt=(bright-bleft)+1; +% crpImg(1:ht,offset:offset+wt-1,:)=im(btop:bbottom,bleft:bright,:); +% % offset=offset+wt+bw; +% end + + %% crop outs fixed sized + uniH=min(60,round(sceneInfo.imgHeight/10)); uniW=round(uniH/aspectRatio); +% crpImg=zeros(round(uniH+bw),round(uniW*size(W,2)+bw*size(W,2)),3); % black + mxfac=.5; + crpImg=im(1:uniH,1:min(sceneInfo.imgWidth,round(uniW*size(W,2)+bw*size(W,2))),:)*mxfac; + crpImg=crpImg + (1-mxfac)*ones(size(crpImg)); % bleeched + for id=extarRed + offset=(id-1)*uniW + (id-1)*bw+1; + bleft=round(X(t,id)-W(t,id)/2); + bright=round(X(t,id)+W(t,id)/2); + btop=round(Y(t,id)-H(t,id)); + bbottom=round(Y(t,id)); + + [bleft bright btop bbottom]= ... + clampBBox(bleft, bright, btop, bbottom, sceneInfo.imgWidth, sceneInfo.imgHeight); + ht=uniH; + imres=imresize(im(btop:bbottom,bleft:bright,:),[uniH uniW]); + crpImg(1:ht,offset:offset+uniW-1,:)=imres; + + end + imshow(crpImg); + + for id=extarRed +% tx=offsets(id)+W(t,id)/2; + tx=id*uniW-uniW/2 + id*bw; + ty=30; % top + ty=size(crpImg,1)-10; % below + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',uniW/2, 'FontUnits','pixels','FontWeight','bold'); % fixed size +% 'FontSize',mean(W(t,extarRed))/2, 'FontUnits','pixels','FontWeight','bold'); % var size + + end + if options.displayConnections + for id=extarRed + if t-find(X(:,id),1,'first')<5 + btop=round(Y(t,id)-H(t,id)); + offset=(id-1)*uniW + (id-1)*bw+1 + uniW/2; + line([X(t,id) offset],[btop uniH],'color',getColorFromID(id),'linestyle','-'); + end + end + end + end + + % show trace + if options.traceLength + for tracet=max(1,t-options.traceLength):max(1,t-1) + ipolpar=(t-tracet)/options.traceLength; % parameter [0,1] for color adjustment + + % pick color from tail +% if tracet==max(1,t-options.traceLength) +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(tracet))]); +% end + + extarpast=find(X(tracet,:)); + % foot position + for id=extarpast + % plot(X(tracet,id),Y(tracet,id), ... + % '.','color',ipolpar*options.grey + (1-ipolpar)*getColorFromID(id),'MarkerSize',max(1,options.dotSize*(1-ipolpar))); + + + if W(tracet+1,id) + posx=round(max(1,X(t,id))); posx=min(sceneInfo.imgWidth,posx); + posy=round(max(1,Y(t,id))); posy=min(sceneInfo.imgHeight,posy); +% endcol=double(reshape(avim(posy,posx,:),1,3)); +% endcol=min(1,endcol); endcol=max(1,endcol); + endcol=options.grey; + line(X(tracet:tracet+1,id) ,Y(tracet:tracet+1,id), ... + 'color',ipolpar*endcol + (1-ipolpar)*getColorFromID(id),'linewidth',(1-ipolpar)*options.traceWidth+1); + end + + end + + end + end + + + pause(options.framePause) + + % save + if isfield(options,'outFolder'); + im2save=getframe(gcf); + im2save=im2save.cdata; + imwrite(im2save, fullfile(options.outFolder,sprintf('frame_%04d.jpg',frameNums(t)))); + end + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayDetectionBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayDetectionBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..85a14f52b9a012f72c0909b95491270609907826 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayDetectionBBoxes.m @@ -0,0 +1,81 @@ +function displayDetectionBBoxes(sceneInfo, detections) +% Display Detection Bounding Boxes +% +% Take scene information sceneInfo and +% an array of detections and display +% them on +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +reopenFig('Detections') + +F=size(detections,2); +assert(F==length(sceneInfo.frameNums), 'length of detections must be equal to the number of frames'); + +detcol=[.1 .2 .9]; +grey=.6*ones(1,3); +framePause=0.01; % pause between frames +% framePause=1; + +traceLength=10; % overlay data from past 10 frames +dotSize=20; +boxLineWidth=3; + +for t=1:F + clf + im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(t))]); + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % foot position + for k=1:length(detections(t).xp) + plot(detections(t).xp(k),detections(t).yp(k),'.','color',detcol,'MarkerSize',dotSize*detections(t).sc(k)); + end + + % box + nboxes=length(detections(t).xp); + for id=1:nboxes + bleft=detections(t).bx(id); + bright=detections(t).bx(id)+detections(t).wd(id); + btop=detections(t).by(id); + bbottom=detections(t).by(id)+detections(t).ht(id); + line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',detcol,'linewidth',boxLineWidth*detections(t).sc(id)); + end + + % show trace + for tracet=max(1,t-traceLength):max(1,t-1) + ipolpar=(t-tracet)/traceLength; % parameter [0,1] for color adjustment + + % foot position + for k=1:length(detections(tracet).xp) + plot(detections(tracet).xi(k),detections(tracet).yi(k), ... + '.','color',ipolpar*grey + (1-ipolpar)*detcol,'MarkerSize',dotSize*detections(tracet).sc(k)); + end + + % box +% nboxes=length(detections(tracet).xp); +% for id=1:nboxes +% bleft=detections(tracet).xp(id)-detections(tracet).wd(id)/2; +% bright=detections(tracet).xp(id)+detections(tracet).wd(id)/2; +% btop=detections(tracet).yp(id)-detections(tracet).ht(id); +% bbottom=detections(tracet).yp(id); +% line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',ipolpar*grey + (1-ipolpar)*detcol); +% end + + end + + pause(framePause) + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayGroundTruth.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayGroundTruth.m new file mode 100644 index 0000000000000000000000000000000000000000..4135ebf073c38772bf347eb1f08f4a32ee9da49e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayGroundTruth.m @@ -0,0 +1,42 @@ +function displayGroundTruth(sceneInfo, gtInfo) +% Display Ground Truth +% +% Take scene information sceneInfo and +% the ground truth from gtInfo +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +W=gtInfo.W; +H=gtInfo.H; + + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.01; % pause between frames + +options.traceLength=20; % overlay data from past 10 frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +X=gtInfo.X; Y=gtInfo.Y; + +reopenFig('Ground Truth'); +displayBBoxes(sceneInfo,gtInfo.frameNums,X,Y,W,H,options) + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayTrackingResult.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayTrackingResult.m new file mode 100644 index 0000000000000000000000000000000000000000..032e1abe3a17d689408768a731d318a3f224d985 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/displayTrackingResult.m @@ -0,0 +1,52 @@ +function displayTrackingResult(sceneInfo, stateInfo) +% Display Tracking Result +% +% Take scene information sceneInfo and +% the tracking result from stateInfo +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt + +if(~opt.display) + return; +end + +W=stateInfo.W; +H=stateInfo.H; +Xi=stateInfo.Xi; +Yi=stateInfo.Yi; + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.01; % pause between frames + +options.traceLength=20; % overlay track from past n frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +% save? +% options.outFolder='tmp'; + +reopenFig('Tracking Results') +displayBBoxes(sceneInfo,stateInfo.frameNums,Xi,Yi,W,H,options) + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/drawTALimits.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/drawTALimits.m new file mode 100644 index 0000000000000000000000000000000000000000..dafde616beee5dd1e9e9b4561ea00ce312b4f616 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/drawTALimits.m @@ -0,0 +1,36 @@ +function drawTALimits +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo + +c1=sceneInfo.trackingArea([1 3]); +c2=sceneInfo.trackingArea([2 3]); +c3=sceneInfo.trackingArea([2 4]); +c4=sceneInfo.trackingArea([1 4]); + + +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); + +[slx sly]=worldToImage(c1(1),c1(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(1)=slx; y(1)=sly; + +[slx sly]=worldToImage(c2(1),c2(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(2)=slx; y(2)=sly; + +[slx sly]=worldToImage(c3(1),c3(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(3)=slx; y(3)=sly; + +[slx sly]=worldToImage(c4(1),c4(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(4)=slx; y(4)=sly; + +line([x x(1)],[y y(1)],'linewidth',2,'color','w','linestyle','--'); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/estimateTargetsSize.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/estimateTargetsSize.m new file mode 100644 index 0000000000000000000000000000000000000000..6b980d7429d28c68ee11eae25b7ad1fb956edc42 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/estimateTargetsSize.m @@ -0,0 +1,53 @@ +function htobj=estimateTargetsSize(sceneInfo) +% Take best n percent of detections +% and fit a 2d surface through their heights +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +npercent = 25; % best 25 % + +% scenario=41; + +% sceneInfo=getSceneInfo(scenario); +detections=parseDetections(sceneInfo); +allxi=[];allxi=[];allyi=[];allsc=[];allht=[]; + +F=length(detections); +for t=1:F + allxi=[allxi detections(t).xi]; + allyi=[allyi detections(t).yi]; + allsc=[allsc detections(t).sc]; + allht=[allht detections(t).ht]; +end +minheight=15; +% goodones=find(allsc>0.75); % confident ones + +[allsc goodones]=sort(allsc,'descend'); goodones=goodones(1:round(length(goodones)/(1/npercent*100))); + +allxi=allxi(goodones);allyi=allyi(goodones);allsc=allsc(goodones);allht=allht(goodones); +htobj=fit([allxi; allyi]',allht','poly21','Robust','on'); + +% %% +% clf +% +% plot3(allxi,allyi,allht,'.'); box on +% xlim(sceneInfo.trackingArea(1:2));ylim(sceneInfo.trackingArea(3:4)); zlim([minheight sceneInfo.imgHeight]); +% set(gca,'Ydir','reverse'); +% +% hold on +% +% %% +% +% %% +% [xi yi]=meshgrid(1:50:sceneInfo.imgWidth, 1:50:sceneInfo.imgHeight); +% htsurface=feval(fitobj,xi(:),yi(:)); htsurface=reshape(htsurface,size(xi,1),size(xi,2)); +% htsurface(htsurfacesceneInfo.imgHeight)=sceneInfo.imgHeight; +% surf(xi,yi,htsurface) +% view(-78,34) \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/evaluateDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/evaluateDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..434bc96a586ea76a1c6195bd0d5a5d8572e5e8cc --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/evaluateDetections.m @@ -0,0 +1,28 @@ +function evaluateDetections(detMatrices,gtInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt +if sceneInfo.gtAvailable + detInfo=detMatrices; detInfo.frameNums=sceneInfo.frameNums; + detInfo.X=detInfo.Xi; detInfo.Y=detInfo.Yi; + [detInfo.F detInfo.N]=size(detInfo); + + if opt.track3d + detInfo=cutStateToTrackingArea(detInfo); +% gtInfo=cutGTToTrackingArea(gtInfo); + end + + printMessage(1,'\nDetections Evaluation (2D):\n'); + [metrics metricsInfo]=CLEAR_MOT(gtInfo,detInfo,struct('eval3d',0)); + printMetrics(metrics,metricsInfo,1,[1 2 3 8 9]); + printMessage(1,'\n'); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getBBoxesFromPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getBBoxesFromPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..fa0582c8ec7ae435a635a20df52d55f93d3b0f1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getBBoxesFromPrior.m @@ -0,0 +1,79 @@ +function stateInfo=getBBoxesFromPrior(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% just take the height prior for that +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo +% [~, N F targetsExist X Y]=getStateInfo(stateInfo); +X=stateInfo.X; Y=stateInfo.Y; + +[F N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + H=heightPrior; +else + error('sorry dude'); +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +% if sceneInfo.gtAvailable +% global gtInfo +% arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% aspectRatio= arithmean; +% end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +% stateInfo.W=H*sceneInfo.targetAR; % or take data set mean +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getBBoxesFromState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getBBoxesFromState.m new file mode 100644 index 0000000000000000000000000000000000000000..9f0857c56600a57e521789deaa1da5c1462a749c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getBBoxesFromState.m @@ -0,0 +1,137 @@ +function stateInfo=getBBoxesFromState(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% To this end, we check for corresponding detections +% and interpolate them to get the solution boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo +X=stateInfo.X; Y=stateInfo.Y; + +[F, N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + + +for id=1:N + sid=targetsExist(id,1); + eid=targetsExist(id,2); + frames=sid:eid; + asscDet=zeros(1,F); % which detection is close by? + widths=zeros(1,F); + heights=zeros(1,F); + scores=zeros(1,F); + + % find closest detections + for t=frames + ndets=length(detections(t).xp); % how many dets in this frame + if ndets + xy=[X(t,id); Y(t,id)]; + dets=[detections(t).xp; detections(t).yp]; + + alldist=sqrt(sum((repmat(xy,1,ndets)-dets).^2)); % distance to all + [mindist, mindet]=min(alldist); + if mindist<=sceneInfo.targetSize + asscDet(t)=mindet; + widths(t)=detections(t).wd(mindet); + heights(t)=detections(t).ht(mindet); + scores(t)=detections(t).sc(mindet); + end + end + end + detsAssc=find(asscDet); % which detections associated + detsAsscWobble=detsAssc;%+0.01*rand(1,length(t))-0.005; % add random noise to avoid NaN in fitting (LOOK INTO THIS!) + + if numel(unique(detsAssc))>1 + polydeg=min(9,max(1,floor(numel(detsAssc)/100))); + polystr=sprintf('poly%d',polydeg); + sp=splinefit(detsAsscWobble, heights(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); + ipolheights=ppval(sp,frames); + + + H((sid:eid)',id)=ipolheights'; + + if ~isfield(sceneInfo,'targetAR') % if no aspect ratio given, estimate widths + sp=splinefit(detsAsscWobble, widths(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); + ipolwidths = ppval(sp,frames); + W((sid:eid)',id)=ipolwidths'; + end + + else % strange trajectory with < 3 detections + detwidthmean=[]; detheightmean=[]; + for t=sid:eid + detwidthmean=[detwidthmean mean(detections(t).wd)]; + detheightmean=[detheightmean mean(detections(t).ht)]; + end + detwidthmean(isnan(detwidthmean))=mean(detwidthmean(~isnan(detwidthmean))); + detheightmean(isnan(detheightmean))=mean(detheightmean(~isnan(detheightmean))); + W((sid:eid)',id)=detwidthmean; + H((sid:eid)',id)=detheightmean; + end + +end + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + prwght=.8; + H=(1-prwght)*H + prwght*heightPrior; + +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +if sceneInfo.gtAvailable + global gtInfo + arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); + aspectRatio= arithmean; +end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getColorFromID.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getColorFromID.m new file mode 100644 index 0000000000000000000000000000000000000000..9ac27b6f3f79c5891348d2e7bf365d61620f6fc7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getColorFromID.m @@ -0,0 +1,32 @@ +function col=getColorFromID(id) + % get rgb [0,1] values from id +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + colors=getIDColors; + col=colors((mod(id,size(colors,1)))+1,:); +end + +function colors=getIDColors() +colors=[ + 128 255 255; % + 255 0 0; % red 1 + 0 255 0; % green 2 + 0 0 255; % blue 3 + 0 255 255; % cyan 4 + 255 0 255; % magenta 5 + 212 212 0; % yellow 6 + 25 25 25; % black 7 + 34,139,34; % forestgreen 8 + 0,191,255; % deepskyblue 9 + 139,0,0 ; % darkred 10 + 218,112,214; % orchid 11 + 244,164,96 ;]; % sandybrown 12 +colors = colors / 255; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getDetectionMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getDetectionMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..8f611515aed16395752333a63d28f2febf12a1d4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getDetectionMatrices.m @@ -0,0 +1,36 @@ +function detMat=getDetectionMatrices(detections) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=length(detections); +Xd=zeros(F,0); +Yd=zeros(F,0); +Sd=zeros(F,0); + +Xi=zeros(F,0); +Yi=zeros(F,0); +W=zeros(F,0); +H=zeros(F,0); +for t=1:length(detections); + Dt=length(detections(t).xp); + Xd(t,1:Dt)=detections(t).xp; + Yd(t,1:Dt)=detections(t).yp; + Sd(t,1:Dt)=detections(t).sc; + + Xi(t,1:Dt)=detections(t).xi; + Yi(t,1:Dt)=detections(t).yi; + W(t,1:Dt)=detections(t).wd; + H(t,1:Dt)=detections(t).ht; +end + +detMat.Xd=Xd; +detMat.Yd=Yd; +detMat.Sd=Sd; + +detMat.Xi=Xi;detMat.Yi=Yi;detMat.W=W;detMat.H=H; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getHeightPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getHeightPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..0f0cf37058d32fb215ae0b6b3265328d9c4f47f1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getHeightPrior.m @@ -0,0 +1,42 @@ +function heightPrior=getHeightPrior(stateInfo) +% for 3d tracking we can compute +% an approximate average bounding box for each target +% which corresponds to a height of 1.70 m in the world +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global sceneInfo +camPar=sceneInfo.camPar; + +% rx=camPar.mExt.mRx;ry=camPar.mExt.mRy;rz=camPar.mExt.mRz; +% tx=camPar.mExt.mTx;ty=camPar.mExt.mTy;tz=camPar.mExt.mTz; +% txi=camPar.mExt.mTxi;tyi=camPar.mExt.mTyi;tzi=camPar.mExt.mTzi; +% kappa=camPar.mInt.mKappa1; focal=camPar.mInt.mFocal;Sx=camPar.mInt.mSx; +% Dpx=camPar.mGeo.mDpx;Dpy=camPar.mGeo.mDpy; + +% [mR mT]=getRotTrans(sceneInfo.camPar); + +% feet +Z=0*ones(size(stateInfo.Xgp)); +[Xi0 Yi0]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +% heads +Z=1700*ones(size(stateInfo.Xgp)); +[XiH YiH]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +heightPrior=Yi0-YiH; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getHomeFolder.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getHomeFolder.m new file mode 100644 index 0000000000000000000000000000000000000000..73c516d61d583341e7938351ddd12e1c9de04ad0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getHomeFolder.m @@ -0,0 +1,18 @@ +function homedir=getHomeFolder() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + homedir='/home/aanton'; + if ispc + homedir='D:'; + end + if exist('/gris/gris-f/home/aandriye','dir') + homedir='/gris/gris-f/home/aandriye'; + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..35b13964f06515bc0f4136d073d0ef57755314fb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/getSceneInfo.m @@ -0,0 +1,526 @@ +function sceneInfo=getSceneInfo(scenario) +% fill all necessary information about the +% scene into the sceneInfo struct +% +% Required: +% detfile detections file (.idl or .xml) +% frameNums frame numbers (eg. frameNums=1:107) +% imgFolder image folder +% imgFileFormat format for images (eg. frame_%04d.jpg) +% targetSize approx. size of targets (default: 5 on image, 350 in 3d) +% +% Required for 3D Tracking only +% trackingArea tracking area +% camFile camera calibration file (.xml PETS format) +% +% Optional: +% gtFile file with ground truth bounding boxes (.xml CVML) +% initSolFile initial solution (.xml or .mat) +% targetAR aspect ratio of targets on image +% bgMask mask to bleach out the background +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt +% opt=getOptions; +% general folders +homefolder=getHomeFolder; +dbfolder=fullfile(filesep,'storage','databases'); if ispc, dbfolder=fullfile('D:','storage','databases'); end +if exist('/gris','dir'), dbfolder=fullfile(filesep,'gris','takatuka_dbases'); end + +% detection file +switch(scenario) + case {23,25,27,70,71,72,73,74,75,80} + dataset='PETS2009'; + case {40,41,42} + dataset='TUD'; + case {30,31,32,35,36,37} + dataset='TUD10'; + case {50,51,52,53} + dataset='ETH-Person'; + case {60,61,62} + dataset='AVSS'; + case {48} + dataset='UBC'; + case {90,91,92} + dataset='DA-ELS'; + otherwise + error('unknown scenario'); +end + +% sequence name +switch(scenario) + case 23 + seqname='PETS2009-S2L1-c1'; + case 25 + seqname='PETS2009-S2L2-c1'; + case 27 + seqname='PETS2009-S2L3-c1'; + case 31 + seqname='TUD10-ped1-c1'; + case 32 + seqname='TUD10-ped1-c2'; + case 36 + seqname='TUD10-ped1-c1'; + case 37 + seqname='TUD10-ped2-c2'; + case 40 + seqname='TUD-Campus'; + case 41 + seqname='TUD-Crossing'; + case 42 + seqname='TUD-Stadtmitte'; + case 48 + seqname='Hockey'; + case {50,51,52,53} + seqname=sprintf('seq%02d',scenario-50); + case 60 + seqname='AB_Easy'; + case 61 + seqname='AB_Medium'; + case 62 + seqname='AB_Hard'; + case 70 + seqname='PETS2009-S1L1-1-c1'; + case 71 + seqname='PETS2009-S1L1-2-c1'; + case 72 + seqname='PETS2009-S1L2-1-c1'; + case 73 + seqname='PETS2009-S1L2-2-c1'; + case 74 + seqname='PETS2009-S1L3-1-c1'; + case 75 + seqname='PETS2009-S1L3-2-c1'; + case 80 + seqname='PETS2009-S3MF1-c1'; + case {90,91,92,93,94} + seqname=sprintf('s%02d',scenario-90); + otherwise + + error('unknown scenario'); +end + +% frameNums +switch(scenario) + case 20 % terrace1 + sceneInfo.frameNums=1:2000; + case 21 % terrace2 + sceneInfo.frameNums=1:2000; + case {22,23} % PETS 2009 S2 L1 + sceneInfo.frameNums=0:794; + case 24 % PETSMONO occlusion + sceneInfo.frameNums=0:794; + case 25 + sceneInfo.frameNums=0:435; + case 27 + sceneInfo.frameNums=0:239; + case {30,31,32,33} % TUD10 ped + sceneInfo.frameNums=1:1400; + % sceneInfo.frameNums=1:300; + case {35,36,37} % TUD10 ped2 + sceneInfo.frameNums=1:1999; + % sceneInfo.frameNums=1:199; + % sceneInfo.frameNums=1670:1680; + % sceneInfo.frameNums=760:770; + case 40 % tud-campus + sceneInfo.frameNums=90:160; + case {41,44} % tud-crossing + sceneInfo.frameNums=1:201; + case 42 % tud-stadtmitte + sceneInfo.frameNums=7022:7200; + % sceneInfo.frameNums=7022:7100; + case 45 % eth central xing1 + sceneInfo.frameNums=1600:2200; + case 46 % eth central xing1 + sceneInfo.frameNums=3300:3600; + case 47 % eth central xing1 + sceneInfo.frameNums=7433:7811; + case 48 % UBC Hockey + sceneInfo.frameNums=700:800; + case 50 % ETH Person seq0 + sceneInfo.frameNums=180:678; + case 51 % ETH Person seq1 + sceneInfo.frameNums=0:999; + case 52 % ETH Person seq2 + sceneInfo.frameNums=0:450; + case 53 % ETH Person seq3 + sceneInfo.frameNums=100:453; + case {60,61,62} % AVSS + sceneInfo.frameNums=1:2000; + case 70 + sceneInfo.frameNums=0:220; + case 71 + sceneInfo.frameNums=0:240; + case 72 + sceneInfo.frameNums=0:200; + case 73 + sceneInfo.frameNums=0:130; + case 74 + sceneInfo.frameNums=0:90; + case 75 + sceneInfo.frameNums=0:343; + case 80 + sceneInfo.frameNums=1:107; + case 81 + sceneInfo.frameNums=0:231; + case 82 + sceneInfo.frameNums=0:108; + case 83 + sceneInfo.frameNums=0:169; + case 84 + sceneInfo.frameNums=0:92; + case 85 + sceneInfo.frameNums=0:107; + case 86 + sceneInfo.frameNums=0:184; + % case 90 + % sceneInfo.frameNums=1:593; + % case 91 + % sceneInfo.frameNums=1:307; + % case 92 + % sceneInfo.frameNums=1:420; + case {101,131} % EnterExitCrossingPaths1 cor, front + sceneInfo.frameNums=0:382; + case {102,132} % EnterExitCrossingPaths2 cor, front + sceneInfo.frameNums=0:484; + case {103,133} % OneLeaveShop1 cor, front + sceneInfo.frameNums=0:294; + case {104,134} % OneLeaveShop2 cor, front + sceneInfo.frameNums=0:1118; + case {105,135} % OneLeaveShopReenter1 cor, front + sceneInfo.frameNums=0:389; + case {106,136} % OneLeaveShopReenter2 cor, front + sceneInfo.frameNums=0:559; + case {107,137} % OneShopOneWait1 cor, front + sceneInfo.frameNums=0:1376; + case {108,138} % OneShopOneWait2 cor, front + sceneInfo.frameNums=0:1461; + case {109,139} % OneStopEnter1 cor, front + sceneInfo.frameNums=0:1499; + case {110,140} % OneStopEnter2 cor, front + sceneInfo.frameNums=0:2724; + case {111,141} % OneStopMoveEnter1 cor, front + sceneInfo.frameNums=0:1586; + case {112,142} % OneStopMoveEnter2 cor, front + sceneInfo.frameNums=0:2236; + case {113,143} % OneStopMoveNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {114,144} % OneStopMoveNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {115,145} % OneStopNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {116,146} % OneStopNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {117,147} % ShopAssistant1 cor, front + sceneInfo.frameNums=0:1674; + case {118,148} % ShopAssistant2 cor, front + sceneInfo.frameNums=0:3699; + case {119,149} % ThreePastShop1 cor, front + sceneInfo.frameNums=0:1649; + case {120,150} % ThreePastShop2 cor, front + sceneInfo.frameNums=0:1520; + case {121,151} % TwoEnterShop1 cor, front + sceneInfo.frameNums=0:1644; + case {122,152} % TwoEnterShop2 cor, front + sceneInfo.frameNums=0:1604; + case {123,153} % TwoEnterShop3 cor, front + sceneInfo.frameNums=0:1604; + case {124,154} % TwoLeaveShop1 cor, front + sceneInfo.frameNums=0:1342; + case {125,155} % TwoLeaveShop2 cor, front + sceneInfo.frameNums=0:599; + case {126,156} % WalkByShop1 cor, front + sceneInfo.frameNums=0:2359; + case 160 + sceneInfo.frameNums=171:184; + case {161,162} + sceneInfo.frameNums=97:114; + otherwise + warning('unknown scenario getFrameNums'); +end + + +detfolder=fullfile(homefolder,'diss','detections','hog-hof-linsvm',dataset,seqname); +% detfolder=fullfile(homefolder,'diss','detections','swd-v2',dataset,seqname); +% detfolder=fullfile(dbfolder,'data-tud','det','',dataset,seqname); + +% detfile +switch(scenario) + case 51 + sceneInfo.detfile=fullfile(detfolder,'test-result-nms-0.8.idl'); + case 53 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'seq03-annot.idl'); + case 62 + sceneInfo.detfile=fullfile(detfolder,['AVSS-' seqname sprintf('-result-00000-05059-nms.idl',length(sceneInfo.frameNums)-1)]); + case 48 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'detections.mat'); + case {90,91,92} + sceneInfo.detfile=fullfile(detfolder,'detections.mat'); + case {23,25,27,70,71,72,73,80,40,41,42} + sceneInfo.detfile=fullfile(dbfolder,'data-tud','det',dataset,[seqname '-det.xml']); + otherwise + sceneInfo.detfile=fullfile(detfolder,[seqname sprintf('-result-00000-%05d-nms.idl',length(sceneInfo.frameNums)-1)]); + +end +assert(exist(sceneInfo.detfile,'file')==2,'detection file does not exist') + + +% img Folder +switch(scenario) + case 23 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); + case 25 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L2','Time_14-55','View_001',filesep); + case 27 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L3','Time_14-41','View_001',filesep); + case 31 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c1',filesep); + case 32 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c2',filesep); + case 36 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c1',filesep); + case 37 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c2',filesep); + case 40 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-campus-sequence',filesep); + case 41 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-crossing-sequence',filesep); + case 42 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-stadtmitte',filesep); + case 48 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case {50,51,52,53} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,'left',filesep); + case {60,61,62} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case 70 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-57','View_001',filesep); + case 71 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-59','View_001',filesep); + case 72 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-06','View_001',filesep); + case 73 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-31','View_001',filesep); + case 80 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 + case {90,91,92,93} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + otherwise + error('unknown scenario image Folder'); +end +assert(exist(sceneInfo.imgFolder,'dir')==7,'imgfolder does not exist') + +% image extension +imgExt='.jpg'; +switch(scenario) + case {20,21,40,41,42,44,50,51,52,53} + imgExt='.png'; +end +sceneInfo.imgFileFormat='frame_%04d'; + +switch(scenario) + case 40 + sceneInfo.imgFileFormat='DaSide0811-seq6-%03d'; + case 41 + sceneInfo.imgFileFormat='DaSide0811-seq7-%03d'; + case 42 + sceneInfo.imgFileFormat='DaMultiview-seq%04d'; + case 48 + sceneInfo.imgFileFormat='h%04d'; + case {50,51,52,53} + sceneInfo.imgFileFormat='image_%08d_0'; + case {90,91,92,93} + sceneInfo.imgFileFormat='%05d'; +end + +% append file extension +sceneInfo.imgFileFormat=[sceneInfo.imgFileFormat imgExt]; + +% if no frame nums, determine from images +if ~isfield(sceneInfo,'frameNums') + imglisting=dir([sceneInfo.imgFolder '*' imgExt]); + sceneInfo.frameNums=1:length(imglisting); +end + +% image dimensions +[sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... + size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); + + + + +%% tracking area +% if we are tracking on the ground plane +% we need to explicitly secify the tracking area +% otherwise image = tracking area +if opt.track3d + switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.trackingArea=[-14069.6, 4981.3, -14274.0, 1733.5]; + case {30,31,32} + sceneInfo.trackingArea=[-197 6708 -2021 6870]; + case {35,36,37} + sceneInfo.trackingArea=[-3438 5271 -2018 7376]; + case 40 + sceneInfo.trackingArea=[-0150 0506 28 1081]; + case 41 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + case 42 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + otherwise + error('Definition of tracking area needed for 3d tracking'); + end + +else + sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +end + +%% camera +cameraconffile=[]; +if opt.track3d + cam=1; + switch(scenario) + case {20,21} %terrace + cameraconffile=sprintf('%sepfl/terrace-tsai-c%i.xml',dbfolder,cam); + case {22, 23,25,27,70,71,72,73,74,75,80,81,82,83,84,85,86} %PETS2009 + cameraconffile=fullfile(dbfolder,dataset,'View_001.xml'); + case 24 + cameraconffile=sprintf('%sPETS2009/View_001.xml',dbfolder); + case 30 + cameraconffile=sprintf('%sTUD10/ped1/c%i-calib.xml',dbfolder,cam); + case 31 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c1-calib.xml'); + case 32 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c2-calib.xml'); + case 36 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c1-calib.xml'); + case 37 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c2-calib.xml'); + case {40,43} + cameraconffile=fullfile(dbfolder,dataset,'tud-campus-calib.xml'); + case {41,44} + cameraconffile=fullfile(dbfolder,dataset,'tud-crossing-calib.xml'); + case 42 + cameraconffile=fullfile(dbfolder,dataset,'tud-stadtmitte-calib.xml'); + case {45,46,47} + cameraconffile=sprintf('%sETH-Central/pedxing-seq1-calib.xml',dbfolder); + case {60,61,62} + cameraconffile=sprintf('%sAVSS/AB_calib.xml',dbfolder); + case intersect(scenario,101:126); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-cor.xml',dbfolder); + case intersect(scenario,131:156); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + case intersect(scenario,160:163) %%% !!! FIX !!! + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + otherwise + error('unknown scenario'); + end +end +sceneInfo.camFile=cameraconffile; + +if ~isempty(sceneInfo.camFile) + sceneInfo.camPar=parseCameraParameters(sceneInfo.camFile); +end + + +%% target size +sceneInfo.targetSize=20; % target 'radius' +sceneInfo.targetSize=sceneInfo.imgWidth/30; +if opt.track3d, sceneInfo.targetSize=350; end + +%% target aspect ratio +sceneInfo.targetAR=1/3; +switch(scenario) + case 48 % Hockey + sceneInfo.targetAR=1/2; + case {90,91,92} % aerial + sceneInfo.targetAR=1; +end + + +%% ground truth +sceneInfo.gtFile=''; +switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + case 31 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c1','GT2d_full_new.mat'); + case 32 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c2','GT2d_full_new.mat'); + case {40,41} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '-interp.mat']); + case 42 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + % sceneInfo.gtFile='/home/aanton/diss/others/yangbo/TUD/TUD_Stadtmitte.avi.gt.mat'; % Yang + case 62 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,'AB_Hard','GT2d_new.mat'); + otherwise + warning('ground truth?'); +end + + +global gtInfo +sceneInfo.gtAvailable=0; +if ~isempty(sceneInfo.gtFile) + sceneInfo.gtAvailable=1; + % first determine the type + [pathtogt, gtfile, fileext]=fileparts(sceneInfo.gtFile); + + if strcmpi(fileext,'.xml') % CVML + gtInfo=parseGT(sceneInfo.gtFile); + elseif strcmpi(fileext,'.mat') + % check for the var gtInfo + fileInfo=who('-file',sceneInfo.gtFile); + varExists=0; cnt=0; + while ~varExists && cnt + +void undistortedToDistortedSensorCoord(double Xu, double Yu, double *Xd, double *Yd, double mKappa1) { + double Ru; + double Rd; + double lambda; + double c; + double d; + double Q; + double R; + double D; + double S; + double T; + double sinT; + double cosT; + + if (((Xu == 0) && (Yu == 0)) || (mKappa1 == 0)) { + *Xd = Xu; + *Yd = Yu; + } + else { + Ru = sqrt(Xu*Xu + Yu*Yu); + + c = 1.0 / mKappa1; + d = -c * Ru; + + Q = c / 3; + R = -d / 2; + D = Q*Q*Q + R*R; + + if (D >= 0) { + /* one real root */ + D = sqrt(D); + if (R + D > 0) { + S = pow(R + D, 1.0/3.0); + } + else { + S = -pow(-R - D, 1.0/3.0); + } + + if (R - D > 0) { + T = pow(R - D, 1.0/3.0); + } + else { + T = -pow(D - R, 1.0/3.0); + } + + Rd = S + T; + + if (Rd < 0) { + Rd = sqrt(-1.0 / (3 * mKappa1)); + /*fprintf (stderr, "\nWarning: undistorted image point to distorted image point mapping limited by\n"); + * fprintf (stderr, " maximum barrel distortion radius of %lf\n", Rd); + * fprintf (stderr, " (Xu = %lf, Yu = %lf) -> (Xd = %lf, Yd = %lf)\n\n", Xu, Yu, Xu * Rd / Ru, Yu * Rd / Ru);*/ + } + } + else { + /* three real roots */ + D = sqrt(-D); + S = pow( sqrt(R*R + D*D) , 1.0/3.0 ); + T = atan2(D, R) / 3; + sinT = sin(T); + cosT = cos(T); + + /* the larger positive root is 2*S*cos(T) */ + /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ + /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ + + Rd = -S * cosT + sqrt(3.0) * S * sinT; /* use the smaller positive root */ + } + + lambda = Rd / Ru; + + Xd[0] = Xu * lambda; + Yd[0] = Yu * lambda; + } +} + + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { + + + /* /Declarations */ + const mxArray *Dpxdata, *Dpydata, *Sxdata, *Cxdata, *Cydata, *Xwdata, *Ywdata, *Zwdata, *focaldata, *kappadata, \ + *mRdata, *mTdata; + + double mDpx, mDpy, mSx, *Xw, *Yw, *Zw, focal, kappa, \ + mR11, mR12, mR13, mR21, mR22, mR23, mR31, mR32, mR33, \ + mTx, mTy, mTz, mCx, mCy; + + double xc; + double yc; + double zc; + double Xu; + double Yu; + double Xd[1]; + double Yd[1]; + double xw, yw, zw; + int F, N; + + double *Xi, *Yi; + int i, j, ind; + + double *mR, *mT; + + /* //Copy input pointer x */ + Xwdata = prhs[0]; + Ywdata = prhs[1]; + Zwdata = prhs[2]; + Dpxdata = prhs[3]; + Dpydata = prhs[4]; + Sxdata = prhs[5]; + Cxdata = prhs[6]; + Cydata = prhs[7]; + focaldata = prhs[8]; + kappadata = prhs[9]; + mRdata = prhs[10]; + mTdata = prhs[11]; + + mDpx = (double)(mxGetScalar(Dpxdata)); + mDpy = (double)(mxGetScalar(Dpydata)); + mSx = (double)(mxGetScalar(Sxdata)); + Xw = mxGetPr(Xwdata); + Yw = mxGetPr(Ywdata); + Zw = mxGetPr(Zwdata); + focal = (double)(mxGetScalar(focaldata)); + kappa = (double)(mxGetScalar(kappadata)); + mCx = (double)(mxGetScalar(Cxdata)); + mCy = (double)(mxGetScalar(Cydata)); + + + mR = mxGetPr(mRdata); + mT = mxGetPr(mTdata); + + mR11 = mR[0]; + mR12 = mR[3]; + mR13 = mR[6]; + mR21 = mR[1]; + mR22 = mR[4]; + mR23 = mR[7]; + mR31 = mR[2]; + mR32 = mR[5]; + mR33 = mR[8]; + mTx = mT[0]; + mTy = mT[1]; + mTz = mT[2]; + + /* //Get number of frames and targets */ + F = mxGetN(Xwdata); + N = mxGetM(Xwdata); + + + /* Allocate memory and assign output pointer */ + plhs[0] = mxCreateDoubleMatrix(N, F, mxREAL); + plhs[1] = mxCreateDoubleMatrix(N, F, mxREAL); + + /*//Get a pointer to the data space in our newly allocated memory */ + Xi = mxGetPr(plhs[0]); + Yi = mxGetPr(plhs[1]); + + /* */ + for(i=0;i& /dev/null',pdffile,pdffile)); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/plotDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/plotDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..9cc7d63d4dcdfd98e6576f8dbc0b0113f0817625 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/plotDetections.m @@ -0,0 +1,61 @@ +function plotDetections(plot3d, limits) +% plot detections as dots +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo + +hold on +% axis equal + +dets=detections; +F=size(dets,2); +detcol=[.6 .6 .6]; +maxFrames=200; +% plot3d=1; + +% imshow(imread('/storage/databases/PETS2009/Crowd_PETS09/S3/Multiple_Flow/Time_12-43/View_001/frame_0026.jpg')); + +if ~exist('plot3d','var'), plot3d=0; end + +if plot3d + for t=1:min(F,maxFrames) +% t +% t*ones(1,length(dets(t).xp)) +% pause + plot3(dets(t).xp,dets(t).yp,t*ones(1,length(dets(t).xp)),'.','color',detcol); + +% pause(.01) + end +% view(3) +% zlim([0 min(F,maxFrames)]); +else + for t=1:F + plot(dets(t).xp,dets(t).yp,'.','color',detcol); + end + +end + +if exist('limits','var') + if length(limits)==4 || length(limits)==6 + xlim(limits(1:2)); + ylim(limits(3:4)); +% if length(limits)==6 +% zlim(limits(5:6)); +% end + else + error('limits must be 4 or 6 long vector'); + end +else + xlim(sceneInfo.trackingArea(1:2)); + ylim(sceneInfo.trackingArea(3:4)); +end + +pause(0.001); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/postProcessState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/postProcessState.m new file mode 100644 index 0000000000000000000000000000000000000000..38de1380a370814a23e8f5e5f7b5b2feb02b9d17 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/postProcessState.m @@ -0,0 +1,27 @@ +function stateInfo=postProcessState(stateInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt sceneInfo + +if opt.track3d && opt.cutToTA + stateInfo=cutStateToTrackingArea(stateInfo); +end + +% if we tracked on image, Xi = X +if ~opt.track3d + stateInfo.Xi=stateInfo.X; stateInfo.Yi=stateInfo.Y; +% otherwise project back +else + stateInfo.Xgp=stateInfo.X; stateInfo.Ygp=stateInfo.Y; + [stateInfo.Xi, stateInfo.Yi]=projectToImage(stateInfo.X,stateInfo.Y,sceneInfo); +end + +%% get bounding boxes from corresponding detections +stateInfo=getBBoxesFromState(stateInfo); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/prepFigure.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/prepFigure.m new file mode 100644 index 0000000000000000000000000000000000000000..27443be17e1e3b690c8d3b28ed6cfcc44fb01ee0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/prepFigure.m @@ -0,0 +1,39 @@ +function prepFigure() +% prepare figure for showing state +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt; + +% figh=findobj('type','figure','name','optimization'); + +% if isempty(figh), figh=figure('name','optimization'); end +% set(figh); + +clf; +hold on; +box on + +if ~opt.track3d + set(gca,'Ydir','reverse'); +end +xlim(sceneInfo.trackingArea(1:2)) +ylim(sceneInfo.trackingArea(3:4)) +if ~opt.track3d + ylim([sceneInfo.imTopLimit sceneInfo.trackingArea(4)]); +end + +zlim([0 length(sceneInfo.frameNums)]) + +view(-78,4) +if ~opt.track3d + view(-40,10); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printFinalEvaluation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printFinalEvaluation.m new file mode 100644 index 0000000000000000000000000000000000000000..d704bd7cefebf61920411668858d16224a30770a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printFinalEvaluation.m @@ -0,0 +1,17 @@ +function printFinalEvaluation(stateInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo gtInfo opt + +if(sceneInfo.gtAvailable && opt.print) + printMessage(1,'\nEvaluation 2D:\n'); + [metrics, metricsInfo] = CLEAR_MOT(gtInfo,stateInfo); + printMetrics(metrics,metricsInfo,1); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printMessage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printMessage.m new file mode 100644 index 0000000000000000000000000000000000000000..52a82a35c457f0890e5e099103633480ff54469c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printMessage.m @@ -0,0 +1,18 @@ +function printMessage(L,F,varargin) +% print a formatted string as F with values from varargin and debug level L +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt + + +if L<=opt.verbosity + fprintf(F,varargin{:}); +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printMetrics.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printMetrics.m new file mode 100644 index 0000000000000000000000000000000000000000..6b8a7929c06d6193c3a6a58b66858ea9ee234965 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printMetrics.m @@ -0,0 +1,43 @@ +function printMetrics(metrics, metricsInfo, dispHeader,dispMetrics,padChar) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +namesToDisplay=metricsInfo.names.long; +widthsToDisplay=metricsInfo.widths.long; +formatToDisplay=metricsInfo.format.long; + +namesToDisplay=metricsInfo.names.short; +widthsToDisplay=metricsInfo.widths.short; +formatToDisplay=metricsInfo.format.short; + +if nargin<3, dispHeader=1; end +if nargin<4 + dispMetrics=1:length(metrics); +end +if nargin<5 + padChar={' ',' ','|',' ',' ',' ','|',' ',' ',' ','| ',' ',' ',' '}; +end + +if dispHeader + for m=dispMetrics + printString=sprintf('fprintf(''%%%is%s'',char(namesToDisplay(m)))',widthsToDisplay(m),char(padChar(m))); + eval(printString) + end + fprintf('\n'); +end + +for m=dispMetrics + printString=sprintf('fprintf(''%%%i%s%s'',metrics(m))',widthsToDisplay(m),char(formatToDisplay(m)),char(padChar(m))); + eval(printString) +end + +% if standard, new line +if nargin<4 + fprintf('\n'); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..a06683f310651afbaca7ba0e8a767ecf4e9dc939 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/printSceneInfo.m @@ -0,0 +1,43 @@ +function printSceneInfo() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% prints information about the scene + +% sceneInfo.targetSize=10; % target 'radius' +% +% +% % sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); % 23 +% sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 +% +% sceneInfo.imgFileFormat='frame_%04d.jpg'; +% sceneInfo.frameNums=1:107; +% % sceneInfo.frameNums=0:794; +% [sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... +% size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); +% sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +% +% %% load detections +% detections=parseDetections(detfile); fr=1:length(detections); +% % fr=1:50; detections=detections(fr); % !!!!!!! REMOVE +% F=size(detections,2); +% stateInfo.F=F; % number of frames +% +% +global sceneInfo + + +%% +% printMessage(1,'Sequence: \t%s\n',sceneInfo.seqName); +printMessage(2, 'Frames: ...... %i\n',length(sceneInfo.frameNums)); +printMessage(2, 'Image size: .. %i x %i\n',sceneInfo.imgWidth,sceneInfo.imgHeight) + +% sceneInfo + +%% +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/projectToGroundPlane.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/projectToGroundPlane.m new file mode 100644 index 0000000000000000000000000000000000000000..b51522119bb738eae46b2fe90930d43d1aca9e74 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/projectToGroundPlane.m @@ -0,0 +1,22 @@ +function [Xgp Ygp]=projectToGroundPlane(Xi, Yi, sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +[F N]=size(Xi); +Xgp=zeros(size(Xi)); +Ygp=zeros(size(Xi)); + +for t=1:F + extar=find(Xi(t,:)); + for id=extar + [Xgp(t,id) Ygp(t,id) zw]=imageToWorld(Xi(t,id), Yi(t,id), sceneInfo.camPar); + end +end + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/projectToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/projectToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..97d5f7fdb9142e4217853da0b834e11a728adb0f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/projectToImage.m @@ -0,0 +1,19 @@ +function [Xi Yi]=projectToImage(X,Y,sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +Z=zeros(size(X)); +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); +[Xi Yi]=allWorldToImage_mex(X,Y,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + mR,mT); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/readIDL.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/readIDL.m new file mode 100644 index 0000000000000000000000000000000000000000..6e94f840fdbc5223ab1e4eada6f90623db9f3800 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/readIDL.m @@ -0,0 +1,60 @@ +% Return IDL structure for given filename +% +% INPUT +% filename filename of IDL file +% +% OUTPUT +% idl IDL structure, consisting of +% idl.img - array of images +% idl.bb - array of array of bounding box coordinates +% idl.score - array of array of scores for boxes + +function idl=readIDL(filename) + +fid=fopen(filename); +idl.bb=[]; +idl.img=[]; +idl.score=[]; + +i=1; +bbnum=0; +while 1 + tline = fgetl(fid); + if ~ischar(tline), break, end + tline = strrep(tline, ',', ' '); %replace commas with spaces + colon=strfind(tline,':'); %all colons + + if isempty(colon) + point = strfind(tline,'";'); + if length(point) > 0 + idl(i).img=tline(2:point(1)-1); %filename + i = i + 1; + continue + else + break + end + end + + bb_idx=[(strfind(tline,'(')+1)' (strfind(tline,')')-1)'];%positions of bb start and stop + + idl(i).img=tline(2:colon(1)-2); %filename + for k=1:size(bb_idx,1) + idl(i).bb(end+1,:)=str2num(tline(bb_idx(k,1):bb_idx(k,2))); % next bb + end + + if length(colon)>1 %there are scores in the file ... + for k=1:size(bb_idx,1)-1 + idl(i).score(end+1) = str2num(tline(colon(k+1)+1:(bb_idx(k+1,1)-2))); %next score + end + idl(i).score(end+1) = str2num(tline(colon(length(colon))+1:length(tline)-1)); + else + idl(i).score = 1*ones(1,size(bb_idx,1)); + end + + i=i+1; + bbnum = bbnum + size(bb_idx,1); +end +fclose(fid); + +% fprintf('%d bounding boxes loaded.', bbnum); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/reopenFig.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/reopenFig.m new file mode 100644 index 0000000000000000000000000000000000000000..dcfc4b09cfad39ea91e1f6a9dae423f639d08a35 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/reopenFig.m @@ -0,0 +1,14 @@ +function reopenFig(figname) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +close(findobj('type','figure','name',figname)) +figure('name',figname); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/examples.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/examples.m new file mode 100644 index 0000000000000000000000000000000000000000..a758a33db3033dacef195b999281160d0723cbde --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/examples.m @@ -0,0 +1,172 @@ +%%% SPLINEFIT EXAMPLES + + +%% EXAMPLE 1: Breaks and pieces + +% Data (200 points) +x = 2*pi*rand(1,200); +y = sin(x) + sin(2*x) + 0.2*randn(size(x)); + +% Uniform breaks +breaks = linspace(0,2*pi,41); % 41 breaks, 40 pieces +pp1 = splinefit(x,y,breaks); + +% Breaks interpolated from data +pp2 = splinefit(x,y,10); % 11 breaks, 10 pieces + +% Plot +figure(1) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +plot(x,y,'.',xx,[y1;y2]) +axis([0,2*pi,-2.5,2.5]), grid on +legend('data','41 breaks, 40 pieces','11 breaks, 10 pieces') +title('EXAMPLE 1: Breaks and pieces') + + + +%% EXAMPLE 2: Spline orders + +% Data (200 points) +x = 2*pi*rand(1,200); +y = sin(x) + sin(2*x) + 0.1*randn(size(x)); + +% Splines +pp1 = splinefit(x,y,8,1); % Piecewise constant +pp2 = splinefit(x,y,8,2); % Piecewise linear +pp3 = splinefit(x,y,8,3); % Piecewise quadratic +pp4 = splinefit(x,y,8,4); % Piecewise cubic +pp5 = splinefit(x,y,8,5); % Etc. + +% Plot +figure(2) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +y3 = ppval(pp3,xx); +y4 = ppval(pp4,xx); +y5 = ppval(pp5,xx); +plot(x,y,'.',xx,[y1;y2;y3;y4;y5]), grid on +legend('data','order 1','order 2','order 3','order 4','order 5') +title('EXAMPLE 2: Spline orders') + + + +%% EXAMPLE 3: Periodic boundary conditions + +% Data (100 points) +x = 2*pi*[0,rand(1,98),1]; +y = sin(x) - cos(2*x) + 0.2*randn(size(x)); + +% No constraints +pp1 = splinefit(x,y,10,5); +% Periodic boundaries +pp2 = splinefit(x,y,10,5,'p'); + +% Plot +figure(3) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +plot(x,y,'.',xx,[y1;y2]), grid on +legend('data','no constraints','periodic') +title('EXAMPLE 3: Periodic boundary conditions') + +% Check boundary conditions +y0 = ppval(pp2,[0,2*pi]); % y +y1 = ppval(ppdiff(pp2,1),[0,2*pi]); % y' +y2 = ppval(ppdiff(pp2,2),[0,2*pi]); % y'' +y3 = ppval(ppdiff(pp2,3),[0,2*pi]); % y''' +disp('Endpoint derivatives:') +disp([y0;y1;y2;y3]) + + + +%% EXAMPLE 4: Endpoint conditions + +% Data (200 points) +x = 2*pi*rand(1,200); +y = sin(2*x) + 0.1*randn(size(x)); + +% Breaks +breaks = linspace(0,2*pi,10); + +% Clamped endpoints, y = y' = 0 +xc = [0,0,2*pi,2*pi]; +cc = [eye(2),eye(2)]; +con = struct('xc',xc,'cc',cc); +pp1 = splinefit(x,y,breaks,con); + +% Hinged periodic endpoints, y = 0 +con = struct('xc',0); +pp2 = splinefit(x,y,breaks,con,'p'); + +% Plot +figure(4) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +plot(x,y,'.',xx,[y1;y2]), grid on +legend('data','clamped','hinged periodic') +title('EXAMPLE 4: Endpoint conditions') + + + +%% EXAMPLE 5: Airfoil data + +% Truncated data +x = [0,1,2,4,8,16,24,40,56,72,80]/80; +y = [0,28,39,53,70,86,90,79,55,22,2]/1000; +xy = [x;y]; + +% Curve length parameter +ds = sqrt(diff(x).^2 + diff(y).^2); +s = [0, cumsum(ds)]; + +% Constraints at s = 0: (x,y) = (0,0), (dx/ds,dy/ds) = (0,1) +con = struct('xc',[0 0],'yc',[0 0; 0 1],'cc',eye(2)); + +% Fit a spline with 4 pieces +pp = splinefit(s,xy,4,con); + +% Plot +figure(5) +ss = linspace(0,s(end),400); +xyfit = ppval(pp,ss); +xyb = ppval(pp,pp.breaks); +plot(x,y,'.',xyfit(1,:),xyfit(2,:),'r',xyb(1,:),xyb(2,:),'ro') +legend('data','spline','breaks') +grid on, axis equal +title('EXAMPLE 5: Airfoil data') + + + +%% EXAMPLE 6: Robust fitting + +% Data +x = linspace(0,2*pi,200); +y = sin(x) + sin(2*x) + 0.05*randn(size(x)); + +% Add outliers +x = [x, linspace(0,2*pi,60)]; +y = [y, -ones(1,60)]; + +% Fit splines with hinged conditions +con = struct('xc',[0,2*pi]); +pp1 = splinefit(x,y,8,con,0.25); % Robust fitting +pp2 = splinefit(x,y,8,con,0.75); % Robust fitting +pp3 = splinefit(x,y,8,con); % No robust fitting + +% Plot +figure(6) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +y3 = ppval(pp3,xx); +plot(x,y,'.',xx,[y1;y2;y3]), grid on +legend('data with outliers','robust, beta = 0.25','robust, beta = 0.75',... + 'no robust fitting') +title('EXAMPLE 6: Robust fitting') + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples.html b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples.html new file mode 100644 index 0000000000000000000000000000000000000000..30b8fca74117199522bf31c2dde92c7be08b570b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples.html @@ -0,0 +1,388 @@ + + + + + SPLINEFIT EXAMPLES

SPLINEFIT EXAMPLES

Contents

EXAMPLE 1: Breaks and pieces

% Data (200 points)
+x = 2*pi*rand(1,200);
+y = sin(x) + sin(2*x) + 0.2*randn(size(x));
+
+% Uniform breaks
+breaks = linspace(0,2*pi,41); % 41 breaks, 40 pieces
+pp1 = splinefit(x,y,breaks);
+
+% Breaks interpolated from data
+pp2 = splinefit(x,y,10);  % 11 breaks, 10 pieces
+
+% Plot
+figure(1)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+plot(x,y,'.',xx,[y1;y2])
+axis([0,2*pi,-2.5,2.5]), grid on
+legend('data','41 breaks, 40 pieces','11 breaks, 10 pieces')
+title('EXAMPLE 1: Breaks and pieces')
+

EXAMPLE 2: Spline orders

% Data (200 points)
+x = 2*pi*rand(1,200);
+y = sin(x) + sin(2*x) + 0.1*randn(size(x));
+
+% Splines
+pp1 = splinefit(x,y,8,1);  % Piecewise constant
+pp2 = splinefit(x,y,8,2);  % Piecewise linear
+pp3 = splinefit(x,y,8,3);  % Piecewise quadratic
+pp4 = splinefit(x,y,8,4);  % Piecewise cubic
+pp5 = splinefit(x,y,8,5);  % Etc.
+
+% Plot
+figure(2)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+y3 = ppval(pp3,xx);
+y4 = ppval(pp4,xx);
+y5 = ppval(pp5,xx);
+plot(x,y,'.',xx,[y1;y2;y3;y4;y5]), grid on
+legend('data','order 1','order 2','order 3','order 4','order 5')
+title('EXAMPLE 2: Spline orders')
+

EXAMPLE 3: Periodic boundary conditions

% Data (100 points)
+x = 2*pi*[0,rand(1,98),1];
+y = sin(x) - cos(2*x) + 0.2*randn(size(x));
+
+% No constraints
+pp1 = splinefit(x,y,10,5);
+% Periodic boundaries
+pp2 = splinefit(x,y,10,5,'p');
+
+% Plot
+figure(3)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+plot(x,y,'.',xx,[y1;y2]), grid on
+legend('data','no constraints','periodic')
+title('EXAMPLE 3: Periodic boundary conditions')
+
+% Check boundary conditions
+y0 = ppval(pp2,[0,2*pi]);             % y
+y1 = ppval(ppdiff(pp2,1),[0,2*pi]);   % y'
+y2 = ppval(ppdiff(pp2,2),[0,2*pi]);   % y''
+y3 = ppval(ppdiff(pp2,3),[0,2*pi]);   % y'''
+disp('Endpoint derivatives:')
+disp([y0;y1;y2;y3])
+
Endpoint derivatives:
+   -0.9885   -0.9885
+    0.7848    0.7848
+    3.2802    3.2802
+    5.6253    5.6253
+
+

EXAMPLE 4: Endpoint conditions

% Data (200 points)
+x = 2*pi*rand(1,200);
+y = sin(2*x) + 0.1*randn(size(x));
+
+% Breaks
+breaks = linspace(0,2*pi,10);
+
+% Clamped endpoints, y = y' = 0
+xc = [0,0,2*pi,2*pi];
+cc = [eye(2),eye(2)];
+con = struct('xc',xc,'cc',cc);
+pp1 = splinefit(x,y,breaks,con);
+
+% Hinged periodic endpoints, y = 0
+con = struct('xc',0);
+pp2 = splinefit(x,y,breaks,con,'p');
+
+% Plot
+figure(4)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+plot(x,y,'.',xx,[y1;y2]), grid on
+legend('data','clamped','hinged periodic')
+title('EXAMPLE 4: Endpoint conditions')
+

EXAMPLE 5: Airfoil data

% Truncated data
+x = [0,1,2,4,8,16,24,40,56,72,80]/80;
+y = [0,28,39,53,70,86,90,79,55,22,2]/1000;
+xy = [x;y];
+
+% Curve length parameter
+ds = sqrt(diff(x).^2 + diff(y).^2);
+s = [0, cumsum(ds)];
+
+% Constraints at s = 0: (x,y) = (0,0), (dx/ds,dy/ds) = (0,1)
+con = struct('xc',[0 0],'yc',[0 0; 0 1],'cc',eye(2));
+
+% Fit a spline with 4 pieces
+pp = splinefit(s,xy,4,con);
+
+% Plot
+figure(5)
+ss = linspace(0,s(end),400);
+xyfit = ppval(pp,ss);
+xyb = ppval(pp,pp.breaks);
+plot(x,y,'.',xyfit(1,:),xyfit(2,:),'r',xyb(1,:),xyb(2,:),'ro')
+legend('data','spline','breaks')
+grid on, axis equal
+title('EXAMPLE 5: Airfoil data')
+

EXAMPLE 6: Robust fitting

% Data
+x = linspace(0,2*pi,200);
+y = sin(x) + sin(2*x) + 0.05*randn(size(x));
+
+% Add outliers
+x = [x, linspace(0,2*pi,60)];
+y = [y, -ones(1,60)];
+
+% Fit splines with hinged conditions
+con = struct('xc',[0,2*pi]);
+pp1 = splinefit(x,y,8,con,0.25); % Robust fitting
+pp2 = splinefit(x,y,8,con,0.75); % Robust fitting
+pp3 = splinefit(x,y,8,con); % No robust fitting
+
+% Plot
+figure(6)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+y3 = ppval(pp3,xx);
+plot(x,y,'.',xx,[y1;y2;y3]), grid on
+legend('data with outliers','robust, beta = 0.25','robust, beta = 0.75',...
+    'no robust fitting')
+title('EXAMPLE 6: Robust fitting')
+
\ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples.png new file mode 100644 index 0000000000000000000000000000000000000000..3a8bb5070926c40f52631f8e3a0e526b98377acf --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c9a67ecc0caa48403485e7d708737deb1bf1acfe2765959784916d2f672d2ad +size 4004 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_01.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_01.png new file mode 100644 index 0000000000000000000000000000000000000000..9e9db855de2aa8b76348a14f3ca3e356ba939bcd --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_01.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1b3a9dca6c4e580d642bc434ac8c18b10a7b63937116df6a82895c9b4371d09 +size 11655 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_02.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_02.png new file mode 100644 index 0000000000000000000000000000000000000000..a143df3ab6c13ed2cde5730122c205812463066d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_02.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:344dd0b4956c3dc0da57c2a92b354e85766343ce49b62e298d9b2f615405e032 +size 12602 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_03.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_03.png new file mode 100644 index 0000000000000000000000000000000000000000..dc25cd3e30f4ed9a2d209efac924d68901cea86a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_03.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4086d1625fcef96884ad09c293b365a69bbd3924e8a1bdf5134d0717be2902e0 +size 9926 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_04.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_04.png new file mode 100644 index 0000000000000000000000000000000000000000..6156466c694455e84c2e36dbe2bb7f66e9bf9bbb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_04.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e43c3a2a1ac2eae55d6f6e1d503739f750cce46cfdcdc9aaeaea8f132cdece27 +size 11077 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_05.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_05.png new file mode 100644 index 0000000000000000000000000000000000000000..9b829bf838d1ff09f0858cee4933490d8d5737db --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_05.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c83d997a51bcbc4519e21baf90456e540a69fa1c089d4b1ddfe3aeb9adf86952 +size 7194 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_06.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_06.png new file mode 100644 index 0000000000000000000000000000000000000000..02469bc5f7fc27a5ce9c926b5b11ce436a596671 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/html/examples_06.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c14e0db99e65a16d61ffbe4e3f595fd88a953ffe7f6ee44ae8c724089acfe89b +size 12048 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/license.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/license.txt new file mode 100644 index 0000000000000000000000000000000000000000..1be63976f4e8261887b25451f09ac4702f1445f4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/license.txt @@ -0,0 +1,24 @@ +Copyright (c) 2010, Jonas Lundgren +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/ppdiff.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/ppdiff.m new file mode 100644 index 0000000000000000000000000000000000000000..8a338f5fb62a1af993b5bab25cb3418fbb4f5f17 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/ppdiff.m @@ -0,0 +1,52 @@ +function qq = ppdiff(pp,j) +%PPDIFF Differentiate piecewise polynomial. +% QQ = PPDIFF(PP,J) returns the J:th derivative of a piecewise +% polynomial PP. PP must be on the form evaluated by PPVAL. QQ is a +% piecewise polynomial on the same form. Default value for J is 1. +% +% Example: +% x = linspace(-pi,pi,9); +% y = sin(x); +% pp = spline(x,y); +% qq = ppdiff(pp); +% xx = linspace(-pi,pi,201); +% plot(xx,cos(xx),'b',xx,ppval(qq,xx),'r') +% +% See also PPVAL, SPLINE, SPLINEFIT, PPINT + +% Author: jonas.lundgren@saabgroup.com, 2009. + +if nargin < 1, help ppdiff, return, end +if nargin < 2, j = 1; end + +% Check diff order +if ~isreal(j) || mod(j,1) || j < 0 + msgid = 'PPDIFF:DiffOrder'; + message = 'Order of derivative must be a non-negative integer!'; + error(msgid,message) +end + +% Get coefficients +coefs = pp.coefs; +[m n] = size(coefs); + +if j == 0 + % Do nothing +elseif j < n + % Derivative of order J + D = [n-j:-1:1; ones(j-1,n-j)]; + D = cumsum(D,1); + D = prod(D,1); + coefs = coefs(:,1:n-j); + for k = 1:n-j + coefs(:,k) = D(k)*coefs(:,k); + end +else + % Derivative kills PP + coefs = zeros(m,1); +end + +% Set output +qq = pp; +qq.coefs = coefs; +qq.order = size(coefs,2); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/ppint.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/ppint.m new file mode 100644 index 0000000000000000000000000000000000000000..b1b0b7d5cef2babf5accd57aa8fd92273a63b6ed --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/ppint.m @@ -0,0 +1,69 @@ +function output = ppint(pp,a,b) +%PPINT Integrate piecewise polynomial. +% QQ = PPINT(PP,A) returns the indefinite integral from A to X of a +% piecewise polynomial PP. PP must be on the form evaluated by PPVAL. +% QQ is a piecewise polynomial on the same form. Default value for A is +% the leftmost break of PP. +% +% I = PPINT(PP,A,B) returns the definite integral from A to B. +% +% Example: +% x = linspace(-pi,pi,7); +% y = sin(x); +% pp = spline(x,y); +% I = ppint(pp,0,pi) +% +% qq = ppint(pp,pi/2); +% xx = linspace(-pi,pi,201); +% plot(xx,-cos(xx),xx,ppval(qq,xx),'r') +% +% See also PPVAL, SPLINE, SPLINEFIT, PPDIFF + +% Author: jonas.lundgren@saabgroup.com, 2009. + +if nargin < 1, help ppint, return, end +if nargin < 2, a = pp.breaks(1); end + +% Get coefficients and breaks +coefs = pp.coefs; +[m n] = size(coefs); +xb = pp.breaks; +pdim = prod(pp.dim); + +% Interval lengths +hb = diff(xb); +hb = repmat(hb,pdim,1); +hb = hb(:); + +% Integration +coefs(:,1) = coefs(:,1)/n; +y = coefs(:,1).*hb; +for k = 2:n + coefs(:,k) = coefs(:,k)/(n-k+1); + y = (y + coefs(:,k)).*hb; +end +y = reshape(y,pdim,[]); +I = cumsum(y,2); +I = I(:); +coefs(:,n+1) = [zeros(pdim,1); I(1:m-pdim)]; + +% Set preliminary indefinite integral +qq = pp; +qq.coefs = coefs; +qq.order = n+1; + +% Set output +if nargin < 3 + % Indefinite integral from a to x + if a ~= xb(1) + I0 = ppval(qq,a); + I0 = I0(:); + I0 = repmat(I0,m/pdim,1); + qq.coefs(:,n+1) = qq.coefs(:,n+1) - I0; + end + output = qq; +else + % Definite integral from a to b + output = ppval(qq,b) - ppval(qq,a); +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/splinefit.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/splinefit.m new file mode 100644 index 0000000000000000000000000000000000000000..c81027bcb9a764c0a6cab575e4f8625b8aa10ee0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/splinefit.m @@ -0,0 +1,611 @@ +function pp = splinefit(varargin) +%SPLINEFIT Fit a spline to noisy data. +% PP = SPLINEFIT(X,Y,BREAKS) fits a piecewise cubic spline with breaks +% (knots) BREAKS to the noisy data (X,Y). X is a vector and Y is a vector +% or an ND array. If Y is an ND array, then X(j) and Y(:,...,:,j) are +% matched. Use PPVAL to evaluate PP. +% +% PP = SPLINEFIT(X,Y,P) where P is a positive integer interpolates the +% breaks linearly from the sorted locations of X. P is the number of +% spline pieces and P+1 is the number of breaks. +% +% OPTIONAL INPUT +% Argument places 4 to 8 are reserved for optional input. +% These optional arguments can be given in any order: +% +% PP = SPLINEFIT(...,'p') applies periodic boundary conditions to +% the spline. The period length is MAX(BREAKS)-MIN(BREAKS). +% +% PP = SPLINEFIT(...,'r') uses robust fitting to reduce the influence +% from outlying data points. Three iterations of weighted least squares +% are performed. Weights are computed from previous residuals. +% +% PP = SPLINEFIT(...,BETA), where 0 < BETA < 1, sets the robust fitting +% parameter BETA and activates robust fitting ('r' can be omitted). +% Default is BETA = 1/2. BETA close 0 gives all data equal weighting. +% Increase BETA to reduce the influence from outlying data. BETA close +% to 1 may cause instability or rank deficiency. +% +% PP = SPLINEFIT(...,N) sets the spline order to N. Default is a cubic +% spline with order N = 4. A spline with P pieces has P+N-1 degrees of +% freedom. With periodic boundary conditions the degrees of freedom are +% reduced to P. +% +% PP = SPLINEFIT(...,CON) applies linear constraints to the spline. +% CON is a structure with fields 'xc', 'yc' and 'cc': +% 'xc', x-locations (vector) +% 'yc', y-values (vector or ND array) +% 'cc', coefficients (matrix). +% +% Constraints are linear combinations of derivatives of order 0 to N-2 +% according to +% +% cc(1,j)*y(x) + cc(2,j)*y'(x) + ... = yc(:,...,:,j), x = xc(j). +% +% The maximum number of rows for 'cc' is N-1. If omitted or empty 'cc' +% defaults to a single row of ones. Default for 'yc' is a zero array. +% +% EXAMPLES +% +% % Noisy data +% x = linspace(0,2*pi,100); +% y = sin(x) + 0.1*randn(size(x)); +% % Breaks +% breaks = [0:5,2*pi]; +% +% % Fit a spline of order 5 +% pp = splinefit(x,y,breaks,5); +% +% % Fit a spline of order 3 with periodic boundary conditions +% pp = splinefit(x,y,breaks,3,'p'); +% +% % Constraints: y(0) = 0, y'(0) = 1 and y(3) + y"(3) = 0 +% xc = [0 0 3]; +% yc = [0 1 0]; +% cc = [1 0 1; 0 1 0; 0 0 1]; +% con = struct('xc',xc,'yc',yc,'cc',cc); +% +% % Fit a cubic spline with 8 pieces and constraints +% pp = splinefit(x,y,8,con); +% +% % Fit a spline of order 6 with constraints and periodicity +% pp = splinefit(x,y,breaks,con,6,'p'); +% +% See also SPLINE, PPVAL, PPDIFF, PPINT + +% Author: jonas.lundgren@saabgroup.com, 2010. + +% 2009-05-06 Original SPLINEFIT. +% 2010-06-23 New version of SPLINEFIT based on B-splines. +% 2010-09-01 Robust fitting scheme added. +% 2010-09-01 Support for data containing NaNs. +% 2011-07-01 Robust fitting parameter added. + +% Check number of arguments +error(nargchk(3,8,nargin)); + +% Check arguments +[x,y,dim,breaks,n,periodic,beta,constr,weights] = arguments(varargin{:}); + +% Evaluate B-splines +base = splinebase(breaks,n); +pieces = base.pieces; +A = ppval(base,x); + +% Bin data +[junk,ibin] = histc(x,[-inf,breaks(2:end-1),inf]); %#ok + +% Sparse system matrix +mx = numel(x); +ii = [ibin; ones(n-1,mx)]; +ii = cumsum(ii,1); +jj = repmat(1:mx,n,1); +if periodic + ii = mod(ii-1,pieces) + 1; + A = sparse(ii,jj,A,pieces,mx); +else + A = sparse(ii,jj,A,pieces+n-1,mx); +end + +% Don't use the sparse solver for small problems +if pieces < 20*n/log(1.7*n) + A = full(A); +end + +% global randw; +% Solve +if isempty(constr) + % Solve Min norm(u*A-y) +% weights=ones(size(x)); + normweights=weights/size(A,1); + weightsmat=repmat(normweights,size(A,1),1); +% weightsmat +% pause +% randw +% A +% y + u = lsqsolve(A.*weightsmat,y.*weightsmat(1:dim,:),beta); +% u=lsqsolve(A,y,beta); +% u +% pause + else + % Evaluate constraints + B = evalcon(base,constr,periodic); + % Solve constraints + [Z,u0] = solvecon(B,constr); + % Solve Min norm(u*A-y), subject to u*B = yc + y = y - u0*A; + A = Z*A; + v = lsqsolve(A,y,beta); + u = u0 + v*Z; +end + +% Periodic expansion of solution +if periodic + jj = mod(0:pieces+n-2,pieces) + 1; + u = u(:,jj); +end + +% Compute polynomial coefficients +ii = [repmat(1:pieces,1,n); ones(n-1,n*pieces)]; +ii = cumsum(ii,1); +jj = repmat(1:n*pieces,n,1); +C = sparse(ii,jj,base.coefs,pieces+n-1,n*pieces); +coefs = u*C; +coefs = reshape(coefs,[],n); + +% Make piecewise polynomial +pp = mkpp(breaks,coefs,dim); + +%-------------------------------------------------------------------------- +function [x,y,dim,breaks,n,periodic,beta,constr,weights] = arguments(varargin) +%ARGUMENTS Lengthy input checking +% x Noisy data x-locations (1 x mx) +% y Noisy data y-values (prod(dim) x mx) +% dim Leading dimensions of y +% breaks Breaks (1 x (pieces+1)) +% n Spline order +% periodic True if periodic boundary conditions +% beta Robust fitting parameter, no robust fitting if beta = 0 +% constr Constraint structure +% constr.xc x-locations (1 x nx) +% constr.yc y-values (prod(dim) x nx) +% constr.cc Coefficients (?? x nx) +% weights weight vector for distances (Anton) + +% Reshape x-data +x = varargin{1}; +mx = numel(x); +x = reshape(x,1,mx); + +% Remove trailing singleton dimensions from y +y = varargin{2}; +dim = size(y); +while numel(dim) > 1 && dim(end) == 1 + dim(end) = []; +end +my = dim(end); + +% Leading dimensions of y +if numel(dim) > 1 + dim(end) = []; +else + dim = 1; +end + +% Reshape y-data +pdim = prod(dim); +y = reshape(y,pdim,my); + +% Check data size +if mx ~= my + mess = 'Last dimension of array y must equal length of vector x.'; + error('arguments:datasize',mess) +end + +% Treat NaNs in x-data +inan = find(isnan(x)); +if ~isempty(inan) + x(inan) = []; + y(:,inan) = []; + mess = 'All data points with NaN as x-location will be ignored.'; + warning('arguments:nanx',mess) +end + +% Treat NaNs in y-data +inan = find(any(isnan(y),1)); +if ~isempty(inan) + x(inan) = []; + y(:,inan) = []; + mess = 'All data points with NaN in their y-value will be ignored.'; + warning('arguments:nany',mess) +end + +% Check number of data points +mx = numel(x); +if mx == 0 + error('arguments:nodata','There must be at least one data point.') +end + +% Sort data +if any(diff(x) < 0) + [x,isort] = sort(x); + y = y(:,isort); +end + +% Breaks +if isscalar(varargin{3}) + % Number of pieces + p = varargin{3}; + if ~isreal(p) || ~isfinite(p) || p < 1 || fix(p) < p + mess = 'Argument #3 must be a vector or a positive integer.'; + error('arguments:breaks1',mess) + end + if x(1) < x(end) + % Interpolate breaks linearly from x-data + dx = diff(x); + ibreaks = linspace(1,mx,p+1); + [junk,ibin] = histc(ibreaks,[0,2:mx-1,mx+1]); %#ok + breaks = x(ibin) + dx(ibin).*(ibreaks-ibin); + else + breaks = x(1) + linspace(0,1,p+1); + end +else + % Vector of breaks + breaks = reshape(varargin{3},1,[]); + if isempty(breaks) || min(breaks) == max(breaks) + mess = 'At least two unique breaks are required.'; + error('arguments:breaks2',mess); + end +end + +% Unique breaks +if any(diff(breaks) <= 0) + breaks = unique(breaks); +end + +% Optional input defaults +n = 4; % Cubic splines +periodic = false; % No periodic boundaries +robust = false; % No robust fitting scheme +beta = 0.5; % Robust fitting parameter +constr = []; % No constraints +weights = ones(1,length(x)); % all ones weights + +% Loop over optional arguments +for k = 4:nargin + a = varargin{k}; + if ischar(a) && isscalar(a) && lower(a) == 'p' + % Periodic conditions + periodic = true; + elseif ischar(a) && isscalar(a) && lower(a) == 'r' + % Robust fitting scheme + robust = true; + elseif isreal(a) && isscalar(a) && isfinite(a) && a > 0 && a < 1 + % Robust fitting parameter + beta = a; + robust = true; + elseif isreal(a) && isscalar(a) && isfinite(a) && a > 0 && fix(a) == a + % Spline order + n = a; + elseif isstruct(a) && isscalar(a) + % Constraint structure + constr = a; + elseif all(size(x)==size(a)) + % weight vector + weights=a; + else + error('arguments:nonsense','Failed to interpret argument #%d.',k) + end +end + +% No robust fitting +if ~robust + beta = 0; +end + +% Check exterior data +h = diff(breaks); +xlim1 = breaks(1) - 0.01*h(1); +xlim2 = breaks(end) + 0.01*h(end); +if x(1) < xlim1 || x(end) > xlim2 + if periodic + % Move data inside domain + P = breaks(end) - breaks(1); + x = mod(x-breaks(1),P) + breaks(1); + % Sort + [x,isort] = sort(x); + y = y(:,isort); + else + mess = 'Some data points are outside the spline domain.'; + warning('arguments:exteriordata',mess) + end +end + +% Return +if isempty(constr) + return +end + +% Unpack constraints +xc = []; +yc = []; +cc = []; +names = fieldnames(constr); +for k = 1:numel(names) + switch names{k} + case {'xc'} + xc = constr.xc; + case {'yc'} + yc = constr.yc; + case {'cc'} + cc = constr.cc; + otherwise + mess = 'Unknown field ''%s'' in constraint structure.'; + warning('arguments:unknownfield',mess,names{k}) + end +end + +% Check xc +if isempty(xc) + mess = 'Constraints contains no x-locations.'; + error('arguments:emptyxc',mess) +else + nx = numel(xc); + xc = reshape(xc,1,nx); +end + +% Check yc +if isempty(yc) + % Zero array + yc = zeros(pdim,nx); +elseif numel(yc) == 1 + % Constant array + yc = zeros(pdim,nx) + yc; +elseif numel(yc) ~= pdim*nx + % Malformed array + error('arguments:ycsize','Cannot reshape yc to size %dx%d.',pdim,nx) +else + % Reshape array + yc = reshape(yc,pdim,nx); +end + +% Check cc +if isempty(cc) + cc = ones(size(xc)); +elseif numel(size(cc)) ~= 2 + error('arguments:ccsize1','Constraint coefficients cc must be 2D.') +elseif size(cc,2) ~= nx + mess = 'Last dimension of cc must equal length of xc.'; + error('arguments:ccsize2',mess) +end + +% Check high order derivatives +if size(cc,1) >= n + if any(any(cc(n:end,:))) + mess = 'Constraints involve derivatives of order %d or larger.'; + error('arguments:difforder',mess,n-1) + end + cc = cc(1:n-1,:); +end + +% Check exterior constraints +if min(xc) < xlim1 || max(xc) > xlim2 + if periodic + % Move constraints inside domain + P = breaks(end) - breaks(1); + xc = mod(xc-breaks(1),P) + breaks(1); + else + mess = 'Some constraints are outside the spline domain.'; + warning('arguments:exteriorconstr',mess) + end +end + +% Pack constraints +constr = struct('xc',xc,'yc',yc,'cc',cc); + + +%-------------------------------------------------------------------------- +function pp = splinebase(breaks,n) +%SPLINEBASE Generate B-spline base PP of order N for breaks BREAKS + +breaks = breaks(:); % Breaks +breaks0 = breaks'; % Initial breaks +h = diff(breaks); % Spacing +pieces = numel(h); % Number of pieces +deg = n - 1; % Polynomial degree + +% Extend breaks periodically +if deg > 0 + if deg <= pieces + hcopy = h; + else + hcopy = repmat(h,ceil(deg/pieces),1); + end + % to the left + hl = hcopy(end:-1:end-deg+1); + bl = breaks(1) - cumsum(hl); + % and to the right + hr = hcopy(1:deg); + br = breaks(end) + cumsum(hr); + % Add breaks + breaks = [bl(deg:-1:1); breaks; br]; + h = diff(breaks); + pieces = numel(h); +end + +% Initiate polynomial coefficients +coefs = zeros(n*pieces,n); +coefs(1:n:end,1) = 1; + +% Expand h +ii = [1:pieces; ones(deg,pieces)]; +ii = cumsum(ii,1); +ii = min(ii,pieces); +H = h(ii(:)); + +% Recursive generation of B-splines +for k = 2:n + % Antiderivatives of splines + for j = 1:k-1 + coefs(:,j) = coefs(:,j).*H/(k-j); + end + Q = sum(coefs,2); + Q = reshape(Q,n,pieces); + Q = cumsum(Q,1); + c0 = [zeros(1,pieces); Q(1:deg,:)]; + coefs(:,k) = c0(:); + % Normalize antiderivatives by max value + fmax = repmat(Q(n,:),n,1); + fmax = fmax(:); + for j = 1:k + coefs(:,j) = coefs(:,j)./fmax; + end + % Diff of adjacent antiderivatives + coefs(1:end-deg,1:k) = coefs(1:end-deg,1:k) - coefs(n:end,1:k); + coefs(1:n:end,k) = 0; +end + +% Scale coefficients +scale = ones(size(H)); +for k = 1:n-1 + scale = scale./H; + coefs(:,n-k) = scale.*coefs(:,n-k); +end + +% Reduce number of pieces +pieces = pieces - 2*deg; + +% Sort coefficients by interval number +ii = [n*(1:pieces); deg*ones(deg,pieces)]; +ii = cumsum(ii,1); +coefs = coefs(ii(:),:); + +% Make piecewise polynomial +pp = mkpp(breaks0,coefs,n); + + +%-------------------------------------------------------------------------- +function B = evalcon(base,constr,periodic) +%EVALCON Evaluate linear constraints + +% Unpack structures +breaks = base.breaks; +pieces = base.pieces; +n = base.order; +xc = constr.xc; +cc = constr.cc; + +% Bin data +[junk,ibin] = histc(xc,[-inf,breaks(2:end-1),inf]); %#ok + +% Evaluate constraints +nx = numel(xc); +B0 = zeros(n,nx); +for k = 1:size(cc,1) + if any(cc(k,:)) + B0 = B0 + repmat(cc(k,:),n,1).*ppval(base,xc); + end + % Differentiate base + coefs = base.coefs(:,1:n-k); + for j = 1:n-k-1 + coefs(:,j) = (n-k-j+1)*coefs(:,j); + end + base.coefs = coefs; + base.order = n-k; +end + +% Sparse output +ii = [ibin; ones(n-1,nx)]; +ii = cumsum(ii,1); +jj = repmat(1:nx,n,1); +if periodic + ii = mod(ii-1,pieces) + 1; + B = sparse(ii,jj,B0,pieces,nx); +else + B = sparse(ii,jj,B0,pieces+n-1,nx); +end + + +%-------------------------------------------------------------------------- +function [Z,u0] = solvecon(B,constr) +%SOLVECON Find a particular solution u0 and null space Z (Z*B = 0) +% for constraint equation u*B = yc. + +yc = constr.yc; +tol = 1000*eps; + +% Remove blank rows +ii = any(B,2); +B2 = full(B(ii,:)); + +% Null space of B2 +if isempty(B2) + Z2 = []; +else + % QR decomposition with column permutation + [Q,R,dummy] = qr(B2); %#ok + R = abs(R); + jj = all(R < R(1)*tol, 2); + Z2 = Q(:,jj)'; +end + +% Sizes +[m,ncon] = size(B); +m2 = size(B2,1); +nz = size(Z2,1); + +% Sparse null space of B +Z = sparse(nz+1:nz+m-m2,find(~ii),1,nz+m-m2,m); +Z(1:nz,ii) = Z2; + +% Warning rank deficient +if nz + ncon > m2 + mess = 'Rank deficient constraints, rank = %d.'; + warning('solvecon:deficient',mess,m2-nz); +end + +% Particular solution +u0 = zeros(size(yc,1),m); +if any(yc(:)) + % Non-homogeneous case + u0(:,ii) = yc/B2; + % Check solution + if norm(u0*B - yc,'fro') > norm(yc,'fro')*tol + mess = 'Inconsistent constraints. No solution within tolerance.'; + error('solvecon:inconsistent',mess) + end +end + + +%-------------------------------------------------------------------------- +function u = lsqsolve(A,y,beta) +%LSQSOLVE Solve Min norm(u*A-y) + +% Avoid sparse-complex limitations +if issparse(A) && ~isreal(y) + A = full(A); +end + +% Solution +u = y/A; + +% Robust fitting +if beta > 0 + [m,n] = size(y); + alpha = 0.5*beta/(1-beta)/m; + for k = 1:3 + % Residual + r = u*A - y; + rr = r.*conj(r); + rrmean = sum(rr,2)/n; + rrmean(~rrmean) = 1; + rrhat = (alpha./rrmean)'*rr; + % Weights + w = exp(-rrhat); + spw = spdiags(w',0,n,n); + % Solve weighted problem + u = (y*spw)/(A*spw); + end +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/splinefit.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/splinefit.png new file mode 100644 index 0000000000000000000000000000000000000000..398cddfdb34347c910993867cef8be1981be856c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/splinefit/splinefit.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:259845451b08c6369401f0da31bc8e1a0ae2988924355c6177cc503b57fd2fea +size 83106 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/vectorToMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/vectorToMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..e55ee05fcf2009ca50793f343d17431c14c3451d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/utils/vectorToMatrices.m @@ -0,0 +1,38 @@ +function [X Y]=vectorToMatrices(x,stateInfo) +% transforms the state vector X +% to matrix representation X and Y +% X and Y are FxN matrices +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=stateInfo.F; N=stateInfo.N; +% +X=zeros(F,N); % x-positions +Y=zeros(F,N); % y-positions + +% naive implementation +% targetsExist=stateInfo.targetsExist; +% +% xind=1; +% for i=1:N +% frames=targetsExist(i,1):targetsExist(i,2); +% nFrames=numel(frames); +% X(frames,i)=(x(xind:2:xind+2*nFrames-1)); +% +% Y(frames,i)=(x(xind+1:2:xind+2*nFrames)); +% xind=xind+nFrames*2; +% end + + +% vectorized implementation +tiInd=find(stateInfo.tiToInd); +X(tiInd)=x(1:2:end); +Y(tiInd)=x(2:2:end); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/vectorToMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/vectorToMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..1e26e1bd859159e241b1c4736834c0258b1e0ed2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CEM/vectorToMatrices.m @@ -0,0 +1,41 @@ +function [X Y]=vectorToMatrices(x,stateInfo) + +% transforms the state vector x +% to matrix representation X and Y +% X and Y are FxN matrices +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +F=stateInfo.F; N=stateInfo.N; +% +X=zeros(F,N); % x-positions +Y=zeros(F,N); % y-positions + +% naive implementation +% targetsExist=stateInfo.targetsExist; +% +% xind=1; +% for i=1:N +% frames=targetsExist(i,1):targetsExist(i,2); +% nFrames=numel(frames); +% X(frames,i)=(x(xind:2:xind+2*nFrames-1)); +% +% Y(frames,i)=(x(xind+1:2:xind+2*nFrames)); +% xind=xind+nFrames*2; +% end + + +% vectorized implementation +tiInd=find(stateInfo.tiToInd); +X(tiInd)=x(1:2:end); +Y(tiInd)=x(2:2:end); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/CenterToLeft.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/CenterToLeft.m new file mode 100644 index 0000000000000000000000000000000000000000..ffaef7cb88525a973a1ae64ae535c96f11d540e2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/CenterToLeft.m @@ -0,0 +1,19 @@ +function [L_x L_y] = CenterToLeft(x,y,height,width) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +% (x,y): Center position + +h_height = height./2; +h_width = width./2; + +L_x = x - round(h_width); +L_y = y- round(h_height); + + + + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/Idx2Types.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/Idx2Types.m new file mode 100644 index 0000000000000000000000000000000000000000..dcaefc36bfa7c4e063b6c3c4826576e2351a998e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/Idx2Types.m @@ -0,0 +1,20 @@ +function [indx,reliable,new] = Idx2Types(Trk,type) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +indx = []; +reliable = []; +new = []; +for i=1:length(Trk) + if strcmp(Trk(i).type, type) + indx = [indx,i]; + if Trk(i).reliable == 1 + reliable =[reliable,i]; + end + if Trk(i).isnew == 1 + new =[new,i]; + end + end +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/Labelling.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/Labelling.m new file mode 100644 index 0000000000000000000000000000000000000000..73447029c5ba746556a439192f51d18289a21cfb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/Labelling.m @@ -0,0 +1,7 @@ +function [param,idx] = Labelling(param) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +label = param.label; +idx = min(find(label==0)); +param.label(idx) = 1; diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/LeftToCenter.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/LeftToCenter.m new file mode 100644 index 0000000000000000000000000000000000000000..a4ead1ff6cf58b1a6f9922f6b14f3565a522a2f2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/LeftToCenter.m @@ -0,0 +1,18 @@ +function [C_x,C_y]=LeftToCenter(x,y,height,width) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + + +h_height = height/2; +h_width = width/2; + +C_x = x + round(h_width); +C_y = y+ round(h_height); + + + + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/affparam2mat.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/affparam2mat.m new file mode 100644 index 0000000000000000000000000000000000000000..c61e0716238d63699151dd080b750b153b40844c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/affparam2mat.m @@ -0,0 +1,30 @@ +function q = affparam2mat(p) +% function q = affparam2mat(p) +% +% The functions affparam2geom and affparam2mat convert a 'geometric' +% affine parameter to/from a matrix form (2x3 matrix). +% +% affparam2geom converts a 2x3 matrix to 6 affine parameters +% (x, y, th, scale, aspect, skew), and affparam2mat does the inverse. +% +% p(6,n) : [dx dy sc th sr phi]' +% q(6,n) : [q(1) q(3) q(4); q(2) q(5) q(6)] +% +% Reference "Multiple View Geometry in Computer Vision" by Richard +% Hartley and Andrew Zisserman. + +% Copyright (C) Jongwoo Lim and David Ross. All rights reserved. + + +sz = size(p); +if (length(p(:)) == 6) + p = p(:); +end +s = p(3,:); th = p(4,:); r = p(5,:); phi = p(6,:); +cth = cos(th); sth = sin(th); cph = cos(phi); sph = sin(phi); +ccc = cth.*cph.*cph; ccs = cth.*cph.*sph; css = cth.*sph.*sph; +scc = sth.*cph.*cph; scs = sth.*cph.*sph; sss = sth.*sph.*sph; +q(1,:) = p(1,:); q(2,:) = p(2,:); +q(3,:) = s.*(ccc +scs +r.*(css -scs)); q(4,:) = s.*(r.*(ccs -scc) -ccs -sss); +q(5,:) = s.*(scc -ccs +r.*(ccs +sss)); q(6,:) = s.*(r.*(ccc +scs) -scs +css); +q = reshape(q, sz); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/calc_overlap2.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/calc_overlap2.m new file mode 100644 index 0000000000000000000000000000000000000000..42253eaa59114fd6981ad43733177ea81602b3fd --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/calc_overlap2.m @@ -0,0 +1,44 @@ +function [ov, ov_n1, ov_n2] = calc_overlap2(cur_det,prev_det,fr) +%%f2 can be an array and f1 should be a scalar. +%%% this will find the overlap between dres1(f1) (only one) and all detection windows in dres2(f2(:)) + + %% Calculate overlap + n2 = length(prev_det.x); + + cx1 = cur_det.x(fr); + cx2 = cur_det.x(fr) + cur_det.w(fr)-1; + cy1 = cur_det.y(fr); + cy2 = cur_det.y(fr) + cur_det.h(fr)-1; + + gx1 = prev_det.x; + gx2 = prev_det.x + prev_det.w-1; + gy1 = prev_det.y; + gy2 = prev_det.y + prev_det.h-1; + + ca = (cur_det.w(fr)).* (cur_det.h(fr)); % area + ga = (prev_det.w).* (prev_det.h); + + + + xx1 = max(cx1, gx1); + yy1 = max(cy1, gy1); + xx2 = min(cx2, gx2); + yy2 = min(cy2, gy2); + w = xx2 - xx1 + 1; + h = yy2 - yy1 + 1; + + inds = find((w>0).*(h>0)); + ov = zeros(1,n2); + ov_n1 = zeros(1,n2); + ov_n2 = zeros(1,n2); + inter = w(inds).*h(inds); %% area of overlap + u = ca + ga(inds) - w(inds).*h(inds); %% area of union + ov(inds) = inter./u; % intersection/union + ov_n1(inds) = inter ./ ca; + ov_n2(inds) = inter ./ga(inds); +end + + + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/estimation_size.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/estimation_size.m new file mode 100644 index 0000000000000000000000000000000000000000..4cdfd47b7a9298ef821053bd422baea1cfc77169 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/estimation_size.m @@ -0,0 +1,28 @@ +function [size_state] = estimation_size(Trk,ystate,fr) + +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +init_time = Trk.ifr; +nof_s = 4; + +sum_size = Trk.state{end}(3:4); +if fr == Trk.last_update; + size_state = ystate(3:4); +else + if fr > init_time + 3 + for j=1:nof_s + sum_size = sum_size + Trk.state{end-j}(3:4); + end + size_state = sum_size/(nof_s+1); + else + all_est = cell2mat(Trk.state); + sum_size = sum_size + sum(all_est(3:4,:),2); + size_state = sum_size/ (size(all_est,2)+1); + end + +end + + + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/motion_affinity.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/motion_affinity.m new file mode 100644 index 0000000000000000000000000000000000000000..0a6f8308cef15d92360bef6b5d923b0bc5c89e31 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/motion_affinity.m @@ -0,0 +1,5 @@ +function prob_pdf = motion_affinity(x,mean,var) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +prob_pdf = exp(-0.5*(x-mean)'*inv(var)*(x-mean)); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/munkres.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/munkres.m new file mode 100644 index 0000000000000000000000000000000000000000..c150740ddc41c87a35fbe636f346db0953c75555 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/Common/munkres.m @@ -0,0 +1,154 @@ +function [assignment,cost] = munkres(costMat) +% MUNKRES Munkres Assign Algorithm +% +% [ASSIGN,COST] = munkres(COSTMAT) returns the optimal assignment in ASSIGN +% with the minimum COST based on the assignment problem represented by the +% COSTMAT, where the (i,j)th element represents the cost to assign the jth +% job to the ith worker. +% + +% This is vectorized implementation of the algorithm. It is the fastest +% among all Matlab implementations of the algorithm. + +% Examples +% Example 1: a 5 x 5 example +%{ +[assignment,cost] = munkres(magic(5)); +[assignedrows,dum]=find(assignment); +disp(assignedrows'); % 3 2 1 5 4 +disp(cost); %15 +%} +% Example 2: 400 x 400 random data +%{ +n=400; +A=rand(n); +tic +[a,b]=munkres(A); +toc % about 6 seconds +%} + +% Reference: +% "Munkres' Assignment Algorithm, Modified for Rectangular Matrices", +% http://csclab.murraystate.edu/bob.pilgrim/445/munkres.html + +% version 1.0 by Yi Cao at Cranfield University on 17th June 2008 + +assignment = false(size(costMat)); +cost = 0; + +costMat(costMat~=costMat)=Inf; +validMat = costMatMxR_t + +% here, the dimension of total scatter matrix may be controlled... +% totalTermFactorZ = totalTermFactorZ(:,1:??); + +num_total = floor(size(totalTermFactorZ,2)); + +totalTermFactorZ = totalTermFactorZ(:,1:num_total); + +% totalTermFactorZ_Limit = ILDA.totalTermFactorZ_Limit; +if num_total > totalTermFactorZ_Limit + totalTermFactorZ = totalTermFactorZ(:,1:totalTermFactorZ_Limit); +end + +[spanningSetTau upperTriMat] = qr(totalTermFactorZ'*betweenEigVect, 0); % O(MR_tR_b + max(R_t,R_b)^3) spanningSetTau->R_txR + +% removing non-significant components for further speed-up +qrThreshold = 0.0001; +upperTriSum = sum(abs(upperTriMat),2); +upperTriRowIndex = find(upperTriSum>qrThreshold)'; +spanningSetTau = spanningSetTau(:,upperTriRowIndex); + +halfMatrix = spanningSetTau' * (totalTermFactorZ' * betweenEigVect); % O(MR_tR_b + RR_tR_b) halfMatrix->RxR_b +compositeMatrix = halfMatrix * betweenEigVal * halfMatrix'; % O(RR_bR_b + R^2R_b) compositeMatrix->RxR: +[U_N S_N U_NT] = svd(compositeMatrix); % O(R^3) + +testRow = diag(S_N); +testIdx = find(testRow>eigenThreshold); +U_N = U_N(:,testIdx); +S_N = diag( testRow(testIdx) ); + +DiscriminativeComponents = totalTermFactorZ * (spanningSetTau * U_N); % O(R^2R_t + MR^2) + +% here, the dimension of the discriminant components may be controlled... diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fGetSbModel_v2.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fGetSbModel_v2.m new file mode 100644 index 0000000000000000000000000000000000000000..729a8b6574b5861cdf7cb92e2766efc6714fa6b1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fGetSbModel_v2.m @@ -0,0 +1,55 @@ +function [meanVector, noOfSample, eigenVectors, eigenValues, samplePerClass, meanPerClass] = fGetSbModel_v2(featureVectorInCol, featureLabel, eigenThreshold) +% ----------------------------------------------------------------------- +% Performing principal component analysis of between-class scatter matrix +% +% written by T-K. Kim and S-F. Wong, 2007 +% ----------------------------------------------------------------------- + +% Input: +% featureVectorInCol: MxN matrix - each column is a feature vector of the raw dataset, M - dimension size, N - the number of sample +% featureLabel: 1xN vector - each cell stores the class label of a sample +% eigenThreshold: 1x1 value - the min value of eigenvalues to be selected + + +% Output: +% meanVector: Mx1 vector - the mean vector of all raw data, M is the dimension +% noOfSample: 1x1 value - the number of sample in the raw data +% eigenVectors: MxR matrix - each column is an eigenvector of the between scatter matrix, R is the reduced dimension +% eigenValues: RxR matrix - diagonal matrix storing the eigenvalues of the between scatter matrix +% samplePerClass: 1xC vector - each cell stores the number of sample per class, and C is the number of class +% meanPerClass: RxC matrix - each column stores the mean vector of a certain class +% ----------------------------------------------------------------------- + + +[noOfDimension, noOfSample]=size(featureVectorInCol); + +labelSet = unique(featureLabel); +noOfClass = size(labelSet,2); + +meanVector = mean(featureVectorInCol, 2); %O(MN) +samplePerClass = zeros(1,noOfClass); +meanPerClass = zeros(noOfDimension, noOfClass); + +%O(MN) +for i=1:noOfClass + classIndex = find(featureLabel==labelSet(i)); + samplePerClass(1,i) = length(classIndex); + classMean = mean(featureVectorInCol(:,classIndex),2); + meanPerClass(:,i)=classMean; +end + +meanMatrix = repmat(meanVector, 1, noOfClass); +PhiMatrix = (meanPerClass - meanMatrix).*repmat( sqrt(samplePerClass), noOfDimension, 1); %O(MC) PhiMatrix->MxC +S_b = PhiMatrix'*PhiMatrix; %O(MC^2) S_b->CxC + +[U Sigma V_T] = svd(S_b); %O(C^3) + +testRow = diag(Sigma); +testIdx = find(testRow>eigenThreshold);%*noOfSample); +U = U(:,testIdx); +Sigma = diag( testRow(testIdx) ); + +eigenVectors = PhiMatrix*(U*inv(sqrt(Sigma))); %O(MC^2+C^3) +eigenValues = Sigma; + +meanPerClass = eigenVectors' * ( meanPerClass - repmat(meanVector, 1, size(meanPerClass,2)) ); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fGetStModel.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fGetStModel.m new file mode 100644 index 0000000000000000000000000000000000000000..0081d610c2212dfa99da337bd69486dd74321c4c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fGetStModel.m @@ -0,0 +1,25 @@ +function [meanVector, noOfSample, eigenVectors, eigenValues] = fGetStModel(featureVectorInCol, eigenThreshold) +% ----------------------------------------------------------------------- +% Performing principal component analysis of total scatter matrix +% +% written by T-K. Kim and S-F. Wong, 2007 +% ----------------------------------------------------------------------- + +% Input: +% featureVectorInCol: MxN matrix - each column is a feature vector of the raw dataset, M - dimension size, N - the number of sample +% eigenThreshold: 1x1 value - the min value of eigenvalues to be selected + +% Output: +% meanVector: Mx1 vector - the mean vector of the raw data +% noOfSample: 1x1 value - the number of sample in the raw data +% eigenVectors: MxR matrix - each column is a principal component, R is the reduced dimension +% eigenValues: RxR matrix - diagonal matrix storing the eigenvalues of the total scatter matrix +% ----------------------------------------------------------------------- + + +[noOfDimension, noOfSample] = size(featureVectorInCol); + +[principalComponents, tmpEigVal, meanVector, reducedData] = fPCA(featureVectorInCol, eigenThreshold); + +eigenVectors = principalComponents; +eigenValues = tmpEigVal; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fMergeSb.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fMergeSb.m new file mode 100644 index 0000000000000000000000000000000000000000..4a8e7fd1bbbb478c2202320010567fbe8d87d9b5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fMergeSb.m @@ -0,0 +1,135 @@ +function [meanVector, noOfSample, eigenVectors, eigenValues, samplePerClass, meanPerClass] = fMergeSb(inMean_1, inNS_1, inEVect_1, inEVal_1, samplePerClass_1, meanPerClass_1, featureLabel_1, inMean_2, inNS_2, inEVect_2, inEVal_2, samplePerClass_2, meanPerClass_2, featureLabel_2, eigenThreshold) +% ----------------------------------------------------------------------- +% Merging two "between scatter matrices" +% +% written by T-K. Kim and S-F. Wong, 2007 +% ----------------------------------------------------------------------- + +% Input: +% inMean_1: Mx1 vector - the mean vector of the old data +% inNS_1: 1x1 value - the number of sample in the old data +% inEVect_1: MxR_1 matrix - each column is an eigenvector of the between scatter matrix of the old data, R_1 is the reduced dimension +% inEVal_1: R_1xR_1 matrix - diagonal matrix storing the eigenvalues of the between scatter matrix of the old data +% samplePerClass_1: 1xC_1 vector - each cell stores the number of sample per class in the old data, and C_1 is the number of class +% meanPerClass_1: R_1xC_1 matrix - each column stores the mean vector of a certain class in the old data +% featureLabel_1: 1xN_1 vector - each cell stores the class label of a sample in the old data + +% inMean_2: Mx1 vector - the mean vector of the new data +% inNS_2: 1x1 value - the number of sample in the new data +% inEVect_2: MxR_2 matrix - each column is an eigenvector of the total scatter matrix of the new data, R_2 is the reduced dimension +% inEVal_2: R_2xR_2 matrix - diagonal matrix storing the eigenvalues of the total scatter matrix of the new data +% samplePerClass_2: 1xC_2 vector - each cell stores the number of sample per class in the new data, and C_2 is the number of class +% meanPerClass_2: R_2xC_2 matrix - each column stores the mean vector of a certain class in the new data +% featureLabel_2: 1xN_2 vector - each cell stores the class label of a sample in the new data + + +% Output: +% meanVector: Mx1 vector - the updated mean vector of all raw data, M is the dimension +% noOfSample: 1x1 value - the number of sample in the raw data +% eigenVectors: MxR matrix - each column is an eigenvector of the between scatter matrix, R is the reduced dimension +% eigenValues: RxR matrix - diagonal matrix storing the eigenvalues of the between scatter matrix +% samplePerClass: 1xC vector - each cell stores the number of sample per class, and C is the number of class +% meanPerClass: RxC matrix - each column stores the mean vector of a certain class +% ----------------------------------------------------------------------- + +noOfDimension = size(inEVect_1, 1); +noOfSample = inNS_1 + inNS_2; +meanVector = (inMean_1 * inNS_1 + inMean_2 * inNS_2 ) / (noOfSample); + +% QR: +residueThreshold = 0.0001; + +GMatrix = inEVect_1' *inEVect_2; % O(R_1MR_2) GMatrix->R_1xR_2 +meanDiff = inMean_1-inMean_2; +residue = inEVect_2 - inEVect_1 * (GMatrix); % O(MR_1R_2) +residueSumRow = sum(abs(residue),1); +pureResidue = residue(:,find(residueSumRow>residueThreshold)); +meanResidue = meanDiff - inEVect_1 * (inEVect_1' * meanDiff); % O(MR_1) +meanResidueSumRow = sum(abs(meanResidue),1); +meanResidue = meanResidue(:,find(meanResidueSumRow>residueThreshold)); + +[OrthSubMatrix upperTri] = qr([pureResidue meanResidue], 0); % O(MR_2^2) OrthSubMatrix->MxR + +qrThreshold = 0.0001; +upperTriSum = sum(abs(upperTri),2); +upperTriRowIndex = find(upperTriSum>qrThreshold)'; +OrthSubMatrix = OrthSubMatrix(:,upperTriRowIndex); + +% %%% Removing zero-columns in OrthMatrix::: +nonZeroThreshold = 0.0001; +OrthMatrixSum = sum(abs(OrthSubMatrix),1); +nonZeroIndex = find(OrthMatrixSum>nonZeroThreshold); +OrthSubMatrix = OrthSubMatrix(:,nonZeroIndex); + +%SVD +TMatrix = OrthSubMatrix' * inEVect_2; % O(MRR_2) TMatrix->RxR_2 +mGMatrix = inEVect_1'*meanDiff; % O(MR_1) mGMatrix->R_1x1 +mTMatrix = OrthSubMatrix'*meanDiff; % O(MR) mTMatrix->Rx1 + +reducedDim = size(inEVect_1, 2) + size(OrthSubMatrix,2); + +term1 = zeros(reducedDim, reducedDim); +term1(1:size(inEVect_1,2),1:size(inEVect_1,2)) = inEVal_1; +term2 = [GMatrix*inEVal_2*GMatrix' GMatrix*inEVal_2*TMatrix'; TMatrix*inEVal_2*GMatrix' TMatrix*inEVal_2*TMatrix']; % O( max(R_1, R_2, R)^3) +term4 = [mGMatrix*mGMatrix' mGMatrix*mTMatrix'; mTMatrix*mGMatrix' mTMatrix*mTMatrix'] *((inNS_1*inNS_2)/(noOfSample)); % O( max(R_1, R)^2) + +% for common classes +term3 = zeros(reducedDim, reducedDim); +% O(C^2 M R_i) +labelSet1 = union([],featureLabel_1); +labelSet2 = union([],featureLabel_2); +labelSet_com = intersect(labelSet1, labelSet2); +if(length(labelSet_com)) + for i=1:length(labelSet_com) + idx1 = find(labelSet_com(i)==labelSet1); + idx2 = find(labelSet_com(i)==labelSet2); + + coeff = (-samplePerClass_1(1,idx1)*samplePerClass_2(1,idx2)) / (samplePerClass_1(1,idx1)+samplePerClass_2(1,idx2)) ; + classmeanDiff = (inEVect_1 * meanPerClass_1(:,idx1) + inMean_1 - inEVect_2 * meanPerClass_2(:,idx2) - inMean_2); % O(MR_iC) + cGMatrix = inEVect_1'*classmeanDiff; % O(R_1M) + cTMatrix = OrthSubMatrix'*classmeanDiff; % O(RM) + term3 = term3 + [cGMatrix*cGMatrix' cGMatrix*cTMatrix';cTMatrix*cGMatrix' cTMatrix*cTMatrix']*coeff; % O(max(R_1, R)^2) + end +end + +CompositeMatrix = term1+term2+term3+term4; % CompositeMatrix->RxR + +[U Sigma V_T] = svd(CompositeMatrix); % O(R^3) + +testRow = diag(Sigma); + + +testIdx = find(testRow>eigenThreshold);%*noOfSample); +U = U(:,testIdx); +Sigma = diag( testRow(testIdx) ); + + +eigenVectors = [inEVect_1 OrthSubMatrix] * U; % O(M (R_1+R) R) +eigenValues = Sigma; + + +% updates other params. +featureLabel = horzcat(featureLabel_1, featureLabel_2); +labelSet = union([],featureLabel); +noOfClass = size(labelSet,2); +samplePerClass = zeros(1,noOfClass); +meanPerClass = zeros( size(eigenVectors, 2), noOfClass); + +for i=1:length(labelSet) + idx1 = find(labelSet(i)==labelSet1); + idx2 = find(labelSet(i)==labelSet2); + subMean_3 = zeros(noOfDimension,1); + + if(length(idx1)) + samplePerClass(1,i) = samplePerClass(1,i) + samplePerClass_1(1,idx1); + subMean_3 = subMean_3 + samplePerClass_1(1,idx1)*(inEVect_1 * meanPerClass_1(:,idx1) + inMean_1); + end + if(length(idx2)) + samplePerClass(1,i) = samplePerClass(1,i) + samplePerClass_2(1,idx2); + subMean_3 = subMean_3 + samplePerClass_2(1,idx2)*(inEVect_2 * meanPerClass_2(:,idx2) + inMean_2); + end + + subMean_3 = subMean_3/samplePerClass(1,i); + meanPerClass(:,i) = eigenVectors'*(subMean_3-meanVector); +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fMergeSt.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fMergeSt.m new file mode 100644 index 0000000000000000000000000000000000000000..e949b04bef4b1dce210d7ce380da75dbcf5e1e81 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fMergeSt.m @@ -0,0 +1,78 @@ +function [outMean, outNSample, outEVect, outEVal] = fMergeSt(inMean_1, inNS_1, inEVect_1, inEVal_1, inMean_2, inNS_2, inEVect_2, inEVal_2, eigenThreshold) +% ----------------------------------------------------------------------- +% Merging two "total scatter matrices" +% +% The detailed algorithm here is the same as P.Hall and et al.'s method +% just except the covariance matrix is replaced by the scatter matrix. +% (P.Hall, D.Marshall and R.Martin, Merging and splitting eigenspace +% models, IEEE Trans. on PAMI, 2000.) +% +% written by T-K. Kim and S-F. Wong, 2007 +% ----------------------------------------------------------------------- + +% Input: +% inMean_1: Mx1 matrix - the mean vector of the old data +% inNS_1: 1x1 value - the number of sample in the old data +% inEVect_1: MxR_1 matrix - each column is an eigenvector of the total scatter matrix of the old data, R_1 is the reduced dimension +% inEVal_1: R_1xR_1 matrix - diagonal matrix storing the eigenvalues of the total scatter matrix of the old data +% inMean_2: Mx1 matrix - the mean vector of the new data +% inNS_2: 1x1 value - the number of sample in the new data +% inEVect_2: MxR_2 matrix - each column is an eigenvector of the total scatter matrix of the new data, R_2 is the reduced dimension +% inEVal_2: R_2xR_2 matrix - diagonal matrix storing the eigenvalues of the total scatter matrix of the new data + +% Output: +% outMean: Mx1 vector - the updated mean vector of all raw data, M is the dimension +% outNSample: 1x1 value - the number of sample in the raw data +% outEVect: MxR matrix - each column is an eigenvector of the total scatter matrix, R is the reduced dimension +% outEVal: RxR matrix - diagonal matrix storing the eigenvalues of the total scatter matrix +% ----------------------------------------------------------------------- + +% updating global mean +outNSample = inNS_1 + inNS_2; +outMean = (inMean_1 * inNS_1 + inMean_2 * inNS_2 ) / outNSample; + + +% QR: +residueThreshold = 0.0001; + +GMatrix = inEVect_1' *inEVect_2; % O(R_1MR_2) +meanDiff = inMean_1-inMean_2; +residue = inEVect_2 - inEVect_1 * (GMatrix); % O(MR_1R_2) +residueSumRow = sum(abs(residue),1); +pureResidue = residue(:,find(residueSumRow>residueThreshold)); +meanResidue = meanDiff - inEVect_1 * (inEVect_1' * meanDiff); % O(MR_1) +meanResidueSumRow = sum(abs(meanResidue),1); +meanResidue = meanResidue(:,find(meanResidueSumRow>residueThreshold)); + +[OrthSubMatrix upperTri] = qr([pureResidue meanResidue], 0); % O(MR_2^2) OrthSubMatrix->MxR + +% QR redundancy removal: +qrThreshold = 0.0001; +upperTriSum = sum(abs(upperTri),2); +upperTriRowIndex = find(upperTriSum>qrThreshold)'; +OrthSubMatrix = OrthSubMatrix(:,upperTriRowIndex); + +%SVD +TMatrix = OrthSubMatrix' * inEVect_2; % O(MRR_2) TMatrix->RxR_2 +mGMatrix = inEVect_1'*meanDiff; % O(MR_1) mGMatrix->R_1x1 +mTMatrix = OrthSubMatrix'*meanDiff; % O(MR) mTMatrix->Rx1 + +reducedDim = size(inEVect_1, 2) + size(OrthSubMatrix,2); + +term1 = zeros(reducedDim, reducedDim); +term1(1:size(inEVect_1,2),1:size(inEVect_1,2)) = inEVal_1; +term2 = [GMatrix*inEVal_2*GMatrix' GMatrix*inEVal_2*TMatrix'; TMatrix*inEVal_2*GMatrix' TMatrix*inEVal_2*TMatrix'];%*(inNS_2/outNSample); % O( max(R_1, R_2, R)^3) +term3 = [mGMatrix*mGMatrix' mGMatrix*mTMatrix'; mTMatrix*mGMatrix' mTMatrix*mTMatrix'] *((inNS_1*inNS_2)/(outNSample));%*outNSample)); % O( max(R_1, R)^2) + +CompositeMatrix = term1 + term2 + term3; % CompositeMatrix->RxR +[U Sigma V_T] = svd(CompositeMatrix); % O(R^3) + +testRow = diag(Sigma); +testIdx = find(testRow>eigenThreshold); + +U = U(:,testIdx); +Sigma = diag( testRow(testIdx) ); + +outEVal = Sigma; +outEVect = [inEVect_1 OrthSubMatrix] * U; % O(M (R_1+R) R) + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fPCA.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fPCA.m new file mode 100644 index 0000000000000000000000000000000000000000..73c5f67377412da38c1546d00c322464e70a26d1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/fPCA.m @@ -0,0 +1,39 @@ +function [principalComponents, eigenValues, meanVector, projectedData] = fPCA(featureVectorInCol, eigenThreshold) +% ----------------------------------------------------------------------- +% Low-dimensional batch eigen-computation when M>>N +% +% written by T-K, Kim and S-F. Wong, 2007 +% ----------------------------------------------------------------------- + +% Input: +% featureVectorInCol: MxN matrix - input data, M=dimension, N=noOfSample +% eigenThreshold: 1x1 value - the min value of eigenvalues to be selected + +% Output: +% principalComponents: MxR matrix - each column is a PC, R is the reduced dimension +% eigenValues: RxR - diagonal matrix storing the eigenvalues which are > eigenThreshold +% meanVector: Mx1 vector - the mean vector of the input data +% projectedData: RxN matrix - the projected data organised in column +% ----------------------------------------------------------------------- + + +[noOfDimension, noOfSample] = size(featureVectorInCol); +meanVector = mean(featureVectorInCol, 2); % O(MN) + +featureVectorInCol=double(featureVectorInCol); +data = featureVectorInCol - repmat(meanVector, 1, noOfSample); + +normCovMatrix = data'*data; % O(N^2M) normCovMatrix->NxN +[V_NN, S_NN,V_NNT] = svd(normCovMatrix); %O(N^3) V_NN->NxR + +% Component selection +testRow = diag(S_NN); +testIdx = find(testRow>eigenThreshold); +V_NN = V_NN(:,testIdx); +S_NN = diag( testRow(testIdx) ); + + +invSigma_NN = inv(diag(sqrt(diag(S_NN)))); +principalComponents = data*(V_NN*invSigma_NN); % O(NR^2+MNR) +eigenValues = S_NN; +projectedData = principalComponents'*data; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/pseudo_code.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/pseudo_code.m new file mode 100644 index 0000000000000000000000000000000000000000..12cf3a0cb5d71337cc17adb3cb6b5072dd4fc505 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/ILDA/pseudo_code.m @@ -0,0 +1,38 @@ + +% ILDA pseudocode + +% written by T-K. Kim, 2007 + +dataset_1 = init_data; label_1 = init_label; + + +for nupdate=0:numOfupdate + + if(nupdate==0) + + % init proc + [m_1, M_1, TeigenVect_1, TeigenVal_1] = fGetStModel(dataset_1, eigenThreshold); + [m_1, M_1, BeigenVect_1, BeigenVal_1, samplePerClass_1, meanPerClass_1] = fGetSbModel(dataset_1, label_1, eigenThreshold); + [DiscriminativeComponents D] = fGetDiscriminativeComponents(TeigenVect_1, TeigenVal_1, BeigenVect_1, BeigenVal_1, M_1, DeigenThreshold); + + else + + % for new data + dataset_2 = New_data; label_2 = New_label; + [m_2, M_2, TeigenVect_2, TeigenVal_2] = fGetStModel(dataset_2, eigenThreshold); + [m_2, M_2, BeigenVect_2, BeigenVal_2, samplePerClass_2, meanPerClass_2] = fGetSbModel(dataset_2, label_2, eigenThreshold); + + % update + [outMean, outNSample, outEVect_t, outEVal_t] = fMergeSt(m_1, M_1, TeigenVect_1, TeigenVal_1, m_2, M_2, TeigenVect_2, TeigenVal_2, eigenThreshold); + [outMean, outNSample, outEVect_b, outEVal_b, outSamplePerClass, outMeanPerClass] = fMergeSb(m_1, M_1, BeigenVect_1, BeigenVal_1, samplePerClass_1, meanPerClass_1, label_1, m_2, M_2, BeigenVect_2, BeigenVal_2, samplePerClass_2, meanPerClass_2, label_2, eigenThreshold); + [DiscriminativeComponents D] = fGetDiscriminativeComponents(outEVect_t, outEVal_t, outEVect_b, outEVal_b, outNSample,DeigenThreshold); + + % update variables + m_1 = outMean; M_1 = outNSample; TeigenVect_1=outEVect_t; TeigenVal_1=outEVal_t; + BeigenVect_1=outEVect_b; BeigenVal_1=outEVal_b; + samplePerClass_1=outSamplePerClass; meanPerClass_1=outMeanPerClass; + label_1 = horzcat(label_1,label_2); + + end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/README.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..e42214e1e36fc5d15678183d9b68c68d3cc9b685 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/README.txt @@ -0,0 +1,56 @@ +Robust Online Multi-Object Tracking based on Tracklet Confidence and Online Discriminative Appearance Learning +Copyright (C) 2014 Seung-Hwan Bae + + + +IMPORTANT: + +1. If you use this code, please cite the following publication. + +[1] Robust Online Multi-Object Tracking based on Tracklet Confidence and Online Discriminative Appearance Learning, +Seung-Hwan Bae and Kuk-Jin Yoon, IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Columbus, June, 2014. + +2. For simplifying the implementation and reducing computational complexity, +this code has been slightly modified from the one that was used to produce results of our CVPR 2014 paper. +Therefore, the results produced by this software can be different from those provided in our paper. + +3. Questions regarding the code may be directed to Seung-Hwan Bae (bshwan@gist.ac.kr; caegar07@gmail.com). + +4. The code was tested on MATLAB 2012a (Windows 7). + + + +INSTALLING & RUNNING (MATLAB 64bit) + +1. Unpack cmot-v1.0.zip + +2. Download the ETHMS-Bahnhof sequence (captured from the left camera, seq03-img-left.tar) from http://www.vision.ee.ethz.ch/~aess/dataset/ +and put the sequence into ./Sequences/ETH_Bahnhof/ + +3. Download Incremental LDA code package (ILDA07.zip) from http://www.iis.ee.ic.ac.uk/icvl/code.htm and place it into ./ILDA/ +Note that you should use the fGetDiscriminativeComponents_v2 and fGetSbModel_v2 instead of fGetDiscriminativeComponents and fGetSbModel in the ILDA package. +(This procedure can be omitted if you do not want to use online appearance learning. To this end, set param.use_ILDA = 0.) + +4. Run tracking_demo.m + +5. The tracking results will be given in the folder: ./Results/ + + + + +CHANGES + +v1.1 Fixed MOT_Local_Association, mot_motion_similarity and km_estimation. +v1.2 Fixed MOT_Global_Association and fGetSbModel_v2. +v1.3 Fixed MOT_State_Update, fGetSbModel_v2, fGetDiscriminativeComponents_v2 and mot_appearance_model_generation. + + + + + + + + + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/kf_loop.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/kf_loop.m new file mode 100644 index 0000000000000000000000000000000000000000..f6547b26f3dc1f417e4171cf79c2c849ebf95ef3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/kf_loop.m @@ -0,0 +1,71 @@ +%KF_LOOP Performs the prediction and update steps of the Kalman filter +% for a set of measurements. +% +% Syntax: +% [MM,PP] = KF_LOOP(X,P,H,R,Y,A,Q) +% +% In: +% X - Nx1 initial estimate for the state mean +% P - NxN initial estimate for the state covariance +% H - DxN measurement matrix +% R - DxD measurement noise covariance +% Y - DxM matrix containing all the measurements. +% A - Transition matrix of the discrete model (optional, default identity) +% Q - Process noise of the discrete model (optional, default zero) +% +% Out: +% MM - Filtered state mean sequence +% PP - Filtered state covariance sequence +% +% Description: +% Calculates state estimates for a set measurements using the +% Kalman filter. This function is for convience, as it basically consists +% only of a space reservation for the estimates and of a for-loop which +% calls the predict and update steps of the KF for each time step in +% the measurements. +% +% See also: +% KF_PREDICT, KF_UPDATE + +% History: +% +% 12.2.2007 JH Initial version. +% +% Copyright (C) 2007 Jouni Hartikainen +% +% This software is distributed under the GNU General Public +% Licence (version 2 or later); please refer to the file +% Licence.txt, included with the software, for details. + +function [MM,PP] = kf_loop(X,P,H,R,Y,A,Q) + + % Check the input parameters. + if nargin < 5 + error('Too few arguments'); + end + if nargin < 6 + A = []; + end + if nargin < 7 + Q = []; + end + + % Apply the defaults + if isempty(A) + A = eye(size(X,1)); + end + if isempty(Q) + Q = zeros(size(X,1)); + end + + % Space for the estimates. + MM = zeros(size(X,1), size(Y,2)); + PP = zeros(size(X,1), size(X,1), size(Y,2)); + + % Filtering steps. + for i = 1:size(Y,2) + [X,P] = kf_predict(X,P,A,Q); + [X,P] = kf_update(X,P,Y(:,i),H,R); + MM(:,i) = X; + PP(:,:,i) = P; + end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/kf_predict.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/kf_predict.m new file mode 100644 index 0000000000000000000000000000000000000000..94634bb636d940247bf5574289109050b215464e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/kf_predict.m @@ -0,0 +1,94 @@ +%KF_PREDICT Perform Kalman Filter prediction step +% +% Syntax: +% [X,P] = KF_PREDICT(X,P,A,Q,B,U) +% +% In: +% X - Nx1 mean state estimate of previous step +% P - NxN state covariance of previous step +% A - Transition matrix of discrete model (optional, default identity) +% Q - Process noise of discrete model (optional, default zero) +% B - Input effect matrix (optional, default identity) +% U - Constant input (optional, default empty) +% +% Out: +% X - Predicted state mean +% P - Predicted state covariance +% +% Description: +% Perform Kalman Filter prediction step. The model is +% +% x[k] = A*x[k-1] + B*u[k-1] + q, q ~ N(0,Q). +% +% The predicted state is distributed as follows: +% +% p(x[k] | x[k-1]) = N(x[k] | A*x[k-1] + B*u[k-1], Q[k-1]) +% +% The predicted mean x-[k] and covariance P-[k] are calculated +% with the following equations: +% +% m-[k] = A*x[k-1] + B*u[k-1] +% P-[k] = A*P[k-1]*A' + Q. +% +% If there is no input u present then the first equation reduces to +% m-[k] = A*x[k-1] +% +% History: +% +% 26.2.2007 JH Added the distribution model for the predicted state +% and equations for calculating the predicted state mean and +% covariance to the description section. +% +% See also: +% KF_UPDATE, LTI_DISC, EKF_PREDICT, EKF_UPDATE + +% Copyright (C) 2002-2006 Simo S?kk? +% Copyright (C) 2007 Jouni Hartikainen +% +% $Id: kf_predict.m 111 2007-09-04 12:09:23Z ssarkka $ +% +% This software is distributed under the GNU General Public +% Licence (version 2 or later); please refer to the file +% Licence.txt, included with the software, for details. + +function [x,P] = kf_predict(x,P,A,Q,B,u) + + % + % Check arguments + % + if nargin < 3 + A = []; + end + if nargin < 4 + Q = []; + end + if nargin < 5 + B = []; + end + if nargin < 6 + u = []; + end + + % + % Apply defaults + % + if isempty(A) + A = eye(size(x,1)); + end + if isempty(Q) + Q = zeros(size(x,1)); + end + if isempty(B) & ~isempty(u) + B = eye(size(x,1),size(u,1)); + end + + % + % Perform prediction + % + if isempty(u) + x = A * x; + P = A * P * A' + Q; + else + x = A * x + B * u; + P = A * P * A' + Q; + end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/kf_update.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/kf_update.m new file mode 100644 index 0000000000000000000000000000000000000000..be2d24dfdca6c228f5fb4bff9765efc49c0c3282 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/kf_update.m @@ -0,0 +1,101 @@ +%KF_UPDATE Kalman Filter update step +% +% Syntax: +% [X,P,K,IM,IS,LH] = KF_UPDATE(X,P,Y,H,R) +% +% In: +% X - Nx1 mean state estimate after prediction step +% P - NxN state covariance after prediction step +% Y - Dx1 measurement vector. +% H - Measurement matrix. +% R - Measurement noise covariance. +% +% Out: +% X - Updated state mean +% P - Updated state covariance +% K - Computed Kalman gain +% IM - Mean of predictive distribution of Y +% IS - Covariance or predictive mean of Y +% LH - Predictive probability (likelihood) of measurement. +% +% Description: +% Kalman filter measurement update step. Kalman Filter +% model is +% +% x[k] = A*x[k-1] + B*u[k-1] + q, q ~ N(0,Q) +% y[k] = H*x[k] + r, r ~ N(0,R) +% +% Prediction step of Kalman filter computes predicted +% mean m-[k] and covariance P-[k] of state: +% +% p(x[k] | y[1:k-1]) = N(x[k] | m-[k], P-[k]) +% +% See for instance KF_PREDICT how m-[k] and P-[k] are +% calculated. +% +% Update step computes the posterior mean m[k] and +% covariance P[k] of state given new measurement: +% +% p(x[k] | y[1:k]) = N(x[k] | m[k], P[k]) +% +% Innovation distribution is defined as +% +% p(y[k] | y[1:k-1]) = N(y[k] | IM[k], IS[k]) +% +% Updated mean x[k] and covarience P[k] are given by +% the following equations (not the only possible ones): +% +% v[k] = y[k] - H[k]*m-[k] +% S[k] = H[k]*P-[k]*H[k]' + R[k] +% K[k] = P-[k]*H[k]'*[S[k]]^(-1) +% m[k] = m-[k] + K[k]*v[k] +% P[k] = P-[k] - K[k]*S[k]*K[k]' +% +% Example: +% m = m0; +% P = P0; +% M = m0; +% for i=1:size(Y,2) +% [m,P] = kf_predict(m,P,A,Q); +% [m,P] = kf_update(m,P,Y(:,i),H,R); +% M = [M m]; +% end +% +% See also: +% KF_PREDICT, EKF_UPDATE + +% History: +% 26.02.2007 JH Added the equations for calculating the updated +% means and covariances to the description section. +% 12.01.2003 SS Symmetrized covariance update +% 20.11.2002 SS The first official version. +% +% Copyright (C) 2002, 2003 Simo S?kk?% Copyright (C) 2007 Jouni Hartikainen +% +% $Id: kf_update.m 111 2007-09-04 12:09:23Z ssarkka $ +% +% This software is distributed under the GNU General Public +% Licence (version 2 or later); please refer to the file +% Licence.txt, included with the software, for details. + +function [X,P,K,IM,IS,LH] = kf_update(X,P,y,H,R) + + % + % Check which arguments are there + % + if nargin < 5 + error('Too few arguments'); + end + + % + % update step + % + IM = H*X; + IS = (R + H*P*H'); + K = P*H'/IS; + X = X + K * (y-IM); + P = P - K*IS*K'; + if nargout > 5 + LH = gauss_pdf(y,IM,IS); + end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/km_estimation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/km_estimation.m new file mode 100644 index 0000000000000000000000000000000000000000..eff1272e40d5a9e83ad2446515497b3c1d702534 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/km_estimation.m @@ -0,0 +1,31 @@ +function [MM,PP] = km_estimation(X,Y,param,P) +% X: object motion state, (x_pos, x_vel, y_pos, y_vel) +% Y: measurements, (x_pos, y_pos) + +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +if nargin <4 + P = param.P; + +end +H = param.H; +R = param.R; + + +Ts = param.Ts; +F1 = [1 Ts;0 1]; +Fz = zeros(2,2); +param.F = [F1 Fz;Fz F1]; + + +A = param.F; +Q = param.Q; + +if ~isempty(Y) + [MM,PP] = kf_loop(X,P,H,R,Y,A,Q); +else + [MM,PP] = kf_predict(X,P,A,Q); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/km_state_est.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/km_state_est.m new file mode 100644 index 0000000000000000000000000000000000000000..afeb51468c13e639b3defd98bfb0358bd991f691 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/km_state_est.m @@ -0,0 +1,22 @@ +function [MM,PP] = km_state_est(X,Y,param,P) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +% X: object motion state, (x_pos, x_vel, y_pos, y_vel) +% Y: measurements, (x_pos, y_pos) + +if nargin <4 + P = param.P; +end +H = param.H; +R = param.R; +A = param.F; +Q = param.Q; + +if ~isempty(Y) + [MM,PP] = kf_loop(X,P,H,R,Y,A,Q); +else + [MM,PP] = kf_predict(X,P,A,Q); +end + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/km_state_update.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/km_state_update.m new file mode 100644 index 0000000000000000000000000000000000000000..bd0d0034ab1c1f703d0894e4aefebd08501af534 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/kf_func/km_state_update.m @@ -0,0 +1,20 @@ +function [Trk] = km_state_update(Trk,ymeas,param,fr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +[size_state] = estimation_size(Trk,ymeas,fr); + +XX = Trk.FMotion.X(:,end); +PP = Trk.FMotion.P(:,:,end); + +if ~isempty(ymeas) + [XX,PP] = km_estimation(XX,ymeas(1:2),param,PP); +else + [XX,PP] = km_estimation(XX,[],param,PP); +end + +pos_state = [XX(1);XX(3)]; +Trk.state{fr} = [pos_state;size_state]; + +Trk.FMotion.X(:,fr) = XX; +Trk.FMotion.P(:,:,fr) = PP; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Confidence_Update.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Confidence_Update.m new file mode 100644 index 0000000000000000000000000000000000000000..0e16718782570fef5392d0bea8ffcfa84d0c0c1a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Confidence_Update.m @@ -0,0 +1,38 @@ +function [Trk] = MOT_Confidence_Update(Trk,param,fr,lambda) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +if nargin < 4 + lambda = 1.2; +end +%% Tracklet confidence update + +for i=1:length(Trk) + if Trk(i).last_update == fr + hyp_score = Trk(i).hyp.score; + + L_T = 0; + ass_idx = []; + for ii = length(hyp_score):-1:1 + if hyp_score(ii) == 0 + break; + end + L_T = L_T + 1; + ass_idx = [ass_idx,ii]; + end + + Conf_prob = 1/(L_T) * sum(hyp_score(ass_idx)) * (1 - exp(-lambda*sqrt(L_T))); + Trk(i).Conf_prob = Conf_prob; + Trk(i).Cont_Asso = L_T; + + else + Conf_prob = Trk(i).Conf_prob; + Trk(i).Conf_prob = Conf_prob*param.atten; + end +end + + +end + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Draw_Tracking.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Draw_Tracking.m new file mode 100644 index 0000000000000000000000000000000000000000..e130bf9e1fbd22939f883ead66003df66554bc49 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Draw_Tracking.m @@ -0,0 +1,105 @@ +function [stateInfo] = MOT_Draw_Tracking(Trk_sets, img_path, img_List, frame_end, option) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +% Draw Tracking Results +if ~isfield(option,'new_thr'); + option.isdraw = 1; + option.iswrite = 0; + option.new_thr = 5; +end +new_thr = option.new_thr; +all_mot = []; +numFrames = length(Trk_sets); + +X = zeros(numFrames, 1); +Y = zeros(numFrames, 1); +W = zeros(numFrames, 1); +H = zeros(numFrames, 1); +for q=1:numFrames + filename = strcat(img_path,img_List(q).name); + rgbimg = imread(filename); + wind_cx=[]; wind_cy =[]; windw = []; windh = []; + Labels =[]; trk_idx = []; trk_sts =[]; conf = []; + + + if q<=new_thr + trk_idx = Trk_sets(new_thr+1).high; + for i=1:length(trk_idx) + states = Trk_sets(new_thr+1).states{trk_idx(i)}; + lab = Trk_sets(new_thr+1).label; + trk_sts = zeros(1,length(trk_idx)); + if sum(states(:,q)) ~=0 + wind_cx = [wind_cx, states(1,q)]; + wind_cy = [wind_cy, states(2,q)]; + windw = [windw,states(3,q)]; + windh = [windh,states(4,q)]; + Labels = [Labels,lab(trk_idx(i))]; + conf(i) = 0.33 + rand *0.33; + end + end + else + high = Trk_sets(q).high; + low = Trk_sets(q).low; + trk_idx = [high,low]; + + for i=1:length(trk_idx) + states = Trk_sets(q).states{trk_idx(i)}; + wind_cx = [wind_cx, states(1,end)]; + wind_cy = [wind_cy, states(2,end)]; + windw = [windw,states(3,end)]; + windh = [windh,states(4,end)]; + conf(i) = Trk_sets(q).conf(trk_idx(i)); + end + if ~isempty(wind_cx) + all_lab = Trk_sets(q).label; + Labels = [all_lab(high), all_lab(low)]; + end + end + + [wind_lx, wind_ly] = CenterToLeft(wind_cx,wind_cy,windh,windw); + + X(q, Labels) = wind_lx; + Y(q, Labels) = wind_ly; + W(q, Labels) = windw; + H(q, Labels) = windh; + + %% Draw results + if option.isdraw + figure(1); + mot_draw_confidence_boxes(rgbimg, wind_lx, wind_ly, windw, windh, Labels, conf); + +% if ~isdir(out_path);mkdir(out_path);end; +% +% out_filename = strcat(out_path,sprintf('Tracking_Results_%04d.jpg',q)); +% +% if option.iswrite +% testImg= frame2im(getframe(fg1)); +% imwrite(testImg, out_filename); +% end + end + + %% Output + if ~isempty(wind_cx) + all_mot.cpos{q} = [wind_cx;wind_cy]; % center position + all_mot.lpos{q} = [wind_lx;wind_ly]; % X-Y position + all_mot.size{q} = [windw;windh]; % size + all_mot.lab{q} = Labels; % labels + end +end + +% save tracking results +stateInfo = []; +xc = X + W/2; +yc = Y + H/2; +% foot position +stateInfo.X = xc; +stateInfo.Y = yc+H/2; +stateInfo.H = W; +stateInfo.W = H; +stateInfo.F = frame_end; +stateInfo.frameNums = 1:frame_end; +stateInfo.Xgp = stateInfo.X; +stateInfo.Ygp = stateInfo.Y; +stateInfo.Xi = stateInfo.X; +stateInfo.Yi = stateInfo.Y; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Generation_Tracklets.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Generation_Tracklets.m new file mode 100644 index 0000000000000000000000000000000000000000..7124013009530298bb9d08906ec7d74356102f71 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Generation_Tracklets.m @@ -0,0 +1,14 @@ +function [Trk ,param, Obs_grap] = MOT_Generation_Tracklets(init_img_set,Trk,detections,param,... + Obs_grap,cfr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +st_fr = cfr-param.show_scan; en_fr = cfr; +ISO.meas= []; ISO.node = []; +[ISO] = mot_non_associated(detections, Obs_grap, ISO,st_fr,en_fr); +[ISO] = mot_pre_association_tracking(ISO,st_fr,en_fr); +[Trk,param,Obs_grap] = mot_generation_tracklet(init_img_set,Trk,Obs_grap,... + ISO.meas,param, ISO.node,cfr); + + + \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Global_Association.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Global_Association.m new file mode 100644 index 0000000000000000000000000000000000000000..75e0c229e6ea1c7c8a52d955df52b5b10b801bf7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Global_Association.m @@ -0,0 +1,141 @@ + +function [Trk, Obs_grap] = MOT_Global_Association(Trk, Obs_grap, Obs_info, param, ILDA, fr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +Refer =[]; Test= []; +all_indx = 1:length(Trk); +[low_indx] = Idx2Types(Trk,'Low'); +[high_indx] = setdiff(all_indx, low_indx); +yidx = find(Obs_grap(fr).iso_idx == 1); + +yhist = Obs_info.yhist; +ystate = Obs_info.ystate; + +High_trk =[]; Low_trk=[]; Y_set = []; +if ~isempty(low_indx) + % For tracklets with low confidence + for ii=1:length(low_indx) + i = low_indx(ii); + Low_trk(ii).hist = Trk(i).A_Model; + Low_trk(ii).FMotion = Trk(i).FMotion; + + Low_trk(ii).h = Trk(i).state{end}(4); + Low_trk(ii).w = Trk(i).state{end}(3); + Low_trk(ii).last_update = Trk(i).last_update; + Low_trk(ii).end_time = Trk(i).efr; + Low_trk(ii).type = Trk(i).type; + end + + % For tracklet with high confidence + for jj=1:length(high_indx) + j = high_indx(jj); + High_trk(jj).hist = Trk(j).A_Model; + High_trk(jj).h = Trk(j).state{end}(4); + High_trk(jj).w = Trk(j).state{end}(3); + High_trk(jj).FMotion = Trk(j).FMotion; + [XX,PP] = mot_motion_model_generation(Trk(j),param,'Backward'); + + High_trk(jj).BMotion.X = XX; + High_trk(jj).BMotion.P = PP; + + High_trk(jj).last_update = Trk(j).last_update; + High_trk(jj).init_time = Trk(j).ifr; + end + + iso_label = []; + if ~isempty(yidx) + + % For detections + for jj=1:length(yidx) + j = yidx(jj); + Y_set(jj).hist = yhist(:,:,j); + Y_set(jj).pos = [ystate(1,j);ystate(2,j)]; + Y_set(jj).h = ystate(4,j); + Y_set(jj).w = ystate(3,j); + iso_label = j; + end + end + + thr = param.obs_thr; + + [score_trk] = mot_eval_association_matrix(Low_trk,High_trk,param,'Trk',ILDA); + [score_obs] = mot_eval_association_matrix(Low_trk, Y_set, param,'Obs', ILDA); + score_mat = [score_trk, score_obs]; + [matching, Affinity] = mot_association_hungarian(score_mat, thr); + + + alpha = param.alpha; + + rm_idx = []; + for m=1: length(Affinity) + mat_idx = matching(m,2); + + % Tracklet Association + if mat_idx <= length(high_indx) + t_idx = low_indx(matching(m,1)); + y_idx = high_indx(matching(m,2)); + + Trk(y_idx).ifr = Trk(t_idx).ifr; + fr1 = Trk(t_idx).ifr; + fr2 = Trk(t_idx).efr; + for kk=fr1:fr2 + Trk(y_idx).state{kk} = Trk(t_idx).state{kk}; + end + + numHyp = length(Trk(t_idx).hyp.score); + for kk=fr1:numHyp + Trk(y_idx).hyp.score(kk) = Trk(t_idx).hyp.score(kk); + Trk(y_idx).hyp.ystate{kk} = Trk(t_idx).hyp.ystate{kk}; + end + + for kk=numHyp + 1:fr-1 + Trk(y_idx).hyp.score(kk) = param.init_prob; + Trk(y_idx).hyp.ystate{kk} = []; + end + Trk(y_idx).A_Model = alpha*(Trk(t_idx).A_Model)+(1-alpha)*(Trk(y_idx).A_Model); + + % Motion Model Generation + XX = []; + numState = length(Trk(y_idx).state); + XX(1,:) = Trk(y_idx).state{fr1}(1); + XX(3,:) = Trk(y_idx).state{fr1}(2); + XX(2,:) = 0; XX(4,:) = 0; + PP = param.P; + for ff=fr1:numState + tState = Trk(y_idx).state{ff}; + if ~isempty(tState) + [XX,PP] = km_estimation(XX,tState(1:2),param,PP); + else + tState = Trk(y_idx).state{fr2}; + [XX,PP] = km_estimation(XX,[],param,PP); + Trk(y_idx).state{ff}(1:2,:) = [XX(1);XX(3)]; + Trk(y_idx).state{ff}(3:4,:) = [tState(1);tState(3)]; + end + Trk(y_idx).FMotion.X(:,ff) = XX; + Trk(y_idx).FMotion.P(:,:,ff) = PP; + end + + Trk(y_idx).label = Trk(t_idx).label; + Trk(y_idx).type = 'High'; + rm_idx = [rm_idx, t_idx]; + + else % Observation Association + m_idx = matching(m,2) - length(high_indx); + t_idx = low_indx(matching(m,1)); + y_idx = yidx(m_idx); + Trk(t_idx).hyp.score(fr) = Affinity(m); + Trk(t_idx).hyp.ystate{fr} = ystate(:,y_idx); + Trk(t_idx).hyp.new_tmpl = yhist(:,:,y_idx); + Trk(t_idx).last_update = fr; + Obs_grap(fr).iso_idx(y_idx) = 0; + end + + end + + if ~isempty(rm_idx) + Trk(rm_idx) = []; + end +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_ILDA_Update.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_ILDA_Update.m new file mode 100644 index 0000000000000000000000000000000000000000..d4c1a4a097f92b2e11a160acc94fb9d5ab6cdef4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_ILDA_Update.m @@ -0,0 +1,75 @@ +function [ILDA]= MOT_ILDA_Update(ILDA, new_data, new_label) +%ILDA pseudocode +%written by T-K. Kim, 2007 +%modified by S-H. Bae, 2012 +%Reference: +%[1] Incremental linear discriminant analysis using sufficient +%spanning sets and its application, Tae-Kyun Kim, Bjorn Stenger, Josef +%Kittler, IJCV, 2010. +%Incremental LDA of a raw dataset. +%featureVectorInCol: MxN matrix - each column is a feature vector of the +%raw dataset, M - dimension size, N - the number of sample + +DeigenThreshold = ILDA.eigenThreshold; +up_ratio = ILDA.up_ratio; +eigenThreshold = ILDA.eigenThreshold; + +if ILDA.n_update == 0 + dataset_1 = new_data; label_1 = new_label; + % init proc + [m_1,M_1,TeigenVect_1,TeigenVal_1] = fGetStModel(dataset_1,eigenThreshold); + [m_1, M_1, BeigenVect_1, BeigenVal_1, samplePerClass_1, meanPerClass_1] = fGetSbModel_v2(dataset_1, label_1, eigenThreshold); + [DiscriminativeComponents D] = fGetDiscriminativeComponents_v2(TeigenVect_1, TeigenVal_1, BeigenVect_1,... + BeigenVal_1, M_1, DeigenThreshold,up_ratio); + + ILDA.m_1 = m_1; + ILDA.M_1 = M_1; + ILDA.TeigenVect_1 = TeigenVect_1; + ILDA.TeigenVal_1 = TeigenVal_1; + + ILDA.BeigenVect_1 = BeigenVect_1; + ILDA.BeigenVal_1 = BeigenVal_1; + ILDA.samplePerClass_1 = samplePerClass_1; + ILDA.meanPerClass_1 = meanPerClass_1; + ILDA.label_1 = label_1; +else + % for new data + dataset_2 = new_data; label_2 = new_label; + [m_2, M_2, TeigenVect_2,TeigenVal_2] = fGetStModel(dataset_2,eigenThreshold); + [m_2, M_2, BeigenVect_2,BeigenVal_2, samplePerClass_2, meanPerClass_2] = fGetSbModel_v2(dataset_2,label_2,eigenThreshold); + + % update + m_1 = ILDA.m_1; + M_1 = ILDA.M_1; + TeigenVect_1 = ILDA.TeigenVect_1; TeigenVal_1 = ILDA.TeigenVal_1; + BeigenVect_1 = ILDA.BeigenVect_1; BeigenVal_1 = ILDA.BeigenVal_1; + samplePerClass_1 = ILDA.samplePerClass_1; meanPerClass_1 = ILDA.meanPerClass_1; + label_1 = ILDA.label_1; + + [outMean, outNSample, outEVect_t, outEVal_t] = fMergeSt(m_1, M_1, TeigenVect_1, TeigenVal_1, m_2, M_2, TeigenVect_2, TeigenVal_2, eigenThreshold); + [outMean, outNSample, outEVect_b, outEVal_b, outSamplePerClass, outMeanPerClass] = fMergeSb(m_1, M_1, BeigenVect_1, BeigenVal_1, samplePerClass_1, meanPerClass_1, label_1,... + m_2, M_2, BeigenVect_2, BeigenVal_2, samplePerClass_2, meanPerClass_2, label_2, eigenThreshold); + [DiscriminativeComponents D] = fGetDiscriminativeComponents_v2(outEVect_t, outEVal_t, outEVect_b,... + outEVal_b, outNSample,DeigenThreshold,up_ratio); + + % update variables + ILDA.m_1 = outMean; + ILDA.M_1 = outNSample; + ILDA.TeigenVect_1 = outEVect_t; + ILDA.TeigenVal_1 = outEVal_t; + + ILDA.BeigenVect_1 = outEVect_b; + ILDA.BeigenVal_1 = outEVal_b; + ILDA.samplePerClass_1 = outSamplePerClass; + ILDA.meanPerClass_1 = outMeanPerClass; + ILDA.label_1 = horzcat(label_1,label_2); + +end +ILDA.DiscriminativeComponents = DiscriminativeComponents; +ILDA.D = D; +ILDA.n_update = ILDA.n_update + 1; + + + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Initialization_Tracklets.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Initialization_Tracklets.m new file mode 100644 index 0000000000000000000000000000000000000000..e737ca6f63c315d2b5c4da2a8219cc685a27dcd5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Initialization_Tracklets.m @@ -0,0 +1,34 @@ +function [Trk,param,Y_set] = MOT_Initialization_Tracklets(rgbimg,Trk,detections,param,Y_set,fr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +new_thr = param.new_thr; +for i=1:length(Y_set(fr).child) + prt_idx = Y_set(fr).child{i}; + if length(prt_idx) <= 1 + [child_idx] = mot_search_association(Y_set, fr,prt_idx); + + [ass_idx] = mot_return_ass_idx(child_idx,prt_idx,i,fr); + else + child_idx =[]; tmp_ass_idx =[]; ass_ln=[]; + for j=1:length(prt_idx) + [child_idx{j}] = mot_search_association(Y_set, fr,prt_idx(j)); + [tmp_ass_idx{j}] = mot_return_ass_idx(child_idx{j},prt_idx(j),i,fr); + ass_ln(j) = length(find(tmp_ass_idx{j} ~= 0)); + end + [~,pid] = max(ass_ln); + ass_idx= tmp_ass_idx{pid}; + + end + if length(find(ass_idx ~=0)) >= new_thr + [Trk,param] = mot_tracklets_components_setup(rgbimg,Trk,detections,fr,ass_idx,param,[]); + for h=1:length(find(ass_idx ~= 0)) + Y_set(fr-h+1).child{ass_idx(end-h+1)} = 0; + end + end + +end + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Local_Association.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Local_Association.m new file mode 100644 index 0000000000000000000000000000000000000000..d3c8e02851d43e87b1bea9da11822b0a656315ed --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Local_Association.m @@ -0,0 +1,75 @@ + +function [Trk, Obs_grap, Obs_info] = MOT_Local_Association(Trk, detections, Obs_grap, param, ILDA, fr, rgbimg) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + + +Z_meas = detections(fr); +ystate = [Z_meas.x, Z_meas.y, Z_meas.w, Z_meas.h]'; +Obs_grap(fr).iso_idx = ones(size(detections(fr).x)); +Obs_info.ystate = []; +Obs_info.yhist =[]; +if ~isempty(ystate) + yhist = mot_appearance_model_generation(rgbimg, param, ystate); + Obs_info.ystate = ystate; + Obs_info.yhist = yhist; + + tidx = Idx2Types(Trk,'High'); + yidx = find(Obs_grap(fr).iso_idx == 1); + + + if ~isempty(tidx) && ~isempty(yidx) + Trk_high =[]; Z_set =[]; + + trk_label = []; + conf_set = []; + % For tracklet with high confidence + for ii=1:length(tidx) + i = tidx(ii); + Trk_high(ii).hist = Trk(i).A_Model; + Trk_high(ii).FMotion = Trk(i).FMotion; + Trk_high(ii).last_update = Trk(i).last_update; + + Trk_high(ii).h = Trk(i).state{end}(4); + Trk_high(ii).w = Trk(i).state{end}(3); + Trk_high(ii).type = Trk(i).type; + trk_label(ii) = Trk(i).label; + conf_set = [conf_set, Trk(i).Conf_prob]; + end + + % For detections + meas_label = []; + for jj=1:length(yidx) + j = yidx(jj); + Z_set(jj).hist = yhist(:,:,j); + Z_set(jj).pos = [ystate(1,j);ystate(2,j)]; + Z_set(jj).h = ystate(4,j); + Z_set(jj).w = ystate(3,j); + meas_label(jj) = j; + end + + thr = param.obs_thr; + + + + [score_mat] = mot_eval_association_matrix(Trk_high, Z_set, param, 'Obs', ILDA); + [matching, ~] = mot_association_hungarian(score_mat, thr); + + + if ~isempty(matching) + for i=1:size(matching,1) + ass_idx_row = matching(i,1); + ta_idx = tidx(ass_idx_row); + ass_idx_col = matching(i,2); + ya_idx = yidx(ass_idx_col); + Trk(ta_idx).hyp.score(fr) = score_mat(matching(i,1),matching(i,2)); + Trk(ta_idx).hyp.ystate{fr} = ystate(:,ya_idx); + Trk(ta_idx).hyp.new_tmpl = yhist(:,:,ya_idx); + Trk(ta_idx).last_update = fr; + Obs_grap(fr).iso_idx(ya_idx) = 0; + + end + end + end +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Online_Appearance_Learning.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Online_Appearance_Learning.m new file mode 100644 index 0000000000000000000000000000000000000000..84659df2ed171fbe3f8f6f716db274930a2e4b7a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Online_Appearance_Learning.m @@ -0,0 +1,51 @@ +function [ILDA] = MOT_Online_Appearance_Learning(cimg,img_path, img_List, fr, Trk, param, ILDA) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +if ILDA.n_update == 0 + for i=1:length(Trk) + % Pactch cropping + states = cell2mat(Trk(i).state); + [bbs] = mot_impatch_crop(states'); + % Feature extraction + for j=1:length(bbs) + img_idx = fr - length(bbs) + j; + filename = strcat(img_path,img_List(img_idx).name); + rgbimg = imread(filename); + col_hist = mot_appearance_model_generation(rgbimg,param,bbs{j}'); + col_hist = squeeze(col_hist); + ILDA.feat_data = [ILDA.feat_data, col_hist]; + nofd = size(col_hist,2); + ILDA.feat_label = [ILDA.feat_label, repmat(Trk(i).label, 1, nofd)]; + end + end +else + states = []; tlabel = []; + for i=1:length(Trk) + % Pactch cropping + states = [states, Trk(i).state{fr}]; + tlabel = [tlabel, Trk(i).label]; + end + + if ~isempty(states) + [bbs] = mot_impatch_crop(states'); + + % Feature extraction + for j=1:length(bbs) + col_hist = mot_appearance_model_generation(cimg,param,bbs{j}'); + col_hist = squeeze(col_hist); + ILDA.feat_data = [ILDA.feat_data, col_hist]; + nofd = size(col_hist,2); + ILDA.feat_label = [ILDA.feat_label, repmat(tlabel(j), 1, nofd)]; + end + end +end + + +% Subspace learning +if rem(fr, ILDA.duration) == 1 && ~isempty(ILDA.feat_data) + [ILDA] = MOT_ILDA_Update(ILDA, ILDA.feat_data, ILDA.feat_label); + ILDA.feat_data = []; + ILDA.feat_label = []; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_State_Update.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_State_Update.m new file mode 100644 index 0000000000000000000000000000000000000000..dd4d9540467c9e7a3795ddc79ad66f45cc556c64 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_State_Update.m @@ -0,0 +1,22 @@ +function [Trk] = MOT_State_Update(Trk, param, fr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. +% Update states and models of tracklets + +for i=1:length(Trk) + if Trk(i).last_update == fr + + new_tmpl = Trk(i).hyp.new_tmpl; + old_tmpl = Trk(i).A_Model; + + alpha = 0.1; + Trk(i).A_Model = (1 - alpha)*old_tmpl + alpha*new_tmpl; + + ystate = Trk(i).hyp.ystate{fr}; + [Trk(i)] = km_state_update(Trk(i),ystate,param,fr); + + else + [Trk(i)]= km_state_update(Trk(i), [], param,fr); + end +end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Tracking_Results.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Tracking_Results.m new file mode 100644 index 0000000000000000000000000000000000000000..87bd9fe353b3af13d96036cd7e04cb79ee7d5064 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Tracking_Results.m @@ -0,0 +1,23 @@ +function [Trk_sets] = MOT_Tracking_Results(Trk,Trk_sets,fr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +[hg_indx] = Idx2Types(Trk,'High'); +[low_indx] = Idx2Types(Trk,'Low'); + +del_indx =[]; +for i=1:length(low_indx) + efr = Trk(low_indx(i)).efr; + if abs(efr - fr) > 5 + del_indx = [del_indx,i]; + end +end + +Trk_sets(fr).high = hg_indx; +Trk_sets(fr).low = setdiff(low_indx, low_indx(del_indx)); + +for i=1:length(Trk) + Trk_sets(fr).states{i} = cell2mat(Trk(i).state); + Trk_sets(fr).conf(i) = Trk(i).Conf_prob; + Trk_sets(fr).label(i) = Trk(i).label; +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Type_Update.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Type_Update.m new file mode 100644 index 0000000000000000000000000000000000000000..4693f2d9c2a129f9b4cded0b4b4f3eea4d0ec6a7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/MOT_Type_Update.m @@ -0,0 +1,55 @@ +function [Trk] = MOT_Type_Update(rgbimg,Trk,type_thr,cfr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +del_idx = []; lb_idx =[]; +max_frame = 50; + +for i=1:length(Trk) + Conf_prob = Trk(i).Conf_prob; + type = Trk(i).type; + switch type + case 'High' + if Conf_prob < type_thr + Trk(i).type = 'Low'; + Trk(i).efr = cfr; + end + case 'Low' + if Conf_prob > type_thr + Trk(i).type = 'High'; + end + efr = Trk(i).efr; + if abs(cfr - efr) >= max_frame + del_idx = [del_idx,i]; + lb_idx= [lb_idx, Trk(i).label]; + end + end +end + +[R_pos(2), R_pos(1), ~] = size(rgbimg); +L_pos = [0,0]; + +margin = [0 0]; +for i=1:length(Trk) + tstates =Trk(i).state{end}; + + if isnan(tstates(1)) + del_idx = [del_idx,i]; + else + fmotion = Trk(i).state{end}; + C_pos(1) = fmotion(1,end); + C_pos(2) = fmotion(2,end); + L_pos = L_pos + margin; + R_pos = R_pos - margin; + if ~(mot_is_reg(C_pos,L_pos,R_pos)) + del_idx = [del_idx,i]; + end + end +end + +if ~isempty(del_idx) + Trk(del_idx) = []; +end + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_appearance_model_generation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_appearance_model_generation.m new file mode 100644 index 0000000000000000000000000000000000000000..8b6d8041ac176bfd61c0ab7e15fc6e09bb4aca01 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_appearance_model_generation.m @@ -0,0 +1,56 @@ +function [tmpl_hist] = mot_appearance_model_generation(img, param, state) +% input : +% img: a color image +% state: [Center(X), Center(Y), Width, Height] +% output : +% tmpl_hist: color histograms + +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +if strcmp(param.color.type,'HSV') + hsv_img = rgb2hsv(img); +else + hsv_img = img; +end +h_img = double(hsv_img(:,:,1))./double(max(max(img(:,:,1)))); +s_img = double(hsv_img(:,:,2))./double(max(max(img(:,:,2)))); +v_img = double(hsv_img(:,:,3))./double(max(max(img(:,:,3)))); + + +initS = state; + +h_tmpl = mot_generate_temp(h_img,initS,param.tmplsize); +s_tmpl = mot_generate_temp(s_img,initS,param.tmplsize); +v_tmpl = mot_generate_temp(v_img,initS,param.tmplsize); + +Nd = size(state,2); + +h_tmpl = reshape(h_tmpl,param.subvec,param.subregion,Nd); +s_tmpl = reshape(s_tmpl,param.subvec,param.subregion,Nd); +v_tmpl = reshape(v_tmpl,param.subvec,param.subregion,Nd); + +all_tmpl{1} =h_tmpl; +all_tmpl{2} =s_tmpl; +all_tmpl{3} = v_tmpl; + +nbins = param.Bin; +tmpl_hist =[]; +temp_hist = []; + +for j=1:Nd + temp_hist =[]; + for i=1:3 + max_val = max(max(all_tmpl{i}(:,:,j))); + cb_tmpl = all_tmpl{i}(:,:,j); + cb_tmpl = cb_tmpl./max_val*nbins; + if param.subregion ==1 + cb_tmpl_hist = (hist(cb_tmpl,nbins)/param.subvec)'; + else + cb_tmpl_hist = (hist(cb_tmpl,nbins)/param.subvec); + end + temp_hist = [temp_hist;cb_tmpl_hist]; + end + tmpl_hist(:,:,j) = temp_hist./3; +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_association_hungarian.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_association_hungarian.m new file mode 100644 index 0000000000000000000000000000000000000000..50f9ef3a7496b5f46938f3cffbfdd3757f5b9993 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_association_hungarian.m @@ -0,0 +1,21 @@ +function [matching, score] = mot_association_hungarian(score_mat, thr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved +% Association using the hungarian algorithm + +if size(score_mat,1) ==1 + [assignment,cost] = munkres(-(score_mat')); + assignment = assignment'; + [ass_row,ass_col] = find(assignment == 1); +else + [assignment,cost] = munkres(-(score_mat)); + [ass_row,ass_col] = find(assignment == 1); +end + +match_cost = score_mat(assignment); +midx = find(match_cost > thr); + +matching = [ass_row(midx),ass_col(midx)]; +score= match_cost(midx); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_color_similarity.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_color_similarity.m new file mode 100644 index 0000000000000000000000000000000000000000..b25801f96bda320d1674c01b1b5a89b8714a764e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_color_similarity.m @@ -0,0 +1,30 @@ +function [likelihood] = mot_color_similarity(refer_hist,target_hist,var) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + + +if nargin >2 + [N,M] = size(target_hist); + bhattcoeff = sum(sqrt(refer_hist.*target_hist)); + Dist = sqrt(ones(1,M) - bhattcoeff); + likelihood = exp(sum((-1/var)*Dist.^2)); +else + [likelihood]= color_similarity_only_bhat(refer_hist,target_hist); +end + + + +end + +function [likelihood]=color_similarity_only_bhat(refer_hist,target_hist) + + +method =1; +bhattcoeff = sum(sqrt(refer_hist.*target_hist)); +if bhattcoeff >1 + [r p] = corrcoef(refer_hist,target_hist); + likelihood = p(1,2); +else + likelihood = mean(bhattcoeff); +end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_draw_confidence_boxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_draw_confidence_boxes.m new file mode 100644 index 0000000000000000000000000000000000000000..22c9519f8a85471c0277560241f0a18cb2fd491f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_draw_confidence_boxes.m @@ -0,0 +1,62 @@ +function mot_draw_confidence_boxes(bg_image, wind_lx,wind_ly,windw,windh,Labels,conf) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + + +rectcolor = colormap(jet(16)); +ncol = size(rectcolor,1); + + +imshow(bg_image); +clf, imagesc(bg_image); hold on +set(gca,'Position',[0,0,1,1],'visible','off'); +hold on; + + +l_width = 5; +base_fonts = 15; +for i=1:length(wind_lx) + Roi = [wind_lx(i), wind_ly(i), windw(i), windh(i)]; + lab = Labels(i); + + + wsize = windw(i); + if wsize < 25 + fonts = base_fonts-1; + elseif (wsize >= 25) && (wsize < 30) + fonts = base_fonts; + elseif (wsize >= 30) && (wsize < 35) + fonts = base_fonts +1; + elseif (wsize >= 35) && (wsize < 40) + fonts = base_fonts +2; + elseif (wsize >= 40) && (wsize < 45) + fonts = base_fonts + 3; + elseif (wsize >= 45) && (wsize < 50) + fonts = base_fonts + 4; + else + fonts = base_fonts + 7; + end + + + [txt_cx txt_cy] = LeftToCenter(wind_lx(i), wind_ly(i), windh(i), windw(i)); + txt_cy = txt_cy -12; + nfonts = fonts + 3; + + + + cindx = ceil(conf(i)*ncol); + if cindx == 0 + cindx = 1; + end + + + Roi = [wind_lx(i), wind_ly(i), windw(i), windh(i)]; + rectangle('Position',Roi,'EdgeColor',rectcolor(cindx,:),... + 'LineWidth',l_width); + hold on; + text(txt_cx, txt_cy ,sprintf('%d',lab),'Color','k','Fontsize',nfonts,... + 'HorizontalAlignment','Center','FontWeight','bold'); +end +hold off; + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_eval_association_matrix.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_eval_association_matrix.m new file mode 100644 index 0000000000000000000000000000000000000000..c30f7c3bf01b411fc847e8fb3d9ee3b311c282af --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_eval_association_matrix.m @@ -0,0 +1,50 @@ +function [score_mat] = mot_eval_association_matrix(Refer,Test,param,type,ILDA) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + + +if ILDA.n_update ~= 0 + nproj = size(ILDA.DiscriminativeComponents,2); +else + nproj = 0; +end + +% Association score matrix +score_mat =zeros(length(Refer),length(Test)); +for i=1:length(Refer) + + refer_hist = Refer(i).hist(:)/sum(Refer(i).hist(:)); + refer_h = Refer(i).h; + refer_w = Refer(i).w; + + + for j=1:length(Test) + + % Appearance affinity + test_hist = Test(j).hist(:)/sum(Test(j).hist(:)); + + if (param.use_ILDA) && (ILDA.n_update ~= 0) && (nproj >2) + proj = ILDA.DiscriminativeComponents; + + refer_feat = proj'*refer_hist; + test_feat = proj'*test_hist; + app_sim = dot(refer_feat, test_feat)/(norm(refer_feat) * norm(test_feat)); + else + app_sim = mot_color_similarity(refer_hist,test_hist); + end + % Motion affinity + [mot_sim] = mot_motion_similarity(Refer(i), Test(j), param, type); + + % Shape affinity + test_h = Test(j).h; + test_w = Test(j).w; + shp_sim = mot_shape_similarity(refer_h, refer_w, test_h, test_w); + + + score_mat(i,j) = mot_sim*app_sim*shp_sim; + end +end + +end + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_generate_temp.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_generate_temp.m new file mode 100644 index 0000000000000000000000000000000000000000..d48193c0d73e66a8a521d5c8cde923febbacb118 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_generate_temp.m @@ -0,0 +1,16 @@ +function [tmpl] = mot_generate_temp(img, state, sz) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +if (nargin < 3) + sz = size(img); +end +if (size(state,1) == 1) + state = state(:); +end +N = size(state,2); + +AFF = [state(1,:); state(2,:); state(3,:)/sz(1); zeros(1,N); state(4,:)./state(3,:); zeros(1,N)]; +AFF = affparam2mat(AFF); +tmpl = warpimg(img, AFF, sz); +tmpl = reshape(tmpl, sz(1)*sz(2), N); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_generation_tracklet.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_generation_tracklet.m new file mode 100644 index 0000000000000000000000000000000000000000..dabe584770b01a811f1b8b53d49fd3bbe7e60708 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_generation_tracklet.m @@ -0,0 +1,48 @@ +function [Trk,param,Obs_grap] = mot_generation_tracklet(rgbimg,Trk,Obs_grap,detections,param,Y_set,fr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +ct = 0; non_iso =[]; +new_thr = param.new_thr; +for i=1:length(Y_set(fr).child) + prt_idx = Y_set(fr).child{i}; + if length(prt_idx) <= 1 + [child_idx] = mot_search_association(Y_set, fr,prt_idx); + [ass_idx] = mot_return_ass_idx(child_idx,prt_idx,i,fr); + else + child_idx =[]; tmp_ass_idx =[]; ass_ln=[]; + for j=1:length(prt_idx) + [child_idx{j}] = mot_search_association(Y_set, fr, prt_idx(j)); + [tmp_ass_idx{j}] = mot_return_ass_idx(child_idx{j},prt_idx(j),i,fr); + ass_ln(j) = length(find(tmp_ass_idx{j} ~= 0)); + end + [~,pid] = max(ass_ln); + ass_idx= tmp_ass_idx{pid}; + + end + + if length(find(ass_idx ~=0)) >= new_thr + ct = ct + 1; + [Trk,param] = mot_tracklets_components_setup(rgbimg,Trk,detections,fr,ass_idx,param,[]); + idx = []; + nT = length(find(ass_idx ~= 0)); + for h=1:nT + idx1 = find(Obs_grap(fr+h-nT).iso_idx == 1); + idx2 = idx1(ass_idx(end+h-nT)); + idx = [idx, idx2]; + end + non_iso(ct,:) = idx; + end +end + + + +for j=1:size(non_iso,2) + setr = unique(non_iso(:,j)); + if Obs_grap(fr+j-nT).iso_idx(setr) ==0 + puase; + end + Obs_grap(fr+j-nT).iso_idx(setr) = 0; +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_impatch_crop.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_impatch_crop.m new file mode 100644 index 0000000000000000000000000000000000000000..7356e0580cff98813bcd20986a7f1c7786296466 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_impatch_crop.m @@ -0,0 +1,14 @@ +function [bbs] = mot_impatch_crop(cn_est) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +nofs = size(cn_est,1); +for i=1:nofs + pos = cn_est(i,1:2); + scale = cn_est(i,3:4); + bbs{i} = [pos,scale]; +end + + +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_is_reg.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_is_reg.m new file mode 100644 index 0000000000000000000000000000000000000000..bf6f6c8c1ed80c742051fcd19f0f870dfca2534d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_is_reg.m @@ -0,0 +1,19 @@ +function [decision]= mot_is_reg(pos,left,right) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +Lx = left(1); +Ly = left(2); +Rx = right(1); +Ry = right(2); + +if (pos(1)>Lx(1) && pos(1)Ly && pos(2) 0 + + init_time = Test.init_time; + FX = Refer.FMotion.X(:,init_time); + + BX = Test.BMotion.X(:,end); + BP = Test.BMotion.P(:,:,end); + while fgap > 0 + [BX,BP] = km_estimation(BX,[],param,BP); + fgap = fgap - 1; + end + + % Forward motion + refer_pos = [FX(1); FX(3)]; + test_pos = [Test.BMotion.X(1,end);Test.BMotion.X(3,end)]; + mot_sim1 = motion_affinity(refer_pos,test_pos,pos_var); + + % Backward motion + refer_pos = [BX(1); BX(3)]; + test_pos = [Refer.FMotion.X(1,end); Refer.FMotion.X(3,end)]; + mot_sim2 = motion_affinity(refer_pos,test_pos,pos_var); + + mot_sim = mot_sim1*mot_sim2; + + else + mot_sim = 0; + + end + otherwise + warning('Unexpected type. Choose Obs or Trk.'); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_non_associated.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_non_associated.m new file mode 100644 index 0000000000000000000000000000000000000000..76464d2026ee846ba7af16114bf7335b7f621ec4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_non_associated.m @@ -0,0 +1,17 @@ +function [ISO] = mot_non_associated(detections, Y_set, ISO,st_fr,en_fr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + + +for i=st_fr:en_fr + iso_idx = find(Y_set(i).iso_idx == 1); + ISO.meas(i).x = detections(i).x(iso_idx); + ISO.meas(i).y = detections(i).y(iso_idx); + ISO.meas(i).w = detections(i).w(iso_idx); + ISO.meas(i).h = detections(i).h(iso_idx); +end + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_pre_association.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_pre_association.m new file mode 100644 index 0000000000000000000000000000000000000000..f1a5e2fbf01bfe670a9abf1f849b8bb3a28170b9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_pre_association.m @@ -0,0 +1,32 @@ +function [Y] = mot_pre_association(detections,Y,start_frame,end_frame) + +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +cur_det = detections(1); +for i=1:length(cur_det.x) + Y(start_frame).child{i} = 0; +end + + +for q=start_frame+1:end_frame + prev_det = detections(q-1); + cur_det = detections(q); + asso_idx = []; + for i=1:length(cur_det.x) + ovs1 = calc_overlap2(cur_det,prev_det,i); + inds1 = find(ovs1 > 0.4); + ratio1 = cur_det.h(i)./prev_det.h(inds1); + inds2 = (min(ratio1, 1./ratio1) > 0.8); + if ~isempty(inds1(inds2)) + Y(q).child{i} = inds1(inds2); + else + Y(q).child{i} = 0; + end + asso_idx = [asso_idx,inds1(inds2)]; + end + Y(q-1).iso_idx(asso_idx) = 0; + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_pre_association_tracking.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_pre_association_tracking.m new file mode 100644 index 0000000000000000000000000000000000000000..2eeb1a30a28e6d96eec8fb3ad6240396cdf17aa1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_pre_association_tracking.m @@ -0,0 +1,40 @@ +function [ISO] = mot_pre_association_tracking(ISO,start_frame,end_frame) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +for i=start_frame:end_frame + ISO.node(i).child =[]; +end +init_det =ISO.meas(start_frame); + +for i=1:length(init_det.x) + ISO.node(start_frame).child{i} = 0; +end + +if ~isempty(init_det.x) + + detections = ISO.meas; + + for q=start_frame+1:end_frame + prev_det = detections(q-1); + cur_det = detections(q); + + for i=1:length(cur_det.x) + ISO.node(q).child{i} = 0; + end + asso_idx = []; + for i=1:length(cur_det.x) + ovs1 = calc_overlap2(cur_det,prev_det,i); + inds1 = find(ovs1 > 0.4); + ratio1 = cur_det.h(i)./prev_det.h(inds1); + inds2 = (min(ratio1, 1./ratio1) > 0.8); + if ~isempty(inds1(inds2)) + ISO.node(q).child{i} = inds1(inds2); + else + ISO.node(q).child{i} = 0; + end + asso_idx = [asso_idx,inds1(inds2)]; + end + end +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_return_ass_idx.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_return_ass_idx.m new file mode 100644 index 0000000000000000000000000000000000000000..23b8e163be0552b9ed5a894e1fc26fd3b6cd2223 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_return_ass_idx.m @@ -0,0 +1,12 @@ +function [all_idx] = mot_return_ass_idx(child_idx,prt_idx,root_idx,c_fr) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +all_idx = zeros(1,c_fr); +all_idx(end) = root_idx; +all_idx(end-1) = prt_idx; +nofc = length(child_idx); +all_idx(end-nofc:end-2) = child_idx(2:end); + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_search_association.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_search_association.m new file mode 100644 index 0000000000000000000000000000000000000000..f0c6f14daebccbfd325b97b261795630dbfcdf6e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_search_association.m @@ -0,0 +1,28 @@ +function [ass_idx] = mot_search_association(Y,fr,prt_idx) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +flg = 1; +ct = 0; +ass_idx = []; +if prt_idx ~=0 + while flg == 1 + ct = ct +1; + prt_idx = Y(fr-ct).child{prt_idx}; + if length(prt_idx) == 1 + if (prt_idx ~=0) && length(prt_idx) ==1 + ass_idx = [prt_idx,ass_idx]; + else + ass_idx = [prt_idx,ass_idx]; + flg = 0; + end + else + ass_idx = [0,ass_idx]; + flg = 0; + end + + end +end + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_setting_params.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_setting_params.m new file mode 100644 index 0000000000000000000000000000000000000000..694b938100b9df05457b38f91438d4d0e6590167 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_setting_params.m @@ -0,0 +1,54 @@ +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +%% Common parameter +param.label(1,:) = zeros(1,10000); +param.show_scan = 4; +param.new_thr = param.show_scan + 1; % Temporal window size for tracklet initialization +param.obs_thr = 0.4; % Threshold for local and global association +param.type_thr = 0.5; % Threshold for changing a tracklet type +param.pos_var = diag([50^2 75^2]); % Covariance used for motion affinity evalutation +param.alpha = 0.25; + +%% Tracklet confidence +param.lambda = 1.2; +param.atten = 0.85; +param.init_prob = 0.75; % Initial confidence + +%% Appearance Model +param.tmplsize = [64, 32]; % template size (height, width) +param.Bin = 48; % # of Histogram Bin +param.vecsize = param.tmplsize(1)*param.tmplsize(2); +param.subregion = 8; +param.subvec = param.vecsize/param.subregion ; +param.color.type = 'RGB'; % RGB or HSV + +%% Motion model +% kalman filter parameter +param.Ts = 1; % Frame rates + +Ts = param.Ts; +F1 = [1 Ts;0 1]; +Fz = zeros(2,2); +param.F = [F1 Fz;Fz F1]; % F matrix: state transition matrix + +% Dynamic model covariance +q= 0.05; + +Q1 = [Ts^4 Ts^2;Ts^2 Ts]*q^2; +param.Q = [Q1 Fz;Fz Q1]; + +% Initial Error Covariance +ppp = 5; +param.P = diag([ppp ppp ppp ppp]'); +param.H = [1 0 0 0;0 0 1 0]; % H matrix: measurement model +param.R = 0.1*eye(2); % Measurement model covariance + +%% ILDA parameters +param.use_ILDA = 0; % 1:ILDA, 0: No-ILDA +ILDA.n_update = 0; +ILDA.eigenThreshold = 0.01; +ILDA.up_ratio = 3; +ILDA.duration = 5; +ILDA.feat_data = []; +ILDA.feat_label = []; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_shape_similarity.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_shape_similarity.m new file mode 100644 index 0000000000000000000000000000000000000000..0ced96d8476d7a619016d71d46b786dd7a880db4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_shape_similarity.m @@ -0,0 +1,5 @@ +function [Affinity] = mot_shape_similarity(rh, rw, th,tw) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +Affinity = exp(-1.5*((abs(rh - th)/(rh + th)) + (abs(rw - tw)/(rw + tw)))); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_tracklets_components_setup.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_tracklets_components_setup.m new file mode 100644 index 0000000000000000000000000000000000000000..4746f65871ecbe3ad6dd6edbd808b9155c5d0910 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/mot_func/mot_tracklets_components_setup.m @@ -0,0 +1,62 @@ +function [Trk, param] = mot_tracklets_components_setup(img,Trk,detections,cfr,y_idx,param,tmp_label) +%% Copyright (C) 2014 Seung-Hwan Bae +%% All rights reserved. + +noft = length(Trk)+1; +ass_idx = y_idx; +nofa = length(find(y_idx ~= 0)); + +Trk(noft).Conf_prob = param.init_prob; + +Trk(noft).type = 'High'; +Trk(noft).reliable = 'False'; +Trk(noft).isnew = 1; +Trk(noft).sub_img = []; +Trk(noft).status = 'none'; + +if ~isempty(tmp_label) + Trk(noft).label = tmp_label; +else + [param,idx] = Labelling(param); + Trk(noft).label = idx; +end + +Trk(noft).ifr = cfr -nofa + 1; +Trk(noft).efr = 0; +Trk(noft).last_update = cfr; + +Acc_tmpl = zeros(param.Bin*3, param.subregion); +for i=1:nofa + tmp_idx = cfr-i+1; + Trk(noft).state{tmp_idx}(1,1) = detections(tmp_idx).x(ass_idx(tmp_idx)); + Trk(noft).state{tmp_idx}(2,1) = detections(tmp_idx).y(ass_idx(tmp_idx)); + Trk(noft).state{tmp_idx}(3,1) = detections(tmp_idx).w(ass_idx(tmp_idx)); + Trk(noft).state{tmp_idx}(4,1) = detections(tmp_idx).h(ass_idx(tmp_idx)); + + tmpl = mot_appearance_model_generation(img{tmp_idx},param,Trk(noft).state{tmp_idx}); + + Acc_tmpl = Acc_tmpl + tmpl; +end + + +% Appearnce Model +Trk(noft).A_Model = Acc_tmpl./nofa; + + +% Forward Motion Model +[XX,PP] = mot_motion_model_generation(Trk(noft),param,'Forward'); + +lt = size(XX,2); +Trk(noft).FMotion.X(:,cfr-lt+1 :cfr) = XX; +Trk(noft).FMotion.P(:,:,cfr-lt+1 :cfr) = PP; + + +Trk(noft).BMotion.X = []; +Trk(noft).BMotion.P = []; + +Trk(noft).hyp.score(cfr) = 0; +Trk(noft).hyp.ystate{cfr} = []; + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/parseDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/parseDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..7cb665bb4814ea8a170152925f35b44ad1b346d5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/parseDetections.m @@ -0,0 +1,14 @@ +function detections = parseDetections(detSet, numFrames) + +for i = numFrames + idx = find(detSet(:,1) == i); + left = detSet(idx,3); + top = detSet(idx,4); + right = detSet(idx,3) + detSet(idx,5) - 1; + down = detSet(idx,4) + detSet(idx,6) - 1; + + detections(i).x = (left+right)/2; + detections(i).y = (top+down)/2; + detections(i).w = (right-left+1); + detections(i).h = (down-top+1); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/run_tracker.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/run_tracker.m new file mode 100644 index 0000000000000000000000000000000000000000..f7c0633a204915985786c1c0212a88b45ae2faa2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/run_tracker.m @@ -0,0 +1,67 @@ +function [stateInfo, speed] = run_tracker(curSequence, baselinedetections) +%% Robust Online Multi-Object Tracking based on Tracklet Confidence +%% and Online Discriminative Appearance Learning (CVPR2014) + +DrawOption.isdraw = 0; +DrawOption.iswrite = 0; +DrawOption.isprint = 1; + +% set parameters +mot_setting_params(); +% load detections +detections = parseDetections(baselinedetections, curSequence.frameNums); +frame_start = 1; +frame_end = length(detections); + +All_Eval = [];cct = 0;Trk = []; Trk_sets = []; +%% Initiailization Tracklet +tstart1 = tic; +init_frame = frame_start + param.show_scan; +init_img_set = cell(1, init_frame); +for i=1:init_frame + Obs_grap(i).iso_idx = ones(size(detections(i).x)); + Obs_grap(i).child = []; + Obs_grap(i).iso_child =[]; +end +Obs_grap = mot_pre_association(detections, Obs_grap, frame_start, init_frame); +st_fr = 1; +en_fr = init_frame; + +for fr = 1:init_frame + filename = strcat(curSequence.imgFolder, curSequence.dataset(fr).name); + init_img_set{fr} = imread(filename); +end + +[Trk, param, Obs_grap] = MOT_Initialization_Tracklets(init_img_set,Trk,detections,param,Obs_grap,init_frame); + +%% Tracking +for fr = init_frame+1:frame_end + filename = strcat(curSequence.imgFolder, curSequence.dataset(fr).name); + init_img_set{fr} = imread(filename); + %% Local Association + [Trk, Obs_grap, Obs_info] = MOT_Local_Association(Trk, detections, Obs_grap, param, ILDA, fr, init_img_set{fr}); + %% Global Association + [Trk, Obs_grap] = MOT_Global_Association(Trk, Obs_grap, Obs_info, param, ILDA, fr); + %% Tracklet Confidence Update + Trk = MOT_Confidence_Update(Trk,param,fr, param.lambda); + Trk = MOT_Type_Update(init_img_set{fr},Trk,param.type_thr,fr); + %% Tracklet State Update & Tracklet Model Update + Trk = MOT_State_Update(Trk, param, fr); + %% New Tracklet Generation + [Trk, param, Obs_grap] = MOT_Generation_Tracklets(init_img_set,Trk,detections,param,Obs_grap,fr); + %% Incremental subspace learning + if param.use_ILDA + rgbimg = init_img_set{fr}; + ILDA = MOT_Online_Appearance_Learning(rgbimg, imgFolder, dataset, fr, Trk, param, ILDA); + end + %% Tracking Results + Trk_sets = MOT_Tracking_Results(Trk,Trk_sets,fr); +end +TotalTime = toc(tstart1); +speed = frame_end/TotalTime; + +%% Draw Tracking Results +DrawOption.new_thr = param.new_thr; +% Box colors indicate the confidences of tracked objects +% High (Red)-> Low (Blue) +stateInfo = MOT_Draw_Tracking(Trk_sets, curSequence.imgFolder, curSequence.dataset, frame_end, DrawOption); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/CLEAR_MOT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/CLEAR_MOT.m new file mode 100644 index 0000000000000000000000000000000000000000..4b3b89c60fccba78e14f8e6700cca0a5abbcf0ce --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/CLEAR_MOT.m @@ -0,0 +1,334 @@ +function [metrics metricsInfo]=CLEAR_MOT(gtInfo,stateInfo,options) +% compute CLEAR MOT and other metrics +% +% metrics contains the following +% [1] recall - recall = percentage of detected targets +% [2] precision - precision = percentage of correctly detected targets +% [3] FAR - number of false alarms per frame +% [4] GT - number of ground truth trajectories +% [5-7] MT, PT, ML - number of mostly tracked, partially tracked and mostly lost trajectories +% [8] falsepositives- number of false positives (FP) +% [9] missed - number of missed targets (FN) +% [10] idswitches - number of id switches (IDs) +% [11] FRA - number of fragmentations +% [12] MOTA - Multi-object tracking accuracy in [0,100] +% [13] MOTP - Multi-object tracking precision in [0,100] (3D) / [td,100] (2D) +% [14] MOTAL - Multi-object tracking accuracy in [0,100] with log10(idswitches) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% default options: 2D +if nargin<3 + options.eval3d=0; % only bounding box overlap + options.td=.5; % threshold 50% +end + +if ~isfield(options,'td') + if options.eval3d + options.td=1000; + else + options.td=0.5; + end +end + +td=options.td; + +assert(length(gtInfo.frameNums)==length(stateInfo.frameNums), ... + 'Ground Truth and state must be of equal length'); +if(gtInfo.frameNums(1)~=stateInfo.frameNums(1)) + gtInfo.frameNums = gtInfo.frameNums + stateInfo.frameNums(1) - gtInfo.frameNums(1); +end +assert(all(gtInfo.frameNums==stateInfo.frameNums), ... + 'Ground Truth and state must contain equal frame numbers'); + +% check if all necessery info is available +if options.eval3d + assert(all(isfield(gtInfo,{'Xgp','Ygp'})), ... + 'Ground Truth Ground Plane coordinates needed for 3D evaluation'); + assert(all(isfield(stateInfo,{'Xgp','Ygp'})), ... + 'Ground Plane coordinates needed for 3D evaluation'); +else + assert(all(isfield(gtInfo,{'X','Y','W','H'})), ... + 'Ground Truth coordinates X,Y,W,H needed for 2D evaluation'); + assert(all(isfield(stateInfo,{'Xi','Yi','W','H'})), ... + 'State coordinates Xi,Yi,W,H needed for 2D evaluation'); + +end + +gtInd=~~gtInfo.X; +stInd=~~stateInfo.X; + +[Fgt Ngt]=size(gtInfo.X); +[F N]=size(stateInfo.X); + +aspectRatio=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% gtInfo.W=gtInfo.H*aspectRatio; + + +metricsInfo.names.long = {'Recall','Precision','False Alarm Rate', ... + 'GT Tracks','Mostly Tracked','Partially Tracked','Mostly Lost', ... + 'False Positives', 'False Negatives', 'ID Switches', 'Fragmentations', ... + 'MOTA','MOTP', 'MOTA Log'}; + +metricsInfo.names.short = {'Rcll','Prcn','FAR', ... + 'GT','MT','PT','ML', ... + 'FP', 'FN', 'IDs', 'FM', ... + 'MOTA','MOTP', 'MOTAL'}; + +metricsInfo.widths.long = [6 9 16 9 14 17 11 15 15 11 14 5 5 8]; +metricsInfo.widths.short = [5 5 5 3 3 3 3 4 4 3 3 5 5 5]; + +metricsInfo.format.long = {'.1f','.1f','.2f', ... + 'i','i','i','i', ... + 'i','i','i','i', ... + '.1f','.1f','.1f'}; + +metricsInfo.format.short=metricsInfo.format.long; + + +metrics=zeros(1,14); +metrics(9)=numel(find(gtInd)); % False Negatives (missed) +metrics(7)=Ngt; % Mostly Lost + +% nothing to be done, if state is empty +if ~N, return; end + +% global opt +% if options.eval3d && opt.mex +% [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% CLEAR_MOT_mex(gtInfo.Xgp', gtInfo.Ygp', stateInfo.Xgp', stateInfo.Ygp',options.td); +% +% % cd /home/aanton/diss/utils +% % [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% % CLEAR_MOT(gtInfo.Xgp, gtInfo.Ygp, stateInfo.Xgp, stateInfo.Ygp,options.td); +% % cd /home/aanton/visinf/projects/ongoing/contracking +% metrics=[rc*100, pc*100, faf, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FM, MOTA*100, MOTP*100, MOTAL*100]; +% metrics +% global gsi +% gsi=stateInfo; +% pause +% return; +% end + + +% mapping +M=zeros(F,Ngt); + +mme=zeros(1,F); % ID Switchtes (mismatches) +c=zeros(1,F); % matches found +fp=zeros(1,F); % false positives +m=zeros(1,F); % misses = false negatives +g=zeros(1,F); +d=zeros(F,Ngt); % all distances; +ious=Inf*ones(F,Ngt); % all overlaps + +matched=@matched2d; +if options.eval3d, matched=@matched3d; end + +alltracked=zeros(F,Ngt); +allfalsepos=zeros(F,N); + +for t=1:F + g(t)=numel(find(gtInd(t,:))); + + % mapping for current frame + if t>1 + mappings=find(M(t-1,:)); + for map=mappings + if gtInd(t,map) && stInd(t,M(t-1,map)) && matched(gtInfo,stateInfo,t,map,M(t-1,map),td*0.8) + M(t,map)=M(t-1,map); + end + end + end + + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + + if options.eval3d +% alldist=Inf*ones(Ngt,N); +% mindist=0; +% while mindist < td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 +% for o=GTsNotMapped +% GT=[gtInfo.Xgp(t,o) gtInfo.Ygp(t,o)]; +% for e=EsNotMapped +% E=[stateInfo.Xgp(t,e) stateInfo.Ygp(t,e)]; +% alldist(o,e)=norm(GT-E); +% end +% end +% [mindist, cind]=min(alldist(:)); +% if mindist <= td +% [u v]=ind2sub(size(alldist),cind); +% M(t,u)=v; +% alldist(:,v)=Inf; +% GTsNotMapped=find(~M(t,:) & gtInd(t,:)); +% EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); +% end +% end + + cost = zeros(numel(GTsNotMapped), numel(EsNotMapped)); + for o = 1:numel(GTsNotMapped) + GT = [gtInfo.Xgp(t,GTsNotMapped(o)), gtInfo.Ygp(t,GTsNotMapped(o))]; + for e = 1:numel(EsNotMapped) + E = [stateInfo.Xgp(t,EsNotMapped(e)), stateInfo.Ygp(t,EsNotMapped(e))]; + cost(o,e)=norm(GT-E); + end + end + cost(cost > td) = Inf; + assignLabel = munkres(cost); + for i = 1:numel(assignLabel) + if(assignLabel(i)) + M(t, GTsNotMapped(i)) = EsNotMapped(assignLabel(i)); + end + end + + else + allisects=zeros(Ngt,N); maxisect=Inf; + + while maxisect > td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 + for o=GTsNotMapped + GT=[gtInfo.X(t,o)-gtInfo.W(t,o)/2 ... + gtInfo.Y(t,o)-gtInfo.H(t,o) ... + gtInfo.W(t,o) gtInfo.H(t,o) ]; + for e=EsNotMapped + E=[stateInfo.Xi(t,e)-stateInfo.W(t,e)/2 ... + stateInfo.Yi(t,e)-stateInfo.H(t,e) ... + stateInfo.W(t,e) stateInfo.H(t,e) ]; + allisects(o,e)=boxiou(GT(1),GT(2),GT(3),GT(4),E(1),E(2),E(3),E(4)); + end + end + [maxisect cind]=max(allisects(:)); + + if maxisect >= td + [u v]=ind2sub(size(allisects),cind); + M(t,u)=v; + allisects(:,v)=0; + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + end + + end + end + + curtracked=find(M(t,:)); + + + alltrackers=find(stInd(t,:)); + mappedtrackers=intersect(M(t,find(M(t,:))),alltrackers); + falsepositives=setdiff(alltrackers,mappedtrackers); + + alltracked(t,:)=M(t,:); + allfalsepos(t,1:length(falsepositives))=falsepositives; + + %% mismatch errors + if t>1 + for ct=curtracked + lastnotempty=find(M(1:t-1,ct),1,'last'); + if gtInd(t-1,ct) && ~isempty(lastnotempty) && M(t,ct)~=M(lastnotempty,ct) + mme(t)=mme(t)+1; + end + end + end + + c(t)=numel(curtracked); + for ct=curtracked + eid=M(t,ct); + if options.eval3d + d(t,ct)=norm([gtInfo.Xgp(t,ct) gtInfo.Ygp(t,ct)] - ... + [stateInfo.Xgp(t,eid) stateInfo.Ygp(t,eid)]); + else + gtLeft=gtInfo.X(t,ct)-gtInfo.W(t,ct)/2; + gtTop=gtInfo.Y(t,ct)-gtInfo.H(t,ct); + gtWidth=gtInfo.W(t,ct); gtHeight=gtInfo.H(t,ct); + + stLeft=stateInfo.Xi(t,eid)-stateInfo.W(t,eid)/2; + stTop=stateInfo.Yi(t,eid)-stateInfo.H(t,eid); + stWidth=stateInfo.W(t,eid); stHeight=stateInfo.H(t,eid); + ious(t,ct)=boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight); + end + end + + + fp(t)=numel(find(stInd(t,:)))-c(t); + m(t)=g(t)-c(t); + + +end + +missed=sum(m); +falsepositives=sum(fp); +idswitches=sum(mme); + +if options.eval3d + MOTP=(1-sum(sum(d))/sum(c)/td) * 100; % avg distance to [0,100] +else + MOTP=sum(ious(ious>=td & ious0)); + if(gtlength/gttotallength >= 0.8 && trlengtha/gttotallength < 0.2) + MTstatsa(i)=3; + elseif(t>=find(gtInd(:,i),1,'last') && trlengtha/gttotallength <= 0.8) + MTstatsa(i)=2; + elseif trlengtha/gttotallength >= 0.8 + MTstatsa(i)=1; + end +end +% MTstatsa +MT=numel(find(MTstatsa==1));PT=numel(find(MTstatsa==2));ML=numel(find(MTstatsa==3)); + +%% fragments +fr=zeros(1,Ngt); +for i=1:Ngt + b=alltracked(find(alltracked(:,i),1,'first'):find(alltracked(:,i),1,'last'),i); + b(~~b)=1; + fr(i)=numel(find(diff(b)==-1)); +end +FRA=sum(fr); + +assert(Ngt==MT+PT+ML,'Hmm... Not all tracks classified correctly.'); +metrics=[recall, precision, FAR, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FRA, MOTA, MOTP, MOTAL]; +end + + + + +function ret=matched2d(gtInfo,stateInfo,t,map,mID,td) + gtLeft=gtInfo.X(t,map)-gtInfo.W(t,map)/2; + gtTop=gtInfo.Y(t,map)-gtInfo.H(t,map); + gtWidth=gtInfo.W(t,map); gtHeight=gtInfo.H(t,map); + + stLeft=stateInfo.Xi(t,mID)-stateInfo.W(t,mID)/2; + stTop=stateInfo.Yi(t,mID)-stateInfo.H(t,mID); + stWidth=stateInfo.W(t,mID); stHeight=stateInfo.H(t,mID); + + ret = boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight) >= td; +end + + +function ret=matched3d(gtInfo,stateInfo,t,map,mID,td) + Xgt=gtInfo.Xgp(t,map); Ygt=gtInfo.Ygp(t,map); + X=stateInfo.Xgp(t,mID); Y=stateInfo.Ygp(t,mID); + ret=norm([Xgt Ygt]-[X Y])<=td; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/boxIntersect.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/boxIntersect.m new file mode 100644 index 0000000000000000000000000000000000000000..5a55b45131c36980ad641f838452967a12bf300b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/boxIntersect.m @@ -0,0 +1,24 @@ +function isect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2) +% A=[bboxleft1 bboxbottom1 abs(bboxright1-bboxleft1) abs(bboxbottom1-bboxup1)]; +% B=[bboxleft2 bboxbottom2 abs(bboxright2-bboxleft2) abs(bboxbottom2-bboxup2)]; +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% isect=rectint(A,B); +isect=0; + +hor= max(0,min(bboxright1,bboxright2) - max(bboxleft1,bboxleft2)); + +if ~hor, return; end +ver= max(0,min(bboxbottom1,bboxbottom2) - max(bboxup1,bboxup2)); +if ~ver, return; end + +isect = hor*ver; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/boxUnion.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/boxUnion.m new file mode 100644 index 0000000000000000000000000000000000000000..c5b8e06c5ea242199dbffa15e553ec07b626fab9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/boxUnion.m @@ -0,0 +1,24 @@ +function union=boxUnion(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2,isect) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +a1=bboxright1-bboxleft1; +b1=bboxbottom1-bboxup1; +a2=bboxright2-bboxleft2; +b2=bboxbottom2-bboxup2; +union=a1*b1+a2*b2; +if nargin>8 + bisect=isect; +else + bisect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2); +end +union=union-bisect; + + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/boxiou.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/boxiou.m new file mode 100644 index 0000000000000000000000000000000000000000..395e5dc90d032ee2d7f3c9554148e56f908eeab5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/boxiou.m @@ -0,0 +1,21 @@ +function iou=boxiou(x1,y1,w1,h1,x2,y2,w2,h2) +% compute intersection over union of two bboxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + bisect=boxIntersect(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2); + iou=0; + if ~bisect, return; end + + bunion=boxUnion(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2,bisect); + + assert(bunion>0,'something wrong with union computation'); + iou=bisect/bunion; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/distortedToUndistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/distortedToUndistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..6e62dfbd4271580faef309647e42784c11964e31 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/distortedToUndistortedImageCoord.m @@ -0,0 +1,15 @@ +function [Xfu Yfu]=distortedToUndistortedImageCoord (Xfd, Yfd, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xd = mDpx * (Xfd - mCx) / mSx; + Yd = mDpy * (Yfd - mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ + [Xu Yu]=distortedToUndistortedSensorCoord(Xd, Yd, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfu = Xu * mSx / mDpx + mCx; + Yfu = Yu / mDpy + mCy; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/distortedToUndistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/distortedToUndistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..14158bd36e686650ae77a8621b1ed3c4d56e298a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/distortedToUndistortedSensorCoord.m @@ -0,0 +1,6 @@ +function [Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mKappa1) +% /* convert from distorted to undistorted sensor plane coordinates */ + distortion_factor = 1 + mKappa1 * (Xd*Xd + Yd*Yd); + Xu = Xd * distortion_factor; + Yu = Yd * distortion_factor; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/getRotTrans.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/getRotTrans.m new file mode 100644 index 0000000000000000000000000000000000000000..725097d307f8d0b7a1d211e756f99d82d45ebe1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/getRotTrans.m @@ -0,0 +1,34 @@ +function [mR mT]=getRotTrans(camPar) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + %%% Rotation Translation %%% + mT=[camPar.mExt.mTx;camPar.mExt.mTy;camPar.mExt.mTz]; + sa = sin(camPar.mExt.mRx); + ca = cos(camPar.mExt.mRx); + sb = sin(camPar.mExt.mRy); + cb = cos(camPar.mExt.mRy); + sg = sin(camPar.mExt.mRz); + cg = cos(camPar.mExt.mRz); + + mR11 = cb * cg; + mR12 = cg * sa * sb - ca * sg; + mR13 = sa * sg + ca * cg * sb; + mR21 = cb * sg; + mR22 = sa * sb * sg + ca * cg; + mR23 = ca * sb * sg - cg * sa; + mR31 = -sb; + mR32 = cb * sa; + mR33 = ca * cb; + + mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/imageToWorld.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/imageToWorld.m new file mode 100644 index 0000000000000000000000000000000000000000..3919cb798acbbeec7f826c6ea524dee3c3035476 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/imageToWorld.m @@ -0,0 +1,62 @@ +function [Xw Yw Zw]=imageToWorld(Xi, Yi, camPar) + +mGeo=camPar.mGeo; +mExt=camPar.mExt; +mInt=camPar.mInt; + +mTx=mExt.mTx; +mTy=mExt.mTy; +mTz=mExt.mTz; + +mT=[mExt.mTx;mExt.mTy;mExt.mTz]; + +%% internal init +sa = sin(mExt.mRx); +ca = cos(mExt.mRx); +sb = sin(mExt.mRy); +cb = cos(mExt.mRy); +sg = sin(mExt.mRz); +cg = cos(mExt.mRz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + + + +% /* convert from image to distorted sensor coordinates */ +Xd = mGeo.mDpx * (Xi - mInt.mCx) / mInt.mSx; +Yd = mGeo.mDpy * (Yi - mInt.mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ +[Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mInt.mKappa1); + +% /* calculate the corresponding xw and yw world coordinates */ +% /* (these equations were derived by simply inverting */ +% /* the perspective projection equations using Macsyma) */ +Zw=0; +common_denominator = ((mR11 * mR32 - mR12 * mR31) * Yu + ... + (mR22 * mR31 - mR21 * mR32) * Xu - ... + mInt.mFocal * mR11 * mR22 + mInt.mFocal * mR12 * mR21); + +Xw = (((mR12 * mR33 - mR13 * mR32) * Yu + ... + (mR23 * mR32 - mR22 * mR33) * Xu - ... + mInt.mFocal * mR12 * mR23 + mInt.mFocal * mR13 * mR22) * Zw + ... + (mR12 * mTz - mR32 * mTx) * Yu + ... + (mR32 * mTy - mR22 * mTz) * Xu - ... + mInt.mFocal * mR12 * mTy + mInt.mFocal * mR22 * mTx) / common_denominator; + +Yw = -(((mR11 * mR33 - mR13 * mR31) * Yu + ... + (mR23 * mR31 - mR21 * mR33) * Xu - ... + mInt.mFocal * mR11 * mR23 + mInt.mFocal * mR13 * mR21) * Zw + ... + (mR11 * mTz - mR31 * mTx) * Yu + ... + (mR31 * mTy - mR21 * mTz) * Xu - ... + mInt.mFocal * mR11 * mTy + mInt.mFocal * mR21 * mTx) / common_denominator; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/parseCameraParameters.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/parseCameraParameters.m new file mode 100644 index 0000000000000000000000000000000000000000..10baec4a50e7d06334ec9a16693a4ce178845580 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/parseCameraParameters.m @@ -0,0 +1,104 @@ +function camPar=parseCameraParameters(camconffile) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +xDoc=xmlread(fullfile(camconffile)); + +width=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('width')); +height=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('height')); + +ncx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('ncx')); +nfx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('nfx')); +dx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dx')); +dy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dy')); +dpx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpx')); +dpy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpy')); + +focal=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('focal')); +kappa1=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('kappa1')); +cx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cx')); +cy=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cy')); +sx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('sx')); + +tx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tx')); +ty=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ty')); +tz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tz')); +rx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rx')); +ry=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ry')); +rz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rz')); + +mGeo.mImgWidth = width; +mGeo.mImgHeight = height; +mGeo.mNcx = ncx; +mGeo.mNfx = nfx; +mGeo.mDx = dx; +mGeo.mDy = dy; +mGeo.mDpx = dpx; +mGeo.mDpy = dpy; + + +%% intrinsic +mInt.mFocal = focal; +mInt.mKappa1 = kappa1; +mInt.mCx = cx; +mInt.mCy = cy; +mInt.mSx = sx; + +%% extrinsic +mExt.mTx = tx; +mExt.mTy = ty; +mExt.mTz = tz; +mExt.mRx = rx; +mExt.mRy = ry; +mExt.mRz = rz; + +%% inverted +mT=[tx;ty;tz]; +sa = sin(rx); +ca = cos(rx); +sb = sin(ry); +cb = cos(ry); +sg = sin(rz); +cg = cos(rz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + +mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; + +transform=[mR mT;[0 0 0 1]]; +invtrans=inv(transform); +tx=invtrans(1,4);ty=invtrans(2,4);tz=invtrans(3,4); + +mExt.mTxi = tx; +mExt.mTyi = ty; +mExt.mTzi = tz; + +camPar.mExt=mExt; +camPar.mInt=mInt; +camPar.mGeo=mGeo; + +%% mkappa<0 +if kappa1<0 + warning('CAREFUL! kappa1 < 0, cam derivates are wrong!'); +end + +[camPar.mR camPar.mT]=getRotTrans(camPar); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/undistortedToDistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/undistortedToDistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..9c9f9a1382cfcbf25407f159a06cc73d4440c9a1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/undistortedToDistortedImageCoord.m @@ -0,0 +1,14 @@ +function [Xfd Yfd]=undistortedToDistortedImageCoord (Xfu, Yfu, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xu = mDpx * (Xfu - mCx) / mSx; + Yu = mDpy * (Yfu - mCy); + +% /* convert from undistorted sensor to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord(Xu, Yu, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfd = Xd * mSx / mDpx + mCx; + Yfd = Yd / mDpy + mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/undistortedToDistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/undistortedToDistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..b689d695a1a98a28a8ba414a7661fe9658d24403 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/undistortedToDistortedSensorCoord.m @@ -0,0 +1,67 @@ +function [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mKappa1) + +% global ifs elses + +if ((~Xu && ~Yu) || ~mKappa1) +% ifs(1)=ifs(1)+1; + Xd = Xu; + Yd = Yu; +else %% THIS ONE %% +% elses(1)=elses(1)+1; + Ru = sqrt(Xu*Xu + Yu*Yu); + + c = 1.0 / mKappa1; + d = -c * Ru; + + Q = c / 3; + R = -d / 2; + D = Q*Q*Q + R*R; + + if (D >= 0) %% THIS ONE %% +% ifs(2)=ifs(2)+1; + %/* one real root */ + D = sqrt(D); + if (R + D > 0) %% THIS ONE %% +% ifs(3)=ifs(3)+1; + S = (R + D)^ (1.0/3.0); + else +% elses(3)=elses(3)+1; + S = -(-R - D)^ (1.0/3.0); + end + if (R - D > 0) +% ifs(4)=ifs(4)+1; + T = (R - D)^(1.0/3.0); + else %% THIS ONE %% +% elses(4)=elses(4)+1; + T = -(D - R)^(1.0/3.0); + end + Rd = S + T; + + if (Rd < 0) + Rd = sqrt(-1.0 / (3 * mKappa1)); + % /*fprintf (stderr, "\nWarning: undistorted image point to distorted image point mapping limited by\n"); + % fprintf (stderr, " maximum barrel distortion radius of %lf\n", Rd); + % fprintf (stderr, " (Xu = %lf, Yu = %lf) -> (Xd = %lf, Yd = %lf)\n\n", Xu, Yu, Xu * Rd / Ru, Yu * Rd / Ru);*/ + end + else +% elses(2)=elses(2)+1; + % /* three real roots */ + D = sqrt(-D); + S = ( sqrt(R*R + D*D))^(1.0/3.0 ); + T = atan2(D, R) / 3; + sinT = sin(T); + cosT = cos(T); + + % /* the larger positive root is 2*S*cos(T) */ + % /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ + % /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ + + Rd = -S * cosT + sqrt(3.0) * S * sinT; % /* use the smaller positive root */ + end + + lambda = Rd / Ru; + + Xd = Xu * lambda; + Yd = Yu * lambda; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/worldToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/worldToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..8bb11eb8cfff82e0e805c07f7f22d5e81042b241 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/camera/worldToImage.m @@ -0,0 +1,28 @@ +function [Xi Yi]=worldToImage(Xw,Yw,Zw,mR,mT,mInt,mGeo) + + + % /* convert from world coordinates to camera coordinates */ + x=[mR mT]*[Xw;Yw;Zw;1]; + xc = x(1); + yc = x(2); + zc = x(3); + + % /* convert from camera coordinates to undistorted sensor plane coordinates */ + Xu = mInt.mFocal * xc / zc; + Yu = mInt.mFocal * yc / zc; + + % /* convert from undistorted to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mInt.mKappa1); + % Xd=Xu; + % Yd=Yu; + + % Rusq=Xu*Xu+Yu*Yu; + % Ru=sqrt(Xu*Xu+Yu*Yu); + % Xd=Xu*(1+mInt.mKappa1*Rusq); + % Yd=Yu*(1+mInt.mKappa1*Rusq); + + + % /* convert from distorted sensor plane coordinates to image coordinates */ + Xi = Xd * mInt.mSx / mGeo.mDpx + mInt.mCx; + Yi = Yd / mGeo.mDpy + mInt.mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/checkInitSolution.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/checkInitSolution.m new file mode 100644 index 0000000000000000000000000000000000000000..2c804a3311ac0367686b89db9d6c9864a4856c0c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/checkInitSolution.m @@ -0,0 +1,22 @@ +function [Xinit Yinit]=checkInitSolution(Xinit,Yinit,F) +% check if initial solution is correct +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + assert(all(size(Xinit)==size(Yinit)), ... + 'X and Y are of different size in initial solution'); + + % pad with zeros if not enough frames + Finit=size(Xinit,1); + if FinitareaLimits(2))=0;Ygp(Ygp>areaLimits(4))=0; +Ygp(Xgp==0)=0; Xgp(Ygp==0)=0; + +allzeros=(Xgp == 0 | Ygp ==0); +gtInfo.X(allzeros)=0;gtInfo.Y(allzeros)=0; +gtInfo.W(allzeros)=0;gtInfo.H(allzeros)=0; +gtInfo.Xgp(allzeros)=0;gtInfo.Ygp(allzeros)=0; + +% now clean up zero columns +gtInfo=cleanGT(gtInfo); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/cutStateToTrackingArea.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/cutStateToTrackingArea.m new file mode 100644 index 0000000000000000000000000000000000000000..977d2e957af687926552ce27c94bcb207992f6b8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/cutStateToTrackingArea.m @@ -0,0 +1,28 @@ +function stateInfo=cutStateToTrackingArea(stateInfo) +% if we are tracking on ground plane +% remove all track segments outside tracking area +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo; + +X=stateInfo.X; Y=stateInfo.Y; +areaLimits=sceneInfo.trackingArea; + +X(XareaLimits(2))=0;Y(Y>areaLimits(4))=0; +Y(X==0)=0; X(Y==0)=0; + +% now clean up zero columns +[X Y stateInfo]=cleanState(X,Y,stateInfo); + +stateInfo.X=X; stateInfo.Y=Y; + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..9068d48fdf2e5ebc45546a2ea6631ec363810209 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayBBoxes.m @@ -0,0 +1,205 @@ +function displayBBoxes(sceneInfo,frameNums,X,Y,W,H,options) +% Draw bounding boxes on top of images +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% +[F,~]=size(X); + +ind=find(W); +aspectRatio=mean(H(ind)./W(ind)); + +%% if we want to display traces, lets compute average image +% or let's not... Doesn't look good, anyway + +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(1))]); +% avim=zeros(size(im)); +% avgF=1:5:min(500,F); +% avgnF=length(avgF); +% for t=avgF +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]); +% avim=avim+double(im)/avgnF; +% end +% avim=avim/255; + +global opt; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + al=0.5; + load(sceneInfo.bgMask); + immask=cat(3,bgmask,bgmask,bgmask); + + end + +for t=1:F + clf + im=double(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]))/255; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + imgray=rgb2gray(im); imgray=imgray+0.5; + imgray=cat(3,imgray,imgray,imgray); + im(immask)=al*im(immask)+(1-al)*(imgray(immask)); + end + + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % tracking area + if opt.track3d && opt.cutToTA + drawTALimits; + end + + + extar=find(X(t,:)); + % foot position + if options.displayDots + for id=extar + plot(X(t,id),Y(t,id),'.','color',getColorFromID(id),'MarkerSize',options.dotSize); + end + end + + % box + if options.displayBoxes + for id=extar + bleft=X(t,id)-W(t,id)/2; + bright=X(t,id)+W(t,id)/2; + btop=Y(t,id)-H(t,id); + bbottom=Y(t,id); +% line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',getColorFromID(id),'linewidth',options.boxLineWidth); + rectangle('Position',[bleft,btop,W(t,id),H(t,id)],'Curvature',[.3,.3*(W(t,id)/H(t,id))],'EdgeColor',getColorFromID(id),'linewidth',options.boxLineWidth); + end + end + + % ID + if options.displayID + for id=extar + tx=X(t,id); + ty=Y(t,id)-H(t,id)*2/3; % inside +% ty=Y(t,id)-H(t,id)-10; % on top + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',W(t,id)/2, 'FontUnits','pixels','FontWeight','bold'); + end + end + + % cropouts + if options.displayCropouts + bw=2; %border cropouts + + %% crop outs var sized + maxTar=30; + extarRed=extar(extar<=maxTar); % reducde +% crpImg=zeros(round(max(max(H))+5),round(sum(max(W))+5*bw),3); +% offset=1; +% offsets=round([1 cumsum(max(W))]); +% for id=extarRed +% % offsets(id)=offset; +% offset=offsets(id); +% bleft=round(X(t,id)-W(t,id)/2); +% bright=round(X(t,id)+W(t,id)/2); +% btop=round(Y(t,id)-H(t,id)); +% bbottom=round(Y(t,id)); +% +% ht=(bbottom-btop)+1;wt=(bright-bleft)+1; +% crpImg(1:ht,offset:offset+wt-1,:)=im(btop:bbottom,bleft:bright,:); +% % offset=offset+wt+bw; +% end + + %% crop outs fixed sized + uniH=min(60,round(sceneInfo.imgHeight/10)); uniW=round(uniH/aspectRatio); +% crpImg=zeros(round(uniH+bw),round(uniW*size(W,2)+bw*size(W,2)),3); % black + mxfac=.5; + crpImg=im(1:uniH,1:min(sceneInfo.imgWidth,round(uniW*size(W,2)+bw*size(W,2))),:)*mxfac; + crpImg=crpImg + (1-mxfac)*ones(size(crpImg)); % bleeched + for id=extarRed + offset=(id-1)*uniW + (id-1)*bw+1; + bleft=round(X(t,id)-W(t,id)/2); + bright=round(X(t,id)+W(t,id)/2); + btop=round(Y(t,id)-H(t,id)); + bbottom=round(Y(t,id)); + + [bleft bright btop bbottom]= ... + clampBBox(bleft, bright, btop, bbottom, sceneInfo.imgWidth, sceneInfo.imgHeight); + ht=uniH; + imres=imresize(im(btop:bbottom,bleft:bright,:),[uniH uniW]); + crpImg(1:ht,offset:offset+uniW-1,:)=imres; + + end + imshow(crpImg); + + for id=extarRed +% tx=offsets(id)+W(t,id)/2; + tx=id*uniW-uniW/2 + id*bw; + ty=30; % top + ty=size(crpImg,1)-10; % below + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',uniW/2, 'FontUnits','pixels','FontWeight','bold'); % fixed size +% 'FontSize',mean(W(t,extarRed))/2, 'FontUnits','pixels','FontWeight','bold'); % var size + + end + if options.displayConnections + for id=extarRed + if t-find(X(:,id),1,'first')<5 + btop=round(Y(t,id)-H(t,id)); + offset=(id-1)*uniW + (id-1)*bw+1 + uniW/2; + line([X(t,id) offset],[btop uniH],'color',getColorFromID(id),'linestyle','-'); + end + end + end + end + + % show trace + if options.traceLength + for tracet=max(1,t-options.traceLength):max(1,t-1) + ipolpar=(t-tracet)/options.traceLength; % parameter [0,1] for color adjustment + + % pick color from tail +% if tracet==max(1,t-options.traceLength) +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(tracet))]); +% end + + extarpast=find(X(tracet,:)); + % foot position + for id=extarpast + % plot(X(tracet,id),Y(tracet,id), ... + % '.','color',ipolpar*options.grey + (1-ipolpar)*getColorFromID(id),'MarkerSize',max(1,options.dotSize*(1-ipolpar))); + + + if W(tracet+1,id) + posx=round(max(1,X(t,id))); posx=min(sceneInfo.imgWidth,posx); + posy=round(max(1,Y(t,id))); posy=min(sceneInfo.imgHeight,posy); +% endcol=double(reshape(avim(posy,posx,:),1,3)); +% endcol=min(1,endcol); endcol=max(1,endcol); + endcol=options.grey; + line(X(tracet:tracet+1,id) ,Y(tracet:tracet+1,id), ... + 'color',ipolpar*endcol + (1-ipolpar)*getColorFromID(id),'linewidth',(1-ipolpar)*options.traceWidth+1); + end + + end + + end + end + + + pause(options.framePause) + + % save + if isfield(options,'outFolder'); + im2save=getframe(gcf); + im2save=im2save.cdata; + imwrite(im2save, fullfile(options.outFolder,sprintf('frame_%04d.jpg',frameNums(t)))); + end + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayDetectionBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayDetectionBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..85a14f52b9a012f72c0909b95491270609907826 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayDetectionBBoxes.m @@ -0,0 +1,81 @@ +function displayDetectionBBoxes(sceneInfo, detections) +% Display Detection Bounding Boxes +% +% Take scene information sceneInfo and +% an array of detections and display +% them on +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +reopenFig('Detections') + +F=size(detections,2); +assert(F==length(sceneInfo.frameNums), 'length of detections must be equal to the number of frames'); + +detcol=[.1 .2 .9]; +grey=.6*ones(1,3); +framePause=0.01; % pause between frames +% framePause=1; + +traceLength=10; % overlay data from past 10 frames +dotSize=20; +boxLineWidth=3; + +for t=1:F + clf + im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(t))]); + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % foot position + for k=1:length(detections(t).xp) + plot(detections(t).xp(k),detections(t).yp(k),'.','color',detcol,'MarkerSize',dotSize*detections(t).sc(k)); + end + + % box + nboxes=length(detections(t).xp); + for id=1:nboxes + bleft=detections(t).bx(id); + bright=detections(t).bx(id)+detections(t).wd(id); + btop=detections(t).by(id); + bbottom=detections(t).by(id)+detections(t).ht(id); + line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',detcol,'linewidth',boxLineWidth*detections(t).sc(id)); + end + + % show trace + for tracet=max(1,t-traceLength):max(1,t-1) + ipolpar=(t-tracet)/traceLength; % parameter [0,1] for color adjustment + + % foot position + for k=1:length(detections(tracet).xp) + plot(detections(tracet).xi(k),detections(tracet).yi(k), ... + '.','color',ipolpar*grey + (1-ipolpar)*detcol,'MarkerSize',dotSize*detections(tracet).sc(k)); + end + + % box +% nboxes=length(detections(tracet).xp); +% for id=1:nboxes +% bleft=detections(tracet).xp(id)-detections(tracet).wd(id)/2; +% bright=detections(tracet).xp(id)+detections(tracet).wd(id)/2; +% btop=detections(tracet).yp(id)-detections(tracet).ht(id); +% bbottom=detections(tracet).yp(id); +% line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',ipolpar*grey + (1-ipolpar)*detcol); +% end + + end + + pause(framePause) + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayGroundTruth.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayGroundTruth.m new file mode 100644 index 0000000000000000000000000000000000000000..4135ebf073c38772bf347eb1f08f4a32ee9da49e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayGroundTruth.m @@ -0,0 +1,42 @@ +function displayGroundTruth(sceneInfo, gtInfo) +% Display Ground Truth +% +% Take scene information sceneInfo and +% the ground truth from gtInfo +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +W=gtInfo.W; +H=gtInfo.H; + + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.01; % pause between frames + +options.traceLength=20; % overlay data from past 10 frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +X=gtInfo.X; Y=gtInfo.Y; + +reopenFig('Ground Truth'); +displayBBoxes(sceneInfo,gtInfo.frameNums,X,Y,W,H,options) + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayTrackingResult.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayTrackingResult.m new file mode 100644 index 0000000000000000000000000000000000000000..83597c454e93ecbce07b434c3c51de8295834caa --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/displayTrackingResult.m @@ -0,0 +1,47 @@ +function displayTrackingResult(sceneInfo, stateInfo) +% Display Tracking Result +% +% Take scene information sceneInfo and +% the tracking result from stateInfo +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% [~, ~, ~, ~, X Y]=getStateInfo(stateInfo); +W=stateInfo.W; +H=stateInfo.H; +Xi=stateInfo.Xi; +Yi=stateInfo.Yi; + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.001; % pause between frames + +options.traceLength=20; % overlay track from past n frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +% save? +% options.outFolder='tmp'; + +reopenFig('Tracking Results') +displayBBoxes(sceneInfo,stateInfo.frameNums,Xi,Yi,W,H,options) + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/drawTALimits.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/drawTALimits.m new file mode 100644 index 0000000000000000000000000000000000000000..dafde616beee5dd1e9e9b4561ea00ce312b4f616 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/drawTALimits.m @@ -0,0 +1,36 @@ +function drawTALimits +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo + +c1=sceneInfo.trackingArea([1 3]); +c2=sceneInfo.trackingArea([2 3]); +c3=sceneInfo.trackingArea([2 4]); +c4=sceneInfo.trackingArea([1 4]); + + +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); + +[slx sly]=worldToImage(c1(1),c1(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(1)=slx; y(1)=sly; + +[slx sly]=worldToImage(c2(1),c2(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(2)=slx; y(2)=sly; + +[slx sly]=worldToImage(c3(1),c3(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(3)=slx; y(3)=sly; + +[slx sly]=worldToImage(c4(1),c4(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(4)=slx; y(4)=sly; + +line([x x(1)],[y y(1)],'linewidth',2,'color','w','linestyle','--'); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/estimateTargetsSize.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/estimateTargetsSize.m new file mode 100644 index 0000000000000000000000000000000000000000..6b980d7429d28c68ee11eae25b7ad1fb956edc42 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/estimateTargetsSize.m @@ -0,0 +1,53 @@ +function htobj=estimateTargetsSize(sceneInfo) +% Take best n percent of detections +% and fit a 2d surface through their heights +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +npercent = 25; % best 25 % + +% scenario=41; + +% sceneInfo=getSceneInfo(scenario); +detections=parseDetections(sceneInfo); +allxi=[];allxi=[];allyi=[];allsc=[];allht=[]; + +F=length(detections); +for t=1:F + allxi=[allxi detections(t).xi]; + allyi=[allyi detections(t).yi]; + allsc=[allsc detections(t).sc]; + allht=[allht detections(t).ht]; +end +minheight=15; +% goodones=find(allsc>0.75); % confident ones + +[allsc goodones]=sort(allsc,'descend'); goodones=goodones(1:round(length(goodones)/(1/npercent*100))); + +allxi=allxi(goodones);allyi=allyi(goodones);allsc=allsc(goodones);allht=allht(goodones); +htobj=fit([allxi; allyi]',allht','poly21','Robust','on'); + +% %% +% clf +% +% plot3(allxi,allyi,allht,'.'); box on +% xlim(sceneInfo.trackingArea(1:2));ylim(sceneInfo.trackingArea(3:4)); zlim([minheight sceneInfo.imgHeight]); +% set(gca,'Ydir','reverse'); +% +% hold on +% +% %% +% +% %% +% [xi yi]=meshgrid(1:50:sceneInfo.imgWidth, 1:50:sceneInfo.imgHeight); +% htsurface=feval(fitobj,xi(:),yi(:)); htsurface=reshape(htsurface,size(xi,1),size(xi,2)); +% htsurface(htsurfacesceneInfo.imgHeight)=sceneInfo.imgHeight; +% surf(xi,yi,htsurface) +% view(-78,34) \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/evaluateDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/evaluateDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..434bc96a586ea76a1c6195bd0d5a5d8572e5e8cc --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/evaluateDetections.m @@ -0,0 +1,28 @@ +function evaluateDetections(detMatrices,gtInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt +if sceneInfo.gtAvailable + detInfo=detMatrices; detInfo.frameNums=sceneInfo.frameNums; + detInfo.X=detInfo.Xi; detInfo.Y=detInfo.Yi; + [detInfo.F detInfo.N]=size(detInfo); + + if opt.track3d + detInfo=cutStateToTrackingArea(detInfo); +% gtInfo=cutGTToTrackingArea(gtInfo); + end + + printMessage(1,'\nDetections Evaluation (2D):\n'); + [metrics metricsInfo]=CLEAR_MOT(gtInfo,detInfo,struct('eval3d',0)); + printMetrics(metrics,metricsInfo,1,[1 2 3 8 9]); + printMessage(1,'\n'); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getBBoxesFromPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getBBoxesFromPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..fa0582c8ec7ae435a635a20df52d55f93d3b0f1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getBBoxesFromPrior.m @@ -0,0 +1,79 @@ +function stateInfo=getBBoxesFromPrior(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% just take the height prior for that +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo +% [~, N F targetsExist X Y]=getStateInfo(stateInfo); +X=stateInfo.X; Y=stateInfo.Y; + +[F N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + H=heightPrior; +else + error('sorry dude'); +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +% if sceneInfo.gtAvailable +% global gtInfo +% arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% aspectRatio= arithmean; +% end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +% stateInfo.W=H*sceneInfo.targetAR; % or take data set mean +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getBBoxesFromState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getBBoxesFromState.m new file mode 100644 index 0000000000000000000000000000000000000000..84f3e7485b0eab07e403e80940bb1a13cfaeaa16 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getBBoxesFromState.m @@ -0,0 +1,207 @@ +function stateInfo=getBBoxesFromState(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% To this end, we check for corresponding detections +% and interpolate them to get the solution boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo +% [~, N F targetsExist X Y]=getStateInfo(stateInfo); +X=stateInfo.X; Y=stateInfo.Y; + +[F N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + + +for id=1:N + sid=targetsExist(id,1); + eid=targetsExist(id,2); + frames=sid:eid; + asscDet=zeros(1,F); % which detection is close by? + widths=zeros(1,F); + heights=zeros(1,F); + scores=zeros(1,F); + + % find closest detections + for t=frames + ndets=length(detections(t).xp); % how many dets in this frame + if ndets + xy=[X(t,id); Y(t,id)]; + dets=[detections(t).xp; detections(t).yp]; + + alldist=sqrt(sum((repmat(xy,1,ndets)-dets).^2)); % distance to all + [mindist mindet]=min(alldist); + if mindist<=sceneInfo.targetSize + asscDet(t)=mindet; + widths(t)=detections(t).wd(mindet); + heights(t)=detections(t).ht(mindet); + scores(t)=detections(t).sc(mindet); + end + end + end + detsAssc=find(asscDet); % which detections associated + detsAsscWobble=detsAssc;%+0.01*rand(1,length(t))-0.005; % add random noise to avoid NaN in fitting (LOOK INTO THIS!) + + if numel(unique(detsAssc))>1 + polydeg=min(9,max(1,floor(numel(detsAssc)/100))); + polystr=sprintf('poly%d',polydeg); + +% global gdetsAssc gwidths +% gdetsAssc=detsAssc; gwidths=widths(detsAssc); +% detsAssc +% unique(detsAssc) +% heights(detsAssc) +% numel(detsAssc) +% +% polydeg +% +% polystr +% p=polyfit(detsAssc,widths(detsAssc),max(1,floor(numel(detsAssc)/100))); +% p=fit(detsAssc',widths(detsAssc)',polystr,'Normalize','on','Robust','on'); + +% ipolwidths = polyval(p,frames); +% ipolwidths = feval(p,frames); +% W((sid:eid)',id)=ipolwidths'; + + + + + +% +% +% numel(detsAssc) +% p=polyfit(detsAssc,heights(detsAssc),max(1,round(numel(detsAssc)/100))); +% [p,~,~,~]=fit(detsAssc',heights(detsAssc)',polystr,'Normalize','on','Robust','on'); + sp=splinefit(detsAsscWobble, heights(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); +% pause + +% ipolheights = polyval(p,frames); +% ipolheights = feval(p,frames); + ipolheights=ppval(sp,frames); + + + H((sid:eid)',id)=ipolheights'; + + if ~isfield(sceneInfo,'targetAR') % if no aspect ratio given, estimate widths +% [p,~,~,~]=fit(detsAssc',widths(detsAssc)',polystr,'Normalize','on','Robust','on'); + sp=splinefit(detsAsscWobble, widths(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); +% ipolwidths = feval(p,frames); + ipolwidths = ppval(sp,frames); + + W((sid:eid)',id)=ipolwidths'; + + end + + else % strange trajectory with < 3 detections + detwidthmean=[]; detheightmean=[]; +% sid +% eid + for t=sid:eid + detwidthmean=[detwidthmean mean(detections(t).wd)]; + detheightmean=[detheightmean mean(detections(t).ht)]; + end +% detwidthmean +% detheightmean + detwidthmean(isnan(detwidthmean))=mean(detwidthmean(~isnan(detwidthmean))); + detheightmean(isnan(detheightmean))=mean(detheightmean(~isnan(detheightmean))); +% detwidthmean +% detheightmean + W((sid:eid)',id)=detwidthmean; + H((sid:eid)',id)=detheightmean; + end + + + +% detsAsscWobble +% +% detsAssc +% unique(detsAssc) +% heights(detsAssc) +% numel(detsAssc) +% +% clf +% hold on +% % size(frames) +% % size(ipolwidths) +% plot(detsAssc,heights(detsAssc),'o') +% plot(frames,ipolheights,'r') +% plot(frames,ppval(sp,frames),'k'); +% +% % global HP +% % plot(frames,HP((sid:eid)',id),'--'); +% +% % plot(frames,lincomb,':'); +% +% % size(sid:eid) +% % size(ipolheights) +% pause + + +end + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + prwght=.8; + H=(1-prwght)*H + prwght*heightPrior; + +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +if sceneInfo.gtAvailable + global gtInfo + arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); + aspectRatio= arithmean; +end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +% stateInfo.W=H*sceneInfo.targetAR; % or take data set mean +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getColorFromID.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getColorFromID.m new file mode 100644 index 0000000000000000000000000000000000000000..9ac27b6f3f79c5891348d2e7bf365d61620f6fc7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getColorFromID.m @@ -0,0 +1,32 @@ +function col=getColorFromID(id) + % get rgb [0,1] values from id +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + colors=getIDColors; + col=colors((mod(id,size(colors,1)))+1,:); +end + +function colors=getIDColors() +colors=[ + 128 255 255; % + 255 0 0; % red 1 + 0 255 0; % green 2 + 0 0 255; % blue 3 + 0 255 255; % cyan 4 + 255 0 255; % magenta 5 + 212 212 0; % yellow 6 + 25 25 25; % black 7 + 34,139,34; % forestgreen 8 + 0,191,255; % deepskyblue 9 + 139,0,0 ; % darkred 10 + 218,112,214; % orchid 11 + 244,164,96 ;]; % sandybrown 12 +colors = colors / 255; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getDetectionMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getDetectionMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..ccf365e0f6df009aa59c17e676dd0af9cec0c320 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getDetectionMatrices.m @@ -0,0 +1,36 @@ +function detMat = getDetectionMatrices(detections) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=length(detections); +Xd=zeros(F,0); +Yd=zeros(F,0); +Sd=zeros(F,0); + +Xi=zeros(F,0); +Yi=zeros(F,0); +W=zeros(F,0); +H=zeros(F,0); +for t=1:length(detections); + Dt=length(detections(t).xp); + Xd(t,1:Dt)=detections(t).xp; + Yd(t,1:Dt)=detections(t).yp; + Sd(t,1:Dt)=detections(t).sc; + + Xi(t,1:Dt)=detections(t).xi; + Yi(t,1:Dt)=detections(t).yi; + W(t,1:Dt)=detections(t).wd; + H(t,1:Dt)=detections(t).ht; +end + +detMat.Xd=Xd; +detMat.Yd=Yd; +detMat.Sd=Sd; + +detMat.Xi=Xi;detMat.Yi=Yi;detMat.W=W;detMat.H=H; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getHeightPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getHeightPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..0f0cf37058d32fb215ae0b6b3265328d9c4f47f1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getHeightPrior.m @@ -0,0 +1,42 @@ +function heightPrior=getHeightPrior(stateInfo) +% for 3d tracking we can compute +% an approximate average bounding box for each target +% which corresponds to a height of 1.70 m in the world +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global sceneInfo +camPar=sceneInfo.camPar; + +% rx=camPar.mExt.mRx;ry=camPar.mExt.mRy;rz=camPar.mExt.mRz; +% tx=camPar.mExt.mTx;ty=camPar.mExt.mTy;tz=camPar.mExt.mTz; +% txi=camPar.mExt.mTxi;tyi=camPar.mExt.mTyi;tzi=camPar.mExt.mTzi; +% kappa=camPar.mInt.mKappa1; focal=camPar.mInt.mFocal;Sx=camPar.mInt.mSx; +% Dpx=camPar.mGeo.mDpx;Dpy=camPar.mGeo.mDpy; + +% [mR mT]=getRotTrans(sceneInfo.camPar); + +% feet +Z=0*ones(size(stateInfo.Xgp)); +[Xi0 Yi0]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +% heads +Z=1700*ones(size(stateInfo.Xgp)); +[XiH YiH]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +heightPrior=Yi0-YiH; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getHomeFolder.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getHomeFolder.m new file mode 100644 index 0000000000000000000000000000000000000000..73c516d61d583341e7938351ddd12e1c9de04ad0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getHomeFolder.m @@ -0,0 +1,18 @@ +function homedir=getHomeFolder() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + homedir='/home/aanton'; + if ispc + homedir='D:'; + end + if exist('/gris/gris-f/home/aandriye','dir') + homedir='/gris/gris-f/home/aandriye'; + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..35b13964f06515bc0f4136d073d0ef57755314fb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/getSceneInfo.m @@ -0,0 +1,526 @@ +function sceneInfo=getSceneInfo(scenario) +% fill all necessary information about the +% scene into the sceneInfo struct +% +% Required: +% detfile detections file (.idl or .xml) +% frameNums frame numbers (eg. frameNums=1:107) +% imgFolder image folder +% imgFileFormat format for images (eg. frame_%04d.jpg) +% targetSize approx. size of targets (default: 5 on image, 350 in 3d) +% +% Required for 3D Tracking only +% trackingArea tracking area +% camFile camera calibration file (.xml PETS format) +% +% Optional: +% gtFile file with ground truth bounding boxes (.xml CVML) +% initSolFile initial solution (.xml or .mat) +% targetAR aspect ratio of targets on image +% bgMask mask to bleach out the background +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt +% opt=getOptions; +% general folders +homefolder=getHomeFolder; +dbfolder=fullfile(filesep,'storage','databases'); if ispc, dbfolder=fullfile('D:','storage','databases'); end +if exist('/gris','dir'), dbfolder=fullfile(filesep,'gris','takatuka_dbases'); end + +% detection file +switch(scenario) + case {23,25,27,70,71,72,73,74,75,80} + dataset='PETS2009'; + case {40,41,42} + dataset='TUD'; + case {30,31,32,35,36,37} + dataset='TUD10'; + case {50,51,52,53} + dataset='ETH-Person'; + case {60,61,62} + dataset='AVSS'; + case {48} + dataset='UBC'; + case {90,91,92} + dataset='DA-ELS'; + otherwise + error('unknown scenario'); +end + +% sequence name +switch(scenario) + case 23 + seqname='PETS2009-S2L1-c1'; + case 25 + seqname='PETS2009-S2L2-c1'; + case 27 + seqname='PETS2009-S2L3-c1'; + case 31 + seqname='TUD10-ped1-c1'; + case 32 + seqname='TUD10-ped1-c2'; + case 36 + seqname='TUD10-ped1-c1'; + case 37 + seqname='TUD10-ped2-c2'; + case 40 + seqname='TUD-Campus'; + case 41 + seqname='TUD-Crossing'; + case 42 + seqname='TUD-Stadtmitte'; + case 48 + seqname='Hockey'; + case {50,51,52,53} + seqname=sprintf('seq%02d',scenario-50); + case 60 + seqname='AB_Easy'; + case 61 + seqname='AB_Medium'; + case 62 + seqname='AB_Hard'; + case 70 + seqname='PETS2009-S1L1-1-c1'; + case 71 + seqname='PETS2009-S1L1-2-c1'; + case 72 + seqname='PETS2009-S1L2-1-c1'; + case 73 + seqname='PETS2009-S1L2-2-c1'; + case 74 + seqname='PETS2009-S1L3-1-c1'; + case 75 + seqname='PETS2009-S1L3-2-c1'; + case 80 + seqname='PETS2009-S3MF1-c1'; + case {90,91,92,93,94} + seqname=sprintf('s%02d',scenario-90); + otherwise + + error('unknown scenario'); +end + +% frameNums +switch(scenario) + case 20 % terrace1 + sceneInfo.frameNums=1:2000; + case 21 % terrace2 + sceneInfo.frameNums=1:2000; + case {22,23} % PETS 2009 S2 L1 + sceneInfo.frameNums=0:794; + case 24 % PETSMONO occlusion + sceneInfo.frameNums=0:794; + case 25 + sceneInfo.frameNums=0:435; + case 27 + sceneInfo.frameNums=0:239; + case {30,31,32,33} % TUD10 ped + sceneInfo.frameNums=1:1400; + % sceneInfo.frameNums=1:300; + case {35,36,37} % TUD10 ped2 + sceneInfo.frameNums=1:1999; + % sceneInfo.frameNums=1:199; + % sceneInfo.frameNums=1670:1680; + % sceneInfo.frameNums=760:770; + case 40 % tud-campus + sceneInfo.frameNums=90:160; + case {41,44} % tud-crossing + sceneInfo.frameNums=1:201; + case 42 % tud-stadtmitte + sceneInfo.frameNums=7022:7200; + % sceneInfo.frameNums=7022:7100; + case 45 % eth central xing1 + sceneInfo.frameNums=1600:2200; + case 46 % eth central xing1 + sceneInfo.frameNums=3300:3600; + case 47 % eth central xing1 + sceneInfo.frameNums=7433:7811; + case 48 % UBC Hockey + sceneInfo.frameNums=700:800; + case 50 % ETH Person seq0 + sceneInfo.frameNums=180:678; + case 51 % ETH Person seq1 + sceneInfo.frameNums=0:999; + case 52 % ETH Person seq2 + sceneInfo.frameNums=0:450; + case 53 % ETH Person seq3 + sceneInfo.frameNums=100:453; + case {60,61,62} % AVSS + sceneInfo.frameNums=1:2000; + case 70 + sceneInfo.frameNums=0:220; + case 71 + sceneInfo.frameNums=0:240; + case 72 + sceneInfo.frameNums=0:200; + case 73 + sceneInfo.frameNums=0:130; + case 74 + sceneInfo.frameNums=0:90; + case 75 + sceneInfo.frameNums=0:343; + case 80 + sceneInfo.frameNums=1:107; + case 81 + sceneInfo.frameNums=0:231; + case 82 + sceneInfo.frameNums=0:108; + case 83 + sceneInfo.frameNums=0:169; + case 84 + sceneInfo.frameNums=0:92; + case 85 + sceneInfo.frameNums=0:107; + case 86 + sceneInfo.frameNums=0:184; + % case 90 + % sceneInfo.frameNums=1:593; + % case 91 + % sceneInfo.frameNums=1:307; + % case 92 + % sceneInfo.frameNums=1:420; + case {101,131} % EnterExitCrossingPaths1 cor, front + sceneInfo.frameNums=0:382; + case {102,132} % EnterExitCrossingPaths2 cor, front + sceneInfo.frameNums=0:484; + case {103,133} % OneLeaveShop1 cor, front + sceneInfo.frameNums=0:294; + case {104,134} % OneLeaveShop2 cor, front + sceneInfo.frameNums=0:1118; + case {105,135} % OneLeaveShopReenter1 cor, front + sceneInfo.frameNums=0:389; + case {106,136} % OneLeaveShopReenter2 cor, front + sceneInfo.frameNums=0:559; + case {107,137} % OneShopOneWait1 cor, front + sceneInfo.frameNums=0:1376; + case {108,138} % OneShopOneWait2 cor, front + sceneInfo.frameNums=0:1461; + case {109,139} % OneStopEnter1 cor, front + sceneInfo.frameNums=0:1499; + case {110,140} % OneStopEnter2 cor, front + sceneInfo.frameNums=0:2724; + case {111,141} % OneStopMoveEnter1 cor, front + sceneInfo.frameNums=0:1586; + case {112,142} % OneStopMoveEnter2 cor, front + sceneInfo.frameNums=0:2236; + case {113,143} % OneStopMoveNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {114,144} % OneStopMoveNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {115,145} % OneStopNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {116,146} % OneStopNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {117,147} % ShopAssistant1 cor, front + sceneInfo.frameNums=0:1674; + case {118,148} % ShopAssistant2 cor, front + sceneInfo.frameNums=0:3699; + case {119,149} % ThreePastShop1 cor, front + sceneInfo.frameNums=0:1649; + case {120,150} % ThreePastShop2 cor, front + sceneInfo.frameNums=0:1520; + case {121,151} % TwoEnterShop1 cor, front + sceneInfo.frameNums=0:1644; + case {122,152} % TwoEnterShop2 cor, front + sceneInfo.frameNums=0:1604; + case {123,153} % TwoEnterShop3 cor, front + sceneInfo.frameNums=0:1604; + case {124,154} % TwoLeaveShop1 cor, front + sceneInfo.frameNums=0:1342; + case {125,155} % TwoLeaveShop2 cor, front + sceneInfo.frameNums=0:599; + case {126,156} % WalkByShop1 cor, front + sceneInfo.frameNums=0:2359; + case 160 + sceneInfo.frameNums=171:184; + case {161,162} + sceneInfo.frameNums=97:114; + otherwise + warning('unknown scenario getFrameNums'); +end + + +detfolder=fullfile(homefolder,'diss','detections','hog-hof-linsvm',dataset,seqname); +% detfolder=fullfile(homefolder,'diss','detections','swd-v2',dataset,seqname); +% detfolder=fullfile(dbfolder,'data-tud','det','',dataset,seqname); + +% detfile +switch(scenario) + case 51 + sceneInfo.detfile=fullfile(detfolder,'test-result-nms-0.8.idl'); + case 53 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'seq03-annot.idl'); + case 62 + sceneInfo.detfile=fullfile(detfolder,['AVSS-' seqname sprintf('-result-00000-05059-nms.idl',length(sceneInfo.frameNums)-1)]); + case 48 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'detections.mat'); + case {90,91,92} + sceneInfo.detfile=fullfile(detfolder,'detections.mat'); + case {23,25,27,70,71,72,73,80,40,41,42} + sceneInfo.detfile=fullfile(dbfolder,'data-tud','det',dataset,[seqname '-det.xml']); + otherwise + sceneInfo.detfile=fullfile(detfolder,[seqname sprintf('-result-00000-%05d-nms.idl',length(sceneInfo.frameNums)-1)]); + +end +assert(exist(sceneInfo.detfile,'file')==2,'detection file does not exist') + + +% img Folder +switch(scenario) + case 23 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); + case 25 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L2','Time_14-55','View_001',filesep); + case 27 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L3','Time_14-41','View_001',filesep); + case 31 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c1',filesep); + case 32 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c2',filesep); + case 36 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c1',filesep); + case 37 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c2',filesep); + case 40 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-campus-sequence',filesep); + case 41 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-crossing-sequence',filesep); + case 42 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-stadtmitte',filesep); + case 48 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case {50,51,52,53} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,'left',filesep); + case {60,61,62} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case 70 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-57','View_001',filesep); + case 71 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-59','View_001',filesep); + case 72 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-06','View_001',filesep); + case 73 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-31','View_001',filesep); + case 80 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 + case {90,91,92,93} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + otherwise + error('unknown scenario image Folder'); +end +assert(exist(sceneInfo.imgFolder,'dir')==7,'imgfolder does not exist') + +% image extension +imgExt='.jpg'; +switch(scenario) + case {20,21,40,41,42,44,50,51,52,53} + imgExt='.png'; +end +sceneInfo.imgFileFormat='frame_%04d'; + +switch(scenario) + case 40 + sceneInfo.imgFileFormat='DaSide0811-seq6-%03d'; + case 41 + sceneInfo.imgFileFormat='DaSide0811-seq7-%03d'; + case 42 + sceneInfo.imgFileFormat='DaMultiview-seq%04d'; + case 48 + sceneInfo.imgFileFormat='h%04d'; + case {50,51,52,53} + sceneInfo.imgFileFormat='image_%08d_0'; + case {90,91,92,93} + sceneInfo.imgFileFormat='%05d'; +end + +% append file extension +sceneInfo.imgFileFormat=[sceneInfo.imgFileFormat imgExt]; + +% if no frame nums, determine from images +if ~isfield(sceneInfo,'frameNums') + imglisting=dir([sceneInfo.imgFolder '*' imgExt]); + sceneInfo.frameNums=1:length(imglisting); +end + +% image dimensions +[sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... + size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); + + + + +%% tracking area +% if we are tracking on the ground plane +% we need to explicitly secify the tracking area +% otherwise image = tracking area +if opt.track3d + switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.trackingArea=[-14069.6, 4981.3, -14274.0, 1733.5]; + case {30,31,32} + sceneInfo.trackingArea=[-197 6708 -2021 6870]; + case {35,36,37} + sceneInfo.trackingArea=[-3438 5271 -2018 7376]; + case 40 + sceneInfo.trackingArea=[-0150 0506 28 1081]; + case 41 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + case 42 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + otherwise + error('Definition of tracking area needed for 3d tracking'); + end + +else + sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +end + +%% camera +cameraconffile=[]; +if opt.track3d + cam=1; + switch(scenario) + case {20,21} %terrace + cameraconffile=sprintf('%sepfl/terrace-tsai-c%i.xml',dbfolder,cam); + case {22, 23,25,27,70,71,72,73,74,75,80,81,82,83,84,85,86} %PETS2009 + cameraconffile=fullfile(dbfolder,dataset,'View_001.xml'); + case 24 + cameraconffile=sprintf('%sPETS2009/View_001.xml',dbfolder); + case 30 + cameraconffile=sprintf('%sTUD10/ped1/c%i-calib.xml',dbfolder,cam); + case 31 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c1-calib.xml'); + case 32 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c2-calib.xml'); + case 36 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c1-calib.xml'); + case 37 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c2-calib.xml'); + case {40,43} + cameraconffile=fullfile(dbfolder,dataset,'tud-campus-calib.xml'); + case {41,44} + cameraconffile=fullfile(dbfolder,dataset,'tud-crossing-calib.xml'); + case 42 + cameraconffile=fullfile(dbfolder,dataset,'tud-stadtmitte-calib.xml'); + case {45,46,47} + cameraconffile=sprintf('%sETH-Central/pedxing-seq1-calib.xml',dbfolder); + case {60,61,62} + cameraconffile=sprintf('%sAVSS/AB_calib.xml',dbfolder); + case intersect(scenario,101:126); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-cor.xml',dbfolder); + case intersect(scenario,131:156); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + case intersect(scenario,160:163) %%% !!! FIX !!! + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + otherwise + error('unknown scenario'); + end +end +sceneInfo.camFile=cameraconffile; + +if ~isempty(sceneInfo.camFile) + sceneInfo.camPar=parseCameraParameters(sceneInfo.camFile); +end + + +%% target size +sceneInfo.targetSize=20; % target 'radius' +sceneInfo.targetSize=sceneInfo.imgWidth/30; +if opt.track3d, sceneInfo.targetSize=350; end + +%% target aspect ratio +sceneInfo.targetAR=1/3; +switch(scenario) + case 48 % Hockey + sceneInfo.targetAR=1/2; + case {90,91,92} % aerial + sceneInfo.targetAR=1; +end + + +%% ground truth +sceneInfo.gtFile=''; +switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + case 31 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c1','GT2d_full_new.mat'); + case 32 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c2','GT2d_full_new.mat'); + case {40,41} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '-interp.mat']); + case 42 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + % sceneInfo.gtFile='/home/aanton/diss/others/yangbo/TUD/TUD_Stadtmitte.avi.gt.mat'; % Yang + case 62 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,'AB_Hard','GT2d_new.mat'); + otherwise + warning('ground truth?'); +end + + +global gtInfo +sceneInfo.gtAvailable=0; +if ~isempty(sceneInfo.gtFile) + sceneInfo.gtAvailable=1; + % first determine the type + [pathtogt, gtfile, fileext]=fileparts(sceneInfo.gtFile); + + if strcmpi(fileext,'.xml') % CVML + gtInfo=parseGT(sceneInfo.gtFile); + elseif strcmpi(fileext,'.mat') + % check for the var gtInfo + fileInfo=who('-file',sceneInfo.gtFile); + varExists=0; cnt=0; + while ~varExists && cnt0.7)=Inf; +[a,b]=munkres(A); +%} +% Example 4: an example of partial assignment +%{ +A = [1 3 Inf; Inf Inf 5; Inf Inf 0.5]; +[a,b]=munkres(A) +%} +% a = [1 0 3] +% b = 1.5 +% Reference: +% "Munkres' Assignment Algorithm, Modified for Rectangular Matrices", +% http://csclab.murraystate.edu/bob.pilgrim/445/munkres.html + +% version 2.3 by Yi Cao at Cranfield University on 11th September 2011 + +assignment = zeros(1,size(costMat,1)); +cost = 0; + +validMat = costMat == costMat & costMat < Inf; +bigM = 10^(ceil(log10(sum(costMat(validMat))))+1); +costMat(~validMat) = bigM; + +% costMat(costMat~=costMat)=Inf; +% validMat = costMat0) + break + end + coverColumn = false(1,n); + coverColumn(starZ(starZ>0))=true; + coverRow = false(n,1); + primeZ = zeros(n,1); + [rIdx, cIdx] = find(dMat(~coverRow,~coverColumn)==bsxfun(@plus,minR(~coverRow),minC(~coverColumn))); + while 1 + %************************************************************************** + % STEP 4: Find a noncovered zero and prime it. If there is no starred + % zero in the row containing this primed zero, Go to Step 5. + % Otherwise, cover this row and uncover the column containing + % the starred zero. Continue in this manner until there are no + % uncovered zeros left. Save the smallest uncovered value and + % Go to Step 6. + %************************************************************************** + cR = find(~coverRow); + cC = find(~coverColumn); + rIdx = cR(rIdx); + cIdx = cC(cIdx); + Step = 6; + while ~isempty(cIdx) + uZr = rIdx(1); + uZc = cIdx(1); + primeZ(uZr) = uZc; + stz = starZ(uZr); + if ~stz + Step = 5; + break; + end + coverRow(uZr) = true; + coverColumn(stz) = false; + z = rIdx==uZr; + rIdx(z) = []; + cIdx(z) = []; + cR = find(~coverRow); + z = dMat(~coverRow,stz) == minR(~coverRow) + minC(stz); + rIdx = [rIdx(:);cR(z)]; + cIdx = [cIdx(:);stz(ones(sum(z),1))]; + end + if Step == 6 + % ************************************************************************* + % STEP 6: Add the minimum uncovered value to every element of each covered + % row, and subtract it from every element of each uncovered column. + % Return to Step 4 without altering any stars, primes, or covered lines. + %************************************************************************** + [minval,rIdx,cIdx]=outerplus(dMat(~coverRow,~coverColumn),minR(~coverRow),minC(~coverColumn)); + minC(~coverColumn) = minC(~coverColumn) + minval; + minR(coverRow) = minR(coverRow) - minval; + else + break + end + end + %************************************************************************** + % STEP 5: + % Construct a series of alternating primed and starred zeros as + % follows: + % Let Z0 represent the uncovered primed zero found in Step 4. + % Let Z1 denote the starred zero in the column of Z0 (if any). + % Let Z2 denote the primed zero in the row of Z1 (there will always + % be one). Continue until the series terminates at a primed zero + % that has no starred zero in its column. Unstar each starred + % zero of the series, star each primed zero of the series, erase + % all primes and uncover every line in the matrix. Return to Step 3. + %************************************************************************** + rowZ1 = find(starZ==uZc); + starZ(uZr)=uZc; + while rowZ1>0 + starZ(rowZ1)=0; + uZc = primeZ(rowZ1); + uZr = rowZ1; + rowZ1 = find(starZ==uZc); + starZ(uZr)=uZc; + end +end + +% Cost of assignment +rowIdx = find(validRow); +colIdx = find(validCol); +starZ = starZ(1:nRows); +vIdx = starZ <= nCols; +assignment(rowIdx(vIdx)) = colIdx(starZ(vIdx)); +pass = assignment(assignment>0); +pass(~diag(validMat(assignment>0,pass))) = 0; +assignment(assignment>0) = pass; +cost = trace(costMat(assignment>0,assignment(assignment>0))); + +function [minval,rIdx,cIdx]=outerplus(M,x,y) +ny=size(M,2); +minval=inf; +for c=1:ny + M(:,c)=M(:,c)-(x+y(c)); + minval = min(minval,min(M(:,c))); +end +[rIdx,cIdx]=find(M==minval); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/myLinExtrap.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/myLinExtrap.m new file mode 100644 index 0000000000000000000000000000000000000000..4f1e2e60b8793bfa472b71825a6401561cb77b21 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/myLinExtrap.m @@ -0,0 +1,26 @@ +function yi=myLinExtrap(Y,steps) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% only takes two element vectors Y +if length(Y)~=2, error('Y must be of length 2'); end + + +n=Y(1); m=diff(Y); + +if steps<0 + xi=steps:-1; +else + xi=(1:steps)+1; +end + +yi = m*xi + n; + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/parseDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/parseDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..3480587e514e9fd56dc963c11243b893318bd8c3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/parseDetections.m @@ -0,0 +1,119 @@ +function [detections, nDets]=parseDetections(sceneInfo,frames) +% read detection file and create a struct array +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt +nDets=0; + +detfile = sceneInfo.detfile; +% first determine the type +[pathstr, filename, ~] = fileparts(detfile); +% is there a .mat file available? +matfile=fullfile(pathstr,[filename '.mat']); +% if exist(matfile,'file') +% load(matfile,'detections'); +% detections = setDetectionPositions(detections); +% % check if all info is available +% if (~isfield(detections,'xp') || ... +% ~isfield(detections,'yp') || ... +% ~isfield(detections,'sc') || ... +% ~isfield(detections,'wd') || ... +% ~isfield(detections,'ht')) +% error('detections must have fields xp,yp,sc,wd,ht'); +% end +% +% if nargin==2 +% detections=detections(frames); +% end +% +% % count detections +% if ~nDets +% for t=1:length(detections),nDets=nDets+length(detections(t).xp);end +% end +% +% return; +% end + +%% now parse +detectionSet = load(detfile); +if(1) + newdetections = detectionAddNoise(detectionSet); +end + +cnt = numel(sceneInfo.frameNums); +detections(cnt).bx=[]; +detections(cnt).by=[]; +detections(cnt).xp=[]; +detections(cnt).yp=[]; +detections(cnt).ht=[]; +detections(cnt).wd=[]; +detections(cnt).sc=[]; + +detections(cnt).xi=[]; +detections(cnt).yi=[]; +for t = 1:numel(sceneInfo.frameNums); + if(~mod(t,100)) + fprintf('.'); + end + idxObj = find(detectionSet(:, 5) == t); + nObjects = numel(idxObj); + bx =[];by=[];xp=[];yp=[]; + ht=[];wd=[];sc=[]; + xi=[];yi=[]; + for j = 1:nObjects + loc = detectionSet(idxObj(j), 1:4); +% score = detectionSet(idxObj(j), 7); + left = loc(1); top = loc(2); + width = loc(3)-left+1;height = loc(4)-top+1; + xis = left + width/2; + yis = top + height; + bx = cat(2, bx, left); + by=cat(2, by, top); + xp=cat(2, xp, xis); + yp=cat(2, xp, yis); + ht=cat(2, ht, height); + wd=cat(2, wd, width); + sc=cat(2, sc, 1); + xi=cat(2, xi, xis); + yi=cat(2, yi, yis); + end + detections(t).bx=bx; + detections(t).by=by; + detections(t).xp=xp; + detections(t).yp=yp; + detections(t).ht=ht; + detections(t).wd=wd; + detections(t).sc=sc; + + detections(t).xi=xi; + detections(t).yi=yi; + + nDets=nDets+length(xi); +end + + +%% set xp and yp accordingly +detections = setDetectionPositions(detections); + +% save detections in a .mat file +save(matfile,'detections'); + +end + +function detections=setDetectionPositions(detections) +% set xp,yp to xi,yi if tracking is in image (2d) +% set xp,yp to xw,yi if tracking is in world (3d) + F = length(detections); + + for t=1:F + detections(t).xp=detections(t).xi; + detections(t).yp=detections(t).yi; + end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/parseGT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/parseGT.m new file mode 100644 index 0000000000000000000000000000000000000000..309e82887abf389bf0d92264f4c81ee04acb3eab --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/parseGT.m @@ -0,0 +1,64 @@ +function gtInfo=parseGT(gtfile) +% read ground truth bounding boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% first determine the type +[~, ~, fileext]=fileparts(gtfile); + +% for now, we can only read CVML schema +if strcmpi(fileext,'.xml'); +else error('Unknown type of detections file.'); +end + +%% now parse +xDoc=xmlread(gtfile); + +allFrames=xDoc.getElementsByTagName('frame'); +F=allFrames.getLength; +frameNums=zeros(1,F); + + +%% +for t=1:F + if ~mod(t,20), fprintf('.'); end + % what is the frame + frame=str2double(allFrames.item(t-1).getAttribute('number')); + frameNums(t)=frame; + + objects=allFrames.item(t-1).getElementsByTagName('object'); + Nt=objects.getLength; + for i=0:Nt-1 + id=str2double(objects.item(i).getAttribute('id')); + if id<1, error('uh oh. IDs should be positive'); end + box=objects.item(i).getElementsByTagName('box'); + h=str2double(box.item(0).getAttribute('h')); + w=str2double(box.item(0).getAttribute('w')); + xc=str2double(box.item(0).getAttribute('xc')); + yc=str2double(box.item(0).getAttribute('yc')); + + % foot position + gtInfo.X(t,id)=xc; gtInfo.Y(t,id)=yc+h/2; + gtInfo.H(t,id)=h; gtInfo.W(t,id)=w; + end +end + +gtInfo.frameNums=frameNums; +% remove zero columns +notEmpty=~~sum(gtInfo.X); +gtInfo.X=gtInfo.X(:,notEmpty); +gtInfo.Y=gtInfo.Y(:,notEmpty); +gtInfo.W=gtInfo.W(:,notEmpty); +gtInfo.H=gtInfo.H(:,notEmpty); + + +% fprintf('all read\n'); + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/parseVehicleGT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/parseVehicleGT.m new file mode 100644 index 0000000000000000000000000000000000000000..c6af75d426cc74efe727c342e0c3c97f00ef7db8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/parseVehicleGT.m @@ -0,0 +1,36 @@ +function gtInfo = parseVehicleGT(gtfile, frameNums) +% read ground truth bounding boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +%% now parse +gt = load(gtfile); +for t = frameNums + idx = find(gt(:,5) == t); + for i = 1:numel(idx) + h = gt(idx(i), 4) - gt(idx(i), 2) + 1; + w = gt(idx(i), 3) - gt(idx(i), 1) + 1; + xc = gt(idx(i), 1) + w/2; + yc = gt(idx(i), 2) + h/2; + id = gt(idx(i), 6); + % foot position + gtInfo.X(t,id)=xc; gtInfo.Y(t,id)=yc+h/2; + gtInfo.H(t,id)=h; gtInfo.W(t,id)=w; + end +end + +gtInfo.frameNums = frameNums; +% remove zero columns +notEmpty = ~~sum(gtInfo.X); +gtInfo.X = gtInfo.X(:,notEmpty); +gtInfo.Y = gtInfo.Y(:,notEmpty); +gtInfo.W = gtInfo.W(:,notEmpty); +gtInfo.H = gtInfo.H(:,notEmpty); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/pdfcrop.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/pdfcrop.m new file mode 100644 index 0000000000000000000000000000000000000000..08a8e427e01bd46c317fa3afaf61e337288e1319 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/pdfcrop.m @@ -0,0 +1,3 @@ +function pdfcrop(pdffile) + eval(sprintf('!pdfcrop %s %s >& /dev/null',pdffile,pdffile)); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/plotDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/plotDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..9cc7d63d4dcdfd98e6576f8dbc0b0113f0817625 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/plotDetections.m @@ -0,0 +1,61 @@ +function plotDetections(plot3d, limits) +% plot detections as dots +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo + +hold on +% axis equal + +dets=detections; +F=size(dets,2); +detcol=[.6 .6 .6]; +maxFrames=200; +% plot3d=1; + +% imshow(imread('/storage/databases/PETS2009/Crowd_PETS09/S3/Multiple_Flow/Time_12-43/View_001/frame_0026.jpg')); + +if ~exist('plot3d','var'), plot3d=0; end + +if plot3d + for t=1:min(F,maxFrames) +% t +% t*ones(1,length(dets(t).xp)) +% pause + plot3(dets(t).xp,dets(t).yp,t*ones(1,length(dets(t).xp)),'.','color',detcol); + +% pause(.01) + end +% view(3) +% zlim([0 min(F,maxFrames)]); +else + for t=1:F + plot(dets(t).xp,dets(t).yp,'.','color',detcol); + end + +end + +if exist('limits','var') + if length(limits)==4 || length(limits)==6 + xlim(limits(1:2)); + ylim(limits(3:4)); +% if length(limits)==6 +% zlim(limits(5:6)); +% end + else + error('limits must be 4 or 6 long vector'); + end +else + xlim(sceneInfo.trackingArea(1:2)); + ylim(sceneInfo.trackingArea(3:4)); +end + +pause(0.001); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/postProcessState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/postProcessState.m new file mode 100644 index 0000000000000000000000000000000000000000..75eefed3d4c8950da89b4591a6f31e8bfc7083d7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/postProcessState.m @@ -0,0 +1,29 @@ +function stateInfo=postProcessState(stateInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt sceneInfo + + +if opt.track3d && opt.cutToTA + stateInfo=cutStateToTrackingArea(stateInfo); +end + +% if we tracked on image, Xi = X +if ~opt.track3d + stateInfo.Xi=stateInfo.X; stateInfo.Yi=stateInfo.Y; +% otherwise project back +else + stateInfo.Xgp=stateInfo.X; stateInfo.Ygp=stateInfo.Y; + [stateInfo.Xi, stateInfo.Yi]=projectToImage(stateInfo.X,stateInfo.Y,sceneInfo); +end + +%% get bounding boxes from corresponding detections +stateInfo=getBBoxesFromState(stateInfo); +% stateInfo=getBBoxesFromPrior(stateInfo); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/prepFigure.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/prepFigure.m new file mode 100644 index 0000000000000000000000000000000000000000..27443be17e1e3b690c8d3b28ed6cfcc44fb01ee0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/prepFigure.m @@ -0,0 +1,39 @@ +function prepFigure() +% prepare figure for showing state +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt; + +% figh=findobj('type','figure','name','optimization'); + +% if isempty(figh), figh=figure('name','optimization'); end +% set(figh); + +clf; +hold on; +box on + +if ~opt.track3d + set(gca,'Ydir','reverse'); +end +xlim(sceneInfo.trackingArea(1:2)) +ylim(sceneInfo.trackingArea(3:4)) +if ~opt.track3d + ylim([sceneInfo.imTopLimit sceneInfo.trackingArea(4)]); +end + +zlim([0 length(sceneInfo.frameNums)]) + +view(-78,4) +if ~opt.track3d + view(-40,10); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printFinalEvaluation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printFinalEvaluation.m new file mode 100644 index 0000000000000000000000000000000000000000..9a3b544ec8c00db6780d2bc1c3fdfd25f5ea7d17 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printFinalEvaluation.m @@ -0,0 +1,29 @@ +function printFinalEvaluation(trackingResultSavePath, gtInfo, frame_end) + +% load stateInfo +left = load([trackingResultSavePath '_LX.txt']); +top = load([trackingResultSavePath '_LY.txt']); +right = load([trackingResultSavePath '_RX.txt']); +down = load([trackingResultSavePath '_RY.txt']); + +stateInfo = []; +h = down - top; +w = right - left; +xc = left + w/2; +yc = top + h/2; +% foot position +stateInfo.X = xc; +stateInfo.Y = yc+h/2; +stateInfo.H = h; +stateInfo.W = w; +stateInfo.F = frame_end; +stateInfo.frameNums = 1:frame_end; +stateInfo.Xgp = stateInfo.X; +stateInfo.Ygp = stateInfo.Y; +stateInfo.Xi = stateInfo.X; +stateInfo.Yi = stateInfo.Y; + +% print result +printMessage(1,'\nEvaluation 2D:\n'); +[metrics, metricsInfo]=CLEAR_MOT(gtInfo,stateInfo); +printMetrics(metrics,metricsInfo,1); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printMessage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printMessage.m new file mode 100644 index 0000000000000000000000000000000000000000..bc6b7d8f3bc92fea3d77c7185445c603db3b0aee --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printMessage.m @@ -0,0 +1,11 @@ +function printMessage(L,F,varargin) +% print a formatted string as F with values from varargin and debug level L +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +fprintf(F,varargin{:}); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printMetrics.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printMetrics.m new file mode 100644 index 0000000000000000000000000000000000000000..6b8a7929c06d6193c3a6a58b66858ea9ee234965 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printMetrics.m @@ -0,0 +1,43 @@ +function printMetrics(metrics, metricsInfo, dispHeader,dispMetrics,padChar) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +namesToDisplay=metricsInfo.names.long; +widthsToDisplay=metricsInfo.widths.long; +formatToDisplay=metricsInfo.format.long; + +namesToDisplay=metricsInfo.names.short; +widthsToDisplay=metricsInfo.widths.short; +formatToDisplay=metricsInfo.format.short; + +if nargin<3, dispHeader=1; end +if nargin<4 + dispMetrics=1:length(metrics); +end +if nargin<5 + padChar={' ',' ','|',' ',' ',' ','|',' ',' ',' ','| ',' ',' ',' '}; +end + +if dispHeader + for m=dispMetrics + printString=sprintf('fprintf(''%%%is%s'',char(namesToDisplay(m)))',widthsToDisplay(m),char(padChar(m))); + eval(printString) + end + fprintf('\n'); +end + +for m=dispMetrics + printString=sprintf('fprintf(''%%%i%s%s'',metrics(m))',widthsToDisplay(m),char(formatToDisplay(m)),char(padChar(m))); + eval(printString) +end + +% if standard, new line +if nargin<4 + fprintf('\n'); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..a06683f310651afbaca7ba0e8a767ecf4e9dc939 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/printSceneInfo.m @@ -0,0 +1,43 @@ +function printSceneInfo() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% prints information about the scene + +% sceneInfo.targetSize=10; % target 'radius' +% +% +% % sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); % 23 +% sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 +% +% sceneInfo.imgFileFormat='frame_%04d.jpg'; +% sceneInfo.frameNums=1:107; +% % sceneInfo.frameNums=0:794; +% [sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... +% size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); +% sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +% +% %% load detections +% detections=parseDetections(detfile); fr=1:length(detections); +% % fr=1:50; detections=detections(fr); % !!!!!!! REMOVE +% F=size(detections,2); +% stateInfo.F=F; % number of frames +% +% +global sceneInfo + + +%% +% printMessage(1,'Sequence: \t%s\n',sceneInfo.seqName); +printMessage(2, 'Frames: ...... %i\n',length(sceneInfo.frameNums)); +printMessage(2, 'Image size: .. %i x %i\n',sceneInfo.imgWidth,sceneInfo.imgHeight) + +% sceneInfo + +%% +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/projectToGroundPlane.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/projectToGroundPlane.m new file mode 100644 index 0000000000000000000000000000000000000000..b51522119bb738eae46b2fe90930d43d1aca9e74 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/projectToGroundPlane.m @@ -0,0 +1,22 @@ +function [Xgp Ygp]=projectToGroundPlane(Xi, Yi, sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +[F N]=size(Xi); +Xgp=zeros(size(Xi)); +Ygp=zeros(size(Xi)); + +for t=1:F + extar=find(Xi(t,:)); + for id=extar + [Xgp(t,id) Ygp(t,id) zw]=imageToWorld(Xi(t,id), Yi(t,id), sceneInfo.camPar); + end +end + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/projectToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/projectToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..97d5f7fdb9142e4217853da0b834e11a728adb0f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/projectToImage.m @@ -0,0 +1,19 @@ +function [Xi Yi]=projectToImage(X,Y,sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +Z=zeros(size(X)); +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); +[Xi Yi]=allWorldToImage_mex(X,Y,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + mR,mT); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/readIDL.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/readIDL.m new file mode 100644 index 0000000000000000000000000000000000000000..6e94f840fdbc5223ab1e4eada6f90623db9f3800 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/readIDL.m @@ -0,0 +1,60 @@ +% Return IDL structure for given filename +% +% INPUT +% filename filename of IDL file +% +% OUTPUT +% idl IDL structure, consisting of +% idl.img - array of images +% idl.bb - array of array of bounding box coordinates +% idl.score - array of array of scores for boxes + +function idl=readIDL(filename) + +fid=fopen(filename); +idl.bb=[]; +idl.img=[]; +idl.score=[]; + +i=1; +bbnum=0; +while 1 + tline = fgetl(fid); + if ~ischar(tline), break, end + tline = strrep(tline, ',', ' '); %replace commas with spaces + colon=strfind(tline,':'); %all colons + + if isempty(colon) + point = strfind(tline,'";'); + if length(point) > 0 + idl(i).img=tline(2:point(1)-1); %filename + i = i + 1; + continue + else + break + end + end + + bb_idx=[(strfind(tline,'(')+1)' (strfind(tline,')')-1)'];%positions of bb start and stop + + idl(i).img=tline(2:colon(1)-2); %filename + for k=1:size(bb_idx,1) + idl(i).bb(end+1,:)=str2num(tline(bb_idx(k,1):bb_idx(k,2))); % next bb + end + + if length(colon)>1 %there are scores in the file ... + for k=1:size(bb_idx,1)-1 + idl(i).score(end+1) = str2num(tline(colon(k+1)+1:(bb_idx(k+1,1)-2))); %next score + end + idl(i).score(end+1) = str2num(tline(colon(length(colon))+1:length(tline)-1)); + else + idl(i).score = 1*ones(1,size(bb_idx,1)); + end + + i=i+1; + bbnum = bbnum + size(bb_idx,1); +end +fclose(fid); + +% fprintf('%d bounding boxes loaded.', bbnum); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/reopenFig.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/reopenFig.m new file mode 100644 index 0000000000000000000000000000000000000000..dcfc4b09cfad39ea91e1f6a9dae423f639d08a35 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/reopenFig.m @@ -0,0 +1,14 @@ +function reopenFig(figname) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +close(findobj('type','figure','name',figname)) +figure('name',figname); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/vectorToMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/vectorToMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..e55ee05fcf2009ca50793f343d17431c14c3451d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/CMOT/utils/vectorToMatrices.m @@ -0,0 +1,38 @@ +function [X Y]=vectorToMatrices(x,stateInfo) +% transforms the state vector X +% to matrix representation X and Y +% X and Y are FxN matrices +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=stateInfo.F; N=stateInfo.N; +% +X=zeros(F,N); % x-positions +Y=zeros(F,N); % y-positions + +% naive implementation +% targetsExist=stateInfo.targetsExist; +% +% xind=1; +% for i=1:N +% frames=targetsExist(i,1):targetsExist(i,2); +% nFrames=numel(frames); +% X(frames,i)=(x(xind:2:xind+2*nFrames-1)); +% +% Y(frames,i)=(x(xind+1:2:xind+2*nFrames)); +% xind=xind+nFrames*2; +% end + + +% vectorized implementation +tiInd=find(stateInfo.tiToInd); +X(tiInd)=x(1:2:end); +Y(tiInd)=x(2:2:end); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/LICENSE.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..9cb2091e6da4357e3ed2a4a47f2817a755293af1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/LICENSE.txt @@ -0,0 +1,15 @@ +Copyright (c) 2012, Anton Andriyenko + +The code may be used free of charge for non-commercial and +educational purposes, the only requirement is that this text is +preserved within the derivative work. For any other purpose you +must contact the authors for permission. This code may not be +redistributed without written permission from the authors. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE +FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/README.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..df5f4ab669b73d31ecfb61324efb8e85a5e4110d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/README.txt @@ -0,0 +1,63 @@ +################################################################### +# # +# Discrete-Continuous Optimization for Multi-Target Tracking # +# Anton Andriyenko, Konrad Schindler and Stefan Roth # +# CVPR 2012 # +# # +# Copyright 2012 Anton Andriyenko # +# # +################################################################### + + + +ABOUT: +This software implements our approach to multi-target tracking +using discrete-continuous optimization [1]. + + +The additional packages + - GCO + - splinefit +are released under a different license and are included for your convenience. +Please refer to the information files within the corresponding folders +for more details. + + + +========================================================================== +DISCLAIMER: +This demo software has been rewritten for the sake of simplifying the +implementation. Therefore, the results produced by the code may differ +from those presented in the paper [1]. +========================================================================== + + +IMPORTANT: +If you use this software you should cite the following in any resulting publication: + [1] Discrete-Continuous Optimization for Multi-Target Tracking + A. Andriyenko, K. Schindler and S. Roth + In CVPR, Providence, RI, USA, June 2012 + + + + +INSTALLING & RUNNING +1. Unpack dctracker-v1.0.zip + +2. Download and install GCO 3.0 from + http://vision.csd.uwo.ca/code/ + and place it into ./gco-v3.0 + You should rebuild the GCO package if the binaries + for your specific platform are missing in ./gco-v3.0/matlab/bin + +3. Start MATLAB and run compileMex.m to build the utilities binaries. + (This step can be omitted if you are using MAC OS 64 bit ot Unix 64 bit.) + +4. Run dcTrackerDemo.m + +You should be able to see the results similar to the ones in demo/result.avi + + + +CHANGES + 1.0 May 25, 2012 Initial public release \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/compileMex.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/compileMex.m new file mode 100644 index 0000000000000000000000000000000000000000..5a6936d702fc9bae9686d9b0184d3a262e0a6bd5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/compileMex.m @@ -0,0 +1,23 @@ +% compile mex files +% ... +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +%% compile utils +utildir=fullfile('utils'); +srcFiles={'allWorldToImage_mex'}; +srcExt='c'; +srcdir=fullfile(utildir,'mex','src'); +outdir=fullfile(utildir,'mex','bin'); + +if ~exist(outdir,'dir'), mkdir(outdir); end +for k=1:length(srcFiles) + eval(sprintf('mex -outdir %s %s.%s',outdir,fullfile(srcdir,char(srcFiles(k))),srcExt)); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/computeImBordersOnGroundPlane.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/computeImBordersOnGroundPlane.m new file mode 100644 index 0000000000000000000000000000000000000000..f29746d975eb3a1c4865e7fb65987671cc8f95d3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/computeImBordersOnGroundPlane.m @@ -0,0 +1,33 @@ +function computeImBordersOnGroundPlane() +% compute image borders on ground plane +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt sceneInfo detections + + +if ~opt.track3d, return; end + +% +% minxi=sceneInfo.imgHeight; +% for t=1:length(detections) +% if min(detections(t).xi)=sceneInfo.trackingArea(1) & ... + detections(t).xw<=sceneInfo.trackingArea(2) & ... + detections(t).yw>=sceneInfo.trackingArea(3) & ... + detections(t).yw<=sceneInfo.trackingArea(4)); + + nDets=nDets+length(tokeep); + + for iField = 1:length(Field) + fcontent=detections(t).(char(Field(iField))); + fcontent=fcontent(tokeep); + detections(t).(char(Field(iField)))=fcontent; + end + end +end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/dcTracker.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/dcTracker.m new file mode 100644 index 0000000000000000000000000000000000000000..449664163a2130b426d12ae2ae5092f32a3449ff --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/dcTracker.m @@ -0,0 +1,267 @@ +% Discrete-Continuous Optimization for Multi-Target Tracking +% +% This code contains minor modifications compared +% to the one that was used +% to produce results for our CVPR 2012 paper +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +clear all +global dcStartTime +dcStartTime=tic; + +addpath(genpath('../contracking/utils/')) +homefolder='d:'; if ~ispc, homefolder=['~' filesep]; end +addpath(genpath(fullfile(homefolder,'software','gco-v3.0'))); + +%% seed random for deterministic results +rng(1); + +%% declare global variables +global detections nPoints sceneInfo opt globiter gtInfo; +globiter=0; + +global LOG_allens LOG_allmets2d LOG_allmets3d %for debug output + + +% fill options struct +opt=getDCOptions; + +% fill scene info +scenario=23; +sceneInfo=getSceneInfo(scenario); +% sceneInfo=getSceneInfoDCDemo; + +frames=1:length(sceneInfo.frameNums); +frames=651:750; % do a part of the whole sequence +sceneInfo.frameNums=sceneInfo.frameNums(frames); + + +%% cut GT to tracking area +if sceneInfo.gtAvailable && opt.track3d && opt.cutToTA + gtInfo=cutGTToTrackingArea(gtInfo); +end + +%% remove unnecessary frames from GT +if sceneInfo.gtAvailable + gtInfo.frameNums=gtInfo.frameNums(frames); + gtInfo.X=gtInfo.X(frames,:);gtInfo.Y=gtInfo.Y(frames,:); + gtInfo.W=gtInfo.W(frames,:);gtInfo.H=gtInfo.H(frames,:); + if opt.track3d + gtInfo.Xgp=gtInfo.Xgp(frames,:);gtInfo.Ygp=gtInfo.Ygp(frames,:); + end + gtInfo=cleanGT(gtInfo); + +end + +% +if opt.visOptim, reopenFig('optimization'); end +%% load detections +[detections nPoints]=parseDetections(sceneInfo,frames); +[detections nPoints]=cutDetections(detections,nPoints); +detMatrices=getDetectionMatrices(detections); + +%% top image limit +sceneInfo.imTopLimit=min([detections(:).yi]); +computeImBordersOnGroundPlane; + +% evaluateDetections(detMatrices,gtInfo); + +T=size(detections,2); % length of sequence +stateInfo.F=T; stateInfo.frameNums=sceneInfo.frameNums; + +%% put all detections into a single vector +alldpoints=createAllDetPoints(detections); + +%% create spatio-temporal neighborhood graph +TNeighbors=getTemporalNeighbors(alldpoints); + +%% init solution +% generate initial spline trajectories +mhs=getSplineProposals(alldpoints,opt.nInitModels,T); + +% +%% get splines from EKF +mhsekf=getSplinesFromEKF(scenario,1:5,frames,alldpoints,T); +mhs=[mhs mhsekf]; +nCurModels=length(mhs); +nInitModels=nCurModels; + + +%% set initial labeling to all outliers +nCurModels=length(mhs); +nLabels=nCurModels+1; outlierLabel=nLabels; +labeling=nLabels*ones(1,nPoints); % all labeled as outliers + + +%% initialize labelcost +[splineGoodness goodnessComp]=getSplineGoodness(mhs,1:opt.nInitModels,alldpoints,T); +% [prox proxt proxcost]=getSplineProximity(mhs,1:nInitModels,alldpoints,labeling,T,proxcostFactor,splineGoodness); + +% unary is constant to outlierCost +Dcost = opt.outlierCost * ones(nLabels,nPoints); +Scost=opt.pairwiseFactor-opt.pairwiseFactor*eye(nLabels); +Lcost=getLabelCost(mhs); + +[inE inD inS inL] = getGCO_Energy(Dcost, Scost, Lcost, TNeighbors, labeling); +bestE=inE; E=inE; D=inD; S=inS; L=inL; + +%% +printDCUpdate(stateInfo,mhs,[],0,0,0,D,S,L); + +%% first plot +drawDCUpdate(mhs,1:length(mhs),alldpoints,0,outlierLabel,TNeighbors,frames); + + +nAddRandomModels=10; % random models +nAddModelsOutliers=10; + +nAdded=0; nRemoved=0; + +%% start energy minimization loop +itcnt=0; % only count one discrete-continuous cycle as one iteration +iteachcnt=0; % count each discrete and each continuous optimization step +used=[]; +mhsafterrefit=[]; +lcorig=opt.labelCost; +while 1 +% opt.labelCost=itcnt*lcorig; + oldN=length(mhs); + for m=1:length(mhs) + if ~isempty(intersect(m,used)) + mhs(m).lastused=0; + else + mhs(m).lastused=mhs(m).lastused+1; + end + end + + mhs_=mhs; + tokeep=find([mhs.lastused]<3); + mhs=mhs(tokeep); + + nRemoved=oldN-length(tokeep); + nCurModels=length(mhs); nLabels=nCurModels+1; outlierLabel=nLabels; + + + + % old labeling + l_ = labeling; + E_=E; D_=D; S_=S; L_=L; + + %% relabel + % minimize discrete Energy E(f), (Eq. 4) + Dcost=getUnarySpline(nLabels,nPoints,mhs,alldpoints,opt.outlierCost,opt.unaryFactor,T); + Lcost=getLabelCost(mhs); + Scost=opt.pairwiseFactor-opt.pairwiseFactor*eye(nLabels); + [E D S L labeling]=doAlphaExpansion(Dcost, Scost, Lcost, TNeighbors); + + % if new energy worse (or same), restore previous labeling and done + if E >= bestE + printMessage(2, 'Discrete Optimization did not find a lower energy\n'); + labeling=l_; + mhs=mhsafterrefit; + E=E_; D=D_; S=S_; L=L_; + nCurModels=length(mhs); nLabels=nCurModels+1; outlierLabel=nLabels; + + used=setdiff(unique(labeling),outlierLabel); nUsed=numel(used); + break; + end + + % otherwise refit and adjust models + bestE=E; + itcnt=itcnt+1; + iteachcnt=iteachcnt+1; + + outlierLabel=nLabels; + used=setdiff(unique(labeling),outlierLabel); nUsed=numel(used); + + + + % print update + drawDCUpdate(mhs,used,alldpoints,labeling,outlierLabel,TNeighbors,frames); + [m2d m3d]=printDCUpdate(stateInfo,mhs,used,nAdded,nRemoved,iteachcnt,D,S,L); + LOG_allens(iteachcnt,:)=double([D S L]);LOG_allmets2d(iteachcnt,:)=m2d;LOG_allmets3d(iteachcnt,:)=m3d; + + % now refit models (Eq. 1) + mhsbeforerefit=mhs; + mhsusedbeforerefit=mhs(used); + mhsnew=reestimateSplines(alldpoints,used,labeling,nLabels,mhs,Dcost,T); + % mhsnew=reestimateSplines(allpoints,used,labeling,minCPs,ncpsPerFrame); + mhsafterrefit=mhsnew; + + Dcost=getUnarySpline(nLabels,nPoints,mhsnew,alldpoints,opt.outlierCost,opt.unaryFactor,T); + Lcost = getLabelCost(mhsnew); + Scost=opt.pairwiseFactor-opt.pairwiseFactor*eye(nLabels); + h=setupGCO(nPoints,nLabels,Dcost,Lcost,Scost,TNeighbors); + GCO_SetLabeling(h,labeling); + [E D S L] = GCO_ComputeEnergy(h); + GCO_Delete(h); + + + mhs(used)=mhsnew(used); + nCurModels=length(mhs); + clear Scost Dcost Lcost + + iteachcnt=iteachcnt+1; + + % print update + drawDCUpdate(mhs,1:length(mhs),alldpoints,0,outlierLabel,TNeighbors,frames); +% pause(.2); + drawDCUpdate(mhs,used,alldpoints,labeling,outlierLabel,TNeighbors,frames); + printDCUpdate(stateInfo,mhs,used,nAdded,nRemoved,iteachcnt,D,S,L); + LOG_allens(iteachcnt,:)=double([D S L]);LOG_allmets2d(iteachcnt,:)=m2d;LOG_allmets3d(iteachcnt,:)=m3d; + +% %% Expand the hypothesis space + if nCurModels4 + outlpts=selectPointsSubset(alldpoints,outlierPoints); + mhsnew=getSplineProposals(outlpts,nAddRandomModels,T); + mhs=[mhs mhsnew]; + end + + %% extend existing + mhs=extendSplines(alldpoints,mhs,used,labeling,T,E); + + %% merge existing + mhs=mergeSplines(alldpoints,mhs,used,labeling,T,E); + + end + nCurModels=length(mhs); nLabels=nCurModels+1; outlierLabel=nLabels; + nAdded=nCurModels-length(mhsbeforerefit); + + +end +% basically we are done +printMessage(1,'All done (%.2f min = %.2fh = %.2f sec per frame)\n',toc(dcStartTime)/60,toc(dcStartTime)/3600,toc(dcStartTime)/stateInfo.F); + +%% final plot +drawDCUpdate(mhs,used,alldpoints,labeling,outlierLabel,TNeighbors,frames); + + +%% +stateInfo=getStateFromSplines(mhs(used), stateInfo); +stateInfo=postProcessState(stateInfo); + +%% if we have ground truth, evaluate results +printFinalEvaluation(stateInfo) + + + +% you can display the results with +% displayTrackingResult(sceneInfo,stateInfo) \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0001.mat b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0001.mat new file mode 100644 index 0000000000000000000000000000000000000000..4d23558d3ecb5de8ddee620ae7c4d87be3688ec0 Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0001.mat differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0002.mat b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0002.mat new file mode 100644 index 0000000000000000000000000000000000000000..96d2127401b24b5501cb3ba6f0c3582810cc5a81 Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0002.mat differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0003.mat b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0003.mat new file mode 100644 index 0000000000000000000000000000000000000000..64f9572ff19dac650338645a242a4ca82518833e Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0003.mat differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0004.mat b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0004.mat new file mode 100644 index 0000000000000000000000000000000000000000..6e1bb09079a932e3a915ed9874be85ae91f276e5 Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0004.mat differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0005.mat b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0005.mat new file mode 100644 index 0000000000000000000000000000000000000000..766a3832c2ccba9dc3b7c94a6dfa59be1b5b0700 Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/demo/ekf/e0005.mat differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/detectionAddNoise.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/detectionAddNoise.m new file mode 100644 index 0000000000000000000000000000000000000000..92d61de3f6d6e316c08a5029955e63285e6533bf --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/detectionAddNoise.m @@ -0,0 +1,64 @@ +function newdetections = detectionAddNoise(detections) + +global sceneInfo + +ignoreRegion = load(sceneInfo.ignorePath); +igrMap = zeros(sceneInfo.imgHeight, sceneInfo.imgWidth); +if(~isempty(ignoreRegion)) + numIgnore = size(ignoreRegion,1); + for j = 1:numIgnore + igrMap(ignoreRegion(j,2):min(sceneInfo.imgHeight,ignoreRegion(j,2)+ignoreRegion(j,4)),ignoreRegion(j,1):min(sceneInfo.imgWidth,ignoreRegion(j,1)+ignoreRegion(j,3))) = 1; +% rectangle('Position', ignoreRegion(j,:),'LineWidth',4,'edgecolor','y'); + end +end + +leftId = []; +addDetections = []; +tic; +for fr = sceneInfo.frameNums + if(mod(fr,200)==0) + fr + end + detMap = zeros(sceneInfo.imgHeight, sceneInfo.imgWidth); + idxDet = find(detections(:,5) == fr); + numDetections = numel(idxDet); + meanWidth = mean(detections(idxDet,3) - detections(idxDet,1)); + meanHeight = mean(detections(idxDet,4) - detections(idxDet,2)); + + for j = 1:numDetections + detMap(detections(idxDet(j),2):min(sceneInfo.imgHeight,detections(idxDet(j),1)), detections(idxDet(j),4):min(sceneInfo.imgWidth,detections(idxDet(j),3))) = 1; + end + imgMap = and(detMap == 1, igrMap == 1); + intMap = createIntImg(imgMap); + + %% add noises + keepNum = numDetections - round(sceneInfo.FNratio*numDetections); + addNum = round(sceneInfo.FPratio*numDetections); + keepId = randperm(numDetections, keepNum); + leftId = cat(2, leftId, keepId); + addPos = []; + for j = 1:5*addNum + x = min(round(sceneInfo.imgWidth*0.95),max(1,round(sceneInfo.imgWidth*rand))); + y = min(round(sceneInfo.imgHeight*0.95),max(1,round(sceneInfo.imgHeight*rand))); + w = min(round(1.25*meanWidth), max(round(0.75*meanWidth), round(rand*meanWidth))); + h = min(round(1.25*meanHeight), max(round(0.75*meanHeight), round(rand*meanHeight))); + tl = intMap(y, x); + tr = intMap(y, min(sceneInfo.imgWidth,x+w)); + bl = intMap(min(sceneInfo.imgHeight,y+h), x); + br = intMap(min(sceneInfo.imgHeight,y+h), min(sceneInfo.imgWidth,x+w)); + foreValue = tl + br - tr - bl; + if(nnz(foreValue)/w*h<0.4) + addPos = cat(1, addPos, [x, y, w, h, fr]); + end + end + if(size(addPos, 1) > addNum) + idx = randperm(size(addPos, 1), addNum); + addPos = addPos(idx, :); + end + addDetections = cat(1, addDetections, addPos); +end +toc; +% drop detections +newdetections = detections(leftId, 1:5); +% add detections +newdetections = cat(1, newdetections, addDetections); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/doAlphaExpansion.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/doAlphaExpansion.m new file mode 100644 index 0000000000000000000000000000000000000000..75263e6ff3997d5dfec16305a5745c2fb9b64c2b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/doAlphaExpansion.m @@ -0,0 +1,27 @@ +function [E D S L labeling]=doAlphaExpansion(Dcost, Scost, Lcost, Neighborhood) +% minimize E(f,T) wrt. f by alpha expansion +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% The gco code is available at +% http://vision.csd.uwo.ca/code/ + + +% set up GCO structure +[nLabels nPoints]=size(Dcost); + +h=setupGCO(nPoints,nLabels,Dcost,Lcost,Scost,Neighborhood); + + +GCO_Expansion(h); +labeling=GCO_GetLabeling(h)'; +[E D S L] = GCO_ComputeEnergy(h); +GCO_Delete(h); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/drawDCUpdate.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/drawDCUpdate.m new file mode 100644 index 0000000000000000000000000000000000000000..8b2203cc0644c856322b85c562074d60f0536348 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/drawDCUpdate.m @@ -0,0 +1,19 @@ +function drawDCUpdate(mhs,used,alldpoints,labeling,outlierLabel,TNeighbors,frames) +% plot the minimization iterations +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt +if opt.visOptim + prepFigure; drawPoints(alldpoints,labeling,outlierLabel,TNeighbors); + drawSplines(mhs,used,labeling,alldpoints,frames) +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/drawPoints.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/drawPoints.m new file mode 100644 index 0000000000000000000000000000000000000000..b9e8a2c0fe0ae53a9736146575e32c16cfeeb79e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/drawPoints.m @@ -0,0 +1,42 @@ +function drawPoints(allpoints,labeling,outlierLabel,TNeighbors) +% plot detections as points +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +% return; + +npts=length(allpoints.xp); +for np=1:min(2000,npts) + msize=15; + if length(labeling)>1, + IDcol=getColorFromID(labeling(np)); marker='.'; + if labeling(np)==outlierLabel, IDcol='k'; marker='o'; msize=msize/4; end + else + IDcol=.6*ones(1,3); marker='.'; + end +% plot3(allpoints.xp(np),allpoints.yp(np), allpoints.tp(np),marker,'color',IDcol,'MarkerSize',5); + plot3(allpoints.xp(np),allpoints.yp(np), allpoints.tp(np),marker,'color',IDcol,'MarkerSize',msize*allpoints.sp(np)); + +% thisneighb=find(TNeighbors(np,:)); +% nthisn=numel(thisneighb); +% for nn=1:nthisn +% plot3([allpoints.xp(np) allpoints.xp(thisneighb(nn))], ... +% [allpoints.yp(np) allpoints.yp(thisneighb(nn))], ... +% [allpoints.tp(np) allpoints.tp(thisneighb(nn))],'color',.6*ones(1,3)) +% end +end +% randpts=randperm(npts); randpts=randpts(1:100); +% for np=randpts +% text(allpoints.xp(np),allpoints.yp(np), allpoints.tp(np),sprintf('%.2f',allpoints.sp(np))); +% end + +pause(0.001); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/drawSplines.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/drawSplines.m new file mode 100644 index 0000000000000000000000000000000000000000..58e9f54ededfd6860afca7741af120dfe41c9e2f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/drawSplines.m @@ -0,0 +1,116 @@ +function drawSplines(mh,used,labeling,allpoints,frames,lst,lw) +% plot splines color coded or gray if outliers +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +if nargin<6, lst='-'; end +if nargin<7, lw=1; end + + +% show head and tail +head=0; +tail=0; +linesmoothing='on'; +linesmoothing='off'; +for id=used + drawwidth=lw; + mhs=mh(id); + if labeling==0 + tt=linspace(1-tail,frames(end)+head,length(frames)*5); + tt=linspace(mhs.start-tail,mhs.end+head,(mhs.end-mhs.start)*5); + col=.6*ones(1,3); +% drawwidth=100*lw/splineGoodness(id); +% drawwidth=max(drawwidth,.1); +% drawwidth=min(drawwidth,3); +% col=500/splineGoodness(id)*ones(1,3); col(col>1)=1; col(col<0)=0; col=1-col; +% splineGoodness(id) +% drawwidth +% pause + else + supportPtsTs=allpoints.tp(labeling==id); + supportPtsTs=sort(supportPtsTs); + tt=linspace(supportPtsTs(1)-tail,supportPtsTs(end)+head,length(supportPtsTs)*5); + col=getColorFromID(id); + end + tt=mh(id).start:mh(id).end; + allval=ppval(mh(id),tt); + allx=allval(1,:);ally=allval(2,:); + + plot3(allx,ally,tt,lst,'color',col,'linewidth',drawwidth,'LineSmoothing',linesmoothing); +% text(allx(1),ally(1),tt(1),sprintf('%i',id),'color',col); + + + %% slope and curvature +% diff1=ppdiff(mh(id),1); +% diff2=ppdiff(mh(id),2); +% curvature=ppval(diff2,tt); +% slope=ppval(diff1,tt); +% abscurv=abs(curvature);sumabscurv=sum(abscurv); +% absslope=abs(slope);sumabsslope=sum(absslope); +% speed=sqrt(sum(slope.^2)); +% sumabscurv=sumabscurv/max(sumabscurv); +% [slowest slowestt]=min(sumabsslope); +% normalizedsumabsslope=sumabsslope/max(sumabsslope); +% for np=1:length(tt) +% plot3(allx(np),ally(np),tt(np),'o','color',col,'MarkerSize',sumabsslope(np)/20); +% end +% plot3(allx(slowestt),ally(slowestt),tt(slowestt),'x','color',col,'MarkerSize',20); +% text(allx(slowestt),ally(slowestt),tt(slowestt),sprintf('%.1f',speed(slowestt)),'color',col); + +% id +% pause +end + +head=0; +tail=0; + +if tail +% tail +for id=used + if labeling==0 + tt=linspace(1-tail,1,tail*10); + col=.6*ones(1,3); + else + supportPtsTs=allpoints.tp(find(labeling==id)); + supportPtsTs=sort(supportPtsTs); + tt=linspace(supportPtsTs(1)-tail,supportPtsTs(1),tail*10); + col=getColorFromID(id); + end + allval=ppval(mh(id),tt); + allx=allval(1,:);ally=allval(2,:); +% plot3(allx,ally,tt,'-','color',min(col+.6,.8),'linewidth',1,'LineSmoothing','off'); + plot3(allx,ally,tt,'-','color',col,'linewidth',1,'LineSmoothing',linesmoothing); +% text(allx(1),ally(1),tt(1),sprintf('%i',id),'color',col); +end + +end + +if head +% head +for id=used + if labeling==0 + tt=linspace(frames(end),frames(end)+head,head*10); + col=.6*ones(1,3); + else + supportPtsTs=allpoints.tp(find(labeling==id)); + supportPtsTs=sort(supportPtsTs); + tt=linspace(supportPtsTs(end),supportPtsTs(end)+head,head*10); + col=getColorFromID(id); + end + allval=ppval(mh(id),tt); + allx=allval(1,:);ally=allval(2,:); +% plot3(allx,ally,tt,'-','color',min(col+.7,.9),'linewidth',1,'LineSmoothing','off'); + plot3(allx,ally,tt,'-','color',col,'linewidth',1,'LineSmoothing',linesmoothing); +% text(allx(1),ally(1),tt(1),sprintf('%i',id),'color',col); +end + +end + +drawnow \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/extendSplines.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/extendSplines.m new file mode 100644 index 0000000000000000000000000000000000000000..afa4454459756bee5487b5839f243790b4629074 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/extendSplines.m @@ -0,0 +1,109 @@ +function mhsret=extendSplines(allpoints, mhs, used,labeling,T,E) +% create new trajectory hypotheses by extending existing ones +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +mhsnew=getEmptyModelStruct; + +nMaxAddExt=50; +exttail=2; +exthead=2; +nCurModels=length(mhs); +addedExt=0; +nUsed=length(used); +if nUsed>1 + for m=randperm(nUsed) + if addedExt>=nMaxAddExt, break; end + + % extend linearly + mod1=used(m); + supp=find(labeling==mod1); + t=allpoints.tp(supp); + [sortedsupp sidx]=sort(t); + if length(unique(sortedsupp))>=4 + + xy=[allpoints.xp(supp);allpoints.yp(supp)]; + + extended=0; + if sortedsupp(1)-exttail>0 + + ntail=sidx(1:4); + tailpts=supp(ntail); + xytail=[allpoints.xp(tailpts);allpoints.yp(tailpts)]; + ttail=allpoints.tp(tailpts); + if length(unique(ttail))>2 + tailline=splinefit(ttail,xytail,1,2); + taillinepts=ppval(tailline,sortedsupp(1)-exttail:sortedsupp(1)-1); + + xy=[taillinepts xy]; + t=[sortedsupp(1)-exttail:sortedsupp(1)-1 t]; + tr=t+0.01*rand(1,length(t))-0.005; + + + sfit=splinefit(tr,xy,mhs(used(m)).pieces); + sfit.start=min(t); sfit.end=max(t); + + addedExt=addedExt+1; + [sfit.goodness sgc]=getSplineGoodness(sfit,1,allpoints,T); + sfit.lastused=0; + mhsnew(addedExt) = sfit; + + extended=1; + end + + end + + if sortedsupp(end)+exthead2 + headline=splinefit(thead,xyhead,1,2); + headlinepts=ppval(headline,sortedsupp(end)+1:sortedsupp(end)+exthead); + + xy=[xy headlinepts]; + t=[t sortedsupp(end)+1:sortedsupp(end)+exthead]; + tr=t+0.01*rand(1,length(t))-0.005; + + + sfit=splinefit(tr,xy,mhs(used(m)).pieces); + sfit.start=min(t); sfit.end=max(t); + + addedExt=addedExt+1; + [sfit.goodness sgc]=getSplineGoodness(sfit,1,allpoints,T); + sfit.lastused=0; + mhsnew(addedExt) = sfit; + + extended=1; + end + end +% +% if extended +% end + end + + +% mhsnew + end + +end + + +allnewgoodness=[mhsnew.goodness]; +mhsnew=mhsnew(E>allnewgoodness); +for m=1:length(mhsnew), mhsnew(m).lastused=0; end + +mhsret=mhs; +if ~isempty(mhsnew), mhsret=[mhs mhsnew]; end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/GCO_README.TXT b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/GCO_README.TXT new file mode 100644 index 0000000000000000000000000000000000000000..a18a155b019a4ba654fe3e533bcca685bf7a8ad4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/GCO_README.TXT @@ -0,0 +1,389 @@ +############################################################################## +# # +# GCoptimization - software for energy minimization with graph cuts # +# Version 3.0 # +# http://www.csd.uwo.ca/faculty/olga/software.html # +# # +# Copyright 2007-2010 Olga Veksler # +# Andrew Delong # +# # +############################################################################## + + C++ requires at least Visual C++ 2005 (VC8) or GCC 4.03. Supports 32 or 64-bit. + See matlab/README.TXT for bundled MATLAB wrapper and its documentation. + + IMPORTANT: + To use this software, YOU MUST CITE the following in any resulting publication: + + [1] Efficient Approximate Energy Minimization via Graph Cuts. + Y. Boykov, O. Veksler, R.Zabih. IEEE TPAMI, 20(12):1222-1239, Nov 2001. + + [2] What Energy Functions can be Minimized via Graph Cuts? + V. Kolmogorov, R.Zabih. IEEE TPAMI, 26(2):147-159, Feb 2004. + + [3] An Experimental Comparison of Min-Cut/Max-Flow Algorithms for + Energy Minimization in Vision. Y. Boykov, V. Kolmogorov. + IEEE TPAMI, 26(9):1124-1137, Sep 2004. + + Furthermore, if you use the label cost feature (setLabelCost), you should cite + + [4] Fast Approximate Energy Minimization with Label Costs. + A. Delong, A. Osokin, H. N. Isack, Y. Boykov. In CVPR, June 2010. + + This software can be used only for research purposes. For commercial purposes, + be aware that there is a US patent on the main algorithm itself: + + R. Zabih, Y. Boykov, O. Veksler, + "System and method for fast approximate energy minimization via graph cuts", + United Stated Patent 6,744,923, June 1, 2004 + + Together with this library implemented by O. Veksler, we provide, with the + permission of the V. Kolmogorov and Y. Boykov, the following two libraries: + + 1) energy.h + Developed by V. Kolmogorov, this implements the binary energy minimization + technique described in [2] above. We use this to implement the binary + energy minimization step for the alpha-expansion and swap algorithms. + The graph construction provided by "energy.h" is more efficient than + the original graph construction for alpha-expansion described in [1]. + + Again, this software can be used only for research purposes. IF YOU USE + THIS SOFTWARE (energy.h), YOU SHOULD CITE THE AFOREMENTIONED PAPER [2] + IN ANY RESULTING PUBLICATION. + + 2) maxflow.cpp, graph.cpp, graph.h, block.h + Developed by Y. Boykov and V. Kolmogorov while at Siemens Corporate Research, + algorithm [3] was later reimplemented by V. Kolmogorov based on open publications + and we use his implementation here with permission. + + If you use either of these libraries for research purposes, you should cite + the aforementioned papers in any resulting publication. + +################################################################## + +2. License & disclaimer. + + Copyright 2007-2010 Olga Veksler + Andrew Delong + + This software and its modifications can be used and distributed for + research purposes only. Publications resulting from use of this code + must cite publications according to the rules given above. Only + Olga Veksler has the right to redistribute this code, unless expressed + permission is given otherwise. Commercial use of this code, any of + its parts, or its modifications is not permited. The copyright notices + must not be removed in case of any modifications. This Licence + commences on the date it is electronically or physically delivered + to you and continues in effect unless you fail to comply with any of + the terms of the License and fail to cure such breach within 30 days + of becoming aware of the breach, in which case the Licence automatically + terminates. This Licence is governed by the laws of Canada and all + disputes arising from or relating to this Licence must be brought + in Toronto, Ontario. + + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +################################################################## + + +3. Energy Minimization + +This software is for minimizing sums of three types of terms: + + E(labeling) = DataCosts(labeling) + SmoothCosts(labeling) + LabelCosts(labeling). + +More specifically, + + DataCosts(l) = sum_p D_p(l_p) where l_p is a potential label for site p, + and D_p is the cost of assigning l_p, + + SmoothCosts(l) = sum_pq V_pq(l_p,l_q) where p and q are two distinct site, and + V_pq is the cost for assigning l_p, l_q, and + + LabelCosts(l) = sum_L' h_L'(l) where L' is some subset of labels L, and h_L' + adds a cost iff at least one label from L' + appears in the labeling l. + +Here we have a finite set of sites (or pixels) P and a finite set of labels L. +A labeling l is assignments of labels in L to pixels in P. The individual pixels +are referred to with small letters p and q, label of pixel p is denoted by l_p, +and the set of all label-pixel assignments is denoted by l, that is +l = {l_p | p in P}. + +The first term in the energy function E(l) is typically called the data term, and +it consists of the sum over all pixels p of the penalty(or cost) D(p,l_p), what +should be the cost of assigning label l_p to pixel p. D(p,l_p) can be arbitrary. + +The second term is a sum over all pairs of neighboring pixels {p,q}. +That is there is a neighborhood relation on the set of pixels (this relationship +is symmetric, that is if p is a neighbor of q then q is a neighbor of p). +Here we assume that the neighbor pairs are unordered. This means that if pixels p and q are +neighbors, then there is either Vpq(l_p,l_q) in the second sum of the energy, +or Vqp(l_q,l_p), but not both. This is not a restriction, since in practice, one can always go +from the ordered energy to the unordered one. This second term is typically called the smoothness +term. + +The third term is a sum over all labels (or, more generally, all subsets of labels) +such that each label can have non-negative penalties associated with its use. +This "label cost" feature is used to encourage labelings that use as fewer unique labels +or, more generally, labels from as few unique subsets as possible. + +The expansion algorithm for energy minimization can be used whenever for any 3 labels a,b,c +V(a,a) + V(b,c) <= V(a,c)+V(b,a). In other words, expansion algorithm can be used if +the binary energy for the expansion algorithm step is regular, using V. Kolmogorov's terminology. + +The swap algorithm for energy minimization can be used whenever for any 2 labels a,b +V(a,a) + V(b,b) <= V(a,b)+V(b,a). In other words, swap algorithm can be used if +the binary energy for the swap algorithm step is regular, using V. Kolmogorov's terminology. + +################################################################## + +4. Data Types + +typedef SiteID; // index of a site (pixel); default is int32 +typedef LabelID; // index of a label; default is int32 +typedef EnergyType; // total energy value; default is int64 +typedef EnergyTermType; // individual energy term; default is int32 + +For efficiency it is best to use integral types when possible; be sure that they are +large enough to avoid integer overflow. By default, the library will warn if energy +terms are dangerously large (larger than GCO_MAX_ENERGYTERM=10000000). + +Keep in mind that float/double may cause expansion/swap to report small increase in energy, +due to arithmetic error during max-flow computation. + +########################################################################### + +5. Specifying the energy + +Before optimizing the energy, one has to specify it, that is specify the number of +labels, number of pixels, neighborhood system, the data terms, and the smoothness terms. +There are 2 constructors to use, one in case of the grid graph, and another in case +of a general graph. +In all cases, it is assumed that the sites go between 0...num_sites-1, +and labels go between 0....num_labels-1. +For a grid (4-connected) graph, site at coordinates (x,y) is numbered with x+y*width, where width +is the width of the grid, that is the row-major ordering of arrays is assumed. +________________________________________________________________________________________________ + +Constructor A. + +GCoptimizationGridGraph(int width, int height,int num_labels); + +Use this constructor only for grid of size width by height. If you use this constructor, +4 connected grid neigbhorhood structure is assumed, so you don't need to specify neighborhood +structure separately (and indeed cannot do so). +_______________________________________________________________________________________________ + +Constructor B. + +GCoptimizationGeneralGraph(int num_sites,int num_labels); + + +Use this constructor for general graphs. If you use this constructor, you must setup up +neighborhood system using function. You can either specify neighbors individually or all at once. + +i) setNeighbors(SiteID s1, SiteID s2, EnergyTermType weight=1); +Specifies neighbors individually. You must call this function exactly once for any +pair of neighboring sites s1 and s2. That is if you call setNeighbors(s1,s2) then you should not call +setNeighbors(s2,s1). If Vpq(l_p,l_q) = V(l_p,l_q)*w_pq, where V(l_p,l_q) is some function that +depends only on the labels l_p,l_q, then specify w_pq by using: setNeighbors(p,q,w_pq). + +ii) To pass in all neighbor information at once, use function: + +void setAllNeighbors(SiteID *numNeighbors,SiteID **neighborsIndexes,EnergyTermType **neighborsWeights); +Here: + (a) numNeighbors is an array of size num_sites, and numNeighbors[i] is the number of neighbors for site i + + (b) neighborIndexes is an array of size num_pixels which stores of pointers. Namely, + neighborsIndexes[i] is a pointer to the array storing the sites which are neighbors to site i + + (c) neighborWeights is an array of size num_sites, and neighborWeighs[i] is a pointer to array + storing the weights between site i and its neighbors in the same order as neighborIndexes[i] + stores the indexes of neighbors. Example: if sites i and j are neighbors, then + for some k and m, neighborsIndexes[i][k] == j and neighborsIndexes[j][m] = i. Then + neighborWeights[i][k] = w_ij and neighborWeights[j][m] = w_ij, where w_ij is the weight + betwen neighbors i and j, that is V_ij = w_ij *V(l_i,l_j) + + +_______________________________________________________________________________________________ + + +6. Setting the data costs, smooth costs, and label costs. + +The following functions can be called any time before or after expansion. + + +------------------------Data Costs (unary terms)----------------------- + +(a) void setDataCost(EnergyTermType *dataArray); + dataArray is an array s.t. the data cost for pixel p and label l is stored at + dataArray[pixel*num_labels+l]. If the current neighborhood system is a grid, then + the data term for label l and pixel with coordinates (x,y) is stored at + dataArray[(x+y*width)*num_labels + l]. Thus the size of array dataArray is num_pixels*num_labels. + Can call this function only one time. + +(b) void setDataCost(DataCostFn fn); + DataCostFn is a pointer to a function f(Pixel p, Label l), s.t. the data cost for pixel p to have + label l is given by f(p,l). Can call this function only one time. + +(c) void setDataCost(DataCostFnExtra fn,void *extraData); + DataCostFnExtra is a pointer to a function f(SiteID p, LabelID l,void *extraData), s.t. the data + cost for pixel p to have label l is given by f(p,l,extraData). Can call this function only one time. + +(d) void setDataCost(SiteID s, LabelID l, EnergyTermType e); + sets up D(s,l) = 3; You must call this function for each pixel and each label. + +(e) void setDataCostFunctor(DataCostFunctor* f); + Experienced C++ users can subclass our DataCostFunctor base class to achieve + a similar functionality as (b) or (c) above. By overriding the compute() method + of DataCostFunctor, your compute() method will be called by the GCoptimization + class each time a data penalty must be computed. + +(f) struct SparseDataCost { + SiteID site; + EnergyTermType cost; + }; + void setDataCost(LabelID l, SparseDataCost *costs, SiteID count); + + For some applications, each label is feasible for only a small fraction + of the overall sites. One way to do this is to simply assign high cost to + any infeasible site. A much more efficient way is to specify exactly + which sites are feasible for each label. Do this by calling + setDataCost(label, costs_for_label, num_costs_for_label) once for each + label. The cost array will be copied internally, so your cost array + can be freed. + Note that giveDataEnergy() will add a huge constant for each site + that is assigned an infeasible label in the current labeling. + + +------------------------Smooth Costs (pairwise terms)----------------------- + +(a) void setSmoothCost(EnergyTermType *V) + + V is an array of smoothness costs, such that V_pq(label1,label2) is stored at V[label1+num_labels*label2] + If graph is a grid, then using this function only if the smooth costs are not spacially varying + that is the smoothness penalty V depends only on labels, but not on sites. If the graph is + not a grid, then you can specify spacially varying coefficients w_pq when you set up the + neighborhood system using setNeighbor(p,q,w_pq) function. In this case, + V_pq(label1,label2) = V[label1+num_labels*label2]*w_pq. This function can be called only one time. + +(b) void setSmoothCost(SmoothCostFn fn); + + fn is pointer to a function f(s1,s2,l1,l2) such that smoothness penalty for neigboring sites + s1 and s2 to have labels, respectively, l1 and l2 is f(s1,s2,l1,l2). This function can be + called only one time. + +(c) void setSmoothCost(SmoothCostFnExtra fn,void *extraData); + + Same as above, but can pass an extra pointer to the data needed for computation + +(d) void setSmoothCost(LabelID l1, LabelID l2, EnergyTermType e) + + sets up V(l1,l2) = e. Must call this function for each pair of labels (l1,l2). Notice + that for any l1 and l2, you must call this function on (l1,l2) AND (l2,l1). + V(l1,l2) has to be equal to V(l2,l1) in this case. + +(e) void setSmoothCostVH(EnergyTermType *V, EnergyTermType *vCosts, EnergyTermType *hCosts); + + This function should be used only if the graph is a grid (GCoptimizationGridGraph class). + Array V is the same as above, under (a). + Arrays hCosts and vCosts have the same size as the image (that is width*height), and are used to set + the spatially varying coefficients w_pq. If p = (x,y) and q = (x+1,y), then + w_pq = hCosts[x+y*width], and so the smoothness penalty for pixels (x,y) and (x+1,y) to have labels + label1 and label2, that is V_pq(label1,label2) = V[label1+num_labels*label2]*hCosts[x+y*width] + If p = (x,y) and q = (x,y+q), then + w_pq = vCosts[x+y*width], and so the smoothness penalty for pixels (x,y) and (x,y+1) to have labels + label1 and label2, that is V_pq(label1,label2) = V[label1+num_labels*label2]*vCosts[x+y*width] + This function can be only called one time. + +(f) void setSmoothCostFunctor(SmoothCostFunctor* f); + + Experienced C++ users can subclass our SmoothCostFunctor base class to achieve + a similar functionality as (b) or (c) above. By overriding the compute() method + of SmoothCostFunctor, your compute() method will be called by the GCoptimization + class each time a smoothness penalty must be computed. + + +------------------------Label Costs (global indicator potentials)-------------------- + +(a) void setLabelCost(EnergyTermType cost); + Penalize the appearance of all labels equally. Replaces all current label + costs, if any. + +(b) void setLabelCost(EnergyTermType* costArray); + Set each individual label cost separately. The costArray must have one + entry for each possible label. Replaces all current label costs, if any. + The cost array will be copied intenally, so your array can be freed. + +(c) void setLabelSubsetCost(LabelID* labels, LabelID numLabels, EnergyTermType cost); + Set cost for a specific subset of labels. The cost will be imposed iff the + current labeling contains at least one label from the 'labels' array. + The labels array will be copied internally, so your array can be freed. + +################################################################## + +6. Optimizing the energy + +You can optimize the energy and get the resulting labeling using the following functions. Notice that they can +be called as many times as one wishes after the constructor has been called and the data/smoothness terms +(and the neighborhood system, if general graph) has beeen set. The initial labeling is set to consists of +all 0's. Use function setLabel(SiteID pixelP, LabelID labelL), described under heading (x) in this section +to initialize the labeling to anything else (but in the valid range, of course, labels must be between +0 and num_labels-1) + +a) EnergyType expansion(int max_num_iterations=-1); + Runs the expansion algorithm until convergence (convergence is guaranteed) + or, if max_num_iterations > 0, until a certain number of cycles (iterations). + Returns the energy of the resulting labeling. + +b) bool alpha_expansion(LabelID alpha_label); + Performs expansion on the label specified by alpha_label. + Returns true if the energy was decreased, false otherwise. + +c) EnergyType swap(int max_num_iterations=-1); + Runs the alpha-beta swap algorithm until convergence (convergence is guaranteed) + or, if max_num_iterations > 0, until a certain number of cycles (iterations). + Returns the energy of the resulting labeling. + +d) void alpha_beta_swap(LabelID alpha_label, LabelID beta_label); + Performs swap on a pair of labels, specified by the input parameters alpha_label, beta_label. + +e) EnergyType compute_energy(); + EnergyType giveDataEnergy(); + EnergyType giveSmoothEnergy(); + EnergyType giveLabelEnergy(); + Returns respectively the total, data part, smooth part, and label part of the energy of the current labling. + +f) LabelID whatLabel(SiteID site); + Returns the current label assigned to site. Can be called at any time after the constructor call. + +g) void setLabel(SiteID s, LabelID l); + Sets the label of site s to the the input parameter l. Can be called at any time after + the constructor call. This is useful for initializing the labeling to something specific + before optimization starts. + +h) void setLabelOrder(bool RANDOM_LABEL_ORDER); + By default, the labels for the swap and expansion algorithms are visited in not random order, + but random label visitation might give better results. To set the label order to + be not random, call setLabelOrder(false). To set it to be random, call setLabelOrder(true). Notice, + that by using functions under heading (iii) and (vii) you can completely and exactly specify the desired + order on labels. + +################################################################## + +7. Example usage. + + See example.cpp for C++ example, or see matlab\README.TXT for MATLAB example. + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_BuildLib.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_BuildLib.m new file mode 100644 index 0000000000000000000000000000000000000000..efc6dd75a32c8985ca7aafb3ef6400351d26607b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_BuildLib.m @@ -0,0 +1,70 @@ +function GCO_BuildLib(Options) +% GCO_BuildLib Attempt to compile and link the GCO_MATLAB library. +% GCO_BuildLib is used internally by all other GCO_MATLAB commands +% to recompile the wrapper library if it is not yet built. +% +% YOU DO NOT NEED TO EXPLICITLY CALL THIS FUNCTION, unless you want to +% customise the build settings via GCO_BuildLib(Options). +% Default options: +% Options.Debug=0 % optimised, detailed checking disabled +% Options.EnergyType32=0 % 64-bit energy counter, 32-bit energy terms +% +% Example: +% % Enable detailed assertions (e.g. than energy does not go up +% % during expansion) and use 32-bit energy counters (slightly faster) +% GCO_BuildLib(struct('Debug',1,'EnergyType32',1)); +% + +if (nargin < 1) + Options = struct(); +end +if (~isfield(Options,'Debug')), Options.Debug = 0; end +if (~isfield(Options,'EnergyType32')), Options.EnergyType32 = 0; end +if (~isfield(Options,'Force')), Options.Force = 1; end + +MEXFLAGS = ''; +if (strcmp(computer(),'GLNXA64') || strcmp(computer(),'PCWIN64') || strcmp(computer(),'MACI64')) + MEXFLAGS = [MEXFLAGS ' -largeArrayDims -DA64BITS']; +end +if (Options.Debug) + MEXFLAGS = [MEXFLAGS ' -g']; +end +if (Options.EnergyType32) + MEXFLAGS = [MEXFLAGS ' -DGCO_ENERGYTYPE32']; +end +if (strcmp(computer(),'PCWIN')) % link with libut for user interruptibility + MEXFLAGS = [MEXFLAGS ' -D_WIN32 "' matlabroot() '\extern\lib\win32\microsoft\libut.lib"' ]; +elseif (strcmp(computer(),'PCWIN64')) + MEXFLAGS = [MEXFLAGS ' -D_WIN64 "' matlabroot() '\extern\lib\win64\microsoft\libut.lib"' ]; +else + MEXFLAGS = [MEXFLAGS ' -lut' ]; +end + +LIB_NAME = 'gco_matlab'; +GCOMATDIR = fileparts(mfilename('fullpath')); +GCODIR = fileparts(GCOMATDIR); +OUTDIR = [ GCOMATDIR filesep 'bin' ]; +[status msg msgid] = mkdir(GCOMATDIR, 'bin'); % Create bin directory +addpath(OUTDIR); % and add it to search path +if (~Options.Force && exist('gco_matlab')==3) + return; +end +clear gco_matlab; + +mexcmd = ['mex ' MEXFLAGS ' -outdir ''' OUTDIR ''' -output ' LIB_NAME ' ' ]; + +% Append all source file names to the MEX command string +SRCCPP = { + [GCOMATDIR filesep 'gco_matlab.cpp'], + [GCODIR filesep 'GCoptimization.cpp'], + [GCODIR filesep 'graph.cpp'], + [GCODIR filesep 'maxflow.cpp'], + [GCODIR filesep 'LinkedBlockList.cpp'] + }; +for f=1:length(SRCCPP) + mexcmd = [mexcmd ' ''' SRCCPP{f} ''' ']; +end + +eval(mexcmd); % compile and link in one step + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_ComputeEnergy.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_ComputeEnergy.m new file mode 100644 index 0000000000000000000000000000000000000000..61c8d1e99c55000eae197af5a67898cd6f5838ef --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_ComputeEnergy.m @@ -0,0 +1,9 @@ +function [Energy D S L] = GCO_ComputeEnergy(Handle) +% GCO_ComputeEnergy Run alpha-expansion algorithm. +% E = GCO_ComputeEnergy(Handle) returns energy of current labeling. +% [E D S L] = GCO_ComputeEnergy(Handle) also provides a breakdown of +% the energy into Data, Smooth, and Label costs. + +GCO_LoadLib(); +[Energy D S L] = gco_matlab('gco_computeenergy',Handle); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Create.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Create.m new file mode 100644 index 0000000000000000000000000000000000000000..8e232e02317fea6bd884cedf627d5d30b2bd5d51 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Create.m @@ -0,0 +1,11 @@ +function Handle = GCO_Create(NumSites,NumLabels) +% GCO_Create Create a GCoptimization object. +% Handle = GCO_Create(NumSites,NumLabels) creates a new GCoptimization +% object and returns a 'handle' to uniquely identify it. +% Call GCO_Delete(Handle) to delete the object and free its memory. +% Call GCO_Delete(GCO_ListHandles) to delete all GCO objects. + +GCO_LoadLib(); +if (nargin < 2), error('Expected 2 arguments'); end +Handle = gco_matlab('gco_create_general',int32(NumSites),int32(NumLabels)); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Delete.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Delete.m new file mode 100644 index 0000000000000000000000000000000000000000..c9f24b2eb8c48d76c51d8701d89e2b9e1c24ac84 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Delete.m @@ -0,0 +1,7 @@ +function GCO_Delete(Handle) +% GCO_Delete Delete a GCoptimization object. +% GCO_Delete(Handle) deletes the object corresponding to Handle +% and frees its memory. + +gco_matlab('gco_delete',int32(Handle)); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_ExpandOnAlpha.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_ExpandOnAlpha.m new file mode 100644 index 0000000000000000000000000000000000000000..4ac069a80937b9e817c7bac134b6f809abec34c7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_ExpandOnAlpha.m @@ -0,0 +1,8 @@ +function GCO_ExpandOnAlpha(Handle,Alpha) +% GCO_ExpandOnAlpha Perform a single alpha-expansion step. +% GCO_Expansion(Handle,Alpha) takes the current labeling and performs +% a single expansion step on label Alpha. + +GCO_LoadLib(); +gco_matlab('gco_alphaexpansion',Handle,int32(Alpha)); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Expansion.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Expansion.m new file mode 100644 index 0000000000000000000000000000000000000000..24dd7ca5b23708f7219f432caa6c4aeccf6302e3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Expansion.m @@ -0,0 +1,22 @@ +function Energy = GCO_Expansion(Handle,MaxIter) +% GCO_Expansion Run alpha-expansion algorithm. +% GCO_Expansion(Handle) minimizes the current energy via +% alpha-expansion until convergence. +% GCO_Expansion(Handle,MaxIter) runs at most MaxIter expansion +% Returns the energy of the computed labeling. +% The labeling itself can be retrieved via GCO_GetLabeling. +% The order of expansion can be influenced by GCO_SetLabelOrder. +% If GCO_SetNeighbors is not called (i.e. no smoothness terms), then +% Expansion will internally use a greedy algorithm (no graph cuts). +% +% IMPORTANT: the first version uses "adaptive cycles" (changed labels) +% until convergence whereas the second applies up to MaxIter +% "standard cycles" (all labels). Each strategy is faster/slower for +% different applications, so see what works fastest for yours. +% + +GCO_LoadLib(); +if (nargin < 1), error('Expansion requires handle to GCO instance'); end +if (nargin < 2), MaxIter = -1; end +Energy = gco_matlab('gco_expansion',Handle,int32(MaxIter)); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_GetLabeling.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_GetLabeling.m new file mode 100644 index 0000000000000000000000000000000000000000..b0c21bdbbbedd44420894658f4df2dea7912970a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_GetLabeling.m @@ -0,0 +1,16 @@ +function Labeling = GCO_GetLabeling(Handle,varargin) +% GCO_GetLabeling Retrieve the current labeling +% GCO_GetLabeling(Handle) returns a column vector of all labels. +% GCO_GetLabeling(Handle,i) returns the label of site i. +% GCO_GetLabeling(Handle,i,count) returns labels i..i+count-1 + +GCO_LoadLib(); +Start = int32(1); +Count = gco_matlab('gco_getnumsites',Handle); +if (length(varargin) > 2) + error('Too many input arguments.'); +end +if (length(varargin) >= 1), Start = int32(varargin{1}); Count = int32(1); end +if (length(varargin) == 2), Count = int32(varargin{2}); end +Labeling = gco_matlab('gco_getlabeling',Handle,Start,Count); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_ListHandles.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_ListHandles.m new file mode 100644 index 0000000000000000000000000000000000000000..880efeb88a847b6c1b12d3e7cea9d42f607ca03d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_ListHandles.m @@ -0,0 +1,10 @@ +function Handles = GCO_ListHandles() +% GCO_ListHandles Retrieve handles to all current GCO instances +% Useful for cleaning up GCO instances that are using memory, +% particularly when a script was interrupted. +% Example: +% GCO_Delete(GCO_ListHandles); % delete all GCO instances + +GCO_LoadLib(); +Handles = gco_matlab('gco_listhandles'); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_LoadLib.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_LoadLib.m new file mode 100644 index 0000000000000000000000000000000000000000..83c65ab387eff8adbc939ea37e0f91e9a8243e3d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_LoadLib.m @@ -0,0 +1,15 @@ +function GCO_LoadLib() +% GCO_LoadLib Attempt to load the GCO_MATLAB library. +% GCO_LoadLib is used internally by all other GCO_MATLAB commands +% to compile (if necessary), load, and bind the wrapper library. + +if (isempty(getenv('GCO_MATLAB'))) + GCO_BuildLib(struct('Force',false)); + if (exist('gco_matlab') ~= 3) + error('Failed to load gco_matlab library'); + end + warning on GCO:int32; + setenv('GCO_MATLAB','LOADED'); % environment variables 10x faster than 'exists' +end + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetDataCost.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetDataCost.m new file mode 100644 index 0000000000000000000000000000000000000000..e8f4eaecb129c5bc25045087977d7ab995576bb8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetDataCost.m @@ -0,0 +1,47 @@ +function GCO_SetDataCost(Handle,DataCost,Label) +% GCO_SetDataCost Set the data cost of individual sites. +% GCO_SetDataCost(Handle,DataCost) accepts a NumLabels-by-NumSites +% int32 matrix where DataCost(k,i) is the cost of assigning +% label k to site i. In this case, the MATLAB matrix is pointed to +% by the C++ code, and so an int32 DataCost array is not copied. +% +% GCO_SetDataCost(Handle,DataCost,Label) accepts a 2-by-N int32 matrix +% of (site,cost) pairs, i.e. DataCost(2,i) is the cost of assigning +% Label to site DataCost(1,i). The site ids must be sorted in increasing +% order. All ommitted site ids are assumed to be infeasible for Label. +% This 'sparse' version of SetDataCost allows Expansion to run much +% faster when labels are only feasible for a small subset of sites. +% It is possible to assign infeasible labelings via GCO_SetLabeling, +% but GCO_ComputeEnergy will add huge constants to represent each +% infeasible assignment. +% +% SetDataCost can be called repeatedly, even after Expansion. +% + +GCO_LoadLib(); +if (nargin < 2), error('Expected at least 2 arguments'); end +if (~isnumeric(DataCost)), error('DataCost must be numeric'); end +if (~isreal(DataCost)), error('DataCost cannot be complex'); end +NumLabels = gco_matlab('gco_getnumlabels',Handle); +NumSites = gco_matlab('gco_getnumsites', Handle); +if (nargin == 2) + Label = 0; % no specific label + if (size(DataCost) ~= [ NumLabels NumSites ]) + error('DataCost size must be [ NumLabels NumSites ]'); + end +else + if (Label < 1 || Label > NumLabels) + error('Label must be in range 1..NumLabels'); + end + if (size(DataCost,1) ~= 2) + error('Sparse DataCost must contain two rows'); + end +end +if (~isa(DataCost,'int32')) + if (NumSites*NumLabels > 200 || any(any(floor(DataCost) ~= DataCost))) + warning('GCO:int32','DataCost converted to int32'); + end + DataCost = int32(DataCost); +end +gco_matlab('gco_setdatacost',Handle,DataCost,int32(Label)); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetLabelCost.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetLabelCost.m new file mode 100644 index 0000000000000000000000000000000000000000..c3437680e009e8f2842922d0997a5b10f8a9d2be --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetLabelCost.m @@ -0,0 +1,41 @@ +function GCO_SetLabelCost(Handle,LabelCost,LabelSubset) +% GCO_SetLabelCost Set costs associated with using labels. +% GCO_SetLabelCost(Handle,LabelCost) with scalar LabelCost gives the +% same cost to all labels. +% GCO_SetLabelCost(Handle,LabelCost) with 1xNumLabels LabelCost +% associates cost LabelCost(k) to label k. +% GCO_SetLabelCost(Handle,LabelCost,LabelSubset) sets the cost for using +% at least one label mentioned in LabelSubset (i.e. LabelSubset is a +% vector containing label indices). The cost is paid once. +% SetLabelCost can be called before or after Expansion. + +GCO_LoadLib(); +if (nargin < 2) + error('Expected at least 2 arguments'); +end +NumLabels = gco_matlab('gco_getnumlabels',Handle); +if (length(LabelCost) ~= 1 && length(LabelCost) ~= NumLabels) + error('LabelCost must be scalar or of length NumLabels'); +end +if ~isa(LabelCost,'int32') + if (length(LabelCost) > 50 || any(any(floor(LabelCost) ~= LabelCost))) + warning('GCO:int32','LabelCost converted to int32'); + end + LabelCost = int32(LabelCost); +end +if (nargin < 3) + gco_matlab('gco_setlabelcost',Handle,LabelCost); +else + if (length(LabelCost) ~= 1), error('LabelCost must be scalar'); end + if (any(LabelSubset < 1) || any(LabelSubset > NumLabels)) + error('LabelSubset must contain indices from 1..NumLabels'); + end + if (~isa(LabelSubset,'int32')) + if (any(any(floor(LabelSubset) ~= LabelSubset))) + error('LabelSubset must contain integers from 1..NumLabels'); + end + LabelSubset = int32(LabelSubset); + end + gco_matlab('gco_setlabelcost',Handle,LabelCost,LabelSubset); +end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetLabelOrder.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetLabelOrder.m new file mode 100644 index 0000000000000000000000000000000000000000..82e155813507a527c9bea7366fd8430c217f7383 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetLabelOrder.m @@ -0,0 +1,14 @@ +function GCO_SetLabelOrder(Handle,Order) +% GCO_SetLabelOrder Set label order for Expansion/Swap moves. +% GCO_SetLabelOrder(Handle,Order) tells Expansion/Swap to select labels +% in a specific order when Order contains integers from 1..NumLabels. +% By default, Expansion/Swap use a consistent, prescribed order of labels +% in until convergence. +% Example: +% GCO_SetLabelOrder(Handle,5:10); % only operate on labels 5..10 +% GCO_SetLabelOrder(Handle,randperm(NumLabels)); % random label order +% + +GCO_LoadLib(); +gco_matlab('gco_setlabelorder',Handle,int32(Order)); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetLabeling.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetLabeling.m new file mode 100644 index 0000000000000000000000000000000000000000..e369867335d164763b9d9d8a55e98cf101038af9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetLabeling.m @@ -0,0 +1,22 @@ +function GCO_SetLabeling(Handle,Labeling) +% GCO_SetLabeling Sets the current labeling +% GCO_SetLabeling(Handle,Labeling) sets the entire labeling. + +GCO_LoadLib(); +if (isnumeric(Labeling)) + NumSites = gco_matlab('gco_getnumsites',Handle); + NumLabels = gco_matlab('gco_getnumlabels',Handle); + if (length(Labeling) ~= NumSites) + error('Labeling must be of length NumSites'); + end + if (~isa(Labeling,'int32')) + if (any(floor(Labeling) ~= Labeling)) + error('Labeling was not integer valued'); + end + Labeling = int32(Labeling); + end + if (min(Labeling) < 1 || max(Labeling) > NumLabels) + error('Label must be in range 1..NumLabels'); + end + gco_matlab('gco_setlabeling',Handle,Labeling); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetNeighbors.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetNeighbors.m new file mode 100644 index 0000000000000000000000000000000000000000..e79ab5076c34fd18be61a7227ce8161a7dacd413 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetNeighbors.m @@ -0,0 +1,28 @@ +function GCO_SetNeighbors(Handle,Weights) +% GCO_SetNeighbors Set (weighted) pairwise connectivity of all sites. +% GCO_SetNeighbors(Handle,Weights) determines which sites are neighbors +% and thereby have a SmoothCost associated with them. Weights is a +% sparse NumSites-by-NumSites matrix, where Weights(i,j) > 0 indicates +% that sites i and j are neighbors. If Weights is a 0-1 matrix, smooth +% costs are spatially invariant. See SetSmoothCost for more. +% +% SetNeighbors cannot be called after Expansion. +% Note: only the upper-triangular area of Weights is consulted +% because the connectivity is undirected. + +GCO_LoadLib(); +NumSites = gco_matlab('gco_getnumsites',Handle); +if (size(Weights) ~= [ NumSites NumSites ]) + error('Neighbors must be of size [ NumSites NumSites ]'); +end +if (~issparse(Weights)) + if (NumSites > 100) + warning('Sparsifying the Neighbors matrix (performance warning)'); + end + if (~isa(Weights,'double')) + error('Neighbors matrix must be of type double, but with integral values'); + end + Weights = sparse(Weights); +end +gco_matlab('gco_setneighbors',Handle,Weights); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetSmoothCost.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetSmoothCost.m new file mode 100644 index 0000000000000000000000000000000000000000..f9b03f1a3b298c3c1ac00ad13b78d08525e6ac8b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetSmoothCost.m @@ -0,0 +1,36 @@ +function GCO_SetSmoothCost(Handle,SmoothCost) +% GCO_SetSmoothCost Set the smooth cost of neighboring sites. +% GCO_SetSmoothCost(Handle,SmoothCost) with a NumLabels-by-NumLabels +% integer matrix makes SmoothCost(k,l) the unweighted cost +% of assigning labels k and l to any neighboring sites. +% For particular neighboring sites i,j the final, weighted cost +% is actually Weights(i,j)*SmoothCost(k,l). The spatially-varying +% weights are determined by GCO_SetNeighbors. +% +% If SetSmoothCost is never called, Potts model is used by default. +% i.e. SmoothCost(k,l) = { 0 if k==l, 1 otherwise } +% +% SetSmoothCost can be called repeatedly, even after Expansion. + +GCO_LoadLib(); +if (nargin < 2) + error('Expected 2 arguments'); +end +if (~isnumeric(SmoothCost)) + error('SmoothCost must be numeric'); +end +NumLabels = gco_matlab('gco_getnumlabels',Handle); +if (size(SmoothCost) ~= [ NumLabels NumLabels ]) + error('SmoothCost size must be [ NumLabels NumLabels ]'); +end +if ~isa(SmoothCost,'int32') + if (NumLabels > 50 || any(any(floor(SmoothCost) ~= SmoothCost))) + warning('GCO:int32','SmoothCost converted to int32'); + end + SmoothCost = int32(SmoothCost); +end +if (any(SmoothCost ~= SmoothCost')) + error('SmoothCost must be symmetric'); +end +gco_matlab('gco_setsmoothcost',Handle,SmoothCost); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetVerbosity.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetVerbosity.m new file mode 100644 index 0000000000000000000000000000000000000000..9803942a5d81d2634df0612cda559e8932668302 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_SetVerbosity.m @@ -0,0 +1,27 @@ +function GCO_SetVerbosity(Handle,Level) +% GCO_SetVerbosity Print status messages during Expansion/Swap. +% Level 0 prints no output (full speed). +% Level 1 prints cycle-level status messages. +% Level 2 prints expansion/swap-level status messages. +% The current energy is printed as +% E=Total (E=DataCost+SmoothCost+LabelCost) +% At level 2, the size of each binary graph cut problem is also +% printed (# vars). +% +% Note that printing may have an effect on overall run time (tic/toc) +% though the internal computation times are printed in milliseconds +% and exclude the time to print. +% +% Example: +% >> GCO_SetVerbosity(Handle,2); % Level 2 output +% >> GCO_Expansion(Handle); +% gco>> starting alpha-expansion w/ adaptive cycles +% gco>> initial energy: E=18 (E=17+0+1) +% gco>> after expansion(3): E=17 (E=14+1+2); 4 vars; (1 of 8); 0.003 ms +% gco>> after expansion(7): E=15 (E=11+1+3); 2 vars; (2 of 8); 0.002 ms +% ... +% gco>> after cycle 1: E=12 (E=6+2+4); 8 expansions(s); + +GCO_LoadLib(); +gco_matlab('gco_setverbosity',Handle,int32(Level)); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Swap.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Swap.m new file mode 100644 index 0000000000000000000000000000000000000000..87a1950155ea00d8cd25b58fe8f19218cc7817c8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_Swap.m @@ -0,0 +1,16 @@ +function Energy = GCO_Swap(Handle,MaxIter) +% GCO_Swap Run alpha-beta-swap algorithm. +% GCO_Swap(Handle) runs alpha-beta-swap until convergence. +% GCO_Swap(Handle,MaxIter) runs at most MaxIter swap cycles. +% Returns the energy of the computed labeling. +% The labeling itself can be retrieved via GCO_GetLabeling. +% The order of expansion can be influenced by GCO_SetLabelOrder. +% +% Note that neither label costs nor sparse data costs are currently +% implement for alpha-beta-swap. + +GCO_LoadLib(); +if (nargin < 1), error('Swap requires handle to GCO instance'); end +if (nargin < 2), MaxIter = 1000000; end +Energy = gco_matlab('gco_swap',Handle,int32(MaxIter)); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_UnitTest.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_UnitTest.m new file mode 100644 index 0000000000000000000000000000000000000000..2f953957ea01ad9bd4aaab3f850f4458632154a5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/GCO_UnitTest.m @@ -0,0 +1,424 @@ +function GCO_UnitTest +% GCO_UnitTest Compile, load, and test the GCO_MATLAB library. +% GCO_UnitTest will make sure the wrapper compiles on the target +% platform and then exercises the library to look for silly bugs. + + function Assert(cond,msg) % for older MATLAB without assert() + if (exist('assert') == 5) + if (nargin < 2) + assert(cond); + else + assert(cond,msg); + end + elseif (~cond) + if (nargin < 2) + msg = 'Assertion failed'; + end + error(msg); + end + end + + function DoSetDataCost(h,dc,iter) + if (iter == 1) + % Set data costs as dense matrix + GCO_SetDataCost(h,dc); + else + % Use the sparse mechanism to set dense data costs, + % to verify that tests all give the same result. + % Note that this is not a good test when the number + % of sites is small, since only some of the sparse datacost + % code path will get exercised. + for label=1:size(dc,1) + ids = find(dc(label,:) < 100000); + GCO_SetDataCost(h,[ids; dc(label,ids)],label); + end + end + end + +sc = [0 1 2 3 3 3 3 3 3; + 1 0 1 2 3 3 3 3 3; + 2 1 0 1 2 3 3 3 3; + 3 2 1 0 1 2 3 3 3; + 3 3 2 1 0 1 2 3 3; + 3 3 3 2 1 0 1 2 3; + 3 3 3 3 2 1 0 1 2; + 3 3 3 3 3 2 1 0 1; + 3 3 3 3 3 3 2 1 0;]; % truncated linear + +GCO_BuildLib; disp('BuildLib PASSED'); +GCO_LoadLib; disp('LoadLib PASSED'); + +% Basic tests with no Create/Delete +caught=false; try GCO_Delete(10); catch, caught=true; end, Assert(caught,'Expected an exception'); +caught=false; try h = GCO_Create(1,1); catch, caught=true; end, Assert(caught,'Expected an exception'); +caught=false; try h = GCO_Create(0,2); catch, caught=true; end, Assert(caught,'Expected an exception'); +h1 = GCO_Create(4,8); +h2 = GCO_Create(10,5); +Assert(all(GCO_ListHandles == [h1; h2])); +GCO_Delete(h1); +caught=false; try GCO_ComputeEnergy(h1); catch, caught=true; end, Assert(caught,'Expected an exception'); +caught=false; try GCO_Delete(h1); catch, caught=true; end, Assert(caught,'Expected an exception'); +Assert(all(GCO_ListHandles == [h2])); +Assert(length(GCO_GetLabeling(h2)) == 10); +GCO_Delete(h2); +Assert(isempty(GCO_ListHandles)); +caught=false; try GCO_Delete(h2); catch, caught=true; end, Assert(caught,'Expected an exception'); +disp('Create/Delete PASSED'); +disp('ListHandles PASSED'); + +% Test Get/SetLabel when no optimization is used +h = GCO_Create(4,3); +Assert(GCO_ComputeEnergy(h) == 0); +l = (mod((1:4),3)+1)'; +caught=false; try GCO_SetLabeling(h,l(1:end-1)); catch, caught=true; end, Assert(caught,'Expected an exception'); +caught=false; try GCO_SetLabeling(h,[l 1]); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_SetLabeling(h,l); +Assert(all(GCO_GetLabeling(h) == l)); +Assert(all(GCO_GetLabeling(h,3) == l(3))); +Assert(all(GCO_GetLabeling(h,2,2) == l(2:3))); +caught=false; try GCO_GetLabeling(h,0,1); catch, caught=true; end, Assert(caught,'Expected an exception'); +caught=false; try GCO_GetLabeling(h,1,5); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_SetLabeling(h,4-l); +Assert(all(GCO_GetLabeling(h) == 4-l)); +GCO_Delete(h); +disp('Get/SetLabeling PASSED'); + +% Test with NO costs +h = GCO_Create(4,3); +Assert(GCO_ComputeEnergy(h) == 0); +GCO_Expansion(h); +Assert(GCO_ComputeEnergy(h) == 0); +GCO_SetLabeling(h,4-GCO_GetLabeling(h)); +Assert(GCO_ComputeEnergy(h) == 0); +GCO_Expansion(h); +GCO_Delete(h); +disp('Expansion-000 PASSED'); + +for iter=1:2 +if (iter == 2) + fprintf('SetDataCost-Sparse...'); + h = GCO_Create(3,2); + GCO_SetDataCost(h,[1 1 1; 2 2 2]); % set dense, then make sure sparse is not allowed afterwards + caught=false; try GCO_SetDataCost(h,[1 2 3; 5 5 5],1); catch, caught=true; end, Assert(caught,'Expected an exception'); + GCO_Delete(h); +% h = GCO_Create(3,2); +% GCO_SetDataCost(h,[1 2 3; 5 6 7],1); % set sparse, then make sure dense is not allowed afterwards +% GCO_SetDataCost(h,[1; 100 ],2); % make sure label cost can be replaced +% Assert(GCO_ComputeEnergy(h) == 18); +% GCO_SetDataCost(h,[1 2 3; 10 11 12],1); % make sure label cost can be replaced +% Assert(GCO_ComputeEnergy(h) == 33); +% % make sure unsorted ids will fail order is checked +% caught=false; try GCO_SetDataCost(h,[1 1 2; 9 9 9],1); catch, caught=true; end, Assert(caught,'Expected an exception'); +% % make sure dense can be used after sparse (though not vice versa) +% GCO_SetDataCost(h,[1 1 1; 2 2 2]); +% GCO_Delete(h); +end + +% Test Expansion with DATA cost only +h = GCO_Create(4,9); +dc = [1 2 5 8 4 2 3 7 9; + 3 1 2 5 4 5 5 5 5; + 5 5 5 5 4 5 2 1 3; + 9 7 3 2 4 8 5 2 1;]'; +if (iter == 1) + caught=false; try GCO_SetDataCost(h,[dc [0 0 0 0]']); catch, caught=true; end, Assert(caught,'Expected an exception'); + caught=false; try GCO_SetDataCost(h,dc(:,1:end-1)); catch, caught=true; end, Assert(caught,'Expected an exception'); + caught=false; try GCO_SetDataCost(h,dc(1:end-1,:)); catch, caught=true; end, Assert(caught,'Expected an exception'); +else + caught=false; try GCO_SetDataCost(h,[1:4; dc(1,:)],0); catch, caught=true; end, Assert(caught,'Expected an exception'); + caught=false; try GCO_SetDataCost(h,[1:4; dc(1,:)],10); catch, caught=true; end, Assert(caught,'Expected an exception'); + caught=false; try GCO_SetDataCost(h,[0:3; dc(1,:)],1); catch, caught=true; end, Assert(caught,'Expected an exception'); + caught=false; try GCO_SetDataCost(h,[2:5; dc(1,:)],1); catch, caught=true; end, Assert(caught,'Expected an exception'); + caught=false; try GCO_SetDataCost(h,[1 2 2;dc(1,1:3)],1);catch, caught=true; end, Assert(caught,'Expected an exception'); +end +DoSetDataCost(h,dc,iter); +GCO_SetLabeling(h,[3 3 3 3]); +Assert(GCO_ComputeEnergy(h) == sum(dc(3,:))); +GCO_SetLabeling(h,[1 2 3 4]); +Assert(GCO_ComputeEnergy(h) == dc(1,1)+dc(2,2)+dc(3,3)+dc(4,4)); +GCO_SetLabeling(h,[5 5 5 5]); +GCO_ExpandOnAlpha(h,8); +Assert(all(GCO_GetLabeling(h) == [5 5 8 8]')); +GCO_ExpandOnAlpha(h,3); +Assert(all(GCO_GetLabeling(h) == [5 3 8 8]')); +GCO_Expansion(h); +Assert(all(GCO_GetLabeling(h) == [1 2 8 9]')); +Assert(GCO_ComputeEnergy(h) == dc(1,1)+dc(2,2)+dc(8,3)+dc(9,4)); +GCO_Delete(h); +if (iter==1), disp('Expansion-D00 PASSED'); end + +% Test DATA+SMOOTH cost +h = GCO_Create(4,9); +dc = [1 2 5 8 4 2 3 7 9; + 3 1 1 5 4 5 5 5 5; + 5 5 5 5 4 5 1 1 3; + 9 7 3 2 4 8 5 2 1;]'; +DoSetDataCost(h,dc,iter); +caught=false; try GCO_SetSmoothCost(h,sc(:,1:end-1)); catch, caught=true; end, Assert(caught,'Expected an exception'); +caught=false; try GCO_SetSmoothCost(h,sc(1:end-1,:)); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_SetSmoothCost(h,sc); +caught=false; try GCO_SetNeighbors(h,eye(4)); catch, caught=true; end, Assert(caught,'Expected an exception'); +caught=false; try GCO_SetNeighbors(h,zeros(5)); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_SetNeighbors(h,[0 2 0 0; + 0 0 1 0; + 0 0 0 2; + 0 0 0 0]); +GCO_SetLabeling(h,[3 3 3 3]); +Assert(GCO_ComputeEnergy(h) == sum(dc(3,:))); +GCO_SetLabeling(h,[1 2 4 5]); +Assert(GCO_ComputeEnergy(h) == dc(1,1)+dc(2,2)+dc(4,3)+dc(5,4) + 6); +GCO_SetLabeling(h,[5 5 5 5]); +GCO_Expansion(h); +Assert(all(GCO_GetLabeling(h) == [2 2 8 8]')); +GCO_Delete(h); +if (iter==1) disp('Expansion-DS0 PASSED'); end + +% Test DATA+LABEL cost +h = GCO_Create(4,9); +dc = [1 2 5 8 4 2 3 7 9; + 3 1 3 5 4 3 5 5 5; + 5 5 5 5 4 5 1 1 3; + 9 7 3 2 4 8 5 2 1;]'; +lc = [9 9 1 1 1 2 1 9 9]; +DoSetDataCost(h,dc,iter); +caught=false; try GCO_SetLabelCost(h,[lc 10]); catch, caught=true; end, Assert(caught,'Expected an exception'); +caught=false; try GCO_SetLabelCost(h,lc(1:end-1)); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_SetLabelCost(h,lc); +GCO_SetLabeling(h,[3 3 3 3]); +Assert(GCO_ComputeEnergy(h) == sum(dc(3,:))+lc(3)); +GCO_SetLabeling(h,[1 2 4 5]); +Assert(GCO_ComputeEnergy(h) == dc(1,1)+dc(2,2)+dc(4,3)+dc(5,4) + sum(lc([1 2 4 5]))); +GCO_SetLabeling(h,[5 5 5 5]); +GCO_Expansion(h); +Assert(all(GCO_GetLabeling(h) == [7 3 7 3]')); +GCO_Delete(h); + +% Test when NumLabels < NumSites and make sure greedy doesn't crash when all labels +% are added. This test thanks to Yangyan Li. +h = GCO_Create(4,3); +DoSetDataCost(h,[1 4 9; 5 2 5; 6 1 3; 5 7 1;]',iter); +GCO_SetLabelCost(h,[1 1 1]); +GCO_Expansion(h); +GCO_Delete(h); + + +% Now do the same test, except add label costs to subsets of labels, not +% just individual labels +h = GCO_Create(4,9); +DoSetDataCost(h,dc,iter); +GCO_SetLabelCost(h,lc); +GCO_SetLabelCost(h,3,[1 3 4 5 6]); +GCO_SetLabelCost(h,4,[4 8 9]); +GCO_SetLabeling(h,[3 3 3 3]); +Assert(GCO_ComputeEnergy(h) == sum(dc(3,:))+lc(3)+3); +GCO_SetLabeling(h,[5 5 8 9]); +Assert(GCO_ComputeEnergy(h) == dc(5,1)+dc(5,2)+dc(8,3)+dc(9,4) + sum(lc([5 8 9]))+3+4); +GCO_SetLabeling(h,[1 2 4 5]); +Assert(GCO_ComputeEnergy(h) == dc(1,1)+dc(2,2)+dc(4,3)+dc(5,4) + sum(lc([1 2 4 5]))+3+4); +GCO_SetLabeling(h,[5 5 5 5]); +GCO_Expansion(h); +Assert(all(GCO_GetLabeling(h) == [7 7 7 7]')); +GCO_SetLabelCost(h,3,[2]); +GCO_Expansion(h); +Assert(all(GCO_GetLabeling(h) == [2 2 7 7]')); +GCO_Delete(h); +if (iter==1), disp('Expansion-D0L PASSED'); end + +% Test DATA+SMOOTH+LABEL cost +h = GCO_Create(4,9); +dc = [1 2 5 8 4 2 3 7 9; + 3 1 3 5 4 2 5 5 5; + 5 5 5 5 5 5 1 1 3; + 9 7 3 2 4 8 5 2 1;]'; +lc = [1 9 1 1 1 1 1 9 9]; +GCO_SetSmoothCost(h,sc); +GCO_SetNeighbors(h,[0 2 0 0; + 0 0 1 0; + 0 0 0 2; + 0 0 0 0]); +DoSetDataCost(h,dc,iter); +GCO_SetLabelCost(h,lc); +GCO_SetLabeling(h,[3 3 3 3]); +Assert(GCO_ComputeEnergy(h) == sum(dc(3,:))+lc(3)); +GCO_SetLabeling(h,[1 2 4 5]); +Assert(GCO_ComputeEnergy(h) == dc(1,1)+dc(2,2)+dc(4,3)+dc(5,4) + sum(lc([1 2 4 5])) + 6); +GCO_SetLabeling(h,[5 5 5 5]); +GCO_Expansion(h); +Assert(all(GCO_GetLabeling(h) == [6 6 7 7]')); +GCO_Delete(h); +% Now do the same test, except add label costs to subsets of labels, not +% just individual labels +h = GCO_Create(4,9); +GCO_SetSmoothCost(h,sc); +GCO_SetNeighbors(h,[0 2 0 0; + 0 0 1 0; + 0 0 0 2; + 0 0 0 0]); +DoSetDataCost(h,dc,iter); +GCO_SetLabelCost(h,lc); +GCO_SetLabelCost(h,3,[1 3 4 5 6]); +GCO_SetLabelCost(h,4,[5 8 9]); +GCO_SetLabeling(h,[3 3 3 3]); +Assert(GCO_ComputeEnergy(h) == sum(dc(3,:))+lc(3)+3); +GCO_SetLabeling(h,[5 5 8 9]); +Assert(GCO_ComputeEnergy(h) == dc(5,1)+dc(5,2)+dc(8,3)+dc(9,4) + sum(lc([5 8 9]))+3+4 + 5); +GCO_SetLabeling(h,[1 2 4 5]); +Assert(GCO_ComputeEnergy(h) == dc(1,1)+dc(2,2)+dc(4,3)+dc(5,4) + sum(lc([1 2 4 5]))+3+4 + 6); +GCO_SetLabeling(h,[5 5 5 5]); +GCO_Expansion(h); +Assert(all(GCO_GetLabeling(h) == [7 7 7 7]')); +GCO_SetLabelCost(h,0,[7]); % Try replacing an existing labelcost +GCO_SetLabeling(h,[3 3 3 3]); +GCO_Expansion(h); +Assert(all(GCO_GetLabeling(h) == [7 7 7 7]')); +[E D S L] = GCO_ComputeEnergy(h); +Assert(L == 0); +GCO_SetLabelCost(h,4,[7]); +GCO_SetLabelCost(h,1,[1 3 4 5 6]); % Try replacing a labelcost subset +GCO_Expansion(h); +Assert(all(GCO_GetLabeling(h) == [6 6 4 4]')); +[E D S L] = GCO_ComputeEnergy(h); +Assert(L == 3); +GCO_SetSmoothCost(h,sc*3); % Try replacing smoothcost +GCO_SetLabeling(h,[5 5 7 9]); +Assert(GCO_ComputeEnergy(h) == dc(5,1)+dc(5,2)+dc(7,3)+dc(9,4) + sum(lc([5 9]))+1+4+4 + 6*3); +GCO_Delete(h); +if (iter==1), disp('Expansion-DSL PASSED'); end + +% Test NON-METRIC SMOOTH cost, and make sure Expansion raises an exception +% so that users do not accidentally get meaningless results. +h = GCO_Create(4,9); +dc = [1 1 1 1 1 1 1 1 1; + 1 1 1 1 1 1 1 1 1; + 1 1 1 1 1 1 1 1 1; + 1 1 1 1 1 1 1 1 1;]'; +DoSetDataCost(h,dc,iter); +sc_nonmetric = sc.*sc; % truncated quadratic +GCO_SetSmoothCost(h,sc_nonmetric); +GCO_SetNeighbors(h,[0 2 0 0; + 0 0 1 0; + 0 0 0 2; + 0 0 0 0]); +GCO_SetLabeling(h,[5 5 7 4]); +caught=false; try GCO_ExpandOnAlpha(h,5); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_Delete(h); +if (iter==1), disp('Expansion-NonMetricWarning PASSED'); end + + +if iter==1 +% Test Swap +h = GCO_Create(4,9); +dc = [1 2 5 8 4 2 3 7 9; + 3 1 1 5 4 5 5 5 5; + 5 5 5 5 4 5 1 1 3; + 9 7 3 2 4 8 5 2 1;]'; +GCO_SetDataCost(h,dc); +GCO_SetLabeling(h,[5 5 5 5]); +GCO_Swap(h); +Assert(all(GCO_GetLabeling(h) == [1 2 7 9]')); +GCO_Delete(h); +disp('Swap-D0 PASSED'); +h = GCO_Create(4,9); +GCO_SetDataCost(h,dc); +GCO_SetSmoothCost(h,sc); +GCO_SetNeighbors(h,[0 2 0 0; + 0 0 1 0; + 0 0 0 2; + 0 0 0 0]); +GCO_SetLabeling(h,[5 5 5 5]); +GCO_Swap(h); +Assert(all(GCO_GetLabeling(h) == [2 2 8 8]')); +GCO_Delete(h); +disp('Swap-DS PASSED'); +end + +% Make sure to generate errors if dangerously large coefficients are used +dc = [1 1 1 1 1 1 1 1 1; + 1 1 1 1 1 1 1 1 1; + 1 1 1 1 1 1 1 1 10000001; % huge capacity, relative to int32 + 1 1 1 1 1 1 1 1 1;]'; +lc = [1 1 0 0 0 0 0 0 10000001]; +h = GCO_Create(4,9); +caught=false; try GCO_SetLabelCost(h,lc); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_SetDataCost(h,dc); % test BadLabelCost, and then BadDataCost code path +caught=false; try GCO_ExpandOnAlpha(h,9); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_Delete(h); + +h = GCO_Create(4,9); +GCO_SetDataCost(h,dc); +GCO_SetSmoothCost(h,sc); % test BadDataCost+GoodSmoothCost code path +caught=false; try GCO_ExpandOnAlpha(h,9); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_Delete(h); + +h = GCO_Create(4,9); +DoSetDataCost(h,min(dc,1),iter); +GCO_SetSmoothCost(h,sc.*10); % test GoodDataCost+BadSmoothCost code path +GCO_SetNeighbors(h,[0 2 0 0; + 0 0 1 0; + 0 0 0 10000001; + 0 0 0 0]); +GCO_SetLabeling(h,[1 1 1 1]); +caught=false; try GCO_ExpandOnAlpha(h,5); catch, caught=true; end, Assert(caught,'Expected an exception'); +GCO_Delete(h); +if (iter==1), disp('IntegerOverflowWarnings PASSED'); end +if (iter==2), fprintf('PASSED\n'); end + + +% Test MEDIUM SCALE problems and make sure dense/sparse data costs +% result in the exact same solution +rand('twister', 987); % get the same random stream each time +wd = 64; ht = 48; +dc = int32(rand([500,wd*ht])*1000); +dc(dc > 100) = 100000; % prune out about 10% of possible labels +dc(1,:) = 1000; % but be sure to allow at least one label per variable +nb = sparse(wd*ht,wd*ht); +for y=1:ht % set up a grid-like neighbourhood, arbitrarily + for x=1:wd + if (x < wd), nb((y-1)*wd+x,(y-1)*wd+x+1) = 30; end + if (y < ht), nb((y-1)*wd+x, y *wd+x ) = 30; end + end +end + +% Test greedy +if (iter==1), fprintf('MediumScale-D0L...'); end +if (iter==2), fprintf('MediumScale-D0L-Sparse...'); end +h = GCO_Create(wd*ht,size(dc,1)); +DoSetDataCost(h,dc,iter); +GCO_SetLabelCost(h,3000); +tic; GCO_Expansion(h); greedytime = toc; +[E D S L] = GCO_ComputeEnergy(h); +if (exist('EDLdense')) + Assert(GCO_ComputeEnergy(h) == EDLdense); % Test D+L costs +else + EDLdense = GCO_ComputeEnergy(h); % remember for next time, to compare with "sparse data cost" solution +end +GCO_Delete(h); +if (iter==1), fprintf('PASSED (%.3fsec greedy)\n',greedytime); end +if (iter==2), fprintf('PASSED (%.3fsec greedy w/ 10%% of sites feasible)\n',greedytime); end + + +% Test expansion +if (iter==1), fprintf('MediumScale-DSL...'); end +if (iter==2), fprintf('MediumScale-DSL-Sparse...'); end +h = GCO_Create(wd*ht,size(dc,1)); +DoSetDataCost(h,dc,iter); +GCO_SetLabelCost(h,1000); +GCO_SetLabelCost(h,5000,2:50); +GCO_SetLabelCost(h,10000,100:200); +GCO_SetNeighbors(h,nb); +tic; GCO_Expansion(h); exptime = toc; + +[E D S L] = GCO_ComputeEnergy(h); +if (exist('EDSLdense')) + Assert(GCO_ComputeEnergy(h) == EDSLdense); % Test D+S+L costs +else + EDSLdense = GCO_ComputeEnergy(h); % remember for next time, to compare with "sparse data cost" solution +end +GCO_Delete(h); +if (iter==1), fprintf('PASSED (%.3fsec expansion)\n',exptime); end +if (iter==2), fprintf('PASSED (%.3fsec expansion w/ 10%% of sites feasible)\n',exptime); end +end + +Assert(isempty(GCO_ListHandles)); % expect there to be no gc handles remaining + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/README.TXT b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/README.TXT new file mode 100644 index 0000000000000000000000000000000000000000..f58e6f83ae271838d04ae7ee911085389b0c31d7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/README.TXT @@ -0,0 +1,144 @@ +/************************************************************************************** + GCO_MATLAB - a Matlab wrapper for Olga Veksler's C++ graph-cut optimization library + + GCO_MATLAB Author(s): + Andrew Delong + Anton Osokin + + We're especially grateful to Lena Gorelick for helpful suggestions and for + tracking down so many bugs! + + GCoptimization Author(s): + Olga Veksler + + Description: + This download provides a Matlab wrapper for the latest version of 'GCoptimization', + Olga Veksler's multi-label optimization library written in C++. + + Note: A wrapper for an earlier version GCoptimization was authored by Shai Bagon and + is available at http://www.wisdom.weizmann.ac.il/~bagon/matlab.html + + Revision History: + Apr 12, 2011; - Fixed bug when sparse data costs had a dense bucket (thanks Joseph Tighe!) + Nov 25, 2010; - Detect MACI64 correctly (thanks Francis Lauzon) + Aug 31, 2010; - Compiles with gcc 4.4.1 on opensuse 11.2 (thanks Wei Liu) + Aug 7, 2010; - Fixed bug when data costs are computed in a callback (thanks Evan Herbst!) + - Fixed bug where setAllNeighbours didn't apply neighbourhood (Evan Herbst again) + Jul 22, 2010; - Compiles with gcc 4.4.1 (thanks Julius Ziegler for the patch!) + Jul 8, 2010; - Fixed crash in greedy code path when all labels get added (thanks Yangyan Li!) + Apr 25, 2010; - Faster code path for sparse data costs; fixed related bug in higher-order labels + Apr 21, 2010; - Added basic "verbose" mode (print cycle, energy, timings etc) + - Expansion cycles now focus on labels for which the energy decreased (faster) + Apr 19, 2010; - Added sparse datacost support + - Allow GCO_SetLabelOrder to specify exact label order + Apr 13, 2010; - Potts model is now the default if SetNeighbors is called without SetSmoothCost + - Fixed bug in higher-order label costs + - Expansion is now interruptable from MATLAB; temporary memory is freed + - Added GCO_ListHandles and allow GCO_Delete to accept multiple handles + - Better error message if a bad handle is passed to GCO_* + Nov 17, 2009; - Fixed integer overflow in label-cost construction + - Fixed bug where greedy algorithm would sometimes skip a label + Nov 6, 2009; - Fixed bug in re-setting label costs after Expansion + - Fixed bug in GCO_LoadLib + Oct 27, 2009; - Removed support for arbitrary smoothcost (too slow, hard to maintain) + - Added support for re-setting data, smooth, and label costs after Expansion + - Added support for label subset costs + - Changed build process to directly use MEX command + - Added integer overflow checks into GCoptimization + - GCoptimization now uses maxflow-3.0 library + Sep 12, 2009; - Added support for arbitrary smoothcost from Matlab via a function_handle + - Added GCO_UnitTest + - Build script now handles spaces in paths properly + Aug 23, 2009; - First version for internal testing + +***************************************************************************************/ + +0. System Requirements + +- Matlab 7.4.0 (R2007a) or above for 32-bit. + Matlab 7.6.0 (R2008) or above for 64-bit. + +- Mex must be pre-configured to use a C++ compiler. (Run "mex -setup" if you have + not already.) The C++ code requires at least Visual C++ 2005 (VC8). + + +---------------------------------------------------------------------------------------- +1. Installation + +- The package should contain the following files: + + GCO_MATLAB files: + gco\matlab\GCO_*.m ; the Matlab commands that you can run + gco\matlab\gco_matlab.cpp ; the library that links Matlab to GCoptimization + + GCoptimization files: + gco\*.{h,cpp} ; the GCoptimization C++ library + +- Start Matlab, and make gco\matlab your working directory or add it to your path. + +- To test your installation of GCO_MATLAB, run the GCO_UnitTest command. + You should hopefully see output like below. + >> GCO_UnitTest + BuildLib PASSED + LoadLib PASSED + Create/Delete PASSED + ... + >> + +---------------------------------------------------------------------------------------- +2. Getting Started -- A basic example, and important usage notes + +Once GCO_UnitTest passes, you should be able run the example sequence of commands below. + + >> h = GCO_Create(4,3); % Create new object with NumSites=4, NumLabels=3 + >> GCO_SetDataCost(h,[0 9 2 0; % Sites 1,4 prefer label 1 + 3 0 3 3; % Site 2 prefers label 2 (strongly) + 5 9 0 5;]); % Site 3 prefers label 3 + >> GCO_SetSmoothCost(h,[0 1 2; % + 1 0 1; % Linear (Total Variation) pairwise cost + 2 1 0;]); % + >> GCO_SetNeighbors(h,[0 1 0 0; % Sites 1 and 2 connected with weight 1 + 0 0 1 0; % Sites 2 and 3 connected with weight 1 + 0 0 0 2; % Sites 3 and 4 connected with weight 2 + 0 0 0 0;]); + >> GCO_Expansion(h); % Compute optimal labeling via alpha-expansion + >> GCO_GetLabeling(h) + ans = + 1 % Optimal labeling is (1,2,1,1) + 2 + 1 + 1 + >> [E D S] = GCO_ComputeEnergy(h) % Energy = Data Energy + Smooth Energy + E = + 4 + D = + 2 + S = + 2 + >> GCO_Delete(h); % Delete the GCoptimization object when finished + + +*** Before using the MATLAB wrapper, please note the following: *** + + - Sites and labels are identified with 1-based indices (i.e. 1..N and *not* 0..N-1) + + - All numeric costs must be INTEGER (int32), not float! + (The "getting started" example above uses small float matrices, which are + silently converted to int32 for the sake of convenience.) + The only function that accepts floats is GCO_SetNeighbors, since it needs a sparse matrix. + ** The weights themselves must still be integer valued!! ** (1.0, 17.0, 42.0 etc) + +---------------------------------------------------------------------------------------- +3. GCO_MATLAB functions + +Run 'help' in MATLAB to see the documentation of each function, e.g. + >> help GCO_SetSmoothCost + +Most of the GCO_MATLAB functions are one-to-one with the C++ methods in the +GCoptimization library. +For more detailed documentation, please refer to the C++ library itself. +Relevant files are: + gco_matlab\src\GCv3\GC_README.txt + gco_matlab\src\GCv3\example.cpp + gco_matlab\src\GCv3\GCoptimization.h + gco_matlab\src\GCv3\LICENSE.txt diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexa64 b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexa64 new file mode 100644 index 0000000000000000000000000000000000000000..22c8700df042d4a218f1f9979134707bd9084384 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexa64 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f7b65a8a6cbe3da327b33be31e150cc4b8f66f9fca5bcae966ce095407580bfa +size 124624 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexmaci b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexmaci new file mode 100644 index 0000000000000000000000000000000000000000..84caee87aefd17cc468c383b8e4fcf8b7583be1c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexmaci @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b9bcf188b2caf1afc87c5b453c2027b3a5496c76166d386b5f56a7801295a84 +size 105968 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexmaci64 b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexmaci64 new file mode 100644 index 0000000000000000000000000000000000000000..9fbdc951951a162db3c9f09497d443156f894ac7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexmaci64 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a3a1368f69a61e638346d701a0bc69875e3387cc9ba3e2b877e93a022aa5ca64 +size 111192 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexw32 b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexw32 new file mode 100644 index 0000000000000000000000000000000000000000..337e0f1c1c702826614c0964ae4aa4a07fef10e2 Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexw32 differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexw64 b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexw64 new file mode 100644 index 0000000000000000000000000000000000000000..865ff7eea51851df929e90f7e5ddeb4cdae154d6 Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/bin/gco_matlab.mexw64 differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/gco_matlab.cpp b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/gco_matlab.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9874526aa5804c812315f503d8efa5e799f8772 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/gco-v3.0/matlab/gco_matlab.cpp @@ -0,0 +1,467 @@ +#include +#include +#include +#include +#include "../GCoptimization.h" + +#if !defined(MX_API_VER) || MX_API_VER < 0x07030000 +typedef int mwSize; +typedef int mwIndex; +#endif + +extern "C" mxArray *mxCreateReference(const mxArray*); // undocumented mex function + +#define GCO_EXPORT(func) \ + extern "C" void func(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]); \ + FuncRegistry::Entry regentry_##func(#func,func); \ + extern "C" void func(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) + +#define MATLAB_ASSERT(expr,msg) if (!(expr)) { throw MatlabError(msg); } +#define MATLAB_ASSERT_ARGCOUNT(nout, nin) \ + MATLAB_ASSERT(nlhs >= nout, "Not enough output arguments, expected " #nout); \ + MATLAB_ASSERT(nlhs <= nout, "Too many output arguments, expected " #nout); \ + MATLAB_ASSERT(nrhs >= nin, "Not enough input arguments, expected " #nin); \ + MATLAB_ASSERT(nrhs <= nin, "Too many input arguments, expected " #nin); +#define MATLAB_ASSERT_INTYPE(arg, type) \ + MATLAB_ASSERT(mxGetClassID(prhs[arg]) == type, "Expected " #type " for input argument " #arg); +#define MATLAB_ASSERT_HANDLE(arg) \ + MATLAB_ASSERT(mxGetClassID(prhs[arg]) == mxINT32_CLASS, "Expected valid handle for argument " #arg); + +struct MatlabError { + MatlabError(const char* msg): msg(msg) { } + const char* msg; +}; + +struct FuncRegistry { + typedef void (*Func)(int, mxArray*[], int, const mxArray*[]); + typedef std::map LookupTable; + static LookupTable sLookup; + struct Entry { + Entry(const char* name, Func ptr) { sLookup[name] = ptr; } + }; +}; +FuncRegistry::LookupTable FuncRegistry::sLookup; + + +struct GCInstanceInfo { + GCInstanceInfo(): gco(0), grid(false), dc(0), sc(0) { } + ~GCInstanceInfo() { + if (sc) mxDestroyArray(sc); + if (dc) mxDestroyArray(dc); + if (gco) delete gco; + } + GCoptimization* gco; + bool grid; + mxArray* dc; + mxArray* sc; +private: +}; + +typedef GCoptimization::LabelID LabelID; +typedef GCoptimization::SiteID SiteID; +typedef GCoptimization::EnergyType EnergyType; +typedef GCoptimization::EnergyTermType EnergyTermType; +mxClassID cLabelClassID = sizeof(LabelID) == 8 ? mxINT64_CLASS : mxINT32_CLASS; +mxClassID cSiteClassID = sizeof(SiteID) == 8 ? mxINT64_CLASS : mxINT32_CLASS; +mxClassID cEnergyTermClassID = sizeof(EnergyTermType) == 8 ? mxINT64_CLASS : mxINT32_CLASS; +mxClassID cEnergyClassID = sizeof(EnergyType) == 8 ? mxINT64_CLASS : mxINT32_CLASS; + +typedef std::map GCInstanceMap; + +static int gNextInstanceID = 10001; // some start id for the first GC object +static GCInstanceMap gInstanceMap; + +GCInstanceMap::mapped_type& sGetGCInstance(int id) { + GCInstanceMap::iterator it = gInstanceMap.find(id); + MATLAB_ASSERT(it != gInstanceMap.end(), "Invalid handle; no such GCoptimization object"); + return it->second; +} + +/* +// Not currently used because it was too slow to shuffle per-edge smoothcosts between MATLAB and C++ +void sBatchSmoothCostFn(SiteID size, const SiteID sites[][2], const LabelID labels[][2], EnergyTermType* energies, void *smoothFn) +{ + mxArray* sitesArr = mxCreateNumericMatrix(2, size, cSiteClassID, mxREAL); + mxArray* labelsArr = mxCreateNumericMatrix(2, size, cLabelClassID, mxREAL); + LabelID* sitesArrData = (LabelID*)mxGetData(sitesArr); + LabelID* labelsArrData = (LabelID*)mxGetData(labelsArr); + + // Convert indices from 0..N-1 to 1..N for Matlab callback + for (SiteID i = 0; i < size*2; ++i) + sitesArrData[i] = ((SiteID*)sites)[i]+1; + for (SiteID i = 0; i < size*2; ++i) + labelsArrData[i] = ((LabelID*)labels)[i]+1; + + + // Call the user-specified smoothcost callback, which is either a string or a function_handle + mxArray* plhs[1] = { 0 }; + mxArray* prhs[3] = { (mxArray*)smoothFn, sitesArr, labelsArr }; + mexCallMATLAB(1, plhs, 3, prhs, "feval"); + + // Copy the result into the output 'energies' array + mxArray* result = plhs[0]; + MATLAB_ASSERT(result, "Batch smoothcost function failed to return a result"); + MATLAB_ASSERT(mxGetClassID(result) == cEnergyTermClassID, "Batch smoothcost function must return numeric array of type GCoptimization::EnergyTermType"); + MATLAB_ASSERT(mxGetNumberOfElements(result) >= size, "Batch smoothcost function returned too few energy terms"); + MATLAB_ASSERT(mxGetNumberOfElements(result) <= size, "Batch smoothcost function returned too many energy terms"); + memcpy(energies, mxGetData(result), size*sizeof(EnergyTermType)); + + // Clean up + mxDestroyArray(sitesArr); + mxDestroyArray(labelsArr); + mxDestroyArray(result); +} +*/ + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) +{ + if (nrhs == 0 || !mxIsChar(prhs[0])) + mexErrMsgTxt("Do not use gco_matlab() directly, instead use the GCO functions such as GCO_Create"); + mwSize nameLen = mxGetN(prhs[0])*sizeof(mxChar)+1; + char funcName[512]; + mxGetString(prhs[0], funcName, nameLen); + FuncRegistry::LookupTable::const_iterator it = FuncRegistry::sLookup.find(funcName); + if (it == FuncRegistry::sLookup.end()) + mexErrMsgTxt("Specified function does not exist within gco_matlab module"); + try { + it->second(nlhs, plhs, nrhs-1, prhs+1); + } catch (GCException err) { + mexErrMsgTxt(err.message); + } catch (MatlabError err) { + mexErrMsgTxt(err.msg); + } +} + + +GCO_EXPORT(gco_create_general) +{ + int instanceID = 0; + try { + MATLAB_ASSERT_ARGCOUNT(1,2); + MATLAB_ASSERT_INTYPE(0,cSiteClassID); + MATLAB_ASSERT_INTYPE(1,cLabelClassID); + SiteID numSites = *(SiteID* )mxGetData(prhs[0]); MATLAB_ASSERT(numSites >= 1, "Number of sites must be positive"); + LabelID numLabels = *(LabelID*)mxGetData(prhs[1]); MATLAB_ASSERT(numLabels >= 2, "Number of labels must be positive"); + instanceID = gNextInstanceID++; + GCInstanceInfo& gcinstance = gInstanceMap[instanceID]; + gcinstance.gco = new GCoptimizationGeneralGraph(numSites, numLabels); + gcinstance.grid = false; + mwSize outSize = 1; + plhs[0] = mxCreateNumericArray(1, &outSize, mxINT32_CLASS, mxREAL); + *(int*)mxGetData(plhs[0]) = instanceID; + } catch (MatlabError) { + if (instanceID) + gInstanceMap.erase(instanceID); + throw; + } +} + +GCO_EXPORT(gco_delete) +{ + MATLAB_ASSERT_HANDLE(0); + const int* instanceIDs = (int*)mxGetData(prhs[0]); + MATLAB_ASSERT(mxGetN(prhs[0]) == 1 || mxGetM(prhs[0]) == 1, "Input must be a scalar or a vector"); + mwIndex count = mxGetNumberOfElements(prhs[0]); + for (mwIndex i = 0; i < count; ++i) { + MATLAB_ASSERT(gInstanceMap.find(instanceIDs[i]) != gInstanceMap.end(), "Invalid handle (no such GCoptimization object)"); + gInstanceMap.erase(instanceIDs[i]); + } +} + +GCO_EXPORT(gco_listhandles) +{ + MATLAB_ASSERT_ARGCOUNT(1,0); + mwSize outSize = (mwSize)gInstanceMap.size(); + plhs[0] = mxCreateNumericArray(1, &outSize, mxINT32_CLASS, mxREAL); + int* instanceIDs = (int*)mxGetData(plhs[0]); + for (GCInstanceMap::const_iterator i = gInstanceMap.begin(); i != gInstanceMap.end(); ++i) + *(instanceIDs++) = i->first; +} + + +GCO_EXPORT(gco_setdatacost) +{ + MATLAB_ASSERT_ARGCOUNT(0,3); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,cEnergyTermClassID); + MATLAB_ASSERT_INTYPE(2,cLabelClassID); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + const mxArray* dc = prhs[1]; + LabelID label = *(LabelID*)mxGetData(prhs[2]); + if (label == 0) { + // Dense data costs + MATLAB_ASSERT(mxGetN(dc) == gcinstance.gco->numSites() && mxGetM(dc) == gcinstance.gco->numLabels(), + "Numeric data cost must be NumLabels x NumSites in size"); + // Increment reference count on this array to avoid copy. + // This way the GCoptimization object refers directly to the Matlab storage. + // If the user modifies their original variable, Matlab will do a lazy copy + // before modifying, thus making sure the pointer used here is valid and + // still points to the original data. + mxArray* newRef = mxCreateReference(dc); + gcinstance.gco->setDataCost((EnergyTermType*)mxGetData(dc)); + if (gcinstance.dc) + mxDestroyArray(gcinstance.dc); + gcinstance.dc = newRef; + } else { + // Sparse data costs + MATLAB_ASSERT(mxGetM(dc) == 2, "Sparse data cost must have 2 rows"); + MATLAB_ASSERT(sizeof(SiteID) == sizeof(EnergyTermType), + "Sparse data costs cannot be used because GCoptimization was compiled " + "such that sizeof(SiteID) != sizeof(EnergyTermType)"); + SiteID count = (SiteID)mxGetN(dc); + GCoptimization::SparseDataCost* dcmem = (GCoptimization::SparseDataCost*)mxGetData(dc); + try { + for (LabelID i = 0; i < count; ++i) + dcmem[i].site--; // from 1-based to 0-based index + gcinstance.gco->setDataCost(label-1,dcmem,count); + if (gcinstance.dc) { + mxDestroyArray(gcinstance.dc); // the gco object forgets about the pointer, so we let MATLAB know + gcinstance.dc = 0; + } + for (LabelID i = 0; i < count; ++i) + dcmem[i].site++; // from 0-based to 1-based index + } catch (...) { + for (LabelID i = 0; i < count; ++i) + dcmem[i].site++; // from 0-based to 1-based index + throw; + } + } +} + +GCO_EXPORT(gco_setsmoothcost) +{ + MATLAB_ASSERT_ARGCOUNT(0,2); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,cEnergyTermClassID); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + const mxArray* sc = prhs[1]; + // Smooth costs provided as numeric array, and is applied to all neighbouring variables. + MATLAB_ASSERT(mxGetN(sc) == gcinstance.gco->numLabels() && mxGetM(sc) == gcinstance.gco->numLabels(), + "Numeric smooth cost must be NumLabels x NumLabels in size"); + // Increment reference count on this array to avoid copy. + // This way the GCoptimization object refers directly to the Matlab storage. + // If the user modifies their original variable, Matlab will do a lazy copy + // before modifying, thus making sure the pointer used here is valid and + // still points to the original data. + if (gcinstance.sc) mxDestroyArray(gcinstance.sc); + gcinstance.sc = mxCreateReference(sc); + gcinstance.gco->setSmoothCost((EnergyTermType*)mxGetData(sc)); +} + +GCO_EXPORT(gco_setlabelcost) +{ + LabelID* subset = 0; + LabelID subsetSize = 0; + try { + MATLAB_ASSERT(nlhs == 0, "Too many output arguments, expected 0"); + MATLAB_ASSERT(nrhs >= 2, "Not enough input arguments, expected at least 2"); + MATLAB_ASSERT(nrhs <= 3, "Too many input arguments, expected at most 3"); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,cEnergyTermClassID); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + const mxArray* lc = prhs[1]; + if (mxGetN(lc) == 1 && mxGetM(lc) == 1) { + if (nrhs == 2) { + // Single cost used independently for all labels + gcinstance.gco->setLabelCost(*(EnergyTermType*)mxGetData(lc)); + } else { + // Cost for using an element from a specific subset of labels + MATLAB_ASSERT_INTYPE(2,cLabelClassID); + subset = (LabelID*)mxGetData(prhs[2]); + subsetSize = (LabelID)mxGetNumberOfElements(prhs[2]); + for (LabelID i = 0; i < subsetSize; ++i) + subset[i]--; // from 1-based to 0-based index + gcinstance.gco->setLabelSubsetCost(subset,subsetSize,*(EnergyTermType*)mxGetData(lc)); + for (LabelID i = 0; i < subsetSize; ++i) + subset[i]++; // from 0-based to 1-based index + } + } else { + // Label costs provided as complete numeric array. + MATLAB_ASSERT(mxGetNumberOfElements(lc) == gcinstance.gco->numLabels(), + "Numeric label cost must have either one element, or NumLabels elements"); + gcinstance.gco->setLabelCost((EnergyTermType*)mxGetData(lc)); + } + } catch (...) { + for (LabelID i = 0; i < subsetSize; ++i) + subset[i]++; // from 0-based to 1-based index + throw; + } +} + +GCO_EXPORT(gco_setneighbors) +{ + MATLAB_ASSERT_ARGCOUNT(0,2); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,mxDOUBLE_CLASS); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + MATLAB_ASSERT(gcinstance.grid == false, "SetNeighbors can only be called on general graphs"); + GCoptimizationGeneralGraph* gco = static_cast(gcinstance.gco); + const mxArray* nb = prhs[1]; + MATLAB_ASSERT(mxIsSparse(nb), "Expected sparse array for neighbours"); + MATLAB_ASSERT(mxGetN(nb) == gcinstance.gco->numSites() && mxGetM(nb) == gcinstance.gco->numSites(), + "Neighbours array must be NumSites x NumSites in size"); + bool warned = false; + mwIndex n = (mwIndex)mxGetN(nb); + const mwIndex* ir = mxGetIr(nb); + const mwIndex* jc = mxGetJc(nb); + double* pr = mxGetPr(nb); + mwIndex count = 0; + for (mwIndex c = 0; c < n; ++c) { + mwIndex rowStart = jc[c]; + mwIndex rowEnd = jc[c+1]; + for (mwIndex ri = rowStart; ri < rowEnd; ++ri) { + mwIndex r = ir[ri]; + MATLAB_ASSERT(r != c, "A site cannot neighbor itself; make sure diagonal is all zero"); + + double dw = pr[count++]; + int w = (int)dw; + if ((double)w != dw && !warned) { + mexWarnMsgTxt("Non-integer weight detected; rounding to int32"); + warned = true; + } + if (r < c) + gco->setNeighbors((SiteID)r, (SiteID)c, w); + } + } +} + +GCO_EXPORT(gco_setlabelorder) +{ + MATLAB_ASSERT_ARGCOUNT(0,2); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,cLabelClassID); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + LabelID* order = (LabelID*)mxGetData(prhs[1]); + LabelID size = (LabelID)mxGetNumberOfElements(prhs[1]); + try { + for (LabelID i = 0; i < size; ++i) + order[i]--; // from 1-based to 0-based index + gcinstance.gco->setLabelOrder(order,size); + for (LabelID i = 0; i < size; ++i) + order[i]++; // from 0-based to 1-based index + } catch (...) { + for (LabelID i = 0; i < size; ++i) + order[i]++; // from 0-based to 1-based index + throw; + } +} + +GCO_EXPORT(gco_setverbosity) +{ + MATLAB_ASSERT_ARGCOUNT(0,2); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,mxINT32_CLASS); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + int level = *(int*)mxGetData(prhs[1]); + MATLAB_ASSERT(level >= 0 && level <= 2,"Level must be in range 0..2"); + gcinstance.gco->setVerbosity(level); +} + +GCO_EXPORT(gco_expansion) +{ + MATLAB_ASSERT_ARGCOUNT(1,2); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,mxINT32_CLASS); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + int maxIter = *(int*)mxGetData(prhs[1]); + EnergyType energy = gcinstance.gco->expansion(maxIter); + mwSize outdim = 1; + plhs[0] = mxCreateNumericArray(1, &outdim, cEnergyClassID, mxREAL); + *(EnergyType*)mxGetData(plhs[0]) = energy; +} + +GCO_EXPORT(gco_swap) +{ + MATLAB_ASSERT_ARGCOUNT(1,2); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,mxINT32_CLASS); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + int maxIter = *(int*)mxGetData(prhs[1]); + EnergyType energy = gcinstance.gco->swap(); + mwSize outdim = 1; + plhs[0] = mxCreateNumericArray(1, &outdim, cEnergyClassID, mxREAL); + *(EnergyType*)mxGetData(plhs[0]) = energy; +} + +GCO_EXPORT(gco_alphaexpansion) +{ + MATLAB_ASSERT_ARGCOUNT(0,2); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,cLabelClassID); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + LabelID alpha = *(LabelID*)mxGetData(prhs[1])-1; + gcinstance.gco->alpha_expansion(alpha); +} + +GCO_EXPORT(gco_computeenergy) +{ + MATLAB_ASSERT_ARGCOUNT(4,1); + MATLAB_ASSERT_HANDLE(0); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + EnergyType energy = gcinstance.gco->compute_energy(); + mwSize outSize = 1; + plhs[0] = mxCreateNumericArray(1, &outSize, cEnergyClassID, mxREAL); + plhs[1] = mxCreateNumericArray(1, &outSize, cEnergyClassID, mxREAL); + plhs[2] = mxCreateNumericArray(1, &outSize, cEnergyClassID, mxREAL); + plhs[3] = mxCreateNumericArray(1, &outSize, cEnergyClassID, mxREAL); + *(EnergyType*)mxGetData(plhs[3]) = gcinstance.gco->giveLabelEnergy(); + *(EnergyType*)mxGetData(plhs[2]) = gcinstance.gco->giveSmoothEnergy(); + *(EnergyType*)mxGetData(plhs[1]) = gcinstance.gco->giveDataEnergy(); + *(EnergyType*)mxGetData(plhs[0]) = *(EnergyType*)mxGetData(plhs[1])+*(EnergyType*)mxGetData(plhs[2])+*(EnergyType*)mxGetData(plhs[3]); +} + +GCO_EXPORT(gco_setlabeling) +{ + MATLAB_ASSERT_ARGCOUNT(0,2); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,cLabelClassID); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + const mxArray* labeling = prhs[1]; + MATLAB_ASSERT(mxGetN(labeling) == gcinstance.gco->numSites() || mxGetM(labeling) == gcinstance.gco->numSites(), + "Labeling must be of length NumSites"); + LabelID* labeldata = (LabelID*)mxGetData(labeling); + for (mwIndex i = 0; i < gcinstance.gco->numSites(); ++i) + MATLAB_ASSERT(labeldata[i] >= 1 && labeldata[i] <= gcinstance.gco->numLabels(), + "Labeling must be in range 1..NumLabels"); + for (mwIndex i = 0; i < gcinstance.gco->numSites(); ++i) + gcinstance.gco->setLabel((SiteID)i, labeldata[i]-1); +} + +GCO_EXPORT(gco_getlabeling) +{ + MATLAB_ASSERT_ARGCOUNT(1,3); + MATLAB_ASSERT_HANDLE(0); + MATLAB_ASSERT_INTYPE(1,cSiteClassID); + MATLAB_ASSERT_INTYPE(2,cSiteClassID); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + MATLAB_ASSERT(*(SiteID*)mxGetData(prhs[1]) > 0, "Start index must be in range 1..NumSites"); + SiteID start = *(SiteID*)mxGetData(prhs[1])-1; + SiteID count = *(SiteID*)mxGetData(prhs[2]); + MATLAB_ASSERT(start+count <= gcinstance.gco->numSites(), "End index must be in range 1..NumSites"); + mwSize mlcount = (mwSize)count; + plhs[0] = mxCreateNumericArray(1, &mlcount, cLabelClassID, mxREAL); + LabelID* labeling = (LabelID*)mxGetData(plhs[0]); + gcinstance.gco->whatLabel(start, count, labeling); + for ( SiteID i = 0; i < count; ++i ) + labeling[i]++; // convert C index to Matlab index +} + +GCO_EXPORT(gco_getnumsites) +{ + MATLAB_ASSERT_ARGCOUNT(1,1); + MATLAB_ASSERT_HANDLE(0); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + mwSize outdim = 1; + plhs[0] = mxCreateNumericArray(1, &outdim, cSiteClassID, mxREAL); + *(SiteID*)mxGetData(plhs[0]) = gcinstance.gco->numSites(); +} + +GCO_EXPORT(gco_getnumlabels) +{ + MATLAB_ASSERT_ARGCOUNT(1,1); + MATLAB_ASSERT_HANDLE(0); + GCInstanceInfo& gcinstance = sGetGCInstance(*(int*)mxGetData(prhs[0])); + mwSize outSize = 1; + plhs[0] = mxCreateNumericArray(1, &outSize, cLabelClassID, mxREAL); + *(LabelID*)mxGetData(plhs[0]) = gcinstance.gco->numLabels(); +} diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getDCOptions.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getDCOptions.m new file mode 100644 index 0000000000000000000000000000000000000000..3970258e993fceef1ee0cbbdf889406c77bfb11e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getDCOptions.m @@ -0,0 +1,54 @@ +function opt=getDCOptions() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +% general +opt.track3d=0; % set to 1 for track estimation on ground plane +opt.verbosity=3; % 0=silent, 1=short info, 2=long info, 3=all +opt.visOptim=1; % visualize optimization +opt.met2d=0; % always compute metrics in 2d (slower) +opt.maxModels=20000; % max number of trajectory hypotheses +opt.keepHistory=3; % keep unused models for n iterations +opt.cutToTA=0; % cut detections, ground truth and result to tracking area + + +% defaults (2d) +opt.labelCost= 200; +opt.outlierCost= 200; +opt.unaryFactor= .1; +opt.pairwiseFactor= 100; +opt.goodnessFactor= 10; +opt.proxcostFactor= 0.0; +opt.nInitModels= 50; +opt.minCPs= 1; +opt.ncpsPerFrame= 1/50; +opt.totalSupFactor= 2; +opt.meanDPFFactor= 2; +opt.meanDPFeFactor= 2; +opt.curvatureFactor=0; +opt.tau = 10; % threshold (pixel) for spatio-temporal neighbors +opt.borderMargin = 100; % (pixel) % distance for persistence + + + +if opt.track3d + opt.labelCost= 20; + opt.outlierCost= 20; + opt.unaryFactor= 10; + opt.pairwiseFactor= 2; + opt.goodnessFactor= 0.1; + + opt.tau = 750; % threshold (mm) for spatio-temporal neighbors + opt.borderMargin = 5000; % distance for persistence +end + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getDCOptionsDemo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getDCOptionsDemo.m new file mode 100644 index 0000000000000000000000000000000000000000..d13a70377568da5a0193b095465f9384cc6c61c6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getDCOptionsDemo.m @@ -0,0 +1,54 @@ +function opt=getDCOptionsDemo() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +% general +opt.track3d=0; % set to 1 for track estimation on ground plane +opt.verbosity=1; % 0=silent, 1=short info, 2=long info, 3=all +opt.visOptim=0; % visualize optimization +opt.met2d=0; % always compute metrics in 2d (slower) +opt.maxModels=20000; % max number of trajectory hypotheses +opt.keepHistory=3; % keep unused models for n iterations +opt.cutToTA=0; % cut detections, ground truth and result to tracking area + +% defaults (2d) +% opt.labelCost= 200; +% opt.outlierCost= 200; +% opt.unaryFactor= .1; +% opt.pairwiseFactor= 100; +% opt.goodnessFactor= 10; +% opt.proxcostFactor= 0.0; +% opt.nInitModels= 500; +% opt.minCPs= 1; +% opt.ncpsPerFrame= 1/50; +% opt.totalSupFactor= 2; +% opt.meanDPFFactor= 2; +% opt.meanDPFeFactor= 2; +% opt.curvatureFactor=0; +% opt.tau = 10; % threshold (pixel) for spatio-temporal neighbors +% opt.borderMargin = 100; % (pixel) % distance for persistence +opt.labelCost= 300; +opt.outlierCost= 200; +opt.unaryFactor= 1; +opt.pairwiseFactor= 100; +opt.goodnessFactor= 10; +opt.proxcostFactor= 0.0; +opt.nInitModels= 500; +opt.minCPs= 1; +opt.ncpsPerFrame= 1/50; +opt.totalSupFactor= 2; +opt.meanDPFFactor= 2; +opt.meanDPFeFactor= 2; +opt.curvatureFactor=0; +opt.tau = 50; % threshold (pixel) for spatio-temporal neighbors +opt.borderMargin = 250; % (pixel) % distance for persistence + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getDetsForTraj.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getDetsForTraj.m new file mode 100644 index 0000000000000000000000000000000000000000..7bf1a48dc238b456c0eadb8ddd9a9e40dc4163b8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getDetsForTraj.m @@ -0,0 +1,40 @@ +function dwt=getDetsForTraj(mhs,alldpoints,T,tau) +% count the number of detections that a close +% to a trajectory (< threshold tau) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% if nargin<4 +% tau=0.25; % threshold +% end + + +tt=mhs.start:mhs.end; +dwt=-1*ones(1,T); + +splinexy=ppval(mhs,1:T); +for t=tt + sx=splinexy(1,t); sy=splinexy(2,t); +% t +% sx + + % find all detections in this frame + detind=find(alldpoints.tp==t); +% detind + sp=[sx*ones(1,numel(detind)); sy*ones(1,numel(detind))]; + dp=[alldpoints.xp(detind);alldpoints.yp(detind)]; + d=sp-dp; + inthisframe=sqrt(sum(d.^2)) < tau; +% sqrt(sum(d.^2))/1000 + dwt(t)=sum(inthisframe); +end + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getEmptyModelStruct.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getEmptyModelStruct.m new file mode 100644 index 0000000000000000000000000000000000000000..a826e59d8ec02d194947abf9501ddbcd07c03f08 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getEmptyModelStruct.m @@ -0,0 +1,19 @@ +function ret=getEmptyModelStruct() +% trajectory model +% same as pmpp object plus temporal start and end points +% as well as the corresponding label cost and a counter +% that states how many iterations ago this trajectory was used last time +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +ret = struct('form',{},'breaks',{},'coefs',{},'pieces',{},'order',{},'dim',{},'start',{},'end',{},'goodness',{},'lastused',{}); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getGCO_Energy.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getGCO_Energy.m new file mode 100644 index 0000000000000000000000000000000000000000..42d27e7ea1e2d273167823da4064d6e75599edcf --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getGCO_Energy.m @@ -0,0 +1,25 @@ +function [inE inD inS inL] = getGCO_Energy(Dcost, Scost, Lcost, TNeighbors, labeling) +% compute energy values for a given labeling +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +[nLabels nPoints]=size(Dcost); +h = GCO_Create(nPoints,nLabels); +GCO_SetDataCost(h,int32(Dcost)); +GCO_SetLabelCost(h,int32(Lcost)); +if ~isempty(Scost) + GCO_SetSmoothCost(h,int32(Scost)); + GCO_SetNeighbors(h,TNeighbors); +end + +GCO_SetLabeling(h,int32(labeling)); + +[inE inD inS inL] = GCO_ComputeEnergy(h); +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getLabelCost.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getLabelCost.m new file mode 100644 index 0000000000000000000000000000000000000000..38133a82bf4920a03f735878a3d2612690f11d63 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getLabelCost.m @@ -0,0 +1,22 @@ +function Lcost=getLabelCost(splines) +% Compute the label cost for all splines +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt + +nCurModels=length(splines); + +lc1=opt.labelCost*ones(1,nCurModels); % standard uniform +lc2=opt.goodnessFactor*[splines.goodness]; % hdyn, hfid, hper,... +lc3=0;%proxcostFactor*proxcost; +Lcost =[lc1+lc2+lc3 0]; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSceneInfoDCDemo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSceneInfoDCDemo.m new file mode 100644 index 0000000000000000000000000000000000000000..04f2c61ddf801652b0c3571fe9e228e0ac414b52 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSceneInfoDCDemo.m @@ -0,0 +1,52 @@ +function sceneInfo = getSceneInfoDCDemo(curSequence) +% fill all necessary information about the +% scene into the sceneInfo struct +% +% Required: +% detfile detections file (.idl or .xml) +% frameNums frame numbers (eg. frameNums=1:107) +% imgFolder image folder +% imgFileFormat format for images (eg. frame_%04d.jpg) +% targetSize approx. size of targets (default: 5 on image, 350 in 3d) +% +% Required for 3D Tracking only +% trackingArea tracking area +% camFile camera calibration file (.xml PETS format) +% +% Optional: +% gtFile file with ground truth bounding boxes (.xml CVML) +% initSolFile initial solution (.xml or .mat) +% targetAR aspect ratio of targets on image +% bgMask mask to bleach out the background +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +sceneInfo.imgFolder = curSequence.imgFolder; +sceneInfo.frameNums = curSequence.frameNums; +sceneInfo.imgFileFormat = curSequence.imgFileFormat; + +% image dimensions +sceneInfo.imgHeight = curSequence.imgHeight; +sceneInfo.imgWidth = curSequence.imgWidth; + +%% tracking area +% if we are tracking on the ground plane +% we need to explicitly secify the tracking area +% otherwise image = tracking area +sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area + +%% camera +cameraconffile = []; +sceneInfo.camFile = cameraconffile; + +%% target size +sceneInfo.targetSize=sceneInfo.imgWidth/30; + +%% ground truth +sceneInfo.gtAvailable=0; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSplineGoodness.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSplineGoodness.m new file mode 100644 index 0000000000000000000000000000000000000000..a4024179c42ae9fe472a34167df84d3fbef55f5c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSplineGoodness.m @@ -0,0 +1,300 @@ +function [goodness components]=getSplineGoodness(mh,used,alldpoints,T) +% compute the goodness (label cost) of each trajectory +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +goodness=zeros(1,length(used)); +components=zeros(length(used),10); +global sceneInfo opt + +gF=opt.goodnessFactor; +% no need to compute if coefficient is 0 anyway +if ~gF, return; end + + +areaLimits=sceneInfo.trackingArea; + + +tau=sceneInfo.targetSize/2; +% if ~opt.track3d, tau=10; end + + + +tt=1:T; +global dwi; + +stateInfo=getStateFromSplines(mh, struct('F',T)); + +for m=used + confpermodel=[]; + distpermodel=[]; + mhs=mh(m); + tt=mhs.start:mhs.end; + % tt + TT=length(tt); +% m +% mhs +% splinexy=ppval(mhs,1:T); + splinexy=[stateInfo.X(:,m)';stateInfo.Y(:,m)']; + + + detsWithin=-1*ones(1,T); + insideAL=zeros(1,T); % inside areaLimits +% insideIM=zeros(1,T); % inside imageLimits + + for t=tt + sx=splinexy(1,t); sy=splinexy(2,t); + + +% if sx>minX && sxminY && sy=tau)=tau; +% if ~isempty(alldistinframe) +% alldistinframe=mean(alldistinframe); +% distpermodel=[distpermodel alldistinframe]; +% end + + + confinframe=alldpoints.sp(detind(inthisframe>0)); + confpermodel=[confpermodel confinframe]; + % [t confinframe] + detsWithin(t)=sum(inthisframe); + % for np=detind + % dp=[alldpoints.xp(np);alldpoints.yp(np)]; + % sp=[sx;sy]; + % eucl = norm(dp-sp); + % % eucl + % % pause + % if eucl < tau + % % plot3(dp(1),dp(2),t,'o'); + % % % plot3(sp(1),sp(2),t,'+'); + % % pause + % + % detsWithin(t)=detsWithin(t)+1; + % end + % end +% end + + end + % if m==6 || m==32 || m==36 + % detsWithin + % insideAL + % end + + + % [m dpm] + + + dwi=detsWithin; + + detsinta=detsWithin(insideAL>0); + detsinta=detsWithin; +% goodness(m)=sum(abs(detsWithin(insideAL>0)-1)); % simple per frame number of detections + + % occlusion gaps + nodetframes=[0 ~detsWithin(insideAL>0) 0]; + multdetframes=[0 detsinta>1 0]; + % nodetframes + % multdetframes + c=find(diff(nodetframes)==1); d=find(diff(nodetframes)==-1); + e=find(diff(multdetframes)==1); f=find(diff(multdetframes)==-1); + occgaps=(d-c); + muldetgaps=(f-e); + % d + % c + % occgaps + % detsWithin(insideAL>0) + % muldetgaps + % detsWithin + % occgaps + occgapspen=0; + occgapsfac=1; + occgapspen=occgapsfac*sum(occgaps.^3);% + ... + %sum(muldetgaps.^2);% + ... + + notonedets=0; +% notonedets=sum(abs(detsWithin(insideAL>0)-1)); + + +% g=find(diff(~insideAL)==1); h=find(diff(~insideAL)==-1); +% outsidegaps=(h-g); + outsideAL=0; +% outsideAL=sum(outsidegaps.^2); +% outsideAL=5 *sum(~insideAL); + + % cfpm=median(confpermodel); + % sigcfpm=100/(1+exp(-25+50*cfpm)); + % goodness(m)=goodness(m)+sigcfpm; + + %% disttodets + distfac=10; +% dpm=tau; +% if ~isempty(distpermodel), dpm=mean(distpermodel); end +% dpm=dpm/tau; dpm=dpm^4; + + + disttodets=0; +% disttodets=distfac*dpm; + + % piecefac=.1; + % goodness(m)=goodness(m)+piecefac*mhs.pieces^2; + + mhs=mh(m); + + %% persistence + perfac=.1; + + persistencestart=0; + persistenceend=0; + s=mhs.start; e=mhs.end; +% xy=ppval(mh(m),[s e]); + xy=[stateInfo.X([s e],m)';stateInfo.Y([s e],m)']; + + if s>1 + xs=xy(1,1); ys=xy(2,1); + if opt.track3d + [dms ci si]=min_dist_im(xs,ys,sceneInfo.imOnGP); + else + [dms ci si]=min_distances(xs,ys,sceneInfo.trackingArea); + end + + dms=min(dms,opt.borderMargin); + persistencestart=perfac*dms; + end + + if e1e5)=1e5; +end + +function [dm ci si]=min_dist_im(x,y,imOnGP) + +% left +x0=imOnGP(1);y0=imOnGP(2); +x1=imOnGP(3);y1=imOnGP(4); +dl = p2l(x,y,x0,x1,y0,y1); + +% top +x0=imOnGP(3);y0=imOnGP(4); +x1=imOnGP(5);y1=imOnGP(6); +du = p2l(x,y,x0,x1,y0,y1); + +% right +x0=imOnGP(5);y0=imOnGP(6); +x1=imOnGP(7);y1=imOnGP(8); +dr = p2l(x,y,x0,x1,y0,y1); + +% bottom +x0=imOnGP(7);y0=imOnGP(8); +x1=imOnGP(1);y1=imOnGP(2); +dd = p2l(x,y,x0,x1,y0,y1); + +distances=abs([dl dr du dd]); + +% choose the closest one +[dm ci]=min(distances); + + +si=1; +% if xmaxX || ymaxY +% si=-1; +% end +end + +function dl=p2l(x,y,x0,x1,y0,y1) +dl = ((y0-y1)*x + (x1-x0)*y + (x0*y1-x1*y0) ) / (sqrt((x1-x0)^2 + (y1-y0)^2) ); +end + +function [dm ci si]=min_distances(x,y,areaLimits) +% returns min distance from x,y to border and index ci + +minX=areaLimits(1); % left border +maxX=areaLimits(2); % right border +minY=areaLimits(3); % bottom border +maxY=areaLimits(4); % top border + +% determine distance to all four borders + +% dist left +dl=abs(minX-x); % dl=x-minX; +% dist right +dr=abs(maxX-x); %dr=maxX-x; +% dist up +du=abs(minY-y); %du=y-minY; +% dist down +dd=abs(maxY-y); %dd=maxY-y; +distances=[dl dr du dd]; + +% choose the closest one +[dm ci]=min(distances); + +si=1; +if xmaxX || ymaxY + si=-1; +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSplineProposals.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSplineProposals.m new file mode 100644 index 0000000000000000000000000000000000000000..fff755ce7d7b05211a9e29fe1f69f1f44d0c91a6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSplineProposals.m @@ -0,0 +1,119 @@ +function mh=getSplineProposals(alldpoints,n,T) +% generate splines from the set of detections +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +mh=getEmptyModelStruct; + +global sceneInfo + +ndp=length(alldpoints.xp); + +assert(ndp>4,'at least 4 points needed to generate proposals...'); +% relpercent=10; +q=2; + + +speedThreshold = sceneInfo.targetSize; +tauThreshold = sceneInfo.targetSize/2; + +maxtries=1e3; +maxtries2=1e3; +generated=0; +trygen2=0; +while generatedspeedThreshold && trygen=randorder %&& min(alldpoints.tp(randPoints))T-T/relpercent + break + end + end + + xy=[alldpoints.xp(randPoints);alldpoints.yp(randPoints)]; + t=alldpoints.tp(randPoints); +% confs=alldpoints.sp(randPoints); + + order=numel(randPoints); + tryfit=splinefit(t,xy,1,order); + if numel(find(isnan(tryfit.coefs))), continue; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % make cubic + if order~=4 + sortedt=sort(t); + t=linspace(sortedt(1),sortedt(end),4); + xy=ppval(tryfit,t); + cubicspline=splinefit(t,xy,1,4); + else + cubicspline=tryfit; + end + + if numel(find(isnan(cubicspline.coefs))), continue; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + cubicspline.start=min(t); cubicspline.end=max(t); + + % cubicspline.start=1; cubicspline.end=10; + + if trygen2=0)) < rand, continue; end + end + + generated=generated+1; + [sg, ~]=getSplineGoodness(cubicspline,1,alldpoints,T); + cubicspline.goodness=sg; + cubicspline.lastused=0; + mh(generated)=cubicspline; + % tgap(generated)=diff([min(t) max(t)]); +end + +% mean(tgap) +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSplinesFromEKF.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSplinesFromEKF.m new file mode 100644 index 0000000000000000000000000000000000000000..ab1890e380699c67cbfe738aa0b54e05d9892c94 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getSplinesFromEKF.m @@ -0,0 +1,104 @@ +function mhs=getSplinesFromEKF(solfile,frames,alldpoints,T) +% Fit splines through an existing EKF solution +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +mhs=getEmptyModelStruct; + + + +newmods=0; +% for experiment=exp + % ncps=3; +% solfile=getSolutionFile(scenario,experiment,'ekf'); +% solfile=fullfile(getHomeFolder,'diss','ekftracking','output',sprintf('s%04d',scenario),sprintf('e%04d.mat',experiment)); + if ~exist(solfile,'file') + mhs=[]; + + return; + end + + load(solfile); + ncps=max(1,round(length(frameNums)/50)); + + % X=X(1:Fd,:);Y=Y(1:Fd,:); + % X=removeShorties(X,2);Y=removeShorties(Y,2); + [F N]=size(X); + if length(frames)3 + %% extend to first and last frame + ff=cptimes(1); lf=cptimes(end); trl=lf-ff; + ncps=max(1,round(trl/50)); + + torig=cptimes'; + xy=[X(cptimes,id) Y(cptimes,id)]'; + + + ttail=cptimes(1:4); + xytail=[X(ttail,id) Y(ttail,id)]'; + + if length(unique(ttail))>2 + tailline=splinefit(ttail,xytail,1,2); + tailtime=torig(1)-exttail:torig(1)-1; + taillinepts=ppval(tailline,tailtime); + + xy=[taillinepts xy]; + cptimes=[(cptimes(1)-exttail:cptimes(1)-1)'; cptimes]; + end + thead=cptimes(end-3:end); + xyhead=[X(thead,id) Y(thead,id)]'; + + if length(unique(thead))>2 + headline=splinefit(thead,xyhead,1,2); + headlinepts=ppval(headline,torig(end)+1:torig(end)+exthead); + + xy=[xy headlinepts]; + cptimes=[cptimes; (cptimes(end)+1:cptimes(end)+exthead)']; + end + + + + newmods=newmods+1; + sfit=splinefit(cptimes,xy,ncps); + sfit.start=ff; sfit.end=lf; + [sfit.goodness sgc]=getSplineGoodness(sfit,1,alldpoints,T); + sfit.lastused=0; + mhs(newmods)=sfit; + end + end +% end + +%% check for doubles + +if ~isempty(mhs) + dists=Inf*ones(newmods); + for m1=1:newmods + for m2=m1+1:newmods + if mhs(m1).pieces==mhs(m2).pieces + dists(m1,m2)=sum(sum(abs(mhs(m1).coefs-mhs(m2).coefs))); + end + end + end + + redundant=sum(~dists,2); + mhs=mhs(~redundant); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getStateFromSplines.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getStateFromSplines.m new file mode 100644 index 0000000000000000000000000000000000000000..48c3ec30c5b65cbd793c07e799472a629e040486 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getStateFromSplines.m @@ -0,0 +1,41 @@ +function stateInfo=getStateFromSplines(splines, stateInfo, onImage) +% convert splines to matrices X and Y +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global sceneInfo opt +N=length(splines); +F=stateInfo.F; +X=zeros(F,N); +Y=zeros(size(X)); + +for id=1:N + tt=splines(id).start:splines(id).end; + + allxy=ppval(splines(id),tt)'; + X(tt,id)=allxy(:,1); Y(tt,id)=allxy(:,2); + + +end + +stateInfo.X=X;stateInfo.Y=Y; +if nargin<3 + onImage=0; +end + +if opt.track3d + stateInfo.Xgp=X;stateInfo.Ygp=Y; + if onImage + [stateInfo.Xi stateInfo.Yi]=projectToImage(stateInfo.X,stateInfo.Y,sceneInfo); + end +else + stateInfo.Xi=X; stateInfo.Yi=Y; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getTemporalNeighbors.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getTemporalNeighbors.m new file mode 100644 index 0000000000000000000000000000000000000000..79d26fd364915496f3d991c26bd222112afb5e66 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getTemporalNeighbors.m @@ -0,0 +1,41 @@ +function TNeighbors=getTemporalNeighbors(allpoints) +% get spatio-temporal neighbors for each detection (Fig. 3) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +global opt +nPoints=length(allpoints.xp); +TNeighbors=sparse(nPoints,nPoints); + +allt=unique(sort(allpoints.tp)); +allt=allt(1:end-1); +for t=allt + thist=find(allpoints.tp==t); + nextt=find(allpoints.tp==t+1); + nt=numel(thist); + ntt=numel(nextt); + if nt>1 + for np1=1:nt + for np2=1:ntt + eucldist=norm([allpoints.xp(thist(np1)) allpoints.yp(thist(np1))] - ... + [allpoints.xp(nextt(np2)) allpoints.yp(nextt(np2))]); + + if eucldist < opt.tau + TNeighbors(thist(np1),nextt(np2))=1; + end + end + + end + end + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getUnarySpline.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getUnarySpline.m new file mode 100644 index 0000000000000000000000000000000000000000..904daf7d882e9bde6c354468c42b916d82b9e4d9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/getUnarySpline.m @@ -0,0 +1,73 @@ +function Dmat = getUnarySpline(nLabels,nPoints,mh,allpoints,dphi,uF,T) +% compute unary energy term for all data points and all labels +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt + +if isempty(mh) + Dmat = dphi * ones(nLabels,nPoints); + return +end + +normfac=1; +if opt.track3d, normfac=1000; end + + +Dmat=zeros(nLabels,nPoints); + +exthead=2; +exttail=2; +allpind=1:nPoints; + +for l=1:nLabels-1 + % + splstart=mh(l).start-exttail; + splend=mh(l).end+exthead; + splineTimespan=max(1,splstart):min(T,splend); + % + % spltime=splstart:splend; + inSplineTimespan=find(allpoints.tp>=splstart & allpoints.tp<=splend); +% allothers=setdiff(1:nPoints,inSplineTimespan); + notinSplineTimespan=true(1,nPoints); + notinSplineTimespan(inSplineTimespan)=0; + allothers=find(allpind & notinSplineTimespan); + + % + pt=allpoints.tp(inSplineTimespan); + xt=ppval(mh(l),pt)'; %pts on spline + px=allpoints.xp(inSplineTimespan); + py=allpoints.yp(inSplineTimespan); + pt=allpoints.tp(inSplineTimespan); + sp=allpoints.sp(inSplineTimespan); + + datapts=[px; py]'; + alldists=xt-datapts; + + alldists=alldists'; + alldists=sqrt(sum(alldists.^2))/normfac; % L2 norm in m + + alln=alldists.^2; + + + Dmat(l,inSplineTimespan)=(alln .* sp); + Dmat(l,allothers)=1e5; +end + +Dmat=uF*Dmat; + + +Dmat(nLabels,1:nPoints)=dphi; +Dmat(nLabels,1:nPoints)=dphi*allpoints.sp; +% Dmat=Dmat+1; +Dmat(Dmat>1e6)=1e6; +Dmat(Dmat<-1e5)=-1e5; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/mergeSplines.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/mergeSplines.m new file mode 100644 index 0000000000000000000000000000000000000000..ad7d7b27098b77634ae4c60c30af93ce65696355 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/mergeSplines.m @@ -0,0 +1,109 @@ +function mhsret=mergeSplines(allpoints, mhs, used,labeling,T,E) +% construct new models from existing ones by +% merging plausible ones +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +mhsnew=getEmptyModelStruct(); + +global opt +normfac=1; +thr1=25; +thr2=2; +thr3=50; +if opt.track3d + normfac=1000; + thr1=.5; + thr2=2; + thr3=1; +end + +%% merge close ones only +nMaxAddMerged=50; +nCurModels=length(mhs); +addedMerged=0; +nUsed=length(used); +if nUsed>1 + for m1=randperm(nUsed) + mod1=used(m1); + mh1=mhs(mod1); + s1=mh1.start; + e1=mh1.end; + for m2=randperm(nUsed) + if addedMerged>=nMaxAddMerged, break; end + + mod2=used(m2); + mh2=mhs(mod2); + s2=mh2.start; + e2=mh2.end; + timegap=s2-e1; + if timegap < -10 || timegap > 10, continue; end + xyend=ppval(mh1,e1); + xystart=ppval(mh2,s2); + xe=xyend(1); ye=xyend(2); + xs=xystart(1); ys=xystart(2); + spacegap=norm(xystart-xyend)/normfac; + if ~timegap, timegap=1; end + speedpf=abs(spacegap/timegap); + % speedpf + if speedpf < thr1 || (abs(timegap) <= thr2 && speedpf < thr3) + + % fit through points + supp1=find(labeling==mod1); + supp2=find(labeling==mod2); + allsup=[supp1 supp2]; + + t=allpoints.tp(allsup); + % FIXME + tr=t+0.01*rand(1,length(t))-0.005; + + xy=[allpoints.xp(allsup);allpoints.yp(allsup)]; + + addedMerged=addedMerged+1; + sfit=splinefit(tr,xy,round(mh1.pieces+mh2.pieces)); + sfit.start=min(t); sfit.end=max(t); + [sfit.goodness sgc]=getSplineGoodness(sfit,1,allpoints,T); + sfit.lastused=0; + mhsnew(addedMerged) = sfit; + + % drawSplines(sfit,1,0,alldpoints,frames); + % [mod1 mod2] + % [timegap speedpf] + % sg=getSplineGoodness([mhs(mod1) mhs(mod2) sfit],1:3,alldpoints,areaLimits,imageLimits,T,goodnessFactor) + % pause + + % fit through splines + xt1=ppval(mh1,s1:e1); %pts on spline + xt2=ppval(mh2,s2:e2); + xy=[xt1 xt2]; + t=[s1:e1 s2:e2]; + tr=t+0.01*rand(1,length(t))-0.005; + addedMerged=addedMerged+1; + sfit=splinefit(tr,xy,round(mh1.pieces+mh2.pieces)); + sfit.start=min(t); sfit.end=max(t); + [sfit.goodness sgc]=getSplineGoodness(sfit,1,allpoints,T); + sfit.lastused=0; + mhsnew(addedMerged) = sfit; + + + + end + end + end + +end + +allnewgoodness=[mhsnew.goodness]; +mhsnew=mhsnew(E>allnewgoodness); +for m=1:length(mhsnew), mhsnew(m).lastused=0; end + +mhsret=mhs; +if ~isempty(mhsnew), mhsret=[mhs mhsnew]; end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/printDCUpdate.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/printDCUpdate.m new file mode 100644 index 0000000000000000000000000000000000000000..f24cbced34b06d3850aa29b61acb82dab65e6d94 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/printDCUpdate.m @@ -0,0 +1,74 @@ +function [metrics2d metrics3d]=printDCUpdate(stateInfo,splines,used,nNew,nRemoved,itcnt,D,S,L) +% print energy and performance information +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt gtInfo dcStartTime sceneInfo + +gtheader=''; +metheader=''; +metrics2d=zeros(1,14); +metrics3d=zeros(1,14); + +if sceneInfo.gtAvailable && opt.verbosity>=3 + gtheader=''; metheader=''; + + if opt.track3d + gtheader=' ----------- M E T R I C S (3D)---------- |||'; + metheader=' MOTA MOTP| GT MT ML| FP FN IDs FM |||'; + if opt.met2d + gtheader=[gtheader ' ----------- M E T R I C S (2D)--------- ']; + metheader=[metheader ' MOTA MOTP| GT MT ML| FP FN IDs FM|']; + end + else + if opt.met2d + gtheader=' ----------- M E T R I C S (2D)---------- |||'; + metheader=' MOTA MOTP| GT MT ML| FP FN IDs FM |'; + end + end + +end + +if ~mod(itcnt,10) + printMessage(2,'\n ------------- INFO -------------|| -------- ENERGY VALUES --------|||%s',gtheader); + printMessage(2,'\n it| time| models| used| add| rem|| Energy | Data | Smooth| Label| |||%s\n',metheader); +end + +printMessage(2,'%4i|%5.1f|%7i|%5i|%4i|%4i||%8i|%7i|%7i|%6i| |||', ... + itcnt, toc(dcStartTime)/60,length(splines),length(used),nNew, nRemoved,int32(D)+int32(S)+int32(L),D,S,L); %%% iter output + +if opt.verbosity>=3 + if sceneInfo.gtAvailable + stateInfo=getStateFromSplines(splines(used), stateInfo); + + + if opt.track3d + [metrics3d metrNames3d]=CLEAR_MOT(gtInfo,stateInfo,struct('eval3d','1')); + printMetrics(metrics3d,metrNames3d,0,[12 13 4 5 7 8 9 10 11]); + printMessage(3,'|||'); + end + + if opt.met2d + if opt.track3d + [stateInfo.Xi stateInfo.Yi]=projectToImage(stateInfo.X, stateInfo.Y,sceneInfo); + else + stateInfo.Xi=stateInfo.X; stateInfo.Yi=stateInfo.Y; + end + stateInfo=getBBoxesFromState(stateInfo); + evopt.eval3d=0; + [metrics2d metricsInfo2d]=CLEAR_MOT(gtInfo,stateInfo,evopt); + printMetrics(metrics2d,metricsInfo2d,0,[12 13 4 5 7 8 9 10 11]); + end + + end +end +printMessage(2,'\n'); + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/reestimateSplines.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/reestimateSplines.m new file mode 100644 index 0000000000000000000000000000000000000000..dd4d959786137a4f1771db3eb758a09922fc729c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/reestimateSplines.m @@ -0,0 +1,162 @@ +function splines=reestimateSplines(allpoints,used,labeling,nLabels,mhsall,DcostAll,T) +% refit splines to data points +% minimize continuous variables T +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +if isempty(used) + splines=mhsall; + return +end + +global opt + +nPoints=length(allpoints.xp); +minCPs=opt.minCPs; +ncpsPerFrame=opt.minCPs; + +exttail=2; +exthead=2; +nUsed=length(used); +Eold=zeros(0,4);Enew=zeros(0,4); +splines=mhsall; +for m=used +% mhsallnew=mhsall; + + mhsold=splines(m); + + %%% Consistency check! + % compute old energy + Dcost=DcostAll; + Lcost = getLabelCost(splines); + h=setupGCO(nPoints,nLabels,Dcost,Lcost,[],[]); + GCO_SetLabeling(h,labeling); + [E D S L] = GCO_ComputeEnergy(h); + GCO_Delete(h); +% Eold=[Eold; E D S L]; + + % find all points labeled m + supportPts=find(labeling==m); + nSP=length(supportPts); + + % careful! if less than 2 points, make standing object + if nSP<1 + error('This cannot happen... I think'); + elseif nSP==1 + xy=[allpoints.xp(supportPts);allpoints.yp(supportPts)]; xy=[xy xy]; + t=allpoints.tp(supportPts); + confs=allpoints.sp(supportPts); + if t==1, + t=[t t+1]; + else + t=[t-1 t]; + end + torig=t; + confsorig=confs; + + supPtsFrames=t; + else + xy=[allpoints.xp(supportPts);allpoints.yp(supportPts)]; + t=allpoints.tp(supportPts); + confs=allpoints.sp(supportPts); + [supPtsFrames sortind]=sort(allpoints.tp(supportPts)); + + % try here this... + % take n first and last points and fit a line to extrapolate + % add these to support + takenpts=4; + torig=t; + confsorig=confs; + if nSP>=takenpts + if exttail + ntail=sortind(1:takenpts); + tailpts=supportPts(ntail); + xytail=[allpoints.xp(tailpts);allpoints.yp(tailpts)]; + ttail=allpoints.tp(tailpts); + ctail=allpoints.sp(tailpts); + + if length(unique(ttail))>2 + tailline=splinefit(ttail,xytail,1,2,ctail); + taillinepts=ppval(tailline,supPtsFrames(1)-exttail:supPtsFrames(1)-1); + xy=[taillinepts xy]; + t=[supPtsFrames(1)-exttail:supPtsFrames(1)-1 torig]; + confs=[ones(1,exttail) confsorig]; + end + end + + if exthead + nhead=sortind(end-takenpts+1:end); + headpts=supportPts(nhead); + xyhead=[allpoints.xp(headpts);allpoints.yp(headpts)]; + thead=allpoints.tp(headpts); + chead=allpoints.sp(headpts); + if length(unique(thead))>2 + headline=splinefit(thead,xyhead,1,2,chead); + headlinepts=ppval(headline,supPtsFrames(end)+1:supPtsFrames(end)+exthead); + + xy=[xy headlinepts]; + t=[t supPtsFrames(end)+1:supPtsFrames(end)+exthead]; + confs=[confs ones(1,exthead)]; + end + end + end + end + + splineorder=4; + order=min(nSP,splineorder); + + + + trackLength(m)=supPtsFrames(end)-supPtsFrames(1); + ncps=max(minCPs,round(trackLength(m)*ncpsPerFrame)); + + tr=t+0.01*rand(1,length(t))-0.005; % add random noise to avoid NaN in fitting (LOOK INTO THIS!) + breaks=linspace(supPtsFrames(1),supPtsFrames(end),ncps); + xyy = xy+rand(size(xy)); + tryfit=splinefit(tr,xyy,mhsold.pieces,mhsold.order,confs); + + % force cubic spline + if order +randn('seed',1); %#ok + +%% declare global variables +global detections nPoints sceneInfo opt globiter +globiter = 0; +global LOG_allens LOG_allmets2d LOG_allmets3d %for debug output + +% fill options struct +opt = getDCOptionsDemo(); +opt.labelCost= 300; +opt.outlierCost= 200; +opt.unaryFactor= 1; +opt.pairwiseFactor= 100; +opt.goodnessFactor= 10; +opt.proxcostFactor= 0.0; +opt.nInitModels= 500; +opt.minCPs= 1; +opt.ncpsPerFrame= 1/50; +opt.totalSupFactor= 2; +opt.meanDPFFactor= 2; +opt.meanDPFeFactor= 2; +opt.curvatureFactor=0; +opt.tau = 25; % threshold (pixel) for spatio-temporal neighbors +opt.borderMargin = 250; % (pixel) % distance for persistence +opt.print = false; +opt.display = false; + +%% multi-object tracking +% fill scene info +sceneInfo = getSceneInfoDCDemo(curSequence); +frames = curSequence.frameNums; + +if(opt.visOptim) + reopenFig('optimization'); +end + +%% load detections +[detections, nPoints] = parseDetections(baselinedetections, frames); + +%% top image limit +sceneInfo.imTopLimit = min([detections(:).yi]); + +dcStartTime = tic; +T = size(detections,2); % length of sequence +stateInfo.F = T; +stateInfo.frameNums = frames; + +%% put all detections into a single vector +alldpoints = createAllDetPoints(detections); + +%% create spatio-temporal neighborhood graph +TNeighbors = getTemporalNeighbors(alldpoints); + +%% init solution +% generate initial spline trajectories +mhs = getSplineProposals(alldpoints,opt.nInitModels,T); + +%% get splines from EKF +for ekfexp = 1:5 + mhsekf = getSplinesFromEKF(fullfile('demo','ekf',sprintf('e%04d.mat',ekfexp)),frames,alldpoints,T); + mhs = [mhs mhsekf]; +end +nCurModels = length(mhs); +nInitModels = nCurModels; + +%% set initial labeling to all outliers +nCurModels = length(mhs); +nLabels = nCurModels+1; +outlierLabel = nLabels; +labeling = nLabels*ones(1,nPoints); % all labeled as outliers + +%% initialize labelcost +[splineGoodness, goodnessComp] = getSplineGoodness(mhs,1:opt.nInitModels,alldpoints,T); + +% unary is constant to outlierCost +Dcost = opt.outlierCost * ones(nLabels,nPoints); +Scost = opt.pairwiseFactor-opt.pairwiseFactor*eye(nLabels); +Lcost = getLabelCost(mhs); + +[inE, inD, inS, inL] = getGCO_Energy(Dcost, Scost, Lcost, TNeighbors, labeling); +bestE=inE; E=inE; D=inD; S=inS; L=inL; +printDCUpdate(stateInfo,mhs,[],0,0,0,D,S,L); + +%% first plot +drawDCUpdate(mhs,1:length(mhs),alldpoints,0,outlierLabel,TNeighbors,frames); + +nAddRandomModels = 10; % random models +nAddModelsOutliers = 10; +nAdded=0; nRemoved=0; + +%% start energy minimization loop +itcnt = 0; % only count one discrete-continuous cycle as one iteration +iteachcnt = 0; % count each discrete and each continuous optimization step +used = []; +mhsafterrefit = []; +while 1 + oldN = length(mhs); + for m = 1:length(mhs) + if(~isempty(intersect(m,used))) + mhs(m).lastused = 0; + else + mhs(m).lastused = mhs(m).lastused+1; + end + end + + mhs_ = mhs; + tokeep = find([mhs.lastused]<3); + mhs = mhs(tokeep); + + nRemoved = oldN-length(tokeep); + nCurModels = length(mhs); nLabels = nCurModels+1; outlierLabel = nLabels; + + % old labeling + l_ = labeling; + E_=E; D_=D; S_=S; L_=L; + + %% relabel + % minimize discrete Energy E(f), (Eq. 4) + Dcost = getUnarySpline(nLabels,nPoints,mhs,alldpoints,opt.outlierCost,opt.unaryFactor,T); + Lcost = getLabelCost(mhs); + Scost = opt.pairwiseFactor-opt.pairwiseFactor*eye(nLabels); + [E, D, S, L, labeling]=doAlphaExpansion(Dcost, Scost, Lcost, TNeighbors); + + % if new energy worse (or same), restore previous labeling and done + if E >= bestE + printMessage(2, 'Discrete Optimization did not find a lower energy\n'); + labeling = l_; + mhs = mhsafterrefit; + E = E_; D = D_; S = S_; L = L_; + nCurModels=length(mhs); nLabels=nCurModels+1; outlierLabel=nLabels; + used=setdiff(unique(labeling),outlierLabel); nUsed=numel(used); + break; + end + + % otherwise refit and adjust models + bestE = E; + itcnt = itcnt+1; + iteachcnt = iteachcnt+1; + outlierLabel = nLabels; + used = setdiff(unique(labeling),outlierLabel); nUsed = numel(used); + + % print update + drawDCUpdate(mhs,used,alldpoints,labeling,outlierLabel,TNeighbors,frames); + [m2d, m3d] = printDCUpdate(stateInfo,mhs,used,nAdded,nRemoved,iteachcnt,D,S,L); + LOG_allens(iteachcnt,:)=double([D S L]);LOG_allmets2d(iteachcnt,:)=m2d;LOG_allmets3d(iteachcnt,:)=m3d; + % now refit models (Eq. 1) + mhsbeforerefit = mhs; + mhsusedbeforerefit = mhs(used); + mhsnew = reestimateSplines(alldpoints,used,labeling,nLabels,mhs,Dcost,T); + mhsafterrefit = mhsnew; + Dcost = getUnarySpline(nLabels,nPoints,mhsnew,alldpoints,opt.outlierCost,opt.unaryFactor,T); + Lcost = getLabelCost(mhsnew); + Scost = opt.pairwiseFactor-opt.pairwiseFactor*eye(nLabels); + h = setupGCO(nPoints,nLabels,Dcost,Lcost,Scost,TNeighbors); + GCO_SetLabeling(h,labeling); + [E, D, S, L] = GCO_ComputeEnergy(h); + GCO_Delete(h); + mhs(used) = mhsnew(used); + nCurModels = length(mhs); + clear Scost Dcost Lcost + iteachcnt = iteachcnt+1; + % print update + drawDCUpdate(mhs,1:length(mhs),alldpoints,0,outlierLabel,TNeighbors,frames); + drawDCUpdate(mhs,used,alldpoints,labeling,outlierLabel,TNeighbors,frames); + printDCUpdate(stateInfo,mhs,used,nAdded,nRemoved,iteachcnt,D,S,L); + LOG_allens(iteachcnt,:)=double([D S L]);LOG_allmets2d(iteachcnt,:)=m2d;LOG_allmets3d(iteachcnt,:)=m3d; + %% Expand the hypothesis space + if(nCurModels4 + outlpts = selectPointsSubset(alldpoints,outlierPoints); + mhsnew = getSplineProposals(outlpts,nAddRandomModels,T); + mhs = [mhs mhsnew]; + end + %% extend existing + mhs = extendSplines(alldpoints,mhs,used,labeling,T,E); + %% merge existing + mhs = mergeSplines(alldpoints,mhs,used,labeling,T,E); + end + nCurModels = length(mhs); nLabels = nCurModels+1; outlierLabel = nLabels; + nAdded = nCurModels-length(mhsbeforerefit); +end + +% basically we are done +speed = stateInfo.F/toc(dcStartTime); + +%% final plot +drawDCUpdate(mhs,used,alldpoints,labeling,outlierLabel,TNeighbors,frames); +stateInfo = getStateFromSplines(mhs(used), stateInfo); +stateInfo = postProcessState(stateInfo); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/selectPointsSubset.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/selectPointsSubset.m new file mode 100644 index 0000000000000000000000000000000000000000..13f1a64d5f0e8e3b469c223c4d20cd58c8266726 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/selectPointsSubset.m @@ -0,0 +1,21 @@ +function outpts=selectPointsSubset(alldpoints,selection) +% TODO +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + + Field = fieldnames(alldpoints); + + for iField = 1:length(Field) + fcontent=alldpoints.(char(Field(iField))); + outpts.(char(Field(iField)))=fcontent(selection); + end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/setupGCO.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/setupGCO.m new file mode 100644 index 0000000000000000000000000000000000000000..4d6e8eff1eb49e09bce089e34c705be7c09e3798 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/setupGCO.m @@ -0,0 +1,24 @@ +function h=setupGCO(nPoints,nLabels,Dcost,Lcost,Scost,Neighborhood) +% set up and return handle for a GCO structure +% to be optimized via GCO alpha expansion +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + + +h = GCO_Create(nPoints,nLabels); +GCO_SetDataCost(h,int32(Dcost)); +GCO_SetLabelCost(h,int32(Lcost)); + +if ~isempty(Scost) && any(any(Scost)) + GCO_SetSmoothCost(h,int32(Scost)); + GCO_SetNeighbors(h,Neighborhood); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/splitSplines.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/splitSplines.m new file mode 100644 index 0000000000000000000000000000000000000000..901ab13e3ab4943f0f163bd96d7ad2b8dfb26e90 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/splitSplines.m @@ -0,0 +1,15 @@ +function mhsret=splitSplines(allpoints, mhs, used,labeling,T,E) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% TODO + +mhsnew=getEmptyModelStruct(); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/CLEAR_MOT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/CLEAR_MOT.m new file mode 100644 index 0000000000000000000000000000000000000000..623d2aded13f68804d9b4d4e56dc890bade2b522 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/CLEAR_MOT.m @@ -0,0 +1,334 @@ +function [metrics metricsInfo]=CLEAR_MOT(gtInfo,stateInfo,options) +% compute CLEAR MOT and other metrics +% +% metrics contains the following +% [1] recall - recall = percentage of detected targets +% [2] precision - precision = percentage of correctly detected targets +% [3] FAR - number of false alarms per frame +% [4] GT - number of ground truth trajectories +% [5-7] MT, PT, ML - number of mostly tracked, partially tracked and mostly lost trajectories +% [8] falsepositives- number of false positives (FP) +% [9] missed - number of missed targets (FN) +% [10] idswitches - number of id switches (IDs) +% [11] FRA - number of fragmentations +% [12] MOTA - Multi-object tracking accuracy in [0,100] +% [13] MOTP - Multi-object tracking precision in [0,100] (3D) / [td,100] (2D) +% [14] MOTAL - Multi-object tracking accuracy in [0,100] with log10(idswitches) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% default options: 2D +if nargin<3 + options.eval3d=0; % only bounding box overlap + options.td=.5; % threshold 50% +end + +if ~isfield(options,'td') + if options.eval3d + options.td=1000; + else + options.td=0.5; + end +end + +td=options.td; + +assert(length(gtInfo.frameNums)==length(stateInfo.frameNums), ... + 'Ground Truth and state must be of equal length'); +if(gtInfo.frameNums(1)~=stateInfo.frameNums(1)) + gtInfo.frameNums = gtInfo.frameNums + stateInfo.frameNums(1) - gtInfo.frameNums(1); +end +assert(all(gtInfo.frameNums==stateInfo.frameNums), ... + 'Ground Truth and state must contain equal frame numbers'); + +% check if all necessery info is available +if options.eval3d + assert(all(isfield(gtInfo,{'Xgp','Ygp'})), ... + 'Ground Truth Ground Plane coordinates needed for 3D evaluation'); + assert(all(isfield(stateInfo,{'Xgp','Ygp'})), ... + 'Ground Plane coordinates needed for 3D evaluation'); +else + assert(all(isfield(gtInfo,{'X','Y','W','H'})), ... + 'Ground Truth coordinates X,Y,W,H needed for 2D evaluation'); + assert(all(isfield(stateInfo,{'Xi','Yi','W','H'})), ... + 'State coordinates Xi,Yi,W,H needed for 2D evaluation'); + +end + +gtInd=~~gtInfo.X; +stInd=~~stateInfo.X; + +[Fgt Ngt]=size(gtInfo.X); +[F N]=size(stateInfo.X); + +aspectRatio=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% gtInfo.W=gtInfo.H*aspectRatio; + + +metricsInfo.names.long = {'Recall','Precision','False Alarm Rate', ... + 'GT Tracks','Mostly Tracked','Partially Tracked','Mostly Lost', ... + 'False Positives', 'False Negatives', 'ID Switches', 'Fragmentations', ... + 'MOTA','MOTP', 'MOTA Log'}; + +metricsInfo.names.short = {'Rcll','Prcn','FAR', ... + 'GT','MT','PT','ML', ... + 'FP', 'FN', 'IDs', 'FM', ... + 'MOTA','MOTP', 'MOTAL'}; + +metricsInfo.widths.long = [6 9 16 9 14 17 11 15 15 11 14 5 5 8]; +metricsInfo.widths.short = [5 5 5 3 3 3 3 4 4 3 3 5 5 5]; + +metricsInfo.format.long = {'.1f','.1f','.2f', ... + 'i','i','i','i', ... + 'i','i','i','i', ... + '.1f','.1f','.1f'}; + +metricsInfo.format.short=metricsInfo.format.long; + + +metrics=zeros(1,14); +metrics(9)=numel(find(gtInd)); % False Negatives (missed) +metrics(7)=Ngt; % Mostly Lost + +% nothing to be done, if state is empty +if ~N, return; end + +% global opt +% if options.eval3d && opt.mex +% [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% CLEAR_MOT_mex(gtInfo.Xgp', gtInfo.Ygp', stateInfo.Xgp', stateInfo.Ygp',options.td); +% +% % cd /home/aanton/diss/utils +% % [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% % CLEAR_MOT(gtInfo.Xgp, gtInfo.Ygp, stateInfo.Xgp, stateInfo.Ygp,options.td); +% % cd /home/aanton/visinf/projects/ongoing/contracking +% metrics=[rc*100, pc*100, faf, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FM, MOTA*100, MOTP*100, MOTAL*100]; +% metrics +% global gsi +% gsi=stateInfo; +% pause +% return; +% end + + +% mapping +M=zeros(F,Ngt); + +mme=zeros(1,F); % ID Switchtes (mismatches) +c=zeros(1,F); % matches found +fp=zeros(1,F); % false positives +m=zeros(1,F); % misses = false negatives +g=zeros(1,F); +d=zeros(F,Ngt); % all distances; +ious=Inf*ones(F,Ngt); % all overlaps + +matched=@matched2d; +if options.eval3d, matched=@matched3d; end + +alltracked=zeros(F,Ngt); +allfalsepos=zeros(F,N); + +for t=1:F + g(t)=numel(find(gtInd(t,:))); + + % mapping for current frame + if t>1 + mappings=find(M(t-1,:)); + for map=mappings + if gtInd(t,map) && stInd(t,M(t-1,map)) && matched(gtInfo,stateInfo,t,map,M(t-1,map),td*0.8) + M(t,map)=M(t-1,map); + end + end + end + + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + + if options.eval3d +% alldist=Inf*ones(Ngt,N); +% mindist=0; +% while mindist < td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 +% for o=GTsNotMapped +% GT=[gtInfo.Xgp(t,o) gtInfo.Ygp(t,o)]; +% for e=EsNotMapped +% E=[stateInfo.Xgp(t,e) stateInfo.Ygp(t,e)]; +% alldist(o,e)=norm(GT-E); +% end +% end +% [mindist, cind]=min(alldist(:)); +% if mindist <= td +% [u v]=ind2sub(size(alldist),cind); +% M(t,u)=v; +% alldist(:,v)=Inf; +% GTsNotMapped=find(~M(t,:) & gtInd(t,:)); +% EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); +% end +% end + + cost = zeros(numel(GTsNotMapped), numel(EsNotMapped)); + for o = 1:numel(GTsNotMapped) + GT = [gtInfo.Xgp(t,GTsNotMapped(o)), gtInfo.Ygp(t,GTsNotMapped(o))]; + for e = 1:numel(EsNotMapped) + E = [stateInfo.Xgp(t,EsNotMapped(e)), stateInfo.Ygp(t,EsNotMapped(e))]; + cost(o,e)=norm(GT-E); + end + end + cost(cost > td) = Inf; + assignLabel = munkres(cost); + for i = 1:numel(assignLabel) + if(assignLabel(i)) + M(t, GTsNotMapped(i)) = EsNotMapped(assignLabel(i)); + end + end + + else + allisects=zeros(Ngt,N); maxisect=Inf; + + while maxisect > td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 + for o=GTsNotMapped + GT=[gtInfo.X(t,o)-gtInfo.W(t,o)/2 ... + gtInfo.Y(t,o)-gtInfo.H(t,o) ... + gtInfo.W(t,o) gtInfo.H(t,o) ]; + for e=EsNotMapped + E=[stateInfo.Xi(t,e)-stateInfo.W(t,e)/2 ... + stateInfo.Yi(t,e)-stateInfo.H(t,e) ... + stateInfo.W(t,e) stateInfo.H(t,e) ]; + allisects(o,e)=boxiou(GT(1),GT(2),GT(3),GT(4),E(1),E(2),E(3),E(4)); + end + end + [maxisect cind]=max(allisects(:)); + + if maxisect >= td + [u v]=ind2sub(size(allisects),cind); + M(t,u)=v; + allisects(:,v)=0; + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + end + + end + end + + curtracked=find(M(t,:)); + + + alltrackers=find(stInd(t,:)); + mappedtrackers=intersect(M(t,find(M(t,:))),alltrackers); + falsepositives=setdiff(alltrackers,mappedtrackers); + + alltracked(t,:)=M(t,:); + allfalsepos(t,1:length(falsepositives))=falsepositives; + + %% mismatch errors + if t>1 + for ct=curtracked + lastnotempty=find(M(1:t-1,ct),1,'last'); + if gtInd(t-1,ct) && ~isempty(lastnotempty) && M(t,ct)~=M(lastnotempty,ct) + mme(t)=mme(t)+1; + end + end + end + + c(t)=numel(curtracked); + for ct=curtracked + eid=M(t,ct); + if options.eval3d + d(t,ct)=norm([gtInfo.Xgp(t,ct) gtInfo.Ygp(t,ct)] - ... + [stateInfo.Xgp(t,eid) stateInfo.Ygp(t,eid)]); + else + gtLeft=gtInfo.X(t,ct)-gtInfo.W(t,ct)/2; + gtTop=gtInfo.Y(t,ct)-gtInfo.H(t,ct); + gtWidth=gtInfo.W(t,ct); gtHeight=gtInfo.H(t,ct); + + stLeft=stateInfo.Xi(t,eid)-stateInfo.W(t,eid)/2; + stTop=stateInfo.Yi(t,eid)-stateInfo.H(t,eid); + stWidth=stateInfo.W(t,eid); stHeight=stateInfo.H(t,eid); + ious(t,ct)=boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight); + end + end + + + fp(t)=numel(find(stInd(t,:)))-c(t); + m(t)=g(t)-c(t); + + +end + +missed=sum(m); +falsepositives=sum(fp); +idswitches=sum(mme); + +if options.eval3d + MOTP=(1-sum(sum(d))/sum(c)/td) * 100; % avg distance to [0,100] +else + MOTP=sum(ious(ious>=td & ious0)); + if gtlength/gttotallength >= 0.8 && trlengtha/gttotallength < 0.2 + MTstatsa(i)=3; + elseif t>=find(gtInd(:,i),1,'last') && trlengtha/gttotallength <= 0.8 + MTstatsa(i)=2; + elseif trlengtha/gttotallength >= 0.8 + MTstatsa(i)=1; + end +end +% MTstatsa +MT=numel(find(MTstatsa==1));PT=numel(find(MTstatsa==2));ML=numel(find(MTstatsa==3)); + +%% fragments +fr=zeros(1,Ngt); +for i=1:Ngt + b=alltracked(find(alltracked(:,i),1,'first'):find(alltracked(:,i),1,'last'),i); + b(~~b)=1; + fr(i)=numel(find(diff(b)==-1)); +end +FRA=sum(fr); + +assert(Ngt==MT+PT+ML,'Hmm... Not all tracks classified correctly.'); +metrics=[recall, precision, FAR, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FRA, MOTA, MOTP, MOTAL]; +end + + + + +function ret=matched2d(gtInfo,stateInfo,t,map,mID,td) + gtLeft=gtInfo.X(t,map)-gtInfo.W(t,map)/2; + gtTop=gtInfo.Y(t,map)-gtInfo.H(t,map); + gtWidth=gtInfo.W(t,map); gtHeight=gtInfo.H(t,map); + + stLeft=stateInfo.Xi(t,mID)-stateInfo.W(t,mID)/2; + stTop=stateInfo.Yi(t,mID)-stateInfo.H(t,mID); + stWidth=stateInfo.W(t,mID); stHeight=stateInfo.H(t,mID); + + ret = boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight) >= td; +end + + +function ret=matched3d(gtInfo,stateInfo,t,map,mID,td) + Xgt=gtInfo.Xgp(t,map); Ygt=gtInfo.Ygp(t,map); + X=stateInfo.Xgp(t,mID); Y=stateInfo.Ygp(t,mID); + ret=norm([Xgt Ygt]-[X Y])<=td; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/boxIntersect.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/boxIntersect.m new file mode 100644 index 0000000000000000000000000000000000000000..5a55b45131c36980ad641f838452967a12bf300b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/boxIntersect.m @@ -0,0 +1,24 @@ +function isect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2) +% A=[bboxleft1 bboxbottom1 abs(bboxright1-bboxleft1) abs(bboxbottom1-bboxup1)]; +% B=[bboxleft2 bboxbottom2 abs(bboxright2-bboxleft2) abs(bboxbottom2-bboxup2)]; +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% isect=rectint(A,B); +isect=0; + +hor= max(0,min(bboxright1,bboxright2) - max(bboxleft1,bboxleft2)); + +if ~hor, return; end +ver= max(0,min(bboxbottom1,bboxbottom2) - max(bboxup1,bboxup2)); +if ~ver, return; end + +isect = hor*ver; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/boxUnion.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/boxUnion.m new file mode 100644 index 0000000000000000000000000000000000000000..c5b8e06c5ea242199dbffa15e553ec07b626fab9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/boxUnion.m @@ -0,0 +1,24 @@ +function union=boxUnion(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2,isect) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +a1=bboxright1-bboxleft1; +b1=bboxbottom1-bboxup1; +a2=bboxright2-bboxleft2; +b2=bboxbottom2-bboxup2; +union=a1*b1+a2*b2; +if nargin>8 + bisect=isect; +else + bisect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2); +end +union=union-bisect; + + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/boxiou.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/boxiou.m new file mode 100644 index 0000000000000000000000000000000000000000..395e5dc90d032ee2d7f3c9554148e56f908eeab5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/boxiou.m @@ -0,0 +1,21 @@ +function iou=boxiou(x1,y1,w1,h1,x2,y2,w2,h2) +% compute intersection over union of two bboxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + bisect=boxIntersect(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2); + iou=0; + if ~bisect, return; end + + bunion=boxUnion(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2,bisect); + + assert(bunion>0,'something wrong with union computation'); + iou=bisect/bunion; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/distortedToUndistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/distortedToUndistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..6e62dfbd4271580faef309647e42784c11964e31 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/distortedToUndistortedImageCoord.m @@ -0,0 +1,15 @@ +function [Xfu Yfu]=distortedToUndistortedImageCoord (Xfd, Yfd, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xd = mDpx * (Xfd - mCx) / mSx; + Yd = mDpy * (Yfd - mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ + [Xu Yu]=distortedToUndistortedSensorCoord(Xd, Yd, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfu = Xu * mSx / mDpx + mCx; + Yfu = Yu / mDpy + mCy; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/distortedToUndistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/distortedToUndistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..14158bd36e686650ae77a8621b1ed3c4d56e298a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/distortedToUndistortedSensorCoord.m @@ -0,0 +1,6 @@ +function [Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mKappa1) +% /* convert from distorted to undistorted sensor plane coordinates */ + distortion_factor = 1 + mKappa1 * (Xd*Xd + Yd*Yd); + Xu = Xd * distortion_factor; + Yu = Yd * distortion_factor; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/getRotTrans.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/getRotTrans.m new file mode 100644 index 0000000000000000000000000000000000000000..725097d307f8d0b7a1d211e756f99d82d45ebe1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/getRotTrans.m @@ -0,0 +1,34 @@ +function [mR mT]=getRotTrans(camPar) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + %%% Rotation Translation %%% + mT=[camPar.mExt.mTx;camPar.mExt.mTy;camPar.mExt.mTz]; + sa = sin(camPar.mExt.mRx); + ca = cos(camPar.mExt.mRx); + sb = sin(camPar.mExt.mRy); + cb = cos(camPar.mExt.mRy); + sg = sin(camPar.mExt.mRz); + cg = cos(camPar.mExt.mRz); + + mR11 = cb * cg; + mR12 = cg * sa * sb - ca * sg; + mR13 = sa * sg + ca * cg * sb; + mR21 = cb * sg; + mR22 = sa * sb * sg + ca * cg; + mR23 = ca * sb * sg - cg * sa; + mR31 = -sb; + mR32 = cb * sa; + mR33 = ca * cb; + + mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/imageToWorld.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/imageToWorld.m new file mode 100644 index 0000000000000000000000000000000000000000..3919cb798acbbeec7f826c6ea524dee3c3035476 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/imageToWorld.m @@ -0,0 +1,62 @@ +function [Xw Yw Zw]=imageToWorld(Xi, Yi, camPar) + +mGeo=camPar.mGeo; +mExt=camPar.mExt; +mInt=camPar.mInt; + +mTx=mExt.mTx; +mTy=mExt.mTy; +mTz=mExt.mTz; + +mT=[mExt.mTx;mExt.mTy;mExt.mTz]; + +%% internal init +sa = sin(mExt.mRx); +ca = cos(mExt.mRx); +sb = sin(mExt.mRy); +cb = cos(mExt.mRy); +sg = sin(mExt.mRz); +cg = cos(mExt.mRz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + + + +% /* convert from image to distorted sensor coordinates */ +Xd = mGeo.mDpx * (Xi - mInt.mCx) / mInt.mSx; +Yd = mGeo.mDpy * (Yi - mInt.mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ +[Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mInt.mKappa1); + +% /* calculate the corresponding xw and yw world coordinates */ +% /* (these equations were derived by simply inverting */ +% /* the perspective projection equations using Macsyma) */ +Zw=0; +common_denominator = ((mR11 * mR32 - mR12 * mR31) * Yu + ... + (mR22 * mR31 - mR21 * mR32) * Xu - ... + mInt.mFocal * mR11 * mR22 + mInt.mFocal * mR12 * mR21); + +Xw = (((mR12 * mR33 - mR13 * mR32) * Yu + ... + (mR23 * mR32 - mR22 * mR33) * Xu - ... + mInt.mFocal * mR12 * mR23 + mInt.mFocal * mR13 * mR22) * Zw + ... + (mR12 * mTz - mR32 * mTx) * Yu + ... + (mR32 * mTy - mR22 * mTz) * Xu - ... + mInt.mFocal * mR12 * mTy + mInt.mFocal * mR22 * mTx) / common_denominator; + +Yw = -(((mR11 * mR33 - mR13 * mR31) * Yu + ... + (mR23 * mR31 - mR21 * mR33) * Xu - ... + mInt.mFocal * mR11 * mR23 + mInt.mFocal * mR13 * mR21) * Zw + ... + (mR11 * mTz - mR31 * mTx) * Yu + ... + (mR31 * mTy - mR21 * mTz) * Xu - ... + mInt.mFocal * mR11 * mTy + mInt.mFocal * mR21 * mTx) / common_denominator; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/parseCameraParameters.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/parseCameraParameters.m new file mode 100644 index 0000000000000000000000000000000000000000..10baec4a50e7d06334ec9a16693a4ce178845580 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/parseCameraParameters.m @@ -0,0 +1,104 @@ +function camPar=parseCameraParameters(camconffile) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +xDoc=xmlread(fullfile(camconffile)); + +width=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('width')); +height=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('height')); + +ncx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('ncx')); +nfx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('nfx')); +dx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dx')); +dy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dy')); +dpx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpx')); +dpy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpy')); + +focal=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('focal')); +kappa1=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('kappa1')); +cx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cx')); +cy=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cy')); +sx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('sx')); + +tx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tx')); +ty=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ty')); +tz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tz')); +rx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rx')); +ry=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ry')); +rz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rz')); + +mGeo.mImgWidth = width; +mGeo.mImgHeight = height; +mGeo.mNcx = ncx; +mGeo.mNfx = nfx; +mGeo.mDx = dx; +mGeo.mDy = dy; +mGeo.mDpx = dpx; +mGeo.mDpy = dpy; + + +%% intrinsic +mInt.mFocal = focal; +mInt.mKappa1 = kappa1; +mInt.mCx = cx; +mInt.mCy = cy; +mInt.mSx = sx; + +%% extrinsic +mExt.mTx = tx; +mExt.mTy = ty; +mExt.mTz = tz; +mExt.mRx = rx; +mExt.mRy = ry; +mExt.mRz = rz; + +%% inverted +mT=[tx;ty;tz]; +sa = sin(rx); +ca = cos(rx); +sb = sin(ry); +cb = cos(ry); +sg = sin(rz); +cg = cos(rz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + +mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; + +transform=[mR mT;[0 0 0 1]]; +invtrans=inv(transform); +tx=invtrans(1,4);ty=invtrans(2,4);tz=invtrans(3,4); + +mExt.mTxi = tx; +mExt.mTyi = ty; +mExt.mTzi = tz; + +camPar.mExt=mExt; +camPar.mInt=mInt; +camPar.mGeo=mGeo; + +%% mkappa<0 +if kappa1<0 + warning('CAREFUL! kappa1 < 0, cam derivates are wrong!'); +end + +[camPar.mR camPar.mT]=getRotTrans(camPar); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/undistortedToDistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/undistortedToDistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..9c9f9a1382cfcbf25407f159a06cc73d4440c9a1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/undistortedToDistortedImageCoord.m @@ -0,0 +1,14 @@ +function [Xfd Yfd]=undistortedToDistortedImageCoord (Xfu, Yfu, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xu = mDpx * (Xfu - mCx) / mSx; + Yu = mDpy * (Yfu - mCy); + +% /* convert from undistorted sensor to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord(Xu, Yu, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfd = Xd * mSx / mDpx + mCx; + Yfd = Yd / mDpy + mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/undistortedToDistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/undistortedToDistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..b689d695a1a98a28a8ba414a7661fe9658d24403 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/undistortedToDistortedSensorCoord.m @@ -0,0 +1,67 @@ +function [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mKappa1) + +% global ifs elses + +if ((~Xu && ~Yu) || ~mKappa1) +% ifs(1)=ifs(1)+1; + Xd = Xu; + Yd = Yu; +else %% THIS ONE %% +% elses(1)=elses(1)+1; + Ru = sqrt(Xu*Xu + Yu*Yu); + + c = 1.0 / mKappa1; + d = -c * Ru; + + Q = c / 3; + R = -d / 2; + D = Q*Q*Q + R*R; + + if (D >= 0) %% THIS ONE %% +% ifs(2)=ifs(2)+1; + %/* one real root */ + D = sqrt(D); + if (R + D > 0) %% THIS ONE %% +% ifs(3)=ifs(3)+1; + S = (R + D)^ (1.0/3.0); + else +% elses(3)=elses(3)+1; + S = -(-R - D)^ (1.0/3.0); + end + if (R - D > 0) +% ifs(4)=ifs(4)+1; + T = (R - D)^(1.0/3.0); + else %% THIS ONE %% +% elses(4)=elses(4)+1; + T = -(D - R)^(1.0/3.0); + end + Rd = S + T; + + if (Rd < 0) + Rd = sqrt(-1.0 / (3 * mKappa1)); + % /*fprintf (stderr, "\nWarning: undistorted image point to distorted image point mapping limited by\n"); + % fprintf (stderr, " maximum barrel distortion radius of %lf\n", Rd); + % fprintf (stderr, " (Xu = %lf, Yu = %lf) -> (Xd = %lf, Yd = %lf)\n\n", Xu, Yu, Xu * Rd / Ru, Yu * Rd / Ru);*/ + end + else +% elses(2)=elses(2)+1; + % /* three real roots */ + D = sqrt(-D); + S = ( sqrt(R*R + D*D))^(1.0/3.0 ); + T = atan2(D, R) / 3; + sinT = sin(T); + cosT = cos(T); + + % /* the larger positive root is 2*S*cos(T) */ + % /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ + % /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ + + Rd = -S * cosT + sqrt(3.0) * S * sinT; % /* use the smaller positive root */ + end + + lambda = Rd / Ru; + + Xd = Xu * lambda; + Yd = Yu * lambda; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/worldToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/worldToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..8bb11eb8cfff82e0e805c07f7f22d5e81042b241 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/camera/worldToImage.m @@ -0,0 +1,28 @@ +function [Xi Yi]=worldToImage(Xw,Yw,Zw,mR,mT,mInt,mGeo) + + + % /* convert from world coordinates to camera coordinates */ + x=[mR mT]*[Xw;Yw;Zw;1]; + xc = x(1); + yc = x(2); + zc = x(3); + + % /* convert from camera coordinates to undistorted sensor plane coordinates */ + Xu = mInt.mFocal * xc / zc; + Yu = mInt.mFocal * yc / zc; + + % /* convert from undistorted to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mInt.mKappa1); + % Xd=Xu; + % Yd=Yu; + + % Rusq=Xu*Xu+Yu*Yu; + % Ru=sqrt(Xu*Xu+Yu*Yu); + % Xd=Xu*(1+mInt.mKappa1*Rusq); + % Yd=Yu*(1+mInt.mKappa1*Rusq); + + + % /* convert from distorted sensor plane coordinates to image coordinates */ + Xi = Xd * mInt.mSx / mGeo.mDpx + mInt.mCx; + Yi = Yd / mGeo.mDpy + mInt.mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/checkInitSolution.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/checkInitSolution.m new file mode 100644 index 0000000000000000000000000000000000000000..2c804a3311ac0367686b89db9d6c9864a4856c0c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/checkInitSolution.m @@ -0,0 +1,22 @@ +function [Xinit Yinit]=checkInitSolution(Xinit,Yinit,F) +% check if initial solution is correct +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + assert(all(size(Xinit)==size(Yinit)), ... + 'X and Y are of different size in initial solution'); + + % pad with zeros if not enough frames + Finit=size(Xinit,1); + if FinitareaLimits(2))=0;Ygp(Ygp>areaLimits(4))=0; +Ygp(Xgp==0)=0; Xgp(Ygp==0)=0; + +allzeros=(Xgp == 0 | Ygp ==0); +gtInfo.X(allzeros)=0;gtInfo.Y(allzeros)=0; +gtInfo.W(allzeros)=0;gtInfo.H(allzeros)=0; +gtInfo.Xgp(allzeros)=0;gtInfo.Ygp(allzeros)=0; + +% now clean up zero columns +gtInfo=cleanGT(gtInfo); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/cutStateToTrackingArea.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/cutStateToTrackingArea.m new file mode 100644 index 0000000000000000000000000000000000000000..977d2e957af687926552ce27c94bcb207992f6b8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/cutStateToTrackingArea.m @@ -0,0 +1,28 @@ +function stateInfo=cutStateToTrackingArea(stateInfo) +% if we are tracking on ground plane +% remove all track segments outside tracking area +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo; + +X=stateInfo.X; Y=stateInfo.Y; +areaLimits=sceneInfo.trackingArea; + +X(XareaLimits(2))=0;Y(Y>areaLimits(4))=0; +Y(X==0)=0; X(Y==0)=0; + +% now clean up zero columns +[X Y stateInfo]=cleanState(X,Y,stateInfo); + +stateInfo.X=X; stateInfo.Y=Y; + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..9068d48fdf2e5ebc45546a2ea6631ec363810209 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayBBoxes.m @@ -0,0 +1,205 @@ +function displayBBoxes(sceneInfo,frameNums,X,Y,W,H,options) +% Draw bounding boxes on top of images +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% +[F,~]=size(X); + +ind=find(W); +aspectRatio=mean(H(ind)./W(ind)); + +%% if we want to display traces, lets compute average image +% or let's not... Doesn't look good, anyway + +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(1))]); +% avim=zeros(size(im)); +% avgF=1:5:min(500,F); +% avgnF=length(avgF); +% for t=avgF +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]); +% avim=avim+double(im)/avgnF; +% end +% avim=avim/255; + +global opt; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + al=0.5; + load(sceneInfo.bgMask); + immask=cat(3,bgmask,bgmask,bgmask); + + end + +for t=1:F + clf + im=double(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]))/255; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + imgray=rgb2gray(im); imgray=imgray+0.5; + imgray=cat(3,imgray,imgray,imgray); + im(immask)=al*im(immask)+(1-al)*(imgray(immask)); + end + + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % tracking area + if opt.track3d && opt.cutToTA + drawTALimits; + end + + + extar=find(X(t,:)); + % foot position + if options.displayDots + for id=extar + plot(X(t,id),Y(t,id),'.','color',getColorFromID(id),'MarkerSize',options.dotSize); + end + end + + % box + if options.displayBoxes + for id=extar + bleft=X(t,id)-W(t,id)/2; + bright=X(t,id)+W(t,id)/2; + btop=Y(t,id)-H(t,id); + bbottom=Y(t,id); +% line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',getColorFromID(id),'linewidth',options.boxLineWidth); + rectangle('Position',[bleft,btop,W(t,id),H(t,id)],'Curvature',[.3,.3*(W(t,id)/H(t,id))],'EdgeColor',getColorFromID(id),'linewidth',options.boxLineWidth); + end + end + + % ID + if options.displayID + for id=extar + tx=X(t,id); + ty=Y(t,id)-H(t,id)*2/3; % inside +% ty=Y(t,id)-H(t,id)-10; % on top + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',W(t,id)/2, 'FontUnits','pixels','FontWeight','bold'); + end + end + + % cropouts + if options.displayCropouts + bw=2; %border cropouts + + %% crop outs var sized + maxTar=30; + extarRed=extar(extar<=maxTar); % reducde +% crpImg=zeros(round(max(max(H))+5),round(sum(max(W))+5*bw),3); +% offset=1; +% offsets=round([1 cumsum(max(W))]); +% for id=extarRed +% % offsets(id)=offset; +% offset=offsets(id); +% bleft=round(X(t,id)-W(t,id)/2); +% bright=round(X(t,id)+W(t,id)/2); +% btop=round(Y(t,id)-H(t,id)); +% bbottom=round(Y(t,id)); +% +% ht=(bbottom-btop)+1;wt=(bright-bleft)+1; +% crpImg(1:ht,offset:offset+wt-1,:)=im(btop:bbottom,bleft:bright,:); +% % offset=offset+wt+bw; +% end + + %% crop outs fixed sized + uniH=min(60,round(sceneInfo.imgHeight/10)); uniW=round(uniH/aspectRatio); +% crpImg=zeros(round(uniH+bw),round(uniW*size(W,2)+bw*size(W,2)),3); % black + mxfac=.5; + crpImg=im(1:uniH,1:min(sceneInfo.imgWidth,round(uniW*size(W,2)+bw*size(W,2))),:)*mxfac; + crpImg=crpImg + (1-mxfac)*ones(size(crpImg)); % bleeched + for id=extarRed + offset=(id-1)*uniW + (id-1)*bw+1; + bleft=round(X(t,id)-W(t,id)/2); + bright=round(X(t,id)+W(t,id)/2); + btop=round(Y(t,id)-H(t,id)); + bbottom=round(Y(t,id)); + + [bleft bright btop bbottom]= ... + clampBBox(bleft, bright, btop, bbottom, sceneInfo.imgWidth, sceneInfo.imgHeight); + ht=uniH; + imres=imresize(im(btop:bbottom,bleft:bright,:),[uniH uniW]); + crpImg(1:ht,offset:offset+uniW-1,:)=imres; + + end + imshow(crpImg); + + for id=extarRed +% tx=offsets(id)+W(t,id)/2; + tx=id*uniW-uniW/2 + id*bw; + ty=30; % top + ty=size(crpImg,1)-10; % below + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',uniW/2, 'FontUnits','pixels','FontWeight','bold'); % fixed size +% 'FontSize',mean(W(t,extarRed))/2, 'FontUnits','pixels','FontWeight','bold'); % var size + + end + if options.displayConnections + for id=extarRed + if t-find(X(:,id),1,'first')<5 + btop=round(Y(t,id)-H(t,id)); + offset=(id-1)*uniW + (id-1)*bw+1 + uniW/2; + line([X(t,id) offset],[btop uniH],'color',getColorFromID(id),'linestyle','-'); + end + end + end + end + + % show trace + if options.traceLength + for tracet=max(1,t-options.traceLength):max(1,t-1) + ipolpar=(t-tracet)/options.traceLength; % parameter [0,1] for color adjustment + + % pick color from tail +% if tracet==max(1,t-options.traceLength) +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(tracet))]); +% end + + extarpast=find(X(tracet,:)); + % foot position + for id=extarpast + % plot(X(tracet,id),Y(tracet,id), ... + % '.','color',ipolpar*options.grey + (1-ipolpar)*getColorFromID(id),'MarkerSize',max(1,options.dotSize*(1-ipolpar))); + + + if W(tracet+1,id) + posx=round(max(1,X(t,id))); posx=min(sceneInfo.imgWidth,posx); + posy=round(max(1,Y(t,id))); posy=min(sceneInfo.imgHeight,posy); +% endcol=double(reshape(avim(posy,posx,:),1,3)); +% endcol=min(1,endcol); endcol=max(1,endcol); + endcol=options.grey; + line(X(tracet:tracet+1,id) ,Y(tracet:tracet+1,id), ... + 'color',ipolpar*endcol + (1-ipolpar)*getColorFromID(id),'linewidth',(1-ipolpar)*options.traceWidth+1); + end + + end + + end + end + + + pause(options.framePause) + + % save + if isfield(options,'outFolder'); + im2save=getframe(gcf); + im2save=im2save.cdata; + imwrite(im2save, fullfile(options.outFolder,sprintf('frame_%04d.jpg',frameNums(t)))); + end + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayDetectionBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayDetectionBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..85a14f52b9a012f72c0909b95491270609907826 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayDetectionBBoxes.m @@ -0,0 +1,81 @@ +function displayDetectionBBoxes(sceneInfo, detections) +% Display Detection Bounding Boxes +% +% Take scene information sceneInfo and +% an array of detections and display +% them on +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +reopenFig('Detections') + +F=size(detections,2); +assert(F==length(sceneInfo.frameNums), 'length of detections must be equal to the number of frames'); + +detcol=[.1 .2 .9]; +grey=.6*ones(1,3); +framePause=0.01; % pause between frames +% framePause=1; + +traceLength=10; % overlay data from past 10 frames +dotSize=20; +boxLineWidth=3; + +for t=1:F + clf + im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(t))]); + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % foot position + for k=1:length(detections(t).xp) + plot(detections(t).xp(k),detections(t).yp(k),'.','color',detcol,'MarkerSize',dotSize*detections(t).sc(k)); + end + + % box + nboxes=length(detections(t).xp); + for id=1:nboxes + bleft=detections(t).bx(id); + bright=detections(t).bx(id)+detections(t).wd(id); + btop=detections(t).by(id); + bbottom=detections(t).by(id)+detections(t).ht(id); + line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',detcol,'linewidth',boxLineWidth*detections(t).sc(id)); + end + + % show trace + for tracet=max(1,t-traceLength):max(1,t-1) + ipolpar=(t-tracet)/traceLength; % parameter [0,1] for color adjustment + + % foot position + for k=1:length(detections(tracet).xp) + plot(detections(tracet).xi(k),detections(tracet).yi(k), ... + '.','color',ipolpar*grey + (1-ipolpar)*detcol,'MarkerSize',dotSize*detections(tracet).sc(k)); + end + + % box +% nboxes=length(detections(tracet).xp); +% for id=1:nboxes +% bleft=detections(tracet).xp(id)-detections(tracet).wd(id)/2; +% bright=detections(tracet).xp(id)+detections(tracet).wd(id)/2; +% btop=detections(tracet).yp(id)-detections(tracet).ht(id); +% bbottom=detections(tracet).yp(id); +% line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',ipolpar*grey + (1-ipolpar)*detcol); +% end + + end + + pause(framePause) + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayGroundTruth.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayGroundTruth.m new file mode 100644 index 0000000000000000000000000000000000000000..4135ebf073c38772bf347eb1f08f4a32ee9da49e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayGroundTruth.m @@ -0,0 +1,42 @@ +function displayGroundTruth(sceneInfo, gtInfo) +% Display Ground Truth +% +% Take scene information sceneInfo and +% the ground truth from gtInfo +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +W=gtInfo.W; +H=gtInfo.H; + + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.01; % pause between frames + +options.traceLength=20; % overlay data from past 10 frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +X=gtInfo.X; Y=gtInfo.Y; + +reopenFig('Ground Truth'); +displayBBoxes(sceneInfo,gtInfo.frameNums,X,Y,W,H,options) + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayTrackingResult.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayTrackingResult.m new file mode 100644 index 0000000000000000000000000000000000000000..83597c454e93ecbce07b434c3c51de8295834caa --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/displayTrackingResult.m @@ -0,0 +1,47 @@ +function displayTrackingResult(sceneInfo, stateInfo) +% Display Tracking Result +% +% Take scene information sceneInfo and +% the tracking result from stateInfo +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% [~, ~, ~, ~, X Y]=getStateInfo(stateInfo); +W=stateInfo.W; +H=stateInfo.H; +Xi=stateInfo.Xi; +Yi=stateInfo.Yi; + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.001; % pause between frames + +options.traceLength=20; % overlay track from past n frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +% save? +% options.outFolder='tmp'; + +reopenFig('Tracking Results') +displayBBoxes(sceneInfo,stateInfo.frameNums,Xi,Yi,W,H,options) + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/drawTALimits.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/drawTALimits.m new file mode 100644 index 0000000000000000000000000000000000000000..dafde616beee5dd1e9e9b4561ea00ce312b4f616 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/drawTALimits.m @@ -0,0 +1,36 @@ +function drawTALimits +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo + +c1=sceneInfo.trackingArea([1 3]); +c2=sceneInfo.trackingArea([2 3]); +c3=sceneInfo.trackingArea([2 4]); +c4=sceneInfo.trackingArea([1 4]); + + +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); + +[slx sly]=worldToImage(c1(1),c1(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(1)=slx; y(1)=sly; + +[slx sly]=worldToImage(c2(1),c2(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(2)=slx; y(2)=sly; + +[slx sly]=worldToImage(c3(1),c3(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(3)=slx; y(3)=sly; + +[slx sly]=worldToImage(c4(1),c4(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(4)=slx; y(4)=sly; + +line([x x(1)],[y y(1)],'linewidth',2,'color','w','linestyle','--'); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/estimateTargetsSize.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/estimateTargetsSize.m new file mode 100644 index 0000000000000000000000000000000000000000..6b980d7429d28c68ee11eae25b7ad1fb956edc42 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/estimateTargetsSize.m @@ -0,0 +1,53 @@ +function htobj=estimateTargetsSize(sceneInfo) +% Take best n percent of detections +% and fit a 2d surface through their heights +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +npercent = 25; % best 25 % + +% scenario=41; + +% sceneInfo=getSceneInfo(scenario); +detections=parseDetections(sceneInfo); +allxi=[];allxi=[];allyi=[];allsc=[];allht=[]; + +F=length(detections); +for t=1:F + allxi=[allxi detections(t).xi]; + allyi=[allyi detections(t).yi]; + allsc=[allsc detections(t).sc]; + allht=[allht detections(t).ht]; +end +minheight=15; +% goodones=find(allsc>0.75); % confident ones + +[allsc goodones]=sort(allsc,'descend'); goodones=goodones(1:round(length(goodones)/(1/npercent*100))); + +allxi=allxi(goodones);allyi=allyi(goodones);allsc=allsc(goodones);allht=allht(goodones); +htobj=fit([allxi; allyi]',allht','poly21','Robust','on'); + +% %% +% clf +% +% plot3(allxi,allyi,allht,'.'); box on +% xlim(sceneInfo.trackingArea(1:2));ylim(sceneInfo.trackingArea(3:4)); zlim([minheight sceneInfo.imgHeight]); +% set(gca,'Ydir','reverse'); +% +% hold on +% +% %% +% +% %% +% [xi yi]=meshgrid(1:50:sceneInfo.imgWidth, 1:50:sceneInfo.imgHeight); +% htsurface=feval(fitobj,xi(:),yi(:)); htsurface=reshape(htsurface,size(xi,1),size(xi,2)); +% htsurface(htsurfacesceneInfo.imgHeight)=sceneInfo.imgHeight; +% surf(xi,yi,htsurface) +% view(-78,34) \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/evaluateDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/evaluateDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..434bc96a586ea76a1c6195bd0d5a5d8572e5e8cc --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/evaluateDetections.m @@ -0,0 +1,28 @@ +function evaluateDetections(detMatrices,gtInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt +if sceneInfo.gtAvailable + detInfo=detMatrices; detInfo.frameNums=sceneInfo.frameNums; + detInfo.X=detInfo.Xi; detInfo.Y=detInfo.Yi; + [detInfo.F detInfo.N]=size(detInfo); + + if opt.track3d + detInfo=cutStateToTrackingArea(detInfo); +% gtInfo=cutGTToTrackingArea(gtInfo); + end + + printMessage(1,'\nDetections Evaluation (2D):\n'); + [metrics metricsInfo]=CLEAR_MOT(gtInfo,detInfo,struct('eval3d',0)); + printMetrics(metrics,metricsInfo,1,[1 2 3 8 9]); + printMessage(1,'\n'); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getBBoxesFromPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getBBoxesFromPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..fa0582c8ec7ae435a635a20df52d55f93d3b0f1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getBBoxesFromPrior.m @@ -0,0 +1,79 @@ +function stateInfo=getBBoxesFromPrior(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% just take the height prior for that +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo +% [~, N F targetsExist X Y]=getStateInfo(stateInfo); +X=stateInfo.X; Y=stateInfo.Y; + +[F N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + H=heightPrior; +else + error('sorry dude'); +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +% if sceneInfo.gtAvailable +% global gtInfo +% arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% aspectRatio= arithmean; +% end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +% stateInfo.W=H*sceneInfo.targetAR; % or take data set mean +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getBBoxesFromState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getBBoxesFromState.m new file mode 100644 index 0000000000000000000000000000000000000000..b34595c4288fa888f76fb0cd0545d220eef643f7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getBBoxesFromState.m @@ -0,0 +1,206 @@ +function stateInfo=getBBoxesFromState(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% To this end, we check for corresponding detections +% and interpolate them to get the solution boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo +% [~, N F targetsExist X Y]=getStateInfo(stateInfo); +X=stateInfo.X; Y=stateInfo.Y; + +[F N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + + +for id=1:N + sid=targetsExist(id,1); + eid=targetsExist(id,2); + frames=sid:eid; + asscDet=zeros(1,F); % which detection is close by? + widths=zeros(1,F); + heights=zeros(1,F); + scores=zeros(1,F); + + % find closest detections + for t=frames + ndets=length(detections(t).xp); % how many dets in this frame + if ndets + xy=[X(t,id); Y(t,id)]; + dets=[detections(t).xp; detections(t).yp]; + + alldist=sqrt(sum((repmat(xy,1,ndets)-dets).^2)); % distance to all + [mindist mindet]=min(alldist); + if mindist<=sceneInfo.targetSize + asscDet(t)=mindet; + widths(t)=detections(t).wd(mindet); + heights(t)=detections(t).ht(mindet); + scores(t)=detections(t).sc(mindet); + end + end + end + detsAssc=find(asscDet); % which detections associated + detsAsscWobble=detsAssc;%+0.01*rand(1,length(t))-0.005; % add random noise to avoid NaN in fitting (LOOK INTO THIS!) + + if numel(unique(detsAssc))>1 + polydeg=min(9,max(1,floor(numel(detsAssc)/100))); + polystr=sprintf('poly%d',polydeg); + +% global gdetsAssc gwidths +% gdetsAssc=detsAssc; gwidths=widths(detsAssc); +% detsAssc +% unique(detsAssc) +% heights(detsAssc) +% numel(detsAssc) +% +% polydeg +% +% polystr +% p=polyfit(detsAssc,widths(detsAssc),max(1,floor(numel(detsAssc)/100))); +% p=fit(detsAssc',widths(detsAssc)',polystr,'Normalize','on','Robust','on'); + +% ipolwidths = polyval(p,frames); +% ipolwidths = feval(p,frames); +% W((sid:eid)',id)=ipolwidths'; + + + + + +% +% +% numel(detsAssc) +% p=polyfit(detsAssc,heights(detsAssc),max(1,round(numel(detsAssc)/100))); +% [p,~,~,~]=fit(detsAssc',heights(detsAssc)',polystr,'Normalize','on','Robust','on'); + sp=splinefit(detsAsscWobble, heights(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); +% pause + +% ipolheights = polyval(p,frames); +% ipolheights = feval(p,frames); + ipolheights=ppval(sp,frames); + + + H((sid:eid)',id)=ipolheights'; + + if ~isfield(sceneInfo,'targetAR') % if no aspect ratio given, estimate widths +% [p,~,~,~]=fit(detsAssc',widths(detsAssc)',polystr,'Normalize','on','Robust','on'); + sp=splinefit(detsAsscWobble, widths(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); +% ipolwidths = feval(p,frames); + ipolwidths = ppval(sp,frames); + + W((sid:eid)',id)=ipolwidths'; + + end + + else % strange trajectory with < 3 detections + detwidthmean=[]; detheightmean=[]; +% sid +% eid + for t=sid:eid + detwidthmean=[detwidthmean mean(detections(t).wd)]; + detheightmean=[detheightmean mean(detections(t).ht)]; + end +% detwidthmean +% detheightmean + detwidthmean(isnan(detwidthmean))=mean(detwidthmean(~isnan(detwidthmean))); + detheightmean(isnan(detheightmean))=mean(detheightmean(~isnan(detheightmean))); +% detwidthmean +% detheightmean + W((sid:eid)',id)=detwidthmean; + H((sid:eid)',id)=detheightmean; + end + + + +% detsAsscWobble +% +% detsAssc +% unique(detsAssc) +% heights(detsAssc) +% numel(detsAssc) +% +% clf +% hold on +% % size(frames) +% % size(ipolwidths) +% plot(detsAssc,heights(detsAssc),'o') +% plot(frames,ipolheights,'r') +% plot(frames,ppval(sp,frames),'k'); +% +% % global HP +% % plot(frames,HP((sid:eid)',id),'--'); +% +% % plot(frames,lincomb,':'); +% +% % size(sid:eid) +% % size(ipolheights) +% pause + + +end + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + prwght=.8; + H=(1-prwght)*H + prwght*heightPrior; + +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +if sceneInfo.gtAvailable + global gtInfo + arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); + aspectRatio= arithmean; +end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getColorFromID.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getColorFromID.m new file mode 100644 index 0000000000000000000000000000000000000000..9ac27b6f3f79c5891348d2e7bf365d61620f6fc7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getColorFromID.m @@ -0,0 +1,32 @@ +function col=getColorFromID(id) + % get rgb [0,1] values from id +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + colors=getIDColors; + col=colors((mod(id,size(colors,1)))+1,:); +end + +function colors=getIDColors() +colors=[ + 128 255 255; % + 255 0 0; % red 1 + 0 255 0; % green 2 + 0 0 255; % blue 3 + 0 255 255; % cyan 4 + 255 0 255; % magenta 5 + 212 212 0; % yellow 6 + 25 25 25; % black 7 + 34,139,34; % forestgreen 8 + 0,191,255; % deepskyblue 9 + 139,0,0 ; % darkred 10 + 218,112,214; % orchid 11 + 244,164,96 ;]; % sandybrown 12 +colors = colors / 255; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getDetectionMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getDetectionMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..ccf365e0f6df009aa59c17e676dd0af9cec0c320 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getDetectionMatrices.m @@ -0,0 +1,36 @@ +function detMat = getDetectionMatrices(detections) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=length(detections); +Xd=zeros(F,0); +Yd=zeros(F,0); +Sd=zeros(F,0); + +Xi=zeros(F,0); +Yi=zeros(F,0); +W=zeros(F,0); +H=zeros(F,0); +for t=1:length(detections); + Dt=length(detections(t).xp); + Xd(t,1:Dt)=detections(t).xp; + Yd(t,1:Dt)=detections(t).yp; + Sd(t,1:Dt)=detections(t).sc; + + Xi(t,1:Dt)=detections(t).xi; + Yi(t,1:Dt)=detections(t).yi; + W(t,1:Dt)=detections(t).wd; + H(t,1:Dt)=detections(t).ht; +end + +detMat.Xd=Xd; +detMat.Yd=Yd; +detMat.Sd=Sd; + +detMat.Xi=Xi;detMat.Yi=Yi;detMat.W=W;detMat.H=H; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getHeightPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getHeightPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..0f0cf37058d32fb215ae0b6b3265328d9c4f47f1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getHeightPrior.m @@ -0,0 +1,42 @@ +function heightPrior=getHeightPrior(stateInfo) +% for 3d tracking we can compute +% an approximate average bounding box for each target +% which corresponds to a height of 1.70 m in the world +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global sceneInfo +camPar=sceneInfo.camPar; + +% rx=camPar.mExt.mRx;ry=camPar.mExt.mRy;rz=camPar.mExt.mRz; +% tx=camPar.mExt.mTx;ty=camPar.mExt.mTy;tz=camPar.mExt.mTz; +% txi=camPar.mExt.mTxi;tyi=camPar.mExt.mTyi;tzi=camPar.mExt.mTzi; +% kappa=camPar.mInt.mKappa1; focal=camPar.mInt.mFocal;Sx=camPar.mInt.mSx; +% Dpx=camPar.mGeo.mDpx;Dpy=camPar.mGeo.mDpy; + +% [mR mT]=getRotTrans(sceneInfo.camPar); + +% feet +Z=0*ones(size(stateInfo.Xgp)); +[Xi0 Yi0]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +% heads +Z=1700*ones(size(stateInfo.Xgp)); +[XiH YiH]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +heightPrior=Yi0-YiH; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getHomeFolder.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getHomeFolder.m new file mode 100644 index 0000000000000000000000000000000000000000..73c516d61d583341e7938351ddd12e1c9de04ad0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getHomeFolder.m @@ -0,0 +1,18 @@ +function homedir=getHomeFolder() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + homedir='/home/aanton'; + if ispc + homedir='D:'; + end + if exist('/gris/gris-f/home/aandriye','dir') + homedir='/gris/gris-f/home/aandriye'; + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..35b13964f06515bc0f4136d073d0ef57755314fb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/getSceneInfo.m @@ -0,0 +1,526 @@ +function sceneInfo=getSceneInfo(scenario) +% fill all necessary information about the +% scene into the sceneInfo struct +% +% Required: +% detfile detections file (.idl or .xml) +% frameNums frame numbers (eg. frameNums=1:107) +% imgFolder image folder +% imgFileFormat format for images (eg. frame_%04d.jpg) +% targetSize approx. size of targets (default: 5 on image, 350 in 3d) +% +% Required for 3D Tracking only +% trackingArea tracking area +% camFile camera calibration file (.xml PETS format) +% +% Optional: +% gtFile file with ground truth bounding boxes (.xml CVML) +% initSolFile initial solution (.xml or .mat) +% targetAR aspect ratio of targets on image +% bgMask mask to bleach out the background +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt +% opt=getOptions; +% general folders +homefolder=getHomeFolder; +dbfolder=fullfile(filesep,'storage','databases'); if ispc, dbfolder=fullfile('D:','storage','databases'); end +if exist('/gris','dir'), dbfolder=fullfile(filesep,'gris','takatuka_dbases'); end + +% detection file +switch(scenario) + case {23,25,27,70,71,72,73,74,75,80} + dataset='PETS2009'; + case {40,41,42} + dataset='TUD'; + case {30,31,32,35,36,37} + dataset='TUD10'; + case {50,51,52,53} + dataset='ETH-Person'; + case {60,61,62} + dataset='AVSS'; + case {48} + dataset='UBC'; + case {90,91,92} + dataset='DA-ELS'; + otherwise + error('unknown scenario'); +end + +% sequence name +switch(scenario) + case 23 + seqname='PETS2009-S2L1-c1'; + case 25 + seqname='PETS2009-S2L2-c1'; + case 27 + seqname='PETS2009-S2L3-c1'; + case 31 + seqname='TUD10-ped1-c1'; + case 32 + seqname='TUD10-ped1-c2'; + case 36 + seqname='TUD10-ped1-c1'; + case 37 + seqname='TUD10-ped2-c2'; + case 40 + seqname='TUD-Campus'; + case 41 + seqname='TUD-Crossing'; + case 42 + seqname='TUD-Stadtmitte'; + case 48 + seqname='Hockey'; + case {50,51,52,53} + seqname=sprintf('seq%02d',scenario-50); + case 60 + seqname='AB_Easy'; + case 61 + seqname='AB_Medium'; + case 62 + seqname='AB_Hard'; + case 70 + seqname='PETS2009-S1L1-1-c1'; + case 71 + seqname='PETS2009-S1L1-2-c1'; + case 72 + seqname='PETS2009-S1L2-1-c1'; + case 73 + seqname='PETS2009-S1L2-2-c1'; + case 74 + seqname='PETS2009-S1L3-1-c1'; + case 75 + seqname='PETS2009-S1L3-2-c1'; + case 80 + seqname='PETS2009-S3MF1-c1'; + case {90,91,92,93,94} + seqname=sprintf('s%02d',scenario-90); + otherwise + + error('unknown scenario'); +end + +% frameNums +switch(scenario) + case 20 % terrace1 + sceneInfo.frameNums=1:2000; + case 21 % terrace2 + sceneInfo.frameNums=1:2000; + case {22,23} % PETS 2009 S2 L1 + sceneInfo.frameNums=0:794; + case 24 % PETSMONO occlusion + sceneInfo.frameNums=0:794; + case 25 + sceneInfo.frameNums=0:435; + case 27 + sceneInfo.frameNums=0:239; + case {30,31,32,33} % TUD10 ped + sceneInfo.frameNums=1:1400; + % sceneInfo.frameNums=1:300; + case {35,36,37} % TUD10 ped2 + sceneInfo.frameNums=1:1999; + % sceneInfo.frameNums=1:199; + % sceneInfo.frameNums=1670:1680; + % sceneInfo.frameNums=760:770; + case 40 % tud-campus + sceneInfo.frameNums=90:160; + case {41,44} % tud-crossing + sceneInfo.frameNums=1:201; + case 42 % tud-stadtmitte + sceneInfo.frameNums=7022:7200; + % sceneInfo.frameNums=7022:7100; + case 45 % eth central xing1 + sceneInfo.frameNums=1600:2200; + case 46 % eth central xing1 + sceneInfo.frameNums=3300:3600; + case 47 % eth central xing1 + sceneInfo.frameNums=7433:7811; + case 48 % UBC Hockey + sceneInfo.frameNums=700:800; + case 50 % ETH Person seq0 + sceneInfo.frameNums=180:678; + case 51 % ETH Person seq1 + sceneInfo.frameNums=0:999; + case 52 % ETH Person seq2 + sceneInfo.frameNums=0:450; + case 53 % ETH Person seq3 + sceneInfo.frameNums=100:453; + case {60,61,62} % AVSS + sceneInfo.frameNums=1:2000; + case 70 + sceneInfo.frameNums=0:220; + case 71 + sceneInfo.frameNums=0:240; + case 72 + sceneInfo.frameNums=0:200; + case 73 + sceneInfo.frameNums=0:130; + case 74 + sceneInfo.frameNums=0:90; + case 75 + sceneInfo.frameNums=0:343; + case 80 + sceneInfo.frameNums=1:107; + case 81 + sceneInfo.frameNums=0:231; + case 82 + sceneInfo.frameNums=0:108; + case 83 + sceneInfo.frameNums=0:169; + case 84 + sceneInfo.frameNums=0:92; + case 85 + sceneInfo.frameNums=0:107; + case 86 + sceneInfo.frameNums=0:184; + % case 90 + % sceneInfo.frameNums=1:593; + % case 91 + % sceneInfo.frameNums=1:307; + % case 92 + % sceneInfo.frameNums=1:420; + case {101,131} % EnterExitCrossingPaths1 cor, front + sceneInfo.frameNums=0:382; + case {102,132} % EnterExitCrossingPaths2 cor, front + sceneInfo.frameNums=0:484; + case {103,133} % OneLeaveShop1 cor, front + sceneInfo.frameNums=0:294; + case {104,134} % OneLeaveShop2 cor, front + sceneInfo.frameNums=0:1118; + case {105,135} % OneLeaveShopReenter1 cor, front + sceneInfo.frameNums=0:389; + case {106,136} % OneLeaveShopReenter2 cor, front + sceneInfo.frameNums=0:559; + case {107,137} % OneShopOneWait1 cor, front + sceneInfo.frameNums=0:1376; + case {108,138} % OneShopOneWait2 cor, front + sceneInfo.frameNums=0:1461; + case {109,139} % OneStopEnter1 cor, front + sceneInfo.frameNums=0:1499; + case {110,140} % OneStopEnter2 cor, front + sceneInfo.frameNums=0:2724; + case {111,141} % OneStopMoveEnter1 cor, front + sceneInfo.frameNums=0:1586; + case {112,142} % OneStopMoveEnter2 cor, front + sceneInfo.frameNums=0:2236; + case {113,143} % OneStopMoveNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {114,144} % OneStopMoveNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {115,145} % OneStopNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {116,146} % OneStopNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {117,147} % ShopAssistant1 cor, front + sceneInfo.frameNums=0:1674; + case {118,148} % ShopAssistant2 cor, front + sceneInfo.frameNums=0:3699; + case {119,149} % ThreePastShop1 cor, front + sceneInfo.frameNums=0:1649; + case {120,150} % ThreePastShop2 cor, front + sceneInfo.frameNums=0:1520; + case {121,151} % TwoEnterShop1 cor, front + sceneInfo.frameNums=0:1644; + case {122,152} % TwoEnterShop2 cor, front + sceneInfo.frameNums=0:1604; + case {123,153} % TwoEnterShop3 cor, front + sceneInfo.frameNums=0:1604; + case {124,154} % TwoLeaveShop1 cor, front + sceneInfo.frameNums=0:1342; + case {125,155} % TwoLeaveShop2 cor, front + sceneInfo.frameNums=0:599; + case {126,156} % WalkByShop1 cor, front + sceneInfo.frameNums=0:2359; + case 160 + sceneInfo.frameNums=171:184; + case {161,162} + sceneInfo.frameNums=97:114; + otherwise + warning('unknown scenario getFrameNums'); +end + + +detfolder=fullfile(homefolder,'diss','detections','hog-hof-linsvm',dataset,seqname); +% detfolder=fullfile(homefolder,'diss','detections','swd-v2',dataset,seqname); +% detfolder=fullfile(dbfolder,'data-tud','det','',dataset,seqname); + +% detfile +switch(scenario) + case 51 + sceneInfo.detfile=fullfile(detfolder,'test-result-nms-0.8.idl'); + case 53 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'seq03-annot.idl'); + case 62 + sceneInfo.detfile=fullfile(detfolder,['AVSS-' seqname sprintf('-result-00000-05059-nms.idl',length(sceneInfo.frameNums)-1)]); + case 48 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'detections.mat'); + case {90,91,92} + sceneInfo.detfile=fullfile(detfolder,'detections.mat'); + case {23,25,27,70,71,72,73,80,40,41,42} + sceneInfo.detfile=fullfile(dbfolder,'data-tud','det',dataset,[seqname '-det.xml']); + otherwise + sceneInfo.detfile=fullfile(detfolder,[seqname sprintf('-result-00000-%05d-nms.idl',length(sceneInfo.frameNums)-1)]); + +end +assert(exist(sceneInfo.detfile,'file')==2,'detection file does not exist') + + +% img Folder +switch(scenario) + case 23 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); + case 25 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L2','Time_14-55','View_001',filesep); + case 27 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L3','Time_14-41','View_001',filesep); + case 31 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c1',filesep); + case 32 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c2',filesep); + case 36 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c1',filesep); + case 37 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c2',filesep); + case 40 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-campus-sequence',filesep); + case 41 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-crossing-sequence',filesep); + case 42 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-stadtmitte',filesep); + case 48 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case {50,51,52,53} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,'left',filesep); + case {60,61,62} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case 70 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-57','View_001',filesep); + case 71 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-59','View_001',filesep); + case 72 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-06','View_001',filesep); + case 73 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-31','View_001',filesep); + case 80 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 + case {90,91,92,93} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + otherwise + error('unknown scenario image Folder'); +end +assert(exist(sceneInfo.imgFolder,'dir')==7,'imgfolder does not exist') + +% image extension +imgExt='.jpg'; +switch(scenario) + case {20,21,40,41,42,44,50,51,52,53} + imgExt='.png'; +end +sceneInfo.imgFileFormat='frame_%04d'; + +switch(scenario) + case 40 + sceneInfo.imgFileFormat='DaSide0811-seq6-%03d'; + case 41 + sceneInfo.imgFileFormat='DaSide0811-seq7-%03d'; + case 42 + sceneInfo.imgFileFormat='DaMultiview-seq%04d'; + case 48 + sceneInfo.imgFileFormat='h%04d'; + case {50,51,52,53} + sceneInfo.imgFileFormat='image_%08d_0'; + case {90,91,92,93} + sceneInfo.imgFileFormat='%05d'; +end + +% append file extension +sceneInfo.imgFileFormat=[sceneInfo.imgFileFormat imgExt]; + +% if no frame nums, determine from images +if ~isfield(sceneInfo,'frameNums') + imglisting=dir([sceneInfo.imgFolder '*' imgExt]); + sceneInfo.frameNums=1:length(imglisting); +end + +% image dimensions +[sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... + size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); + + + + +%% tracking area +% if we are tracking on the ground plane +% we need to explicitly secify the tracking area +% otherwise image = tracking area +if opt.track3d + switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.trackingArea=[-14069.6, 4981.3, -14274.0, 1733.5]; + case {30,31,32} + sceneInfo.trackingArea=[-197 6708 -2021 6870]; + case {35,36,37} + sceneInfo.trackingArea=[-3438 5271 -2018 7376]; + case 40 + sceneInfo.trackingArea=[-0150 0506 28 1081]; + case 41 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + case 42 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + otherwise + error('Definition of tracking area needed for 3d tracking'); + end + +else + sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +end + +%% camera +cameraconffile=[]; +if opt.track3d + cam=1; + switch(scenario) + case {20,21} %terrace + cameraconffile=sprintf('%sepfl/terrace-tsai-c%i.xml',dbfolder,cam); + case {22, 23,25,27,70,71,72,73,74,75,80,81,82,83,84,85,86} %PETS2009 + cameraconffile=fullfile(dbfolder,dataset,'View_001.xml'); + case 24 + cameraconffile=sprintf('%sPETS2009/View_001.xml',dbfolder); + case 30 + cameraconffile=sprintf('%sTUD10/ped1/c%i-calib.xml',dbfolder,cam); + case 31 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c1-calib.xml'); + case 32 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c2-calib.xml'); + case 36 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c1-calib.xml'); + case 37 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c2-calib.xml'); + case {40,43} + cameraconffile=fullfile(dbfolder,dataset,'tud-campus-calib.xml'); + case {41,44} + cameraconffile=fullfile(dbfolder,dataset,'tud-crossing-calib.xml'); + case 42 + cameraconffile=fullfile(dbfolder,dataset,'tud-stadtmitte-calib.xml'); + case {45,46,47} + cameraconffile=sprintf('%sETH-Central/pedxing-seq1-calib.xml',dbfolder); + case {60,61,62} + cameraconffile=sprintf('%sAVSS/AB_calib.xml',dbfolder); + case intersect(scenario,101:126); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-cor.xml',dbfolder); + case intersect(scenario,131:156); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + case intersect(scenario,160:163) %%% !!! FIX !!! + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + otherwise + error('unknown scenario'); + end +end +sceneInfo.camFile=cameraconffile; + +if ~isempty(sceneInfo.camFile) + sceneInfo.camPar=parseCameraParameters(sceneInfo.camFile); +end + + +%% target size +sceneInfo.targetSize=20; % target 'radius' +sceneInfo.targetSize=sceneInfo.imgWidth/30; +if opt.track3d, sceneInfo.targetSize=350; end + +%% target aspect ratio +sceneInfo.targetAR=1/3; +switch(scenario) + case 48 % Hockey + sceneInfo.targetAR=1/2; + case {90,91,92} % aerial + sceneInfo.targetAR=1; +end + + +%% ground truth +sceneInfo.gtFile=''; +switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + case 31 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c1','GT2d_full_new.mat'); + case 32 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c2','GT2d_full_new.mat'); + case {40,41} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '-interp.mat']); + case 42 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + % sceneInfo.gtFile='/home/aanton/diss/others/yangbo/TUD/TUD_Stadtmitte.avi.gt.mat'; % Yang + case 62 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,'AB_Hard','GT2d_new.mat'); + otherwise + warning('ground truth?'); +end + + +global gtInfo +sceneInfo.gtAvailable=0; +if ~isempty(sceneInfo.gtFile) + sceneInfo.gtAvailable=1; + % first determine the type + [pathtogt, gtfile, fileext]=fileparts(sceneInfo.gtFile); + + if strcmpi(fileext,'.xml') % CVML + gtInfo=parseGT(sceneInfo.gtFile); + elseif strcmpi(fileext,'.mat') + % check for the var gtInfo + fileInfo=who('-file',sceneInfo.gtFile); + varExists=0; cnt=0; + while ~varExists && cnt + +void undistortedToDistortedSensorCoord(double Xu, double Yu, double *Xd, double *Yd, double mKappa1) { + double Ru; + double Rd; + double lambda; + double c; + double d; + double Q; + double R; + double D; + double S; + double T; + double sinT; + double cosT; + + if (((Xu == 0) && (Yu == 0)) || (mKappa1 == 0)) { + *Xd = Xu; + *Yd = Yu; + } + else { + Ru = sqrt(Xu*Xu + Yu*Yu); + + c = 1.0 / mKappa1; + d = -c * Ru; + + Q = c / 3; + R = -d / 2; + D = Q*Q*Q + R*R; + + if (D >= 0) { + /* one real root */ + D = sqrt(D); + if (R + D > 0) { + S = pow(R + D, 1.0/3.0); + } + else { + S = -pow(-R - D, 1.0/3.0); + } + + if (R - D > 0) { + T = pow(R - D, 1.0/3.0); + } + else { + T = -pow(D - R, 1.0/3.0); + } + + Rd = S + T; + + if (Rd < 0) { + Rd = sqrt(-1.0 / (3 * mKappa1)); + /*fprintf (stderr, "\nWarning: undistorted image point to distorted image point mapping limited by\n"); + * fprintf (stderr, " maximum barrel distortion radius of %lf\n", Rd); + * fprintf (stderr, " (Xu = %lf, Yu = %lf) -> (Xd = %lf, Yd = %lf)\n\n", Xu, Yu, Xu * Rd / Ru, Yu * Rd / Ru);*/ + } + } + else { + /* three real roots */ + D = sqrt(-D); + S = pow( sqrt(R*R + D*D) , 1.0/3.0 ); + T = atan2(D, R) / 3; + sinT = sin(T); + cosT = cos(T); + + /* the larger positive root is 2*S*cos(T) */ + /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ + /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ + + Rd = -S * cosT + sqrt(3.0) * S * sinT; /* use the smaller positive root */ + } + + lambda = Rd / Ru; + + Xd[0] = Xu * lambda; + Yd[0] = Yu * lambda; + } +} + + +void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { + + + /* /Declarations */ + const mxArray *Dpxdata, *Dpydata, *Sxdata, *Cxdata, *Cydata, *Xwdata, *Ywdata, *Zwdata, *focaldata, *kappadata, \ + *mRdata, *mTdata; + + double mDpx, mDpy, mSx, *Xw, *Yw, *Zw, focal, kappa, \ + mR11, mR12, mR13, mR21, mR22, mR23, mR31, mR32, mR33, \ + mTx, mTy, mTz, mCx, mCy; + + double xc; + double yc; + double zc; + double Xu; + double Yu; + double Xd[1]; + double Yd[1]; + double xw, yw, zw; + int F, N; + + double *Xi, *Yi; + int i, j, ind; + + double *mR, *mT; + + /* //Copy input pointer x */ + Xwdata = prhs[0]; + Ywdata = prhs[1]; + Zwdata = prhs[2]; + Dpxdata = prhs[3]; + Dpydata = prhs[4]; + Sxdata = prhs[5]; + Cxdata = prhs[6]; + Cydata = prhs[7]; + focaldata = prhs[8]; + kappadata = prhs[9]; + mRdata = prhs[10]; + mTdata = prhs[11]; + + mDpx = (double)(mxGetScalar(Dpxdata)); + mDpy = (double)(mxGetScalar(Dpydata)); + mSx = (double)(mxGetScalar(Sxdata)); + Xw = mxGetPr(Xwdata); + Yw = mxGetPr(Ywdata); + Zw = mxGetPr(Zwdata); + focal = (double)(mxGetScalar(focaldata)); + kappa = (double)(mxGetScalar(kappadata)); + mCx = (double)(mxGetScalar(Cxdata)); + mCy = (double)(mxGetScalar(Cydata)); + + + mR = mxGetPr(mRdata); + mT = mxGetPr(mTdata); + + mR11 = mR[0]; + mR12 = mR[3]; + mR13 = mR[6]; + mR21 = mR[1]; + mR22 = mR[4]; + mR23 = mR[7]; + mR31 = mR[2]; + mR32 = mR[5]; + mR33 = mR[8]; + mTx = mT[0]; + mTy = mT[1]; + mTz = mT[2]; + + /* //Get number of frames and targets */ + F = mxGetN(Xwdata); + N = mxGetM(Xwdata); + + + /* Allocate memory and assign output pointer */ + plhs[0] = mxCreateDoubleMatrix(N, F, mxREAL); + plhs[1] = mxCreateDoubleMatrix(N, F, mxREAL); + + /*//Get a pointer to the data space in our newly allocated memory */ + Xi = mxGetPr(plhs[0]); + Yi = mxGetPr(plhs[1]); + + /* */ + for(i=0;i0.7)=Inf; +[a,b]=munkres(A); +%} +% Example 4: an example of partial assignment +%{ +A = [1 3 Inf; Inf Inf 5; Inf Inf 0.5]; +[a,b]=munkres(A) +%} +% a = [1 0 3] +% b = 1.5 +% Reference: +% "Munkres' Assignment Algorithm, Modified for Rectangular Matrices", +% http://csclab.murraystate.edu/bob.pilgrim/445/munkres.html + +% version 2.3 by Yi Cao at Cranfield University on 11th September 2011 + +assignment = zeros(1,size(costMat,1)); +cost = 0; + +validMat = costMat == costMat & costMat < Inf; +bigM = 10^(ceil(log10(sum(costMat(validMat))))+1); +costMat(~validMat) = bigM; + +% costMat(costMat~=costMat)=Inf; +% validMat = costMat0) + break + end + coverColumn = false(1,n); + coverColumn(starZ(starZ>0))=true; + coverRow = false(n,1); + primeZ = zeros(n,1); + [rIdx, cIdx] = find(dMat(~coverRow,~coverColumn)==bsxfun(@plus,minR(~coverRow),minC(~coverColumn))); + while 1 + %************************************************************************** + % STEP 4: Find a noncovered zero and prime it. If there is no starred + % zero in the row containing this primed zero, Go to Step 5. + % Otherwise, cover this row and uncover the column containing + % the starred zero. Continue in this manner until there are no + % uncovered zeros left. Save the smallest uncovered value and + % Go to Step 6. + %************************************************************************** + cR = find(~coverRow); + cC = find(~coverColumn); + rIdx = cR(rIdx); + cIdx = cC(cIdx); + Step = 6; + while ~isempty(cIdx) + uZr = rIdx(1); + uZc = cIdx(1); + primeZ(uZr) = uZc; + stz = starZ(uZr); + if ~stz + Step = 5; + break; + end + coverRow(uZr) = true; + coverColumn(stz) = false; + z = rIdx==uZr; + rIdx(z) = []; + cIdx(z) = []; + cR = find(~coverRow); + z = dMat(~coverRow,stz) == minR(~coverRow) + minC(stz); + rIdx = [rIdx(:);cR(z)]; + cIdx = [cIdx(:);stz(ones(sum(z),1))]; + end + if Step == 6 + % ************************************************************************* + % STEP 6: Add the minimum uncovered value to every element of each covered + % row, and subtract it from every element of each uncovered column. + % Return to Step 4 without altering any stars, primes, or covered lines. + %************************************************************************** + [minval,rIdx,cIdx]=outerplus(dMat(~coverRow,~coverColumn),minR(~coverRow),minC(~coverColumn)); + minC(~coverColumn) = minC(~coverColumn) + minval; + minR(coverRow) = minR(coverRow) - minval; + else + break + end + end + %************************************************************************** + % STEP 5: + % Construct a series of alternating primed and starred zeros as + % follows: + % Let Z0 represent the uncovered primed zero found in Step 4. + % Let Z1 denote the starred zero in the column of Z0 (if any). + % Let Z2 denote the primed zero in the row of Z1 (there will always + % be one). Continue until the series terminates at a primed zero + % that has no starred zero in its column. Unstar each starred + % zero of the series, star each primed zero of the series, erase + % all primes and uncover every line in the matrix. Return to Step 3. + %************************************************************************** + rowZ1 = find(starZ==uZc); + starZ(uZr)=uZc; + while rowZ1>0 + starZ(rowZ1)=0; + uZc = primeZ(rowZ1); + uZr = rowZ1; + rowZ1 = find(starZ==uZc); + starZ(uZr)=uZc; + end +end + +% Cost of assignment +rowIdx = find(validRow); +colIdx = find(validCol); +starZ = starZ(1:nRows); +vIdx = starZ <= nCols; +assignment(rowIdx(vIdx)) = colIdx(starZ(vIdx)); +pass = assignment(assignment>0); +pass(~diag(validMat(assignment>0,pass))) = 0; +assignment(assignment>0) = pass; +cost = trace(costMat(assignment>0,assignment(assignment>0))); + +function [minval,rIdx,cIdx]=outerplus(M,x,y) +ny=size(M,2); +minval=inf; +for c=1:ny + M(:,c)=M(:,c)-(x+y(c)); + minval = min(minval,min(M(:,c))); +end +[rIdx,cIdx]=find(M==minval); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/myLinExtrap.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/myLinExtrap.m new file mode 100644 index 0000000000000000000000000000000000000000..4f1e2e60b8793bfa472b71825a6401561cb77b21 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/myLinExtrap.m @@ -0,0 +1,26 @@ +function yi=myLinExtrap(Y,steps) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% only takes two element vectors Y +if length(Y)~=2, error('Y must be of length 2'); end + + +n=Y(1); m=diff(Y); + +if steps<0 + xi=steps:-1; +else + xi=(1:steps)+1; +end + +yi = m*xi + n; + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/parseDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/parseDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..12084c5ae87cf59181aad3b8d5d7c30d8a28e606 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/parseDetections.m @@ -0,0 +1,80 @@ +function [detections, nDets] = parseDetections(detectionSet, frameNums) +% read detection file and create a struct array +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +nDets=0; + +%% now parse +cnt = numel(frameNums); +detections(cnt).bx=[]; +detections(cnt).by=[]; +detections(cnt).xp=[]; +detections(cnt).yp=[]; +detections(cnt).ht=[]; +detections(cnt).wd=[]; +detections(cnt).sc=[]; + +detections(cnt).xi=[]; +detections(cnt).yi=[]; +for t = 1:numel(frameNums); + idxObj = find(detectionSet(:, 1) == t); + nObjects = numel(idxObj); + bx =[];by=[];xp=[];yp=[]; + ht=[];wd=[];sc=[]; + xi=[];yi=[]; + for j = 1:nObjects + loc = detectionSet(idxObj(j), 3:6); + score = detectionSet(idxObj(j), 7); + left = loc(1); + top = loc(2); + width = loc(3); + height = loc(4); + xis = left + width/2; + yis = top + height; + bx = cat(2, bx, left); + by=cat(2, by, top); + xp=cat(2, xp, xis); + yp=cat(2, xp, yis); + ht=cat(2, ht, height); + wd=cat(2, wd, width); + sc=cat(2, sc, score); + xi=cat(2, xi, xis); + yi=cat(2, yi, yis); + end + detections(t).bx=bx; + detections(t).by=by; + detections(t).xp=xp; + detections(t).yp=yp; + detections(t).ht=ht; + detections(t).wd=wd; + detections(t).sc=sc; + + detections(t).xi=xi; + detections(t).yi=yi; + + nDets=nDets+length(xi); +end + + +%% set xp and yp accordingly +detections = setDetectionPositions(detections); + +end + +function detections=setDetectionPositions(detections) +% set xp,yp to xi,yi if tracking is in image (2d) +% set xp,yp to xw,yi if tracking is in world (3d) + F = length(detections); + + for t=1:F + detections(t).xp=detections(t).xi; + detections(t).yp=detections(t).yi; + end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/parseGT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/parseGT.m new file mode 100644 index 0000000000000000000000000000000000000000..309e82887abf389bf0d92264f4c81ee04acb3eab --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/parseGT.m @@ -0,0 +1,64 @@ +function gtInfo=parseGT(gtfile) +% read ground truth bounding boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% first determine the type +[~, ~, fileext]=fileparts(gtfile); + +% for now, we can only read CVML schema +if strcmpi(fileext,'.xml'); +else error('Unknown type of detections file.'); +end + +%% now parse +xDoc=xmlread(gtfile); + +allFrames=xDoc.getElementsByTagName('frame'); +F=allFrames.getLength; +frameNums=zeros(1,F); + + +%% +for t=1:F + if ~mod(t,20), fprintf('.'); end + % what is the frame + frame=str2double(allFrames.item(t-1).getAttribute('number')); + frameNums(t)=frame; + + objects=allFrames.item(t-1).getElementsByTagName('object'); + Nt=objects.getLength; + for i=0:Nt-1 + id=str2double(objects.item(i).getAttribute('id')); + if id<1, error('uh oh. IDs should be positive'); end + box=objects.item(i).getElementsByTagName('box'); + h=str2double(box.item(0).getAttribute('h')); + w=str2double(box.item(0).getAttribute('w')); + xc=str2double(box.item(0).getAttribute('xc')); + yc=str2double(box.item(0).getAttribute('yc')); + + % foot position + gtInfo.X(t,id)=xc; gtInfo.Y(t,id)=yc+h/2; + gtInfo.H(t,id)=h; gtInfo.W(t,id)=w; + end +end + +gtInfo.frameNums=frameNums; +% remove zero columns +notEmpty=~~sum(gtInfo.X); +gtInfo.X=gtInfo.X(:,notEmpty); +gtInfo.Y=gtInfo.Y(:,notEmpty); +gtInfo.W=gtInfo.W(:,notEmpty); +gtInfo.H=gtInfo.H(:,notEmpty); + + +% fprintf('all read\n'); + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/parseVehicleGT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/parseVehicleGT.m new file mode 100644 index 0000000000000000000000000000000000000000..c6af75d426cc74efe727c342e0c3c97f00ef7db8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/parseVehicleGT.m @@ -0,0 +1,36 @@ +function gtInfo = parseVehicleGT(gtfile, frameNums) +% read ground truth bounding boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +%% now parse +gt = load(gtfile); +for t = frameNums + idx = find(gt(:,5) == t); + for i = 1:numel(idx) + h = gt(idx(i), 4) - gt(idx(i), 2) + 1; + w = gt(idx(i), 3) - gt(idx(i), 1) + 1; + xc = gt(idx(i), 1) + w/2; + yc = gt(idx(i), 2) + h/2; + id = gt(idx(i), 6); + % foot position + gtInfo.X(t,id)=xc; gtInfo.Y(t,id)=yc+h/2; + gtInfo.H(t,id)=h; gtInfo.W(t,id)=w; + end +end + +gtInfo.frameNums = frameNums; +% remove zero columns +notEmpty = ~~sum(gtInfo.X); +gtInfo.X = gtInfo.X(:,notEmpty); +gtInfo.Y = gtInfo.Y(:,notEmpty); +gtInfo.W = gtInfo.W(:,notEmpty); +gtInfo.H = gtInfo.H(:,notEmpty); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/pdfcrop.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/pdfcrop.m new file mode 100644 index 0000000000000000000000000000000000000000..08a8e427e01bd46c317fa3afaf61e337288e1319 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/pdfcrop.m @@ -0,0 +1,3 @@ +function pdfcrop(pdffile) + eval(sprintf('!pdfcrop %s %s >& /dev/null',pdffile,pdffile)); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/plotDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/plotDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..9cc7d63d4dcdfd98e6576f8dbc0b0113f0817625 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/plotDetections.m @@ -0,0 +1,61 @@ +function plotDetections(plot3d, limits) +% plot detections as dots +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo + +hold on +% axis equal + +dets=detections; +F=size(dets,2); +detcol=[.6 .6 .6]; +maxFrames=200; +% plot3d=1; + +% imshow(imread('/storage/databases/PETS2009/Crowd_PETS09/S3/Multiple_Flow/Time_12-43/View_001/frame_0026.jpg')); + +if ~exist('plot3d','var'), plot3d=0; end + +if plot3d + for t=1:min(F,maxFrames) +% t +% t*ones(1,length(dets(t).xp)) +% pause + plot3(dets(t).xp,dets(t).yp,t*ones(1,length(dets(t).xp)),'.','color',detcol); + +% pause(.01) + end +% view(3) +% zlim([0 min(F,maxFrames)]); +else + for t=1:F + plot(dets(t).xp,dets(t).yp,'.','color',detcol); + end + +end + +if exist('limits','var') + if length(limits)==4 || length(limits)==6 + xlim(limits(1:2)); + ylim(limits(3:4)); +% if length(limits)==6 +% zlim(limits(5:6)); +% end + else + error('limits must be 4 or 6 long vector'); + end +else + xlim(sceneInfo.trackingArea(1:2)); + ylim(sceneInfo.trackingArea(3:4)); +end + +pause(0.001); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/postProcessState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/postProcessState.m new file mode 100644 index 0000000000000000000000000000000000000000..194b042921c9468e4fe502f3c33cf4dbadc46826 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/postProcessState.m @@ -0,0 +1,28 @@ +function stateInfo=postProcessState(stateInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt sceneInfo + + +if(opt.track3d && opt.cutToTA) + stateInfo=cutStateToTrackingArea(stateInfo); +end + +% if we tracked on image, Xi = X +if ~opt.track3d + stateInfo.Xi=stateInfo.X; stateInfo.Yi=stateInfo.Y; +% otherwise project back +else + stateInfo.Xgp=stateInfo.X; stateInfo.Ygp=stateInfo.Y; + [stateInfo.Xi, stateInfo.Yi]=projectToImage(stateInfo.X,stateInfo.Y,sceneInfo); +end + +%% get bounding boxes from corresponding detections +stateInfo=getBBoxesFromState(stateInfo); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/prepFigure.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/prepFigure.m new file mode 100644 index 0000000000000000000000000000000000000000..27443be17e1e3b690c8d3b28ed6cfcc44fb01ee0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/prepFigure.m @@ -0,0 +1,39 @@ +function prepFigure() +% prepare figure for showing state +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt; + +% figh=findobj('type','figure','name','optimization'); + +% if isempty(figh), figh=figure('name','optimization'); end +% set(figh); + +clf; +hold on; +box on + +if ~opt.track3d + set(gca,'Ydir','reverse'); +end +xlim(sceneInfo.trackingArea(1:2)) +ylim(sceneInfo.trackingArea(3:4)) +if ~opt.track3d + ylim([sceneInfo.imTopLimit sceneInfo.trackingArea(4)]); +end + +zlim([0 length(sceneInfo.frameNums)]) + +view(-78,4) +if ~opt.track3d + view(-40,10); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printFinalEvaluation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printFinalEvaluation.m new file mode 100644 index 0000000000000000000000000000000000000000..2a551f7afd287d23a6c14777ecd52370744730fe --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printFinalEvaluation.m @@ -0,0 +1,17 @@ +function printFinalEvaluation(stateInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo gtInfo + +if sceneInfo.gtAvailable + printMessage(1,'\nEvaluation 2D:\n'); + [metrics, metricsInfo]=CLEAR_MOT(gtInfo,stateInfo); + printMetrics(metrics,metricsInfo,1); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printMessage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printMessage.m new file mode 100644 index 0000000000000000000000000000000000000000..52a82a35c457f0890e5e099103633480ff54469c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printMessage.m @@ -0,0 +1,18 @@ +function printMessage(L,F,varargin) +% print a formatted string as F with values from varargin and debug level L +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt + + +if L<=opt.verbosity + fprintf(F,varargin{:}); +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printMetrics.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printMetrics.m new file mode 100644 index 0000000000000000000000000000000000000000..6b8a7929c06d6193c3a6a58b66858ea9ee234965 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printMetrics.m @@ -0,0 +1,43 @@ +function printMetrics(metrics, metricsInfo, dispHeader,dispMetrics,padChar) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +namesToDisplay=metricsInfo.names.long; +widthsToDisplay=metricsInfo.widths.long; +formatToDisplay=metricsInfo.format.long; + +namesToDisplay=metricsInfo.names.short; +widthsToDisplay=metricsInfo.widths.short; +formatToDisplay=metricsInfo.format.short; + +if nargin<3, dispHeader=1; end +if nargin<4 + dispMetrics=1:length(metrics); +end +if nargin<5 + padChar={' ',' ','|',' ',' ',' ','|',' ',' ',' ','| ',' ',' ',' '}; +end + +if dispHeader + for m=dispMetrics + printString=sprintf('fprintf(''%%%is%s'',char(namesToDisplay(m)))',widthsToDisplay(m),char(padChar(m))); + eval(printString) + end + fprintf('\n'); +end + +for m=dispMetrics + printString=sprintf('fprintf(''%%%i%s%s'',metrics(m))',widthsToDisplay(m),char(formatToDisplay(m)),char(padChar(m))); + eval(printString) +end + +% if standard, new line +if nargin<4 + fprintf('\n'); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..a06683f310651afbaca7ba0e8a767ecf4e9dc939 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/printSceneInfo.m @@ -0,0 +1,43 @@ +function printSceneInfo() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% prints information about the scene + +% sceneInfo.targetSize=10; % target 'radius' +% +% +% % sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); % 23 +% sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 +% +% sceneInfo.imgFileFormat='frame_%04d.jpg'; +% sceneInfo.frameNums=1:107; +% % sceneInfo.frameNums=0:794; +% [sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... +% size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); +% sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +% +% %% load detections +% detections=parseDetections(detfile); fr=1:length(detections); +% % fr=1:50; detections=detections(fr); % !!!!!!! REMOVE +% F=size(detections,2); +% stateInfo.F=F; % number of frames +% +% +global sceneInfo + + +%% +% printMessage(1,'Sequence: \t%s\n',sceneInfo.seqName); +printMessage(2, 'Frames: ...... %i\n',length(sceneInfo.frameNums)); +printMessage(2, 'Image size: .. %i x %i\n',sceneInfo.imgWidth,sceneInfo.imgHeight) + +% sceneInfo + +%% +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/projectToGroundPlane.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/projectToGroundPlane.m new file mode 100644 index 0000000000000000000000000000000000000000..b51522119bb738eae46b2fe90930d43d1aca9e74 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/projectToGroundPlane.m @@ -0,0 +1,22 @@ +function [Xgp Ygp]=projectToGroundPlane(Xi, Yi, sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +[F N]=size(Xi); +Xgp=zeros(size(Xi)); +Ygp=zeros(size(Xi)); + +for t=1:F + extar=find(Xi(t,:)); + for id=extar + [Xgp(t,id) Ygp(t,id) zw]=imageToWorld(Xi(t,id), Yi(t,id), sceneInfo.camPar); + end +end + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/projectToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/projectToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..97d5f7fdb9142e4217853da0b834e11a728adb0f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/projectToImage.m @@ -0,0 +1,19 @@ +function [Xi Yi]=projectToImage(X,Y,sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +Z=zeros(size(X)); +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); +[Xi Yi]=allWorldToImage_mex(X,Y,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + mR,mT); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/readIDL.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/readIDL.m new file mode 100644 index 0000000000000000000000000000000000000000..6e94f840fdbc5223ab1e4eada6f90623db9f3800 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/readIDL.m @@ -0,0 +1,60 @@ +% Return IDL structure for given filename +% +% INPUT +% filename filename of IDL file +% +% OUTPUT +% idl IDL structure, consisting of +% idl.img - array of images +% idl.bb - array of array of bounding box coordinates +% idl.score - array of array of scores for boxes + +function idl=readIDL(filename) + +fid=fopen(filename); +idl.bb=[]; +idl.img=[]; +idl.score=[]; + +i=1; +bbnum=0; +while 1 + tline = fgetl(fid); + if ~ischar(tline), break, end + tline = strrep(tline, ',', ' '); %replace commas with spaces + colon=strfind(tline,':'); %all colons + + if isempty(colon) + point = strfind(tline,'";'); + if length(point) > 0 + idl(i).img=tline(2:point(1)-1); %filename + i = i + 1; + continue + else + break + end + end + + bb_idx=[(strfind(tline,'(')+1)' (strfind(tline,')')-1)'];%positions of bb start and stop + + idl(i).img=tline(2:colon(1)-2); %filename + for k=1:size(bb_idx,1) + idl(i).bb(end+1,:)=str2num(tline(bb_idx(k,1):bb_idx(k,2))); % next bb + end + + if length(colon)>1 %there are scores in the file ... + for k=1:size(bb_idx,1)-1 + idl(i).score(end+1) = str2num(tline(colon(k+1)+1:(bb_idx(k+1,1)-2))); %next score + end + idl(i).score(end+1) = str2num(tline(colon(length(colon))+1:length(tline)-1)); + else + idl(i).score = 1*ones(1,size(bb_idx,1)); + end + + i=i+1; + bbnum = bbnum + size(bb_idx,1); +end +fclose(fid); + +% fprintf('%d bounding boxes loaded.', bbnum); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/reopenFig.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/reopenFig.m new file mode 100644 index 0000000000000000000000000000000000000000..dcfc4b09cfad39ea91e1f6a9dae423f639d08a35 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/reopenFig.m @@ -0,0 +1,14 @@ +function reopenFig(figname) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +close(findobj('type','figure','name',figname)) +figure('name',figname); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/examples.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/examples.m new file mode 100644 index 0000000000000000000000000000000000000000..a758a33db3033dacef195b999281160d0723cbde --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/examples.m @@ -0,0 +1,172 @@ +%%% SPLINEFIT EXAMPLES + + +%% EXAMPLE 1: Breaks and pieces + +% Data (200 points) +x = 2*pi*rand(1,200); +y = sin(x) + sin(2*x) + 0.2*randn(size(x)); + +% Uniform breaks +breaks = linspace(0,2*pi,41); % 41 breaks, 40 pieces +pp1 = splinefit(x,y,breaks); + +% Breaks interpolated from data +pp2 = splinefit(x,y,10); % 11 breaks, 10 pieces + +% Plot +figure(1) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +plot(x,y,'.',xx,[y1;y2]) +axis([0,2*pi,-2.5,2.5]), grid on +legend('data','41 breaks, 40 pieces','11 breaks, 10 pieces') +title('EXAMPLE 1: Breaks and pieces') + + + +%% EXAMPLE 2: Spline orders + +% Data (200 points) +x = 2*pi*rand(1,200); +y = sin(x) + sin(2*x) + 0.1*randn(size(x)); + +% Splines +pp1 = splinefit(x,y,8,1); % Piecewise constant +pp2 = splinefit(x,y,8,2); % Piecewise linear +pp3 = splinefit(x,y,8,3); % Piecewise quadratic +pp4 = splinefit(x,y,8,4); % Piecewise cubic +pp5 = splinefit(x,y,8,5); % Etc. + +% Plot +figure(2) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +y3 = ppval(pp3,xx); +y4 = ppval(pp4,xx); +y5 = ppval(pp5,xx); +plot(x,y,'.',xx,[y1;y2;y3;y4;y5]), grid on +legend('data','order 1','order 2','order 3','order 4','order 5') +title('EXAMPLE 2: Spline orders') + + + +%% EXAMPLE 3: Periodic boundary conditions + +% Data (100 points) +x = 2*pi*[0,rand(1,98),1]; +y = sin(x) - cos(2*x) + 0.2*randn(size(x)); + +% No constraints +pp1 = splinefit(x,y,10,5); +% Periodic boundaries +pp2 = splinefit(x,y,10,5,'p'); + +% Plot +figure(3) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +plot(x,y,'.',xx,[y1;y2]), grid on +legend('data','no constraints','periodic') +title('EXAMPLE 3: Periodic boundary conditions') + +% Check boundary conditions +y0 = ppval(pp2,[0,2*pi]); % y +y1 = ppval(ppdiff(pp2,1),[0,2*pi]); % y' +y2 = ppval(ppdiff(pp2,2),[0,2*pi]); % y'' +y3 = ppval(ppdiff(pp2,3),[0,2*pi]); % y''' +disp('Endpoint derivatives:') +disp([y0;y1;y2;y3]) + + + +%% EXAMPLE 4: Endpoint conditions + +% Data (200 points) +x = 2*pi*rand(1,200); +y = sin(2*x) + 0.1*randn(size(x)); + +% Breaks +breaks = linspace(0,2*pi,10); + +% Clamped endpoints, y = y' = 0 +xc = [0,0,2*pi,2*pi]; +cc = [eye(2),eye(2)]; +con = struct('xc',xc,'cc',cc); +pp1 = splinefit(x,y,breaks,con); + +% Hinged periodic endpoints, y = 0 +con = struct('xc',0); +pp2 = splinefit(x,y,breaks,con,'p'); + +% Plot +figure(4) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +plot(x,y,'.',xx,[y1;y2]), grid on +legend('data','clamped','hinged periodic') +title('EXAMPLE 4: Endpoint conditions') + + + +%% EXAMPLE 5: Airfoil data + +% Truncated data +x = [0,1,2,4,8,16,24,40,56,72,80]/80; +y = [0,28,39,53,70,86,90,79,55,22,2]/1000; +xy = [x;y]; + +% Curve length parameter +ds = sqrt(diff(x).^2 + diff(y).^2); +s = [0, cumsum(ds)]; + +% Constraints at s = 0: (x,y) = (0,0), (dx/ds,dy/ds) = (0,1) +con = struct('xc',[0 0],'yc',[0 0; 0 1],'cc',eye(2)); + +% Fit a spline with 4 pieces +pp = splinefit(s,xy,4,con); + +% Plot +figure(5) +ss = linspace(0,s(end),400); +xyfit = ppval(pp,ss); +xyb = ppval(pp,pp.breaks); +plot(x,y,'.',xyfit(1,:),xyfit(2,:),'r',xyb(1,:),xyb(2,:),'ro') +legend('data','spline','breaks') +grid on, axis equal +title('EXAMPLE 5: Airfoil data') + + + +%% EXAMPLE 6: Robust fitting + +% Data +x = linspace(0,2*pi,200); +y = sin(x) + sin(2*x) + 0.05*randn(size(x)); + +% Add outliers +x = [x, linspace(0,2*pi,60)]; +y = [y, -ones(1,60)]; + +% Fit splines with hinged conditions +con = struct('xc',[0,2*pi]); +pp1 = splinefit(x,y,8,con,0.25); % Robust fitting +pp2 = splinefit(x,y,8,con,0.75); % Robust fitting +pp3 = splinefit(x,y,8,con); % No robust fitting + +% Plot +figure(6) +xx = linspace(0,2*pi,400); +y1 = ppval(pp1,xx); +y2 = ppval(pp2,xx); +y3 = ppval(pp3,xx); +plot(x,y,'.',xx,[y1;y2;y3]), grid on +legend('data with outliers','robust, beta = 0.25','robust, beta = 0.75',... + 'no robust fitting') +title('EXAMPLE 6: Robust fitting') + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples.html b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples.html new file mode 100644 index 0000000000000000000000000000000000000000..30b8fca74117199522bf31c2dde92c7be08b570b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples.html @@ -0,0 +1,388 @@ + + + + + SPLINEFIT EXAMPLES

SPLINEFIT EXAMPLES

Contents

EXAMPLE 1: Breaks and pieces

% Data (200 points)
+x = 2*pi*rand(1,200);
+y = sin(x) + sin(2*x) + 0.2*randn(size(x));
+
+% Uniform breaks
+breaks = linspace(0,2*pi,41); % 41 breaks, 40 pieces
+pp1 = splinefit(x,y,breaks);
+
+% Breaks interpolated from data
+pp2 = splinefit(x,y,10);  % 11 breaks, 10 pieces
+
+% Plot
+figure(1)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+plot(x,y,'.',xx,[y1;y2])
+axis([0,2*pi,-2.5,2.5]), grid on
+legend('data','41 breaks, 40 pieces','11 breaks, 10 pieces')
+title('EXAMPLE 1: Breaks and pieces')
+

EXAMPLE 2: Spline orders

% Data (200 points)
+x = 2*pi*rand(1,200);
+y = sin(x) + sin(2*x) + 0.1*randn(size(x));
+
+% Splines
+pp1 = splinefit(x,y,8,1);  % Piecewise constant
+pp2 = splinefit(x,y,8,2);  % Piecewise linear
+pp3 = splinefit(x,y,8,3);  % Piecewise quadratic
+pp4 = splinefit(x,y,8,4);  % Piecewise cubic
+pp5 = splinefit(x,y,8,5);  % Etc.
+
+% Plot
+figure(2)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+y3 = ppval(pp3,xx);
+y4 = ppval(pp4,xx);
+y5 = ppval(pp5,xx);
+plot(x,y,'.',xx,[y1;y2;y3;y4;y5]), grid on
+legend('data','order 1','order 2','order 3','order 4','order 5')
+title('EXAMPLE 2: Spline orders')
+

EXAMPLE 3: Periodic boundary conditions

% Data (100 points)
+x = 2*pi*[0,rand(1,98),1];
+y = sin(x) - cos(2*x) + 0.2*randn(size(x));
+
+% No constraints
+pp1 = splinefit(x,y,10,5);
+% Periodic boundaries
+pp2 = splinefit(x,y,10,5,'p');
+
+% Plot
+figure(3)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+plot(x,y,'.',xx,[y1;y2]), grid on
+legend('data','no constraints','periodic')
+title('EXAMPLE 3: Periodic boundary conditions')
+
+% Check boundary conditions
+y0 = ppval(pp2,[0,2*pi]);             % y
+y1 = ppval(ppdiff(pp2,1),[0,2*pi]);   % y'
+y2 = ppval(ppdiff(pp2,2),[0,2*pi]);   % y''
+y3 = ppval(ppdiff(pp2,3),[0,2*pi]);   % y'''
+disp('Endpoint derivatives:')
+disp([y0;y1;y2;y3])
+
Endpoint derivatives:
+   -0.9885   -0.9885
+    0.7848    0.7848
+    3.2802    3.2802
+    5.6253    5.6253
+
+

EXAMPLE 4: Endpoint conditions

% Data (200 points)
+x = 2*pi*rand(1,200);
+y = sin(2*x) + 0.1*randn(size(x));
+
+% Breaks
+breaks = linspace(0,2*pi,10);
+
+% Clamped endpoints, y = y' = 0
+xc = [0,0,2*pi,2*pi];
+cc = [eye(2),eye(2)];
+con = struct('xc',xc,'cc',cc);
+pp1 = splinefit(x,y,breaks,con);
+
+% Hinged periodic endpoints, y = 0
+con = struct('xc',0);
+pp2 = splinefit(x,y,breaks,con,'p');
+
+% Plot
+figure(4)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+plot(x,y,'.',xx,[y1;y2]), grid on
+legend('data','clamped','hinged periodic')
+title('EXAMPLE 4: Endpoint conditions')
+

EXAMPLE 5: Airfoil data

% Truncated data
+x = [0,1,2,4,8,16,24,40,56,72,80]/80;
+y = [0,28,39,53,70,86,90,79,55,22,2]/1000;
+xy = [x;y];
+
+% Curve length parameter
+ds = sqrt(diff(x).^2 + diff(y).^2);
+s = [0, cumsum(ds)];
+
+% Constraints at s = 0: (x,y) = (0,0), (dx/ds,dy/ds) = (0,1)
+con = struct('xc',[0 0],'yc',[0 0; 0 1],'cc',eye(2));
+
+% Fit a spline with 4 pieces
+pp = splinefit(s,xy,4,con);
+
+% Plot
+figure(5)
+ss = linspace(0,s(end),400);
+xyfit = ppval(pp,ss);
+xyb = ppval(pp,pp.breaks);
+plot(x,y,'.',xyfit(1,:),xyfit(2,:),'r',xyb(1,:),xyb(2,:),'ro')
+legend('data','spline','breaks')
+grid on, axis equal
+title('EXAMPLE 5: Airfoil data')
+

EXAMPLE 6: Robust fitting

% Data
+x = linspace(0,2*pi,200);
+y = sin(x) + sin(2*x) + 0.05*randn(size(x));
+
+% Add outliers
+x = [x, linspace(0,2*pi,60)];
+y = [y, -ones(1,60)];
+
+% Fit splines with hinged conditions
+con = struct('xc',[0,2*pi]);
+pp1 = splinefit(x,y,8,con,0.25); % Robust fitting
+pp2 = splinefit(x,y,8,con,0.75); % Robust fitting
+pp3 = splinefit(x,y,8,con); % No robust fitting
+
+% Plot
+figure(6)
+xx = linspace(0,2*pi,400);
+y1 = ppval(pp1,xx);
+y2 = ppval(pp2,xx);
+y3 = ppval(pp3,xx);
+plot(x,y,'.',xx,[y1;y2;y3]), grid on
+legend('data with outliers','robust, beta = 0.25','robust, beta = 0.75',...
+    'no robust fitting')
+title('EXAMPLE 6: Robust fitting')
+
\ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples.png new file mode 100644 index 0000000000000000000000000000000000000000..3a8bb5070926c40f52631f8e3a0e526b98377acf --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c9a67ecc0caa48403485e7d708737deb1bf1acfe2765959784916d2f672d2ad +size 4004 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_01.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_01.png new file mode 100644 index 0000000000000000000000000000000000000000..9e9db855de2aa8b76348a14f3ca3e356ba939bcd --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_01.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1b3a9dca6c4e580d642bc434ac8c18b10a7b63937116df6a82895c9b4371d09 +size 11655 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_02.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_02.png new file mode 100644 index 0000000000000000000000000000000000000000..a143df3ab6c13ed2cde5730122c205812463066d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_02.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:344dd0b4956c3dc0da57c2a92b354e85766343ce49b62e298d9b2f615405e032 +size 12602 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_03.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_03.png new file mode 100644 index 0000000000000000000000000000000000000000..dc25cd3e30f4ed9a2d209efac924d68901cea86a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_03.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4086d1625fcef96884ad09c293b365a69bbd3924e8a1bdf5134d0717be2902e0 +size 9926 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_04.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_04.png new file mode 100644 index 0000000000000000000000000000000000000000..6156466c694455e84c2e36dbe2bb7f66e9bf9bbb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_04.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e43c3a2a1ac2eae55d6f6e1d503739f750cce46cfdcdc9aaeaea8f132cdece27 +size 11077 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_05.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_05.png new file mode 100644 index 0000000000000000000000000000000000000000..9b829bf838d1ff09f0858cee4933490d8d5737db --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_05.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c83d997a51bcbc4519e21baf90456e540a69fa1c089d4b1ddfe3aeb9adf86952 +size 7194 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_06.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_06.png new file mode 100644 index 0000000000000000000000000000000000000000..02469bc5f7fc27a5ce9c926b5b11ce436a596671 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/html/examples_06.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c14e0db99e65a16d61ffbe4e3f595fd88a953ffe7f6ee44ae8c724089acfe89b +size 12048 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/license.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/license.txt new file mode 100644 index 0000000000000000000000000000000000000000..1be63976f4e8261887b25451f09ac4702f1445f4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/license.txt @@ -0,0 +1,24 @@ +Copyright (c) 2010, Jonas Lundgren +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/ppdiff.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/ppdiff.m new file mode 100644 index 0000000000000000000000000000000000000000..8a338f5fb62a1af993b5bab25cb3418fbb4f5f17 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/ppdiff.m @@ -0,0 +1,52 @@ +function qq = ppdiff(pp,j) +%PPDIFF Differentiate piecewise polynomial. +% QQ = PPDIFF(PP,J) returns the J:th derivative of a piecewise +% polynomial PP. PP must be on the form evaluated by PPVAL. QQ is a +% piecewise polynomial on the same form. Default value for J is 1. +% +% Example: +% x = linspace(-pi,pi,9); +% y = sin(x); +% pp = spline(x,y); +% qq = ppdiff(pp); +% xx = linspace(-pi,pi,201); +% plot(xx,cos(xx),'b',xx,ppval(qq,xx),'r') +% +% See also PPVAL, SPLINE, SPLINEFIT, PPINT + +% Author: jonas.lundgren@saabgroup.com, 2009. + +if nargin < 1, help ppdiff, return, end +if nargin < 2, j = 1; end + +% Check diff order +if ~isreal(j) || mod(j,1) || j < 0 + msgid = 'PPDIFF:DiffOrder'; + message = 'Order of derivative must be a non-negative integer!'; + error(msgid,message) +end + +% Get coefficients +coefs = pp.coefs; +[m n] = size(coefs); + +if j == 0 + % Do nothing +elseif j < n + % Derivative of order J + D = [n-j:-1:1; ones(j-1,n-j)]; + D = cumsum(D,1); + D = prod(D,1); + coefs = coefs(:,1:n-j); + for k = 1:n-j + coefs(:,k) = D(k)*coefs(:,k); + end +else + % Derivative kills PP + coefs = zeros(m,1); +end + +% Set output +qq = pp; +qq.coefs = coefs; +qq.order = size(coefs,2); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/ppint.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/ppint.m new file mode 100644 index 0000000000000000000000000000000000000000..b1b0b7d5cef2babf5accd57aa8fd92273a63b6ed --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/ppint.m @@ -0,0 +1,69 @@ +function output = ppint(pp,a,b) +%PPINT Integrate piecewise polynomial. +% QQ = PPINT(PP,A) returns the indefinite integral from A to X of a +% piecewise polynomial PP. PP must be on the form evaluated by PPVAL. +% QQ is a piecewise polynomial on the same form. Default value for A is +% the leftmost break of PP. +% +% I = PPINT(PP,A,B) returns the definite integral from A to B. +% +% Example: +% x = linspace(-pi,pi,7); +% y = sin(x); +% pp = spline(x,y); +% I = ppint(pp,0,pi) +% +% qq = ppint(pp,pi/2); +% xx = linspace(-pi,pi,201); +% plot(xx,-cos(xx),xx,ppval(qq,xx),'r') +% +% See also PPVAL, SPLINE, SPLINEFIT, PPDIFF + +% Author: jonas.lundgren@saabgroup.com, 2009. + +if nargin < 1, help ppint, return, end +if nargin < 2, a = pp.breaks(1); end + +% Get coefficients and breaks +coefs = pp.coefs; +[m n] = size(coefs); +xb = pp.breaks; +pdim = prod(pp.dim); + +% Interval lengths +hb = diff(xb); +hb = repmat(hb,pdim,1); +hb = hb(:); + +% Integration +coefs(:,1) = coefs(:,1)/n; +y = coefs(:,1).*hb; +for k = 2:n + coefs(:,k) = coefs(:,k)/(n-k+1); + y = (y + coefs(:,k)).*hb; +end +y = reshape(y,pdim,[]); +I = cumsum(y,2); +I = I(:); +coefs(:,n+1) = [zeros(pdim,1); I(1:m-pdim)]; + +% Set preliminary indefinite integral +qq = pp; +qq.coefs = coefs; +qq.order = n+1; + +% Set output +if nargin < 3 + % Indefinite integral from a to x + if a ~= xb(1) + I0 = ppval(qq,a); + I0 = I0(:); + I0 = repmat(I0,m/pdim,1); + qq.coefs(:,n+1) = qq.coefs(:,n+1) - I0; + end + output = qq; +else + % Definite integral from a to b + output = ppval(qq,b) - ppval(qq,a); +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/splinefit.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/splinefit.m new file mode 100644 index 0000000000000000000000000000000000000000..c81027bcb9a764c0a6cab575e4f8625b8aa10ee0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/splinefit.m @@ -0,0 +1,611 @@ +function pp = splinefit(varargin) +%SPLINEFIT Fit a spline to noisy data. +% PP = SPLINEFIT(X,Y,BREAKS) fits a piecewise cubic spline with breaks +% (knots) BREAKS to the noisy data (X,Y). X is a vector and Y is a vector +% or an ND array. If Y is an ND array, then X(j) and Y(:,...,:,j) are +% matched. Use PPVAL to evaluate PP. +% +% PP = SPLINEFIT(X,Y,P) where P is a positive integer interpolates the +% breaks linearly from the sorted locations of X. P is the number of +% spline pieces and P+1 is the number of breaks. +% +% OPTIONAL INPUT +% Argument places 4 to 8 are reserved for optional input. +% These optional arguments can be given in any order: +% +% PP = SPLINEFIT(...,'p') applies periodic boundary conditions to +% the spline. The period length is MAX(BREAKS)-MIN(BREAKS). +% +% PP = SPLINEFIT(...,'r') uses robust fitting to reduce the influence +% from outlying data points. Three iterations of weighted least squares +% are performed. Weights are computed from previous residuals. +% +% PP = SPLINEFIT(...,BETA), where 0 < BETA < 1, sets the robust fitting +% parameter BETA and activates robust fitting ('r' can be omitted). +% Default is BETA = 1/2. BETA close 0 gives all data equal weighting. +% Increase BETA to reduce the influence from outlying data. BETA close +% to 1 may cause instability or rank deficiency. +% +% PP = SPLINEFIT(...,N) sets the spline order to N. Default is a cubic +% spline with order N = 4. A spline with P pieces has P+N-1 degrees of +% freedom. With periodic boundary conditions the degrees of freedom are +% reduced to P. +% +% PP = SPLINEFIT(...,CON) applies linear constraints to the spline. +% CON is a structure with fields 'xc', 'yc' and 'cc': +% 'xc', x-locations (vector) +% 'yc', y-values (vector or ND array) +% 'cc', coefficients (matrix). +% +% Constraints are linear combinations of derivatives of order 0 to N-2 +% according to +% +% cc(1,j)*y(x) + cc(2,j)*y'(x) + ... = yc(:,...,:,j), x = xc(j). +% +% The maximum number of rows for 'cc' is N-1. If omitted or empty 'cc' +% defaults to a single row of ones. Default for 'yc' is a zero array. +% +% EXAMPLES +% +% % Noisy data +% x = linspace(0,2*pi,100); +% y = sin(x) + 0.1*randn(size(x)); +% % Breaks +% breaks = [0:5,2*pi]; +% +% % Fit a spline of order 5 +% pp = splinefit(x,y,breaks,5); +% +% % Fit a spline of order 3 with periodic boundary conditions +% pp = splinefit(x,y,breaks,3,'p'); +% +% % Constraints: y(0) = 0, y'(0) = 1 and y(3) + y"(3) = 0 +% xc = [0 0 3]; +% yc = [0 1 0]; +% cc = [1 0 1; 0 1 0; 0 0 1]; +% con = struct('xc',xc,'yc',yc,'cc',cc); +% +% % Fit a cubic spline with 8 pieces and constraints +% pp = splinefit(x,y,8,con); +% +% % Fit a spline of order 6 with constraints and periodicity +% pp = splinefit(x,y,breaks,con,6,'p'); +% +% See also SPLINE, PPVAL, PPDIFF, PPINT + +% Author: jonas.lundgren@saabgroup.com, 2010. + +% 2009-05-06 Original SPLINEFIT. +% 2010-06-23 New version of SPLINEFIT based on B-splines. +% 2010-09-01 Robust fitting scheme added. +% 2010-09-01 Support for data containing NaNs. +% 2011-07-01 Robust fitting parameter added. + +% Check number of arguments +error(nargchk(3,8,nargin)); + +% Check arguments +[x,y,dim,breaks,n,periodic,beta,constr,weights] = arguments(varargin{:}); + +% Evaluate B-splines +base = splinebase(breaks,n); +pieces = base.pieces; +A = ppval(base,x); + +% Bin data +[junk,ibin] = histc(x,[-inf,breaks(2:end-1),inf]); %#ok + +% Sparse system matrix +mx = numel(x); +ii = [ibin; ones(n-1,mx)]; +ii = cumsum(ii,1); +jj = repmat(1:mx,n,1); +if periodic + ii = mod(ii-1,pieces) + 1; + A = sparse(ii,jj,A,pieces,mx); +else + A = sparse(ii,jj,A,pieces+n-1,mx); +end + +% Don't use the sparse solver for small problems +if pieces < 20*n/log(1.7*n) + A = full(A); +end + +% global randw; +% Solve +if isempty(constr) + % Solve Min norm(u*A-y) +% weights=ones(size(x)); + normweights=weights/size(A,1); + weightsmat=repmat(normweights,size(A,1),1); +% weightsmat +% pause +% randw +% A +% y + u = lsqsolve(A.*weightsmat,y.*weightsmat(1:dim,:),beta); +% u=lsqsolve(A,y,beta); +% u +% pause + else + % Evaluate constraints + B = evalcon(base,constr,periodic); + % Solve constraints + [Z,u0] = solvecon(B,constr); + % Solve Min norm(u*A-y), subject to u*B = yc + y = y - u0*A; + A = Z*A; + v = lsqsolve(A,y,beta); + u = u0 + v*Z; +end + +% Periodic expansion of solution +if periodic + jj = mod(0:pieces+n-2,pieces) + 1; + u = u(:,jj); +end + +% Compute polynomial coefficients +ii = [repmat(1:pieces,1,n); ones(n-1,n*pieces)]; +ii = cumsum(ii,1); +jj = repmat(1:n*pieces,n,1); +C = sparse(ii,jj,base.coefs,pieces+n-1,n*pieces); +coefs = u*C; +coefs = reshape(coefs,[],n); + +% Make piecewise polynomial +pp = mkpp(breaks,coefs,dim); + +%-------------------------------------------------------------------------- +function [x,y,dim,breaks,n,periodic,beta,constr,weights] = arguments(varargin) +%ARGUMENTS Lengthy input checking +% x Noisy data x-locations (1 x mx) +% y Noisy data y-values (prod(dim) x mx) +% dim Leading dimensions of y +% breaks Breaks (1 x (pieces+1)) +% n Spline order +% periodic True if periodic boundary conditions +% beta Robust fitting parameter, no robust fitting if beta = 0 +% constr Constraint structure +% constr.xc x-locations (1 x nx) +% constr.yc y-values (prod(dim) x nx) +% constr.cc Coefficients (?? x nx) +% weights weight vector for distances (Anton) + +% Reshape x-data +x = varargin{1}; +mx = numel(x); +x = reshape(x,1,mx); + +% Remove trailing singleton dimensions from y +y = varargin{2}; +dim = size(y); +while numel(dim) > 1 && dim(end) == 1 + dim(end) = []; +end +my = dim(end); + +% Leading dimensions of y +if numel(dim) > 1 + dim(end) = []; +else + dim = 1; +end + +% Reshape y-data +pdim = prod(dim); +y = reshape(y,pdim,my); + +% Check data size +if mx ~= my + mess = 'Last dimension of array y must equal length of vector x.'; + error('arguments:datasize',mess) +end + +% Treat NaNs in x-data +inan = find(isnan(x)); +if ~isempty(inan) + x(inan) = []; + y(:,inan) = []; + mess = 'All data points with NaN as x-location will be ignored.'; + warning('arguments:nanx',mess) +end + +% Treat NaNs in y-data +inan = find(any(isnan(y),1)); +if ~isempty(inan) + x(inan) = []; + y(:,inan) = []; + mess = 'All data points with NaN in their y-value will be ignored.'; + warning('arguments:nany',mess) +end + +% Check number of data points +mx = numel(x); +if mx == 0 + error('arguments:nodata','There must be at least one data point.') +end + +% Sort data +if any(diff(x) < 0) + [x,isort] = sort(x); + y = y(:,isort); +end + +% Breaks +if isscalar(varargin{3}) + % Number of pieces + p = varargin{3}; + if ~isreal(p) || ~isfinite(p) || p < 1 || fix(p) < p + mess = 'Argument #3 must be a vector or a positive integer.'; + error('arguments:breaks1',mess) + end + if x(1) < x(end) + % Interpolate breaks linearly from x-data + dx = diff(x); + ibreaks = linspace(1,mx,p+1); + [junk,ibin] = histc(ibreaks,[0,2:mx-1,mx+1]); %#ok + breaks = x(ibin) + dx(ibin).*(ibreaks-ibin); + else + breaks = x(1) + linspace(0,1,p+1); + end +else + % Vector of breaks + breaks = reshape(varargin{3},1,[]); + if isempty(breaks) || min(breaks) == max(breaks) + mess = 'At least two unique breaks are required.'; + error('arguments:breaks2',mess); + end +end + +% Unique breaks +if any(diff(breaks) <= 0) + breaks = unique(breaks); +end + +% Optional input defaults +n = 4; % Cubic splines +periodic = false; % No periodic boundaries +robust = false; % No robust fitting scheme +beta = 0.5; % Robust fitting parameter +constr = []; % No constraints +weights = ones(1,length(x)); % all ones weights + +% Loop over optional arguments +for k = 4:nargin + a = varargin{k}; + if ischar(a) && isscalar(a) && lower(a) == 'p' + % Periodic conditions + periodic = true; + elseif ischar(a) && isscalar(a) && lower(a) == 'r' + % Robust fitting scheme + robust = true; + elseif isreal(a) && isscalar(a) && isfinite(a) && a > 0 && a < 1 + % Robust fitting parameter + beta = a; + robust = true; + elseif isreal(a) && isscalar(a) && isfinite(a) && a > 0 && fix(a) == a + % Spline order + n = a; + elseif isstruct(a) && isscalar(a) + % Constraint structure + constr = a; + elseif all(size(x)==size(a)) + % weight vector + weights=a; + else + error('arguments:nonsense','Failed to interpret argument #%d.',k) + end +end + +% No robust fitting +if ~robust + beta = 0; +end + +% Check exterior data +h = diff(breaks); +xlim1 = breaks(1) - 0.01*h(1); +xlim2 = breaks(end) + 0.01*h(end); +if x(1) < xlim1 || x(end) > xlim2 + if periodic + % Move data inside domain + P = breaks(end) - breaks(1); + x = mod(x-breaks(1),P) + breaks(1); + % Sort + [x,isort] = sort(x); + y = y(:,isort); + else + mess = 'Some data points are outside the spline domain.'; + warning('arguments:exteriordata',mess) + end +end + +% Return +if isempty(constr) + return +end + +% Unpack constraints +xc = []; +yc = []; +cc = []; +names = fieldnames(constr); +for k = 1:numel(names) + switch names{k} + case {'xc'} + xc = constr.xc; + case {'yc'} + yc = constr.yc; + case {'cc'} + cc = constr.cc; + otherwise + mess = 'Unknown field ''%s'' in constraint structure.'; + warning('arguments:unknownfield',mess,names{k}) + end +end + +% Check xc +if isempty(xc) + mess = 'Constraints contains no x-locations.'; + error('arguments:emptyxc',mess) +else + nx = numel(xc); + xc = reshape(xc,1,nx); +end + +% Check yc +if isempty(yc) + % Zero array + yc = zeros(pdim,nx); +elseif numel(yc) == 1 + % Constant array + yc = zeros(pdim,nx) + yc; +elseif numel(yc) ~= pdim*nx + % Malformed array + error('arguments:ycsize','Cannot reshape yc to size %dx%d.',pdim,nx) +else + % Reshape array + yc = reshape(yc,pdim,nx); +end + +% Check cc +if isempty(cc) + cc = ones(size(xc)); +elseif numel(size(cc)) ~= 2 + error('arguments:ccsize1','Constraint coefficients cc must be 2D.') +elseif size(cc,2) ~= nx + mess = 'Last dimension of cc must equal length of xc.'; + error('arguments:ccsize2',mess) +end + +% Check high order derivatives +if size(cc,1) >= n + if any(any(cc(n:end,:))) + mess = 'Constraints involve derivatives of order %d or larger.'; + error('arguments:difforder',mess,n-1) + end + cc = cc(1:n-1,:); +end + +% Check exterior constraints +if min(xc) < xlim1 || max(xc) > xlim2 + if periodic + % Move constraints inside domain + P = breaks(end) - breaks(1); + xc = mod(xc-breaks(1),P) + breaks(1); + else + mess = 'Some constraints are outside the spline domain.'; + warning('arguments:exteriorconstr',mess) + end +end + +% Pack constraints +constr = struct('xc',xc,'yc',yc,'cc',cc); + + +%-------------------------------------------------------------------------- +function pp = splinebase(breaks,n) +%SPLINEBASE Generate B-spline base PP of order N for breaks BREAKS + +breaks = breaks(:); % Breaks +breaks0 = breaks'; % Initial breaks +h = diff(breaks); % Spacing +pieces = numel(h); % Number of pieces +deg = n - 1; % Polynomial degree + +% Extend breaks periodically +if deg > 0 + if deg <= pieces + hcopy = h; + else + hcopy = repmat(h,ceil(deg/pieces),1); + end + % to the left + hl = hcopy(end:-1:end-deg+1); + bl = breaks(1) - cumsum(hl); + % and to the right + hr = hcopy(1:deg); + br = breaks(end) + cumsum(hr); + % Add breaks + breaks = [bl(deg:-1:1); breaks; br]; + h = diff(breaks); + pieces = numel(h); +end + +% Initiate polynomial coefficients +coefs = zeros(n*pieces,n); +coefs(1:n:end,1) = 1; + +% Expand h +ii = [1:pieces; ones(deg,pieces)]; +ii = cumsum(ii,1); +ii = min(ii,pieces); +H = h(ii(:)); + +% Recursive generation of B-splines +for k = 2:n + % Antiderivatives of splines + for j = 1:k-1 + coefs(:,j) = coefs(:,j).*H/(k-j); + end + Q = sum(coefs,2); + Q = reshape(Q,n,pieces); + Q = cumsum(Q,1); + c0 = [zeros(1,pieces); Q(1:deg,:)]; + coefs(:,k) = c0(:); + % Normalize antiderivatives by max value + fmax = repmat(Q(n,:),n,1); + fmax = fmax(:); + for j = 1:k + coefs(:,j) = coefs(:,j)./fmax; + end + % Diff of adjacent antiderivatives + coefs(1:end-deg,1:k) = coefs(1:end-deg,1:k) - coefs(n:end,1:k); + coefs(1:n:end,k) = 0; +end + +% Scale coefficients +scale = ones(size(H)); +for k = 1:n-1 + scale = scale./H; + coefs(:,n-k) = scale.*coefs(:,n-k); +end + +% Reduce number of pieces +pieces = pieces - 2*deg; + +% Sort coefficients by interval number +ii = [n*(1:pieces); deg*ones(deg,pieces)]; +ii = cumsum(ii,1); +coefs = coefs(ii(:),:); + +% Make piecewise polynomial +pp = mkpp(breaks0,coefs,n); + + +%-------------------------------------------------------------------------- +function B = evalcon(base,constr,periodic) +%EVALCON Evaluate linear constraints + +% Unpack structures +breaks = base.breaks; +pieces = base.pieces; +n = base.order; +xc = constr.xc; +cc = constr.cc; + +% Bin data +[junk,ibin] = histc(xc,[-inf,breaks(2:end-1),inf]); %#ok + +% Evaluate constraints +nx = numel(xc); +B0 = zeros(n,nx); +for k = 1:size(cc,1) + if any(cc(k,:)) + B0 = B0 + repmat(cc(k,:),n,1).*ppval(base,xc); + end + % Differentiate base + coefs = base.coefs(:,1:n-k); + for j = 1:n-k-1 + coefs(:,j) = (n-k-j+1)*coefs(:,j); + end + base.coefs = coefs; + base.order = n-k; +end + +% Sparse output +ii = [ibin; ones(n-1,nx)]; +ii = cumsum(ii,1); +jj = repmat(1:nx,n,1); +if periodic + ii = mod(ii-1,pieces) + 1; + B = sparse(ii,jj,B0,pieces,nx); +else + B = sparse(ii,jj,B0,pieces+n-1,nx); +end + + +%-------------------------------------------------------------------------- +function [Z,u0] = solvecon(B,constr) +%SOLVECON Find a particular solution u0 and null space Z (Z*B = 0) +% for constraint equation u*B = yc. + +yc = constr.yc; +tol = 1000*eps; + +% Remove blank rows +ii = any(B,2); +B2 = full(B(ii,:)); + +% Null space of B2 +if isempty(B2) + Z2 = []; +else + % QR decomposition with column permutation + [Q,R,dummy] = qr(B2); %#ok + R = abs(R); + jj = all(R < R(1)*tol, 2); + Z2 = Q(:,jj)'; +end + +% Sizes +[m,ncon] = size(B); +m2 = size(B2,1); +nz = size(Z2,1); + +% Sparse null space of B +Z = sparse(nz+1:nz+m-m2,find(~ii),1,nz+m-m2,m); +Z(1:nz,ii) = Z2; + +% Warning rank deficient +if nz + ncon > m2 + mess = 'Rank deficient constraints, rank = %d.'; + warning('solvecon:deficient',mess,m2-nz); +end + +% Particular solution +u0 = zeros(size(yc,1),m); +if any(yc(:)) + % Non-homogeneous case + u0(:,ii) = yc/B2; + % Check solution + if norm(u0*B - yc,'fro') > norm(yc,'fro')*tol + mess = 'Inconsistent constraints. No solution within tolerance.'; + error('solvecon:inconsistent',mess) + end +end + + +%-------------------------------------------------------------------------- +function u = lsqsolve(A,y,beta) +%LSQSOLVE Solve Min norm(u*A-y) + +% Avoid sparse-complex limitations +if issparse(A) && ~isreal(y) + A = full(A); +end + +% Solution +u = y/A; + +% Robust fitting +if beta > 0 + [m,n] = size(y); + alpha = 0.5*beta/(1-beta)/m; + for k = 1:3 + % Residual + r = u*A - y; + rr = r.*conj(r); + rrmean = sum(rr,2)/n; + rrmean(~rrmean) = 1; + rrhat = (alpha./rrmean)'*rr; + % Weights + w = exp(-rrhat); + spw = spdiags(w',0,n,n); + % Solve weighted problem + u = (y*spw)/(A*spw); + end +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/splinefit.png b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/splinefit.png new file mode 100644 index 0000000000000000000000000000000000000000..398cddfdb34347c910993867cef8be1981be856c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/splinefit/splinefit.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:259845451b08c6369401f0da31bc8e1a0ae2988924355c6177cc503b57fd2fea +size 83106 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/vectorToMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/vectorToMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..e55ee05fcf2009ca50793f343d17431c14c3451d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/DCT/utils/vectorToMatrices.m @@ -0,0 +1,38 @@ +function [X Y]=vectorToMatrices(x,stateInfo) +% transforms the state vector X +% to matrix representation X and Y +% X and Y are FxN matrices +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=stateInfo.F; N=stateInfo.N; +% +X=zeros(F,N); % x-positions +Y=zeros(F,N); % y-positions + +% naive implementation +% targetsExist=stateInfo.targetsExist; +% +% xind=1; +% for i=1:N +% frames=targetsExist(i,1):targetsExist(i,2); +% nFrames=numel(frames); +% X(frames,i)=(x(xind:2:xind+2*nFrames-1)); +% +% Y(frames,i)=(x(xind+1:2:xind+2*nFrames)); +% xind=xind+nFrames*2; +% end + + +% vectorized implementation +tiInd=find(stateInfo.tiToInd); +X(tiInd)=x(1:2:end); +Y(tiInd)=x(2:2:end); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/Config.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/Config.txt new file mode 100644 index 0000000000000000000000000000000000000000..82380b8c5c37ed5afc0fc7ce7ccb290c5892f0c1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/Config.txt @@ -0,0 +1,41 @@ +################################################################################### +## Main Parameters for Hierarchical Dense Structures Revealing Based Tracker +################################################################################### +#VERSION +2 + +#INPUT_DATA_FILE_NAME +MVI_39931 + +#INPUT_VIDEO_FILE_PATH +imagelist.txt + +#INPUT_DETECTION_FILE_PATH +detections.txt + +#OUTPUT_TRAJECTORY_FILE_PATH +result\ + +#OUTPUT_SPEED_FILE_PATH +result\ + +#IMAGE_WIDTH +960 + +#IMAGE_HEIGHT +540 + +#TOTAL_FRAME_NUMBER +1270 + +#CAR_MINIMAL_WIDTH +5 + +#CAR_MINIMAL_HEIGHT +5 + +#SEGMENT_SIZE_EACH_LAYER +10,4 + +#TRACK_KARY_LAYER +3 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphDecompose.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphDecompose.dll new file mode 100644 index 0000000000000000000000000000000000000000..947203fd1b7a55e21e1c2c1fa41e3a567ef79840 Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphDecompose.dll differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker.exe b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker.exe new file mode 100644 index 0000000000000000000000000000000000000000..0ec6a9a69417b64a453fe9ec6f2859b71743d370 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ab82defb6e74c0d176d6b6d365756b19a39a2e59d7d93b1957dc921955b69f2 +size 267776 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker.pdb b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker.pdb new file mode 100644 index 0000000000000000000000000000000000000000..a74dc28e5b8ad7e7ee702558f93d2bf24fa668e2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker.pdb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:caf5ff3a0e836591837acfcbdea5622a368e1e59a0227232d80ecffa0d85a741 +size 1977344 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker_Config.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker_Config.txt new file mode 100644 index 0000000000000000000000000000000000000000..464f8b02d5ac0625e3e7b21cd450bf97a954e172 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/GraphMultiCarTracker_Config.txt @@ -0,0 +1,41 @@ +################################################################################### +## Main Parameters for Hierarchical Dense Structures Revealing Based Tracker +################################################################################### +#VERSION +2 + +#INPUT_DATA_FILE_NAME +Cloudy_MVI_39501 + +#INPUT_VIDEO_FILE_PATH +imagelist.txt + +#INPUT_DETECTION_FILE_PATH +F:\Vehicle-Experiment\Car-Debug\Results\Cloudy_MVI_39501_Det_FN_0_FP_0.txt + +#OUTPUT_TRAJECTORY_FILE_PATH +result\ + +#OUTPUT_SPEED_FILE_PATH +result\ + +#IMAGE_WIDTH +960 + +#IMAGE_HEIGHT +540 + +#TOTAL_FRAME_NUMBER +540 + +#CAR_MINIMAL_WIDTH +5 + +#CAR_MINIMAL_HEIGHT +5 + +#SEGMENT_SIZE_EACH_LAYER +10,3 + +#TRACK_KARY_LAYER +3 \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/imagelist.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/imagelist.txt new file mode 100644 index 0000000000000000000000000000000000000000..38fd90844a3607d82b916a5ffe2aa5605bae312a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/imagelist.txt @@ -0,0 +1,1270 @@ +D:/DETRAC-Images/MVI_39931\img00001.jpg +D:/DETRAC-Images/MVI_39931\img00002.jpg +D:/DETRAC-Images/MVI_39931\img00003.jpg +D:/DETRAC-Images/MVI_39931\img00004.jpg +D:/DETRAC-Images/MVI_39931\img00005.jpg +D:/DETRAC-Images/MVI_39931\img00006.jpg +D:/DETRAC-Images/MVI_39931\img00007.jpg +D:/DETRAC-Images/MVI_39931\img00008.jpg +D:/DETRAC-Images/MVI_39931\img00009.jpg +D:/DETRAC-Images/MVI_39931\img00010.jpg +D:/DETRAC-Images/MVI_39931\img00011.jpg +D:/DETRAC-Images/MVI_39931\img00012.jpg +D:/DETRAC-Images/MVI_39931\img00013.jpg +D:/DETRAC-Images/MVI_39931\img00014.jpg +D:/DETRAC-Images/MVI_39931\img00015.jpg +D:/DETRAC-Images/MVI_39931\img00016.jpg +D:/DETRAC-Images/MVI_39931\img00017.jpg +D:/DETRAC-Images/MVI_39931\img00018.jpg +D:/DETRAC-Images/MVI_39931\img00019.jpg +D:/DETRAC-Images/MVI_39931\img00020.jpg +D:/DETRAC-Images/MVI_39931\img00021.jpg +D:/DETRAC-Images/MVI_39931\img00022.jpg +D:/DETRAC-Images/MVI_39931\img00023.jpg +D:/DETRAC-Images/MVI_39931\img00024.jpg +D:/DETRAC-Images/MVI_39931\img00025.jpg +D:/DETRAC-Images/MVI_39931\img00026.jpg +D:/DETRAC-Images/MVI_39931\img00027.jpg +D:/DETRAC-Images/MVI_39931\img00028.jpg +D:/DETRAC-Images/MVI_39931\img00029.jpg +D:/DETRAC-Images/MVI_39931\img00030.jpg +D:/DETRAC-Images/MVI_39931\img00031.jpg +D:/DETRAC-Images/MVI_39931\img00032.jpg +D:/DETRAC-Images/MVI_39931\img00033.jpg +D:/DETRAC-Images/MVI_39931\img00034.jpg +D:/DETRAC-Images/MVI_39931\img00035.jpg +D:/DETRAC-Images/MVI_39931\img00036.jpg +D:/DETRAC-Images/MVI_39931\img00037.jpg +D:/DETRAC-Images/MVI_39931\img00038.jpg +D:/DETRAC-Images/MVI_39931\img00039.jpg +D:/DETRAC-Images/MVI_39931\img00040.jpg +D:/DETRAC-Images/MVI_39931\img00041.jpg +D:/DETRAC-Images/MVI_39931\img00042.jpg +D:/DETRAC-Images/MVI_39931\img00043.jpg +D:/DETRAC-Images/MVI_39931\img00044.jpg +D:/DETRAC-Images/MVI_39931\img00045.jpg +D:/DETRAC-Images/MVI_39931\img00046.jpg +D:/DETRAC-Images/MVI_39931\img00047.jpg +D:/DETRAC-Images/MVI_39931\img00048.jpg +D:/DETRAC-Images/MVI_39931\img00049.jpg +D:/DETRAC-Images/MVI_39931\img00050.jpg +D:/DETRAC-Images/MVI_39931\img00051.jpg +D:/DETRAC-Images/MVI_39931\img00052.jpg +D:/DETRAC-Images/MVI_39931\img00053.jpg +D:/DETRAC-Images/MVI_39931\img00054.jpg +D:/DETRAC-Images/MVI_39931\img00055.jpg +D:/DETRAC-Images/MVI_39931\img00056.jpg +D:/DETRAC-Images/MVI_39931\img00057.jpg +D:/DETRAC-Images/MVI_39931\img00058.jpg +D:/DETRAC-Images/MVI_39931\img00059.jpg +D:/DETRAC-Images/MVI_39931\img00060.jpg +D:/DETRAC-Images/MVI_39931\img00061.jpg +D:/DETRAC-Images/MVI_39931\img00062.jpg +D:/DETRAC-Images/MVI_39931\img00063.jpg +D:/DETRAC-Images/MVI_39931\img00064.jpg +D:/DETRAC-Images/MVI_39931\img00065.jpg +D:/DETRAC-Images/MVI_39931\img00066.jpg +D:/DETRAC-Images/MVI_39931\img00067.jpg +D:/DETRAC-Images/MVI_39931\img00068.jpg +D:/DETRAC-Images/MVI_39931\img00069.jpg +D:/DETRAC-Images/MVI_39931\img00070.jpg +D:/DETRAC-Images/MVI_39931\img00071.jpg +D:/DETRAC-Images/MVI_39931\img00072.jpg +D:/DETRAC-Images/MVI_39931\img00073.jpg +D:/DETRAC-Images/MVI_39931\img00074.jpg +D:/DETRAC-Images/MVI_39931\img00075.jpg +D:/DETRAC-Images/MVI_39931\img00076.jpg +D:/DETRAC-Images/MVI_39931\img00077.jpg +D:/DETRAC-Images/MVI_39931\img00078.jpg +D:/DETRAC-Images/MVI_39931\img00079.jpg +D:/DETRAC-Images/MVI_39931\img00080.jpg +D:/DETRAC-Images/MVI_39931\img00081.jpg +D:/DETRAC-Images/MVI_39931\img00082.jpg +D:/DETRAC-Images/MVI_39931\img00083.jpg +D:/DETRAC-Images/MVI_39931\img00084.jpg +D:/DETRAC-Images/MVI_39931\img00085.jpg +D:/DETRAC-Images/MVI_39931\img00086.jpg +D:/DETRAC-Images/MVI_39931\img00087.jpg +D:/DETRAC-Images/MVI_39931\img00088.jpg +D:/DETRAC-Images/MVI_39931\img00089.jpg +D:/DETRAC-Images/MVI_39931\img00090.jpg +D:/DETRAC-Images/MVI_39931\img00091.jpg +D:/DETRAC-Images/MVI_39931\img00092.jpg +D:/DETRAC-Images/MVI_39931\img00093.jpg +D:/DETRAC-Images/MVI_39931\img00094.jpg +D:/DETRAC-Images/MVI_39931\img00095.jpg +D:/DETRAC-Images/MVI_39931\img00096.jpg +D:/DETRAC-Images/MVI_39931\img00097.jpg +D:/DETRAC-Images/MVI_39931\img00098.jpg +D:/DETRAC-Images/MVI_39931\img00099.jpg +D:/DETRAC-Images/MVI_39931\img00100.jpg +D:/DETRAC-Images/MVI_39931\img00101.jpg +D:/DETRAC-Images/MVI_39931\img00102.jpg +D:/DETRAC-Images/MVI_39931\img00103.jpg +D:/DETRAC-Images/MVI_39931\img00104.jpg +D:/DETRAC-Images/MVI_39931\img00105.jpg +D:/DETRAC-Images/MVI_39931\img00106.jpg +D:/DETRAC-Images/MVI_39931\img00107.jpg +D:/DETRAC-Images/MVI_39931\img00108.jpg +D:/DETRAC-Images/MVI_39931\img00109.jpg +D:/DETRAC-Images/MVI_39931\img00110.jpg +D:/DETRAC-Images/MVI_39931\img00111.jpg +D:/DETRAC-Images/MVI_39931\img00112.jpg +D:/DETRAC-Images/MVI_39931\img00113.jpg +D:/DETRAC-Images/MVI_39931\img00114.jpg +D:/DETRAC-Images/MVI_39931\img00115.jpg +D:/DETRAC-Images/MVI_39931\img00116.jpg +D:/DETRAC-Images/MVI_39931\img00117.jpg +D:/DETRAC-Images/MVI_39931\img00118.jpg +D:/DETRAC-Images/MVI_39931\img00119.jpg +D:/DETRAC-Images/MVI_39931\img00120.jpg +D:/DETRAC-Images/MVI_39931\img00121.jpg +D:/DETRAC-Images/MVI_39931\img00122.jpg +D:/DETRAC-Images/MVI_39931\img00123.jpg +D:/DETRAC-Images/MVI_39931\img00124.jpg +D:/DETRAC-Images/MVI_39931\img00125.jpg +D:/DETRAC-Images/MVI_39931\img00126.jpg +D:/DETRAC-Images/MVI_39931\img00127.jpg +D:/DETRAC-Images/MVI_39931\img00128.jpg +D:/DETRAC-Images/MVI_39931\img00129.jpg +D:/DETRAC-Images/MVI_39931\img00130.jpg +D:/DETRAC-Images/MVI_39931\img00131.jpg +D:/DETRAC-Images/MVI_39931\img00132.jpg +D:/DETRAC-Images/MVI_39931\img00133.jpg +D:/DETRAC-Images/MVI_39931\img00134.jpg +D:/DETRAC-Images/MVI_39931\img00135.jpg +D:/DETRAC-Images/MVI_39931\img00136.jpg +D:/DETRAC-Images/MVI_39931\img00137.jpg +D:/DETRAC-Images/MVI_39931\img00138.jpg +D:/DETRAC-Images/MVI_39931\img00139.jpg +D:/DETRAC-Images/MVI_39931\img00140.jpg +D:/DETRAC-Images/MVI_39931\img00141.jpg +D:/DETRAC-Images/MVI_39931\img00142.jpg +D:/DETRAC-Images/MVI_39931\img00143.jpg +D:/DETRAC-Images/MVI_39931\img00144.jpg +D:/DETRAC-Images/MVI_39931\img00145.jpg +D:/DETRAC-Images/MVI_39931\img00146.jpg +D:/DETRAC-Images/MVI_39931\img00147.jpg +D:/DETRAC-Images/MVI_39931\img00148.jpg +D:/DETRAC-Images/MVI_39931\img00149.jpg +D:/DETRAC-Images/MVI_39931\img00150.jpg +D:/DETRAC-Images/MVI_39931\img00151.jpg +D:/DETRAC-Images/MVI_39931\img00152.jpg +D:/DETRAC-Images/MVI_39931\img00153.jpg +D:/DETRAC-Images/MVI_39931\img00154.jpg +D:/DETRAC-Images/MVI_39931\img00155.jpg +D:/DETRAC-Images/MVI_39931\img00156.jpg +D:/DETRAC-Images/MVI_39931\img00157.jpg +D:/DETRAC-Images/MVI_39931\img00158.jpg +D:/DETRAC-Images/MVI_39931\img00159.jpg +D:/DETRAC-Images/MVI_39931\img00160.jpg +D:/DETRAC-Images/MVI_39931\img00161.jpg +D:/DETRAC-Images/MVI_39931\img00162.jpg +D:/DETRAC-Images/MVI_39931\img00163.jpg +D:/DETRAC-Images/MVI_39931\img00164.jpg +D:/DETRAC-Images/MVI_39931\img00165.jpg +D:/DETRAC-Images/MVI_39931\img00166.jpg +D:/DETRAC-Images/MVI_39931\img00167.jpg +D:/DETRAC-Images/MVI_39931\img00168.jpg +D:/DETRAC-Images/MVI_39931\img00169.jpg +D:/DETRAC-Images/MVI_39931\img00170.jpg +D:/DETRAC-Images/MVI_39931\img00171.jpg +D:/DETRAC-Images/MVI_39931\img00172.jpg +D:/DETRAC-Images/MVI_39931\img00173.jpg +D:/DETRAC-Images/MVI_39931\img00174.jpg +D:/DETRAC-Images/MVI_39931\img00175.jpg +D:/DETRAC-Images/MVI_39931\img00176.jpg +D:/DETRAC-Images/MVI_39931\img00177.jpg +D:/DETRAC-Images/MVI_39931\img00178.jpg +D:/DETRAC-Images/MVI_39931\img00179.jpg +D:/DETRAC-Images/MVI_39931\img00180.jpg +D:/DETRAC-Images/MVI_39931\img00181.jpg +D:/DETRAC-Images/MVI_39931\img00182.jpg +D:/DETRAC-Images/MVI_39931\img00183.jpg +D:/DETRAC-Images/MVI_39931\img00184.jpg +D:/DETRAC-Images/MVI_39931\img00185.jpg +D:/DETRAC-Images/MVI_39931\img00186.jpg +D:/DETRAC-Images/MVI_39931\img00187.jpg +D:/DETRAC-Images/MVI_39931\img00188.jpg +D:/DETRAC-Images/MVI_39931\img00189.jpg +D:/DETRAC-Images/MVI_39931\img00190.jpg +D:/DETRAC-Images/MVI_39931\img00191.jpg +D:/DETRAC-Images/MVI_39931\img00192.jpg +D:/DETRAC-Images/MVI_39931\img00193.jpg +D:/DETRAC-Images/MVI_39931\img00194.jpg +D:/DETRAC-Images/MVI_39931\img00195.jpg +D:/DETRAC-Images/MVI_39931\img00196.jpg +D:/DETRAC-Images/MVI_39931\img00197.jpg +D:/DETRAC-Images/MVI_39931\img00198.jpg +D:/DETRAC-Images/MVI_39931\img00199.jpg +D:/DETRAC-Images/MVI_39931\img00200.jpg +D:/DETRAC-Images/MVI_39931\img00201.jpg +D:/DETRAC-Images/MVI_39931\img00202.jpg +D:/DETRAC-Images/MVI_39931\img00203.jpg +D:/DETRAC-Images/MVI_39931\img00204.jpg +D:/DETRAC-Images/MVI_39931\img00205.jpg +D:/DETRAC-Images/MVI_39931\img00206.jpg +D:/DETRAC-Images/MVI_39931\img00207.jpg +D:/DETRAC-Images/MVI_39931\img00208.jpg +D:/DETRAC-Images/MVI_39931\img00209.jpg +D:/DETRAC-Images/MVI_39931\img00210.jpg +D:/DETRAC-Images/MVI_39931\img00211.jpg +D:/DETRAC-Images/MVI_39931\img00212.jpg +D:/DETRAC-Images/MVI_39931\img00213.jpg +D:/DETRAC-Images/MVI_39931\img00214.jpg +D:/DETRAC-Images/MVI_39931\img00215.jpg +D:/DETRAC-Images/MVI_39931\img00216.jpg +D:/DETRAC-Images/MVI_39931\img00217.jpg +D:/DETRAC-Images/MVI_39931\img00218.jpg +D:/DETRAC-Images/MVI_39931\img00219.jpg +D:/DETRAC-Images/MVI_39931\img00220.jpg +D:/DETRAC-Images/MVI_39931\img00221.jpg +D:/DETRAC-Images/MVI_39931\img00222.jpg +D:/DETRAC-Images/MVI_39931\img00223.jpg +D:/DETRAC-Images/MVI_39931\img00224.jpg +D:/DETRAC-Images/MVI_39931\img00225.jpg +D:/DETRAC-Images/MVI_39931\img00226.jpg +D:/DETRAC-Images/MVI_39931\img00227.jpg +D:/DETRAC-Images/MVI_39931\img00228.jpg +D:/DETRAC-Images/MVI_39931\img00229.jpg +D:/DETRAC-Images/MVI_39931\img00230.jpg +D:/DETRAC-Images/MVI_39931\img00231.jpg +D:/DETRAC-Images/MVI_39931\img00232.jpg +D:/DETRAC-Images/MVI_39931\img00233.jpg +D:/DETRAC-Images/MVI_39931\img00234.jpg +D:/DETRAC-Images/MVI_39931\img00235.jpg +D:/DETRAC-Images/MVI_39931\img00236.jpg +D:/DETRAC-Images/MVI_39931\img00237.jpg +D:/DETRAC-Images/MVI_39931\img00238.jpg +D:/DETRAC-Images/MVI_39931\img00239.jpg +D:/DETRAC-Images/MVI_39931\img00240.jpg +D:/DETRAC-Images/MVI_39931\img00241.jpg +D:/DETRAC-Images/MVI_39931\img00242.jpg +D:/DETRAC-Images/MVI_39931\img00243.jpg +D:/DETRAC-Images/MVI_39931\img00244.jpg +D:/DETRAC-Images/MVI_39931\img00245.jpg +D:/DETRAC-Images/MVI_39931\img00246.jpg +D:/DETRAC-Images/MVI_39931\img00247.jpg +D:/DETRAC-Images/MVI_39931\img00248.jpg +D:/DETRAC-Images/MVI_39931\img00249.jpg +D:/DETRAC-Images/MVI_39931\img00250.jpg +D:/DETRAC-Images/MVI_39931\img00251.jpg +D:/DETRAC-Images/MVI_39931\img00252.jpg +D:/DETRAC-Images/MVI_39931\img00253.jpg +D:/DETRAC-Images/MVI_39931\img00254.jpg +D:/DETRAC-Images/MVI_39931\img00255.jpg +D:/DETRAC-Images/MVI_39931\img00256.jpg +D:/DETRAC-Images/MVI_39931\img00257.jpg +D:/DETRAC-Images/MVI_39931\img00258.jpg +D:/DETRAC-Images/MVI_39931\img00259.jpg +D:/DETRAC-Images/MVI_39931\img00260.jpg +D:/DETRAC-Images/MVI_39931\img00261.jpg +D:/DETRAC-Images/MVI_39931\img00262.jpg +D:/DETRAC-Images/MVI_39931\img00263.jpg +D:/DETRAC-Images/MVI_39931\img00264.jpg +D:/DETRAC-Images/MVI_39931\img00265.jpg +D:/DETRAC-Images/MVI_39931\img00266.jpg +D:/DETRAC-Images/MVI_39931\img00267.jpg +D:/DETRAC-Images/MVI_39931\img00268.jpg +D:/DETRAC-Images/MVI_39931\img00269.jpg +D:/DETRAC-Images/MVI_39931\img00270.jpg +D:/DETRAC-Images/MVI_39931\img00271.jpg +D:/DETRAC-Images/MVI_39931\img00272.jpg +D:/DETRAC-Images/MVI_39931\img00273.jpg +D:/DETRAC-Images/MVI_39931\img00274.jpg +D:/DETRAC-Images/MVI_39931\img00275.jpg +D:/DETRAC-Images/MVI_39931\img00276.jpg +D:/DETRAC-Images/MVI_39931\img00277.jpg +D:/DETRAC-Images/MVI_39931\img00278.jpg +D:/DETRAC-Images/MVI_39931\img00279.jpg +D:/DETRAC-Images/MVI_39931\img00280.jpg +D:/DETRAC-Images/MVI_39931\img00281.jpg +D:/DETRAC-Images/MVI_39931\img00282.jpg +D:/DETRAC-Images/MVI_39931\img00283.jpg +D:/DETRAC-Images/MVI_39931\img00284.jpg +D:/DETRAC-Images/MVI_39931\img00285.jpg +D:/DETRAC-Images/MVI_39931\img00286.jpg +D:/DETRAC-Images/MVI_39931\img00287.jpg +D:/DETRAC-Images/MVI_39931\img00288.jpg +D:/DETRAC-Images/MVI_39931\img00289.jpg +D:/DETRAC-Images/MVI_39931\img00290.jpg +D:/DETRAC-Images/MVI_39931\img00291.jpg +D:/DETRAC-Images/MVI_39931\img00292.jpg +D:/DETRAC-Images/MVI_39931\img00293.jpg +D:/DETRAC-Images/MVI_39931\img00294.jpg +D:/DETRAC-Images/MVI_39931\img00295.jpg +D:/DETRAC-Images/MVI_39931\img00296.jpg +D:/DETRAC-Images/MVI_39931\img00297.jpg +D:/DETRAC-Images/MVI_39931\img00298.jpg +D:/DETRAC-Images/MVI_39931\img00299.jpg +D:/DETRAC-Images/MVI_39931\img00300.jpg +D:/DETRAC-Images/MVI_39931\img00301.jpg +D:/DETRAC-Images/MVI_39931\img00302.jpg +D:/DETRAC-Images/MVI_39931\img00303.jpg +D:/DETRAC-Images/MVI_39931\img00304.jpg +D:/DETRAC-Images/MVI_39931\img00305.jpg +D:/DETRAC-Images/MVI_39931\img00306.jpg +D:/DETRAC-Images/MVI_39931\img00307.jpg +D:/DETRAC-Images/MVI_39931\img00308.jpg +D:/DETRAC-Images/MVI_39931\img00309.jpg +D:/DETRAC-Images/MVI_39931\img00310.jpg +D:/DETRAC-Images/MVI_39931\img00311.jpg +D:/DETRAC-Images/MVI_39931\img00312.jpg +D:/DETRAC-Images/MVI_39931\img00313.jpg +D:/DETRAC-Images/MVI_39931\img00314.jpg +D:/DETRAC-Images/MVI_39931\img00315.jpg +D:/DETRAC-Images/MVI_39931\img00316.jpg +D:/DETRAC-Images/MVI_39931\img00317.jpg +D:/DETRAC-Images/MVI_39931\img00318.jpg +D:/DETRAC-Images/MVI_39931\img00319.jpg +D:/DETRAC-Images/MVI_39931\img00320.jpg +D:/DETRAC-Images/MVI_39931\img00321.jpg +D:/DETRAC-Images/MVI_39931\img00322.jpg +D:/DETRAC-Images/MVI_39931\img00323.jpg +D:/DETRAC-Images/MVI_39931\img00324.jpg +D:/DETRAC-Images/MVI_39931\img00325.jpg +D:/DETRAC-Images/MVI_39931\img00326.jpg +D:/DETRAC-Images/MVI_39931\img00327.jpg +D:/DETRAC-Images/MVI_39931\img00328.jpg +D:/DETRAC-Images/MVI_39931\img00329.jpg +D:/DETRAC-Images/MVI_39931\img00330.jpg +D:/DETRAC-Images/MVI_39931\img00331.jpg +D:/DETRAC-Images/MVI_39931\img00332.jpg +D:/DETRAC-Images/MVI_39931\img00333.jpg +D:/DETRAC-Images/MVI_39931\img00334.jpg +D:/DETRAC-Images/MVI_39931\img00335.jpg +D:/DETRAC-Images/MVI_39931\img00336.jpg +D:/DETRAC-Images/MVI_39931\img00337.jpg +D:/DETRAC-Images/MVI_39931\img00338.jpg +D:/DETRAC-Images/MVI_39931\img00339.jpg +D:/DETRAC-Images/MVI_39931\img00340.jpg +D:/DETRAC-Images/MVI_39931\img00341.jpg +D:/DETRAC-Images/MVI_39931\img00342.jpg +D:/DETRAC-Images/MVI_39931\img00343.jpg +D:/DETRAC-Images/MVI_39931\img00344.jpg +D:/DETRAC-Images/MVI_39931\img00345.jpg +D:/DETRAC-Images/MVI_39931\img00346.jpg +D:/DETRAC-Images/MVI_39931\img00347.jpg +D:/DETRAC-Images/MVI_39931\img00348.jpg +D:/DETRAC-Images/MVI_39931\img00349.jpg +D:/DETRAC-Images/MVI_39931\img00350.jpg +D:/DETRAC-Images/MVI_39931\img00351.jpg +D:/DETRAC-Images/MVI_39931\img00352.jpg +D:/DETRAC-Images/MVI_39931\img00353.jpg +D:/DETRAC-Images/MVI_39931\img00354.jpg +D:/DETRAC-Images/MVI_39931\img00355.jpg +D:/DETRAC-Images/MVI_39931\img00356.jpg +D:/DETRAC-Images/MVI_39931\img00357.jpg +D:/DETRAC-Images/MVI_39931\img00358.jpg +D:/DETRAC-Images/MVI_39931\img00359.jpg +D:/DETRAC-Images/MVI_39931\img00360.jpg +D:/DETRAC-Images/MVI_39931\img00361.jpg +D:/DETRAC-Images/MVI_39931\img00362.jpg +D:/DETRAC-Images/MVI_39931\img00363.jpg +D:/DETRAC-Images/MVI_39931\img00364.jpg +D:/DETRAC-Images/MVI_39931\img00365.jpg +D:/DETRAC-Images/MVI_39931\img00366.jpg +D:/DETRAC-Images/MVI_39931\img00367.jpg +D:/DETRAC-Images/MVI_39931\img00368.jpg +D:/DETRAC-Images/MVI_39931\img00369.jpg +D:/DETRAC-Images/MVI_39931\img00370.jpg +D:/DETRAC-Images/MVI_39931\img00371.jpg +D:/DETRAC-Images/MVI_39931\img00372.jpg +D:/DETRAC-Images/MVI_39931\img00373.jpg +D:/DETRAC-Images/MVI_39931\img00374.jpg +D:/DETRAC-Images/MVI_39931\img00375.jpg +D:/DETRAC-Images/MVI_39931\img00376.jpg +D:/DETRAC-Images/MVI_39931\img00377.jpg +D:/DETRAC-Images/MVI_39931\img00378.jpg +D:/DETRAC-Images/MVI_39931\img00379.jpg +D:/DETRAC-Images/MVI_39931\img00380.jpg +D:/DETRAC-Images/MVI_39931\img00381.jpg +D:/DETRAC-Images/MVI_39931\img00382.jpg +D:/DETRAC-Images/MVI_39931\img00383.jpg +D:/DETRAC-Images/MVI_39931\img00384.jpg +D:/DETRAC-Images/MVI_39931\img00385.jpg +D:/DETRAC-Images/MVI_39931\img00386.jpg +D:/DETRAC-Images/MVI_39931\img00387.jpg +D:/DETRAC-Images/MVI_39931\img00388.jpg +D:/DETRAC-Images/MVI_39931\img00389.jpg +D:/DETRAC-Images/MVI_39931\img00390.jpg +D:/DETRAC-Images/MVI_39931\img00391.jpg +D:/DETRAC-Images/MVI_39931\img00392.jpg +D:/DETRAC-Images/MVI_39931\img00393.jpg +D:/DETRAC-Images/MVI_39931\img00394.jpg +D:/DETRAC-Images/MVI_39931\img00395.jpg +D:/DETRAC-Images/MVI_39931\img00396.jpg +D:/DETRAC-Images/MVI_39931\img00397.jpg +D:/DETRAC-Images/MVI_39931\img00398.jpg +D:/DETRAC-Images/MVI_39931\img00399.jpg +D:/DETRAC-Images/MVI_39931\img00400.jpg +D:/DETRAC-Images/MVI_39931\img00401.jpg +D:/DETRAC-Images/MVI_39931\img00402.jpg +D:/DETRAC-Images/MVI_39931\img00403.jpg +D:/DETRAC-Images/MVI_39931\img00404.jpg +D:/DETRAC-Images/MVI_39931\img00405.jpg +D:/DETRAC-Images/MVI_39931\img00406.jpg +D:/DETRAC-Images/MVI_39931\img00407.jpg +D:/DETRAC-Images/MVI_39931\img00408.jpg +D:/DETRAC-Images/MVI_39931\img00409.jpg +D:/DETRAC-Images/MVI_39931\img00410.jpg +D:/DETRAC-Images/MVI_39931\img00411.jpg +D:/DETRAC-Images/MVI_39931\img00412.jpg +D:/DETRAC-Images/MVI_39931\img00413.jpg +D:/DETRAC-Images/MVI_39931\img00414.jpg +D:/DETRAC-Images/MVI_39931\img00415.jpg +D:/DETRAC-Images/MVI_39931\img00416.jpg +D:/DETRAC-Images/MVI_39931\img00417.jpg +D:/DETRAC-Images/MVI_39931\img00418.jpg +D:/DETRAC-Images/MVI_39931\img00419.jpg +D:/DETRAC-Images/MVI_39931\img00420.jpg +D:/DETRAC-Images/MVI_39931\img00421.jpg +D:/DETRAC-Images/MVI_39931\img00422.jpg +D:/DETRAC-Images/MVI_39931\img00423.jpg +D:/DETRAC-Images/MVI_39931\img00424.jpg +D:/DETRAC-Images/MVI_39931\img00425.jpg +D:/DETRAC-Images/MVI_39931\img00426.jpg +D:/DETRAC-Images/MVI_39931\img00427.jpg +D:/DETRAC-Images/MVI_39931\img00428.jpg +D:/DETRAC-Images/MVI_39931\img00429.jpg +D:/DETRAC-Images/MVI_39931\img00430.jpg +D:/DETRAC-Images/MVI_39931\img00431.jpg +D:/DETRAC-Images/MVI_39931\img00432.jpg +D:/DETRAC-Images/MVI_39931\img00433.jpg +D:/DETRAC-Images/MVI_39931\img00434.jpg +D:/DETRAC-Images/MVI_39931\img00435.jpg +D:/DETRAC-Images/MVI_39931\img00436.jpg +D:/DETRAC-Images/MVI_39931\img00437.jpg +D:/DETRAC-Images/MVI_39931\img00438.jpg +D:/DETRAC-Images/MVI_39931\img00439.jpg +D:/DETRAC-Images/MVI_39931\img00440.jpg +D:/DETRAC-Images/MVI_39931\img00441.jpg +D:/DETRAC-Images/MVI_39931\img00442.jpg +D:/DETRAC-Images/MVI_39931\img00443.jpg +D:/DETRAC-Images/MVI_39931\img00444.jpg +D:/DETRAC-Images/MVI_39931\img00445.jpg +D:/DETRAC-Images/MVI_39931\img00446.jpg +D:/DETRAC-Images/MVI_39931\img00447.jpg +D:/DETRAC-Images/MVI_39931\img00448.jpg +D:/DETRAC-Images/MVI_39931\img00449.jpg +D:/DETRAC-Images/MVI_39931\img00450.jpg +D:/DETRAC-Images/MVI_39931\img00451.jpg +D:/DETRAC-Images/MVI_39931\img00452.jpg +D:/DETRAC-Images/MVI_39931\img00453.jpg +D:/DETRAC-Images/MVI_39931\img00454.jpg +D:/DETRAC-Images/MVI_39931\img00455.jpg +D:/DETRAC-Images/MVI_39931\img00456.jpg +D:/DETRAC-Images/MVI_39931\img00457.jpg +D:/DETRAC-Images/MVI_39931\img00458.jpg +D:/DETRAC-Images/MVI_39931\img00459.jpg +D:/DETRAC-Images/MVI_39931\img00460.jpg +D:/DETRAC-Images/MVI_39931\img00461.jpg +D:/DETRAC-Images/MVI_39931\img00462.jpg +D:/DETRAC-Images/MVI_39931\img00463.jpg +D:/DETRAC-Images/MVI_39931\img00464.jpg +D:/DETRAC-Images/MVI_39931\img00465.jpg +D:/DETRAC-Images/MVI_39931\img00466.jpg +D:/DETRAC-Images/MVI_39931\img00467.jpg +D:/DETRAC-Images/MVI_39931\img00468.jpg +D:/DETRAC-Images/MVI_39931\img00469.jpg +D:/DETRAC-Images/MVI_39931\img00470.jpg +D:/DETRAC-Images/MVI_39931\img00471.jpg +D:/DETRAC-Images/MVI_39931\img00472.jpg +D:/DETRAC-Images/MVI_39931\img00473.jpg +D:/DETRAC-Images/MVI_39931\img00474.jpg +D:/DETRAC-Images/MVI_39931\img00475.jpg +D:/DETRAC-Images/MVI_39931\img00476.jpg +D:/DETRAC-Images/MVI_39931\img00477.jpg +D:/DETRAC-Images/MVI_39931\img00478.jpg +D:/DETRAC-Images/MVI_39931\img00479.jpg +D:/DETRAC-Images/MVI_39931\img00480.jpg +D:/DETRAC-Images/MVI_39931\img00481.jpg +D:/DETRAC-Images/MVI_39931\img00482.jpg +D:/DETRAC-Images/MVI_39931\img00483.jpg +D:/DETRAC-Images/MVI_39931\img00484.jpg +D:/DETRAC-Images/MVI_39931\img00485.jpg +D:/DETRAC-Images/MVI_39931\img00486.jpg +D:/DETRAC-Images/MVI_39931\img00487.jpg +D:/DETRAC-Images/MVI_39931\img00488.jpg +D:/DETRAC-Images/MVI_39931\img00489.jpg +D:/DETRAC-Images/MVI_39931\img00490.jpg +D:/DETRAC-Images/MVI_39931\img00491.jpg +D:/DETRAC-Images/MVI_39931\img00492.jpg +D:/DETRAC-Images/MVI_39931\img00493.jpg +D:/DETRAC-Images/MVI_39931\img00494.jpg +D:/DETRAC-Images/MVI_39931\img00495.jpg +D:/DETRAC-Images/MVI_39931\img00496.jpg +D:/DETRAC-Images/MVI_39931\img00497.jpg +D:/DETRAC-Images/MVI_39931\img00498.jpg +D:/DETRAC-Images/MVI_39931\img00499.jpg +D:/DETRAC-Images/MVI_39931\img00500.jpg +D:/DETRAC-Images/MVI_39931\img00501.jpg +D:/DETRAC-Images/MVI_39931\img00502.jpg +D:/DETRAC-Images/MVI_39931\img00503.jpg +D:/DETRAC-Images/MVI_39931\img00504.jpg +D:/DETRAC-Images/MVI_39931\img00505.jpg +D:/DETRAC-Images/MVI_39931\img00506.jpg +D:/DETRAC-Images/MVI_39931\img00507.jpg +D:/DETRAC-Images/MVI_39931\img00508.jpg +D:/DETRAC-Images/MVI_39931\img00509.jpg +D:/DETRAC-Images/MVI_39931\img00510.jpg +D:/DETRAC-Images/MVI_39931\img00511.jpg +D:/DETRAC-Images/MVI_39931\img00512.jpg +D:/DETRAC-Images/MVI_39931\img00513.jpg +D:/DETRAC-Images/MVI_39931\img00514.jpg +D:/DETRAC-Images/MVI_39931\img00515.jpg +D:/DETRAC-Images/MVI_39931\img00516.jpg +D:/DETRAC-Images/MVI_39931\img00517.jpg +D:/DETRAC-Images/MVI_39931\img00518.jpg +D:/DETRAC-Images/MVI_39931\img00519.jpg +D:/DETRAC-Images/MVI_39931\img00520.jpg +D:/DETRAC-Images/MVI_39931\img00521.jpg +D:/DETRAC-Images/MVI_39931\img00522.jpg +D:/DETRAC-Images/MVI_39931\img00523.jpg +D:/DETRAC-Images/MVI_39931\img00524.jpg +D:/DETRAC-Images/MVI_39931\img00525.jpg +D:/DETRAC-Images/MVI_39931\img00526.jpg +D:/DETRAC-Images/MVI_39931\img00527.jpg +D:/DETRAC-Images/MVI_39931\img00528.jpg +D:/DETRAC-Images/MVI_39931\img00529.jpg +D:/DETRAC-Images/MVI_39931\img00530.jpg +D:/DETRAC-Images/MVI_39931\img00531.jpg +D:/DETRAC-Images/MVI_39931\img00532.jpg +D:/DETRAC-Images/MVI_39931\img00533.jpg +D:/DETRAC-Images/MVI_39931\img00534.jpg +D:/DETRAC-Images/MVI_39931\img00535.jpg +D:/DETRAC-Images/MVI_39931\img00536.jpg +D:/DETRAC-Images/MVI_39931\img00537.jpg +D:/DETRAC-Images/MVI_39931\img00538.jpg +D:/DETRAC-Images/MVI_39931\img00539.jpg +D:/DETRAC-Images/MVI_39931\img00540.jpg +D:/DETRAC-Images/MVI_39931\img00541.jpg +D:/DETRAC-Images/MVI_39931\img00542.jpg +D:/DETRAC-Images/MVI_39931\img00543.jpg +D:/DETRAC-Images/MVI_39931\img00544.jpg +D:/DETRAC-Images/MVI_39931\img00545.jpg +D:/DETRAC-Images/MVI_39931\img00546.jpg +D:/DETRAC-Images/MVI_39931\img00547.jpg +D:/DETRAC-Images/MVI_39931\img00548.jpg +D:/DETRAC-Images/MVI_39931\img00549.jpg +D:/DETRAC-Images/MVI_39931\img00550.jpg +D:/DETRAC-Images/MVI_39931\img00551.jpg +D:/DETRAC-Images/MVI_39931\img00552.jpg +D:/DETRAC-Images/MVI_39931\img00553.jpg +D:/DETRAC-Images/MVI_39931\img00554.jpg +D:/DETRAC-Images/MVI_39931\img00555.jpg +D:/DETRAC-Images/MVI_39931\img00556.jpg +D:/DETRAC-Images/MVI_39931\img00557.jpg +D:/DETRAC-Images/MVI_39931\img00558.jpg +D:/DETRAC-Images/MVI_39931\img00559.jpg +D:/DETRAC-Images/MVI_39931\img00560.jpg +D:/DETRAC-Images/MVI_39931\img00561.jpg +D:/DETRAC-Images/MVI_39931\img00562.jpg +D:/DETRAC-Images/MVI_39931\img00563.jpg +D:/DETRAC-Images/MVI_39931\img00564.jpg +D:/DETRAC-Images/MVI_39931\img00565.jpg +D:/DETRAC-Images/MVI_39931\img00566.jpg +D:/DETRAC-Images/MVI_39931\img00567.jpg +D:/DETRAC-Images/MVI_39931\img00568.jpg +D:/DETRAC-Images/MVI_39931\img00569.jpg +D:/DETRAC-Images/MVI_39931\img00570.jpg +D:/DETRAC-Images/MVI_39931\img00571.jpg +D:/DETRAC-Images/MVI_39931\img00572.jpg +D:/DETRAC-Images/MVI_39931\img00573.jpg +D:/DETRAC-Images/MVI_39931\img00574.jpg +D:/DETRAC-Images/MVI_39931\img00575.jpg +D:/DETRAC-Images/MVI_39931\img00576.jpg +D:/DETRAC-Images/MVI_39931\img00577.jpg +D:/DETRAC-Images/MVI_39931\img00578.jpg +D:/DETRAC-Images/MVI_39931\img00579.jpg +D:/DETRAC-Images/MVI_39931\img00580.jpg +D:/DETRAC-Images/MVI_39931\img00581.jpg +D:/DETRAC-Images/MVI_39931\img00582.jpg +D:/DETRAC-Images/MVI_39931\img00583.jpg +D:/DETRAC-Images/MVI_39931\img00584.jpg +D:/DETRAC-Images/MVI_39931\img00585.jpg +D:/DETRAC-Images/MVI_39931\img00586.jpg +D:/DETRAC-Images/MVI_39931\img00587.jpg +D:/DETRAC-Images/MVI_39931\img00588.jpg +D:/DETRAC-Images/MVI_39931\img00589.jpg +D:/DETRAC-Images/MVI_39931\img00590.jpg +D:/DETRAC-Images/MVI_39931\img00591.jpg +D:/DETRAC-Images/MVI_39931\img00592.jpg +D:/DETRAC-Images/MVI_39931\img00593.jpg +D:/DETRAC-Images/MVI_39931\img00594.jpg +D:/DETRAC-Images/MVI_39931\img00595.jpg +D:/DETRAC-Images/MVI_39931\img00596.jpg +D:/DETRAC-Images/MVI_39931\img00597.jpg +D:/DETRAC-Images/MVI_39931\img00598.jpg +D:/DETRAC-Images/MVI_39931\img00599.jpg +D:/DETRAC-Images/MVI_39931\img00600.jpg +D:/DETRAC-Images/MVI_39931\img00601.jpg +D:/DETRAC-Images/MVI_39931\img00602.jpg +D:/DETRAC-Images/MVI_39931\img00603.jpg +D:/DETRAC-Images/MVI_39931\img00604.jpg +D:/DETRAC-Images/MVI_39931\img00605.jpg +D:/DETRAC-Images/MVI_39931\img00606.jpg +D:/DETRAC-Images/MVI_39931\img00607.jpg +D:/DETRAC-Images/MVI_39931\img00608.jpg +D:/DETRAC-Images/MVI_39931\img00609.jpg +D:/DETRAC-Images/MVI_39931\img00610.jpg +D:/DETRAC-Images/MVI_39931\img00611.jpg +D:/DETRAC-Images/MVI_39931\img00612.jpg +D:/DETRAC-Images/MVI_39931\img00613.jpg +D:/DETRAC-Images/MVI_39931\img00614.jpg +D:/DETRAC-Images/MVI_39931\img00615.jpg +D:/DETRAC-Images/MVI_39931\img00616.jpg +D:/DETRAC-Images/MVI_39931\img00617.jpg +D:/DETRAC-Images/MVI_39931\img00618.jpg +D:/DETRAC-Images/MVI_39931\img00619.jpg +D:/DETRAC-Images/MVI_39931\img00620.jpg +D:/DETRAC-Images/MVI_39931\img00621.jpg +D:/DETRAC-Images/MVI_39931\img00622.jpg +D:/DETRAC-Images/MVI_39931\img00623.jpg +D:/DETRAC-Images/MVI_39931\img00624.jpg +D:/DETRAC-Images/MVI_39931\img00625.jpg +D:/DETRAC-Images/MVI_39931\img00626.jpg +D:/DETRAC-Images/MVI_39931\img00627.jpg +D:/DETRAC-Images/MVI_39931\img00628.jpg +D:/DETRAC-Images/MVI_39931\img00629.jpg +D:/DETRAC-Images/MVI_39931\img00630.jpg +D:/DETRAC-Images/MVI_39931\img00631.jpg +D:/DETRAC-Images/MVI_39931\img00632.jpg +D:/DETRAC-Images/MVI_39931\img00633.jpg +D:/DETRAC-Images/MVI_39931\img00634.jpg +D:/DETRAC-Images/MVI_39931\img00635.jpg +D:/DETRAC-Images/MVI_39931\img00636.jpg +D:/DETRAC-Images/MVI_39931\img00637.jpg +D:/DETRAC-Images/MVI_39931\img00638.jpg +D:/DETRAC-Images/MVI_39931\img00639.jpg +D:/DETRAC-Images/MVI_39931\img00640.jpg +D:/DETRAC-Images/MVI_39931\img00641.jpg +D:/DETRAC-Images/MVI_39931\img00642.jpg +D:/DETRAC-Images/MVI_39931\img00643.jpg +D:/DETRAC-Images/MVI_39931\img00644.jpg +D:/DETRAC-Images/MVI_39931\img00645.jpg +D:/DETRAC-Images/MVI_39931\img00646.jpg +D:/DETRAC-Images/MVI_39931\img00647.jpg +D:/DETRAC-Images/MVI_39931\img00648.jpg +D:/DETRAC-Images/MVI_39931\img00649.jpg +D:/DETRAC-Images/MVI_39931\img00650.jpg +D:/DETRAC-Images/MVI_39931\img00651.jpg +D:/DETRAC-Images/MVI_39931\img00652.jpg +D:/DETRAC-Images/MVI_39931\img00653.jpg +D:/DETRAC-Images/MVI_39931\img00654.jpg +D:/DETRAC-Images/MVI_39931\img00655.jpg +D:/DETRAC-Images/MVI_39931\img00656.jpg +D:/DETRAC-Images/MVI_39931\img00657.jpg +D:/DETRAC-Images/MVI_39931\img00658.jpg +D:/DETRAC-Images/MVI_39931\img00659.jpg +D:/DETRAC-Images/MVI_39931\img00660.jpg +D:/DETRAC-Images/MVI_39931\img00661.jpg +D:/DETRAC-Images/MVI_39931\img00662.jpg +D:/DETRAC-Images/MVI_39931\img00663.jpg +D:/DETRAC-Images/MVI_39931\img00664.jpg +D:/DETRAC-Images/MVI_39931\img00665.jpg +D:/DETRAC-Images/MVI_39931\img00666.jpg +D:/DETRAC-Images/MVI_39931\img00667.jpg +D:/DETRAC-Images/MVI_39931\img00668.jpg +D:/DETRAC-Images/MVI_39931\img00669.jpg +D:/DETRAC-Images/MVI_39931\img00670.jpg +D:/DETRAC-Images/MVI_39931\img00671.jpg +D:/DETRAC-Images/MVI_39931\img00672.jpg +D:/DETRAC-Images/MVI_39931\img00673.jpg +D:/DETRAC-Images/MVI_39931\img00674.jpg +D:/DETRAC-Images/MVI_39931\img00675.jpg +D:/DETRAC-Images/MVI_39931\img00676.jpg +D:/DETRAC-Images/MVI_39931\img00677.jpg +D:/DETRAC-Images/MVI_39931\img00678.jpg +D:/DETRAC-Images/MVI_39931\img00679.jpg +D:/DETRAC-Images/MVI_39931\img00680.jpg +D:/DETRAC-Images/MVI_39931\img00681.jpg +D:/DETRAC-Images/MVI_39931\img00682.jpg +D:/DETRAC-Images/MVI_39931\img00683.jpg +D:/DETRAC-Images/MVI_39931\img00684.jpg +D:/DETRAC-Images/MVI_39931\img00685.jpg +D:/DETRAC-Images/MVI_39931\img00686.jpg +D:/DETRAC-Images/MVI_39931\img00687.jpg +D:/DETRAC-Images/MVI_39931\img00688.jpg +D:/DETRAC-Images/MVI_39931\img00689.jpg +D:/DETRAC-Images/MVI_39931\img00690.jpg +D:/DETRAC-Images/MVI_39931\img00691.jpg +D:/DETRAC-Images/MVI_39931\img00692.jpg +D:/DETRAC-Images/MVI_39931\img00693.jpg +D:/DETRAC-Images/MVI_39931\img00694.jpg +D:/DETRAC-Images/MVI_39931\img00695.jpg +D:/DETRAC-Images/MVI_39931\img00696.jpg +D:/DETRAC-Images/MVI_39931\img00697.jpg +D:/DETRAC-Images/MVI_39931\img00698.jpg +D:/DETRAC-Images/MVI_39931\img00699.jpg +D:/DETRAC-Images/MVI_39931\img00700.jpg +D:/DETRAC-Images/MVI_39931\img00701.jpg +D:/DETRAC-Images/MVI_39931\img00702.jpg +D:/DETRAC-Images/MVI_39931\img00703.jpg +D:/DETRAC-Images/MVI_39931\img00704.jpg +D:/DETRAC-Images/MVI_39931\img00705.jpg +D:/DETRAC-Images/MVI_39931\img00706.jpg +D:/DETRAC-Images/MVI_39931\img00707.jpg +D:/DETRAC-Images/MVI_39931\img00708.jpg +D:/DETRAC-Images/MVI_39931\img00709.jpg +D:/DETRAC-Images/MVI_39931\img00710.jpg +D:/DETRAC-Images/MVI_39931\img00711.jpg +D:/DETRAC-Images/MVI_39931\img00712.jpg +D:/DETRAC-Images/MVI_39931\img00713.jpg +D:/DETRAC-Images/MVI_39931\img00714.jpg +D:/DETRAC-Images/MVI_39931\img00715.jpg +D:/DETRAC-Images/MVI_39931\img00716.jpg +D:/DETRAC-Images/MVI_39931\img00717.jpg +D:/DETRAC-Images/MVI_39931\img00718.jpg +D:/DETRAC-Images/MVI_39931\img00719.jpg +D:/DETRAC-Images/MVI_39931\img00720.jpg +D:/DETRAC-Images/MVI_39931\img00721.jpg +D:/DETRAC-Images/MVI_39931\img00722.jpg +D:/DETRAC-Images/MVI_39931\img00723.jpg +D:/DETRAC-Images/MVI_39931\img00724.jpg +D:/DETRAC-Images/MVI_39931\img00725.jpg +D:/DETRAC-Images/MVI_39931\img00726.jpg +D:/DETRAC-Images/MVI_39931\img00727.jpg +D:/DETRAC-Images/MVI_39931\img00728.jpg +D:/DETRAC-Images/MVI_39931\img00729.jpg +D:/DETRAC-Images/MVI_39931\img00730.jpg +D:/DETRAC-Images/MVI_39931\img00731.jpg +D:/DETRAC-Images/MVI_39931\img00732.jpg +D:/DETRAC-Images/MVI_39931\img00733.jpg +D:/DETRAC-Images/MVI_39931\img00734.jpg +D:/DETRAC-Images/MVI_39931\img00735.jpg +D:/DETRAC-Images/MVI_39931\img00736.jpg +D:/DETRAC-Images/MVI_39931\img00737.jpg +D:/DETRAC-Images/MVI_39931\img00738.jpg +D:/DETRAC-Images/MVI_39931\img00739.jpg +D:/DETRAC-Images/MVI_39931\img00740.jpg +D:/DETRAC-Images/MVI_39931\img00741.jpg +D:/DETRAC-Images/MVI_39931\img00742.jpg +D:/DETRAC-Images/MVI_39931\img00743.jpg +D:/DETRAC-Images/MVI_39931\img00744.jpg +D:/DETRAC-Images/MVI_39931\img00745.jpg +D:/DETRAC-Images/MVI_39931\img00746.jpg +D:/DETRAC-Images/MVI_39931\img00747.jpg +D:/DETRAC-Images/MVI_39931\img00748.jpg +D:/DETRAC-Images/MVI_39931\img00749.jpg +D:/DETRAC-Images/MVI_39931\img00750.jpg +D:/DETRAC-Images/MVI_39931\img00751.jpg +D:/DETRAC-Images/MVI_39931\img00752.jpg +D:/DETRAC-Images/MVI_39931\img00753.jpg +D:/DETRAC-Images/MVI_39931\img00754.jpg +D:/DETRAC-Images/MVI_39931\img00755.jpg +D:/DETRAC-Images/MVI_39931\img00756.jpg +D:/DETRAC-Images/MVI_39931\img00757.jpg +D:/DETRAC-Images/MVI_39931\img00758.jpg +D:/DETRAC-Images/MVI_39931\img00759.jpg +D:/DETRAC-Images/MVI_39931\img00760.jpg +D:/DETRAC-Images/MVI_39931\img00761.jpg +D:/DETRAC-Images/MVI_39931\img00762.jpg +D:/DETRAC-Images/MVI_39931\img00763.jpg +D:/DETRAC-Images/MVI_39931\img00764.jpg +D:/DETRAC-Images/MVI_39931\img00765.jpg +D:/DETRAC-Images/MVI_39931\img00766.jpg +D:/DETRAC-Images/MVI_39931\img00767.jpg +D:/DETRAC-Images/MVI_39931\img00768.jpg +D:/DETRAC-Images/MVI_39931\img00769.jpg +D:/DETRAC-Images/MVI_39931\img00770.jpg +D:/DETRAC-Images/MVI_39931\img00771.jpg +D:/DETRAC-Images/MVI_39931\img00772.jpg +D:/DETRAC-Images/MVI_39931\img00773.jpg +D:/DETRAC-Images/MVI_39931\img00774.jpg +D:/DETRAC-Images/MVI_39931\img00775.jpg +D:/DETRAC-Images/MVI_39931\img00776.jpg +D:/DETRAC-Images/MVI_39931\img00777.jpg +D:/DETRAC-Images/MVI_39931\img00778.jpg +D:/DETRAC-Images/MVI_39931\img00779.jpg +D:/DETRAC-Images/MVI_39931\img00780.jpg +D:/DETRAC-Images/MVI_39931\img00781.jpg +D:/DETRAC-Images/MVI_39931\img00782.jpg +D:/DETRAC-Images/MVI_39931\img00783.jpg +D:/DETRAC-Images/MVI_39931\img00784.jpg +D:/DETRAC-Images/MVI_39931\img00785.jpg +D:/DETRAC-Images/MVI_39931\img00786.jpg +D:/DETRAC-Images/MVI_39931\img00787.jpg +D:/DETRAC-Images/MVI_39931\img00788.jpg +D:/DETRAC-Images/MVI_39931\img00789.jpg +D:/DETRAC-Images/MVI_39931\img00790.jpg +D:/DETRAC-Images/MVI_39931\img00791.jpg +D:/DETRAC-Images/MVI_39931\img00792.jpg +D:/DETRAC-Images/MVI_39931\img00793.jpg +D:/DETRAC-Images/MVI_39931\img00794.jpg +D:/DETRAC-Images/MVI_39931\img00795.jpg +D:/DETRAC-Images/MVI_39931\img00796.jpg +D:/DETRAC-Images/MVI_39931\img00797.jpg +D:/DETRAC-Images/MVI_39931\img00798.jpg +D:/DETRAC-Images/MVI_39931\img00799.jpg +D:/DETRAC-Images/MVI_39931\img00800.jpg +D:/DETRAC-Images/MVI_39931\img00801.jpg +D:/DETRAC-Images/MVI_39931\img00802.jpg +D:/DETRAC-Images/MVI_39931\img00803.jpg +D:/DETRAC-Images/MVI_39931\img00804.jpg +D:/DETRAC-Images/MVI_39931\img00805.jpg +D:/DETRAC-Images/MVI_39931\img00806.jpg +D:/DETRAC-Images/MVI_39931\img00807.jpg +D:/DETRAC-Images/MVI_39931\img00808.jpg +D:/DETRAC-Images/MVI_39931\img00809.jpg +D:/DETRAC-Images/MVI_39931\img00810.jpg +D:/DETRAC-Images/MVI_39931\img00811.jpg +D:/DETRAC-Images/MVI_39931\img00812.jpg +D:/DETRAC-Images/MVI_39931\img00813.jpg +D:/DETRAC-Images/MVI_39931\img00814.jpg +D:/DETRAC-Images/MVI_39931\img00815.jpg +D:/DETRAC-Images/MVI_39931\img00816.jpg +D:/DETRAC-Images/MVI_39931\img00817.jpg +D:/DETRAC-Images/MVI_39931\img00818.jpg +D:/DETRAC-Images/MVI_39931\img00819.jpg +D:/DETRAC-Images/MVI_39931\img00820.jpg +D:/DETRAC-Images/MVI_39931\img00821.jpg +D:/DETRAC-Images/MVI_39931\img00822.jpg +D:/DETRAC-Images/MVI_39931\img00823.jpg +D:/DETRAC-Images/MVI_39931\img00824.jpg +D:/DETRAC-Images/MVI_39931\img00825.jpg +D:/DETRAC-Images/MVI_39931\img00826.jpg +D:/DETRAC-Images/MVI_39931\img00827.jpg +D:/DETRAC-Images/MVI_39931\img00828.jpg +D:/DETRAC-Images/MVI_39931\img00829.jpg +D:/DETRAC-Images/MVI_39931\img00830.jpg +D:/DETRAC-Images/MVI_39931\img00831.jpg +D:/DETRAC-Images/MVI_39931\img00832.jpg +D:/DETRAC-Images/MVI_39931\img00833.jpg +D:/DETRAC-Images/MVI_39931\img00834.jpg +D:/DETRAC-Images/MVI_39931\img00835.jpg +D:/DETRAC-Images/MVI_39931\img00836.jpg +D:/DETRAC-Images/MVI_39931\img00837.jpg +D:/DETRAC-Images/MVI_39931\img00838.jpg +D:/DETRAC-Images/MVI_39931\img00839.jpg +D:/DETRAC-Images/MVI_39931\img00840.jpg +D:/DETRAC-Images/MVI_39931\img00841.jpg +D:/DETRAC-Images/MVI_39931\img00842.jpg +D:/DETRAC-Images/MVI_39931\img00843.jpg +D:/DETRAC-Images/MVI_39931\img00844.jpg +D:/DETRAC-Images/MVI_39931\img00845.jpg +D:/DETRAC-Images/MVI_39931\img00846.jpg +D:/DETRAC-Images/MVI_39931\img00847.jpg +D:/DETRAC-Images/MVI_39931\img00848.jpg +D:/DETRAC-Images/MVI_39931\img00849.jpg +D:/DETRAC-Images/MVI_39931\img00850.jpg +D:/DETRAC-Images/MVI_39931\img00851.jpg +D:/DETRAC-Images/MVI_39931\img00852.jpg +D:/DETRAC-Images/MVI_39931\img00853.jpg +D:/DETRAC-Images/MVI_39931\img00854.jpg +D:/DETRAC-Images/MVI_39931\img00855.jpg +D:/DETRAC-Images/MVI_39931\img00856.jpg +D:/DETRAC-Images/MVI_39931\img00857.jpg +D:/DETRAC-Images/MVI_39931\img00858.jpg +D:/DETRAC-Images/MVI_39931\img00859.jpg +D:/DETRAC-Images/MVI_39931\img00860.jpg +D:/DETRAC-Images/MVI_39931\img00861.jpg +D:/DETRAC-Images/MVI_39931\img00862.jpg +D:/DETRAC-Images/MVI_39931\img00863.jpg +D:/DETRAC-Images/MVI_39931\img00864.jpg +D:/DETRAC-Images/MVI_39931\img00865.jpg +D:/DETRAC-Images/MVI_39931\img00866.jpg +D:/DETRAC-Images/MVI_39931\img00867.jpg +D:/DETRAC-Images/MVI_39931\img00868.jpg +D:/DETRAC-Images/MVI_39931\img00869.jpg +D:/DETRAC-Images/MVI_39931\img00870.jpg +D:/DETRAC-Images/MVI_39931\img00871.jpg +D:/DETRAC-Images/MVI_39931\img00872.jpg +D:/DETRAC-Images/MVI_39931\img00873.jpg +D:/DETRAC-Images/MVI_39931\img00874.jpg +D:/DETRAC-Images/MVI_39931\img00875.jpg +D:/DETRAC-Images/MVI_39931\img00876.jpg +D:/DETRAC-Images/MVI_39931\img00877.jpg +D:/DETRAC-Images/MVI_39931\img00878.jpg +D:/DETRAC-Images/MVI_39931\img00879.jpg +D:/DETRAC-Images/MVI_39931\img00880.jpg +D:/DETRAC-Images/MVI_39931\img00881.jpg +D:/DETRAC-Images/MVI_39931\img00882.jpg +D:/DETRAC-Images/MVI_39931\img00883.jpg +D:/DETRAC-Images/MVI_39931\img00884.jpg +D:/DETRAC-Images/MVI_39931\img00885.jpg +D:/DETRAC-Images/MVI_39931\img00886.jpg +D:/DETRAC-Images/MVI_39931\img00887.jpg +D:/DETRAC-Images/MVI_39931\img00888.jpg +D:/DETRAC-Images/MVI_39931\img00889.jpg +D:/DETRAC-Images/MVI_39931\img00890.jpg +D:/DETRAC-Images/MVI_39931\img00891.jpg +D:/DETRAC-Images/MVI_39931\img00892.jpg +D:/DETRAC-Images/MVI_39931\img00893.jpg +D:/DETRAC-Images/MVI_39931\img00894.jpg +D:/DETRAC-Images/MVI_39931\img00895.jpg +D:/DETRAC-Images/MVI_39931\img00896.jpg +D:/DETRAC-Images/MVI_39931\img00897.jpg +D:/DETRAC-Images/MVI_39931\img00898.jpg +D:/DETRAC-Images/MVI_39931\img00899.jpg +D:/DETRAC-Images/MVI_39931\img00900.jpg +D:/DETRAC-Images/MVI_39931\img00901.jpg +D:/DETRAC-Images/MVI_39931\img00902.jpg +D:/DETRAC-Images/MVI_39931\img00903.jpg +D:/DETRAC-Images/MVI_39931\img00904.jpg +D:/DETRAC-Images/MVI_39931\img00905.jpg +D:/DETRAC-Images/MVI_39931\img00906.jpg +D:/DETRAC-Images/MVI_39931\img00907.jpg +D:/DETRAC-Images/MVI_39931\img00908.jpg +D:/DETRAC-Images/MVI_39931\img00909.jpg +D:/DETRAC-Images/MVI_39931\img00910.jpg +D:/DETRAC-Images/MVI_39931\img00911.jpg +D:/DETRAC-Images/MVI_39931\img00912.jpg +D:/DETRAC-Images/MVI_39931\img00913.jpg +D:/DETRAC-Images/MVI_39931\img00914.jpg +D:/DETRAC-Images/MVI_39931\img00915.jpg +D:/DETRAC-Images/MVI_39931\img00916.jpg +D:/DETRAC-Images/MVI_39931\img00917.jpg +D:/DETRAC-Images/MVI_39931\img00918.jpg +D:/DETRAC-Images/MVI_39931\img00919.jpg +D:/DETRAC-Images/MVI_39931\img00920.jpg +D:/DETRAC-Images/MVI_39931\img00921.jpg +D:/DETRAC-Images/MVI_39931\img00922.jpg +D:/DETRAC-Images/MVI_39931\img00923.jpg +D:/DETRAC-Images/MVI_39931\img00924.jpg +D:/DETRAC-Images/MVI_39931\img00925.jpg +D:/DETRAC-Images/MVI_39931\img00926.jpg +D:/DETRAC-Images/MVI_39931\img00927.jpg +D:/DETRAC-Images/MVI_39931\img00928.jpg +D:/DETRAC-Images/MVI_39931\img00929.jpg +D:/DETRAC-Images/MVI_39931\img00930.jpg +D:/DETRAC-Images/MVI_39931\img00931.jpg +D:/DETRAC-Images/MVI_39931\img00932.jpg +D:/DETRAC-Images/MVI_39931\img00933.jpg +D:/DETRAC-Images/MVI_39931\img00934.jpg +D:/DETRAC-Images/MVI_39931\img00935.jpg +D:/DETRAC-Images/MVI_39931\img00936.jpg +D:/DETRAC-Images/MVI_39931\img00937.jpg +D:/DETRAC-Images/MVI_39931\img00938.jpg +D:/DETRAC-Images/MVI_39931\img00939.jpg +D:/DETRAC-Images/MVI_39931\img00940.jpg +D:/DETRAC-Images/MVI_39931\img00941.jpg +D:/DETRAC-Images/MVI_39931\img00942.jpg +D:/DETRAC-Images/MVI_39931\img00943.jpg +D:/DETRAC-Images/MVI_39931\img00944.jpg +D:/DETRAC-Images/MVI_39931\img00945.jpg +D:/DETRAC-Images/MVI_39931\img00946.jpg +D:/DETRAC-Images/MVI_39931\img00947.jpg +D:/DETRAC-Images/MVI_39931\img00948.jpg +D:/DETRAC-Images/MVI_39931\img00949.jpg +D:/DETRAC-Images/MVI_39931\img00950.jpg +D:/DETRAC-Images/MVI_39931\img00951.jpg +D:/DETRAC-Images/MVI_39931\img00952.jpg +D:/DETRAC-Images/MVI_39931\img00953.jpg +D:/DETRAC-Images/MVI_39931\img00954.jpg +D:/DETRAC-Images/MVI_39931\img00955.jpg +D:/DETRAC-Images/MVI_39931\img00956.jpg +D:/DETRAC-Images/MVI_39931\img00957.jpg +D:/DETRAC-Images/MVI_39931\img00958.jpg +D:/DETRAC-Images/MVI_39931\img00959.jpg +D:/DETRAC-Images/MVI_39931\img00960.jpg +D:/DETRAC-Images/MVI_39931\img00961.jpg +D:/DETRAC-Images/MVI_39931\img00962.jpg +D:/DETRAC-Images/MVI_39931\img00963.jpg +D:/DETRAC-Images/MVI_39931\img00964.jpg +D:/DETRAC-Images/MVI_39931\img00965.jpg +D:/DETRAC-Images/MVI_39931\img00966.jpg +D:/DETRAC-Images/MVI_39931\img00967.jpg +D:/DETRAC-Images/MVI_39931\img00968.jpg +D:/DETRAC-Images/MVI_39931\img00969.jpg +D:/DETRAC-Images/MVI_39931\img00970.jpg +D:/DETRAC-Images/MVI_39931\img00971.jpg +D:/DETRAC-Images/MVI_39931\img00972.jpg +D:/DETRAC-Images/MVI_39931\img00973.jpg +D:/DETRAC-Images/MVI_39931\img00974.jpg +D:/DETRAC-Images/MVI_39931\img00975.jpg +D:/DETRAC-Images/MVI_39931\img00976.jpg +D:/DETRAC-Images/MVI_39931\img00977.jpg +D:/DETRAC-Images/MVI_39931\img00978.jpg +D:/DETRAC-Images/MVI_39931\img00979.jpg +D:/DETRAC-Images/MVI_39931\img00980.jpg +D:/DETRAC-Images/MVI_39931\img00981.jpg +D:/DETRAC-Images/MVI_39931\img00982.jpg +D:/DETRAC-Images/MVI_39931\img00983.jpg +D:/DETRAC-Images/MVI_39931\img00984.jpg +D:/DETRAC-Images/MVI_39931\img00985.jpg +D:/DETRAC-Images/MVI_39931\img00986.jpg +D:/DETRAC-Images/MVI_39931\img00987.jpg +D:/DETRAC-Images/MVI_39931\img00988.jpg +D:/DETRAC-Images/MVI_39931\img00989.jpg +D:/DETRAC-Images/MVI_39931\img00990.jpg +D:/DETRAC-Images/MVI_39931\img00991.jpg +D:/DETRAC-Images/MVI_39931\img00992.jpg +D:/DETRAC-Images/MVI_39931\img00993.jpg +D:/DETRAC-Images/MVI_39931\img00994.jpg +D:/DETRAC-Images/MVI_39931\img00995.jpg +D:/DETRAC-Images/MVI_39931\img00996.jpg +D:/DETRAC-Images/MVI_39931\img00997.jpg +D:/DETRAC-Images/MVI_39931\img00998.jpg +D:/DETRAC-Images/MVI_39931\img00999.jpg +D:/DETRAC-Images/MVI_39931\img01000.jpg +D:/DETRAC-Images/MVI_39931\img01001.jpg +D:/DETRAC-Images/MVI_39931\img01002.jpg +D:/DETRAC-Images/MVI_39931\img01003.jpg +D:/DETRAC-Images/MVI_39931\img01004.jpg +D:/DETRAC-Images/MVI_39931\img01005.jpg +D:/DETRAC-Images/MVI_39931\img01006.jpg +D:/DETRAC-Images/MVI_39931\img01007.jpg +D:/DETRAC-Images/MVI_39931\img01008.jpg +D:/DETRAC-Images/MVI_39931\img01009.jpg +D:/DETRAC-Images/MVI_39931\img01010.jpg +D:/DETRAC-Images/MVI_39931\img01011.jpg +D:/DETRAC-Images/MVI_39931\img01012.jpg +D:/DETRAC-Images/MVI_39931\img01013.jpg +D:/DETRAC-Images/MVI_39931\img01014.jpg +D:/DETRAC-Images/MVI_39931\img01015.jpg +D:/DETRAC-Images/MVI_39931\img01016.jpg +D:/DETRAC-Images/MVI_39931\img01017.jpg +D:/DETRAC-Images/MVI_39931\img01018.jpg +D:/DETRAC-Images/MVI_39931\img01019.jpg +D:/DETRAC-Images/MVI_39931\img01020.jpg +D:/DETRAC-Images/MVI_39931\img01021.jpg +D:/DETRAC-Images/MVI_39931\img01022.jpg +D:/DETRAC-Images/MVI_39931\img01023.jpg +D:/DETRAC-Images/MVI_39931\img01024.jpg +D:/DETRAC-Images/MVI_39931\img01025.jpg +D:/DETRAC-Images/MVI_39931\img01026.jpg +D:/DETRAC-Images/MVI_39931\img01027.jpg +D:/DETRAC-Images/MVI_39931\img01028.jpg +D:/DETRAC-Images/MVI_39931\img01029.jpg +D:/DETRAC-Images/MVI_39931\img01030.jpg +D:/DETRAC-Images/MVI_39931\img01031.jpg +D:/DETRAC-Images/MVI_39931\img01032.jpg +D:/DETRAC-Images/MVI_39931\img01033.jpg +D:/DETRAC-Images/MVI_39931\img01034.jpg +D:/DETRAC-Images/MVI_39931\img01035.jpg +D:/DETRAC-Images/MVI_39931\img01036.jpg +D:/DETRAC-Images/MVI_39931\img01037.jpg +D:/DETRAC-Images/MVI_39931\img01038.jpg +D:/DETRAC-Images/MVI_39931\img01039.jpg +D:/DETRAC-Images/MVI_39931\img01040.jpg +D:/DETRAC-Images/MVI_39931\img01041.jpg +D:/DETRAC-Images/MVI_39931\img01042.jpg +D:/DETRAC-Images/MVI_39931\img01043.jpg +D:/DETRAC-Images/MVI_39931\img01044.jpg +D:/DETRAC-Images/MVI_39931\img01045.jpg +D:/DETRAC-Images/MVI_39931\img01046.jpg +D:/DETRAC-Images/MVI_39931\img01047.jpg +D:/DETRAC-Images/MVI_39931\img01048.jpg +D:/DETRAC-Images/MVI_39931\img01049.jpg +D:/DETRAC-Images/MVI_39931\img01050.jpg +D:/DETRAC-Images/MVI_39931\img01051.jpg +D:/DETRAC-Images/MVI_39931\img01052.jpg +D:/DETRAC-Images/MVI_39931\img01053.jpg +D:/DETRAC-Images/MVI_39931\img01054.jpg +D:/DETRAC-Images/MVI_39931\img01055.jpg +D:/DETRAC-Images/MVI_39931\img01056.jpg +D:/DETRAC-Images/MVI_39931\img01057.jpg +D:/DETRAC-Images/MVI_39931\img01058.jpg +D:/DETRAC-Images/MVI_39931\img01059.jpg +D:/DETRAC-Images/MVI_39931\img01060.jpg +D:/DETRAC-Images/MVI_39931\img01061.jpg +D:/DETRAC-Images/MVI_39931\img01062.jpg +D:/DETRAC-Images/MVI_39931\img01063.jpg +D:/DETRAC-Images/MVI_39931\img01064.jpg +D:/DETRAC-Images/MVI_39931\img01065.jpg +D:/DETRAC-Images/MVI_39931\img01066.jpg +D:/DETRAC-Images/MVI_39931\img01067.jpg +D:/DETRAC-Images/MVI_39931\img01068.jpg +D:/DETRAC-Images/MVI_39931\img01069.jpg +D:/DETRAC-Images/MVI_39931\img01070.jpg +D:/DETRAC-Images/MVI_39931\img01071.jpg +D:/DETRAC-Images/MVI_39931\img01072.jpg +D:/DETRAC-Images/MVI_39931\img01073.jpg +D:/DETRAC-Images/MVI_39931\img01074.jpg +D:/DETRAC-Images/MVI_39931\img01075.jpg +D:/DETRAC-Images/MVI_39931\img01076.jpg +D:/DETRAC-Images/MVI_39931\img01077.jpg +D:/DETRAC-Images/MVI_39931\img01078.jpg +D:/DETRAC-Images/MVI_39931\img01079.jpg +D:/DETRAC-Images/MVI_39931\img01080.jpg +D:/DETRAC-Images/MVI_39931\img01081.jpg +D:/DETRAC-Images/MVI_39931\img01082.jpg +D:/DETRAC-Images/MVI_39931\img01083.jpg +D:/DETRAC-Images/MVI_39931\img01084.jpg +D:/DETRAC-Images/MVI_39931\img01085.jpg +D:/DETRAC-Images/MVI_39931\img01086.jpg +D:/DETRAC-Images/MVI_39931\img01087.jpg +D:/DETRAC-Images/MVI_39931\img01088.jpg +D:/DETRAC-Images/MVI_39931\img01089.jpg +D:/DETRAC-Images/MVI_39931\img01090.jpg +D:/DETRAC-Images/MVI_39931\img01091.jpg +D:/DETRAC-Images/MVI_39931\img01092.jpg +D:/DETRAC-Images/MVI_39931\img01093.jpg +D:/DETRAC-Images/MVI_39931\img01094.jpg +D:/DETRAC-Images/MVI_39931\img01095.jpg +D:/DETRAC-Images/MVI_39931\img01096.jpg +D:/DETRAC-Images/MVI_39931\img01097.jpg +D:/DETRAC-Images/MVI_39931\img01098.jpg +D:/DETRAC-Images/MVI_39931\img01099.jpg +D:/DETRAC-Images/MVI_39931\img01100.jpg +D:/DETRAC-Images/MVI_39931\img01101.jpg +D:/DETRAC-Images/MVI_39931\img01102.jpg +D:/DETRAC-Images/MVI_39931\img01103.jpg +D:/DETRAC-Images/MVI_39931\img01104.jpg +D:/DETRAC-Images/MVI_39931\img01105.jpg +D:/DETRAC-Images/MVI_39931\img01106.jpg +D:/DETRAC-Images/MVI_39931\img01107.jpg +D:/DETRAC-Images/MVI_39931\img01108.jpg +D:/DETRAC-Images/MVI_39931\img01109.jpg +D:/DETRAC-Images/MVI_39931\img01110.jpg +D:/DETRAC-Images/MVI_39931\img01111.jpg +D:/DETRAC-Images/MVI_39931\img01112.jpg +D:/DETRAC-Images/MVI_39931\img01113.jpg +D:/DETRAC-Images/MVI_39931\img01114.jpg +D:/DETRAC-Images/MVI_39931\img01115.jpg +D:/DETRAC-Images/MVI_39931\img01116.jpg +D:/DETRAC-Images/MVI_39931\img01117.jpg +D:/DETRAC-Images/MVI_39931\img01118.jpg +D:/DETRAC-Images/MVI_39931\img01119.jpg +D:/DETRAC-Images/MVI_39931\img01120.jpg +D:/DETRAC-Images/MVI_39931\img01121.jpg +D:/DETRAC-Images/MVI_39931\img01122.jpg +D:/DETRAC-Images/MVI_39931\img01123.jpg +D:/DETRAC-Images/MVI_39931\img01124.jpg +D:/DETRAC-Images/MVI_39931\img01125.jpg +D:/DETRAC-Images/MVI_39931\img01126.jpg +D:/DETRAC-Images/MVI_39931\img01127.jpg +D:/DETRAC-Images/MVI_39931\img01128.jpg +D:/DETRAC-Images/MVI_39931\img01129.jpg +D:/DETRAC-Images/MVI_39931\img01130.jpg +D:/DETRAC-Images/MVI_39931\img01131.jpg +D:/DETRAC-Images/MVI_39931\img01132.jpg +D:/DETRAC-Images/MVI_39931\img01133.jpg +D:/DETRAC-Images/MVI_39931\img01134.jpg +D:/DETRAC-Images/MVI_39931\img01135.jpg +D:/DETRAC-Images/MVI_39931\img01136.jpg +D:/DETRAC-Images/MVI_39931\img01137.jpg +D:/DETRAC-Images/MVI_39931\img01138.jpg +D:/DETRAC-Images/MVI_39931\img01139.jpg +D:/DETRAC-Images/MVI_39931\img01140.jpg +D:/DETRAC-Images/MVI_39931\img01141.jpg +D:/DETRAC-Images/MVI_39931\img01142.jpg +D:/DETRAC-Images/MVI_39931\img01143.jpg +D:/DETRAC-Images/MVI_39931\img01144.jpg +D:/DETRAC-Images/MVI_39931\img01145.jpg +D:/DETRAC-Images/MVI_39931\img01146.jpg +D:/DETRAC-Images/MVI_39931\img01147.jpg +D:/DETRAC-Images/MVI_39931\img01148.jpg +D:/DETRAC-Images/MVI_39931\img01149.jpg +D:/DETRAC-Images/MVI_39931\img01150.jpg +D:/DETRAC-Images/MVI_39931\img01151.jpg +D:/DETRAC-Images/MVI_39931\img01152.jpg +D:/DETRAC-Images/MVI_39931\img01153.jpg +D:/DETRAC-Images/MVI_39931\img01154.jpg +D:/DETRAC-Images/MVI_39931\img01155.jpg +D:/DETRAC-Images/MVI_39931\img01156.jpg +D:/DETRAC-Images/MVI_39931\img01157.jpg +D:/DETRAC-Images/MVI_39931\img01158.jpg +D:/DETRAC-Images/MVI_39931\img01159.jpg +D:/DETRAC-Images/MVI_39931\img01160.jpg +D:/DETRAC-Images/MVI_39931\img01161.jpg +D:/DETRAC-Images/MVI_39931\img01162.jpg +D:/DETRAC-Images/MVI_39931\img01163.jpg +D:/DETRAC-Images/MVI_39931\img01164.jpg +D:/DETRAC-Images/MVI_39931\img01165.jpg +D:/DETRAC-Images/MVI_39931\img01166.jpg +D:/DETRAC-Images/MVI_39931\img01167.jpg +D:/DETRAC-Images/MVI_39931\img01168.jpg +D:/DETRAC-Images/MVI_39931\img01169.jpg +D:/DETRAC-Images/MVI_39931\img01170.jpg +D:/DETRAC-Images/MVI_39931\img01171.jpg +D:/DETRAC-Images/MVI_39931\img01172.jpg +D:/DETRAC-Images/MVI_39931\img01173.jpg +D:/DETRAC-Images/MVI_39931\img01174.jpg +D:/DETRAC-Images/MVI_39931\img01175.jpg +D:/DETRAC-Images/MVI_39931\img01176.jpg +D:/DETRAC-Images/MVI_39931\img01177.jpg +D:/DETRAC-Images/MVI_39931\img01178.jpg +D:/DETRAC-Images/MVI_39931\img01179.jpg +D:/DETRAC-Images/MVI_39931\img01180.jpg +D:/DETRAC-Images/MVI_39931\img01181.jpg +D:/DETRAC-Images/MVI_39931\img01182.jpg +D:/DETRAC-Images/MVI_39931\img01183.jpg +D:/DETRAC-Images/MVI_39931\img01184.jpg +D:/DETRAC-Images/MVI_39931\img01185.jpg +D:/DETRAC-Images/MVI_39931\img01186.jpg +D:/DETRAC-Images/MVI_39931\img01187.jpg +D:/DETRAC-Images/MVI_39931\img01188.jpg +D:/DETRAC-Images/MVI_39931\img01189.jpg +D:/DETRAC-Images/MVI_39931\img01190.jpg +D:/DETRAC-Images/MVI_39931\img01191.jpg +D:/DETRAC-Images/MVI_39931\img01192.jpg +D:/DETRAC-Images/MVI_39931\img01193.jpg +D:/DETRAC-Images/MVI_39931\img01194.jpg +D:/DETRAC-Images/MVI_39931\img01195.jpg +D:/DETRAC-Images/MVI_39931\img01196.jpg +D:/DETRAC-Images/MVI_39931\img01197.jpg +D:/DETRAC-Images/MVI_39931\img01198.jpg +D:/DETRAC-Images/MVI_39931\img01199.jpg +D:/DETRAC-Images/MVI_39931\img01200.jpg +D:/DETRAC-Images/MVI_39931\img01201.jpg +D:/DETRAC-Images/MVI_39931\img01202.jpg +D:/DETRAC-Images/MVI_39931\img01203.jpg +D:/DETRAC-Images/MVI_39931\img01204.jpg +D:/DETRAC-Images/MVI_39931\img01205.jpg +D:/DETRAC-Images/MVI_39931\img01206.jpg +D:/DETRAC-Images/MVI_39931\img01207.jpg +D:/DETRAC-Images/MVI_39931\img01208.jpg +D:/DETRAC-Images/MVI_39931\img01209.jpg +D:/DETRAC-Images/MVI_39931\img01210.jpg +D:/DETRAC-Images/MVI_39931\img01211.jpg +D:/DETRAC-Images/MVI_39931\img01212.jpg +D:/DETRAC-Images/MVI_39931\img01213.jpg +D:/DETRAC-Images/MVI_39931\img01214.jpg +D:/DETRAC-Images/MVI_39931\img01215.jpg +D:/DETRAC-Images/MVI_39931\img01216.jpg +D:/DETRAC-Images/MVI_39931\img01217.jpg +D:/DETRAC-Images/MVI_39931\img01218.jpg +D:/DETRAC-Images/MVI_39931\img01219.jpg +D:/DETRAC-Images/MVI_39931\img01220.jpg +D:/DETRAC-Images/MVI_39931\img01221.jpg +D:/DETRAC-Images/MVI_39931\img01222.jpg +D:/DETRAC-Images/MVI_39931\img01223.jpg +D:/DETRAC-Images/MVI_39931\img01224.jpg +D:/DETRAC-Images/MVI_39931\img01225.jpg +D:/DETRAC-Images/MVI_39931\img01226.jpg +D:/DETRAC-Images/MVI_39931\img01227.jpg +D:/DETRAC-Images/MVI_39931\img01228.jpg +D:/DETRAC-Images/MVI_39931\img01229.jpg +D:/DETRAC-Images/MVI_39931\img01230.jpg +D:/DETRAC-Images/MVI_39931\img01231.jpg +D:/DETRAC-Images/MVI_39931\img01232.jpg +D:/DETRAC-Images/MVI_39931\img01233.jpg +D:/DETRAC-Images/MVI_39931\img01234.jpg +D:/DETRAC-Images/MVI_39931\img01235.jpg +D:/DETRAC-Images/MVI_39931\img01236.jpg +D:/DETRAC-Images/MVI_39931\img01237.jpg +D:/DETRAC-Images/MVI_39931\img01238.jpg +D:/DETRAC-Images/MVI_39931\img01239.jpg +D:/DETRAC-Images/MVI_39931\img01240.jpg +D:/DETRAC-Images/MVI_39931\img01241.jpg +D:/DETRAC-Images/MVI_39931\img01242.jpg +D:/DETRAC-Images/MVI_39931\img01243.jpg +D:/DETRAC-Images/MVI_39931\img01244.jpg +D:/DETRAC-Images/MVI_39931\img01245.jpg +D:/DETRAC-Images/MVI_39931\img01246.jpg +D:/DETRAC-Images/MVI_39931\img01247.jpg +D:/DETRAC-Images/MVI_39931\img01248.jpg +D:/DETRAC-Images/MVI_39931\img01249.jpg +D:/DETRAC-Images/MVI_39931\img01250.jpg +D:/DETRAC-Images/MVI_39931\img01251.jpg +D:/DETRAC-Images/MVI_39931\img01252.jpg +D:/DETRAC-Images/MVI_39931\img01253.jpg +D:/DETRAC-Images/MVI_39931\img01254.jpg +D:/DETRAC-Images/MVI_39931\img01255.jpg +D:/DETRAC-Images/MVI_39931\img01256.jpg +D:/DETRAC-Images/MVI_39931\img01257.jpg +D:/DETRAC-Images/MVI_39931\img01258.jpg +D:/DETRAC-Images/MVI_39931\img01259.jpg +D:/DETRAC-Images/MVI_39931\img01260.jpg +D:/DETRAC-Images/MVI_39931\img01261.jpg +D:/DETRAC-Images/MVI_39931\img01262.jpg +D:/DETRAC-Images/MVI_39931\img01263.jpg +D:/DETRAC-Images/MVI_39931\img01264.jpg +D:/DETRAC-Images/MVI_39931\img01265.jpg +D:/DETRAC-Images/MVI_39931\img01266.jpg +D:/DETRAC-Images/MVI_39931\img01267.jpg +D:/DETRAC-Images/MVI_39931\img01268.jpg +D:/DETRAC-Images/MVI_39931\img01269.jpg +D:/DETRAC-Images/MVI_39931\img01270.jpg diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_core231.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_core231.dll new file mode 100644 index 0000000000000000000000000000000000000000..8d27aec7c9932312268f2380b3e21567977ad4f7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_core231.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4790ab9e72c09fda1b02caa0543b0d85ce17e0e2d6543a8a7900f46d7f66a534 +size 2090496 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_highgui231.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_highgui231.dll new file mode 100644 index 0000000000000000000000000000000000000000..4be83695db0ae82dba7a98df98a78c8303dabdbb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_highgui231.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d9706d3a4979b004dc384952db4c3e4273547e56e2336b3c01fc43f94eae6d7 +size 1122816 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_imgproc231.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_imgproc231.dll new file mode 100644 index 0000000000000000000000000000000000000000..0e84c47773aa96433bd3ad3b5a3caff17e73d9c5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/opencv_imgproc231.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ea5b40cbc3e52c4112ffae6c82db4ae9fdd496ed903a19682a9ad25512eaa62 +size 1896448 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/run_tracker.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/run_tracker.m new file mode 100644 index 0000000000000000000000000000000000000000..1df30b0d923ac4abb0c00fb82628ad8cf5892844 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/run_tracker.m @@ -0,0 +1,113 @@ +function [stateInfo, speed] = run_tracker(curSequence, baselinedetections) +% parameters +minCarWidth = 5; +minCarHeight = 5; +segSize = [10,4]; +nTry = 3; + +%% multi-object tracking +frameNums = curSequence.frameNums; +% create list file +listPath = 'imagelist.txt'; +fidlist = fopen(listPath, 'w'); +partsID = ismember(curSequence.imgFolder, '\'); +id = find(partsID==1); +newFolder = []; +for i = 1:length(id) + if(i == 1) + staId = 1; + endId = id(i)-1; + else + staId = id(i-1)+1; + endId = id(i)-1; + end + newFolder = cat(2, newFolder, cat(2, curSequence.imgFolder(staId:endId), '\\')); +end +for k = frameNums + fprintf(fidlist,[newFolder curSequence.imgFileFormat '\n'], k); +end +fclose(fidlist); +% configuration +fileIn = 'GraphMultiCarTracker_Config.txt'; +fileOut = 'Config.txt'; +fidin = fopen(fileIn,'r'); +fidout = fopen(fileOut,'w'); +nline = 0; +while(~feof(fidin)) + tline = fgetl(fidin); + nline = nline+1; + % change the parameter + if(nline == 8) + tline_ = curSequence.seqName; + fprintf(fidout,'%s\n', tline_); + elseif(nline == 14) + detPath = 'detections.txt'; % detection file + baselinedetections(:,5) = baselinedetections(:,5) + baselinedetections(:,3); + baselinedetections(:,6) = baselinedetections(:,6) + baselinedetections(:,4); + dlmwrite(detPath, baselinedetections); + tline_ = detPath; + fprintf(fidout,'%s\n', tline_); + elseif(nline == 29) + tline_ = num2str(numel(frameNums)); + fprintf(fidout,'%s\n', tline_); + elseif(nline == 32) + tline_ = num2str(minCarWidth); + fprintf(fidout,'%s\n', tline_); + elseif(nline == 35) + tline_ = num2str(minCarHeight); + fprintf(fidout,'%s\n', tline_); + elseif(nline == 38) + tline_ = [num2str(segSize(1)) ',' num2str(segSize(2))]; + fprintf(fidout,'%s\n', tline_); + elseif(nline == 41) + tline_ = num2str(nTry); + fprintf(fidout,'%s\n', tline_); + else + fprintf(fidout,'%s\n', tline); + end +end +fclose(fidin); +fclose(fidout); +% run the tracker +if verLessThan('matlab', '7.14.0') + [status, output] = system('GraphMultiCarTracker.exe Config.txt'); +else + [status, output] = system('GraphMultiCarTracker.exe Config.txt', ''); +end + +% save tracking results +stateInfo = []; +stateInfo.F = numel(curSequence.frameNums); +stateInfo.frameNums = curSequence.frameNums; +seqID = curSequence.seqName; +if(exist(['result\' seqID '_LX.txt'],'file')) + X = load(['result\' seqID '_LX.txt']); + Y = load(['result\' seqID '_LY.txt']); + W = load(['result\' seqID '_RX.txt']) - X; + H = load(['result\' seqID '_RY.txt']) - Y; + speed = load(['result\' seqID '_speed.txt']); + xc = X + W/2; + yc = Y + H/2; + % foot position + stateInfo.X = xc; + stateInfo.Y = yc+H/2; + stateInfo.H = W; + stateInfo.W = H; + stateInfo.Xgp = stateInfo.X; + stateInfo.Ygp = stateInfo.Y; + stateInfo.Xi = stateInfo.X; + stateInfo.Yi = stateInfo.Y; +else + stateInfo.X = []; + stateInfo.Y = []; + stateInfo.H = []; + stateInfo.W = []; + stateInfo.Xgp = stateInfo.X; + stateInfo.Ygp = stateInfo.Y; + stateInfo.Xi = stateInfo.X; + stateInfo.Yi = stateInfo.Y; + speed = 0; +end +% delete the temp files +delete('result\*.txt'); +delete('detections.txt'); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/tbb.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/tbb.dll new file mode 100644 index 0000000000000000000000000000000000000000..4ef3d77561860ec74c45be9983f3cdc17c12760d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/tbb.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c7b24b0c7f8ccfd9ec2a2df0232aab3f079ed90bdd90fa9da6d01d12a5643c6 +size 278944 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/CLEAR_MOT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/CLEAR_MOT.m new file mode 100644 index 0000000000000000000000000000000000000000..4b3b89c60fccba78e14f8e6700cca0a5abbcf0ce --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/CLEAR_MOT.m @@ -0,0 +1,334 @@ +function [metrics metricsInfo]=CLEAR_MOT(gtInfo,stateInfo,options) +% compute CLEAR MOT and other metrics +% +% metrics contains the following +% [1] recall - recall = percentage of detected targets +% [2] precision - precision = percentage of correctly detected targets +% [3] FAR - number of false alarms per frame +% [4] GT - number of ground truth trajectories +% [5-7] MT, PT, ML - number of mostly tracked, partially tracked and mostly lost trajectories +% [8] falsepositives- number of false positives (FP) +% [9] missed - number of missed targets (FN) +% [10] idswitches - number of id switches (IDs) +% [11] FRA - number of fragmentations +% [12] MOTA - Multi-object tracking accuracy in [0,100] +% [13] MOTP - Multi-object tracking precision in [0,100] (3D) / [td,100] (2D) +% [14] MOTAL - Multi-object tracking accuracy in [0,100] with log10(idswitches) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% default options: 2D +if nargin<3 + options.eval3d=0; % only bounding box overlap + options.td=.5; % threshold 50% +end + +if ~isfield(options,'td') + if options.eval3d + options.td=1000; + else + options.td=0.5; + end +end + +td=options.td; + +assert(length(gtInfo.frameNums)==length(stateInfo.frameNums), ... + 'Ground Truth and state must be of equal length'); +if(gtInfo.frameNums(1)~=stateInfo.frameNums(1)) + gtInfo.frameNums = gtInfo.frameNums + stateInfo.frameNums(1) - gtInfo.frameNums(1); +end +assert(all(gtInfo.frameNums==stateInfo.frameNums), ... + 'Ground Truth and state must contain equal frame numbers'); + +% check if all necessery info is available +if options.eval3d + assert(all(isfield(gtInfo,{'Xgp','Ygp'})), ... + 'Ground Truth Ground Plane coordinates needed for 3D evaluation'); + assert(all(isfield(stateInfo,{'Xgp','Ygp'})), ... + 'Ground Plane coordinates needed for 3D evaluation'); +else + assert(all(isfield(gtInfo,{'X','Y','W','H'})), ... + 'Ground Truth coordinates X,Y,W,H needed for 2D evaluation'); + assert(all(isfield(stateInfo,{'Xi','Yi','W','H'})), ... + 'State coordinates Xi,Yi,W,H needed for 2D evaluation'); + +end + +gtInd=~~gtInfo.X; +stInd=~~stateInfo.X; + +[Fgt Ngt]=size(gtInfo.X); +[F N]=size(stateInfo.X); + +aspectRatio=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% gtInfo.W=gtInfo.H*aspectRatio; + + +metricsInfo.names.long = {'Recall','Precision','False Alarm Rate', ... + 'GT Tracks','Mostly Tracked','Partially Tracked','Mostly Lost', ... + 'False Positives', 'False Negatives', 'ID Switches', 'Fragmentations', ... + 'MOTA','MOTP', 'MOTA Log'}; + +metricsInfo.names.short = {'Rcll','Prcn','FAR', ... + 'GT','MT','PT','ML', ... + 'FP', 'FN', 'IDs', 'FM', ... + 'MOTA','MOTP', 'MOTAL'}; + +metricsInfo.widths.long = [6 9 16 9 14 17 11 15 15 11 14 5 5 8]; +metricsInfo.widths.short = [5 5 5 3 3 3 3 4 4 3 3 5 5 5]; + +metricsInfo.format.long = {'.1f','.1f','.2f', ... + 'i','i','i','i', ... + 'i','i','i','i', ... + '.1f','.1f','.1f'}; + +metricsInfo.format.short=metricsInfo.format.long; + + +metrics=zeros(1,14); +metrics(9)=numel(find(gtInd)); % False Negatives (missed) +metrics(7)=Ngt; % Mostly Lost + +% nothing to be done, if state is empty +if ~N, return; end + +% global opt +% if options.eval3d && opt.mex +% [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% CLEAR_MOT_mex(gtInfo.Xgp', gtInfo.Ygp', stateInfo.Xgp', stateInfo.Ygp',options.td); +% +% % cd /home/aanton/diss/utils +% % [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% % CLEAR_MOT(gtInfo.Xgp, gtInfo.Ygp, stateInfo.Xgp, stateInfo.Ygp,options.td); +% % cd /home/aanton/visinf/projects/ongoing/contracking +% metrics=[rc*100, pc*100, faf, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FM, MOTA*100, MOTP*100, MOTAL*100]; +% metrics +% global gsi +% gsi=stateInfo; +% pause +% return; +% end + + +% mapping +M=zeros(F,Ngt); + +mme=zeros(1,F); % ID Switchtes (mismatches) +c=zeros(1,F); % matches found +fp=zeros(1,F); % false positives +m=zeros(1,F); % misses = false negatives +g=zeros(1,F); +d=zeros(F,Ngt); % all distances; +ious=Inf*ones(F,Ngt); % all overlaps + +matched=@matched2d; +if options.eval3d, matched=@matched3d; end + +alltracked=zeros(F,Ngt); +allfalsepos=zeros(F,N); + +for t=1:F + g(t)=numel(find(gtInd(t,:))); + + % mapping for current frame + if t>1 + mappings=find(M(t-1,:)); + for map=mappings + if gtInd(t,map) && stInd(t,M(t-1,map)) && matched(gtInfo,stateInfo,t,map,M(t-1,map),td*0.8) + M(t,map)=M(t-1,map); + end + end + end + + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + + if options.eval3d +% alldist=Inf*ones(Ngt,N); +% mindist=0; +% while mindist < td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 +% for o=GTsNotMapped +% GT=[gtInfo.Xgp(t,o) gtInfo.Ygp(t,o)]; +% for e=EsNotMapped +% E=[stateInfo.Xgp(t,e) stateInfo.Ygp(t,e)]; +% alldist(o,e)=norm(GT-E); +% end +% end +% [mindist, cind]=min(alldist(:)); +% if mindist <= td +% [u v]=ind2sub(size(alldist),cind); +% M(t,u)=v; +% alldist(:,v)=Inf; +% GTsNotMapped=find(~M(t,:) & gtInd(t,:)); +% EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); +% end +% end + + cost = zeros(numel(GTsNotMapped), numel(EsNotMapped)); + for o = 1:numel(GTsNotMapped) + GT = [gtInfo.Xgp(t,GTsNotMapped(o)), gtInfo.Ygp(t,GTsNotMapped(o))]; + for e = 1:numel(EsNotMapped) + E = [stateInfo.Xgp(t,EsNotMapped(e)), stateInfo.Ygp(t,EsNotMapped(e))]; + cost(o,e)=norm(GT-E); + end + end + cost(cost > td) = Inf; + assignLabel = munkres(cost); + for i = 1:numel(assignLabel) + if(assignLabel(i)) + M(t, GTsNotMapped(i)) = EsNotMapped(assignLabel(i)); + end + end + + else + allisects=zeros(Ngt,N); maxisect=Inf; + + while maxisect > td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 + for o=GTsNotMapped + GT=[gtInfo.X(t,o)-gtInfo.W(t,o)/2 ... + gtInfo.Y(t,o)-gtInfo.H(t,o) ... + gtInfo.W(t,o) gtInfo.H(t,o) ]; + for e=EsNotMapped + E=[stateInfo.Xi(t,e)-stateInfo.W(t,e)/2 ... + stateInfo.Yi(t,e)-stateInfo.H(t,e) ... + stateInfo.W(t,e) stateInfo.H(t,e) ]; + allisects(o,e)=boxiou(GT(1),GT(2),GT(3),GT(4),E(1),E(2),E(3),E(4)); + end + end + [maxisect cind]=max(allisects(:)); + + if maxisect >= td + [u v]=ind2sub(size(allisects),cind); + M(t,u)=v; + allisects(:,v)=0; + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + end + + end + end + + curtracked=find(M(t,:)); + + + alltrackers=find(stInd(t,:)); + mappedtrackers=intersect(M(t,find(M(t,:))),alltrackers); + falsepositives=setdiff(alltrackers,mappedtrackers); + + alltracked(t,:)=M(t,:); + allfalsepos(t,1:length(falsepositives))=falsepositives; + + %% mismatch errors + if t>1 + for ct=curtracked + lastnotempty=find(M(1:t-1,ct),1,'last'); + if gtInd(t-1,ct) && ~isempty(lastnotempty) && M(t,ct)~=M(lastnotempty,ct) + mme(t)=mme(t)+1; + end + end + end + + c(t)=numel(curtracked); + for ct=curtracked + eid=M(t,ct); + if options.eval3d + d(t,ct)=norm([gtInfo.Xgp(t,ct) gtInfo.Ygp(t,ct)] - ... + [stateInfo.Xgp(t,eid) stateInfo.Ygp(t,eid)]); + else + gtLeft=gtInfo.X(t,ct)-gtInfo.W(t,ct)/2; + gtTop=gtInfo.Y(t,ct)-gtInfo.H(t,ct); + gtWidth=gtInfo.W(t,ct); gtHeight=gtInfo.H(t,ct); + + stLeft=stateInfo.Xi(t,eid)-stateInfo.W(t,eid)/2; + stTop=stateInfo.Yi(t,eid)-stateInfo.H(t,eid); + stWidth=stateInfo.W(t,eid); stHeight=stateInfo.H(t,eid); + ious(t,ct)=boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight); + end + end + + + fp(t)=numel(find(stInd(t,:)))-c(t); + m(t)=g(t)-c(t); + + +end + +missed=sum(m); +falsepositives=sum(fp); +idswitches=sum(mme); + +if options.eval3d + MOTP=(1-sum(sum(d))/sum(c)/td) * 100; % avg distance to [0,100] +else + MOTP=sum(ious(ious>=td & ious0)); + if(gtlength/gttotallength >= 0.8 && trlengtha/gttotallength < 0.2) + MTstatsa(i)=3; + elseif(t>=find(gtInd(:,i),1,'last') && trlengtha/gttotallength <= 0.8) + MTstatsa(i)=2; + elseif trlengtha/gttotallength >= 0.8 + MTstatsa(i)=1; + end +end +% MTstatsa +MT=numel(find(MTstatsa==1));PT=numel(find(MTstatsa==2));ML=numel(find(MTstatsa==3)); + +%% fragments +fr=zeros(1,Ngt); +for i=1:Ngt + b=alltracked(find(alltracked(:,i),1,'first'):find(alltracked(:,i),1,'last'),i); + b(~~b)=1; + fr(i)=numel(find(diff(b)==-1)); +end +FRA=sum(fr); + +assert(Ngt==MT+PT+ML,'Hmm... Not all tracks classified correctly.'); +metrics=[recall, precision, FAR, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FRA, MOTA, MOTP, MOTAL]; +end + + + + +function ret=matched2d(gtInfo,stateInfo,t,map,mID,td) + gtLeft=gtInfo.X(t,map)-gtInfo.W(t,map)/2; + gtTop=gtInfo.Y(t,map)-gtInfo.H(t,map); + gtWidth=gtInfo.W(t,map); gtHeight=gtInfo.H(t,map); + + stLeft=stateInfo.Xi(t,mID)-stateInfo.W(t,mID)/2; + stTop=stateInfo.Yi(t,mID)-stateInfo.H(t,mID); + stWidth=stateInfo.W(t,mID); stHeight=stateInfo.H(t,mID); + + ret = boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight) >= td; +end + + +function ret=matched3d(gtInfo,stateInfo,t,map,mID,td) + Xgt=gtInfo.Xgp(t,map); Ygt=gtInfo.Ygp(t,map); + X=stateInfo.Xgp(t,mID); Y=stateInfo.Ygp(t,mID); + ret=norm([Xgt Ygt]-[X Y])<=td; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/boxIntersect.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/boxIntersect.m new file mode 100644 index 0000000000000000000000000000000000000000..5a55b45131c36980ad641f838452967a12bf300b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/boxIntersect.m @@ -0,0 +1,24 @@ +function isect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2) +% A=[bboxleft1 bboxbottom1 abs(bboxright1-bboxleft1) abs(bboxbottom1-bboxup1)]; +% B=[bboxleft2 bboxbottom2 abs(bboxright2-bboxleft2) abs(bboxbottom2-bboxup2)]; +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% isect=rectint(A,B); +isect=0; + +hor= max(0,min(bboxright1,bboxright2) - max(bboxleft1,bboxleft2)); + +if ~hor, return; end +ver= max(0,min(bboxbottom1,bboxbottom2) - max(bboxup1,bboxup2)); +if ~ver, return; end + +isect = hor*ver; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/boxUnion.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/boxUnion.m new file mode 100644 index 0000000000000000000000000000000000000000..c5b8e06c5ea242199dbffa15e553ec07b626fab9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/boxUnion.m @@ -0,0 +1,24 @@ +function union=boxUnion(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2,isect) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +a1=bboxright1-bboxleft1; +b1=bboxbottom1-bboxup1; +a2=bboxright2-bboxleft2; +b2=bboxbottom2-bboxup2; +union=a1*b1+a2*b2; +if nargin>8 + bisect=isect; +else + bisect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2); +end +union=union-bisect; + + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/boxiou.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/boxiou.m new file mode 100644 index 0000000000000000000000000000000000000000..395e5dc90d032ee2d7f3c9554148e56f908eeab5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/boxiou.m @@ -0,0 +1,21 @@ +function iou=boxiou(x1,y1,w1,h1,x2,y2,w2,h2) +% compute intersection over union of two bboxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + bisect=boxIntersect(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2); + iou=0; + if ~bisect, return; end + + bunion=boxUnion(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2,bisect); + + assert(bunion>0,'something wrong with union computation'); + iou=bisect/bunion; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/distortedToUndistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/distortedToUndistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..6e62dfbd4271580faef309647e42784c11964e31 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/distortedToUndistortedImageCoord.m @@ -0,0 +1,15 @@ +function [Xfu Yfu]=distortedToUndistortedImageCoord (Xfd, Yfd, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xd = mDpx * (Xfd - mCx) / mSx; + Yd = mDpy * (Yfd - mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ + [Xu Yu]=distortedToUndistortedSensorCoord(Xd, Yd, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfu = Xu * mSx / mDpx + mCx; + Yfu = Yu / mDpy + mCy; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/distortedToUndistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/distortedToUndistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..14158bd36e686650ae77a8621b1ed3c4d56e298a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/distortedToUndistortedSensorCoord.m @@ -0,0 +1,6 @@ +function [Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mKappa1) +% /* convert from distorted to undistorted sensor plane coordinates */ + distortion_factor = 1 + mKappa1 * (Xd*Xd + Yd*Yd); + Xu = Xd * distortion_factor; + Yu = Yd * distortion_factor; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/getRotTrans.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/getRotTrans.m new file mode 100644 index 0000000000000000000000000000000000000000..725097d307f8d0b7a1d211e756f99d82d45ebe1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/getRotTrans.m @@ -0,0 +1,34 @@ +function [mR mT]=getRotTrans(camPar) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + %%% Rotation Translation %%% + mT=[camPar.mExt.mTx;camPar.mExt.mTy;camPar.mExt.mTz]; + sa = sin(camPar.mExt.mRx); + ca = cos(camPar.mExt.mRx); + sb = sin(camPar.mExt.mRy); + cb = cos(camPar.mExt.mRy); + sg = sin(camPar.mExt.mRz); + cg = cos(camPar.mExt.mRz); + + mR11 = cb * cg; + mR12 = cg * sa * sb - ca * sg; + mR13 = sa * sg + ca * cg * sb; + mR21 = cb * sg; + mR22 = sa * sb * sg + ca * cg; + mR23 = ca * sb * sg - cg * sa; + mR31 = -sb; + mR32 = cb * sa; + mR33 = ca * cb; + + mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/imageToWorld.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/imageToWorld.m new file mode 100644 index 0000000000000000000000000000000000000000..3919cb798acbbeec7f826c6ea524dee3c3035476 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/imageToWorld.m @@ -0,0 +1,62 @@ +function [Xw Yw Zw]=imageToWorld(Xi, Yi, camPar) + +mGeo=camPar.mGeo; +mExt=camPar.mExt; +mInt=camPar.mInt; + +mTx=mExt.mTx; +mTy=mExt.mTy; +mTz=mExt.mTz; + +mT=[mExt.mTx;mExt.mTy;mExt.mTz]; + +%% internal init +sa = sin(mExt.mRx); +ca = cos(mExt.mRx); +sb = sin(mExt.mRy); +cb = cos(mExt.mRy); +sg = sin(mExt.mRz); +cg = cos(mExt.mRz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + + + +% /* convert from image to distorted sensor coordinates */ +Xd = mGeo.mDpx * (Xi - mInt.mCx) / mInt.mSx; +Yd = mGeo.mDpy * (Yi - mInt.mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ +[Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mInt.mKappa1); + +% /* calculate the corresponding xw and yw world coordinates */ +% /* (these equations were derived by simply inverting */ +% /* the perspective projection equations using Macsyma) */ +Zw=0; +common_denominator = ((mR11 * mR32 - mR12 * mR31) * Yu + ... + (mR22 * mR31 - mR21 * mR32) * Xu - ... + mInt.mFocal * mR11 * mR22 + mInt.mFocal * mR12 * mR21); + +Xw = (((mR12 * mR33 - mR13 * mR32) * Yu + ... + (mR23 * mR32 - mR22 * mR33) * Xu - ... + mInt.mFocal * mR12 * mR23 + mInt.mFocal * mR13 * mR22) * Zw + ... + (mR12 * mTz - mR32 * mTx) * Yu + ... + (mR32 * mTy - mR22 * mTz) * Xu - ... + mInt.mFocal * mR12 * mTy + mInt.mFocal * mR22 * mTx) / common_denominator; + +Yw = -(((mR11 * mR33 - mR13 * mR31) * Yu + ... + (mR23 * mR31 - mR21 * mR33) * Xu - ... + mInt.mFocal * mR11 * mR23 + mInt.mFocal * mR13 * mR21) * Zw + ... + (mR11 * mTz - mR31 * mTx) * Yu + ... + (mR31 * mTy - mR21 * mTz) * Xu - ... + mInt.mFocal * mR11 * mTy + mInt.mFocal * mR21 * mTx) / common_denominator; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/parseCameraParameters.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/parseCameraParameters.m new file mode 100644 index 0000000000000000000000000000000000000000..10baec4a50e7d06334ec9a16693a4ce178845580 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/parseCameraParameters.m @@ -0,0 +1,104 @@ +function camPar=parseCameraParameters(camconffile) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +xDoc=xmlread(fullfile(camconffile)); + +width=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('width')); +height=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('height')); + +ncx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('ncx')); +nfx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('nfx')); +dx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dx')); +dy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dy')); +dpx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpx')); +dpy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpy')); + +focal=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('focal')); +kappa1=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('kappa1')); +cx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cx')); +cy=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cy')); +sx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('sx')); + +tx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tx')); +ty=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ty')); +tz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tz')); +rx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rx')); +ry=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ry')); +rz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rz')); + +mGeo.mImgWidth = width; +mGeo.mImgHeight = height; +mGeo.mNcx = ncx; +mGeo.mNfx = nfx; +mGeo.mDx = dx; +mGeo.mDy = dy; +mGeo.mDpx = dpx; +mGeo.mDpy = dpy; + + +%% intrinsic +mInt.mFocal = focal; +mInt.mKappa1 = kappa1; +mInt.mCx = cx; +mInt.mCy = cy; +mInt.mSx = sx; + +%% extrinsic +mExt.mTx = tx; +mExt.mTy = ty; +mExt.mTz = tz; +mExt.mRx = rx; +mExt.mRy = ry; +mExt.mRz = rz; + +%% inverted +mT=[tx;ty;tz]; +sa = sin(rx); +ca = cos(rx); +sb = sin(ry); +cb = cos(ry); +sg = sin(rz); +cg = cos(rz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + +mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; + +transform=[mR mT;[0 0 0 1]]; +invtrans=inv(transform); +tx=invtrans(1,4);ty=invtrans(2,4);tz=invtrans(3,4); + +mExt.mTxi = tx; +mExt.mTyi = ty; +mExt.mTzi = tz; + +camPar.mExt=mExt; +camPar.mInt=mInt; +camPar.mGeo=mGeo; + +%% mkappa<0 +if kappa1<0 + warning('CAREFUL! kappa1 < 0, cam derivates are wrong!'); +end + +[camPar.mR camPar.mT]=getRotTrans(camPar); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/undistortedToDistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/undistortedToDistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..9c9f9a1382cfcbf25407f159a06cc73d4440c9a1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/undistortedToDistortedImageCoord.m @@ -0,0 +1,14 @@ +function [Xfd Yfd]=undistortedToDistortedImageCoord (Xfu, Yfu, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xu = mDpx * (Xfu - mCx) / mSx; + Yu = mDpy * (Yfu - mCy); + +% /* convert from undistorted sensor to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord(Xu, Yu, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfd = Xd * mSx / mDpx + mCx; + Yfd = Yd / mDpy + mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/undistortedToDistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/undistortedToDistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..b689d695a1a98a28a8ba414a7661fe9658d24403 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/undistortedToDistortedSensorCoord.m @@ -0,0 +1,67 @@ +function [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mKappa1) + +% global ifs elses + +if ((~Xu && ~Yu) || ~mKappa1) +% ifs(1)=ifs(1)+1; + Xd = Xu; + Yd = Yu; +else %% THIS ONE %% +% elses(1)=elses(1)+1; + Ru = sqrt(Xu*Xu + Yu*Yu); + + c = 1.0 / mKappa1; + d = -c * Ru; + + Q = c / 3; + R = -d / 2; + D = Q*Q*Q + R*R; + + if (D >= 0) %% THIS ONE %% +% ifs(2)=ifs(2)+1; + %/* one real root */ + D = sqrt(D); + if (R + D > 0) %% THIS ONE %% +% ifs(3)=ifs(3)+1; + S = (R + D)^ (1.0/3.0); + else +% elses(3)=elses(3)+1; + S = -(-R - D)^ (1.0/3.0); + end + if (R - D > 0) +% ifs(4)=ifs(4)+1; + T = (R - D)^(1.0/3.0); + else %% THIS ONE %% +% elses(4)=elses(4)+1; + T = -(D - R)^(1.0/3.0); + end + Rd = S + T; + + if (Rd < 0) + Rd = sqrt(-1.0 / (3 * mKappa1)); + % /*fprintf (stderr, "\nWarning: undistorted image point to distorted image point mapping limited by\n"); + % fprintf (stderr, " maximum barrel distortion radius of %lf\n", Rd); + % fprintf (stderr, " (Xu = %lf, Yu = %lf) -> (Xd = %lf, Yd = %lf)\n\n", Xu, Yu, Xu * Rd / Ru, Yu * Rd / Ru);*/ + end + else +% elses(2)=elses(2)+1; + % /* three real roots */ + D = sqrt(-D); + S = ( sqrt(R*R + D*D))^(1.0/3.0 ); + T = atan2(D, R) / 3; + sinT = sin(T); + cosT = cos(T); + + % /* the larger positive root is 2*S*cos(T) */ + % /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ + % /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ + + Rd = -S * cosT + sqrt(3.0) * S * sinT; % /* use the smaller positive root */ + end + + lambda = Rd / Ru; + + Xd = Xu * lambda; + Yd = Yu * lambda; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/worldToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/worldToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..8bb11eb8cfff82e0e805c07f7f22d5e81042b241 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/camera/worldToImage.m @@ -0,0 +1,28 @@ +function [Xi Yi]=worldToImage(Xw,Yw,Zw,mR,mT,mInt,mGeo) + + + % /* convert from world coordinates to camera coordinates */ + x=[mR mT]*[Xw;Yw;Zw;1]; + xc = x(1); + yc = x(2); + zc = x(3); + + % /* convert from camera coordinates to undistorted sensor plane coordinates */ + Xu = mInt.mFocal * xc / zc; + Yu = mInt.mFocal * yc / zc; + + % /* convert from undistorted to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mInt.mKappa1); + % Xd=Xu; + % Yd=Yu; + + % Rusq=Xu*Xu+Yu*Yu; + % Ru=sqrt(Xu*Xu+Yu*Yu); + % Xd=Xu*(1+mInt.mKappa1*Rusq); + % Yd=Yu*(1+mInt.mKappa1*Rusq); + + + % /* convert from distorted sensor plane coordinates to image coordinates */ + Xi = Xd * mInt.mSx / mGeo.mDpx + mInt.mCx; + Yi = Yd / mGeo.mDpy + mInt.mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/checkInitSolution.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/checkInitSolution.m new file mode 100644 index 0000000000000000000000000000000000000000..2c804a3311ac0367686b89db9d6c9864a4856c0c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/checkInitSolution.m @@ -0,0 +1,22 @@ +function [Xinit Yinit]=checkInitSolution(Xinit,Yinit,F) +% check if initial solution is correct +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + assert(all(size(Xinit)==size(Yinit)), ... + 'X and Y are of different size in initial solution'); + + % pad with zeros if not enough frames + Finit=size(Xinit,1); + if FinitareaLimits(2))=0;Ygp(Ygp>areaLimits(4))=0; +Ygp(Xgp==0)=0; Xgp(Ygp==0)=0; + +allzeros=(Xgp == 0 | Ygp ==0); +gtInfo.X(allzeros)=0;gtInfo.Y(allzeros)=0; +gtInfo.W(allzeros)=0;gtInfo.H(allzeros)=0; +gtInfo.Xgp(allzeros)=0;gtInfo.Ygp(allzeros)=0; + +% now clean up zero columns +gtInfo=cleanGT(gtInfo); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/cutStateToTrackingArea.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/cutStateToTrackingArea.m new file mode 100644 index 0000000000000000000000000000000000000000..977d2e957af687926552ce27c94bcb207992f6b8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/cutStateToTrackingArea.m @@ -0,0 +1,28 @@ +function stateInfo=cutStateToTrackingArea(stateInfo) +% if we are tracking on ground plane +% remove all track segments outside tracking area +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo; + +X=stateInfo.X; Y=stateInfo.Y; +areaLimits=sceneInfo.trackingArea; + +X(XareaLimits(2))=0;Y(Y>areaLimits(4))=0; +Y(X==0)=0; X(Y==0)=0; + +% now clean up zero columns +[X Y stateInfo]=cleanState(X,Y,stateInfo); + +stateInfo.X=X; stateInfo.Y=Y; + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..9068d48fdf2e5ebc45546a2ea6631ec363810209 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayBBoxes.m @@ -0,0 +1,205 @@ +function displayBBoxes(sceneInfo,frameNums,X,Y,W,H,options) +% Draw bounding boxes on top of images +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% +[F,~]=size(X); + +ind=find(W); +aspectRatio=mean(H(ind)./W(ind)); + +%% if we want to display traces, lets compute average image +% or let's not... Doesn't look good, anyway + +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(1))]); +% avim=zeros(size(im)); +% avgF=1:5:min(500,F); +% avgnF=length(avgF); +% for t=avgF +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]); +% avim=avim+double(im)/avgnF; +% end +% avim=avim/255; + +global opt; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + al=0.5; + load(sceneInfo.bgMask); + immask=cat(3,bgmask,bgmask,bgmask); + + end + +for t=1:F + clf + im=double(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]))/255; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + imgray=rgb2gray(im); imgray=imgray+0.5; + imgray=cat(3,imgray,imgray,imgray); + im(immask)=al*im(immask)+(1-al)*(imgray(immask)); + end + + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % tracking area + if opt.track3d && opt.cutToTA + drawTALimits; + end + + + extar=find(X(t,:)); + % foot position + if options.displayDots + for id=extar + plot(X(t,id),Y(t,id),'.','color',getColorFromID(id),'MarkerSize',options.dotSize); + end + end + + % box + if options.displayBoxes + for id=extar + bleft=X(t,id)-W(t,id)/2; + bright=X(t,id)+W(t,id)/2; + btop=Y(t,id)-H(t,id); + bbottom=Y(t,id); +% line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',getColorFromID(id),'linewidth',options.boxLineWidth); + rectangle('Position',[bleft,btop,W(t,id),H(t,id)],'Curvature',[.3,.3*(W(t,id)/H(t,id))],'EdgeColor',getColorFromID(id),'linewidth',options.boxLineWidth); + end + end + + % ID + if options.displayID + for id=extar + tx=X(t,id); + ty=Y(t,id)-H(t,id)*2/3; % inside +% ty=Y(t,id)-H(t,id)-10; % on top + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',W(t,id)/2, 'FontUnits','pixels','FontWeight','bold'); + end + end + + % cropouts + if options.displayCropouts + bw=2; %border cropouts + + %% crop outs var sized + maxTar=30; + extarRed=extar(extar<=maxTar); % reducde +% crpImg=zeros(round(max(max(H))+5),round(sum(max(W))+5*bw),3); +% offset=1; +% offsets=round([1 cumsum(max(W))]); +% for id=extarRed +% % offsets(id)=offset; +% offset=offsets(id); +% bleft=round(X(t,id)-W(t,id)/2); +% bright=round(X(t,id)+W(t,id)/2); +% btop=round(Y(t,id)-H(t,id)); +% bbottom=round(Y(t,id)); +% +% ht=(bbottom-btop)+1;wt=(bright-bleft)+1; +% crpImg(1:ht,offset:offset+wt-1,:)=im(btop:bbottom,bleft:bright,:); +% % offset=offset+wt+bw; +% end + + %% crop outs fixed sized + uniH=min(60,round(sceneInfo.imgHeight/10)); uniW=round(uniH/aspectRatio); +% crpImg=zeros(round(uniH+bw),round(uniW*size(W,2)+bw*size(W,2)),3); % black + mxfac=.5; + crpImg=im(1:uniH,1:min(sceneInfo.imgWidth,round(uniW*size(W,2)+bw*size(W,2))),:)*mxfac; + crpImg=crpImg + (1-mxfac)*ones(size(crpImg)); % bleeched + for id=extarRed + offset=(id-1)*uniW + (id-1)*bw+1; + bleft=round(X(t,id)-W(t,id)/2); + bright=round(X(t,id)+W(t,id)/2); + btop=round(Y(t,id)-H(t,id)); + bbottom=round(Y(t,id)); + + [bleft bright btop bbottom]= ... + clampBBox(bleft, bright, btop, bbottom, sceneInfo.imgWidth, sceneInfo.imgHeight); + ht=uniH; + imres=imresize(im(btop:bbottom,bleft:bright,:),[uniH uniW]); + crpImg(1:ht,offset:offset+uniW-1,:)=imres; + + end + imshow(crpImg); + + for id=extarRed +% tx=offsets(id)+W(t,id)/2; + tx=id*uniW-uniW/2 + id*bw; + ty=30; % top + ty=size(crpImg,1)-10; % below + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',uniW/2, 'FontUnits','pixels','FontWeight','bold'); % fixed size +% 'FontSize',mean(W(t,extarRed))/2, 'FontUnits','pixels','FontWeight','bold'); % var size + + end + if options.displayConnections + for id=extarRed + if t-find(X(:,id),1,'first')<5 + btop=round(Y(t,id)-H(t,id)); + offset=(id-1)*uniW + (id-1)*bw+1 + uniW/2; + line([X(t,id) offset],[btop uniH],'color',getColorFromID(id),'linestyle','-'); + end + end + end + end + + % show trace + if options.traceLength + for tracet=max(1,t-options.traceLength):max(1,t-1) + ipolpar=(t-tracet)/options.traceLength; % parameter [0,1] for color adjustment + + % pick color from tail +% if tracet==max(1,t-options.traceLength) +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(tracet))]); +% end + + extarpast=find(X(tracet,:)); + % foot position + for id=extarpast + % plot(X(tracet,id),Y(tracet,id), ... + % '.','color',ipolpar*options.grey + (1-ipolpar)*getColorFromID(id),'MarkerSize',max(1,options.dotSize*(1-ipolpar))); + + + if W(tracet+1,id) + posx=round(max(1,X(t,id))); posx=min(sceneInfo.imgWidth,posx); + posy=round(max(1,Y(t,id))); posy=min(sceneInfo.imgHeight,posy); +% endcol=double(reshape(avim(posy,posx,:),1,3)); +% endcol=min(1,endcol); endcol=max(1,endcol); + endcol=options.grey; + line(X(tracet:tracet+1,id) ,Y(tracet:tracet+1,id), ... + 'color',ipolpar*endcol + (1-ipolpar)*getColorFromID(id),'linewidth',(1-ipolpar)*options.traceWidth+1); + end + + end + + end + end + + + pause(options.framePause) + + % save + if isfield(options,'outFolder'); + im2save=getframe(gcf); + im2save=im2save.cdata; + imwrite(im2save, fullfile(options.outFolder,sprintf('frame_%04d.jpg',frameNums(t)))); + end + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayDetectionBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayDetectionBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..85a14f52b9a012f72c0909b95491270609907826 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayDetectionBBoxes.m @@ -0,0 +1,81 @@ +function displayDetectionBBoxes(sceneInfo, detections) +% Display Detection Bounding Boxes +% +% Take scene information sceneInfo and +% an array of detections and display +% them on +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +reopenFig('Detections') + +F=size(detections,2); +assert(F==length(sceneInfo.frameNums), 'length of detections must be equal to the number of frames'); + +detcol=[.1 .2 .9]; +grey=.6*ones(1,3); +framePause=0.01; % pause between frames +% framePause=1; + +traceLength=10; % overlay data from past 10 frames +dotSize=20; +boxLineWidth=3; + +for t=1:F + clf + im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(t))]); + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % foot position + for k=1:length(detections(t).xp) + plot(detections(t).xp(k),detections(t).yp(k),'.','color',detcol,'MarkerSize',dotSize*detections(t).sc(k)); + end + + % box + nboxes=length(detections(t).xp); + for id=1:nboxes + bleft=detections(t).bx(id); + bright=detections(t).bx(id)+detections(t).wd(id); + btop=detections(t).by(id); + bbottom=detections(t).by(id)+detections(t).ht(id); + line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',detcol,'linewidth',boxLineWidth*detections(t).sc(id)); + end + + % show trace + for tracet=max(1,t-traceLength):max(1,t-1) + ipolpar=(t-tracet)/traceLength; % parameter [0,1] for color adjustment + + % foot position + for k=1:length(detections(tracet).xp) + plot(detections(tracet).xi(k),detections(tracet).yi(k), ... + '.','color',ipolpar*grey + (1-ipolpar)*detcol,'MarkerSize',dotSize*detections(tracet).sc(k)); + end + + % box +% nboxes=length(detections(tracet).xp); +% for id=1:nboxes +% bleft=detections(tracet).xp(id)-detections(tracet).wd(id)/2; +% bright=detections(tracet).xp(id)+detections(tracet).wd(id)/2; +% btop=detections(tracet).yp(id)-detections(tracet).ht(id); +% bbottom=detections(tracet).yp(id); +% line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',ipolpar*grey + (1-ipolpar)*detcol); +% end + + end + + pause(framePause) + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayGroundTruth.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayGroundTruth.m new file mode 100644 index 0000000000000000000000000000000000000000..4135ebf073c38772bf347eb1f08f4a32ee9da49e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayGroundTruth.m @@ -0,0 +1,42 @@ +function displayGroundTruth(sceneInfo, gtInfo) +% Display Ground Truth +% +% Take scene information sceneInfo and +% the ground truth from gtInfo +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +W=gtInfo.W; +H=gtInfo.H; + + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.01; % pause between frames + +options.traceLength=20; % overlay data from past 10 frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +X=gtInfo.X; Y=gtInfo.Y; + +reopenFig('Ground Truth'); +displayBBoxes(sceneInfo,gtInfo.frameNums,X,Y,W,H,options) + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayTrackingResult.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayTrackingResult.m new file mode 100644 index 0000000000000000000000000000000000000000..83597c454e93ecbce07b434c3c51de8295834caa --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/displayTrackingResult.m @@ -0,0 +1,47 @@ +function displayTrackingResult(sceneInfo, stateInfo) +% Display Tracking Result +% +% Take scene information sceneInfo and +% the tracking result from stateInfo +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% [~, ~, ~, ~, X Y]=getStateInfo(stateInfo); +W=stateInfo.W; +H=stateInfo.H; +Xi=stateInfo.Xi; +Yi=stateInfo.Yi; + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.001; % pause between frames + +options.traceLength=20; % overlay track from past n frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +% save? +% options.outFolder='tmp'; + +reopenFig('Tracking Results') +displayBBoxes(sceneInfo,stateInfo.frameNums,Xi,Yi,W,H,options) + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/drawTALimits.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/drawTALimits.m new file mode 100644 index 0000000000000000000000000000000000000000..dafde616beee5dd1e9e9b4561ea00ce312b4f616 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/drawTALimits.m @@ -0,0 +1,36 @@ +function drawTALimits +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo + +c1=sceneInfo.trackingArea([1 3]); +c2=sceneInfo.trackingArea([2 3]); +c3=sceneInfo.trackingArea([2 4]); +c4=sceneInfo.trackingArea([1 4]); + + +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); + +[slx sly]=worldToImage(c1(1),c1(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(1)=slx; y(1)=sly; + +[slx sly]=worldToImage(c2(1),c2(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(2)=slx; y(2)=sly; + +[slx sly]=worldToImage(c3(1),c3(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(3)=slx; y(3)=sly; + +[slx sly]=worldToImage(c4(1),c4(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(4)=slx; y(4)=sly; + +line([x x(1)],[y y(1)],'linewidth',2,'color','w','linestyle','--'); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/estimateTargetsSize.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/estimateTargetsSize.m new file mode 100644 index 0000000000000000000000000000000000000000..6b980d7429d28c68ee11eae25b7ad1fb956edc42 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/estimateTargetsSize.m @@ -0,0 +1,53 @@ +function htobj=estimateTargetsSize(sceneInfo) +% Take best n percent of detections +% and fit a 2d surface through their heights +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +npercent = 25; % best 25 % + +% scenario=41; + +% sceneInfo=getSceneInfo(scenario); +detections=parseDetections(sceneInfo); +allxi=[];allxi=[];allyi=[];allsc=[];allht=[]; + +F=length(detections); +for t=1:F + allxi=[allxi detections(t).xi]; + allyi=[allyi detections(t).yi]; + allsc=[allsc detections(t).sc]; + allht=[allht detections(t).ht]; +end +minheight=15; +% goodones=find(allsc>0.75); % confident ones + +[allsc goodones]=sort(allsc,'descend'); goodones=goodones(1:round(length(goodones)/(1/npercent*100))); + +allxi=allxi(goodones);allyi=allyi(goodones);allsc=allsc(goodones);allht=allht(goodones); +htobj=fit([allxi; allyi]',allht','poly21','Robust','on'); + +% %% +% clf +% +% plot3(allxi,allyi,allht,'.'); box on +% xlim(sceneInfo.trackingArea(1:2));ylim(sceneInfo.trackingArea(3:4)); zlim([minheight sceneInfo.imgHeight]); +% set(gca,'Ydir','reverse'); +% +% hold on +% +% %% +% +% %% +% [xi yi]=meshgrid(1:50:sceneInfo.imgWidth, 1:50:sceneInfo.imgHeight); +% htsurface=feval(fitobj,xi(:),yi(:)); htsurface=reshape(htsurface,size(xi,1),size(xi,2)); +% htsurface(htsurfacesceneInfo.imgHeight)=sceneInfo.imgHeight; +% surf(xi,yi,htsurface) +% view(-78,34) \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/evaluateDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/evaluateDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..434bc96a586ea76a1c6195bd0d5a5d8572e5e8cc --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/evaluateDetections.m @@ -0,0 +1,28 @@ +function evaluateDetections(detMatrices,gtInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt +if sceneInfo.gtAvailable + detInfo=detMatrices; detInfo.frameNums=sceneInfo.frameNums; + detInfo.X=detInfo.Xi; detInfo.Y=detInfo.Yi; + [detInfo.F detInfo.N]=size(detInfo); + + if opt.track3d + detInfo=cutStateToTrackingArea(detInfo); +% gtInfo=cutGTToTrackingArea(gtInfo); + end + + printMessage(1,'\nDetections Evaluation (2D):\n'); + [metrics metricsInfo]=CLEAR_MOT(gtInfo,detInfo,struct('eval3d',0)); + printMetrics(metrics,metricsInfo,1,[1 2 3 8 9]); + printMessage(1,'\n'); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getBBoxesFromPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getBBoxesFromPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..fa0582c8ec7ae435a635a20df52d55f93d3b0f1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getBBoxesFromPrior.m @@ -0,0 +1,79 @@ +function stateInfo=getBBoxesFromPrior(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% just take the height prior for that +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo +% [~, N F targetsExist X Y]=getStateInfo(stateInfo); +X=stateInfo.X; Y=stateInfo.Y; + +[F N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + H=heightPrior; +else + error('sorry dude'); +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +% if sceneInfo.gtAvailable +% global gtInfo +% arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% aspectRatio= arithmean; +% end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +% stateInfo.W=H*sceneInfo.targetAR; % or take data set mean +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getBBoxesFromState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getBBoxesFromState.m new file mode 100644 index 0000000000000000000000000000000000000000..84f3e7485b0eab07e403e80940bb1a13cfaeaa16 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getBBoxesFromState.m @@ -0,0 +1,207 @@ +function stateInfo=getBBoxesFromState(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% To this end, we check for corresponding detections +% and interpolate them to get the solution boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo +% [~, N F targetsExist X Y]=getStateInfo(stateInfo); +X=stateInfo.X; Y=stateInfo.Y; + +[F N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + + +for id=1:N + sid=targetsExist(id,1); + eid=targetsExist(id,2); + frames=sid:eid; + asscDet=zeros(1,F); % which detection is close by? + widths=zeros(1,F); + heights=zeros(1,F); + scores=zeros(1,F); + + % find closest detections + for t=frames + ndets=length(detections(t).xp); % how many dets in this frame + if ndets + xy=[X(t,id); Y(t,id)]; + dets=[detections(t).xp; detections(t).yp]; + + alldist=sqrt(sum((repmat(xy,1,ndets)-dets).^2)); % distance to all + [mindist mindet]=min(alldist); + if mindist<=sceneInfo.targetSize + asscDet(t)=mindet; + widths(t)=detections(t).wd(mindet); + heights(t)=detections(t).ht(mindet); + scores(t)=detections(t).sc(mindet); + end + end + end + detsAssc=find(asscDet); % which detections associated + detsAsscWobble=detsAssc;%+0.01*rand(1,length(t))-0.005; % add random noise to avoid NaN in fitting (LOOK INTO THIS!) + + if numel(unique(detsAssc))>1 + polydeg=min(9,max(1,floor(numel(detsAssc)/100))); + polystr=sprintf('poly%d',polydeg); + +% global gdetsAssc gwidths +% gdetsAssc=detsAssc; gwidths=widths(detsAssc); +% detsAssc +% unique(detsAssc) +% heights(detsAssc) +% numel(detsAssc) +% +% polydeg +% +% polystr +% p=polyfit(detsAssc,widths(detsAssc),max(1,floor(numel(detsAssc)/100))); +% p=fit(detsAssc',widths(detsAssc)',polystr,'Normalize','on','Robust','on'); + +% ipolwidths = polyval(p,frames); +% ipolwidths = feval(p,frames); +% W((sid:eid)',id)=ipolwidths'; + + + + + +% +% +% numel(detsAssc) +% p=polyfit(detsAssc,heights(detsAssc),max(1,round(numel(detsAssc)/100))); +% [p,~,~,~]=fit(detsAssc',heights(detsAssc)',polystr,'Normalize','on','Robust','on'); + sp=splinefit(detsAsscWobble, heights(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); +% pause + +% ipolheights = polyval(p,frames); +% ipolheights = feval(p,frames); + ipolheights=ppval(sp,frames); + + + H((sid:eid)',id)=ipolheights'; + + if ~isfield(sceneInfo,'targetAR') % if no aspect ratio given, estimate widths +% [p,~,~,~]=fit(detsAssc',widths(detsAssc)',polystr,'Normalize','on','Robust','on'); + sp=splinefit(detsAsscWobble, widths(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); +% ipolwidths = feval(p,frames); + ipolwidths = ppval(sp,frames); + + W((sid:eid)',id)=ipolwidths'; + + end + + else % strange trajectory with < 3 detections + detwidthmean=[]; detheightmean=[]; +% sid +% eid + for t=sid:eid + detwidthmean=[detwidthmean mean(detections(t).wd)]; + detheightmean=[detheightmean mean(detections(t).ht)]; + end +% detwidthmean +% detheightmean + detwidthmean(isnan(detwidthmean))=mean(detwidthmean(~isnan(detwidthmean))); + detheightmean(isnan(detheightmean))=mean(detheightmean(~isnan(detheightmean))); +% detwidthmean +% detheightmean + W((sid:eid)',id)=detwidthmean; + H((sid:eid)',id)=detheightmean; + end + + + +% detsAsscWobble +% +% detsAssc +% unique(detsAssc) +% heights(detsAssc) +% numel(detsAssc) +% +% clf +% hold on +% % size(frames) +% % size(ipolwidths) +% plot(detsAssc,heights(detsAssc),'o') +% plot(frames,ipolheights,'r') +% plot(frames,ppval(sp,frames),'k'); +% +% % global HP +% % plot(frames,HP((sid:eid)',id),'--'); +% +% % plot(frames,lincomb,':'); +% +% % size(sid:eid) +% % size(ipolheights) +% pause + + +end + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + prwght=.8; + H=(1-prwght)*H + prwght*heightPrior; + +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +if sceneInfo.gtAvailable + global gtInfo + arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); + aspectRatio= arithmean; +end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +% stateInfo.W=H*sceneInfo.targetAR; % or take data set mean +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getColorFromID.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getColorFromID.m new file mode 100644 index 0000000000000000000000000000000000000000..9ac27b6f3f79c5891348d2e7bf365d61620f6fc7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getColorFromID.m @@ -0,0 +1,32 @@ +function col=getColorFromID(id) + % get rgb [0,1] values from id +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + colors=getIDColors; + col=colors((mod(id,size(colors,1)))+1,:); +end + +function colors=getIDColors() +colors=[ + 128 255 255; % + 255 0 0; % red 1 + 0 255 0; % green 2 + 0 0 255; % blue 3 + 0 255 255; % cyan 4 + 255 0 255; % magenta 5 + 212 212 0; % yellow 6 + 25 25 25; % black 7 + 34,139,34; % forestgreen 8 + 0,191,255; % deepskyblue 9 + 139,0,0 ; % darkred 10 + 218,112,214; % orchid 11 + 244,164,96 ;]; % sandybrown 12 +colors = colors / 255; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getDetectionMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getDetectionMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..ccf365e0f6df009aa59c17e676dd0af9cec0c320 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getDetectionMatrices.m @@ -0,0 +1,36 @@ +function detMat = getDetectionMatrices(detections) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=length(detections); +Xd=zeros(F,0); +Yd=zeros(F,0); +Sd=zeros(F,0); + +Xi=zeros(F,0); +Yi=zeros(F,0); +W=zeros(F,0); +H=zeros(F,0); +for t=1:length(detections); + Dt=length(detections(t).xp); + Xd(t,1:Dt)=detections(t).xp; + Yd(t,1:Dt)=detections(t).yp; + Sd(t,1:Dt)=detections(t).sc; + + Xi(t,1:Dt)=detections(t).xi; + Yi(t,1:Dt)=detections(t).yi; + W(t,1:Dt)=detections(t).wd; + H(t,1:Dt)=detections(t).ht; +end + +detMat.Xd=Xd; +detMat.Yd=Yd; +detMat.Sd=Sd; + +detMat.Xi=Xi;detMat.Yi=Yi;detMat.W=W;detMat.H=H; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getHeightPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getHeightPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..0f0cf37058d32fb215ae0b6b3265328d9c4f47f1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getHeightPrior.m @@ -0,0 +1,42 @@ +function heightPrior=getHeightPrior(stateInfo) +% for 3d tracking we can compute +% an approximate average bounding box for each target +% which corresponds to a height of 1.70 m in the world +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global sceneInfo +camPar=sceneInfo.camPar; + +% rx=camPar.mExt.mRx;ry=camPar.mExt.mRy;rz=camPar.mExt.mRz; +% tx=camPar.mExt.mTx;ty=camPar.mExt.mTy;tz=camPar.mExt.mTz; +% txi=camPar.mExt.mTxi;tyi=camPar.mExt.mTyi;tzi=camPar.mExt.mTzi; +% kappa=camPar.mInt.mKappa1; focal=camPar.mInt.mFocal;Sx=camPar.mInt.mSx; +% Dpx=camPar.mGeo.mDpx;Dpy=camPar.mGeo.mDpy; + +% [mR mT]=getRotTrans(sceneInfo.camPar); + +% feet +Z=0*ones(size(stateInfo.Xgp)); +[Xi0 Yi0]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +% heads +Z=1700*ones(size(stateInfo.Xgp)); +[XiH YiH]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +heightPrior=Yi0-YiH; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getHomeFolder.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getHomeFolder.m new file mode 100644 index 0000000000000000000000000000000000000000..73c516d61d583341e7938351ddd12e1c9de04ad0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getHomeFolder.m @@ -0,0 +1,18 @@ +function homedir=getHomeFolder() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + homedir='/home/aanton'; + if ispc + homedir='D:'; + end + if exist('/gris/gris-f/home/aandriye','dir') + homedir='/gris/gris-f/home/aandriye'; + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..35b13964f06515bc0f4136d073d0ef57755314fb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/getSceneInfo.m @@ -0,0 +1,526 @@ +function sceneInfo=getSceneInfo(scenario) +% fill all necessary information about the +% scene into the sceneInfo struct +% +% Required: +% detfile detections file (.idl or .xml) +% frameNums frame numbers (eg. frameNums=1:107) +% imgFolder image folder +% imgFileFormat format for images (eg. frame_%04d.jpg) +% targetSize approx. size of targets (default: 5 on image, 350 in 3d) +% +% Required for 3D Tracking only +% trackingArea tracking area +% camFile camera calibration file (.xml PETS format) +% +% Optional: +% gtFile file with ground truth bounding boxes (.xml CVML) +% initSolFile initial solution (.xml or .mat) +% targetAR aspect ratio of targets on image +% bgMask mask to bleach out the background +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt +% opt=getOptions; +% general folders +homefolder=getHomeFolder; +dbfolder=fullfile(filesep,'storage','databases'); if ispc, dbfolder=fullfile('D:','storage','databases'); end +if exist('/gris','dir'), dbfolder=fullfile(filesep,'gris','takatuka_dbases'); end + +% detection file +switch(scenario) + case {23,25,27,70,71,72,73,74,75,80} + dataset='PETS2009'; + case {40,41,42} + dataset='TUD'; + case {30,31,32,35,36,37} + dataset='TUD10'; + case {50,51,52,53} + dataset='ETH-Person'; + case {60,61,62} + dataset='AVSS'; + case {48} + dataset='UBC'; + case {90,91,92} + dataset='DA-ELS'; + otherwise + error('unknown scenario'); +end + +% sequence name +switch(scenario) + case 23 + seqname='PETS2009-S2L1-c1'; + case 25 + seqname='PETS2009-S2L2-c1'; + case 27 + seqname='PETS2009-S2L3-c1'; + case 31 + seqname='TUD10-ped1-c1'; + case 32 + seqname='TUD10-ped1-c2'; + case 36 + seqname='TUD10-ped1-c1'; + case 37 + seqname='TUD10-ped2-c2'; + case 40 + seqname='TUD-Campus'; + case 41 + seqname='TUD-Crossing'; + case 42 + seqname='TUD-Stadtmitte'; + case 48 + seqname='Hockey'; + case {50,51,52,53} + seqname=sprintf('seq%02d',scenario-50); + case 60 + seqname='AB_Easy'; + case 61 + seqname='AB_Medium'; + case 62 + seqname='AB_Hard'; + case 70 + seqname='PETS2009-S1L1-1-c1'; + case 71 + seqname='PETS2009-S1L1-2-c1'; + case 72 + seqname='PETS2009-S1L2-1-c1'; + case 73 + seqname='PETS2009-S1L2-2-c1'; + case 74 + seqname='PETS2009-S1L3-1-c1'; + case 75 + seqname='PETS2009-S1L3-2-c1'; + case 80 + seqname='PETS2009-S3MF1-c1'; + case {90,91,92,93,94} + seqname=sprintf('s%02d',scenario-90); + otherwise + + error('unknown scenario'); +end + +% frameNums +switch(scenario) + case 20 % terrace1 + sceneInfo.frameNums=1:2000; + case 21 % terrace2 + sceneInfo.frameNums=1:2000; + case {22,23} % PETS 2009 S2 L1 + sceneInfo.frameNums=0:794; + case 24 % PETSMONO occlusion + sceneInfo.frameNums=0:794; + case 25 + sceneInfo.frameNums=0:435; + case 27 + sceneInfo.frameNums=0:239; + case {30,31,32,33} % TUD10 ped + sceneInfo.frameNums=1:1400; + % sceneInfo.frameNums=1:300; + case {35,36,37} % TUD10 ped2 + sceneInfo.frameNums=1:1999; + % sceneInfo.frameNums=1:199; + % sceneInfo.frameNums=1670:1680; + % sceneInfo.frameNums=760:770; + case 40 % tud-campus + sceneInfo.frameNums=90:160; + case {41,44} % tud-crossing + sceneInfo.frameNums=1:201; + case 42 % tud-stadtmitte + sceneInfo.frameNums=7022:7200; + % sceneInfo.frameNums=7022:7100; + case 45 % eth central xing1 + sceneInfo.frameNums=1600:2200; + case 46 % eth central xing1 + sceneInfo.frameNums=3300:3600; + case 47 % eth central xing1 + sceneInfo.frameNums=7433:7811; + case 48 % UBC Hockey + sceneInfo.frameNums=700:800; + case 50 % ETH Person seq0 + sceneInfo.frameNums=180:678; + case 51 % ETH Person seq1 + sceneInfo.frameNums=0:999; + case 52 % ETH Person seq2 + sceneInfo.frameNums=0:450; + case 53 % ETH Person seq3 + sceneInfo.frameNums=100:453; + case {60,61,62} % AVSS + sceneInfo.frameNums=1:2000; + case 70 + sceneInfo.frameNums=0:220; + case 71 + sceneInfo.frameNums=0:240; + case 72 + sceneInfo.frameNums=0:200; + case 73 + sceneInfo.frameNums=0:130; + case 74 + sceneInfo.frameNums=0:90; + case 75 + sceneInfo.frameNums=0:343; + case 80 + sceneInfo.frameNums=1:107; + case 81 + sceneInfo.frameNums=0:231; + case 82 + sceneInfo.frameNums=0:108; + case 83 + sceneInfo.frameNums=0:169; + case 84 + sceneInfo.frameNums=0:92; + case 85 + sceneInfo.frameNums=0:107; + case 86 + sceneInfo.frameNums=0:184; + % case 90 + % sceneInfo.frameNums=1:593; + % case 91 + % sceneInfo.frameNums=1:307; + % case 92 + % sceneInfo.frameNums=1:420; + case {101,131} % EnterExitCrossingPaths1 cor, front + sceneInfo.frameNums=0:382; + case {102,132} % EnterExitCrossingPaths2 cor, front + sceneInfo.frameNums=0:484; + case {103,133} % OneLeaveShop1 cor, front + sceneInfo.frameNums=0:294; + case {104,134} % OneLeaveShop2 cor, front + sceneInfo.frameNums=0:1118; + case {105,135} % OneLeaveShopReenter1 cor, front + sceneInfo.frameNums=0:389; + case {106,136} % OneLeaveShopReenter2 cor, front + sceneInfo.frameNums=0:559; + case {107,137} % OneShopOneWait1 cor, front + sceneInfo.frameNums=0:1376; + case {108,138} % OneShopOneWait2 cor, front + sceneInfo.frameNums=0:1461; + case {109,139} % OneStopEnter1 cor, front + sceneInfo.frameNums=0:1499; + case {110,140} % OneStopEnter2 cor, front + sceneInfo.frameNums=0:2724; + case {111,141} % OneStopMoveEnter1 cor, front + sceneInfo.frameNums=0:1586; + case {112,142} % OneStopMoveEnter2 cor, front + sceneInfo.frameNums=0:2236; + case {113,143} % OneStopMoveNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {114,144} % OneStopMoveNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {115,145} % OneStopNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {116,146} % OneStopNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {117,147} % ShopAssistant1 cor, front + sceneInfo.frameNums=0:1674; + case {118,148} % ShopAssistant2 cor, front + sceneInfo.frameNums=0:3699; + case {119,149} % ThreePastShop1 cor, front + sceneInfo.frameNums=0:1649; + case {120,150} % ThreePastShop2 cor, front + sceneInfo.frameNums=0:1520; + case {121,151} % TwoEnterShop1 cor, front + sceneInfo.frameNums=0:1644; + case {122,152} % TwoEnterShop2 cor, front + sceneInfo.frameNums=0:1604; + case {123,153} % TwoEnterShop3 cor, front + sceneInfo.frameNums=0:1604; + case {124,154} % TwoLeaveShop1 cor, front + sceneInfo.frameNums=0:1342; + case {125,155} % TwoLeaveShop2 cor, front + sceneInfo.frameNums=0:599; + case {126,156} % WalkByShop1 cor, front + sceneInfo.frameNums=0:2359; + case 160 + sceneInfo.frameNums=171:184; + case {161,162} + sceneInfo.frameNums=97:114; + otherwise + warning('unknown scenario getFrameNums'); +end + + +detfolder=fullfile(homefolder,'diss','detections','hog-hof-linsvm',dataset,seqname); +% detfolder=fullfile(homefolder,'diss','detections','swd-v2',dataset,seqname); +% detfolder=fullfile(dbfolder,'data-tud','det','',dataset,seqname); + +% detfile +switch(scenario) + case 51 + sceneInfo.detfile=fullfile(detfolder,'test-result-nms-0.8.idl'); + case 53 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'seq03-annot.idl'); + case 62 + sceneInfo.detfile=fullfile(detfolder,['AVSS-' seqname sprintf('-result-00000-05059-nms.idl',length(sceneInfo.frameNums)-1)]); + case 48 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'detections.mat'); + case {90,91,92} + sceneInfo.detfile=fullfile(detfolder,'detections.mat'); + case {23,25,27,70,71,72,73,80,40,41,42} + sceneInfo.detfile=fullfile(dbfolder,'data-tud','det',dataset,[seqname '-det.xml']); + otherwise + sceneInfo.detfile=fullfile(detfolder,[seqname sprintf('-result-00000-%05d-nms.idl',length(sceneInfo.frameNums)-1)]); + +end +assert(exist(sceneInfo.detfile,'file')==2,'detection file does not exist') + + +% img Folder +switch(scenario) + case 23 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); + case 25 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L2','Time_14-55','View_001',filesep); + case 27 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L3','Time_14-41','View_001',filesep); + case 31 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c1',filesep); + case 32 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c2',filesep); + case 36 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c1',filesep); + case 37 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c2',filesep); + case 40 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-campus-sequence',filesep); + case 41 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-crossing-sequence',filesep); + case 42 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-stadtmitte',filesep); + case 48 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case {50,51,52,53} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,'left',filesep); + case {60,61,62} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case 70 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-57','View_001',filesep); + case 71 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-59','View_001',filesep); + case 72 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-06','View_001',filesep); + case 73 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-31','View_001',filesep); + case 80 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 + case {90,91,92,93} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + otherwise + error('unknown scenario image Folder'); +end +assert(exist(sceneInfo.imgFolder,'dir')==7,'imgfolder does not exist') + +% image extension +imgExt='.jpg'; +switch(scenario) + case {20,21,40,41,42,44,50,51,52,53} + imgExt='.png'; +end +sceneInfo.imgFileFormat='frame_%04d'; + +switch(scenario) + case 40 + sceneInfo.imgFileFormat='DaSide0811-seq6-%03d'; + case 41 + sceneInfo.imgFileFormat='DaSide0811-seq7-%03d'; + case 42 + sceneInfo.imgFileFormat='DaMultiview-seq%04d'; + case 48 + sceneInfo.imgFileFormat='h%04d'; + case {50,51,52,53} + sceneInfo.imgFileFormat='image_%08d_0'; + case {90,91,92,93} + sceneInfo.imgFileFormat='%05d'; +end + +% append file extension +sceneInfo.imgFileFormat=[sceneInfo.imgFileFormat imgExt]; + +% if no frame nums, determine from images +if ~isfield(sceneInfo,'frameNums') + imglisting=dir([sceneInfo.imgFolder '*' imgExt]); + sceneInfo.frameNums=1:length(imglisting); +end + +% image dimensions +[sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... + size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); + + + + +%% tracking area +% if we are tracking on the ground plane +% we need to explicitly secify the tracking area +% otherwise image = tracking area +if opt.track3d + switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.trackingArea=[-14069.6, 4981.3, -14274.0, 1733.5]; + case {30,31,32} + sceneInfo.trackingArea=[-197 6708 -2021 6870]; + case {35,36,37} + sceneInfo.trackingArea=[-3438 5271 -2018 7376]; + case 40 + sceneInfo.trackingArea=[-0150 0506 28 1081]; + case 41 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + case 42 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + otherwise + error('Definition of tracking area needed for 3d tracking'); + end + +else + sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +end + +%% camera +cameraconffile=[]; +if opt.track3d + cam=1; + switch(scenario) + case {20,21} %terrace + cameraconffile=sprintf('%sepfl/terrace-tsai-c%i.xml',dbfolder,cam); + case {22, 23,25,27,70,71,72,73,74,75,80,81,82,83,84,85,86} %PETS2009 + cameraconffile=fullfile(dbfolder,dataset,'View_001.xml'); + case 24 + cameraconffile=sprintf('%sPETS2009/View_001.xml',dbfolder); + case 30 + cameraconffile=sprintf('%sTUD10/ped1/c%i-calib.xml',dbfolder,cam); + case 31 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c1-calib.xml'); + case 32 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c2-calib.xml'); + case 36 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c1-calib.xml'); + case 37 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c2-calib.xml'); + case {40,43} + cameraconffile=fullfile(dbfolder,dataset,'tud-campus-calib.xml'); + case {41,44} + cameraconffile=fullfile(dbfolder,dataset,'tud-crossing-calib.xml'); + case 42 + cameraconffile=fullfile(dbfolder,dataset,'tud-stadtmitte-calib.xml'); + case {45,46,47} + cameraconffile=sprintf('%sETH-Central/pedxing-seq1-calib.xml',dbfolder); + case {60,61,62} + cameraconffile=sprintf('%sAVSS/AB_calib.xml',dbfolder); + case intersect(scenario,101:126); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-cor.xml',dbfolder); + case intersect(scenario,131:156); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + case intersect(scenario,160:163) %%% !!! FIX !!! + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + otherwise + error('unknown scenario'); + end +end +sceneInfo.camFile=cameraconffile; + +if ~isempty(sceneInfo.camFile) + sceneInfo.camPar=parseCameraParameters(sceneInfo.camFile); +end + + +%% target size +sceneInfo.targetSize=20; % target 'radius' +sceneInfo.targetSize=sceneInfo.imgWidth/30; +if opt.track3d, sceneInfo.targetSize=350; end + +%% target aspect ratio +sceneInfo.targetAR=1/3; +switch(scenario) + case 48 % Hockey + sceneInfo.targetAR=1/2; + case {90,91,92} % aerial + sceneInfo.targetAR=1; +end + + +%% ground truth +sceneInfo.gtFile=''; +switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + case 31 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c1','GT2d_full_new.mat'); + case 32 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c2','GT2d_full_new.mat'); + case {40,41} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '-interp.mat']); + case 42 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + % sceneInfo.gtFile='/home/aanton/diss/others/yangbo/TUD/TUD_Stadtmitte.avi.gt.mat'; % Yang + case 62 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,'AB_Hard','GT2d_new.mat'); + otherwise + warning('ground truth?'); +end + + +global gtInfo +sceneInfo.gtAvailable=0; +if ~isempty(sceneInfo.gtFile) + sceneInfo.gtAvailable=1; + % first determine the type + [pathtogt, gtfile, fileext]=fileparts(sceneInfo.gtFile); + + if strcmpi(fileext,'.xml') % CVML + gtInfo=parseGT(sceneInfo.gtFile); + elseif strcmpi(fileext,'.mat') + % check for the var gtInfo + fileInfo=who('-file',sceneInfo.gtFile); + varExists=0; cnt=0; + while ~varExists && cnt0.7)=Inf; +[a,b]=munkres(A); +%} +% Example 4: an example of partial assignment +%{ +A = [1 3 Inf; Inf Inf 5; Inf Inf 0.5]; +[a,b]=munkres(A) +%} +% a = [1 0 3] +% b = 1.5 +% Reference: +% "Munkres' Assignment Algorithm, Modified for Rectangular Matrices", +% http://csclab.murraystate.edu/bob.pilgrim/445/munkres.html + +% version 2.3 by Yi Cao at Cranfield University on 11th September 2011 + +assignment = zeros(1,size(costMat,1)); +cost = 0; + +validMat = costMat == costMat & costMat < Inf; +bigM = 10^(ceil(log10(sum(costMat(validMat))))+1); +costMat(~validMat) = bigM; + +% costMat(costMat~=costMat)=Inf; +% validMat = costMat0) + break + end + coverColumn = false(1,n); + coverColumn(starZ(starZ>0))=true; + coverRow = false(n,1); + primeZ = zeros(n,1); + [rIdx, cIdx] = find(dMat(~coverRow,~coverColumn)==bsxfun(@plus,minR(~coverRow),minC(~coverColumn))); + while 1 + %************************************************************************** + % STEP 4: Find a noncovered zero and prime it. If there is no starred + % zero in the row containing this primed zero, Go to Step 5. + % Otherwise, cover this row and uncover the column containing + % the starred zero. Continue in this manner until there are no + % uncovered zeros left. Save the smallest uncovered value and + % Go to Step 6. + %************************************************************************** + cR = find(~coverRow); + cC = find(~coverColumn); + rIdx = cR(rIdx); + cIdx = cC(cIdx); + Step = 6; + while ~isempty(cIdx) + uZr = rIdx(1); + uZc = cIdx(1); + primeZ(uZr) = uZc; + stz = starZ(uZr); + if ~stz + Step = 5; + break; + end + coverRow(uZr) = true; + coverColumn(stz) = false; + z = rIdx==uZr; + rIdx(z) = []; + cIdx(z) = []; + cR = find(~coverRow); + z = dMat(~coverRow,stz) == minR(~coverRow) + minC(stz); + rIdx = [rIdx(:);cR(z)]; + cIdx = [cIdx(:);stz(ones(sum(z),1))]; + end + if Step == 6 + % ************************************************************************* + % STEP 6: Add the minimum uncovered value to every element of each covered + % row, and subtract it from every element of each uncovered column. + % Return to Step 4 without altering any stars, primes, or covered lines. + %************************************************************************** + [minval,rIdx,cIdx]=outerplus(dMat(~coverRow,~coverColumn),minR(~coverRow),minC(~coverColumn)); + minC(~coverColumn) = minC(~coverColumn) + minval; + minR(coverRow) = minR(coverRow) - minval; + else + break + end + end + %************************************************************************** + % STEP 5: + % Construct a series of alternating primed and starred zeros as + % follows: + % Let Z0 represent the uncovered primed zero found in Step 4. + % Let Z1 denote the starred zero in the column of Z0 (if any). + % Let Z2 denote the primed zero in the row of Z1 (there will always + % be one). Continue until the series terminates at a primed zero + % that has no starred zero in its column. Unstar each starred + % zero of the series, star each primed zero of the series, erase + % all primes and uncover every line in the matrix. Return to Step 3. + %************************************************************************** + rowZ1 = find(starZ==uZc); + starZ(uZr)=uZc; + while rowZ1>0 + starZ(rowZ1)=0; + uZc = primeZ(rowZ1); + uZr = rowZ1; + rowZ1 = find(starZ==uZc); + starZ(uZr)=uZc; + end +end + +% Cost of assignment +rowIdx = find(validRow); +colIdx = find(validCol); +starZ = starZ(1:nRows); +vIdx = starZ <= nCols; +assignment(rowIdx(vIdx)) = colIdx(starZ(vIdx)); +pass = assignment(assignment>0); +pass(~diag(validMat(assignment>0,pass))) = 0; +assignment(assignment>0) = pass; +cost = trace(costMat(assignment>0,assignment(assignment>0))); + +function [minval,rIdx,cIdx]=outerplus(M,x,y) +ny=size(M,2); +minval=inf; +for c=1:ny + M(:,c)=M(:,c)-(x+y(c)); + minval = min(minval,min(M(:,c))); +end +[rIdx,cIdx]=find(M==minval); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/myLinExtrap.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/myLinExtrap.m new file mode 100644 index 0000000000000000000000000000000000000000..4f1e2e60b8793bfa472b71825a6401561cb77b21 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/myLinExtrap.m @@ -0,0 +1,26 @@ +function yi=myLinExtrap(Y,steps) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% only takes two element vectors Y +if length(Y)~=2, error('Y must be of length 2'); end + + +n=Y(1); m=diff(Y); + +if steps<0 + xi=steps:-1; +else + xi=(1:steps)+1; +end + +yi = m*xi + n; + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/parseDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/parseDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..3480587e514e9fd56dc963c11243b893318bd8c3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/parseDetections.m @@ -0,0 +1,119 @@ +function [detections, nDets]=parseDetections(sceneInfo,frames) +% read detection file and create a struct array +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt +nDets=0; + +detfile = sceneInfo.detfile; +% first determine the type +[pathstr, filename, ~] = fileparts(detfile); +% is there a .mat file available? +matfile=fullfile(pathstr,[filename '.mat']); +% if exist(matfile,'file') +% load(matfile,'detections'); +% detections = setDetectionPositions(detections); +% % check if all info is available +% if (~isfield(detections,'xp') || ... +% ~isfield(detections,'yp') || ... +% ~isfield(detections,'sc') || ... +% ~isfield(detections,'wd') || ... +% ~isfield(detections,'ht')) +% error('detections must have fields xp,yp,sc,wd,ht'); +% end +% +% if nargin==2 +% detections=detections(frames); +% end +% +% % count detections +% if ~nDets +% for t=1:length(detections),nDets=nDets+length(detections(t).xp);end +% end +% +% return; +% end + +%% now parse +detectionSet = load(detfile); +if(1) + newdetections = detectionAddNoise(detectionSet); +end + +cnt = numel(sceneInfo.frameNums); +detections(cnt).bx=[]; +detections(cnt).by=[]; +detections(cnt).xp=[]; +detections(cnt).yp=[]; +detections(cnt).ht=[]; +detections(cnt).wd=[]; +detections(cnt).sc=[]; + +detections(cnt).xi=[]; +detections(cnt).yi=[]; +for t = 1:numel(sceneInfo.frameNums); + if(~mod(t,100)) + fprintf('.'); + end + idxObj = find(detectionSet(:, 5) == t); + nObjects = numel(idxObj); + bx =[];by=[];xp=[];yp=[]; + ht=[];wd=[];sc=[]; + xi=[];yi=[]; + for j = 1:nObjects + loc = detectionSet(idxObj(j), 1:4); +% score = detectionSet(idxObj(j), 7); + left = loc(1); top = loc(2); + width = loc(3)-left+1;height = loc(4)-top+1; + xis = left + width/2; + yis = top + height; + bx = cat(2, bx, left); + by=cat(2, by, top); + xp=cat(2, xp, xis); + yp=cat(2, xp, yis); + ht=cat(2, ht, height); + wd=cat(2, wd, width); + sc=cat(2, sc, 1); + xi=cat(2, xi, xis); + yi=cat(2, yi, yis); + end + detections(t).bx=bx; + detections(t).by=by; + detections(t).xp=xp; + detections(t).yp=yp; + detections(t).ht=ht; + detections(t).wd=wd; + detections(t).sc=sc; + + detections(t).xi=xi; + detections(t).yi=yi; + + nDets=nDets+length(xi); +end + + +%% set xp and yp accordingly +detections = setDetectionPositions(detections); + +% save detections in a .mat file +save(matfile,'detections'); + +end + +function detections=setDetectionPositions(detections) +% set xp,yp to xi,yi if tracking is in image (2d) +% set xp,yp to xw,yi if tracking is in world (3d) + F = length(detections); + + for t=1:F + detections(t).xp=detections(t).xi; + detections(t).yp=detections(t).yi; + end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/parseGT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/parseGT.m new file mode 100644 index 0000000000000000000000000000000000000000..309e82887abf389bf0d92264f4c81ee04acb3eab --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/parseGT.m @@ -0,0 +1,64 @@ +function gtInfo=parseGT(gtfile) +% read ground truth bounding boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% first determine the type +[~, ~, fileext]=fileparts(gtfile); + +% for now, we can only read CVML schema +if strcmpi(fileext,'.xml'); +else error('Unknown type of detections file.'); +end + +%% now parse +xDoc=xmlread(gtfile); + +allFrames=xDoc.getElementsByTagName('frame'); +F=allFrames.getLength; +frameNums=zeros(1,F); + + +%% +for t=1:F + if ~mod(t,20), fprintf('.'); end + % what is the frame + frame=str2double(allFrames.item(t-1).getAttribute('number')); + frameNums(t)=frame; + + objects=allFrames.item(t-1).getElementsByTagName('object'); + Nt=objects.getLength; + for i=0:Nt-1 + id=str2double(objects.item(i).getAttribute('id')); + if id<1, error('uh oh. IDs should be positive'); end + box=objects.item(i).getElementsByTagName('box'); + h=str2double(box.item(0).getAttribute('h')); + w=str2double(box.item(0).getAttribute('w')); + xc=str2double(box.item(0).getAttribute('xc')); + yc=str2double(box.item(0).getAttribute('yc')); + + % foot position + gtInfo.X(t,id)=xc; gtInfo.Y(t,id)=yc+h/2; + gtInfo.H(t,id)=h; gtInfo.W(t,id)=w; + end +end + +gtInfo.frameNums=frameNums; +% remove zero columns +notEmpty=~~sum(gtInfo.X); +gtInfo.X=gtInfo.X(:,notEmpty); +gtInfo.Y=gtInfo.Y(:,notEmpty); +gtInfo.W=gtInfo.W(:,notEmpty); +gtInfo.H=gtInfo.H(:,notEmpty); + + +% fprintf('all read\n'); + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/parseVehicleGT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/parseVehicleGT.m new file mode 100644 index 0000000000000000000000000000000000000000..c6af75d426cc74efe727c342e0c3c97f00ef7db8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/parseVehicleGT.m @@ -0,0 +1,36 @@ +function gtInfo = parseVehicleGT(gtfile, frameNums) +% read ground truth bounding boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +%% now parse +gt = load(gtfile); +for t = frameNums + idx = find(gt(:,5) == t); + for i = 1:numel(idx) + h = gt(idx(i), 4) - gt(idx(i), 2) + 1; + w = gt(idx(i), 3) - gt(idx(i), 1) + 1; + xc = gt(idx(i), 1) + w/2; + yc = gt(idx(i), 2) + h/2; + id = gt(idx(i), 6); + % foot position + gtInfo.X(t,id)=xc; gtInfo.Y(t,id)=yc+h/2; + gtInfo.H(t,id)=h; gtInfo.W(t,id)=w; + end +end + +gtInfo.frameNums = frameNums; +% remove zero columns +notEmpty = ~~sum(gtInfo.X); +gtInfo.X = gtInfo.X(:,notEmpty); +gtInfo.Y = gtInfo.Y(:,notEmpty); +gtInfo.W = gtInfo.W(:,notEmpty); +gtInfo.H = gtInfo.H(:,notEmpty); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/pdfcrop.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/pdfcrop.m new file mode 100644 index 0000000000000000000000000000000000000000..08a8e427e01bd46c317fa3afaf61e337288e1319 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/pdfcrop.m @@ -0,0 +1,3 @@ +function pdfcrop(pdffile) + eval(sprintf('!pdfcrop %s %s >& /dev/null',pdffile,pdffile)); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/plotDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/plotDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..9cc7d63d4dcdfd98e6576f8dbc0b0113f0817625 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/plotDetections.m @@ -0,0 +1,61 @@ +function plotDetections(plot3d, limits) +% plot detections as dots +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo + +hold on +% axis equal + +dets=detections; +F=size(dets,2); +detcol=[.6 .6 .6]; +maxFrames=200; +% plot3d=1; + +% imshow(imread('/storage/databases/PETS2009/Crowd_PETS09/S3/Multiple_Flow/Time_12-43/View_001/frame_0026.jpg')); + +if ~exist('plot3d','var'), plot3d=0; end + +if plot3d + for t=1:min(F,maxFrames) +% t +% t*ones(1,length(dets(t).xp)) +% pause + plot3(dets(t).xp,dets(t).yp,t*ones(1,length(dets(t).xp)),'.','color',detcol); + +% pause(.01) + end +% view(3) +% zlim([0 min(F,maxFrames)]); +else + for t=1:F + plot(dets(t).xp,dets(t).yp,'.','color',detcol); + end + +end + +if exist('limits','var') + if length(limits)==4 || length(limits)==6 + xlim(limits(1:2)); + ylim(limits(3:4)); +% if length(limits)==6 +% zlim(limits(5:6)); +% end + else + error('limits must be 4 or 6 long vector'); + end +else + xlim(sceneInfo.trackingArea(1:2)); + ylim(sceneInfo.trackingArea(3:4)); +end + +pause(0.001); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/postProcessState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/postProcessState.m new file mode 100644 index 0000000000000000000000000000000000000000..75eefed3d4c8950da89b4591a6f31e8bfc7083d7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/postProcessState.m @@ -0,0 +1,29 @@ +function stateInfo=postProcessState(stateInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt sceneInfo + + +if opt.track3d && opt.cutToTA + stateInfo=cutStateToTrackingArea(stateInfo); +end + +% if we tracked on image, Xi = X +if ~opt.track3d + stateInfo.Xi=stateInfo.X; stateInfo.Yi=stateInfo.Y; +% otherwise project back +else + stateInfo.Xgp=stateInfo.X; stateInfo.Ygp=stateInfo.Y; + [stateInfo.Xi, stateInfo.Yi]=projectToImage(stateInfo.X,stateInfo.Y,sceneInfo); +end + +%% get bounding boxes from corresponding detections +stateInfo=getBBoxesFromState(stateInfo); +% stateInfo=getBBoxesFromPrior(stateInfo); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/prepFigure.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/prepFigure.m new file mode 100644 index 0000000000000000000000000000000000000000..27443be17e1e3b690c8d3b28ed6cfcc44fb01ee0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/prepFigure.m @@ -0,0 +1,39 @@ +function prepFigure() +% prepare figure for showing state +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt; + +% figh=findobj('type','figure','name','optimization'); + +% if isempty(figh), figh=figure('name','optimization'); end +% set(figh); + +clf; +hold on; +box on + +if ~opt.track3d + set(gca,'Ydir','reverse'); +end +xlim(sceneInfo.trackingArea(1:2)) +ylim(sceneInfo.trackingArea(3:4)) +if ~opt.track3d + ylim([sceneInfo.imTopLimit sceneInfo.trackingArea(4)]); +end + +zlim([0 length(sceneInfo.frameNums)]) + +view(-78,4) +if ~opt.track3d + view(-40,10); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printFinalEvaluation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printFinalEvaluation.m new file mode 100644 index 0000000000000000000000000000000000000000..6d99b03b0073658a9fa79002085ae48f6e53e38f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printFinalEvaluation.m @@ -0,0 +1,30 @@ +function printFinalEvaluation(res_path, res_mat_name, cutgtFile, frame_end) + +% load gtInfo +load(cutgtFile); +% load stateInfo +left = load([res_path res_mat_name '_LX.txt']); +top = load([res_path res_mat_name '_LY.txt']); +right = load([res_path res_mat_name '_RX.txt']); +down = load([res_path res_mat_name '_RY.txt']); +stateInfo = []; +h = down - top; +w = right - left; +xc = left + w/2; +yc = top + h/2; +% foot position +stateInfo.X = xc; +stateInfo.Y = yc+h/2; +stateInfo.H = h; +stateInfo.W = w; +stateInfo.F = frame_end; +stateInfo.frameNums = 1:frame_end; +stateInfo.Xgp = stateInfo.X; +stateInfo.Ygp = stateInfo.Y; +stateInfo.Xi = stateInfo.X; +stateInfo.Yi = stateInfo.Y; + +% print result +printMessage(1,'\nEvaluation 2D:\n'); +[metrics, metricsInfo]=CLEAR_MOT(gtInfo,stateInfo); +printMetrics(metrics,metricsInfo,1); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printMessage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printMessage.m new file mode 100644 index 0000000000000000000000000000000000000000..bc6b7d8f3bc92fea3d77c7185445c603db3b0aee --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printMessage.m @@ -0,0 +1,11 @@ +function printMessage(L,F,varargin) +% print a formatted string as F with values from varargin and debug level L +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +fprintf(F,varargin{:}); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printMetrics.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printMetrics.m new file mode 100644 index 0000000000000000000000000000000000000000..6b8a7929c06d6193c3a6a58b66858ea9ee234965 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printMetrics.m @@ -0,0 +1,43 @@ +function printMetrics(metrics, metricsInfo, dispHeader,dispMetrics,padChar) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +namesToDisplay=metricsInfo.names.long; +widthsToDisplay=metricsInfo.widths.long; +formatToDisplay=metricsInfo.format.long; + +namesToDisplay=metricsInfo.names.short; +widthsToDisplay=metricsInfo.widths.short; +formatToDisplay=metricsInfo.format.short; + +if nargin<3, dispHeader=1; end +if nargin<4 + dispMetrics=1:length(metrics); +end +if nargin<5 + padChar={' ',' ','|',' ',' ',' ','|',' ',' ',' ','| ',' ',' ',' '}; +end + +if dispHeader + for m=dispMetrics + printString=sprintf('fprintf(''%%%is%s'',char(namesToDisplay(m)))',widthsToDisplay(m),char(padChar(m))); + eval(printString) + end + fprintf('\n'); +end + +for m=dispMetrics + printString=sprintf('fprintf(''%%%i%s%s'',metrics(m))',widthsToDisplay(m),char(formatToDisplay(m)),char(padChar(m))); + eval(printString) +end + +% if standard, new line +if nargin<4 + fprintf('\n'); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..a06683f310651afbaca7ba0e8a767ecf4e9dc939 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/printSceneInfo.m @@ -0,0 +1,43 @@ +function printSceneInfo() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% prints information about the scene + +% sceneInfo.targetSize=10; % target 'radius' +% +% +% % sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); % 23 +% sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 +% +% sceneInfo.imgFileFormat='frame_%04d.jpg'; +% sceneInfo.frameNums=1:107; +% % sceneInfo.frameNums=0:794; +% [sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... +% size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); +% sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +% +% %% load detections +% detections=parseDetections(detfile); fr=1:length(detections); +% % fr=1:50; detections=detections(fr); % !!!!!!! REMOVE +% F=size(detections,2); +% stateInfo.F=F; % number of frames +% +% +global sceneInfo + + +%% +% printMessage(1,'Sequence: \t%s\n',sceneInfo.seqName); +printMessage(2, 'Frames: ...... %i\n',length(sceneInfo.frameNums)); +printMessage(2, 'Image size: .. %i x %i\n',sceneInfo.imgWidth,sceneInfo.imgHeight) + +% sceneInfo + +%% +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/projectToGroundPlane.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/projectToGroundPlane.m new file mode 100644 index 0000000000000000000000000000000000000000..b51522119bb738eae46b2fe90930d43d1aca9e74 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/projectToGroundPlane.m @@ -0,0 +1,22 @@ +function [Xgp Ygp]=projectToGroundPlane(Xi, Yi, sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +[F N]=size(Xi); +Xgp=zeros(size(Xi)); +Ygp=zeros(size(Xi)); + +for t=1:F + extar=find(Xi(t,:)); + for id=extar + [Xgp(t,id) Ygp(t,id) zw]=imageToWorld(Xi(t,id), Yi(t,id), sceneInfo.camPar); + end +end + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/projectToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/projectToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..97d5f7fdb9142e4217853da0b834e11a728adb0f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/projectToImage.m @@ -0,0 +1,19 @@ +function [Xi Yi]=projectToImage(X,Y,sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +Z=zeros(size(X)); +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); +[Xi Yi]=allWorldToImage_mex(X,Y,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + mR,mT); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/readIDL.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/readIDL.m new file mode 100644 index 0000000000000000000000000000000000000000..6e94f840fdbc5223ab1e4eada6f90623db9f3800 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/readIDL.m @@ -0,0 +1,60 @@ +% Return IDL structure for given filename +% +% INPUT +% filename filename of IDL file +% +% OUTPUT +% idl IDL structure, consisting of +% idl.img - array of images +% idl.bb - array of array of bounding box coordinates +% idl.score - array of array of scores for boxes + +function idl=readIDL(filename) + +fid=fopen(filename); +idl.bb=[]; +idl.img=[]; +idl.score=[]; + +i=1; +bbnum=0; +while 1 + tline = fgetl(fid); + if ~ischar(tline), break, end + tline = strrep(tline, ',', ' '); %replace commas with spaces + colon=strfind(tline,':'); %all colons + + if isempty(colon) + point = strfind(tline,'";'); + if length(point) > 0 + idl(i).img=tline(2:point(1)-1); %filename + i = i + 1; + continue + else + break + end + end + + bb_idx=[(strfind(tline,'(')+1)' (strfind(tline,')')-1)'];%positions of bb start and stop + + idl(i).img=tline(2:colon(1)-2); %filename + for k=1:size(bb_idx,1) + idl(i).bb(end+1,:)=str2num(tline(bb_idx(k,1):bb_idx(k,2))); % next bb + end + + if length(colon)>1 %there are scores in the file ... + for k=1:size(bb_idx,1)-1 + idl(i).score(end+1) = str2num(tline(colon(k+1)+1:(bb_idx(k+1,1)-2))); %next score + end + idl(i).score(end+1) = str2num(tline(colon(length(colon))+1:length(tline)-1)); + else + idl(i).score = 1*ones(1,size(bb_idx,1)); + end + + i=i+1; + bbnum = bbnum + size(bb_idx,1); +end +fclose(fid); + +% fprintf('%d bounding boxes loaded.', bbnum); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/reopenFig.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/reopenFig.m new file mode 100644 index 0000000000000000000000000000000000000000..dcfc4b09cfad39ea91e1f6a9dae423f639d08a35 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/reopenFig.m @@ -0,0 +1,14 @@ +function reopenFig(figname) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +close(findobj('type','figure','name',figname)) +figure('name',figname); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/vectorToMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/vectorToMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..e55ee05fcf2009ca50793f343d17431c14c3451d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/FH2T/utils/vectorToMatrices.m @@ -0,0 +1,38 @@ +function [X Y]=vectorToMatrices(x,stateInfo) +% transforms the state vector X +% to matrix representation X and Y +% X and Y are FxN matrices +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=stateInfo.F; N=stateInfo.N; +% +X=zeros(F,N); % x-positions +Y=zeros(F,N); % y-positions + +% naive implementation +% targetsExist=stateInfo.targetsExist; +% +% xind=1; +% for i=1:N +% frames=targetsExist(i,1):targetsExist(i,2); +% nFrames=numel(frames); +% X(frames,i)=(x(xind:2:xind+2*nFrames-1)); +% +% Y(frames,i)=(x(xind+1:2:xind+2*nFrames)); +% xind=xind+nFrames*2; +% end + + +% vectorized implementation +tiInd=find(stateInfo.tiToInd); +X(tiInd)=x(1:2:end); +Y(tiInd)=x(2:2:end); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/CLEAR_MOT3D.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/CLEAR_MOT3D.m new file mode 100644 index 0000000000000000000000000000000000000000..959591b72ba2dc6128449e453cb1462bb8ae1674 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/CLEAR_MOT3D.m @@ -0,0 +1,318 @@ +function [metrics, metricsInfo]=CLEAR_MOT3D(gtInfo,stateInfo,options) +% compute CLEAR MOT and other metrics +% +% metrics contains the following +% [1] recall - recall = percentage of detected targets +% [2] precision - precision = percentage of correctly detected targets +% [3] FAR - number of false alarms per frame +% [4] GT - number of ground truth trajectories +% [5-7] MT, PT, ML - number of mostly tracked, partially tracked and mostly lost trajectories +% [8] falsepositives- number of false positives (FP) +% [9] missed - number of missed targets (FN) +% [10] idswitches - number of id switches (IDs) +% [11] FRA - number of fragmentations +% [12] MOTA - Multi-object tracking accuracy in [0,100] +% [13] MOTP - Multi-object tracking precision in [0,100] (3D) / [td,100] (2D) +% [14] MOTAL - Multi-object tracking accuracy in [0,100] with log10(idswitches) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% default options: 2D +if nargin<3 + options.eval3d=0; % only bounding box overlap + options.td=.5; % threshold 50% +end + +if ~isfield(options,'td') + if options.eval3d + options.td=1000; + else + options.td=0.5; + end +end + +td=options.td; + +assert(length(gtInfo.frameNums)==length(stateInfo.frameNums), ... + 'Ground Truth and state must be of equal length'); + +assert(all(gtInfo.frameNums==stateInfo.frameNums), ... + 'Ground Truth and state must contain equal frame numbers'); + +% check if all necessery info is available +if options.eval3d + assert(all(isfield(gtInfo,{'Xgp','Ygp'})), ... + 'Ground Truth Ground Plane coordinates needed for 3D evaluation'); + assert(all(isfield(stateInfo,{'Xgp','Ygp'})), ... + 'Ground Plane coordinates needed for 3D evaluation'); +else + assert(all(isfield(gtInfo,{'X','Y','W','H'})), ... + 'Ground Truth coordinates X,Y,W,H needed for 2D evaluation'); + assert(all(isfield(stateInfo,{'Xi','Yi','W','H'})), ... + 'State coordinates Xi,Yi,W,H needed for 2D evaluation'); + +end + +gtInd=~~gtInfo.X; +stInd=~~stateInfo.X; + +[Fgt, Ngt]=size(gtInfo.X); +[F, N]=size(stateInfo.X); + +aspectRatio=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% gtInfo.W=gtInfo.H*aspectRatio; + + +metricsInfo.names.long = {'Recall','Precision','False Alarm Rate', ... + 'GT Tracks','Mostly Tracked','Partially Tracked','Mostly Lost', ... + 'False Positives', 'False Negatives', 'ID Switches', 'Fragmentations', ... + 'MOTA','MOTP', 'MOTA Log'}; + +metricsInfo.names.short = {'Rcll','Prcn','FAR', ... + 'GT','MT','PT','ML', ... + 'FP', 'FN', 'IDs', 'FM', ... + 'MOTA','MOTP', 'MOTAL'}; + +metricsInfo.widths.long = [6 9 16 9 14 17 11 15 15 11 14 5 5 8]; +metricsInfo.widths.short = [5 5 5 3 3 3 3 4 4 3 3 5 5 5]; + +metricsInfo.format.long = {'.1f','.1f','.2f', ... + 'i','i','i','i', ... + 'i','i','i','i', ... + '.1f','.1f','.1f'}; + +metricsInfo.format.short=metricsInfo.format.long; + + +metrics=zeros(1,14); +metrics(9)=numel(find(gtInd)); % False Negatives (missed) +metrics(7)=Ngt; % Mostly Lost + +% nothing to be done, if state is empty +if ~N, return; end + +% global opt +% if options.eval3d && opt.mex +% [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% CLEAR_MOT_mex(gtInfo.Xgp', gtInfo.Ygp', stateInfo.Xgp', stateInfo.Ygp',options.td); +% +% % cd /home/aanton/diss/utils +% % [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% % CLEAR_MOT(gtInfo.Xgp, gtInfo.Ygp, stateInfo.Xgp, stateInfo.Ygp,options.td); +% % cd /home/aanton/visinf/projects/ongoing/contracking +% metrics=[rc*100, pc*100, faf, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FM, MOTA*100, MOTP*100, MOTAL*100]; +% metrics +% global gsi +% gsi=stateInfo; +% pause +% return; +% end + + +% mapping +M=zeros(F,Ngt); + +mme=zeros(1,F); % ID Switchtes (mismatches) +c=zeros(1,F); % matches found +fp=zeros(1,F); % false positives +m=zeros(1,F); % misses = false negatives +g=zeros(1,F); +d=zeros(F,Ngt); % all distances; +ious=Inf*ones(F,Ngt); % all overlaps + +matched=@matched2d; +if options.eval3d, matched=@matched3d; end + +alltracked=zeros(F,Ngt); +allfalsepos=zeros(F,N); + +for t=1:F + g(t)=numel(find(gtInd(t,:))); + + % mapping for current frame + if t>1 + mappings=find(M(t-1,:)); + for map=mappings + if gtInd(t,map) && stInd(t,M(t-1,map)) && matched(gtInfo,stateInfo,t,map,M(t-1,map),td) + M(t,map)=M(t-1,map); + end + end + end + + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + + if options.eval3d + alldist=Inf*ones(Ngt,N); + + mindist=0; + while mindist < td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 + for o=GTsNotMapped + GT=[gtInfo.Xgp(t,o) gtInfo.Ygp(t,o)]; + for e=EsNotMapped + E=[stateInfo.Xgp(t,e) stateInfo.Ygp(t,e)]; + alldist(o,e)=norm(GT-E); + end + end + [mindist cind]=min(alldist(:)); + + if mindist <= td + [u v]=ind2sub(size(alldist),cind); + M(t,u)=v; + alldist(:,v)=Inf; + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + end + end + + else + allisects=zeros(Ngt,N); maxisect=Inf; + + while maxisect > td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 + for o=GTsNotMapped + GT=[gtInfo.X(t,o)-gtInfo.W(t,o)/2 ... + gtInfo.Y(t,o)-gtInfo.H(t,o) ... + gtInfo.W(t,o) gtInfo.H(t,o) ]; + for e=EsNotMapped + E=[stateInfo.Xi(t,e)-stateInfo.W(t,e)/2 ... + stateInfo.Yi(t,e)-stateInfo.H(t,e) ... + stateInfo.W(t,e) stateInfo.H(t,e) ]; + allisects(o,e)=boxiou3D(GT(1),GT(2),GT(3),GT(4),E(1),E(2),E(3),E(4)); + end + end + [maxisect cind]=max(allisects(:)); + + if maxisect >= td + [u v]=ind2sub(size(allisects),cind); + M(t,u)=v; + allisects(:,v)=0; + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + end + + end + end + + curtracked=find(M(t,:)); + + + alltrackers=find(stInd(t,:)); + mappedtrackers=intersect(M(t,find(M(t,:))),alltrackers); + falsepositives=setdiff(alltrackers,mappedtrackers); + + alltracked(t,:)=M(t,:); + allfalsepos(t,1:length(falsepositives))=falsepositives; + + %% mismatch errors + if t>1 + for ct=curtracked + lastnotempty=find(M(1:t-1,ct),1,'last'); + if gtInd(t-1,ct) && ~isempty(lastnotempty) && M(t,ct)~=M(lastnotempty,ct) + mme(t)=mme(t)+1; + end + end + end + + c(t)=numel(curtracked); + for ct=curtracked + eid=M(t,ct); + if options.eval3d + d(t,ct)=norm([gtInfo.Xgp(t,ct) gtInfo.Ygp(t,ct)] - ... + [stateInfo.Xgp(t,eid) stateInfo.Ygp(t,eid)]); + else + gtLeft=gtInfo.X(t,ct)-gtInfo.W(t,ct)/2; + gtTop=gtInfo.Y(t,ct)-gtInfo.H(t,ct); + gtWidth=gtInfo.W(t,ct); gtHeight=gtInfo.H(t,ct); + + stLeft=stateInfo.Xi(t,eid)-stateInfo.W(t,eid)/2; + stTop=stateInfo.Yi(t,eid)-stateInfo.H(t,eid); + stWidth=stateInfo.W(t,eid); stHeight=stateInfo.H(t,eid); + ious(t,ct)=boxiou3D(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight); + end + end + + + fp(t)=numel(find(stInd(t,:)))-c(t); + m(t)=g(t)-c(t); + + +end + +missed=sum(m); +falsepositives=sum(fp); +idswitches=sum(mme); + +if options.eval3d + MOTP=(1-sum(sum(d))/sum(c)/td) * 100; % avg distance to [0,100] +else + MOTP=sum(ious(ious>=td & ious0)); + if gtlength/gttotallength >= 0.8 && trlengtha/gttotallength < 0.2 + MTstatsa(i)=3; + elseif t>=find(gtInd(:,i),1,'last') && trlengtha/gttotallength <= 0.8 + MTstatsa(i)=2; + elseif trlengtha/gttotallength >= 0.8 + MTstatsa(i)=1; + end +end +% MTstatsa +MT=numel(find(MTstatsa==1));PT=numel(find(MTstatsa==2));ML=numel(find(MTstatsa==3)); + +%% fragments +fr=zeros(1,Ngt); +for i=1:Ngt + b=alltracked(find(alltracked(:,i),1,'first'):find(alltracked(:,i),1,'last'),i); + b(~~b)=1; + fr(i)=numel(find(diff(b)==-1)); +end +FRA=sum(fr); + +assert(Ngt==MT+PT+ML,'Hmm... Not all tracks classified correctly.'); +metrics=[recall, precision, FAR, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FRA, MOTA, MOTP, MOTAL]; +end + + + + +function ret=matched2d(gtInfo,stateInfo,t,map,mID,td) + gtLeft=gtInfo.X(t,map)-gtInfo.W(t,map)/2; + gtTop=gtInfo.Y(t,map)-gtInfo.H(t,map); + gtWidth=gtInfo.W(t,map); gtHeight=gtInfo.H(t,map); + + stLeft=stateInfo.Xi(t,mID)-stateInfo.W(t,mID)/2; + stTop=stateInfo.Yi(t,mID)-stateInfo.H(t,mID); + stWidth=stateInfo.W(t,mID); stHeight=stateInfo.H(t,mID); + + ret = boxiou3D(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight) >= td; +end + + +function ret=matched3d(gtInfo,stateInfo,t,map,mID,td) + Xgt=gtInfo.Xgp(t,map); Ygt=gtInfo.Ygp(t,map); + X=stateInfo.Xgp(t,mID); Y=stateInfo.Ygp(t,mID); + ret=norm([Xgt Ygt]-[X Y])<=td; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/README.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..b0d513a9e75626fb0f550514d15909da3b53d481 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/README.txt @@ -0,0 +1,17 @@ +This is an implementation of our CVPR 2011 paper: + +Hamed Pirsiavash, Deva Ramanan, Charless C. Fowlkes, "Globally-Optimal Greedy Algorithms for Tracking a Variable Number of Objects," to appear in International Conference on Computer vision and Pattern Recognition (CVPR'11), Jun 2011. + +We are using matlab/C implementation of part based object detector from http://people.cs.uchicago.edu/~pff/latent/ +and also C implementation of push-relabel algorithm from http://www.igsystems.com/cs2/index.html (please note the copyright file in "3rd_party/cs2/") + +To run, please call "main.m". +1. It will download ETHZ dataset (481MB) if not available (may take 30 minutes) +2. It will run part-based object detector to detect humans if the result is no available in the cache (may take an hour using 8 CPU cores). You don't need to run it since the result is included in the cache. +3. It will build the graph +4. It will call three tracking algorithms(DP, DP with NMS in the loop, and push-relabel) and plot the scores.(Figure 7 on the paper) +5. It will draw detected bounding boxes for the result of "DP with NMS in the loop" algorithm and make a new video. (you may change it to show the results of DP or push-relabel algorithm) + +Please note that since "successive shortest path (SSP)" and "push-relabel" algorithms are both optimum and have identical results, we do not include the implementation of SSP. + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/add.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/add.m new file mode 100644 index 0000000000000000000000000000000000000000..c03f11953efad93f3b2372f444b3b59a18066c79 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/add.m @@ -0,0 +1,15 @@ +function s = add(s1,s2), +% s = add(s1,s2) +% Appends structures s2 to the end of s1 + +if isempty(s1) + s = s2; +elseif isempty(s2), + s = s1; +else + n = fieldnames(s1); + for i = 1:length(n), + f = n{i}; + s.(f) = cat(1,s1.(f),s2.(f)); + end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/bboxes2dres.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/bboxes2dres.m new file mode 100644 index 0000000000000000000000000000000000000000..42bdb82e5ead0c769fd869e110fc5568b2c3155c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/bboxes2dres.m @@ -0,0 +1,29 @@ +function dres = bboxes2dres(bboxes) +k=0; + +dres.x = []; +dres.y = []; +dres.w = []; +dres.h = []; +dres.r = []; +dres.fr = []; + +for i=1:length(bboxes) + bbox = bboxes(i).bbox; + if isempty(bbox) + continue + end + dres.x = [dres.x; bbox(:,1)]; + dres.y = [dres.y; bbox(:,2)]; +% dres.w = [dres.w; bbox(:,3)]; +% dres.h = [dres.h; bbox(:,4)]; + dres.w = [dres.w; bbox(:,3) - bbox(:,1)+1]; + dres.h = [dres.h; bbox(:,4) - bbox(:,2)+1]; + dres.r = [dres.r; bbox(:,5)]; + dres.fr = [dres.fr; repmat(i, [size(bbox,1) 1])]; +end + + + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/build_graph.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/build_graph.m new file mode 100644 index 0000000000000000000000000000000000000000..469f46a86164680eb0a15d135b871b9e9e2d40c0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/build_graph.m @@ -0,0 +1,17 @@ +function dres = build_graph(dres) +ov_thresh = 0.3; %original = 0.5 +dnum = length(dres.x); +len1 = max(dres.fr); +for fr = 2:max(dres.fr) + f1 = find(dres.fr == fr); %% indices for detections on this frame + f2 = find(dres.fr == fr-1); %% indices for detections on the previous frame + for i = 1:length(f1) + ovs1 = calc_overlap(dres, f1(i), dres, f2); + inds1 = find(ovs1 > ov_thresh); %% find overlapping bounding boxes. + + ratio1 = dres.h(f1(i))./dres.h(f2(inds1)); + inds2 = (min(ratio1, 1./ratio1) > 0.8); %% we ignore transitions with large change in the size of bounding boxes. + + dres.nei(f1(i),1).inds = f2(inds1(inds2))'; %% each detction window will have a list of indices pointing to its neighbors in the previous frame. + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/calc_overlap.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/calc_overlap.m new file mode 100644 index 0000000000000000000000000000000000000000..b17df6581b00aeec60e40b2593485a7273e71851 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/calc_overlap.m @@ -0,0 +1,38 @@ +function [ov ov_n1 ov_n2] = calc_overlap(dres1, f1, dres2, f2) +%%f2 can be an array and f1 should be a scalar. +%%% this will find the overlap between dres1(f1) (only one) and all detection windows in dres2(f2(:)) + +f2=f2(:)'; +n = length(f2); + +cx1 = dres1.x(f1); +cx2 = dres1.x(f1)+dres1.w(f1)-1; +cy1 = dres1.y(f1); +cy2 = dres1.y(f1)+dres1.h(f1)-1; + +gx1 = dres2.x(f2); +gx2 = dres2.x(f2)+dres2.w(f2)-1; +gy1 = dres2.y(f2); +gy2 = dres2.y(f2)+dres2.h(f2)-1; + +ca = dres1.h(f1).*dres1.w(f1); %% area +ga = dres2.h(f2).*dres2.w(f2); + +%%% find the overlapping area +xx1 = max(cx1, gx1); +yy1 = max(cy1, gy1); +xx2 = min(cx2, gx2); +yy2 = min(cy2, gy2); +w = xx2-xx1+1; +h = yy2-yy1+1; + +inds = find((w > 0) .* (h > 0)); %% real overlap +ov = zeros(1, n); +ov_n1 = zeros(1, n); +ov_n2 = zeros(1, n); +inter = w(inds).*h(inds); %% area of overlap +u = ca + ga(inds) - w(inds).*h(inds); %% area of union +ov(inds) = inter ./ u; %% intersection / union +ov_n1(inds) = inter / ca; %% intersection / area in dres1 +ov_n2(inds) = inter ./ ga(inds); %% intersection / area in dres2 + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/cs2_func.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/cs2_func.m new file mode 100644 index 0000000000000000000000000000000000000000..70930c05e533bad50ad2251a22923bbde31eb9f5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/cs2_func.m @@ -0,0 +1,22 @@ +% This function calls c implementation of push-relabel algorithm. It is downloaded from http://www.igsystems.com/cs2/index.html and then we mex'ed it to run faster in matlab. +% dat_in = [tail head cost lb ub]; +% dat_out = [frail fhead flow]; +% excess_node = [source_num sink_num]; +% excess_flow = [sourec_flow sink_flow]; + +function [cost, dat_out] = cs2_func(dat_in, excess_node, excess_flow) + +num_arc = size(dat_in,1); + +tail = dat_in(:,1)'; +head = dat_in(:,2)'; +cost = dat_in(:,3)'; + +low = dat_in(:,4)'; +acap = dat_in(:,5)'; + +num_node = max([tail head]); +scale = 12; +[cost,ftail,fhead,flow] = cs2mex(scale, num_node, num_arc, excess_node, excess_flow, tail, head, low, acap, cost); + +dat_out = [ftail fhead flow]; diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/detect_objects.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/detect_objects.m new file mode 100644 index 0000000000000000000000000000000000000000..1ed2c38a7b2f2d3386847847d5831a6dec6a3493 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/detect_objects.m @@ -0,0 +1,37 @@ +function [dres bboxes] = detect_objects(vid_path) +% vid_path = 'data/seq03-img-left/'; +thresh = -2; %% threshod on SVM response in human detection, we'll have more detections by decreasing it. + +n_cores = 8; %% number of cores to use. Matlab doesn't let you use more that 8 cores on a single machine. decrese it if you have less than 8 cores. +n_cores = min(8, n_cores); +if matlabpool('size') ~= n_cores + if matlabpool('size') > 0 + matlabpool('close'); + end + matlabpool(n_cores); +end + +dirlist = dir([vid_path '*.png']); + +tmp = load ('3rd_party/voc-release3.1/INRIA/inria_final.mat'); %% load the model for human. This can be changed to any of those 20 objects in PASCAL competition. +model= tmp.model; +clear tmp + +parfor i=1:length(dirlist) + display(['frame ' num2str(i)]); + im = imread([vid_path dirlist(i).name]); + im = imresize(im,2); %% double the image size to detect small objects. + + boxes = detect(im, model, thresh); %% running the detector + bbox = getboxes(model, boxes); + + bboxes(i).bbox = nms(bbox, 0.5); %% running non-max-suppression to suppress overlaping weak detections. +end +dres = bboxes2dres(bboxes); %% converting the data format. +dres.x = dres.x/2; %% compensate doubling image size. +dres.y = dres.y/2; +dres.w = dres.w/2; +dres.h = dres.h/2; + +matlabpool('size'); + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/distortedToUndistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/distortedToUndistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..14158bd36e686650ae77a8621b1ed3c4d56e298a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/distortedToUndistortedSensorCoord.m @@ -0,0 +1,6 @@ +function [Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mKappa1) +% /* convert from distorted to undistorted sensor plane coordinates */ + distortion_factor = 1 + mKappa1 * (Xd*Xd + Yd*Yd); + Xu = Xd * distortion_factor; + Yu = Yd * distortion_factor; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/dres2bboxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/dres2bboxes.m new file mode 100644 index 0000000000000000000000000000000000000000..6c716f45c812d3f43bb36e5af4ea5bfbb4dc1928 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/dres2bboxes.m @@ -0,0 +1,10 @@ +function bboxes = dres2bboxes(dres, fnum) +for i = 1:fnum + bboxes(i).bbox = []; +end + +for i = 1:length(dres.x) +% bbox = [dres.x(i) dres.y(i) dres.w(i) dres.h(i) dres.r(i)]; + bbox = [dres.x(i) dres.y(i) dres.x(i)+dres.w(i) dres.y(i)+dres.h(i) dres.id(i)]; + bboxes(dres.fr(i)).bbox = [bboxes(dres.fr(i)).bbox; bbox]; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/find_overlap.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/find_overlap.m new file mode 100644 index 0000000000000000000000000000000000000000..967f2245a28feb381970cfa3cbc7371c1136f432 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/find_overlap.m @@ -0,0 +1,38 @@ +function [ov ov_n1 ov_n2] = find_overlap(dres1, f1, dres2, f2) +%%f2 can be an array and f1 should be a scalar. +%%% this will find the overlap between dres1(f1) (only one) and all detection windows in dres2(f2(:)) + +f2=f2(:)'; +n = length(f2); + +cx1 = dres1.x(f1); +cx2 = dres1.x(f1)+dres1.w(f1)-1; +cy1 = dres1.y(f1); +cy2 = dres1.y(f1)+dres1.h(f1)-1; + +gx1 = dres2.x(f2); +gx2 = dres2.x(f2)+dres2.w(f2)-1; +gy1 = dres2.y(f2); +gy2 = dres2.y(f2)+dres2.h(f2)-1; + +ca = dres1.h(f1).*dres1.w(f1); %% area +ga = dres2.h(f2).*dres2.w(f2); + +%%% find the overlapping area +xx1 = max(cx1, gx1); +yy1 = max(cy1, gy1); +xx2 = min(cx2, gx2); +yy2 = min(cy2, gy2); +w = xx2-xx1+1; +h = yy2-yy1+1; + +inds = find((w > 0) .* (h > 0)); %% real overlap +ov = zeros(1, n); +ov_n1 = zeros(1, n); +ov_n2 = zeros(1, n); +inter = w(ff).*h(inds); %% area of overlap +u = ca + ga(inds) - w(inds).*h(inds); %% area of union +ov(ff) = inter ./ u; %% intersection / union +ov_n1(ff) = inter / ca; %% intersection / area in dres1 +ov_n2(ff) = inter ./ ga(ff); %% intersection / area in dres2 + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/frames_to_video.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/frames_to_video.m new file mode 100644 index 0000000000000000000000000000000000000000..079ecdd49ae1e8336dc6c9b0a0f6cf69344e662d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/frames_to_video.m @@ -0,0 +1,9 @@ +% converts bunch of frames to a video file +function frames_to_video(frames_path, video_fname, frame_rate) +if ~exist('frame_rate') + frame_rate = 5; +end +% unix(['ffmpeg -y -i ' frames_path '%6d.jpg -ar 22050 -b 50000 -vtag DIVX +% -f avi ' video_fname]); +% unix(['ffmpeg -y -r ' num2str(frame_rate) ' -i ' frames_path '%6d.jpg -ar 22050 -b 50000 -r 24 -vtag DIVX -f avi ' video_fname]); +unix(['ffmpeg -y -r ' num2str(frame_rate) ' -i ' frames_path '%8d.jpg -b 1000000 -vtag DIVX -f avi ' video_fname]); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/getRotTrans.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/getRotTrans.m new file mode 100644 index 0000000000000000000000000000000000000000..725097d307f8d0b7a1d211e756f99d82d45ebe1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/getRotTrans.m @@ -0,0 +1,34 @@ +function [mR mT]=getRotTrans(camPar) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + %%% Rotation Translation %%% + mT=[camPar.mExt.mTx;camPar.mExt.mTy;camPar.mExt.mTz]; + sa = sin(camPar.mExt.mRx); + ca = cos(camPar.mExt.mRx); + sb = sin(camPar.mExt.mRy); + cb = cos(camPar.mExt.mRy); + sg = sin(camPar.mExt.mRz); + cg = cos(camPar.mExt.mRz); + + mR11 = cb * cg; + mR12 = cg * sa * sb - ca * sg; + mR13 = sa * sg + ca * cg * sb; + mR21 = cb * sg; + mR22 = sa * sb * sg + ca * cg; + mR23 = ca * sb * sg - cg * sa; + mR31 = -sb; + mR32 = cb * sa; + mR33 = ca * cb; + + mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/imageToWorld.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/imageToWorld.m new file mode 100644 index 0000000000000000000000000000000000000000..3919cb798acbbeec7f826c6ea524dee3c3035476 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/imageToWorld.m @@ -0,0 +1,62 @@ +function [Xw Yw Zw]=imageToWorld(Xi, Yi, camPar) + +mGeo=camPar.mGeo; +mExt=camPar.mExt; +mInt=camPar.mInt; + +mTx=mExt.mTx; +mTy=mExt.mTy; +mTz=mExt.mTz; + +mT=[mExt.mTx;mExt.mTy;mExt.mTz]; + +%% internal init +sa = sin(mExt.mRx); +ca = cos(mExt.mRx); +sb = sin(mExt.mRy); +cb = cos(mExt.mRy); +sg = sin(mExt.mRz); +cg = cos(mExt.mRz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + + + +% /* convert from image to distorted sensor coordinates */ +Xd = mGeo.mDpx * (Xi - mInt.mCx) / mInt.mSx; +Yd = mGeo.mDpy * (Yi - mInt.mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ +[Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mInt.mKappa1); + +% /* calculate the corresponding xw and yw world coordinates */ +% /* (these equations were derived by simply inverting */ +% /* the perspective projection equations using Macsyma) */ +Zw=0; +common_denominator = ((mR11 * mR32 - mR12 * mR31) * Yu + ... + (mR22 * mR31 - mR21 * mR32) * Xu - ... + mInt.mFocal * mR11 * mR22 + mInt.mFocal * mR12 * mR21); + +Xw = (((mR12 * mR33 - mR13 * mR32) * Yu + ... + (mR23 * mR32 - mR22 * mR33) * Xu - ... + mInt.mFocal * mR12 * mR23 + mInt.mFocal * mR13 * mR22) * Zw + ... + (mR12 * mTz - mR32 * mTx) * Yu + ... + (mR32 * mTy - mR22 * mTz) * Xu - ... + mInt.mFocal * mR12 * mTy + mInt.mFocal * mR22 * mTx) / common_denominator; + +Yw = -(((mR11 * mR33 - mR13 * mR31) * Yu + ... + (mR23 * mR31 - mR21 * mR33) * Xu - ... + mInt.mFocal * mR11 * mR23 + mInt.mFocal * mR13 * mR21) * Zw + ... + (mR11 * mTz - mR31 * mTx) * Yu + ... + (mR31 * mTy - mR21 * mTz) * Xu - ... + mInt.mFocal * mR11 * mTy + mInt.mFocal * mR21 * mTx) / common_denominator; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/mydetect_objects.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/mydetect_objects.m new file mode 100644 index 0000000000000000000000000000000000000000..9f71e3b090ef7c487a0782836221e2b5fdcc5f82 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/mydetect_objects.m @@ -0,0 +1,34 @@ +function [dres, bboxes] = mydetect_objects(sceneInfo, vid_path) + +n_cores = 4; %% number of cores to use. Matlab doesn't let you use more that 8 cores on a single machine. decrese it if you have less than 8 cores. +n_cores = min(8, n_cores); +if matlabpool('size') ~= n_cores + if matlabpool('size') > 0 + matlabpool('close'); + end + matlabpool(n_cores); +end + +dirlist = dir([vid_path '*.jpg']); + +frames=1:length(sceneInfo.frameNums); +[detections nPoints]=parseDetections(sceneInfo, frames); + +parfor i=1:length(dirlist) + display(['frame ' num2str(i)]); + im = imread([vid_path dirlist(i).name]); + + boxes = detect(im, model, thresh); %% running the detector + bbox = getboxes(model, boxes); + bbox + bboxes(i).bbox = nms(bbox, 0.5); %% running non-max-suppression to suppress overlaping weak detections. +end + +dres = bboxes2dres(bboxes); %% converting the data format. +dres.x = dres.x/2; %% compensate doubling image size. +dres.y = dres.y/2; +dres.w = dres.w/2; +dres.h = dres.h/2; + +matlabpool('size'); + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/nms_aggressive.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/nms_aggressive.m new file mode 100644 index 0000000000000000000000000000000000000000..1cd945eb76e2d4e25a097ba7597c50d8095c03fe --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/nms_aggressive.m @@ -0,0 +1,14 @@ +function inds_out = nms_aggressive(dres, inds, thr) + +inds_out = zeros(length(dres.x),1); +k = 0; +for i=1:length(inds) + f1 = inds(i); %% index of this detetion + f2 = find(dres.fr == dres.fr(f1)); %% indices of all detections on the same frame + + [ovs ovs_n1] = calc_overlap(dres,f1,dres,f2); + f3 = f2(find((ovs > thr) + (ovs_n1 > 0.9))); + inds_out(k+1:k+length(f3)) = f3; + k = k + length(f3); +end +inds_out = inds_out(1:k); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/parseCameraParameters.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/parseCameraParameters.m new file mode 100644 index 0000000000000000000000000000000000000000..10baec4a50e7d06334ec9a16693a4ce178845580 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/parseCameraParameters.m @@ -0,0 +1,104 @@ +function camPar=parseCameraParameters(camconffile) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +xDoc=xmlread(fullfile(camconffile)); + +width=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('width')); +height=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('height')); + +ncx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('ncx')); +nfx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('nfx')); +dx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dx')); +dy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dy')); +dpx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpx')); +dpy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpy')); + +focal=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('focal')); +kappa1=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('kappa1')); +cx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cx')); +cy=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cy')); +sx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('sx')); + +tx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tx')); +ty=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ty')); +tz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tz')); +rx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rx')); +ry=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ry')); +rz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rz')); + +mGeo.mImgWidth = width; +mGeo.mImgHeight = height; +mGeo.mNcx = ncx; +mGeo.mNfx = nfx; +mGeo.mDx = dx; +mGeo.mDy = dy; +mGeo.mDpx = dpx; +mGeo.mDpy = dpy; + + +%% intrinsic +mInt.mFocal = focal; +mInt.mKappa1 = kappa1; +mInt.mCx = cx; +mInt.mCy = cy; +mInt.mSx = sx; + +%% extrinsic +mExt.mTx = tx; +mExt.mTy = ty; +mExt.mTz = tz; +mExt.mRx = rx; +mExt.mRy = ry; +mExt.mRz = rz; + +%% inverted +mT=[tx;ty;tz]; +sa = sin(rx); +ca = cos(rx); +sb = sin(ry); +cb = cos(ry); +sg = sin(rz); +cg = cos(rz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + +mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; + +transform=[mR mT;[0 0 0 1]]; +invtrans=inv(transform); +tx=invtrans(1,4);ty=invtrans(2,4);tz=invtrans(3,4); + +mExt.mTxi = tx; +mExt.mTyi = ty; +mExt.mTzi = tz; + +camPar.mExt=mExt; +camPar.mInt=mInt; +camPar.mGeo=mGeo; + +%% mkappa<0 +if kappa1<0 + warning('CAREFUL! kappa1 < 0, cam derivates are wrong!'); +end + +[camPar.mR camPar.mT]=getRotTrans(camPar); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/projectToGroundPlane.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/projectToGroundPlane.m new file mode 100644 index 0000000000000000000000000000000000000000..01587719cd5e42d797266b1946acd39164565b79 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/projectToGroundPlane.m @@ -0,0 +1,24 @@ +function [Xgp Ygp]=projectToGroundPlane(Xi, Yi, sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +[F, N]=size(Xi); +Xgp=zeros(size(Xi)); +Ygp=zeros(size(Xi)); + + +for t=1:F + extar=find(Xi(t,:)); + for id=extar + [Xgp(t,id), Ygp(t,id), zw]=imageToWorld(Xi(t,id), Yi(t,id), sceneInfo.camPar); + end +end + + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/run_tracker.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/run_tracker.m new file mode 100644 index 0000000000000000000000000000000000000000..555bdf14d36d966d75089bc20a70d325ddbe0d47 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/run_tracker.m @@ -0,0 +1,25 @@ +function [stateInfo, speed] = run_tracker(curSequence, baselinedetections) + +%% setting parameters for tracking +c_en = 10; %% 10 birth cost, has no influence on the result +c_ex = 10; %% 10 death cost, has no influence on the result +c_ij = -2; %% 0 transition cost +betta = 0.01; %% 0.2 betta, increase will have less tracks, for every single detection +max_it = inf; %% inf max number of iterations (max number of tracks) +thr_cost = 18; %% 18 max acceptable cost for a track (increase it to have more tracks.), for every tracklet 19.8 + +time_start = tic; +%% Run object/human detector on all frames. +frameNums = curSequence.frameNums; +dres = greedy_detect_generator(baselinedetections, frameNums); + +%% Running tracking algorithms +dres_dp_nms = tracking_dp(dres, c_en, c_ex, c_ij, betta, thr_cost, max_it, 1); +dres_dp_nms.r = -dres_dp_nms.id; +totalTime = toc(time_start); +speed = numel(frameNums)/totalTime; + +%% save the tracking result +fnum = numel(frameNums); +bboxes_tracked = dres2bboxes(dres_dp_nms, fnum); %% we are visualizing the "DP with NMS in the lop" results. Can be changed to show the results of DP or push relabel algorithm. +stateInfo = saveStateInfo(bboxes_tracked); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/saveStateInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/saveStateInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..d6ee2293332a1ce9575e005f0522b7f63291d312 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/saveStateInfo.m @@ -0,0 +1,47 @@ +function stateInfo = saveStateInfo(bboxes_tracked) + +frame_num = size(bboxes_tracked, 2); +index = 1; + +for frame = 1:frame_num + bboxes = bboxes_tracked(1,frame).bbox; + id_num = size(bboxes, 1); + for id = 1:id_num + track_result(index,1) = bboxes(id, 1); + track_result(index,2) = bboxes(id, 2); + track_result(index,3) = bboxes(id, 3) - bboxes(id, 1); + track_result(index,4) = bboxes(id, 4) - bboxes(id, 2); + track_result(index,5) = frame; + track_result(index,6) = bboxes(id, 5); + index = index + 1; + end +end + +sorted_result = sortrows(track_result,6); + +stateInfo.F = frame_num; +stateInfo.frameNums = 1:frame_num; +detect_num = size(sorted_result,1); +index = 0; +cur_id = -1; + +for i = 1:detect_num + if (cur_id ~= sorted_result(i,6)) + cur_id = sorted_result(i,6); + index = index + 1; + stateInfo.X(:,index) = zeros(frame_num,1); + stateInfo.Y(:,index) = zeros(frame_num,1); + stateInfo.Xi(:,index) = zeros(frame_num,1); + stateInfo.Yi(:,index) = zeros(frame_num,1); + stateInfo.W(:,index) = zeros(frame_num,1); + stateInfo.H(:,index) = zeros(frame_num,1); + end + bbox = sorted_result(i,:); + n = bbox(1,5); + stateInfo.X(n,index) = bbox(1,1)+0.5*bbox(1,3); + stateInfo.Y(n,index) = bbox(1,2)+bbox(1,4); + stateInfo.Xi(n,index) = stateInfo.X(n,index); + stateInfo.Yi(n,index) = stateInfo.Y(n,index); + stateInfo.W(n,index) = bbox(1,3); + stateInfo.H(n,index) = bbox(1,4); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/score.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/score.m new file mode 100644 index 0000000000000000000000000000000000000000..9763734cc2271e332fae69f248f7b8a8f7996b14 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/score.m @@ -0,0 +1,70 @@ +function [missr, fppi] = score(c, g, n) + +thr = 0.5; + +if isempty(c) || isempty(g), + missr = 1; + fppi = inf; + prec = 0; + rec = 0; + ap = 0; + return; +end + +r = c.r; +pos = zeros(length(c.x), 1); + +%%% find positives +for fr = min(c.fr):max(c.fr) + I = find(c.fr == fr); + J = find(g.fr == fr); + [v,ind] = sort(r(I)); + I = I(ind); + + while ~isempty(I) && ~isempty(J), + i = I(end); %% Select highest scoring candidate + ov = calc_overlap(c,i,g,J); %% Search for an unclaimed positive + [val, ind] = max(ov); + if val > thr, + pos(i) = 1; + J(ind) = []; + end + I(end) = []; + end +end + +% remove false-positives that overlap with "people" in ground truth +keep = logical(ones(size(c.x))); +for fr = min(c.fr):max(c.fr) + I = find(c.fr == fr & pos == 0); + J = find(n.fr == fr); + [v,ind] = sort(r(I)); + I = I(ind); + + while ~isempty(I) && ~isempty(J), + i = I(end); %% Select highest scoring candidate + ov = calc_overlap(c,i,n,J); %% Search for a positive on "people" area. + [val,ind] = max(ov); + if val > thr, + keep(i) = 0; %% ignore it completely since it overlaps with "people" + J(ind) = []; + end + I(end) = []; + end +end + +r = r(keep); +pos = pos(keep); + +[r, I] = sort(r,'descend'); +pos = pos(I); +fp = cumsum(~pos); +tp = cumsum(pos); +rec = tp/length(g.x); +prec = tp./(fp+tp); + +nfrs = length(unique(c.fr)); +% nfrs = max(c.fr) - min(c.fr) + 1; +missr = 1-rec; +fppi = fp / nfrs; + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/show_bbox_on_image.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/show_bbox_on_image.m new file mode 100644 index 0000000000000000000000000000000000000000..80d25c86448f2edded3089d28d843f1bb4e42098 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/show_bbox_on_image.m @@ -0,0 +1,49 @@ +% drawss bbox on an image (im1) and returns the image file +% bbox: a matrix of size n*5 +% default line width (lw) is 2 +function im1 = show_bbox_on_image(im1, bbox, bws, col, lw) + +if ~exist('lw') + lw = 2; +end + +m1 = floor((lw-1)/2); %% reduce 1 for the pixel itself +m2 = ceil((lw-1)/2); + +[sz1 sz2 sz3] = size(im1); +sz = size(bbox, 1); + +bbox = round(bbox); + +for j = floor(size(bbox,2)/4):-1:1 %%for all parts + for i = 1:sz + x1 = bbox(i, (j-1)*4+1); + y1 = bbox(i, (j-1)*4+2); + x2 = bbox(i, (j-1)*4+3); + y2 = bbox(i, (j-1)*4+4); + + for k = 1:3 %% RGB channels + im1(max(1,y1-m1):min(sz1,y1+m2), max(1,x1):min(sz2,x2), k) = col(k, bbox(i,end)); + im1(max(1,y2-m1):min(sz1,y2+m2), max(1,x1):min(sz2,x2), k) = col(k, bbox(i,end)); + im1(max(1,y1):min(sz1,y2), max(1,x1-m1):min(sz2,x1+m2), k) = col(k, bbox(i,end)); + im1(max(1,y1):min(sz1,y2), max(1,x2-m1):min(sz2,x2+m2), k) = col(k, bbox(i,end)); + end + if ~isempty(bws) %% add text if needed + col1 = col(:, bbox(i, end)); + im1 = show_text_on_image(im1, num2str(bbox(i,end)), col1, min(max(x1-10,1),sz2), min(max(y1-20,1),sz1), 20, bws(bbox(i,end)).bw); + end + end +end + +function im = show_text_on_image(im, txt, col, x, y, h, bw) +[sz11 sz22 sz33] =size(im); + +[sz1 sz2] = size(bw); +y2 = min(y+sz1-1, sz11); +x2 = min(x+sz2-1, sz22); + +for k = 1:3 %% RGB channels + im(y2-sz1+1:y2, x2-sz2+1:x2, k) = (1-bw) * col(k); +end + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/show_bboxes_on_video.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/show_bboxes_on_video.m new file mode 100644 index 0000000000000000000000000000000000000000..059a1f53e6184a507c76b9bd6f2c39d9032215b6 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/show_bboxes_on_video.m @@ -0,0 +1,61 @@ +% it shows bboxes on frames of a video (bunch of frames in "input_frames") and outputs a video "video_fname" +% bboxes(i).bbox is an n*5 matrix: detections on the i'th frame +% "thr" is used to prune detection results: default: -inf +% if you don't pass "output_frames", it will make a temporary one and then delete it in the end. +% "bws" is track numbers in image format (used as label for the boxes) + +function show_bboxes_on_video(input_frames, bboxes, video_fname, bws, frame_rate, thr, output_frames, frameNums) + +if ~exist('frame_rate', 'var') + frame_rate = 20; +end +if ~exist('thr', 'var') + thr = -inf; +end +if exist('output_frames', 'var') + if ~isempty(output_frames) + flag = 0; +% unix(['rm -r ' output_frames]); + else + flag = 1; + end +else + flag = 1; +end +if flag == 1 + output_frames = tempname; %% A temporary folder name + output_frames = [output_frames(end-9:end) '/']; +end + +% mkdir (output_frames); + +col = round((rand(3,1e4)/2+.5)*255); %% we assume number of tracks is less than 1e4. + +dirlist = dir([input_frames '*.jpg']); %%list of images +if isempty(dirlist) + dirlist = dir([input_frames '*.png']); +end + +figure(1), title('Tracking Results'); +% [imgWidth, imgHeight] = size(imread(fullfile(input_frames, [sprintf('img%0.5d', frameNums(1)) '.jpg']))); +% figure('Position',[100 200 imgWidth imgHeight]), title('Tracking Results'); +for i = 1:length(bboxes) + bbox = bboxes(i).bbox; +% img = imread(fullfile(input_frames, [sprintf('frame_%0.4d', frameNums(i)-1) '.jpg']));%% read an image + img = imread(fullfile(input_frames, [sprintf('img%0.5d', frameNums(i)) '.jpg']));%% read an image + if ~isempty(bbox) + img = show_bbox_on_image(img, bbox(bbox(:,end) > thr, :), bws, col); + end + imshow(img); + % frame number + text(20,50,sprintf('%d',i),'FontSize',20); + pause(0.01); +% imwrite(img, [output_frames sprintf('%0.4d', i) '.jpg']); %%write the output image +% imwrite(img, [output_frames sprintf('%0.5d', i) '.jpg']); %%write the output image +end + +frames_to_video(output_frames, video_fname, frame_rate); %%convert frames to video + +if flag +% unix(['rm -r ' output_frames]); %%remove temporary output folder +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/sub.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/sub.m new file mode 100644 index 0000000000000000000000000000000000000000..0f0fcf9bcccfa859d6c4d81e691942716dcb73f1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/sub.m @@ -0,0 +1,16 @@ +function s = sub(s,I), +% s = sub(s,I) +% Returns a subset of the structure s + +if ~isempty(s), + n = fieldnames(s); + for i = 1:length(n), + f = n{i}; + s.(f) = s.(f)(I,:); + end +end + + + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/text_to_image.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/text_to_image.m new file mode 100644 index 0000000000000000000000000000000000000000..6ee38d808029bbdea5e08c0e92072f41ab8a4224 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/text_to_image.m @@ -0,0 +1,45 @@ +% this function write contents of "txt" on an image and then returns its image. +% "h" is the texyt height in pixels +% "figNum" is the number for figure. +% note that you may not interacti with matlab while running this command since the figure window should be on the top. + +function bw = text_to_image(txt, h, figNum) +f = h/1.2; +sz1 = round(f*4); +sz2 = round(length(txt)*f*1.5); +r = 1; +if sz2 > 800 + r = sz2/800; + sz2 = round(sz2/r); + f = round(f/r); +end + +im1 = ones(sz1, sz2, 3); +flag1 = 0; +if ~exist('figNum') + figNum = ceil((rand*1000)+1); + flag1 = 1; +end + +figure(figNum); +imshow(im1); +text(10,f*3, txt, 'fontsize', f,'color', 'b'); +im2 = getframe; +if flag1 + close(figNum); +end + +im2 = im2.cdata; +bw2 = im2bw(im2); +f1 = find(sum(~bw2)); +f2 = find(sum(~bw2')); +x1 = f1(1); +y1 = f2(1); +x2 = f1(end); +y2 = f2(end); +bw = ~bw2(y1:y2, x1:x2); + +if r~=1 + bw = im2bw(imresize(double(bw), h/size(bw,1))); +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/tracking_dp.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/tracking_dp.m new file mode 100644 index 0000000000000000000000000000000000000000..3fca843ee5be7c9aaf4d650e178f32a3e3fed653 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/tracking_dp.m @@ -0,0 +1,85 @@ +function [res, min_cs] = tracking_dp(dres, c_en, c_ex, c_ij, betta, thr_cost, max_it, nms_in_loop) + +if ~exist('max_it') + max_it = 1e5; +end +if ~exist('thr_cost') + thr_cost = 0; +end + +thr_nms = 0.5; + +dnum = length(dres.x); + +dres.c = betta - dres.r; + +dres.dp_c = []; +dres.dp_link = []; +dres.orig = []; + +min_c = -inf; +it = 0; +k = 0; +inds_all = zeros(1,1e5); +id_s = zeros(1,1e5); +redo_nodes = [1:dnum]'; +while (min_c < thr_cost) && (it < max_it) + it = it+1; + + dres.dp_c(redo_nodes,1) = dres.c(redo_nodes) + c_en; + dres.dp_link(redo_nodes,1) = 0; + dres.orig(redo_nodes,1) = redo_nodes; + + for ii=1:length(redo_nodes) + i = redo_nodes(ii); + f2 = dres.nei(i).inds; + if isempty(f2) + continue; + end + + [min_cost j] = min(c_ij + dres.c(i) + dres.dp_c(f2)); + min_link = f2(j); + if dres.dp_c(i,1) > min_cost + dres.dp_c(i,1) = min_cost; + dres.dp_link(i,1) = min_link; + dres.orig(i,1) = dres.orig(min_link); + end + end + + [min_c ind] = min(dres.dp_c + c_ex); + + inds = zeros(dnum,1); + + k1 = 0; + while ind~=0 + k1 = k1+1; + inds(k1) = ind; + ind = dres.dp_link(ind); + end + inds = inds(1:k1); + + inds_all(k+1:k+length(inds)) = inds; + id_s(k+1:k+length(inds)) = it; + k = k+length(inds); + + if nms_in_loop + supp_inds = nms_aggressive(dres, inds, thr_nms); + origs = unique(dres.orig(supp_inds)); + redo_nodes = find(ismember(dres.orig, origs)); + else + supp_inds = inds; + origs = inds(end); + redo_nodes = find(dres.orig == origs); + end + redo_nodes = setdiff(redo_nodes, supp_inds); + dres.dp_c(supp_inds) = inf; + dres.c(supp_inds) = inf; + + min_cs(it) = min_c; +end +inds_all = inds_all(1:k); +id_s = id_s(1:k); + +res = sub(dres, inds_all); +res.id = id_s'; + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/tracking_push_relabel.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/tracking_push_relabel.m new file mode 100644 index 0000000000000000000000000000000000000000..92463dd866b220a6d58687c9c876a370c1b3cce9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/tracking_push_relabel.m @@ -0,0 +1,115 @@ +function [res] = tracking_push_relabel(dres, c_en, c_ex, c_ij, betta, max_it) + +dnum = length(dres.x); + +dres.c = betta - dres.r; %% cost for each detection window + +%%% The mex function works with large numbers. +dres.c = dres.c *1e6; +c_en = c_en *1e6; +c_ex = c_ex *1e6; +c_ij = c_ij *1e6; + +n_nodes = 2*dnum+2; %% number of nodes in the graph +n_edges = 0; + +dat_in = zeros(1e7,3); %% each row represents an edge from node in column 1 to node in column 2 with cost in column 3. +k_dat = 0; +for i = 1:dnum + k_dat = k_dat+3; + dat_in(k_dat-2,:) = [1 2*i c_en ]; + dat_in(k_dat-1,:) = [2*i 2*i+1 dres.c(i) ]; + dat_in(k_dat,:) = [2*i+1 n_nodes c_ex ]; +end +for i=1:dnum + f2 = dres.nei(i).inds; + for j = 1:length(f2) + k_dat = k_dat+1; + dat_in(k_dat,:) = [2*f2(j)+1 2*i c_ij]; + end +end +dat_in = [dat_in repmat([0 1],size(dat_in,1),1)]; %% add two columns: 0 for min capacity in column 4 and 1 for max capacity in column 5 for all edges. + +excess_node = [1 n_nodes]; %% push flow in the first node and collect it in the last node. + +k = 0; +dat2_old = [0 0 0]; + +inds_all = []; +tic +lb=1; +ub=1e4; +tr_num_old = 1; + +tic + +while ub-lb > 1 %% bisection search for the optimum amount of flow. This can be implemented by Golden section search more efficiently. + tr_num = round((lb+ub)/2); + + [cost_l, dat_l] = cs2_func(dat_in(1:k_dat,:), excess_node, [tr_num -tr_num]); %% try flow = tr_num + [cost_u, dat_u] = cs2_func(dat_in(1:k_dat,:), excess_node, [tr_num+1 -tr_num-1]); %% try flow = tr_num+1 + if cost_u-cost_l > 0 + ub = tr_num; + else + lb = tr_num; + end + k=k+1; +end + +if cost_u < cost_l + dat1 = dat_u; +else + cost1 = cost_l; + dat1 = dat_l; +end + +%%%% backtrack tracks to get ids +tmp = find( dat1(:, 1) == 1); +start = dat1(tmp, 2); %% starting nodes; is even + +tmp = find( ~mod(dat1(:, 1), 2) .* (dat1(:, 2)-dat1(:, 1) == 11) ); +detcs = dat1(tmp, 1); %% detection nodes; is even + +tmp = find( mod(dat1(:, 1), 2) .* ~mod(dat1(:, 2), 2) .* (dat1(:, 2)-dat1(:, 1) ~= 1) ); +links = dat1(tmp, 1:2); %% links; is [even odd] + +res_inds = zeros(1, 1e5); +res_ids = zeros(1, 1e5); + +k = 0; +for i = 1:length(start); %% for each track + this1 = start(i); + while this1 ~= n_nodes + k = k+1; + res_inds(k) = this1/2; + res_ids(k) = i; + this1 = links(find(links(:,1) == this1+1), 2); %% should have only one value + if mod(this1, 2) + (length(this1) ~= 1) %% sanity check + display('error in the output of solver'); + end + end +end +res_inds = res_inds(1:k); %% only these detection windows are used in tracks. +res_ids = res_ids(1:k); %% track id for each detection window + +%%% Calculate the cost value to sort tracks +this_cost = zeros(1, max(res_ids)); +for i = 1:max(res_ids) %% for each track + inds = find(res_ids == i); + len1= length(inds); + track_cost(i) = sum(dres.c(res_inds(inds))) + (len1-1) * c_ij + c_en + c_ex; +end +[dummy sort_inds] = sort(track_cost); + +for i = 1:length(sort_inds) + res_ids_sorted(res_ids == sort_inds(i)) = i; +end + +res = sub(dres, res_inds); +res.id = res_ids_sorted(:); + +% [dummy tmp] = sort(res.id); +% res = sub(res,tmp); +% % res = sub(dres,inds_all_its(1).inds); +% % res.r = res.r/1e6; + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/undistortedToDistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/undistortedToDistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..b689d695a1a98a28a8ba414a7661fe9658d24403 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/undistortedToDistortedSensorCoord.m @@ -0,0 +1,67 @@ +function [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mKappa1) + +% global ifs elses + +if ((~Xu && ~Yu) || ~mKappa1) +% ifs(1)=ifs(1)+1; + Xd = Xu; + Yd = Yu; +else %% THIS ONE %% +% elses(1)=elses(1)+1; + Ru = sqrt(Xu*Xu + Yu*Yu); + + c = 1.0 / mKappa1; + d = -c * Ru; + + Q = c / 3; + R = -d / 2; + D = Q*Q*Q + R*R; + + if (D >= 0) %% THIS ONE %% +% ifs(2)=ifs(2)+1; + %/* one real root */ + D = sqrt(D); + if (R + D > 0) %% THIS ONE %% +% ifs(3)=ifs(3)+1; + S = (R + D)^ (1.0/3.0); + else +% elses(3)=elses(3)+1; + S = -(-R - D)^ (1.0/3.0); + end + if (R - D > 0) +% ifs(4)=ifs(4)+1; + T = (R - D)^(1.0/3.0); + else %% THIS ONE %% +% elses(4)=elses(4)+1; + T = -(D - R)^(1.0/3.0); + end + Rd = S + T; + + if (Rd < 0) + Rd = sqrt(-1.0 / (3 * mKappa1)); + % /*fprintf (stderr, "\nWarning: undistorted image point to distorted image point mapping limited by\n"); + % fprintf (stderr, " maximum barrel distortion radius of %lf\n", Rd); + % fprintf (stderr, " (Xu = %lf, Yu = %lf) -> (Xd = %lf, Yd = %lf)\n\n", Xu, Yu, Xu * Rd / Ru, Yu * Rd / Ru);*/ + end + else +% elses(2)=elses(2)+1; + % /* three real roots */ + D = sqrt(-D); + S = ( sqrt(R*R + D*D))^(1.0/3.0 ); + T = atan2(D, R) / 3; + sinT = sin(T); + cosT = cos(T); + + % /* the larger positive root is 2*S*cos(T) */ + % /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ + % /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ + + Rd = -S * cosT + sqrt(3.0) * S * sinT; % /* use the smaller positive root */ + end + + lambda = Rd / Ru; + + Xd = Xu * lambda; + Yd = Yu * lambda; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/cutDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/cutDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..834fae873d2c4b4e18f7e1ff6d7fad8984c07017 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/cutDetections.m @@ -0,0 +1,34 @@ +function [detections nDets]=cutDetections(detections,nDets) +% remove all detections that are +% outside the tracking area +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% + +global sceneInfo opt +if opt.track3d && opt.cutToTA + F=length(detections); + Field = fieldnames(detections); + nDets=0; + for t=1:F + tokeep=find(detections(t).xw>=sceneInfo.trackingArea(1) & ... + detections(t).xw<=sceneInfo.trackingArea(2) & ... + detections(t).yw>=sceneInfo.trackingArea(3) & ... + detections(t).yw<=sceneInfo.trackingArea(4)); + + nDets=nDets+length(tokeep); + + for iField = 1:length(Field) + fcontent=detections(t).(char(Field(iField))); + fcontent=fcontent(tokeep); + detections(t).(char(Field(iField)))=fcontent; + end + end +end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/distortedToUndistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/distortedToUndistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..14158bd36e686650ae77a8621b1ed3c4d56e298a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/distortedToUndistortedSensorCoord.m @@ -0,0 +1,6 @@ +function [Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mKappa1) +% /* convert from distorted to undistorted sensor plane coordinates */ + distortion_factor = 1 + mKappa1 * (Xd*Xd + Yd*Yd); + Xu = Xd * distortion_factor; + Yu = Yd * distortion_factor; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/getRotTrans.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/getRotTrans.m new file mode 100644 index 0000000000000000000000000000000000000000..725097d307f8d0b7a1d211e756f99d82d45ebe1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/getRotTrans.m @@ -0,0 +1,34 @@ +function [mR mT]=getRotTrans(camPar) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + %%% Rotation Translation %%% + mT=[camPar.mExt.mTx;camPar.mExt.mTy;camPar.mExt.mTz]; + sa = sin(camPar.mExt.mRx); + ca = cos(camPar.mExt.mRx); + sb = sin(camPar.mExt.mRy); + cb = cos(camPar.mExt.mRy); + sg = sin(camPar.mExt.mRz); + cg = cos(camPar.mExt.mRz); + + mR11 = cb * cg; + mR12 = cg * sa * sb - ca * sg; + mR13 = sa * sg + ca * cg * sb; + mR21 = cb * sg; + mR22 = sa * sb * sg + ca * cg; + mR23 = ca * sb * sg - cg * sa; + mR31 = -sb; + mR32 = cb * sa; + mR33 = ca * cb; + + mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/greedy_Pets_detct_generator.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/greedy_Pets_detct_generator.m new file mode 100644 index 0000000000000000000000000000000000000000..f7e670ceb835d9041c681c18b5fbc2d373884101 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/greedy_Pets_detct_generator.m @@ -0,0 +1,35 @@ +clear;clc; +addpath('../../input_trans'); + +outPath1 = '.\pls_detect\PETS\'; +video_name = 'PETS2009-S2L1'; +outName1 = [video_name '_pls_detect.mat']; +out1 = [outPath1 outName1]; + +global sceneInfo opt detections nPoints; +frames=1:795; +sceneInfo=getSceneInfoDCDemo; +opt.cutToTA=0; +[detections, nPoints]=parseDetections(sceneInfo,frames); +[detections, nPoints]=cutDetections(detections,nPoints); + +frameNum = size(detections,2); +count = 1; + +for i = 1:frameNum + i + obj_num = size(detections(i).xi, 2); + for j=1:obj_num + dres.w(count,1) = detections(i).wd(1,j); + dres.h(count,1) = detections(i).ht(1,j); + w = dres.w(count,1); + h = dres.h(count,1); + dres.x(count,1) = detections(i).xi(1,j) - 0.5*w; + dres.y(count,1) = detections(i).yi(1,j) - h; + dres.fr(count,1) = i; + dres.r(count,1) = detections(i).sc(1,j)*3-1.5; + count = count+1; + end +end + +save(out1,'dres'); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/greedy_Pets_gt_generator.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/greedy_Pets_gt_generator.m new file mode 100644 index 0000000000000000000000000000000000000000..e04dcc3d954bc798d5d7fd30b4e147939a6eddb4 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/greedy_Pets_gt_generator.m @@ -0,0 +1,85 @@ +clear;clc; +addpath('../../input_trans'); + +global sceneInfo opt; + +dbfolder='E:\ComputerVision\Multi-target Tracking\TPAMI_Dataset\Pedestrian_Dataset\PETS2009\S2_L1'; +video_name = 'PETS2009-S2L1'; +opt.track3d = 1; + +%% camera +cameraconffile=[]; +if opt.track3d + cameraconffile=fullfile(dbfolder,'camera','CameraView001.xml'); +end +sceneInfo.camFile=cameraconffile; + +if ~isempty(sceneInfo.camFile) + sceneInfo.camPar=parseCameraParameters(sceneInfo.camFile); +end + +%% ground truth +sceneInfo.gtFile=''; +sceneInfo.gtFile=fullfile(dbfolder,'gt','PETS2009-S2L1.xml'); +outPath = '.\gtInfo\PETS\'; +outName = [video_name '_gtInfo.mat']; + +outPath2 = '.\detect_gt\PETS\'; +outName2 = [video_name '_detect_gt.mat']; +global gtInfo +sceneInfo.gtAvailable=0; +if ~isempty(sceneInfo.gtFile) + sceneInfo.gtAvailable=1; + % first determine the type + [~, ~, fileext]=fileparts(sceneInfo.gtFile); + + if strcmpi(fileext,'.xml') % CVML + gtInfo=parseGT(sceneInfo.gtFile); + elseif strcmpi(fileext,'.mat') + % check for the var gtInfo + fileInfo=who('-file',sceneInfo.gtFile); + varExists=0; cnt=0; + while ~varExists && cnt= 0) %% THIS ONE %% +% ifs(2)=ifs(2)+1; + %/* one real root */ + D = sqrt(D); + if (R + D > 0) %% THIS ONE %% +% ifs(3)=ifs(3)+1; + S = (R + D)^ (1.0/3.0); + else +% elses(3)=elses(3)+1; + S = -(-R - D)^ (1.0/3.0); + end + if (R - D > 0) +% ifs(4)=ifs(4)+1; + T = (R - D)^(1.0/3.0); + else %% THIS ONE %% +% elses(4)=elses(4)+1; + T = -(D - R)^(1.0/3.0); + end + Rd = S + T; + + if (Rd < 0) + Rd = sqrt(-1.0 / (3 * mKappa1)); + % /*fprintf (stderr, "\nWarning: undistorted image point to distorted image point mapping limited by\n"); + % fprintf (stderr, " maximum barrel distortion radius of %lf\n", Rd); + % fprintf (stderr, " (Xu = %lf, Yu = %lf) -> (Xd = %lf, Yd = %lf)\n\n", Xu, Yu, Xu * Rd / Ru, Yu * Rd / Ru);*/ + end + else +% elses(2)=elses(2)+1; + % /* three real roots */ + D = sqrt(-D); + S = ( sqrt(R*R + D*D))^(1.0/3.0 ); + T = atan2(D, R) / 3; + sinT = sin(T); + cosT = cos(T); + + % /* the larger positive root is 2*S*cos(T) */ + % /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ + % /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ + + Rd = -S * cosT + sqrt(3.0) * S * sinT; % /* use the smaller positive root */ + end + + lambda = Rd / Ru; + + Xd = Xu * lambda; + Yd = Yu * lambda; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/worldToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/worldToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..8bb11eb8cfff82e0e805c07f7f22d5e81042b241 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/worldToImage.m @@ -0,0 +1,28 @@ +function [Xi Yi]=worldToImage(Xw,Yw,Zw,mR,mT,mInt,mGeo) + + + % /* convert from world coordinates to camera coordinates */ + x=[mR mT]*[Xw;Yw;Zw;1]; + xc = x(1); + yc = x(2); + zc = x(3); + + % /* convert from camera coordinates to undistorted sensor plane coordinates */ + Xu = mInt.mFocal * xc / zc; + Yu = mInt.mFocal * yc / zc; + + % /* convert from undistorted to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mInt.mKappa1); + % Xd=Xu; + % Yd=Yu; + + % Rusq=Xu*Xu+Yu*Yu; + % Ru=sqrt(Xu*Xu+Yu*Yu); + % Xd=Xu*(1+mInt.mKappa1*Rusq); + % Yd=Yu*(1+mInt.mKappa1*Rusq); + + + % /* convert from distorted sensor plane coordinates to image coordinates */ + Xi = Xd * mInt.mSx / mGeo.mDpx + mInt.mCx; + Yi = Yd / mGeo.mDpy + mInt.mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/xml_read.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/xml_read.m new file mode 100644 index 0000000000000000000000000000000000000000..03c590d65843979489cc5616dd9b466041353ece --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/xml_read.m @@ -0,0 +1,550 @@ +function [tree, RootName, DOMnode] = xml_read(xmlfile, Pref) +%XML_READ reads xml files and converts them into Matlab's struct tree. +% +% DESCRIPTION +% tree = xml_read(xmlfile) reads 'xmlfile' into data structure 'tree' +% +% tree = xml_read(xmlfile, Pref) reads 'xmlfile' into data structure 'tree' +% according to your preferences +% +% [tree, RootName, DOMnode] = xml_read(xmlfile) get additional information +% about XML file +% +% INPUT: +% xmlfile URL or filename of xml file to read +% Pref Preferences: +% Pref.ItemName - default 'item' - name of a special tag used to itemize +% cell arrays +% Pref.ReadAttr - default true - allow reading attributes +% Pref.ReadSpec - default true - allow reading special nodes +% Pref.Str2Num - default 'smart' - convert strings that look like numbers +% to numbers. Options: "always", "never", and "smart" +% Pref.KeepNS - default true - keep or strip namespace info +% Pref.NoCells - default true - force output to have no cell arrays +% Pref.Debug - default false - show mode specific error messages +% Pref.NumLevels- default infinity - how many recursive levels are +% allowed. Can be used to speed up the function by prunning the tree. +% Pref.RootOnly - default true - output variable 'tree' corresponds to +% xml file root element, otherwise it correspond to the whole file. +% Pref.CellItem - default 'true' - leave 'item' nodes in cell notation. +% OUTPUT: +% tree tree of structs and/or cell arrays corresponding to xml file +% RootName XML tag name used for root (top level) node. +% Optionally it can be a string cell array storing: Name of +% root node, document "Processing Instructions" data and +% document "comment" string +% DOMnode output of xmlread +% +% DETAILS: +% Function xml_read first calls MATLAB's xmlread function and than +% converts its output ('Document Object Model' tree of Java objects) +% to tree of MATLAB struct's. The output is in format of nested structs +% and cells. In the output data structure field names are based on +% XML tags, except in cases when tags produce illegal variable names. +% +% Several special xml node types result in special tags for fields of +% 'tree' nodes: +% - node.CONTENT - stores data section of the node if other fields are +% present. Usually data section is stored directly in 'node'. +% - node.ATTRIBUTE.name - stores node's attribute called 'name'. +% - node.COMMENT - stores node's comment section (string). For global +% comments see "RootName" output variable. +% - node.CDATA_SECTION - stores node's CDATA section (string). +% - node.PROCESSING_INSTRUCTIONS - stores "processing instruction" child +% node. For global "processing instructions" see "RootName" output variable. +% - other special node types like: document fragment nodes, document type +% nodes, entity nodes, notation nodes and processing instruction nodes +% will be treated like regular nodes +% +% EXAMPLES: +% MyTree=[]; +% MyTree.MyNumber = 13; +% MyTree.MyString = 'Hello World'; +% xml_write('test.xml', MyTree); +% [tree treeName] = xml_read ('test.xml'); +% disp(treeName) +% gen_object_display() +% % See also xml_examples.m +% +% See also: +% xml_write, xmlread, xmlwrite +% +% Written by Jarek Tuszynski, SAIC, jaroslaw.w.tuszynski_at_saic.com +% References: +% - Function inspired by Example 3 found in xmlread function. +% - Output data structures inspired by xml_toolbox structures. + +%% default preferences +DPref.TableName = {'tr','td'}; % name of a special tags used to itemize 2D cell arrays +DPref.ItemName = 'item'; % name of a special tag used to itemize 1D cell arrays +DPref.CellItem = false; % leave 'item' nodes in cell notation +DPref.ReadAttr = true; % allow reading attributes +DPref.ReadSpec = true; % allow reading special nodes: comments, CData, etc. +DPref.KeepNS = true; % Keep or strip namespace info +DPref.Str2Num = 'smart';% convert strings that look like numbers to numbers +DPref.NoCells = true; % force output to have no cell arrays +DPref.NumLevels = 1e10; % number of recurence levels +DPref.PreserveSpace = false; % Preserve or delete spaces at the beggining and the end of stings? +RootOnly = true; % return root node with no top level special nodes +Debug = false; % show specific errors (true) or general (false)? +tree = []; +RootName = []; + +%% Check Matlab Version +v = ver('MATLAB'); +version = str2double(regexp(v.Version, '\d.\d','match','once')); +if (version<7.1) + error('Your MATLAB version is too old. You need version 7.1 or newer.'); +end + +%% read user preferences +if (nargin>1) + if (isfield(Pref, 'TableName')), DPref.TableName = Pref.TableName; end + if (isfield(Pref, 'ItemName' )), DPref.ItemName = Pref.ItemName; end + if (isfield(Pref, 'CellItem' )), DPref.CellItem = Pref.CellItem; end + if (isfield(Pref, 'Str2Num' )), DPref.Str2Num = Pref.Str2Num ; end + if (isfield(Pref, 'NoCells' )), DPref.NoCells = Pref.NoCells ; end + if (isfield(Pref, 'NumLevels')), DPref.NumLevels = Pref.NumLevels; end + if (isfield(Pref, 'ReadAttr' )), DPref.ReadAttr = Pref.ReadAttr; end + if (isfield(Pref, 'ReadSpec' )), DPref.ReadSpec = Pref.ReadSpec; end + if (isfield(Pref, 'KeepNS' )), DPref.KeepNS = Pref.KeepNS; end + if (isfield(Pref, 'RootOnly' )), RootOnly = Pref.RootOnly; end + if (isfield(Pref, 'Debug' )), Debug = Pref.Debug ; end + if (isfield(Pref, 'PreserveSpace')), DPref.PreserveSpace = Pref.PreserveSpace; end +end +if ischar(DPref.Str2Num), % convert from character description to numbers + DPref.Str2Num = find(strcmpi(DPref.Str2Num, {'never', 'smart', 'always'}))-1; + if isempty(DPref.Str2Num), DPref.Str2Num=1; end % 1-smart by default +end + +%% read xml file using Matlab function +if isa(xmlfile, 'org.apache.xerces.dom.DeferredDocumentImpl'); + % if xmlfile is a DOMnode than skip the call to xmlread + try + try + DOMnode = xmlfile; + catch ME + error('Invalid DOM node: \n%s.', getReport(ME)); + end + catch %#ok catch for mablab versions prior to 7.5 + error('Invalid DOM node. \n'); + end +else % we assume xmlfile is a filename + if (Debug) % in debuging mode crashes are allowed + DOMnode = xmlread(xmlfile); + else % in normal mode crashes are not allowed + try + try + DOMnode = xmlread(xmlfile); + catch ME + error('Failed to read XML file %s: \n%s',xmlfile, getReport(ME)); + end + catch %#ok catch for mablab versions prior to 7.5 + error('Failed to read XML file %s\n',xmlfile); + end + end +end +Node = DOMnode.getFirstChild; + +%% Find the Root node. Also store data from Global Comment and Processing +% Instruction nodes, if any. +GlobalTextNodes = cell(1,3); +GlobalProcInst = []; +GlobalComment = []; +GlobalDocType = []; +while (~isempty(Node)) + if (Node.getNodeType==Node.ELEMENT_NODE) + RootNode=Node; + elseif (Node.getNodeType==Node.PROCESSING_INSTRUCTION_NODE) + data = strtrim(char(Node.getData)); + target = strtrim(char(Node.getTarget)); + GlobalProcInst = [target, ' ', data]; + GlobalTextNodes{2} = GlobalProcInst; + elseif (Node.getNodeType==Node.COMMENT_NODE) + GlobalComment = strtrim(char(Node.getData)); + GlobalTextNodes{3} = GlobalComment; + % elseif (Node.getNodeType==Node.DOCUMENT_TYPE_NODE) + % GlobalTextNodes{4} = GlobalDocType; + end + Node = Node.getNextSibling; +end + +%% parse xml file through calls to recursive DOMnode2struct function +if (Debug) % in debuging mode crashes are allowed + [tree RootName] = DOMnode2struct(RootNode, DPref, 1); +else % in normal mode crashes are not allowed + try + try + [tree RootName] = DOMnode2struct(RootNode, DPref, 1); + catch ME + error('Unable to parse XML file %s: \n %s.',xmlfile, getReport(ME)); + end + catch %#ok catch for mablab versions prior to 7.5 + error('Unable to parse XML file %s.',xmlfile); + end +end + +%% If there were any Global Text nodes than return them +if (~RootOnly) + if (~isempty(GlobalProcInst) && DPref.ReadSpec) + t.PROCESSING_INSTRUCTION = GlobalProcInst; + end + if (~isempty(GlobalComment) && DPref.ReadSpec) + t.COMMENT = GlobalComment; + end + if (~isempty(GlobalDocType) && DPref.ReadSpec) + t.DOCUMENT_TYPE = GlobalDocType; + end + t.(RootName) = tree; + tree=t; +end +if (~isempty(GlobalTextNodes)) + GlobalTextNodes{1} = RootName; + RootName = GlobalTextNodes; +end + + +%% ======================================================================= +% === DOMnode2struct Function =========================================== +% ======================================================================= +function [s TagName LeafNode] = DOMnode2struct(node, Pref, level) + +%% === Step 1: Get node name and check if it is a leaf node ============== +[TagName LeafNode] = NodeName(node, Pref.KeepNS); +s = []; % initialize output structure + +%% === Step 2: Process Leaf Nodes (nodes with no children) =============== +if (LeafNode) + if (LeafNode>1 && ~Pref.ReadSpec), LeafNode=-1; end % tags only so ignore special nodes + if (LeafNode>0) % supported leaf node types + try + try % use try-catch: errors here are often due to VERY large fields (like images) that overflow java memory + s = char(node.getData); + if (isempty(s)), s = ' '; end % make it a string + % for some reason current xmlread 'creates' a lot of empty text + % fields with first chatacter=10 - those will be deleted. + if (~Pref.PreserveSpace || s(1)==10) + if (isspace(s(1)) || isspace(s(end))), s = strtrim(s); end % trim speces is any + end + if (LeafNode==1), s=str2var(s, Pref.Str2Num, 0); end % convert to number(s) if needed + catch ME % catch for mablab versions 7.5 and higher + warning('xml_io_tools:read:LeafRead', ... + 'This leaf node could not be read and was ignored. '); + getReport(ME) + end + catch %#ok catch for mablab versions prior to 7.5 + warning('xml_io_tools:read:LeafRead', ... + 'This leaf node could not be read and was ignored. '); + end + end + if (LeafNode==3) % ProcessingInstructions need special treatment + target = strtrim(char(node.getTarget)); + s = [target, ' ', s]; + end + return % We are done the rest of the function deals with nodes with children +end +if (level>Pref.NumLevels+1), return; end % if Pref.NumLevels is reached than we are done + +%% === Step 3: Process nodes with children =============================== +if (node.hasChildNodes) % children present + Child = node.getChildNodes; % create array of children nodes + nChild = Child.getLength; % number of children + + % --- pass 1: how many children with each name ----------------------- + f = []; + for iChild = 1:nChild % read in each child + [cname cLeaf] = NodeName(Child.item(iChild-1), Pref.KeepNS); + if (cLeaf<0), continue; end % unsupported leaf node types + if (~isfield(f,cname)), + f.(cname)=0; % initialize first time I see this name + end + f.(cname) = f.(cname)+1; % add to the counter + end % end for iChild + % text_nodes become CONTENT & for some reason current xmlread 'creates' a + % lot of empty text fields so f.CONTENT value should not be trusted + if (isfield(f,'CONTENT') && f.CONTENT>2), f.CONTENT=2; end + + % --- pass 2: store all the children as struct of cell arrays ---------- + for iChild = 1:nChild % read in each child + [c cname cLeaf] = DOMnode2struct(Child.item(iChild-1), Pref, level+1); + if (cLeaf && isempty(c)) % if empty leaf node than skip + continue; % usually empty text node or one of unhandled node types + elseif (nChild==1 && cLeaf==1) + s=c; % shortcut for a common case + else % if normal node + if (level>Pref.NumLevels), continue; end + n = f.(cname); % how many of them in the array so far? + if (~isfield(s,cname)) % encountered this name for the first time + if (n==1) % if there will be only one of them ... + s.(cname) = c; % than save it in format it came in + else % if there will be many of them ... + s.(cname) = cell(1,n); + s.(cname){1} = c; % than save as cell array + end + f.(cname) = 1; % initialize the counter + else % already have seen this name + s.(cname){n+1} = c; % add to the array + f.(cname) = n+1; % add to the array counter + end + end + end % for iChild +end % end if (node.hasChildNodes) + +%% === Step 4: Post-process struct's created for nodes with children ===== +if (isstruct(s)) + fields = fieldnames(s); + nField = length(fields); + + % Detect structure that looks like Html table and store it in cell Matrix + if (nField==1 && strcmpi(fields{1},Pref.TableName{1})) + tr = s.(Pref.TableName{1}); + fields2 = fieldnames(tr{1}); + if (length(fields2)==1 && strcmpi(fields2{1},Pref.TableName{2})) + % This seems to be a special structure such that for + % Pref.TableName = {'tr','td'} 's' corresponds to + % M11 M12 + % M12 M22 + % Recognize it as encoding for 2D struct + nr = length(tr); + for r = 1:nr + row = tr{r}.(Pref.TableName{2}); + Table(r,1:length(row)) = row; %#ok + end + s = Table; + end + end + + % --- Post-processing: convert 'struct of cell-arrays' to 'array of structs' + % Example: let say s has 3 fields s.a, s.b & s.c and each field is an + % cell-array with more than one cell-element and all 3 have the same length. + % Then change it to array of structs, each with single cell. + % This way element s.a{1} will be now accessed through s(1).a + vec = zeros(size(fields)); + for i=1:nField, vec(i) = f.(fields{i}); end + if (numel(vec)>1 && vec(1)>1 && var(vec)==0) % convert from struct of + s = cell2struct(struct2cell(s), fields, 1); % arrays to array of struct + end % if anyone knows better way to do above conversion please let me know. + +end + +%% === Step 5: Process nodes with attributes ============================= +if (node.hasAttributes && Pref.ReadAttr) + if (~isstruct(s)), % make into struct if is not already + ss.CONTENT=s; + s=ss; + end + Attr = node.getAttributes; % list of all attributes + for iAttr = 1:Attr.getLength % for each attribute + name = char(Attr.item(iAttr-1).getName); % attribute name + name = str2varName(name, Pref.KeepNS); % fix name if needed + value = char(Attr.item(iAttr-1).getValue); % attribute value + value = str2var(value, Pref.Str2Num, 1); % convert to number if possible + s.ATTRIBUTE.(name) = value; % save again + end % end iAttr loop +end % done with attributes +if (~isstruct(s)), return; end %The rest of the code deals with struct's + +%% === Post-processing: fields of "s" +% convert 'cell-array of structs' to 'arrays of structs' +fields = fieldnames(s); % get field names +nField = length(fields); +for iItem=1:length(s) % for each struct in the array - usually one + for iField=1:length(fields) + field = fields{iField}; % get field name + % if this is an 'item' field and user want to leave those as cells + % than skip this one + if (strcmpi(field, Pref.ItemName) && Pref.CellItem), continue; end + x = s(iItem).(field); + if (iscell(x) && all(cellfun(@isstruct,x(:))) && numel(x)>1) % it's cell-array of structs + % numel(x)>1 check is to keep 1 cell-arrays created when Pref.CellItem=1 + try % this operation fails sometimes + % example: change s(1).a{1}.b='jack'; s(1).a{2}.b='john'; to + % more convinient s(1).a(1).b='jack'; s(1).a(2).b='john'; + s(iItem).(field) = [x{:}]'; %#ok % converted to arrays of structs + catch %#ok + % above operation will fail if s(1).a{1} and s(1).a{2} have + % different fields. If desired, function forceCell2Struct can force + % them to the same field structure by adding empty fields. + if (Pref.NoCells) + s(iItem).(field) = forceCell2Struct(x); %#ok + end + end % end catch + end + end +end + +%% === Step 4: Post-process struct's created for nodes with children ===== + +% --- Post-processing: remove special 'item' tags --------------------- +% many xml writes (including xml_write) use a special keyword to mark +% arrays of nodes (see xml_write for examples). The code below converts +% s.item to s.CONTENT +ItemContent = false; +if (isfield(s,Pref.ItemName)) + s.CONTENT = s.(Pref.ItemName); + s = rmfield(s,Pref.ItemName); + ItemContent = Pref.CellItem; % if CellItem than keep s.CONTENT as cells +end + +% --- Post-processing: clean up CONTENT tags --------------------- +% if s.CONTENT is a cell-array with empty elements at the end than trim +% the length of this cell-array. Also if s.CONTENT is the only field than +% remove .CONTENT part and store it as s. +if (isfield(s,'CONTENT')) + if (iscell(s.CONTENT) && isvector(s.CONTENT)) + x = s.CONTENT; + for i=numel(x):-1:1, if ~isempty(x{i}), break; end; end + if (i==1 && ~ItemContent) + s.CONTENT = x{1}; % delete cell structure + else + s.CONTENT = x(1:i); % delete empty cells + end + end + if (nField==1) + if (ItemContent) + ss = s.CONTENT; % only child: remove a level but ensure output is a cell-array + s=[]; s{1}=ss; + else + s = s.CONTENT; % only child: remove a level + end + end +end + + + +%% ======================================================================= +% === forceCell2Struct Function ========================================= +% ======================================================================= +function s = forceCell2Struct(x) +% Convert cell-array of structs, where not all of structs have the same +% fields, to a single array of structs + +%% Convert 1D cell array of structs to 2D cell array, where each row +% represents item in original array and each column corresponds to a unique +% field name. Array "AllFields" store fieldnames for each column +AllFields = fieldnames(x{1}); % get field names of the first struct +CellMat = cell(length(x), length(AllFields)); +for iItem=1:length(x) + fields = fieldnames(x{iItem}); % get field names of the next struct + for iField=1:length(fields) % inspect all fieldnames and find those + field = fields{iField}; % get field name + col = find(strcmp(field,AllFields),1); + if isempty(col) % no column for such fieldname yet + AllFields = [AllFields; field]; %#ok + col = length(AllFields); % create a new column for it + end + CellMat{iItem,col} = x{iItem}.(field); % store rearanged data + end +end +%% Convert 2D cell array to array of structs +s = cell2struct(CellMat, AllFields, 2); + +%% ======================================================================= +% === str2var Function ================================================== +% ======================================================================= +function val=str2var(str, option, attribute) +% Can this string 'str' be converted to a number? if so than do it. +val = str; +len = numel(str); +if (len==0 || option==0), return; end % Str2Num="never" of empty string -> do not do enything +if (len>10000 && option==1), return; end % Str2Num="smart" and string is very long -> probably base64 encoded binary +digits = '(Inf)|(NaN)|(pi)|[\t\n\d\+\-\*\.ei EI\[\]\;\,]'; +s = regexprep(str, digits, ''); % remove all the digits and other allowed characters +if (~all(~isempty(s))) % if nothing left than this is probably a number + if (~isempty(strfind(str, ' '))), option=2; end %if str has white-spaces assume by default that it is not a date string + if (~isempty(strfind(str, '['))), option=2; end % same with brackets + str(strfind(str, '\n')) = ';';% parse data tables into 2D arrays, if any + if (option==1) % the 'smart' option + try % try to convert to a date, like 2007-12-05 + datenum(str); % if successful than leave it as string + catch %#ok % if this is not a date than ... + option=2; % ... try converting to a number + end + end + if (option==2) + if (attribute) + num = str2double(str); % try converting to a single number using sscanf function + if isnan(num), return; end % So, it wasn't really a number after all + else + num = str2num(str); %#ok % try converting to a single number or array using eval function + end + if(isnumeric(num) && numel(num)>0), val=num; end % if convertion to a single was succesful than save + end +elseif ((str(1)=='[' && str(end)==']') || (str(1)=='{' && str(end)=='}')) % this looks like a (cell) array encoded as a string + try + val = eval(str); + catch %#ok + val = str; + end +elseif (~attribute) % see if it is a boolean array with no [] brackets + str1 = lower(str); + str1 = strrep(str1, 'false', '0'); + str1 = strrep(str1, 'true' , '1'); + s = regexprep(str1, '[01 \;\,]', ''); % remove all 0/1, spaces, commas and semicolons + if (~all(~isempty(s))) % if nothing left than this is probably a boolean array + num = str2num(str1); %#ok + if(isnumeric(num) && numel(num)>0), val = (num>0); end % if convertion was succesful than save as logical + end +end + + +%% ======================================================================= +% === str2varName Function ============================================== +% ======================================================================= +function str = str2varName(str, KeepNS) +% convert a sting to a valid matlab variable name +if(KeepNS) + str = regexprep(str,':','_COLON_', 'once', 'ignorecase'); +else + k = strfind(str,':'); + if (~isempty(k)) + str = str(k+1:end); + end +end +str = regexprep(str,'-','_DASH_' ,'once', 'ignorecase'); +if (~isvarname(str)) && (~iskeyword(str)) + str = genvarname(str); +end + +%% ======================================================================= +% === NodeName Function ================================================= +% ======================================================================= +function [Name LeafNode] = NodeName(node, KeepNS) +% get node name and make sure it is a valid variable name in Matlab. +% also get node type: +% LeafNode=0 - normal element node, +% LeafNode=1 - text node +% LeafNode=2 - supported non-text leaf node, +% LeafNode=3 - supported processing instructions leaf node, +% LeafNode=-1 - unsupported non-text leaf node +switch (node.getNodeType) + case node.ELEMENT_NODE + Name = char(node.getNodeName);% capture name of the node + Name = str2varName(Name, KeepNS); % if Name is not a good variable name - fix it + LeafNode = 0; + case node.TEXT_NODE + Name = 'CONTENT'; + LeafNode = 1; + case node.COMMENT_NODE + Name = 'COMMENT'; + LeafNode = 2; + case node.CDATA_SECTION_NODE + Name = 'CDATA_SECTION'; + LeafNode = 2; + case node.DOCUMENT_TYPE_NODE + Name = 'DOCUMENT_TYPE'; + LeafNode = 2; + case node.PROCESSING_INSTRUCTION_NODE + Name = 'PROCESSING_INSTRUCTION'; + LeafNode = 3; + otherwise + NodeType = {'ELEMENT','ATTRIBUTE','TEXT','CDATA_SECTION', ... + 'ENTITY_REFERENCE', 'ENTITY', 'PROCESSING_INSTRUCTION', 'COMMENT',... + 'DOCUMENT', 'DOCUMENT_TYPE', 'DOCUMENT_FRAGMENT', 'NOTATION'}; + Name = char(node.getNodeName);% capture name of the node + warning('xml_io_tools:read:unkNode', ... + 'Unknown node type encountered: %s_NODE (%s)', NodeType{node.getNodeType}, Name); + LeafNode = -1; +end + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/xml_write.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/xml_write.m new file mode 100644 index 0000000000000000000000000000000000000000..8ed29d5267b92b1e93fd7640e63dea3b57c17f93 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/xml_write.m @@ -0,0 +1,447 @@ +function DOMnode = xml_write(filename, tree, RootName, Pref) +%XML_WRITE Writes Matlab data structures to XML file +% +% DESCRIPTION +% xml_write( filename, tree) Converts Matlab data structure 'tree' containing +% cells, structs, numbers and strings to Document Object Model (DOM) node +% tree, then saves it to XML file 'filename' using Matlab's xmlwrite +% function. Optionally one can also use alternative version of xmlwrite +% function which directly calls JAVA functions for XML writing without +% MATLAB middleware. This function is provided as a patch to existing +% bugs in xmlwrite (in R2006b). +% +% xml_write(filename, tree, RootName, Pref) allows you to specify +% additional preferences about file format +% +% DOMnode = xml_write([], tree) same as above except that DOM node is +% not saved to the file but returned. +% +% INPUT +% filename file name +% tree Matlab structure tree to store in xml file. +% RootName String with XML tag name used for root (top level) node +% Optionally it can be a string cell array storing: Name of +% root node, document "Processing Instructions" data and +% document "comment" string +% Pref Other preferences: +% Pref.ItemName - default 'item' - name of a special tag used to +% itemize cell or struct arrays +% Pref.XmlEngine - let you choose the XML engine. Currently default is +% 'Xerces', which is using directly the apache xerces java file. +% Other option is 'Matlab' which uses MATLAB's xmlwrite and its +% XMLUtils java file. Both options create identical results except in +% case of CDATA sections where xmlwrite fails. +% Pref.CellItem - default 'true' - allow cell arrays to use 'item' +% notation. See below. +% Pref.RootOnly - default true - output variable 'tree' corresponds to +% xml file root element, otherwise it correspond to the whole file. +% Pref.StructItem - default 'true' - allow arrays of structs to use +% 'item' notation. For example "Pref.StructItem = true" gives: +% +% +% ... <\item> +% ... <\item> +% <\b> +% <\a> +% while "Pref.StructItem = false" gives: +% +% ... <\b> +% ... <\b> +% <\a> +% +% +% Several special xml node types can be created if special tags are used +% for field names of 'tree' nodes: +% - node.CONTENT - stores data section of the node if other fields +% (usually ATTRIBUTE are present. Usually data section is stored +% directly in 'node'. +% - node.ATTRIBUTE.name - stores node's attribute called 'name'. +% - node.COMMENT - create comment child node from the string. For global +% comments see "RootName" input variable. +% - node.PROCESSING_INSTRUCTIONS - create "processing instruction" child +% node from the string. For global "processing instructions" see +% "RootName" input variable. +% - node.CDATA_SECTION - stores node's CDATA section (string). Only works +% if Pref.XmlEngine='Xerces'. For more info, see comments of F_xmlwrite. +% - other special node types like: document fragment nodes, document type +% nodes, entity nodes and notation nodes are not being handled by +% 'xml_write' at the moment. +% +% OUTPUT +% DOMnode Document Object Model (DOM) node tree in the format +% required as input to xmlwrite. (optional) +% +% EXAMPLES: +% MyTree=[]; +% MyTree.MyNumber = 13; +% MyTree.MyString = 'Hello World'; +% xml_write('test.xml', MyTree); +% type('test.xml') +% %See also xml_tutorial.m +% +% See also +% xml_read, xmlread, xmlwrite +% +% Written by Jarek Tuszynski, SAIC, jaroslaw.w.tuszynski_at_saic.com + +%% Check Matlab Version +v = ver('MATLAB'); +v = str2double(regexp(v.Version, '\d.\d','match','once')); +if (v<7) + error('Your MATLAB version is too old. You need version 7.0 or newer.'); +end + +%% default preferences +DPref.TableName = {'tr','td'}; % name of a special tags used to itemize 2D cell arrays +DPref.ItemName = 'item'; % name of a special tag used to itemize 1D cell arrays +DPref.StructItem = true; % allow arrays of structs to use 'item' notation +DPref.CellItem = true; % allow cell arrays to use 'item' notation +DPref.StructTable= 'Html'; +DPref.CellTable = 'Html'; +DPref.XmlEngine = 'Matlab'; % use matlab provided XMLUtils +%DPref.XmlEngine = 'Xerces'; % use Xerces xml generator directly +DPref.PreserveSpace = false; % Preserve or delete spaces at the beggining and the end of stings? +RootOnly = true; % Input is root node only +GlobalProcInst = []; +GlobalComment = []; +GlobalDocType = []; + +%% read user preferences +if (nargin>3) + if (isfield(Pref, 'TableName' )), DPref.TableName = Pref.TableName; end + if (isfield(Pref, 'ItemName' )), DPref.ItemName = Pref.ItemName; end + if (isfield(Pref, 'StructItem')), DPref.StructItem = Pref.StructItem; end + if (isfield(Pref, 'CellItem' )), DPref.CellItem = Pref.CellItem; end + if (isfield(Pref, 'CellTable')), DPref.CellTable = Pref.CellTable; end + if (isfield(Pref, 'StructTable')), DPref.StructTable= Pref.StructTable; end + if (isfield(Pref, 'XmlEngine' )), DPref.XmlEngine = Pref.XmlEngine; end + if (isfield(Pref, 'RootOnly' )), RootOnly = Pref.RootOnly; end + if (isfield(Pref, 'PreserveSpace')), DPref.PreserveSpace = Pref.PreserveSpace; end +end +if (nargin<3 || isempty(RootName)), RootName=inputname(2); end +if (isempty(RootName)), RootName='ROOT'; end +if (iscell(RootName)) % RootName also stores global text node data + rName = RootName; + RootName = char(rName{1}); + if (length(rName)>1), GlobalProcInst = char(rName{2}); end + if (length(rName)>2), GlobalComment = char(rName{3}); end + if (length(rName)>3), GlobalDocType = char(rName{4}); end +end +if(~RootOnly && isstruct(tree)) % if struct than deal with each field separatly + fields = fieldnames(tree); + for i=1:length(fields) + field = fields{i}; + x = tree(1).(field); + if (strcmp(field, 'COMMENT')) + GlobalComment = x; + elseif (strcmp(field, 'PROCESSING_INSTRUCTION')) + GlobalProcInst = x; + elseif (strcmp(field, 'DOCUMENT_TYPE')) + GlobalDocType = x; + else + RootName = field; + t = x; + end + end + tree = t; +end + +%% Initialize jave object that will store xml data structure +RootName = varName2str(RootName); +if (~isempty(GlobalDocType)) + % n = strfind(GlobalDocType, ' '); + % if (~isempty(n)) + % dtype = com.mathworks.xml.XMLUtils.createDocumentType(GlobalDocType); + % end + % DOMnode = com.mathworks.xml.XMLUtils.createDocument(RootName, dtype); + warning('xml_io_tools:write:docType', ... + 'DOCUMENT_TYPE node was encountered which is not supported yet. Ignoring.'); +end +DOMnode = com.mathworks.xml.XMLUtils.createDocument(RootName); + + +%% Use recursive function to convert matlab data structure to XML +root = DOMnode.getDocumentElement; +struct2DOMnode(DOMnode, root, tree, DPref.ItemName, DPref); + +%% Remove the only child of the root node +root = DOMnode.getDocumentElement; +Child = root.getChildNodes; % create array of children nodes +nChild = Child.getLength; % number of children +if (nChild==1) + node = root.removeChild(root.getFirstChild); + while(node.hasChildNodes) + root.appendChild(node.removeChild(node.getFirstChild)); + end + while(node.hasAttributes) % copy all attributes + root.setAttributeNode(node.removeAttributeNode(node.getAttributes.item(0))); + end +end + +%% Save exotic Global nodes +if (~isempty(GlobalComment)) + DOMnode.insertBefore(DOMnode.createComment(GlobalComment), DOMnode.getFirstChild()); +end +if (~isempty(GlobalProcInst)) + n = strfind(GlobalProcInst, ' '); + if (~isempty(n)) + proc = DOMnode.createProcessingInstruction(GlobalProcInst(1:(n(1)-1)),... + GlobalProcInst((n(1)+1):end)); + DOMnode.insertBefore(proc, DOMnode.getFirstChild()); + end +end +% Not supported yet as the code below does not work +% if (~isempty(GlobalDocType)) +% n = strfind(GlobalDocType, ' '); +% if (~isempty(n)) +% dtype = DOMnode.createDocumentType(GlobalDocType); +% DOMnode.insertBefore(dtype, DOMnode.getFirstChild()); +% end +% end + +%% save java DOM tree to XML file +if (~isempty(filename)) + if (strcmpi(DPref.XmlEngine, 'Xerces')) + xmlwrite_xerces(filename, DOMnode); + else + xmlwrite(filename, DOMnode); + end +end + + +%% ======================================================================= +% === struct2DOMnode Function =========================================== +% ======================================================================= +function [] = struct2DOMnode(xml, parent, s, TagName, Pref) +% struct2DOMnode is a recursive function that converts matlab's structs to +% DOM nodes. +% INPUTS: +% xml - jave object that will store xml data structure +% parent - parent DOM Element +% s - Matlab data structure to save +% TagName - name to be used in xml tags describing 's' +% Pref - preferenced +% OUTPUT: +% parent - modified 'parent' + +% perform some conversions +if (ischar(s) && min(size(s))>1) % if 2D array of characters + s=cellstr(s); % than convert to cell array +end +% if (strcmp(TagName, 'CONTENT')) +% while (iscell(s) && length(s)==1), s = s{1}; end % unwrap cell arrays of length 1 +% end +TagName = varName2str(TagName); + +%% == node is a 2D cell array == +% convert to some other format prior to further processing +nDim = nnz(size(s)>1); % is it a scalar, vector, 2D array, 3D cube, etc? +if (iscell(s) && nDim==2 && strcmpi(Pref.CellTable, 'Matlab')) + s = var2str(s, Pref.PreserveSpace); +end +if (nDim==2 && (iscell (s) && strcmpi(Pref.CellTable, 'Vector')) || ... + (isstruct(s) && strcmpi(Pref.StructTable, 'Vector'))) + s = s(:); +end +if (nDim>2), s = s(:); end % can not handle this case well +nItem = numel(s); +nDim = nnz(size(s)>1); % is it a scalar, vector, 2D array, 3D cube, etc? + +%% == node is a cell == +if (iscell(s)) % if this is a cell or cell array + if ((nDim==2 && strcmpi(Pref.CellTable,'Html')) || (nDim< 2 && Pref.CellItem)) + % if 2D array of cells than can use HTML-like notation or if 1D array + % than can use item notation + if (strcmp(TagName, 'CONTENT')) % CONTENT nodes already have ... + array2DOMnode(xml, parent, s, Pref.ItemName, Pref ); % recursive call + else + node = xml.createElement(TagName); % ... + array2DOMnode(xml, node, s, Pref.ItemName, Pref ); % recursive call + parent.appendChild(node); + end + else % use ...<\TagName> ...<\TagName> notation + array2DOMnode(xml, parent, s, TagName, Pref ); % recursive call + end +%% == node is a struct == +elseif (isstruct(s)) % if struct than deal with each field separatly + if ((nDim==2 && strcmpi(Pref.StructTable,'Html')) || (nItem>1 && Pref.StructItem)) + % if 2D array of structs than can use HTML-like notation or + % if 1D array of structs than can use 'items' notation + node = xml.createElement(TagName); + array2DOMnode(xml, node, s, Pref.ItemName, Pref ); % recursive call + parent.appendChild(node); + elseif (nItem>1) % use ...<\TagName> ...<\TagName> notation + array2DOMnode(xml, parent, s, TagName, Pref ); % recursive call + else % otherwise save each struct separatelly + fields = fieldnames(s); + node = xml.createElement(TagName); + for i=1:length(fields) % add field by field to the node + field = fields{i}; + x = s.(field); + switch field + case {'COMMENT', 'CDATA_SECTION', 'PROCESSING_INSTRUCTION'} + if iscellstr(x) % cell array of strings -> add them one by one + array2DOMnode(xml, node, x(:), field, Pref ); % recursive call will modify 'node' + elseif ischar(x) % single string -> add it + struct2DOMnode(xml, node, x, field, Pref ); % recursive call will modify 'node' + else % not a string - Ignore + warning('xml_io_tools:write:badSpecialNode', ... + ['Struct field named ',field,' encountered which was not a string. Ignoring.']); + end + case 'ATTRIBUTE' % set attributes of the node + if (isempty(x)), continue; end + if (isstruct(x)) + attName = fieldnames(x); % get names of all the attributes + for k=1:length(attName) % attach them to the node + att = xml.createAttribute(varName2str(attName(k))); + att.setValue(var2str(x.(attName{k}),Pref.PreserveSpace)); + node.setAttributeNode(att); + end + else + warning('xml_io_tools:write:badAttribute', ... + 'Struct field named ATTRIBUTE encountered which was not a struct. Ignoring.'); + end + otherwise % set children of the node + struct2DOMnode(xml, node, x, field, Pref ); % recursive call will modify 'node' + end + end % end for i=1:nFields + parent.appendChild(node); + end +%% == node is a leaf node == +else % if not a struct and not a cell than it is a leaf node + switch TagName % different processing depending on desired type of the node + case 'COMMENT' % create comment node + com = xml.createComment(s); + parent.appendChild(com); + case 'CDATA_SECTION' % create CDATA Section + cdt = xml.createCDATASection(s); + parent.appendChild(cdt); + case 'PROCESSING_INSTRUCTION' % set attributes of the node + OK = false; + if (ischar(s)) + n = strfind(s, ' '); + if (~isempty(n)) + proc = xml.createProcessingInstruction(s(1:(n(1)-1)),s((n(1)+1):end)); + parent.insertBefore(proc, parent.getFirstChild()); + OK = true; + end + end + if (~OK) + warning('xml_io_tools:write:badProcInst', ... + ['Struct field named PROCESSING_INSTRUCTION need to be',... + ' a string, for example: xml-stylesheet type="text/css" ', ... + 'href="myStyleSheet.css". Ignoring.']); + end + case 'CONTENT' % this is text part of already existing node + txt = xml.createTextNode(var2str(s, Pref.PreserveSpace)); % convert to text + parent.appendChild(txt); + otherwise % I guess it is a regular text leaf node + txt = xml.createTextNode(var2str(s, Pref.PreserveSpace)); + node = xml.createElement(TagName); + node.appendChild(txt); + parent.appendChild(node); + end +end % of struct2DOMnode function + +%% ======================================================================= +% === array2DOMnode Function ============================================ +% ======================================================================= +function [] = array2DOMnode(xml, parent, s, TagName, Pref) +% Deal with 1D and 2D arrays of cell or struct. Will modify 'parent'. +nDim = nnz(size(s)>1); % is it a scalar, vector, 2D array, 3D cube, etc? +switch nDim + case 2 % 2D array + for r=1:size(s,1) + subnode = xml.createElement(Pref.TableName{1}); + for c=1:size(s,2) + v = s(r,c); + if iscell(v), v = v{1}; end + struct2DOMnode(xml, subnode, v, Pref.TableName{2}, Pref ); % recursive call + end + parent.appendChild(subnode); + end + case 1 %1D array + for iItem=1:numel(s) + v = s(iItem); + if iscell(v), v = v{1}; end + struct2DOMnode(xml, parent, v, TagName, Pref ); % recursive call + end + case 0 % scalar -> this case should never be called + if ~isempty(s) + if iscell(s), s = s{1}; end + struct2DOMnode(xml, parent, s, TagName, Pref ); + end +end + +%% ======================================================================= +% === var2str Function ================================================== +% ======================================================================= +function str = var2str(object, PreserveSpace) +% convert matlab variables to a string +switch (1) + case isempty(object) + str = ''; + case (isnumeric(object) || islogical(object)) + if ndims(object)>2, object=object(:); end % can't handle arrays with dimention > 2 + str=mat2str(object); % convert matrix to a string + % mark logical scalars with [] (logical arrays already have them) so the xml_read + % recognizes them as MATLAB objects instead of strings. Same with sparse + % matrices + if ((islogical(object) && isscalar(object)) || issparse(object)), + str = ['[' str ']']; + end + if (isinteger(object)), + str = ['[', class(object), '(', str ')]']; + end + case iscell(object) + if ndims(object)>2, object=object(:); end % can't handle cell arrays with dimention > 2 + [nr nc] = size(object); + obj2 = object; + for i=1:length(object(:)) + str = var2str(object{i}, PreserveSpace); + if (ischar(object{i})), object{i} = ['''' object{i} '''']; else object{i}=str; end + obj2{i} = [object{i} ',']; + end + for r = 1:nr, obj2{r,nc} = [object{r,nc} ';']; end + obj2 = obj2.'; + str = ['{' obj2{:} '}']; + case isstruct(object) + str=''; + warning('xml_io_tools:write:var2str', ... + 'Struct was encountered where string was expected. Ignoring.'); + case isa(object, 'function_handle') + str = ['[@' char(object) ']']; + case ischar(object) + str = object; + otherwise + str = char(object); +end + +%% string clean-up +str=str(:); str=str.'; % make sure this is a row vector of char's +if (~isempty(str)) + str(str<32|str==127)=' '; % convert no-printable characters to spaces + if (~PreserveSpace) + str = strtrim(str); % remove spaces from begining and the end + str = regexprep(str,'\s+',' '); % remove multiple spaces + end +end + +%% ======================================================================= +% === var2Namestr Function ============================================== +% ======================================================================= +function str = varName2str(str) +% convert matlab variable names to a sting +str = char(str); +p = strfind(str,'0x'); +if (~isempty(p)) + for i=1:length(p) + before = str( p(i)+(0:3) ); % string to replace + after = char(hex2dec(before(3:4))); % string to replace with + str = regexprep(str,before,after, 'once', 'ignorecase'); + p=p-3; % since 4 characters were replaced with one - compensate + end +end +str = regexprep(str,'_COLON_',':', 'once', 'ignorecase'); +str = regexprep(str,'_DASH_' ,'-', 'once', 'ignorecase'); + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/xmlwrite_xerces.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/xmlwrite_xerces.m new file mode 100644 index 0000000000000000000000000000000000000000..56dd30f3fb92ca5d27f460352ee0ca742bb802f1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/utils/xmlwrite_xerces.m @@ -0,0 +1,109 @@ +function varargout=xmlwrite_xerces(varargin) +%XMLWRITE_XERCES Serialize an XML Document Object Model node using Xerces parser. +% xmlwrite_xerces(FILENAME,DOMNODE) serializes the DOMNODE to file FILENAME. +% +% The function xmlwrite_xerces is very similar the Matlab function xmlwrite +% but works directly with the XERCES java classes (written by Apache XML +% Project) instead of the XMLUtils class created by Mathworks. Xerces files +% are provided in standard MATLAB instalation and live in root\java\jarext +% directory. +% +% Written by A.Amaro (02-22-2007) and generously donated to xml_io_tools. +% This function is needed as a work-around for a bug in XMLUtils library +% which can not write CDATA SECTION nodes correctly. Also Xerces and +% XMLUtils libraries handle namespaces differently. +% +% Examples: +% % See xmlwrite examples this function have almost identical behavior. +% +% Advanced use: +% FILENAME can also be a URN, java.io.OutputStream or java.io.Writer object +% SOURCE can also be a SAX InputSource, JAXP Source, InputStream, or +% Reader object + +returnString = false; +if length(varargin)==1 + returnString = true; + result = java.io.StringWriter; + source = varargin{1}; +else + result = varargin{1}; + if ischar(result) + % Using the XERCES classes directly, is not needed to modify the + % filename string. So I have commented this next line + % result = F_xmlstringinput(result,false); + end + + source = varargin{2}; + if ischar(source) + source = F_xmlstringinput(source,true); + end +end + +% SERIALIZATION OF THE DOM DOCUMENT USING XERCES CLASSES DIRECTLY + +% 1) create the output format according to the document definitions +% and type +objOutputFormat = org.apache.xml.serialize.OutputFormat(source); +set(objOutputFormat,'Indenting','on'); + +% 2) create the output stream. In this case: an XML file +objFile = java.io.File(result); +objOutputStream = java.io.FileOutputStream(objFile); + +% 3) Create the Xerces Serializer object +objSerializer= org.apache.xml.serialize.XMLSerializer(objOutputStream,objOutputFormat); + +% 4) Serialize to the XML files +javaMethod('serialize',objSerializer,source); + +% 5) IMPORTANT! Delete the objects to liberate the XML file created +objOutputStream.close; + +if returnString + varargout{1}=char(result.toString); +end + +%% ======================================================================== + function out = F_xmlstringinput(xString,isFullSearch,varargin) +% The function F_xmlstringinput is a copy of the private function: +% 'xmlstringinput' that the original xmlwrite function uses. + +if isempty(xString) + error('Filename is empty'); +elseif ~isempty(findstr(xString,'://')) + %xString is already a URL, most likely prefaced by file:// or http:// + out = xString; + return; +end + +xPath=fileparts(xString); +if isempty(xPath) + if nargin<2 || isFullSearch + out = which(xString); + if isempty(out) + error('xml:FileNotFound','File %s not found',xString); + end + else + out = fullfile(pwd,xString); + end +else + out = xString; + if (nargin<2 || isFullSearch) && ~exist(xString,'file') + %search to see if xString exists when isFullSearch + error('xml:FileNotFound','File %s not found',xString); + end +end + +%Return as a URN +if strncmp(out,'\\',2) + % SAXON UNC filepaths need to look like file:///\\\server-name\ + out = ['file:///\',out]; +elseif strncmp(out,'/',1) + % SAXON UNIX filepaths need to look like file:///root/dir/dir + out = ['file://',out]; +else + % DOS filepaths need to look like file:///d:/foo/bar + out = ['file:///',strrep(out,'\','/')]; +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/worldToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/worldToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..8bb11eb8cfff82e0e805c07f7f22d5e81042b241 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/GOG/worldToImage.m @@ -0,0 +1,28 @@ +function [Xi Yi]=worldToImage(Xw,Yw,Zw,mR,mT,mInt,mGeo) + + + % /* convert from world coordinates to camera coordinates */ + x=[mR mT]*[Xw;Yw;Zw;1]; + xc = x(1); + yc = x(2); + zc = x(3); + + % /* convert from camera coordinates to undistorted sensor plane coordinates */ + Xu = mInt.mFocal * xc / zc; + Yu = mInt.mFocal * yc / zc; + + % /* convert from undistorted to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mInt.mKappa1); + % Xd=Xu; + % Yd=Yu; + + % Rusq=Xu*Xu+Yu*Yu; + % Ru=sqrt(Xu*Xu+Yu*Yu); + % Xd=Xu*(1+mInt.mKappa1*Rusq); + % Yd=Yu*(1+mInt.mKappa1*Rusq); + + + % /* convert from distorted sensor plane coordinates to image coordinates */ + Xi = Xd * mInt.mSx / mGeo.mDpx + mInt.mCx; + Yi = Yd / mGeo.mDpy + mInt.mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/Config.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/Config.txt new file mode 100644 index 0000000000000000000000000000000000000000..517c7188a127cba253c03fe36b92565006ac0010 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/Config.txt @@ -0,0 +1,41 @@ +################################################################################### +## Main Parameters for Hierarchical Dense Structures Revealing Based Tracker +################################################################################### +#VERSION +1 + +#INPUT_DATA_FILE_NAME +MVI_39771 + +#INPUT_VIDEO_FILE_PATH +imagelist.txt + +#INPUT_DETECTION_FILE_PATH +detections.txt + +#OUTPUT_TRAJECTORY_FILE_PATH +result\ + +#OUTPUT_SPEED_FILE_PATH +result\ + +#IMAGE_WIDTH +960 + +#IMAGE_HEIGHT +540 + +#TOTAL_FRAME_NUMBER +570 + +#CAR_MINIMAL_WIDTH +5 + +#CAR_MINIMAL_HEIGHT +5 + +#SEGMENT_SIZE_EACH_LAYER +10,4 + +#TRACK_KARY_LAYER +3 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphDecompose.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphDecompose.dll new file mode 100644 index 0000000000000000000000000000000000000000..947203fd1b7a55e21e1c2c1fa41e3a567ef79840 Binary files /dev/null and b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphDecompose.dll differ diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker.exe b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker.exe new file mode 100644 index 0000000000000000000000000000000000000000..0ec6a9a69417b64a453fe9ec6f2859b71743d370 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ab82defb6e74c0d176d6b6d365756b19a39a2e59d7d93b1957dc921955b69f2 +size 267776 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker.pdb b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker.pdb new file mode 100644 index 0000000000000000000000000000000000000000..a74dc28e5b8ad7e7ee702558f93d2bf24fa668e2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker.pdb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:caf5ff3a0e836591837acfcbdea5622a368e1e59a0227232d80ecffa0d85a741 +size 1977344 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker_Config.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker_Config.txt new file mode 100644 index 0000000000000000000000000000000000000000..44e448d33c3d3590e771df0d60519887f1a7f0dd --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/GraphMultiCarTracker_Config.txt @@ -0,0 +1,41 @@ +################################################################################### +## Main Parameters for Hierarchical Dense Structures Revealing Based Tracker +################################################################################### +#VERSION +1 + +#INPUT_DATA_FILE_NAME +Cloudy_MVI_39501 + +#INPUT_VIDEO_FILE_PATH +imagelist.txt + +#INPUT_DETECTION_FILE_PATH +F:\Vehicle-Experiment\Car-Debug\Results\Cloudy_MVI_39501_Det_FN_0_FP_0.txt + +#OUTPUT_TRAJECTORY_FILE_PATH +result\ + +#OUTPUT_SPEED_FILE_PATH +result\ + +#IMAGE_WIDTH +960 + +#IMAGE_HEIGHT +540 + +#TOTAL_FRAME_NUMBER +540 + +#CAR_MINIMAL_WIDTH +5 + +#CAR_MINIMAL_HEIGHT +5 + +#SEGMENT_SIZE_EACH_LAYER +10,3 + +#TRACK_KARY_LAYER +3 \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/imagelist.txt b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/imagelist.txt new file mode 100644 index 0000000000000000000000000000000000000000..bf09621f5048ccfe8a301334a0e81214999862ab --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/imagelist.txt @@ -0,0 +1,570 @@ +D:/DETRAC-Images/MVI_39771\img00001.jpg +D:/DETRAC-Images/MVI_39771\img00002.jpg +D:/DETRAC-Images/MVI_39771\img00003.jpg +D:/DETRAC-Images/MVI_39771\img00004.jpg +D:/DETRAC-Images/MVI_39771\img00005.jpg +D:/DETRAC-Images/MVI_39771\img00006.jpg +D:/DETRAC-Images/MVI_39771\img00007.jpg +D:/DETRAC-Images/MVI_39771\img00008.jpg +D:/DETRAC-Images/MVI_39771\img00009.jpg +D:/DETRAC-Images/MVI_39771\img00010.jpg +D:/DETRAC-Images/MVI_39771\img00011.jpg +D:/DETRAC-Images/MVI_39771\img00012.jpg +D:/DETRAC-Images/MVI_39771\img00013.jpg +D:/DETRAC-Images/MVI_39771\img00014.jpg +D:/DETRAC-Images/MVI_39771\img00015.jpg +D:/DETRAC-Images/MVI_39771\img00016.jpg +D:/DETRAC-Images/MVI_39771\img00017.jpg +D:/DETRAC-Images/MVI_39771\img00018.jpg +D:/DETRAC-Images/MVI_39771\img00019.jpg +D:/DETRAC-Images/MVI_39771\img00020.jpg +D:/DETRAC-Images/MVI_39771\img00021.jpg +D:/DETRAC-Images/MVI_39771\img00022.jpg +D:/DETRAC-Images/MVI_39771\img00023.jpg +D:/DETRAC-Images/MVI_39771\img00024.jpg +D:/DETRAC-Images/MVI_39771\img00025.jpg +D:/DETRAC-Images/MVI_39771\img00026.jpg +D:/DETRAC-Images/MVI_39771\img00027.jpg +D:/DETRAC-Images/MVI_39771\img00028.jpg +D:/DETRAC-Images/MVI_39771\img00029.jpg +D:/DETRAC-Images/MVI_39771\img00030.jpg +D:/DETRAC-Images/MVI_39771\img00031.jpg +D:/DETRAC-Images/MVI_39771\img00032.jpg +D:/DETRAC-Images/MVI_39771\img00033.jpg +D:/DETRAC-Images/MVI_39771\img00034.jpg +D:/DETRAC-Images/MVI_39771\img00035.jpg +D:/DETRAC-Images/MVI_39771\img00036.jpg +D:/DETRAC-Images/MVI_39771\img00037.jpg +D:/DETRAC-Images/MVI_39771\img00038.jpg +D:/DETRAC-Images/MVI_39771\img00039.jpg +D:/DETRAC-Images/MVI_39771\img00040.jpg +D:/DETRAC-Images/MVI_39771\img00041.jpg +D:/DETRAC-Images/MVI_39771\img00042.jpg +D:/DETRAC-Images/MVI_39771\img00043.jpg +D:/DETRAC-Images/MVI_39771\img00044.jpg +D:/DETRAC-Images/MVI_39771\img00045.jpg +D:/DETRAC-Images/MVI_39771\img00046.jpg +D:/DETRAC-Images/MVI_39771\img00047.jpg +D:/DETRAC-Images/MVI_39771\img00048.jpg +D:/DETRAC-Images/MVI_39771\img00049.jpg +D:/DETRAC-Images/MVI_39771\img00050.jpg +D:/DETRAC-Images/MVI_39771\img00051.jpg +D:/DETRAC-Images/MVI_39771\img00052.jpg +D:/DETRAC-Images/MVI_39771\img00053.jpg +D:/DETRAC-Images/MVI_39771\img00054.jpg +D:/DETRAC-Images/MVI_39771\img00055.jpg +D:/DETRAC-Images/MVI_39771\img00056.jpg +D:/DETRAC-Images/MVI_39771\img00057.jpg +D:/DETRAC-Images/MVI_39771\img00058.jpg +D:/DETRAC-Images/MVI_39771\img00059.jpg +D:/DETRAC-Images/MVI_39771\img00060.jpg +D:/DETRAC-Images/MVI_39771\img00061.jpg +D:/DETRAC-Images/MVI_39771\img00062.jpg +D:/DETRAC-Images/MVI_39771\img00063.jpg +D:/DETRAC-Images/MVI_39771\img00064.jpg +D:/DETRAC-Images/MVI_39771\img00065.jpg +D:/DETRAC-Images/MVI_39771\img00066.jpg +D:/DETRAC-Images/MVI_39771\img00067.jpg +D:/DETRAC-Images/MVI_39771\img00068.jpg +D:/DETRAC-Images/MVI_39771\img00069.jpg +D:/DETRAC-Images/MVI_39771\img00070.jpg +D:/DETRAC-Images/MVI_39771\img00071.jpg +D:/DETRAC-Images/MVI_39771\img00072.jpg +D:/DETRAC-Images/MVI_39771\img00073.jpg +D:/DETRAC-Images/MVI_39771\img00074.jpg +D:/DETRAC-Images/MVI_39771\img00075.jpg +D:/DETRAC-Images/MVI_39771\img00076.jpg +D:/DETRAC-Images/MVI_39771\img00077.jpg +D:/DETRAC-Images/MVI_39771\img00078.jpg +D:/DETRAC-Images/MVI_39771\img00079.jpg +D:/DETRAC-Images/MVI_39771\img00080.jpg +D:/DETRAC-Images/MVI_39771\img00081.jpg +D:/DETRAC-Images/MVI_39771\img00082.jpg +D:/DETRAC-Images/MVI_39771\img00083.jpg +D:/DETRAC-Images/MVI_39771\img00084.jpg +D:/DETRAC-Images/MVI_39771\img00085.jpg +D:/DETRAC-Images/MVI_39771\img00086.jpg +D:/DETRAC-Images/MVI_39771\img00087.jpg +D:/DETRAC-Images/MVI_39771\img00088.jpg +D:/DETRAC-Images/MVI_39771\img00089.jpg +D:/DETRAC-Images/MVI_39771\img00090.jpg +D:/DETRAC-Images/MVI_39771\img00091.jpg +D:/DETRAC-Images/MVI_39771\img00092.jpg +D:/DETRAC-Images/MVI_39771\img00093.jpg +D:/DETRAC-Images/MVI_39771\img00094.jpg +D:/DETRAC-Images/MVI_39771\img00095.jpg +D:/DETRAC-Images/MVI_39771\img00096.jpg +D:/DETRAC-Images/MVI_39771\img00097.jpg +D:/DETRAC-Images/MVI_39771\img00098.jpg +D:/DETRAC-Images/MVI_39771\img00099.jpg +D:/DETRAC-Images/MVI_39771\img00100.jpg +D:/DETRAC-Images/MVI_39771\img00101.jpg +D:/DETRAC-Images/MVI_39771\img00102.jpg +D:/DETRAC-Images/MVI_39771\img00103.jpg +D:/DETRAC-Images/MVI_39771\img00104.jpg +D:/DETRAC-Images/MVI_39771\img00105.jpg +D:/DETRAC-Images/MVI_39771\img00106.jpg +D:/DETRAC-Images/MVI_39771\img00107.jpg +D:/DETRAC-Images/MVI_39771\img00108.jpg +D:/DETRAC-Images/MVI_39771\img00109.jpg +D:/DETRAC-Images/MVI_39771\img00110.jpg +D:/DETRAC-Images/MVI_39771\img00111.jpg +D:/DETRAC-Images/MVI_39771\img00112.jpg +D:/DETRAC-Images/MVI_39771\img00113.jpg +D:/DETRAC-Images/MVI_39771\img00114.jpg +D:/DETRAC-Images/MVI_39771\img00115.jpg +D:/DETRAC-Images/MVI_39771\img00116.jpg +D:/DETRAC-Images/MVI_39771\img00117.jpg +D:/DETRAC-Images/MVI_39771\img00118.jpg +D:/DETRAC-Images/MVI_39771\img00119.jpg +D:/DETRAC-Images/MVI_39771\img00120.jpg +D:/DETRAC-Images/MVI_39771\img00121.jpg +D:/DETRAC-Images/MVI_39771\img00122.jpg +D:/DETRAC-Images/MVI_39771\img00123.jpg +D:/DETRAC-Images/MVI_39771\img00124.jpg +D:/DETRAC-Images/MVI_39771\img00125.jpg +D:/DETRAC-Images/MVI_39771\img00126.jpg +D:/DETRAC-Images/MVI_39771\img00127.jpg +D:/DETRAC-Images/MVI_39771\img00128.jpg +D:/DETRAC-Images/MVI_39771\img00129.jpg +D:/DETRAC-Images/MVI_39771\img00130.jpg +D:/DETRAC-Images/MVI_39771\img00131.jpg +D:/DETRAC-Images/MVI_39771\img00132.jpg +D:/DETRAC-Images/MVI_39771\img00133.jpg +D:/DETRAC-Images/MVI_39771\img00134.jpg +D:/DETRAC-Images/MVI_39771\img00135.jpg +D:/DETRAC-Images/MVI_39771\img00136.jpg +D:/DETRAC-Images/MVI_39771\img00137.jpg +D:/DETRAC-Images/MVI_39771\img00138.jpg +D:/DETRAC-Images/MVI_39771\img00139.jpg +D:/DETRAC-Images/MVI_39771\img00140.jpg +D:/DETRAC-Images/MVI_39771\img00141.jpg +D:/DETRAC-Images/MVI_39771\img00142.jpg +D:/DETRAC-Images/MVI_39771\img00143.jpg +D:/DETRAC-Images/MVI_39771\img00144.jpg +D:/DETRAC-Images/MVI_39771\img00145.jpg +D:/DETRAC-Images/MVI_39771\img00146.jpg +D:/DETRAC-Images/MVI_39771\img00147.jpg +D:/DETRAC-Images/MVI_39771\img00148.jpg +D:/DETRAC-Images/MVI_39771\img00149.jpg +D:/DETRAC-Images/MVI_39771\img00150.jpg +D:/DETRAC-Images/MVI_39771\img00151.jpg +D:/DETRAC-Images/MVI_39771\img00152.jpg +D:/DETRAC-Images/MVI_39771\img00153.jpg +D:/DETRAC-Images/MVI_39771\img00154.jpg +D:/DETRAC-Images/MVI_39771\img00155.jpg +D:/DETRAC-Images/MVI_39771\img00156.jpg +D:/DETRAC-Images/MVI_39771\img00157.jpg +D:/DETRAC-Images/MVI_39771\img00158.jpg +D:/DETRAC-Images/MVI_39771\img00159.jpg +D:/DETRAC-Images/MVI_39771\img00160.jpg +D:/DETRAC-Images/MVI_39771\img00161.jpg +D:/DETRAC-Images/MVI_39771\img00162.jpg +D:/DETRAC-Images/MVI_39771\img00163.jpg +D:/DETRAC-Images/MVI_39771\img00164.jpg +D:/DETRAC-Images/MVI_39771\img00165.jpg +D:/DETRAC-Images/MVI_39771\img00166.jpg +D:/DETRAC-Images/MVI_39771\img00167.jpg +D:/DETRAC-Images/MVI_39771\img00168.jpg +D:/DETRAC-Images/MVI_39771\img00169.jpg +D:/DETRAC-Images/MVI_39771\img00170.jpg +D:/DETRAC-Images/MVI_39771\img00171.jpg +D:/DETRAC-Images/MVI_39771\img00172.jpg +D:/DETRAC-Images/MVI_39771\img00173.jpg +D:/DETRAC-Images/MVI_39771\img00174.jpg +D:/DETRAC-Images/MVI_39771\img00175.jpg +D:/DETRAC-Images/MVI_39771\img00176.jpg +D:/DETRAC-Images/MVI_39771\img00177.jpg +D:/DETRAC-Images/MVI_39771\img00178.jpg +D:/DETRAC-Images/MVI_39771\img00179.jpg +D:/DETRAC-Images/MVI_39771\img00180.jpg +D:/DETRAC-Images/MVI_39771\img00181.jpg +D:/DETRAC-Images/MVI_39771\img00182.jpg +D:/DETRAC-Images/MVI_39771\img00183.jpg +D:/DETRAC-Images/MVI_39771\img00184.jpg +D:/DETRAC-Images/MVI_39771\img00185.jpg +D:/DETRAC-Images/MVI_39771\img00186.jpg +D:/DETRAC-Images/MVI_39771\img00187.jpg +D:/DETRAC-Images/MVI_39771\img00188.jpg +D:/DETRAC-Images/MVI_39771\img00189.jpg +D:/DETRAC-Images/MVI_39771\img00190.jpg +D:/DETRAC-Images/MVI_39771\img00191.jpg +D:/DETRAC-Images/MVI_39771\img00192.jpg +D:/DETRAC-Images/MVI_39771\img00193.jpg +D:/DETRAC-Images/MVI_39771\img00194.jpg +D:/DETRAC-Images/MVI_39771\img00195.jpg +D:/DETRAC-Images/MVI_39771\img00196.jpg +D:/DETRAC-Images/MVI_39771\img00197.jpg +D:/DETRAC-Images/MVI_39771\img00198.jpg +D:/DETRAC-Images/MVI_39771\img00199.jpg +D:/DETRAC-Images/MVI_39771\img00200.jpg +D:/DETRAC-Images/MVI_39771\img00201.jpg +D:/DETRAC-Images/MVI_39771\img00202.jpg +D:/DETRAC-Images/MVI_39771\img00203.jpg +D:/DETRAC-Images/MVI_39771\img00204.jpg +D:/DETRAC-Images/MVI_39771\img00205.jpg +D:/DETRAC-Images/MVI_39771\img00206.jpg +D:/DETRAC-Images/MVI_39771\img00207.jpg +D:/DETRAC-Images/MVI_39771\img00208.jpg +D:/DETRAC-Images/MVI_39771\img00209.jpg +D:/DETRAC-Images/MVI_39771\img00210.jpg +D:/DETRAC-Images/MVI_39771\img00211.jpg +D:/DETRAC-Images/MVI_39771\img00212.jpg +D:/DETRAC-Images/MVI_39771\img00213.jpg +D:/DETRAC-Images/MVI_39771\img00214.jpg +D:/DETRAC-Images/MVI_39771\img00215.jpg +D:/DETRAC-Images/MVI_39771\img00216.jpg +D:/DETRAC-Images/MVI_39771\img00217.jpg +D:/DETRAC-Images/MVI_39771\img00218.jpg +D:/DETRAC-Images/MVI_39771\img00219.jpg +D:/DETRAC-Images/MVI_39771\img00220.jpg +D:/DETRAC-Images/MVI_39771\img00221.jpg +D:/DETRAC-Images/MVI_39771\img00222.jpg +D:/DETRAC-Images/MVI_39771\img00223.jpg +D:/DETRAC-Images/MVI_39771\img00224.jpg +D:/DETRAC-Images/MVI_39771\img00225.jpg +D:/DETRAC-Images/MVI_39771\img00226.jpg +D:/DETRAC-Images/MVI_39771\img00227.jpg +D:/DETRAC-Images/MVI_39771\img00228.jpg +D:/DETRAC-Images/MVI_39771\img00229.jpg +D:/DETRAC-Images/MVI_39771\img00230.jpg +D:/DETRAC-Images/MVI_39771\img00231.jpg +D:/DETRAC-Images/MVI_39771\img00232.jpg +D:/DETRAC-Images/MVI_39771\img00233.jpg +D:/DETRAC-Images/MVI_39771\img00234.jpg +D:/DETRAC-Images/MVI_39771\img00235.jpg +D:/DETRAC-Images/MVI_39771\img00236.jpg +D:/DETRAC-Images/MVI_39771\img00237.jpg +D:/DETRAC-Images/MVI_39771\img00238.jpg +D:/DETRAC-Images/MVI_39771\img00239.jpg +D:/DETRAC-Images/MVI_39771\img00240.jpg +D:/DETRAC-Images/MVI_39771\img00241.jpg +D:/DETRAC-Images/MVI_39771\img00242.jpg +D:/DETRAC-Images/MVI_39771\img00243.jpg +D:/DETRAC-Images/MVI_39771\img00244.jpg +D:/DETRAC-Images/MVI_39771\img00245.jpg +D:/DETRAC-Images/MVI_39771\img00246.jpg +D:/DETRAC-Images/MVI_39771\img00247.jpg +D:/DETRAC-Images/MVI_39771\img00248.jpg +D:/DETRAC-Images/MVI_39771\img00249.jpg +D:/DETRAC-Images/MVI_39771\img00250.jpg +D:/DETRAC-Images/MVI_39771\img00251.jpg +D:/DETRAC-Images/MVI_39771\img00252.jpg +D:/DETRAC-Images/MVI_39771\img00253.jpg +D:/DETRAC-Images/MVI_39771\img00254.jpg +D:/DETRAC-Images/MVI_39771\img00255.jpg +D:/DETRAC-Images/MVI_39771\img00256.jpg +D:/DETRAC-Images/MVI_39771\img00257.jpg +D:/DETRAC-Images/MVI_39771\img00258.jpg +D:/DETRAC-Images/MVI_39771\img00259.jpg +D:/DETRAC-Images/MVI_39771\img00260.jpg +D:/DETRAC-Images/MVI_39771\img00261.jpg +D:/DETRAC-Images/MVI_39771\img00262.jpg +D:/DETRAC-Images/MVI_39771\img00263.jpg +D:/DETRAC-Images/MVI_39771\img00264.jpg +D:/DETRAC-Images/MVI_39771\img00265.jpg +D:/DETRAC-Images/MVI_39771\img00266.jpg +D:/DETRAC-Images/MVI_39771\img00267.jpg +D:/DETRAC-Images/MVI_39771\img00268.jpg +D:/DETRAC-Images/MVI_39771\img00269.jpg +D:/DETRAC-Images/MVI_39771\img00270.jpg +D:/DETRAC-Images/MVI_39771\img00271.jpg +D:/DETRAC-Images/MVI_39771\img00272.jpg +D:/DETRAC-Images/MVI_39771\img00273.jpg +D:/DETRAC-Images/MVI_39771\img00274.jpg +D:/DETRAC-Images/MVI_39771\img00275.jpg +D:/DETRAC-Images/MVI_39771\img00276.jpg +D:/DETRAC-Images/MVI_39771\img00277.jpg +D:/DETRAC-Images/MVI_39771\img00278.jpg +D:/DETRAC-Images/MVI_39771\img00279.jpg +D:/DETRAC-Images/MVI_39771\img00280.jpg +D:/DETRAC-Images/MVI_39771\img00281.jpg +D:/DETRAC-Images/MVI_39771\img00282.jpg +D:/DETRAC-Images/MVI_39771\img00283.jpg +D:/DETRAC-Images/MVI_39771\img00284.jpg +D:/DETRAC-Images/MVI_39771\img00285.jpg +D:/DETRAC-Images/MVI_39771\img00286.jpg +D:/DETRAC-Images/MVI_39771\img00287.jpg +D:/DETRAC-Images/MVI_39771\img00288.jpg +D:/DETRAC-Images/MVI_39771\img00289.jpg +D:/DETRAC-Images/MVI_39771\img00290.jpg +D:/DETRAC-Images/MVI_39771\img00291.jpg +D:/DETRAC-Images/MVI_39771\img00292.jpg +D:/DETRAC-Images/MVI_39771\img00293.jpg +D:/DETRAC-Images/MVI_39771\img00294.jpg +D:/DETRAC-Images/MVI_39771\img00295.jpg +D:/DETRAC-Images/MVI_39771\img00296.jpg +D:/DETRAC-Images/MVI_39771\img00297.jpg +D:/DETRAC-Images/MVI_39771\img00298.jpg +D:/DETRAC-Images/MVI_39771\img00299.jpg +D:/DETRAC-Images/MVI_39771\img00300.jpg +D:/DETRAC-Images/MVI_39771\img00301.jpg +D:/DETRAC-Images/MVI_39771\img00302.jpg +D:/DETRAC-Images/MVI_39771\img00303.jpg +D:/DETRAC-Images/MVI_39771\img00304.jpg +D:/DETRAC-Images/MVI_39771\img00305.jpg +D:/DETRAC-Images/MVI_39771\img00306.jpg +D:/DETRAC-Images/MVI_39771\img00307.jpg +D:/DETRAC-Images/MVI_39771\img00308.jpg +D:/DETRAC-Images/MVI_39771\img00309.jpg +D:/DETRAC-Images/MVI_39771\img00310.jpg +D:/DETRAC-Images/MVI_39771\img00311.jpg +D:/DETRAC-Images/MVI_39771\img00312.jpg +D:/DETRAC-Images/MVI_39771\img00313.jpg +D:/DETRAC-Images/MVI_39771\img00314.jpg +D:/DETRAC-Images/MVI_39771\img00315.jpg +D:/DETRAC-Images/MVI_39771\img00316.jpg +D:/DETRAC-Images/MVI_39771\img00317.jpg +D:/DETRAC-Images/MVI_39771\img00318.jpg +D:/DETRAC-Images/MVI_39771\img00319.jpg +D:/DETRAC-Images/MVI_39771\img00320.jpg +D:/DETRAC-Images/MVI_39771\img00321.jpg +D:/DETRAC-Images/MVI_39771\img00322.jpg +D:/DETRAC-Images/MVI_39771\img00323.jpg +D:/DETRAC-Images/MVI_39771\img00324.jpg +D:/DETRAC-Images/MVI_39771\img00325.jpg +D:/DETRAC-Images/MVI_39771\img00326.jpg +D:/DETRAC-Images/MVI_39771\img00327.jpg +D:/DETRAC-Images/MVI_39771\img00328.jpg +D:/DETRAC-Images/MVI_39771\img00329.jpg +D:/DETRAC-Images/MVI_39771\img00330.jpg +D:/DETRAC-Images/MVI_39771\img00331.jpg +D:/DETRAC-Images/MVI_39771\img00332.jpg +D:/DETRAC-Images/MVI_39771\img00333.jpg +D:/DETRAC-Images/MVI_39771\img00334.jpg +D:/DETRAC-Images/MVI_39771\img00335.jpg +D:/DETRAC-Images/MVI_39771\img00336.jpg +D:/DETRAC-Images/MVI_39771\img00337.jpg +D:/DETRAC-Images/MVI_39771\img00338.jpg +D:/DETRAC-Images/MVI_39771\img00339.jpg +D:/DETRAC-Images/MVI_39771\img00340.jpg +D:/DETRAC-Images/MVI_39771\img00341.jpg +D:/DETRAC-Images/MVI_39771\img00342.jpg +D:/DETRAC-Images/MVI_39771\img00343.jpg +D:/DETRAC-Images/MVI_39771\img00344.jpg +D:/DETRAC-Images/MVI_39771\img00345.jpg +D:/DETRAC-Images/MVI_39771\img00346.jpg +D:/DETRAC-Images/MVI_39771\img00347.jpg +D:/DETRAC-Images/MVI_39771\img00348.jpg +D:/DETRAC-Images/MVI_39771\img00349.jpg +D:/DETRAC-Images/MVI_39771\img00350.jpg +D:/DETRAC-Images/MVI_39771\img00351.jpg +D:/DETRAC-Images/MVI_39771\img00352.jpg +D:/DETRAC-Images/MVI_39771\img00353.jpg +D:/DETRAC-Images/MVI_39771\img00354.jpg +D:/DETRAC-Images/MVI_39771\img00355.jpg +D:/DETRAC-Images/MVI_39771\img00356.jpg +D:/DETRAC-Images/MVI_39771\img00357.jpg +D:/DETRAC-Images/MVI_39771\img00358.jpg +D:/DETRAC-Images/MVI_39771\img00359.jpg +D:/DETRAC-Images/MVI_39771\img00360.jpg +D:/DETRAC-Images/MVI_39771\img00361.jpg +D:/DETRAC-Images/MVI_39771\img00362.jpg +D:/DETRAC-Images/MVI_39771\img00363.jpg +D:/DETRAC-Images/MVI_39771\img00364.jpg +D:/DETRAC-Images/MVI_39771\img00365.jpg +D:/DETRAC-Images/MVI_39771\img00366.jpg +D:/DETRAC-Images/MVI_39771\img00367.jpg +D:/DETRAC-Images/MVI_39771\img00368.jpg +D:/DETRAC-Images/MVI_39771\img00369.jpg +D:/DETRAC-Images/MVI_39771\img00370.jpg +D:/DETRAC-Images/MVI_39771\img00371.jpg +D:/DETRAC-Images/MVI_39771\img00372.jpg +D:/DETRAC-Images/MVI_39771\img00373.jpg +D:/DETRAC-Images/MVI_39771\img00374.jpg +D:/DETRAC-Images/MVI_39771\img00375.jpg +D:/DETRAC-Images/MVI_39771\img00376.jpg +D:/DETRAC-Images/MVI_39771\img00377.jpg +D:/DETRAC-Images/MVI_39771\img00378.jpg +D:/DETRAC-Images/MVI_39771\img00379.jpg +D:/DETRAC-Images/MVI_39771\img00380.jpg +D:/DETRAC-Images/MVI_39771\img00381.jpg +D:/DETRAC-Images/MVI_39771\img00382.jpg +D:/DETRAC-Images/MVI_39771\img00383.jpg +D:/DETRAC-Images/MVI_39771\img00384.jpg +D:/DETRAC-Images/MVI_39771\img00385.jpg +D:/DETRAC-Images/MVI_39771\img00386.jpg +D:/DETRAC-Images/MVI_39771\img00387.jpg +D:/DETRAC-Images/MVI_39771\img00388.jpg +D:/DETRAC-Images/MVI_39771\img00389.jpg +D:/DETRAC-Images/MVI_39771\img00390.jpg +D:/DETRAC-Images/MVI_39771\img00391.jpg +D:/DETRAC-Images/MVI_39771\img00392.jpg +D:/DETRAC-Images/MVI_39771\img00393.jpg +D:/DETRAC-Images/MVI_39771\img00394.jpg +D:/DETRAC-Images/MVI_39771\img00395.jpg +D:/DETRAC-Images/MVI_39771\img00396.jpg +D:/DETRAC-Images/MVI_39771\img00397.jpg +D:/DETRAC-Images/MVI_39771\img00398.jpg +D:/DETRAC-Images/MVI_39771\img00399.jpg +D:/DETRAC-Images/MVI_39771\img00400.jpg +D:/DETRAC-Images/MVI_39771\img00401.jpg +D:/DETRAC-Images/MVI_39771\img00402.jpg +D:/DETRAC-Images/MVI_39771\img00403.jpg +D:/DETRAC-Images/MVI_39771\img00404.jpg +D:/DETRAC-Images/MVI_39771\img00405.jpg +D:/DETRAC-Images/MVI_39771\img00406.jpg +D:/DETRAC-Images/MVI_39771\img00407.jpg +D:/DETRAC-Images/MVI_39771\img00408.jpg +D:/DETRAC-Images/MVI_39771\img00409.jpg +D:/DETRAC-Images/MVI_39771\img00410.jpg +D:/DETRAC-Images/MVI_39771\img00411.jpg +D:/DETRAC-Images/MVI_39771\img00412.jpg +D:/DETRAC-Images/MVI_39771\img00413.jpg +D:/DETRAC-Images/MVI_39771\img00414.jpg +D:/DETRAC-Images/MVI_39771\img00415.jpg +D:/DETRAC-Images/MVI_39771\img00416.jpg +D:/DETRAC-Images/MVI_39771\img00417.jpg +D:/DETRAC-Images/MVI_39771\img00418.jpg +D:/DETRAC-Images/MVI_39771\img00419.jpg +D:/DETRAC-Images/MVI_39771\img00420.jpg +D:/DETRAC-Images/MVI_39771\img00421.jpg +D:/DETRAC-Images/MVI_39771\img00422.jpg +D:/DETRAC-Images/MVI_39771\img00423.jpg +D:/DETRAC-Images/MVI_39771\img00424.jpg +D:/DETRAC-Images/MVI_39771\img00425.jpg +D:/DETRAC-Images/MVI_39771\img00426.jpg +D:/DETRAC-Images/MVI_39771\img00427.jpg +D:/DETRAC-Images/MVI_39771\img00428.jpg +D:/DETRAC-Images/MVI_39771\img00429.jpg +D:/DETRAC-Images/MVI_39771\img00430.jpg +D:/DETRAC-Images/MVI_39771\img00431.jpg +D:/DETRAC-Images/MVI_39771\img00432.jpg +D:/DETRAC-Images/MVI_39771\img00433.jpg +D:/DETRAC-Images/MVI_39771\img00434.jpg +D:/DETRAC-Images/MVI_39771\img00435.jpg +D:/DETRAC-Images/MVI_39771\img00436.jpg +D:/DETRAC-Images/MVI_39771\img00437.jpg +D:/DETRAC-Images/MVI_39771\img00438.jpg +D:/DETRAC-Images/MVI_39771\img00439.jpg +D:/DETRAC-Images/MVI_39771\img00440.jpg +D:/DETRAC-Images/MVI_39771\img00441.jpg +D:/DETRAC-Images/MVI_39771\img00442.jpg +D:/DETRAC-Images/MVI_39771\img00443.jpg +D:/DETRAC-Images/MVI_39771\img00444.jpg +D:/DETRAC-Images/MVI_39771\img00445.jpg +D:/DETRAC-Images/MVI_39771\img00446.jpg +D:/DETRAC-Images/MVI_39771\img00447.jpg +D:/DETRAC-Images/MVI_39771\img00448.jpg +D:/DETRAC-Images/MVI_39771\img00449.jpg +D:/DETRAC-Images/MVI_39771\img00450.jpg +D:/DETRAC-Images/MVI_39771\img00451.jpg +D:/DETRAC-Images/MVI_39771\img00452.jpg +D:/DETRAC-Images/MVI_39771\img00453.jpg +D:/DETRAC-Images/MVI_39771\img00454.jpg +D:/DETRAC-Images/MVI_39771\img00455.jpg +D:/DETRAC-Images/MVI_39771\img00456.jpg +D:/DETRAC-Images/MVI_39771\img00457.jpg +D:/DETRAC-Images/MVI_39771\img00458.jpg +D:/DETRAC-Images/MVI_39771\img00459.jpg +D:/DETRAC-Images/MVI_39771\img00460.jpg +D:/DETRAC-Images/MVI_39771\img00461.jpg +D:/DETRAC-Images/MVI_39771\img00462.jpg +D:/DETRAC-Images/MVI_39771\img00463.jpg +D:/DETRAC-Images/MVI_39771\img00464.jpg +D:/DETRAC-Images/MVI_39771\img00465.jpg +D:/DETRAC-Images/MVI_39771\img00466.jpg +D:/DETRAC-Images/MVI_39771\img00467.jpg +D:/DETRAC-Images/MVI_39771\img00468.jpg +D:/DETRAC-Images/MVI_39771\img00469.jpg +D:/DETRAC-Images/MVI_39771\img00470.jpg +D:/DETRAC-Images/MVI_39771\img00471.jpg +D:/DETRAC-Images/MVI_39771\img00472.jpg +D:/DETRAC-Images/MVI_39771\img00473.jpg +D:/DETRAC-Images/MVI_39771\img00474.jpg +D:/DETRAC-Images/MVI_39771\img00475.jpg +D:/DETRAC-Images/MVI_39771\img00476.jpg +D:/DETRAC-Images/MVI_39771\img00477.jpg +D:/DETRAC-Images/MVI_39771\img00478.jpg +D:/DETRAC-Images/MVI_39771\img00479.jpg +D:/DETRAC-Images/MVI_39771\img00480.jpg +D:/DETRAC-Images/MVI_39771\img00481.jpg +D:/DETRAC-Images/MVI_39771\img00482.jpg +D:/DETRAC-Images/MVI_39771\img00483.jpg +D:/DETRAC-Images/MVI_39771\img00484.jpg +D:/DETRAC-Images/MVI_39771\img00485.jpg +D:/DETRAC-Images/MVI_39771\img00486.jpg +D:/DETRAC-Images/MVI_39771\img00487.jpg +D:/DETRAC-Images/MVI_39771\img00488.jpg +D:/DETRAC-Images/MVI_39771\img00489.jpg +D:/DETRAC-Images/MVI_39771\img00490.jpg +D:/DETRAC-Images/MVI_39771\img00491.jpg +D:/DETRAC-Images/MVI_39771\img00492.jpg +D:/DETRAC-Images/MVI_39771\img00493.jpg +D:/DETRAC-Images/MVI_39771\img00494.jpg +D:/DETRAC-Images/MVI_39771\img00495.jpg +D:/DETRAC-Images/MVI_39771\img00496.jpg +D:/DETRAC-Images/MVI_39771\img00497.jpg +D:/DETRAC-Images/MVI_39771\img00498.jpg +D:/DETRAC-Images/MVI_39771\img00499.jpg +D:/DETRAC-Images/MVI_39771\img00500.jpg +D:/DETRAC-Images/MVI_39771\img00501.jpg +D:/DETRAC-Images/MVI_39771\img00502.jpg +D:/DETRAC-Images/MVI_39771\img00503.jpg +D:/DETRAC-Images/MVI_39771\img00504.jpg +D:/DETRAC-Images/MVI_39771\img00505.jpg +D:/DETRAC-Images/MVI_39771\img00506.jpg +D:/DETRAC-Images/MVI_39771\img00507.jpg +D:/DETRAC-Images/MVI_39771\img00508.jpg +D:/DETRAC-Images/MVI_39771\img00509.jpg +D:/DETRAC-Images/MVI_39771\img00510.jpg +D:/DETRAC-Images/MVI_39771\img00511.jpg +D:/DETRAC-Images/MVI_39771\img00512.jpg +D:/DETRAC-Images/MVI_39771\img00513.jpg +D:/DETRAC-Images/MVI_39771\img00514.jpg +D:/DETRAC-Images/MVI_39771\img00515.jpg +D:/DETRAC-Images/MVI_39771\img00516.jpg +D:/DETRAC-Images/MVI_39771\img00517.jpg +D:/DETRAC-Images/MVI_39771\img00518.jpg +D:/DETRAC-Images/MVI_39771\img00519.jpg +D:/DETRAC-Images/MVI_39771\img00520.jpg +D:/DETRAC-Images/MVI_39771\img00521.jpg +D:/DETRAC-Images/MVI_39771\img00522.jpg +D:/DETRAC-Images/MVI_39771\img00523.jpg +D:/DETRAC-Images/MVI_39771\img00524.jpg +D:/DETRAC-Images/MVI_39771\img00525.jpg +D:/DETRAC-Images/MVI_39771\img00526.jpg +D:/DETRAC-Images/MVI_39771\img00527.jpg +D:/DETRAC-Images/MVI_39771\img00528.jpg +D:/DETRAC-Images/MVI_39771\img00529.jpg +D:/DETRAC-Images/MVI_39771\img00530.jpg +D:/DETRAC-Images/MVI_39771\img00531.jpg +D:/DETRAC-Images/MVI_39771\img00532.jpg +D:/DETRAC-Images/MVI_39771\img00533.jpg +D:/DETRAC-Images/MVI_39771\img00534.jpg +D:/DETRAC-Images/MVI_39771\img00535.jpg +D:/DETRAC-Images/MVI_39771\img00536.jpg +D:/DETRAC-Images/MVI_39771\img00537.jpg +D:/DETRAC-Images/MVI_39771\img00538.jpg +D:/DETRAC-Images/MVI_39771\img00539.jpg +D:/DETRAC-Images/MVI_39771\img00540.jpg +D:/DETRAC-Images/MVI_39771\img00541.jpg +D:/DETRAC-Images/MVI_39771\img00542.jpg +D:/DETRAC-Images/MVI_39771\img00543.jpg +D:/DETRAC-Images/MVI_39771\img00544.jpg +D:/DETRAC-Images/MVI_39771\img00545.jpg +D:/DETRAC-Images/MVI_39771\img00546.jpg +D:/DETRAC-Images/MVI_39771\img00547.jpg +D:/DETRAC-Images/MVI_39771\img00548.jpg +D:/DETRAC-Images/MVI_39771\img00549.jpg +D:/DETRAC-Images/MVI_39771\img00550.jpg +D:/DETRAC-Images/MVI_39771\img00551.jpg +D:/DETRAC-Images/MVI_39771\img00552.jpg +D:/DETRAC-Images/MVI_39771\img00553.jpg +D:/DETRAC-Images/MVI_39771\img00554.jpg +D:/DETRAC-Images/MVI_39771\img00555.jpg +D:/DETRAC-Images/MVI_39771\img00556.jpg +D:/DETRAC-Images/MVI_39771\img00557.jpg +D:/DETRAC-Images/MVI_39771\img00558.jpg +D:/DETRAC-Images/MVI_39771\img00559.jpg +D:/DETRAC-Images/MVI_39771\img00560.jpg +D:/DETRAC-Images/MVI_39771\img00561.jpg +D:/DETRAC-Images/MVI_39771\img00562.jpg +D:/DETRAC-Images/MVI_39771\img00563.jpg +D:/DETRAC-Images/MVI_39771\img00564.jpg +D:/DETRAC-Images/MVI_39771\img00565.jpg +D:/DETRAC-Images/MVI_39771\img00566.jpg +D:/DETRAC-Images/MVI_39771\img00567.jpg +D:/DETRAC-Images/MVI_39771\img00568.jpg +D:/DETRAC-Images/MVI_39771\img00569.jpg +D:/DETRAC-Images/MVI_39771\img00570.jpg diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_core231.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_core231.dll new file mode 100644 index 0000000000000000000000000000000000000000..8d27aec7c9932312268f2380b3e21567977ad4f7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_core231.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4790ab9e72c09fda1b02caa0543b0d85ce17e0e2d6543a8a7900f46d7f66a534 +size 2090496 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_highgui231.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_highgui231.dll new file mode 100644 index 0000000000000000000000000000000000000000..4be83695db0ae82dba7a98df98a78c8303dabdbb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_highgui231.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d9706d3a4979b004dc384952db4c3e4273547e56e2336b3c01fc43f94eae6d7 +size 1122816 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_imgproc231.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_imgproc231.dll new file mode 100644 index 0000000000000000000000000000000000000000..0e84c47773aa96433bd3ad3b5a3caff17e73d9c5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/opencv_imgproc231.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ea5b40cbc3e52c4112ffae6c82db4ae9fdd496ed903a19682a9ad25512eaa62 +size 1896448 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/run_tracker.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/run_tracker.m new file mode 100644 index 0000000000000000000000000000000000000000..1df30b0d923ac4abb0c00fb82628ad8cf5892844 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/run_tracker.m @@ -0,0 +1,113 @@ +function [stateInfo, speed] = run_tracker(curSequence, baselinedetections) +% parameters +minCarWidth = 5; +minCarHeight = 5; +segSize = [10,4]; +nTry = 3; + +%% multi-object tracking +frameNums = curSequence.frameNums; +% create list file +listPath = 'imagelist.txt'; +fidlist = fopen(listPath, 'w'); +partsID = ismember(curSequence.imgFolder, '\'); +id = find(partsID==1); +newFolder = []; +for i = 1:length(id) + if(i == 1) + staId = 1; + endId = id(i)-1; + else + staId = id(i-1)+1; + endId = id(i)-1; + end + newFolder = cat(2, newFolder, cat(2, curSequence.imgFolder(staId:endId), '\\')); +end +for k = frameNums + fprintf(fidlist,[newFolder curSequence.imgFileFormat '\n'], k); +end +fclose(fidlist); +% configuration +fileIn = 'GraphMultiCarTracker_Config.txt'; +fileOut = 'Config.txt'; +fidin = fopen(fileIn,'r'); +fidout = fopen(fileOut,'w'); +nline = 0; +while(~feof(fidin)) + tline = fgetl(fidin); + nline = nline+1; + % change the parameter + if(nline == 8) + tline_ = curSequence.seqName; + fprintf(fidout,'%s\n', tline_); + elseif(nline == 14) + detPath = 'detections.txt'; % detection file + baselinedetections(:,5) = baselinedetections(:,5) + baselinedetections(:,3); + baselinedetections(:,6) = baselinedetections(:,6) + baselinedetections(:,4); + dlmwrite(detPath, baselinedetections); + tline_ = detPath; + fprintf(fidout,'%s\n', tline_); + elseif(nline == 29) + tline_ = num2str(numel(frameNums)); + fprintf(fidout,'%s\n', tline_); + elseif(nline == 32) + tline_ = num2str(minCarWidth); + fprintf(fidout,'%s\n', tline_); + elseif(nline == 35) + tline_ = num2str(minCarHeight); + fprintf(fidout,'%s\n', tline_); + elseif(nline == 38) + tline_ = [num2str(segSize(1)) ',' num2str(segSize(2))]; + fprintf(fidout,'%s\n', tline_); + elseif(nline == 41) + tline_ = num2str(nTry); + fprintf(fidout,'%s\n', tline_); + else + fprintf(fidout,'%s\n', tline); + end +end +fclose(fidin); +fclose(fidout); +% run the tracker +if verLessThan('matlab', '7.14.0') + [status, output] = system('GraphMultiCarTracker.exe Config.txt'); +else + [status, output] = system('GraphMultiCarTracker.exe Config.txt', ''); +end + +% save tracking results +stateInfo = []; +stateInfo.F = numel(curSequence.frameNums); +stateInfo.frameNums = curSequence.frameNums; +seqID = curSequence.seqName; +if(exist(['result\' seqID '_LX.txt'],'file')) + X = load(['result\' seqID '_LX.txt']); + Y = load(['result\' seqID '_LY.txt']); + W = load(['result\' seqID '_RX.txt']) - X; + H = load(['result\' seqID '_RY.txt']) - Y; + speed = load(['result\' seqID '_speed.txt']); + xc = X + W/2; + yc = Y + H/2; + % foot position + stateInfo.X = xc; + stateInfo.Y = yc+H/2; + stateInfo.H = W; + stateInfo.W = H; + stateInfo.Xgp = stateInfo.X; + stateInfo.Ygp = stateInfo.Y; + stateInfo.Xi = stateInfo.X; + stateInfo.Yi = stateInfo.Y; +else + stateInfo.X = []; + stateInfo.Y = []; + stateInfo.H = []; + stateInfo.W = []; + stateInfo.Xgp = stateInfo.X; + stateInfo.Ygp = stateInfo.Y; + stateInfo.Xi = stateInfo.X; + stateInfo.Yi = stateInfo.Y; + speed = 0; +end +% delete the temp files +delete('result\*.txt'); +delete('detections.txt'); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/tbb.dll b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/tbb.dll new file mode 100644 index 0000000000000000000000000000000000000000..4ef3d77561860ec74c45be9983f3cdc17c12760d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/tbb.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c7b24b0c7f8ccfd9ec2a2df0232aab3f079ed90bdd90fa9da6d01d12a5643c6 +size 278944 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/CLEAR_MOT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/CLEAR_MOT.m new file mode 100644 index 0000000000000000000000000000000000000000..4b3b89c60fccba78e14f8e6700cca0a5abbcf0ce --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/CLEAR_MOT.m @@ -0,0 +1,334 @@ +function [metrics metricsInfo]=CLEAR_MOT(gtInfo,stateInfo,options) +% compute CLEAR MOT and other metrics +% +% metrics contains the following +% [1] recall - recall = percentage of detected targets +% [2] precision - precision = percentage of correctly detected targets +% [3] FAR - number of false alarms per frame +% [4] GT - number of ground truth trajectories +% [5-7] MT, PT, ML - number of mostly tracked, partially tracked and mostly lost trajectories +% [8] falsepositives- number of false positives (FP) +% [9] missed - number of missed targets (FN) +% [10] idswitches - number of id switches (IDs) +% [11] FRA - number of fragmentations +% [12] MOTA - Multi-object tracking accuracy in [0,100] +% [13] MOTP - Multi-object tracking precision in [0,100] (3D) / [td,100] (2D) +% [14] MOTAL - Multi-object tracking accuracy in [0,100] with log10(idswitches) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +% default options: 2D +if nargin<3 + options.eval3d=0; % only bounding box overlap + options.td=.5; % threshold 50% +end + +if ~isfield(options,'td') + if options.eval3d + options.td=1000; + else + options.td=0.5; + end +end + +td=options.td; + +assert(length(gtInfo.frameNums)==length(stateInfo.frameNums), ... + 'Ground Truth and state must be of equal length'); +if(gtInfo.frameNums(1)~=stateInfo.frameNums(1)) + gtInfo.frameNums = gtInfo.frameNums + stateInfo.frameNums(1) - gtInfo.frameNums(1); +end +assert(all(gtInfo.frameNums==stateInfo.frameNums), ... + 'Ground Truth and state must contain equal frame numbers'); + +% check if all necessery info is available +if options.eval3d + assert(all(isfield(gtInfo,{'Xgp','Ygp'})), ... + 'Ground Truth Ground Plane coordinates needed for 3D evaluation'); + assert(all(isfield(stateInfo,{'Xgp','Ygp'})), ... + 'Ground Plane coordinates needed for 3D evaluation'); +else + assert(all(isfield(gtInfo,{'X','Y','W','H'})), ... + 'Ground Truth coordinates X,Y,W,H needed for 2D evaluation'); + assert(all(isfield(stateInfo,{'Xi','Yi','W','H'})), ... + 'State coordinates Xi,Yi,W,H needed for 2D evaluation'); + +end + +gtInd=~~gtInfo.X; +stInd=~~stateInfo.X; + +[Fgt Ngt]=size(gtInfo.X); +[F N]=size(stateInfo.X); + +aspectRatio=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% gtInfo.W=gtInfo.H*aspectRatio; + + +metricsInfo.names.long = {'Recall','Precision','False Alarm Rate', ... + 'GT Tracks','Mostly Tracked','Partially Tracked','Mostly Lost', ... + 'False Positives', 'False Negatives', 'ID Switches', 'Fragmentations', ... + 'MOTA','MOTP', 'MOTA Log'}; + +metricsInfo.names.short = {'Rcll','Prcn','FAR', ... + 'GT','MT','PT','ML', ... + 'FP', 'FN', 'IDs', 'FM', ... + 'MOTA','MOTP', 'MOTAL'}; + +metricsInfo.widths.long = [6 9 16 9 14 17 11 15 15 11 14 5 5 8]; +metricsInfo.widths.short = [5 5 5 3 3 3 3 4 4 3 3 5 5 5]; + +metricsInfo.format.long = {'.1f','.1f','.2f', ... + 'i','i','i','i', ... + 'i','i','i','i', ... + '.1f','.1f','.1f'}; + +metricsInfo.format.short=metricsInfo.format.long; + + +metrics=zeros(1,14); +metrics(9)=numel(find(gtInd)); % False Negatives (missed) +metrics(7)=Ngt; % Mostly Lost + +% nothing to be done, if state is empty +if ~N, return; end + +% global opt +% if options.eval3d && opt.mex +% [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% CLEAR_MOT_mex(gtInfo.Xgp', gtInfo.Ygp', stateInfo.Xgp', stateInfo.Ygp',options.td); +% +% % cd /home/aanton/diss/utils +% % [MOTA MOTP ma fpa mmea idsw missed falsepositives idswitches at afp MT PT ML rc pc faf FM MOTAL alld]= ... +% % CLEAR_MOT(gtInfo.Xgp, gtInfo.Ygp, stateInfo.Xgp, stateInfo.Ygp,options.td); +% % cd /home/aanton/visinf/projects/ongoing/contracking +% metrics=[rc*100, pc*100, faf, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FM, MOTA*100, MOTP*100, MOTAL*100]; +% metrics +% global gsi +% gsi=stateInfo; +% pause +% return; +% end + + +% mapping +M=zeros(F,Ngt); + +mme=zeros(1,F); % ID Switchtes (mismatches) +c=zeros(1,F); % matches found +fp=zeros(1,F); % false positives +m=zeros(1,F); % misses = false negatives +g=zeros(1,F); +d=zeros(F,Ngt); % all distances; +ious=Inf*ones(F,Ngt); % all overlaps + +matched=@matched2d; +if options.eval3d, matched=@matched3d; end + +alltracked=zeros(F,Ngt); +allfalsepos=zeros(F,N); + +for t=1:F + g(t)=numel(find(gtInd(t,:))); + + % mapping for current frame + if t>1 + mappings=find(M(t-1,:)); + for map=mappings + if gtInd(t,map) && stInd(t,M(t-1,map)) && matched(gtInfo,stateInfo,t,map,M(t-1,map),td*0.8) + M(t,map)=M(t-1,map); + end + end + end + + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + + if options.eval3d +% alldist=Inf*ones(Ngt,N); +% mindist=0; +% while mindist < td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 +% for o=GTsNotMapped +% GT=[gtInfo.Xgp(t,o) gtInfo.Ygp(t,o)]; +% for e=EsNotMapped +% E=[stateInfo.Xgp(t,e) stateInfo.Ygp(t,e)]; +% alldist(o,e)=norm(GT-E); +% end +% end +% [mindist, cind]=min(alldist(:)); +% if mindist <= td +% [u v]=ind2sub(size(alldist),cind); +% M(t,u)=v; +% alldist(:,v)=Inf; +% GTsNotMapped=find(~M(t,:) & gtInd(t,:)); +% EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); +% end +% end + + cost = zeros(numel(GTsNotMapped), numel(EsNotMapped)); + for o = 1:numel(GTsNotMapped) + GT = [gtInfo.Xgp(t,GTsNotMapped(o)), gtInfo.Ygp(t,GTsNotMapped(o))]; + for e = 1:numel(EsNotMapped) + E = [stateInfo.Xgp(t,EsNotMapped(e)), stateInfo.Ygp(t,EsNotMapped(e))]; + cost(o,e)=norm(GT-E); + end + end + cost(cost > td) = Inf; + assignLabel = munkres(cost); + for i = 1:numel(assignLabel) + if(assignLabel(i)) + M(t, GTsNotMapped(i)) = EsNotMapped(assignLabel(i)); + end + end + + else + allisects=zeros(Ngt,N); maxisect=Inf; + + while maxisect > td && numel(GTsNotMapped)>0 && numel(EsNotMapped)>0 + for o=GTsNotMapped + GT=[gtInfo.X(t,o)-gtInfo.W(t,o)/2 ... + gtInfo.Y(t,o)-gtInfo.H(t,o) ... + gtInfo.W(t,o) gtInfo.H(t,o) ]; + for e=EsNotMapped + E=[stateInfo.Xi(t,e)-stateInfo.W(t,e)/2 ... + stateInfo.Yi(t,e)-stateInfo.H(t,e) ... + stateInfo.W(t,e) stateInfo.H(t,e) ]; + allisects(o,e)=boxiou(GT(1),GT(2),GT(3),GT(4),E(1),E(2),E(3),E(4)); + end + end + [maxisect cind]=max(allisects(:)); + + if maxisect >= td + [u v]=ind2sub(size(allisects),cind); + M(t,u)=v; + allisects(:,v)=0; + GTsNotMapped=find(~M(t,:) & gtInd(t,:)); + EsNotMapped=setdiff(find(stInd(t,:)),M(t,:)); + end + + end + end + + curtracked=find(M(t,:)); + + + alltrackers=find(stInd(t,:)); + mappedtrackers=intersect(M(t,find(M(t,:))),alltrackers); + falsepositives=setdiff(alltrackers,mappedtrackers); + + alltracked(t,:)=M(t,:); + allfalsepos(t,1:length(falsepositives))=falsepositives; + + %% mismatch errors + if t>1 + for ct=curtracked + lastnotempty=find(M(1:t-1,ct),1,'last'); + if gtInd(t-1,ct) && ~isempty(lastnotempty) && M(t,ct)~=M(lastnotempty,ct) + mme(t)=mme(t)+1; + end + end + end + + c(t)=numel(curtracked); + for ct=curtracked + eid=M(t,ct); + if options.eval3d + d(t,ct)=norm([gtInfo.Xgp(t,ct) gtInfo.Ygp(t,ct)] - ... + [stateInfo.Xgp(t,eid) stateInfo.Ygp(t,eid)]); + else + gtLeft=gtInfo.X(t,ct)-gtInfo.W(t,ct)/2; + gtTop=gtInfo.Y(t,ct)-gtInfo.H(t,ct); + gtWidth=gtInfo.W(t,ct); gtHeight=gtInfo.H(t,ct); + + stLeft=stateInfo.Xi(t,eid)-stateInfo.W(t,eid)/2; + stTop=stateInfo.Yi(t,eid)-stateInfo.H(t,eid); + stWidth=stateInfo.W(t,eid); stHeight=stateInfo.H(t,eid); + ious(t,ct)=boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight); + end + end + + + fp(t)=numel(find(stInd(t,:)))-c(t); + m(t)=g(t)-c(t); + + +end + +missed=sum(m); +falsepositives=sum(fp); +idswitches=sum(mme); + +if options.eval3d + MOTP=(1-sum(sum(d))/sum(c)/td) * 100; % avg distance to [0,100] +else + MOTP=sum(ious(ious>=td & ious0)); + if(gtlength/gttotallength >= 0.8 && trlengtha/gttotallength < 0.2) + MTstatsa(i)=3; + elseif(t>=find(gtInd(:,i),1,'last') && trlengtha/gttotallength <= 0.8) + MTstatsa(i)=2; + elseif trlengtha/gttotallength >= 0.8 + MTstatsa(i)=1; + end +end +% MTstatsa +MT=numel(find(MTstatsa==1));PT=numel(find(MTstatsa==2));ML=numel(find(MTstatsa==3)); + +%% fragments +fr=zeros(1,Ngt); +for i=1:Ngt + b=alltracked(find(alltracked(:,i),1,'first'):find(alltracked(:,i),1,'last'),i); + b(~~b)=1; + fr(i)=numel(find(diff(b)==-1)); +end +FRA=sum(fr); + +assert(Ngt==MT+PT+ML,'Hmm... Not all tracks classified correctly.'); +metrics=[recall, precision, FAR, Ngt, MT, PT, ML, falsepositives, missed, idswitches, FRA, MOTA, MOTP, MOTAL]; +end + + + + +function ret=matched2d(gtInfo,stateInfo,t,map,mID,td) + gtLeft=gtInfo.X(t,map)-gtInfo.W(t,map)/2; + gtTop=gtInfo.Y(t,map)-gtInfo.H(t,map); + gtWidth=gtInfo.W(t,map); gtHeight=gtInfo.H(t,map); + + stLeft=stateInfo.Xi(t,mID)-stateInfo.W(t,mID)/2; + stTop=stateInfo.Yi(t,mID)-stateInfo.H(t,mID); + stWidth=stateInfo.W(t,mID); stHeight=stateInfo.H(t,mID); + + ret = boxiou(gtLeft,gtTop,gtWidth,gtHeight,stLeft,stTop,stWidth,stHeight) >= td; +end + + +function ret=matched3d(gtInfo,stateInfo,t,map,mID,td) + Xgt=gtInfo.Xgp(t,map); Ygt=gtInfo.Ygp(t,map); + X=stateInfo.Xgp(t,mID); Y=stateInfo.Ygp(t,mID); + ret=norm([Xgt Ygt]-[X Y])<=td; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/boxIntersect.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/boxIntersect.m new file mode 100644 index 0000000000000000000000000000000000000000..5a55b45131c36980ad641f838452967a12bf300b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/boxIntersect.m @@ -0,0 +1,24 @@ +function isect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2) +% A=[bboxleft1 bboxbottom1 abs(bboxright1-bboxleft1) abs(bboxbottom1-bboxup1)]; +% B=[bboxleft2 bboxbottom2 abs(bboxright2-bboxleft2) abs(bboxbottom2-bboxup2)]; +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% isect=rectint(A,B); +isect=0; + +hor= max(0,min(bboxright1,bboxright2) - max(bboxleft1,bboxleft2)); + +if ~hor, return; end +ver= max(0,min(bboxbottom1,bboxbottom2) - max(bboxup1,bboxup2)); +if ~ver, return; end + +isect = hor*ver; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/boxUnion.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/boxUnion.m new file mode 100644 index 0000000000000000000000000000000000000000..c5b8e06c5ea242199dbffa15e553ec07b626fab9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/boxUnion.m @@ -0,0 +1,24 @@ +function union=boxUnion(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2,isect) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +a1=bboxright1-bboxleft1; +b1=bboxbottom1-bboxup1; +a2=bboxright2-bboxleft2; +b2=bboxbottom2-bboxup2; +union=a1*b1+a2*b2; +if nargin>8 + bisect=isect; +else + bisect=boxIntersect(bboxleft1, bboxright1, bboxbottom1, bboxup1, bboxleft2, bboxright2, bboxbottom2, bboxup2); +end +union=union-bisect; + + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/boxiou.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/boxiou.m new file mode 100644 index 0000000000000000000000000000000000000000..395e5dc90d032ee2d7f3c9554148e56f908eeab5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/boxiou.m @@ -0,0 +1,21 @@ +function iou=boxiou(x1,y1,w1,h1,x2,y2,w2,h2) +% compute intersection over union of two bboxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + bisect=boxIntersect(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2); + iou=0; + if ~bisect, return; end + + bunion=boxUnion(x1,x1+w1,y1+h1,y1,x2,x2+w2,y2+h2,y2,bisect); + + assert(bunion>0,'something wrong with union computation'); + iou=bisect/bunion; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/distortedToUndistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/distortedToUndistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..6e62dfbd4271580faef309647e42784c11964e31 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/distortedToUndistortedImageCoord.m @@ -0,0 +1,15 @@ +function [Xfu Yfu]=distortedToUndistortedImageCoord (Xfd, Yfd, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xd = mDpx * (Xfd - mCx) / mSx; + Yd = mDpy * (Yfd - mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ + [Xu Yu]=distortedToUndistortedSensorCoord(Xd, Yd, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfu = Xu * mSx / mDpx + mCx; + Yfu = Yu / mDpy + mCy; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/distortedToUndistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/distortedToUndistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..14158bd36e686650ae77a8621b1ed3c4d56e298a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/distortedToUndistortedSensorCoord.m @@ -0,0 +1,6 @@ +function [Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mKappa1) +% /* convert from distorted to undistorted sensor plane coordinates */ + distortion_factor = 1 + mKappa1 * (Xd*Xd + Yd*Yd); + Xu = Xd * distortion_factor; + Yu = Yd * distortion_factor; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/getRotTrans.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/getRotTrans.m new file mode 100644 index 0000000000000000000000000000000000000000..725097d307f8d0b7a1d211e756f99d82d45ebe1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/getRotTrans.m @@ -0,0 +1,34 @@ +function [mR mT]=getRotTrans(camPar) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + %%% Rotation Translation %%% + mT=[camPar.mExt.mTx;camPar.mExt.mTy;camPar.mExt.mTz]; + sa = sin(camPar.mExt.mRx); + ca = cos(camPar.mExt.mRx); + sb = sin(camPar.mExt.mRy); + cb = cos(camPar.mExt.mRy); + sg = sin(camPar.mExt.mRz); + cg = cos(camPar.mExt.mRz); + + mR11 = cb * cg; + mR12 = cg * sa * sb - ca * sg; + mR13 = sa * sg + ca * cg * sb; + mR21 = cb * sg; + mR22 = sa * sb * sg + ca * cg; + mR23 = ca * sb * sg - cg * sa; + mR31 = -sb; + mR32 = cb * sa; + mR33 = ca * cb; + + mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/imageToWorld.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/imageToWorld.m new file mode 100644 index 0000000000000000000000000000000000000000..3919cb798acbbeec7f826c6ea524dee3c3035476 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/imageToWorld.m @@ -0,0 +1,62 @@ +function [Xw Yw Zw]=imageToWorld(Xi, Yi, camPar) + +mGeo=camPar.mGeo; +mExt=camPar.mExt; +mInt=camPar.mInt; + +mTx=mExt.mTx; +mTy=mExt.mTy; +mTz=mExt.mTz; + +mT=[mExt.mTx;mExt.mTy;mExt.mTz]; + +%% internal init +sa = sin(mExt.mRx); +ca = cos(mExt.mRx); +sb = sin(mExt.mRy); +cb = cos(mExt.mRy); +sg = sin(mExt.mRz); +cg = cos(mExt.mRz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + + + +% /* convert from image to distorted sensor coordinates */ +Xd = mGeo.mDpx * (Xi - mInt.mCx) / mInt.mSx; +Yd = mGeo.mDpy * (Yi - mInt.mCy); + +% /* convert from distorted sensor to undistorted sensor plane coordinates */ +[Xu Yu]=distortedToUndistortedSensorCoord (Xd, Yd, mInt.mKappa1); + +% /* calculate the corresponding xw and yw world coordinates */ +% /* (these equations were derived by simply inverting */ +% /* the perspective projection equations using Macsyma) */ +Zw=0; +common_denominator = ((mR11 * mR32 - mR12 * mR31) * Yu + ... + (mR22 * mR31 - mR21 * mR32) * Xu - ... + mInt.mFocal * mR11 * mR22 + mInt.mFocal * mR12 * mR21); + +Xw = (((mR12 * mR33 - mR13 * mR32) * Yu + ... + (mR23 * mR32 - mR22 * mR33) * Xu - ... + mInt.mFocal * mR12 * mR23 + mInt.mFocal * mR13 * mR22) * Zw + ... + (mR12 * mTz - mR32 * mTx) * Yu + ... + (mR32 * mTy - mR22 * mTz) * Xu - ... + mInt.mFocal * mR12 * mTy + mInt.mFocal * mR22 * mTx) / common_denominator; + +Yw = -(((mR11 * mR33 - mR13 * mR31) * Yu + ... + (mR23 * mR31 - mR21 * mR33) * Xu - ... + mInt.mFocal * mR11 * mR23 + mInt.mFocal * mR13 * mR21) * Zw + ... + (mR11 * mTz - mR31 * mTx) * Yu + ... + (mR31 * mTy - mR21 * mTz) * Xu - ... + mInt.mFocal * mR11 * mTy + mInt.mFocal * mR21 * mTx) / common_denominator; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/parseCameraParameters.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/parseCameraParameters.m new file mode 100644 index 0000000000000000000000000000000000000000..10baec4a50e7d06334ec9a16693a4ce178845580 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/parseCameraParameters.m @@ -0,0 +1,104 @@ +function camPar=parseCameraParameters(camconffile) +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +xDoc=xmlread(fullfile(camconffile)); + +width=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('width')); +height=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('height')); + +ncx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('ncx')); +nfx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('nfx')); +dx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dx')); +dy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dy')); +dpx=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpx')); +dpy=str2double(xDoc.getElementsByTagName('Geometry').item(0).getAttribute('dpy')); + +focal=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('focal')); +kappa1=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('kappa1')); +cx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cx')); +cy=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('cy')); +sx=str2double(xDoc.getElementsByTagName('Intrinsic').item(0).getAttribute('sx')); + +tx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tx')); +ty=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ty')); +tz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('tz')); +rx=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rx')); +ry=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('ry')); +rz=str2double(xDoc.getElementsByTagName('Extrinsic').item(0).getAttribute('rz')); + +mGeo.mImgWidth = width; +mGeo.mImgHeight = height; +mGeo.mNcx = ncx; +mGeo.mNfx = nfx; +mGeo.mDx = dx; +mGeo.mDy = dy; +mGeo.mDpx = dpx; +mGeo.mDpy = dpy; + + +%% intrinsic +mInt.mFocal = focal; +mInt.mKappa1 = kappa1; +mInt.mCx = cx; +mInt.mCy = cy; +mInt.mSx = sx; + +%% extrinsic +mExt.mTx = tx; +mExt.mTy = ty; +mExt.mTz = tz; +mExt.mRx = rx; +mExt.mRy = ry; +mExt.mRz = rz; + +%% inverted +mT=[tx;ty;tz]; +sa = sin(rx); +ca = cos(rx); +sb = sin(ry); +cb = cos(ry); +sg = sin(rz); +cg = cos(rz); + +mR11 = cb * cg; +mR12 = cg * sa * sb - ca * sg; +mR13 = sa * sg + ca * cg * sb; +mR21 = cb * sg; +mR22 = sa * sb * sg + ca * cg; +mR23 = ca * sb * sg - cg * sa; +mR31 = -sb; +mR32 = cb * sa; +mR33 = ca * cb; + +mR=[mR11 mR12 mR13; + mR21 mR22 mR23; + mR31 mR32 mR33]; + +transform=[mR mT;[0 0 0 1]]; +invtrans=inv(transform); +tx=invtrans(1,4);ty=invtrans(2,4);tz=invtrans(3,4); + +mExt.mTxi = tx; +mExt.mTyi = ty; +mExt.mTzi = tz; + +camPar.mExt=mExt; +camPar.mInt=mInt; +camPar.mGeo=mGeo; + +%% mkappa<0 +if kappa1<0 + warning('CAREFUL! kappa1 < 0, cam derivates are wrong!'); +end + +[camPar.mR camPar.mT]=getRotTrans(camPar); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/undistortedToDistortedImageCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/undistortedToDistortedImageCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..9c9f9a1382cfcbf25407f159a06cc73d4440c9a1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/undistortedToDistortedImageCoord.m @@ -0,0 +1,14 @@ +function [Xfd Yfd]=undistortedToDistortedImageCoord (Xfu, Yfu, mDpx, mDpy, mCx, mCy, mSx, mKappa1) + + +% /* convert from image to sensor coordinates */ + Xu = mDpx * (Xfu - mCx) / mSx; + Yu = mDpy * (Yfu - mCy); + +% /* convert from undistorted sensor to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord(Xu, Yu, mKappa1); + +% /* convert from sensor to image coordinates */ + Xfd = Xd * mSx / mDpx + mCx; + Yfd = Yd / mDpy + mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/undistortedToDistortedSensorCoord.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/undistortedToDistortedSensorCoord.m new file mode 100644 index 0000000000000000000000000000000000000000..b689d695a1a98a28a8ba414a7661fe9658d24403 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/undistortedToDistortedSensorCoord.m @@ -0,0 +1,67 @@ +function [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mKappa1) + +% global ifs elses + +if ((~Xu && ~Yu) || ~mKappa1) +% ifs(1)=ifs(1)+1; + Xd = Xu; + Yd = Yu; +else %% THIS ONE %% +% elses(1)=elses(1)+1; + Ru = sqrt(Xu*Xu + Yu*Yu); + + c = 1.0 / mKappa1; + d = -c * Ru; + + Q = c / 3; + R = -d / 2; + D = Q*Q*Q + R*R; + + if (D >= 0) %% THIS ONE %% +% ifs(2)=ifs(2)+1; + %/* one real root */ + D = sqrt(D); + if (R + D > 0) %% THIS ONE %% +% ifs(3)=ifs(3)+1; + S = (R + D)^ (1.0/3.0); + else +% elses(3)=elses(3)+1; + S = -(-R - D)^ (1.0/3.0); + end + if (R - D > 0) +% ifs(4)=ifs(4)+1; + T = (R - D)^(1.0/3.0); + else %% THIS ONE %% +% elses(4)=elses(4)+1; + T = -(D - R)^(1.0/3.0); + end + Rd = S + T; + + if (Rd < 0) + Rd = sqrt(-1.0 / (3 * mKappa1)); + % /*fprintf (stderr, "\nWarning: undistorted image point to distorted image point mapping limited by\n"); + % fprintf (stderr, " maximum barrel distortion radius of %lf\n", Rd); + % fprintf (stderr, " (Xu = %lf, Yu = %lf) -> (Xd = %lf, Yd = %lf)\n\n", Xu, Yu, Xu * Rd / Ru, Yu * Rd / Ru);*/ + end + else +% elses(2)=elses(2)+1; + % /* three real roots */ + D = sqrt(-D); + S = ( sqrt(R*R + D*D))^(1.0/3.0 ); + T = atan2(D, R) / 3; + sinT = sin(T); + cosT = cos(T); + + % /* the larger positive root is 2*S*cos(T) */ + % /* the smaller positive root is -S*cos(T) + SQRT(3)*S*sin(T) */ + % /* the negative root is -S*cos(T) - SQRT(3)*S*sin(T) */ + + Rd = -S * cosT + sqrt(3.0) * S * sinT; % /* use the smaller positive root */ + end + + lambda = Rd / Ru; + + Xd = Xu * lambda; + Yd = Yu * lambda; +end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/worldToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/worldToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..8bb11eb8cfff82e0e805c07f7f22d5e81042b241 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/camera/worldToImage.m @@ -0,0 +1,28 @@ +function [Xi Yi]=worldToImage(Xw,Yw,Zw,mR,mT,mInt,mGeo) + + + % /* convert from world coordinates to camera coordinates */ + x=[mR mT]*[Xw;Yw;Zw;1]; + xc = x(1); + yc = x(2); + zc = x(3); + + % /* convert from camera coordinates to undistorted sensor plane coordinates */ + Xu = mInt.mFocal * xc / zc; + Yu = mInt.mFocal * yc / zc; + + % /* convert from undistorted to distorted sensor plane coordinates */ + [Xd Yd]=undistortedToDistortedSensorCoord (Xu, Yu, mInt.mKappa1); + % Xd=Xu; + % Yd=Yu; + + % Rusq=Xu*Xu+Yu*Yu; + % Ru=sqrt(Xu*Xu+Yu*Yu); + % Xd=Xu*(1+mInt.mKappa1*Rusq); + % Yd=Yu*(1+mInt.mKappa1*Rusq); + + + % /* convert from distorted sensor plane coordinates to image coordinates */ + Xi = Xd * mInt.mSx / mGeo.mDpx + mInt.mCx; + Yi = Yd / mGeo.mDpy + mInt.mCy; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/checkInitSolution.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/checkInitSolution.m new file mode 100644 index 0000000000000000000000000000000000000000..2c804a3311ac0367686b89db9d6c9864a4856c0c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/checkInitSolution.m @@ -0,0 +1,22 @@ +function [Xinit Yinit]=checkInitSolution(Xinit,Yinit,F) +% check if initial solution is correct +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + assert(all(size(Xinit)==size(Yinit)), ... + 'X and Y are of different size in initial solution'); + + % pad with zeros if not enough frames + Finit=size(Xinit,1); + if FinitareaLimits(2))=0;Ygp(Ygp>areaLimits(4))=0; +Ygp(Xgp==0)=0; Xgp(Ygp==0)=0; + +allzeros=(Xgp == 0 | Ygp ==0); +gtInfo.X(allzeros)=0;gtInfo.Y(allzeros)=0; +gtInfo.W(allzeros)=0;gtInfo.H(allzeros)=0; +gtInfo.Xgp(allzeros)=0;gtInfo.Ygp(allzeros)=0; + +% now clean up zero columns +gtInfo=cleanGT(gtInfo); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/cutStateToTrackingArea.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/cutStateToTrackingArea.m new file mode 100644 index 0000000000000000000000000000000000000000..977d2e957af687926552ce27c94bcb207992f6b8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/cutStateToTrackingArea.m @@ -0,0 +1,28 @@ +function stateInfo=cutStateToTrackingArea(stateInfo) +% if we are tracking on ground plane +% remove all track segments outside tracking area +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo; + +X=stateInfo.X; Y=stateInfo.Y; +areaLimits=sceneInfo.trackingArea; + +X(XareaLimits(2))=0;Y(Y>areaLimits(4))=0; +Y(X==0)=0; X(Y==0)=0; + +% now clean up zero columns +[X Y stateInfo]=cleanState(X,Y,stateInfo); + +stateInfo.X=X; stateInfo.Y=Y; + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..9068d48fdf2e5ebc45546a2ea6631ec363810209 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayBBoxes.m @@ -0,0 +1,205 @@ +function displayBBoxes(sceneInfo,frameNums,X,Y,W,H,options) +% Draw bounding boxes on top of images +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% +[F,~]=size(X); + +ind=find(W); +aspectRatio=mean(H(ind)./W(ind)); + +%% if we want to display traces, lets compute average image +% or let's not... Doesn't look good, anyway + +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(1))]); +% avim=zeros(size(im)); +% avgF=1:5:min(500,F); +% avgnF=length(avgF); +% for t=avgF +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]); +% avim=avim+double(im)/avgnF; +% end +% avim=avim/255; + +global opt; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + al=0.5; + load(sceneInfo.bgMask); + immask=cat(3,bgmask,bgmask,bgmask); + + end + +for t=1:F + clf + im=double(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(t))]))/255; + + if options.hideBG && opt.cutToTA && isfield(sceneInfo,'bgMask') + imgray=rgb2gray(im); imgray=imgray+0.5; + imgray=cat(3,imgray,imgray,imgray); + im(immask)=al*im(immask)+(1-al)*(imgray(immask)); + end + + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % tracking area + if opt.track3d && opt.cutToTA + drawTALimits; + end + + + extar=find(X(t,:)); + % foot position + if options.displayDots + for id=extar + plot(X(t,id),Y(t,id),'.','color',getColorFromID(id),'MarkerSize',options.dotSize); + end + end + + % box + if options.displayBoxes + for id=extar + bleft=X(t,id)-W(t,id)/2; + bright=X(t,id)+W(t,id)/2; + btop=Y(t,id)-H(t,id); + bbottom=Y(t,id); +% line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',getColorFromID(id),'linewidth',options.boxLineWidth); + rectangle('Position',[bleft,btop,W(t,id),H(t,id)],'Curvature',[.3,.3*(W(t,id)/H(t,id))],'EdgeColor',getColorFromID(id),'linewidth',options.boxLineWidth); + end + end + + % ID + if options.displayID + for id=extar + tx=X(t,id); + ty=Y(t,id)-H(t,id)*2/3; % inside +% ty=Y(t,id)-H(t,id)-10; % on top + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',W(t,id)/2, 'FontUnits','pixels','FontWeight','bold'); + end + end + + % cropouts + if options.displayCropouts + bw=2; %border cropouts + + %% crop outs var sized + maxTar=30; + extarRed=extar(extar<=maxTar); % reducde +% crpImg=zeros(round(max(max(H))+5),round(sum(max(W))+5*bw),3); +% offset=1; +% offsets=round([1 cumsum(max(W))]); +% for id=extarRed +% % offsets(id)=offset; +% offset=offsets(id); +% bleft=round(X(t,id)-W(t,id)/2); +% bright=round(X(t,id)+W(t,id)/2); +% btop=round(Y(t,id)-H(t,id)); +% bbottom=round(Y(t,id)); +% +% ht=(bbottom-btop)+1;wt=(bright-bleft)+1; +% crpImg(1:ht,offset:offset+wt-1,:)=im(btop:bbottom,bleft:bright,:); +% % offset=offset+wt+bw; +% end + + %% crop outs fixed sized + uniH=min(60,round(sceneInfo.imgHeight/10)); uniW=round(uniH/aspectRatio); +% crpImg=zeros(round(uniH+bw),round(uniW*size(W,2)+bw*size(W,2)),3); % black + mxfac=.5; + crpImg=im(1:uniH,1:min(sceneInfo.imgWidth,round(uniW*size(W,2)+bw*size(W,2))),:)*mxfac; + crpImg=crpImg + (1-mxfac)*ones(size(crpImg)); % bleeched + for id=extarRed + offset=(id-1)*uniW + (id-1)*bw+1; + bleft=round(X(t,id)-W(t,id)/2); + bright=round(X(t,id)+W(t,id)/2); + btop=round(Y(t,id)-H(t,id)); + bbottom=round(Y(t,id)); + + [bleft bright btop bbottom]= ... + clampBBox(bleft, bright, btop, bbottom, sceneInfo.imgWidth, sceneInfo.imgHeight); + ht=uniH; + imres=imresize(im(btop:bbottom,bleft:bright,:),[uniH uniW]); + crpImg(1:ht,offset:offset+uniW-1,:)=imres; + + end + imshow(crpImg); + + for id=extarRed +% tx=offsets(id)+W(t,id)/2; + tx=id*uniW-uniW/2 + id*bw; + ty=30; % top + ty=size(crpImg,1)-10; % below + text(tx,ty,sprintf('%i',id),'color',getColorFromID(id), ... + 'HorizontalAlignment','center', ... + 'FontSize',uniW/2, 'FontUnits','pixels','FontWeight','bold'); % fixed size +% 'FontSize',mean(W(t,extarRed))/2, 'FontUnits','pixels','FontWeight','bold'); % var size + + end + if options.displayConnections + for id=extarRed + if t-find(X(:,id),1,'first')<5 + btop=round(Y(t,id)-H(t,id)); + offset=(id-1)*uniW + (id-1)*bw+1 + uniW/2; + line([X(t,id) offset],[btop uniH],'color',getColorFromID(id),'linestyle','-'); + end + end + end + end + + % show trace + if options.traceLength + for tracet=max(1,t-options.traceLength):max(1,t-1) + ipolpar=(t-tracet)/options.traceLength; % parameter [0,1] for color adjustment + + % pick color from tail +% if tracet==max(1,t-options.traceLength) +% im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,frameNums(tracet))]); +% end + + extarpast=find(X(tracet,:)); + % foot position + for id=extarpast + % plot(X(tracet,id),Y(tracet,id), ... + % '.','color',ipolpar*options.grey + (1-ipolpar)*getColorFromID(id),'MarkerSize',max(1,options.dotSize*(1-ipolpar))); + + + if W(tracet+1,id) + posx=round(max(1,X(t,id))); posx=min(sceneInfo.imgWidth,posx); + posy=round(max(1,Y(t,id))); posy=min(sceneInfo.imgHeight,posy); +% endcol=double(reshape(avim(posy,posx,:),1,3)); +% endcol=min(1,endcol); endcol=max(1,endcol); + endcol=options.grey; + line(X(tracet:tracet+1,id) ,Y(tracet:tracet+1,id), ... + 'color',ipolpar*endcol + (1-ipolpar)*getColorFromID(id),'linewidth',(1-ipolpar)*options.traceWidth+1); + end + + end + + end + end + + + pause(options.framePause) + + % save + if isfield(options,'outFolder'); + im2save=getframe(gcf); + im2save=im2save.cdata; + imwrite(im2save, fullfile(options.outFolder,sprintf('frame_%04d.jpg',frameNums(t)))); + end + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayDetectionBBoxes.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayDetectionBBoxes.m new file mode 100644 index 0000000000000000000000000000000000000000..85a14f52b9a012f72c0909b95491270609907826 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayDetectionBBoxes.m @@ -0,0 +1,81 @@ +function displayDetectionBBoxes(sceneInfo, detections) +% Display Detection Bounding Boxes +% +% Take scene information sceneInfo and +% an array of detections and display +% them on +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +reopenFig('Detections') + +F=size(detections,2); +assert(F==length(sceneInfo.frameNums), 'length of detections must be equal to the number of frames'); + +detcol=[.1 .2 .9]; +grey=.6*ones(1,3); +framePause=0.01; % pause between frames +% framePause=1; + +traceLength=10; % overlay data from past 10 frames +dotSize=20; +boxLineWidth=3; + +for t=1:F + clf + im=imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(t))]); + if (size(im,3)==1), im=repmat(im,[1 1 3]); end % greyscale + imshow(im,'Border','tight') + hold on + + % frame number + text(20,50,sprintf('%d',t),'FontSize',20); + + % foot position + for k=1:length(detections(t).xp) + plot(detections(t).xp(k),detections(t).yp(k),'.','color',detcol,'MarkerSize',dotSize*detections(t).sc(k)); + end + + % box + nboxes=length(detections(t).xp); + for id=1:nboxes + bleft=detections(t).bx(id); + bright=detections(t).bx(id)+detections(t).wd(id); + btop=detections(t).by(id); + bbottom=detections(t).by(id)+detections(t).ht(id); + line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',detcol,'linewidth',boxLineWidth*detections(t).sc(id)); + end + + % show trace + for tracet=max(1,t-traceLength):max(1,t-1) + ipolpar=(t-tracet)/traceLength; % parameter [0,1] for color adjustment + + % foot position + for k=1:length(detections(tracet).xp) + plot(detections(tracet).xi(k),detections(tracet).yi(k), ... + '.','color',ipolpar*grey + (1-ipolpar)*detcol,'MarkerSize',dotSize*detections(tracet).sc(k)); + end + + % box +% nboxes=length(detections(tracet).xp); +% for id=1:nboxes +% bleft=detections(tracet).xp(id)-detections(tracet).wd(id)/2; +% bright=detections(tracet).xp(id)+detections(tracet).wd(id)/2; +% btop=detections(tracet).yp(id)-detections(tracet).ht(id); +% bbottom=detections(tracet).yp(id); +% line([bleft bleft bright bright bleft],[btop bbottom bbottom btop btop],'color',ipolpar*grey + (1-ipolpar)*detcol); +% end + + end + + pause(framePause) + +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayGroundTruth.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayGroundTruth.m new file mode 100644 index 0000000000000000000000000000000000000000..4135ebf073c38772bf347eb1f08f4a32ee9da49e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayGroundTruth.m @@ -0,0 +1,42 @@ +function displayGroundTruth(sceneInfo, gtInfo) +% Display Ground Truth +% +% Take scene information sceneInfo and +% the ground truth from gtInfo +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +W=gtInfo.W; +H=gtInfo.H; + + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.01; % pause between frames + +options.traceLength=20; % overlay data from past 10 frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +X=gtInfo.X; Y=gtInfo.Y; + +reopenFig('Ground Truth'); +displayBBoxes(sceneInfo,gtInfo.frameNums,X,Y,W,H,options) + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayTrackingResult.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayTrackingResult.m new file mode 100644 index 0000000000000000000000000000000000000000..83597c454e93ecbce07b434c3c51de8295834caa --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/displayTrackingResult.m @@ -0,0 +1,47 @@ +function displayTrackingResult(sceneInfo, stateInfo) +% Display Tracking Result +% +% Take scene information sceneInfo and +% the tracking result from stateInfo +% +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% [~, ~, ~, ~, X Y]=getStateInfo(stateInfo); +W=stateInfo.W; +H=stateInfo.H; +Xi=stateInfo.Xi; +Yi=stateInfo.Yi; + +options.defaultColor=[.1 .2 .9]; +options.grey=.7*ones(1,3); +options.framePause=0.001; % pause between frames + +options.traceLength=20; % overlay track from past n frames +options.dotSize=20; +options.boxLineWidth=3; +options.traceWidth=2; + +options.hideBG=0; + +% what to display +options.displayDots=1; +options.displayBoxes=1; +options.displayID=0; +options.displayCropouts=0; +options.displayConnections=0; + +% save? +% options.outFolder='tmp'; + +reopenFig('Tracking Results') +displayBBoxes(sceneInfo,stateInfo.frameNums,Xi,Yi,W,H,options) + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/drawTALimits.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/drawTALimits.m new file mode 100644 index 0000000000000000000000000000000000000000..dafde616beee5dd1e9e9b4561ea00ce312b4f616 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/drawTALimits.m @@ -0,0 +1,36 @@ +function drawTALimits +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo + +c1=sceneInfo.trackingArea([1 3]); +c2=sceneInfo.trackingArea([2 3]); +c3=sceneInfo.trackingArea([2 4]); +c4=sceneInfo.trackingArea([1 4]); + + +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); + +[slx sly]=worldToImage(c1(1),c1(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(1)=slx; y(1)=sly; + +[slx sly]=worldToImage(c2(1),c2(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(2)=slx; y(2)=sly; + +[slx sly]=worldToImage(c3(1),c3(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(3)=slx; y(3)=sly; + +[slx sly]=worldToImage(c4(1),c4(2),0,mR,mT,camPar.mInt,camPar.mGeo); +x(4)=slx; y(4)=sly; + +line([x x(1)],[y y(1)],'linewidth',2,'color','w','linestyle','--'); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/estimateTargetsSize.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/estimateTargetsSize.m new file mode 100644 index 0000000000000000000000000000000000000000..6b980d7429d28c68ee11eae25b7ad1fb956edc42 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/estimateTargetsSize.m @@ -0,0 +1,53 @@ +function htobj=estimateTargetsSize(sceneInfo) +% Take best n percent of detections +% and fit a 2d surface through their heights +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +npercent = 25; % best 25 % + +% scenario=41; + +% sceneInfo=getSceneInfo(scenario); +detections=parseDetections(sceneInfo); +allxi=[];allxi=[];allyi=[];allsc=[];allht=[]; + +F=length(detections); +for t=1:F + allxi=[allxi detections(t).xi]; + allyi=[allyi detections(t).yi]; + allsc=[allsc detections(t).sc]; + allht=[allht detections(t).ht]; +end +minheight=15; +% goodones=find(allsc>0.75); % confident ones + +[allsc goodones]=sort(allsc,'descend'); goodones=goodones(1:round(length(goodones)/(1/npercent*100))); + +allxi=allxi(goodones);allyi=allyi(goodones);allsc=allsc(goodones);allht=allht(goodones); +htobj=fit([allxi; allyi]',allht','poly21','Robust','on'); + +% %% +% clf +% +% plot3(allxi,allyi,allht,'.'); box on +% xlim(sceneInfo.trackingArea(1:2));ylim(sceneInfo.trackingArea(3:4)); zlim([minheight sceneInfo.imgHeight]); +% set(gca,'Ydir','reverse'); +% +% hold on +% +% %% +% +% %% +% [xi yi]=meshgrid(1:50:sceneInfo.imgWidth, 1:50:sceneInfo.imgHeight); +% htsurface=feval(fitobj,xi(:),yi(:)); htsurface=reshape(htsurface,size(xi,1),size(xi,2)); +% htsurface(htsurfacesceneInfo.imgHeight)=sceneInfo.imgHeight; +% surf(xi,yi,htsurface) +% view(-78,34) \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/evaluateDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/evaluateDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..434bc96a586ea76a1c6195bd0d5a5d8572e5e8cc --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/evaluateDetections.m @@ -0,0 +1,28 @@ +function evaluateDetections(detMatrices,gtInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt +if sceneInfo.gtAvailable + detInfo=detMatrices; detInfo.frameNums=sceneInfo.frameNums; + detInfo.X=detInfo.Xi; detInfo.Y=detInfo.Yi; + [detInfo.F detInfo.N]=size(detInfo); + + if opt.track3d + detInfo=cutStateToTrackingArea(detInfo); +% gtInfo=cutGTToTrackingArea(gtInfo); + end + + printMessage(1,'\nDetections Evaluation (2D):\n'); + [metrics metricsInfo]=CLEAR_MOT(gtInfo,detInfo,struct('eval3d',0)); + printMetrics(metrics,metricsInfo,1,[1 2 3 8 9]); + printMessage(1,'\n'); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getBBoxesFromPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getBBoxesFromPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..fa0582c8ec7ae435a635a20df52d55f93d3b0f1d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getBBoxesFromPrior.m @@ -0,0 +1,79 @@ +function stateInfo=getBBoxesFromPrior(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% just take the height prior for that +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo +% [~, N F targetsExist X Y]=getStateInfo(stateInfo); +X=stateInfo.X; Y=stateInfo.Y; + +[F N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + H=heightPrior; +else + error('sorry dude'); +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +% if sceneInfo.gtAvailable +% global gtInfo +% arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); +% aspectRatio= arithmean; +% end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +% stateInfo.W=H*sceneInfo.targetAR; % or take data set mean +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getBBoxesFromState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getBBoxesFromState.m new file mode 100644 index 0000000000000000000000000000000000000000..84f3e7485b0eab07e403e80940bb1a13cfaeaa16 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getBBoxesFromState.m @@ -0,0 +1,207 @@ +function stateInfo=getBBoxesFromState(stateInfo) +% for visualization and for 2D evaluation +% we need the bounding boxes of the targets +% To this end, we check for corresponding detections +% and interpolate them to get the solution boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo +% [~, N F targetsExist X Y]=getStateInfo(stateInfo); +X=stateInfo.X; Y=stateInfo.Y; + +[F N]=size(X); +targetsExist=getTracksLifeSpans(X); + +W=zeros(size(X)); +H=zeros(size(Y)); + + +for id=1:N + sid=targetsExist(id,1); + eid=targetsExist(id,2); + frames=sid:eid; + asscDet=zeros(1,F); % which detection is close by? + widths=zeros(1,F); + heights=zeros(1,F); + scores=zeros(1,F); + + % find closest detections + for t=frames + ndets=length(detections(t).xp); % how many dets in this frame + if ndets + xy=[X(t,id); Y(t,id)]; + dets=[detections(t).xp; detections(t).yp]; + + alldist=sqrt(sum((repmat(xy,1,ndets)-dets).^2)); % distance to all + [mindist mindet]=min(alldist); + if mindist<=sceneInfo.targetSize + asscDet(t)=mindet; + widths(t)=detections(t).wd(mindet); + heights(t)=detections(t).ht(mindet); + scores(t)=detections(t).sc(mindet); + end + end + end + detsAssc=find(asscDet); % which detections associated + detsAsscWobble=detsAssc;%+0.01*rand(1,length(t))-0.005; % add random noise to avoid NaN in fitting (LOOK INTO THIS!) + + if numel(unique(detsAssc))>1 + polydeg=min(9,max(1,floor(numel(detsAssc)/100))); + polystr=sprintf('poly%d',polydeg); + +% global gdetsAssc gwidths +% gdetsAssc=detsAssc; gwidths=widths(detsAssc); +% detsAssc +% unique(detsAssc) +% heights(detsAssc) +% numel(detsAssc) +% +% polydeg +% +% polystr +% p=polyfit(detsAssc,widths(detsAssc),max(1,floor(numel(detsAssc)/100))); +% p=fit(detsAssc',widths(detsAssc)',polystr,'Normalize','on','Robust','on'); + +% ipolwidths = polyval(p,frames); +% ipolwidths = feval(p,frames); +% W((sid:eid)',id)=ipolwidths'; + + + + + +% +% +% numel(detsAssc) +% p=polyfit(detsAssc,heights(detsAssc),max(1,round(numel(detsAssc)/100))); +% [p,~,~,~]=fit(detsAssc',heights(detsAssc)',polystr,'Normalize','on','Robust','on'); + sp=splinefit(detsAsscWobble, heights(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); +% pause + +% ipolheights = polyval(p,frames); +% ipolheights = feval(p,frames); + ipolheights=ppval(sp,frames); + + + H((sid:eid)',id)=ipolheights'; + + if ~isfield(sceneInfo,'targetAR') % if no aspect ratio given, estimate widths +% [p,~,~,~]=fit(detsAssc',widths(detsAssc)',polystr,'Normalize','on','Robust','on'); + sp=splinefit(detsAsscWobble, widths(detsAssc),1,max(1,floor(numel(detsAssc)/100))+1,'r',scores(detsAssc)); +% ipolwidths = feval(p,frames); + ipolwidths = ppval(sp,frames); + + W((sid:eid)',id)=ipolwidths'; + + end + + else % strange trajectory with < 3 detections + detwidthmean=[]; detheightmean=[]; +% sid +% eid + for t=sid:eid + detwidthmean=[detwidthmean mean(detections(t).wd)]; + detheightmean=[detheightmean mean(detections(t).ht)]; + end +% detwidthmean +% detheightmean + detwidthmean(isnan(detwidthmean))=mean(detwidthmean(~isnan(detwidthmean))); + detheightmean(isnan(detheightmean))=mean(detheightmean(~isnan(detheightmean))); +% detwidthmean +% detheightmean + W((sid:eid)',id)=detwidthmean; + H((sid:eid)',id)=detheightmean; + end + + + +% detsAsscWobble +% +% detsAssc +% unique(detsAssc) +% heights(detsAssc) +% numel(detsAssc) +% +% clf +% hold on +% % size(frames) +% % size(ipolwidths) +% plot(detsAssc,heights(detsAssc),'o') +% plot(frames,ipolheights,'r') +% plot(frames,ppval(sp,frames),'k'); +% +% % global HP +% % plot(frames,HP((sid:eid)',id),'--'); +% +% % plot(frames,lincomb,':'); +% +% % size(sid:eid) +% % size(ipolheights) +% pause + + +end + +% if we have camera calibration +% lets assume all people are 1.7m tall and push +% the heights of bboxes towards that value +if isfield(sceneInfo,'camPar') + heightPrior=getHeightPrior(stateInfo); + prwght=.8; + H=(1-prwght)*H + prwght*heightPrior; + +end + + + +% aspectRatio= 1/2; +% aspectRatio= 1/3; +% aspectRatio=1; + +% normalize ratio to dataset mean? +if sceneInfo.gtAvailable + global gtInfo + arithmean=mean(gtInfo.W(~~gtInfo.W)./gtInfo.H(~~gtInfo.H)); + aspectRatio= arithmean; +end + +stateInfo.H=H; + +% at least 30 pixels heigh +stateInfo.H(stateInfo.H<30)=30; + + +% if aspect ratio provided by user, take it +if isfield(sceneInfo,'targetAR') + stateInfo.W=H*sceneInfo.targetAR; +% stateInfo.W=H*sceneInfo.targetAR; % or take data set mean +else + stateInfo.W=W; +end + + +% at least 15 pixels wide +stateInfo.W(stateInfo.W<15)=15; + +% clean up mess +stateInfo.W(~X)=0; stateInfo.H(~X)=0; + +% WTF? +% isnanH=find(isnan(stateInfo.H)); +% isnumH=setdiff(find(stateInfo.H),isnanH); +% stateInfo.H(isnanH)=mean(stateInfo.H(isnumH)); +% isnanW=find(isnan(stateInfo.W)); +% isnumW=setdiff(find(stateInfo.W),isnanW); +% stateInfo.W(isnanW)=mean(stateInfo.W(isnumW)); + + + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getColorFromID.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getColorFromID.m new file mode 100644 index 0000000000000000000000000000000000000000..9ac27b6f3f79c5891348d2e7bf365d61620f6fc7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getColorFromID.m @@ -0,0 +1,32 @@ +function col=getColorFromID(id) + % get rgb [0,1] values from id +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + colors=getIDColors; + col=colors((mod(id,size(colors,1)))+1,:); +end + +function colors=getIDColors() +colors=[ + 128 255 255; % + 255 0 0; % red 1 + 0 255 0; % green 2 + 0 0 255; % blue 3 + 0 255 255; % cyan 4 + 255 0 255; % magenta 5 + 212 212 0; % yellow 6 + 25 25 25; % black 7 + 34,139,34; % forestgreen 8 + 0,191,255; % deepskyblue 9 + 139,0,0 ; % darkred 10 + 218,112,214; % orchid 11 + 244,164,96 ;]; % sandybrown 12 +colors = colors / 255; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getDetectionMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getDetectionMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..ccf365e0f6df009aa59c17e676dd0af9cec0c320 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getDetectionMatrices.m @@ -0,0 +1,36 @@ +function detMat = getDetectionMatrices(detections) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=length(detections); +Xd=zeros(F,0); +Yd=zeros(F,0); +Sd=zeros(F,0); + +Xi=zeros(F,0); +Yi=zeros(F,0); +W=zeros(F,0); +H=zeros(F,0); +for t=1:length(detections); + Dt=length(detections(t).xp); + Xd(t,1:Dt)=detections(t).xp; + Yd(t,1:Dt)=detections(t).yp; + Sd(t,1:Dt)=detections(t).sc; + + Xi(t,1:Dt)=detections(t).xi; + Yi(t,1:Dt)=detections(t).yi; + W(t,1:Dt)=detections(t).wd; + H(t,1:Dt)=detections(t).ht; +end + +detMat.Xd=Xd; +detMat.Yd=Yd; +detMat.Sd=Sd; + +detMat.Xi=Xi;detMat.Yi=Yi;detMat.W=W;detMat.H=H; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getHeightPrior.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getHeightPrior.m new file mode 100644 index 0000000000000000000000000000000000000000..0f0cf37058d32fb215ae0b6b3265328d9c4f47f1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getHeightPrior.m @@ -0,0 +1,42 @@ +function heightPrior=getHeightPrior(stateInfo) +% for 3d tracking we can compute +% an approximate average bounding box for each target +% which corresponds to a height of 1.70 m in the world +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global sceneInfo +camPar=sceneInfo.camPar; + +% rx=camPar.mExt.mRx;ry=camPar.mExt.mRy;rz=camPar.mExt.mRz; +% tx=camPar.mExt.mTx;ty=camPar.mExt.mTy;tz=camPar.mExt.mTz; +% txi=camPar.mExt.mTxi;tyi=camPar.mExt.mTyi;tzi=camPar.mExt.mTzi; +% kappa=camPar.mInt.mKappa1; focal=camPar.mInt.mFocal;Sx=camPar.mInt.mSx; +% Dpx=camPar.mGeo.mDpx;Dpy=camPar.mGeo.mDpy; + +% [mR mT]=getRotTrans(sceneInfo.camPar); + +% feet +Z=0*ones(size(stateInfo.Xgp)); +[Xi0 Yi0]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +% heads +Z=1700*ones(size(stateInfo.Xgp)); +[XiH YiH]=allWorldToImage_mex(stateInfo.Xgp,stateInfo.Ygp,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + camPar.mR,camPar.mT); + +heightPrior=Yi0-YiH; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getHomeFolder.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getHomeFolder.m new file mode 100644 index 0000000000000000000000000000000000000000..73c516d61d583341e7938351ddd12e1c9de04ad0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getHomeFolder.m @@ -0,0 +1,18 @@ +function homedir=getHomeFolder() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + homedir='/home/aanton'; + if ispc + homedir='D:'; + end + if exist('/gris/gris-f/home/aandriye','dir') + homedir='/gris/gris-f/home/aandriye'; + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..35b13964f06515bc0f4136d073d0ef57755314fb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/getSceneInfo.m @@ -0,0 +1,526 @@ +function sceneInfo=getSceneInfo(scenario) +% fill all necessary information about the +% scene into the sceneInfo struct +% +% Required: +% detfile detections file (.idl or .xml) +% frameNums frame numbers (eg. frameNums=1:107) +% imgFolder image folder +% imgFileFormat format for images (eg. frame_%04d.jpg) +% targetSize approx. size of targets (default: 5 on image, 350 in 3d) +% +% Required for 3D Tracking only +% trackingArea tracking area +% camFile camera calibration file (.xml PETS format) +% +% Optional: +% gtFile file with ground truth bounding boxes (.xml CVML) +% initSolFile initial solution (.xml or .mat) +% targetAR aspect ratio of targets on image +% bgMask mask to bleach out the background +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + + +global opt +% opt=getOptions; +% general folders +homefolder=getHomeFolder; +dbfolder=fullfile(filesep,'storage','databases'); if ispc, dbfolder=fullfile('D:','storage','databases'); end +if exist('/gris','dir'), dbfolder=fullfile(filesep,'gris','takatuka_dbases'); end + +% detection file +switch(scenario) + case {23,25,27,70,71,72,73,74,75,80} + dataset='PETS2009'; + case {40,41,42} + dataset='TUD'; + case {30,31,32,35,36,37} + dataset='TUD10'; + case {50,51,52,53} + dataset='ETH-Person'; + case {60,61,62} + dataset='AVSS'; + case {48} + dataset='UBC'; + case {90,91,92} + dataset='DA-ELS'; + otherwise + error('unknown scenario'); +end + +% sequence name +switch(scenario) + case 23 + seqname='PETS2009-S2L1-c1'; + case 25 + seqname='PETS2009-S2L2-c1'; + case 27 + seqname='PETS2009-S2L3-c1'; + case 31 + seqname='TUD10-ped1-c1'; + case 32 + seqname='TUD10-ped1-c2'; + case 36 + seqname='TUD10-ped1-c1'; + case 37 + seqname='TUD10-ped2-c2'; + case 40 + seqname='TUD-Campus'; + case 41 + seqname='TUD-Crossing'; + case 42 + seqname='TUD-Stadtmitte'; + case 48 + seqname='Hockey'; + case {50,51,52,53} + seqname=sprintf('seq%02d',scenario-50); + case 60 + seqname='AB_Easy'; + case 61 + seqname='AB_Medium'; + case 62 + seqname='AB_Hard'; + case 70 + seqname='PETS2009-S1L1-1-c1'; + case 71 + seqname='PETS2009-S1L1-2-c1'; + case 72 + seqname='PETS2009-S1L2-1-c1'; + case 73 + seqname='PETS2009-S1L2-2-c1'; + case 74 + seqname='PETS2009-S1L3-1-c1'; + case 75 + seqname='PETS2009-S1L3-2-c1'; + case 80 + seqname='PETS2009-S3MF1-c1'; + case {90,91,92,93,94} + seqname=sprintf('s%02d',scenario-90); + otherwise + + error('unknown scenario'); +end + +% frameNums +switch(scenario) + case 20 % terrace1 + sceneInfo.frameNums=1:2000; + case 21 % terrace2 + sceneInfo.frameNums=1:2000; + case {22,23} % PETS 2009 S2 L1 + sceneInfo.frameNums=0:794; + case 24 % PETSMONO occlusion + sceneInfo.frameNums=0:794; + case 25 + sceneInfo.frameNums=0:435; + case 27 + sceneInfo.frameNums=0:239; + case {30,31,32,33} % TUD10 ped + sceneInfo.frameNums=1:1400; + % sceneInfo.frameNums=1:300; + case {35,36,37} % TUD10 ped2 + sceneInfo.frameNums=1:1999; + % sceneInfo.frameNums=1:199; + % sceneInfo.frameNums=1670:1680; + % sceneInfo.frameNums=760:770; + case 40 % tud-campus + sceneInfo.frameNums=90:160; + case {41,44} % tud-crossing + sceneInfo.frameNums=1:201; + case 42 % tud-stadtmitte + sceneInfo.frameNums=7022:7200; + % sceneInfo.frameNums=7022:7100; + case 45 % eth central xing1 + sceneInfo.frameNums=1600:2200; + case 46 % eth central xing1 + sceneInfo.frameNums=3300:3600; + case 47 % eth central xing1 + sceneInfo.frameNums=7433:7811; + case 48 % UBC Hockey + sceneInfo.frameNums=700:800; + case 50 % ETH Person seq0 + sceneInfo.frameNums=180:678; + case 51 % ETH Person seq1 + sceneInfo.frameNums=0:999; + case 52 % ETH Person seq2 + sceneInfo.frameNums=0:450; + case 53 % ETH Person seq3 + sceneInfo.frameNums=100:453; + case {60,61,62} % AVSS + sceneInfo.frameNums=1:2000; + case 70 + sceneInfo.frameNums=0:220; + case 71 + sceneInfo.frameNums=0:240; + case 72 + sceneInfo.frameNums=0:200; + case 73 + sceneInfo.frameNums=0:130; + case 74 + sceneInfo.frameNums=0:90; + case 75 + sceneInfo.frameNums=0:343; + case 80 + sceneInfo.frameNums=1:107; + case 81 + sceneInfo.frameNums=0:231; + case 82 + sceneInfo.frameNums=0:108; + case 83 + sceneInfo.frameNums=0:169; + case 84 + sceneInfo.frameNums=0:92; + case 85 + sceneInfo.frameNums=0:107; + case 86 + sceneInfo.frameNums=0:184; + % case 90 + % sceneInfo.frameNums=1:593; + % case 91 + % sceneInfo.frameNums=1:307; + % case 92 + % sceneInfo.frameNums=1:420; + case {101,131} % EnterExitCrossingPaths1 cor, front + sceneInfo.frameNums=0:382; + case {102,132} % EnterExitCrossingPaths2 cor, front + sceneInfo.frameNums=0:484; + case {103,133} % OneLeaveShop1 cor, front + sceneInfo.frameNums=0:294; + case {104,134} % OneLeaveShop2 cor, front + sceneInfo.frameNums=0:1118; + case {105,135} % OneLeaveShopReenter1 cor, front + sceneInfo.frameNums=0:389; + case {106,136} % OneLeaveShopReenter2 cor, front + sceneInfo.frameNums=0:559; + case {107,137} % OneShopOneWait1 cor, front + sceneInfo.frameNums=0:1376; + case {108,138} % OneShopOneWait2 cor, front + sceneInfo.frameNums=0:1461; + case {109,139} % OneStopEnter1 cor, front + sceneInfo.frameNums=0:1499; + case {110,140} % OneStopEnter2 cor, front + sceneInfo.frameNums=0:2724; + case {111,141} % OneStopMoveEnter1 cor, front + sceneInfo.frameNums=0:1586; + case {112,142} % OneStopMoveEnter2 cor, front + sceneInfo.frameNums=0:2236; + case {113,143} % OneStopMoveNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {114,144} % OneStopMoveNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {115,145} % OneStopNoEnter1 cor, front + sceneInfo.frameNums=0:1664; + case {116,146} % OneStopNoEnter2 cor, front + sceneInfo.frameNums=0:1034; + case {117,147} % ShopAssistant1 cor, front + sceneInfo.frameNums=0:1674; + case {118,148} % ShopAssistant2 cor, front + sceneInfo.frameNums=0:3699; + case {119,149} % ThreePastShop1 cor, front + sceneInfo.frameNums=0:1649; + case {120,150} % ThreePastShop2 cor, front + sceneInfo.frameNums=0:1520; + case {121,151} % TwoEnterShop1 cor, front + sceneInfo.frameNums=0:1644; + case {122,152} % TwoEnterShop2 cor, front + sceneInfo.frameNums=0:1604; + case {123,153} % TwoEnterShop3 cor, front + sceneInfo.frameNums=0:1604; + case {124,154} % TwoLeaveShop1 cor, front + sceneInfo.frameNums=0:1342; + case {125,155} % TwoLeaveShop2 cor, front + sceneInfo.frameNums=0:599; + case {126,156} % WalkByShop1 cor, front + sceneInfo.frameNums=0:2359; + case 160 + sceneInfo.frameNums=171:184; + case {161,162} + sceneInfo.frameNums=97:114; + otherwise + warning('unknown scenario getFrameNums'); +end + + +detfolder=fullfile(homefolder,'diss','detections','hog-hof-linsvm',dataset,seqname); +% detfolder=fullfile(homefolder,'diss','detections','swd-v2',dataset,seqname); +% detfolder=fullfile(dbfolder,'data-tud','det','',dataset,seqname); + +% detfile +switch(scenario) + case 51 + sceneInfo.detfile=fullfile(detfolder,'test-result-nms-0.8.idl'); + case 53 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'seq03-annot.idl'); + case 62 + sceneInfo.detfile=fullfile(detfolder,['AVSS-' seqname sprintf('-result-00000-05059-nms.idl',length(sceneInfo.frameNums)-1)]); + case 48 + sceneInfo.detfile=fullfile(dbfolder,dataset,seqname,'detections.mat'); + case {90,91,92} + sceneInfo.detfile=fullfile(detfolder,'detections.mat'); + case {23,25,27,70,71,72,73,80,40,41,42} + sceneInfo.detfile=fullfile(dbfolder,'data-tud','det',dataset,[seqname '-det.xml']); + otherwise + sceneInfo.detfile=fullfile(detfolder,[seqname sprintf('-result-00000-%05d-nms.idl',length(sceneInfo.frameNums)-1)]); + +end +assert(exist(sceneInfo.detfile,'file')==2,'detection file does not exist') + + +% img Folder +switch(scenario) + case 23 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); + case 25 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L2','Time_14-55','View_001',filesep); + case 27 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L3','Time_14-41','View_001',filesep); + case 31 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c1',filesep); + case 32 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped1','c2',filesep); + case 36 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c1',filesep); + case 37 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'ped2','c2',filesep); + case 40 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-campus-sequence',filesep); + case 41 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-crossing-sequence',filesep); + case 42 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'tud-stadtmitte',filesep); + case 48 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case {50,51,52,53} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,'left',filesep); + case {60,61,62} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + case 70 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-57','View_001',filesep); + case 71 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L1','Time_13-59','View_001',filesep); + case 72 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-06','View_001',filesep); + case 73 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S1','L2','Time_14-31','View_001',filesep); + case 80 + sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 + case {90,91,92,93} + sceneInfo.imgFolder=fullfile(dbfolder,dataset,seqname,filesep); + otherwise + error('unknown scenario image Folder'); +end +assert(exist(sceneInfo.imgFolder,'dir')==7,'imgfolder does not exist') + +% image extension +imgExt='.jpg'; +switch(scenario) + case {20,21,40,41,42,44,50,51,52,53} + imgExt='.png'; +end +sceneInfo.imgFileFormat='frame_%04d'; + +switch(scenario) + case 40 + sceneInfo.imgFileFormat='DaSide0811-seq6-%03d'; + case 41 + sceneInfo.imgFileFormat='DaSide0811-seq7-%03d'; + case 42 + sceneInfo.imgFileFormat='DaMultiview-seq%04d'; + case 48 + sceneInfo.imgFileFormat='h%04d'; + case {50,51,52,53} + sceneInfo.imgFileFormat='image_%08d_0'; + case {90,91,92,93} + sceneInfo.imgFileFormat='%05d'; +end + +% append file extension +sceneInfo.imgFileFormat=[sceneInfo.imgFileFormat imgExt]; + +% if no frame nums, determine from images +if ~isfield(sceneInfo,'frameNums') + imglisting=dir([sceneInfo.imgFolder '*' imgExt]); + sceneInfo.frameNums=1:length(imglisting); +end + +% image dimensions +[sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... + size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); + + + + +%% tracking area +% if we are tracking on the ground plane +% we need to explicitly secify the tracking area +% otherwise image = tracking area +if opt.track3d + switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.trackingArea=[-14069.6, 4981.3, -14274.0, 1733.5]; + case {30,31,32} + sceneInfo.trackingArea=[-197 6708 -2021 6870]; + case {35,36,37} + sceneInfo.trackingArea=[-3438 5271 -2018 7376]; + case 40 + sceneInfo.trackingArea=[-0150 0506 28 1081]; + case 41 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + case 42 + sceneInfo.trackingArea=[-19, 12939, -48, 10053]; + otherwise + error('Definition of tracking area needed for 3d tracking'); + end + +else + sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +end + +%% camera +cameraconffile=[]; +if opt.track3d + cam=1; + switch(scenario) + case {20,21} %terrace + cameraconffile=sprintf('%sepfl/terrace-tsai-c%i.xml',dbfolder,cam); + case {22, 23,25,27,70,71,72,73,74,75,80,81,82,83,84,85,86} %PETS2009 + cameraconffile=fullfile(dbfolder,dataset,'View_001.xml'); + case 24 + cameraconffile=sprintf('%sPETS2009/View_001.xml',dbfolder); + case 30 + cameraconffile=sprintf('%sTUD10/ped1/c%i-calib.xml',dbfolder,cam); + case 31 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c1-calib.xml'); + case 32 + cameraconffile=fullfile(dbfolder,dataset,'ped1/c2-calib.xml'); + case 36 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c1-calib.xml'); + case 37 + cameraconffile=fullfile(dbfolder,dataset,'ped2/c2-calib.xml'); + case {40,43} + cameraconffile=fullfile(dbfolder,dataset,'tud-campus-calib.xml'); + case {41,44} + cameraconffile=fullfile(dbfolder,dataset,'tud-crossing-calib.xml'); + case 42 + cameraconffile=fullfile(dbfolder,dataset,'tud-stadtmitte-calib.xml'); + case {45,46,47} + cameraconffile=sprintf('%sETH-Central/pedxing-seq1-calib.xml',dbfolder); + case {60,61,62} + cameraconffile=sprintf('%sAVSS/AB_calib.xml',dbfolder); + case intersect(scenario,101:126); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-cor.xml',dbfolder); + case intersect(scenario,131:156); + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + case intersect(scenario,160:163) %%% !!! FIX !!! + cameraconffile=sprintf('%sCAVIAR/CAVIAR-front.xml',dbfolder); + otherwise + error('unknown scenario'); + end +end +sceneInfo.camFile=cameraconffile; + +if ~isempty(sceneInfo.camFile) + sceneInfo.camPar=parseCameraParameters(sceneInfo.camFile); +end + + +%% target size +sceneInfo.targetSize=20; % target 'radius' +sceneInfo.targetSize=sceneInfo.imgWidth/30; +if opt.track3d, sceneInfo.targetSize=350; end + +%% target aspect ratio +sceneInfo.targetAR=1/3; +switch(scenario) + case 48 % Hockey + sceneInfo.targetAR=1/2; + case {90,91,92} % aerial + sceneInfo.targetAR=1; +end + + +%% ground truth +sceneInfo.gtFile=''; +switch(scenario) + case {23,25,27,70,71,72,73,80} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + case 31 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c1','GT2d_full_new.mat'); + case 32 + sceneInfo.gtFile=fullfile(dbfolder,dataset,'ped1','c2','GT2d_full_new.mat'); + case {40,41} + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '-interp.mat']); + case 42 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,[seqname '.mat']); + % sceneInfo.gtFile='/home/aanton/diss/others/yangbo/TUD/TUD_Stadtmitte.avi.gt.mat'; % Yang + case 62 + sceneInfo.gtFile=fullfile(dbfolder,'data-tud','gt',dataset,'AB_Hard','GT2d_new.mat'); + otherwise + warning('ground truth?'); +end + + +global gtInfo +sceneInfo.gtAvailable=0; +if ~isempty(sceneInfo.gtFile) + sceneInfo.gtAvailable=1; + % first determine the type + [pathtogt, gtfile, fileext]=fileparts(sceneInfo.gtFile); + + if strcmpi(fileext,'.xml') % CVML + gtInfo=parseGT(sceneInfo.gtFile); + elseif strcmpi(fileext,'.mat') + % check for the var gtInfo + fileInfo=who('-file',sceneInfo.gtFile); + varExists=0; cnt=0; + while ~varExists && cnt0.7)=Inf; +[a,b]=munkres(A); +%} +% Example 4: an example of partial assignment +%{ +A = [1 3 Inf; Inf Inf 5; Inf Inf 0.5]; +[a,b]=munkres(A) +%} +% a = [1 0 3] +% b = 1.5 +% Reference: +% "Munkres' Assignment Algorithm, Modified for Rectangular Matrices", +% http://csclab.murraystate.edu/bob.pilgrim/445/munkres.html + +% version 2.3 by Yi Cao at Cranfield University on 11th September 2011 + +assignment = zeros(1,size(costMat,1)); +cost = 0; + +validMat = costMat == costMat & costMat < Inf; +bigM = 10^(ceil(log10(sum(costMat(validMat))))+1); +costMat(~validMat) = bigM; + +% costMat(costMat~=costMat)=Inf; +% validMat = costMat0) + break + end + coverColumn = false(1,n); + coverColumn(starZ(starZ>0))=true; + coverRow = false(n,1); + primeZ = zeros(n,1); + [rIdx, cIdx] = find(dMat(~coverRow,~coverColumn)==bsxfun(@plus,minR(~coverRow),minC(~coverColumn))); + while 1 + %************************************************************************** + % STEP 4: Find a noncovered zero and prime it. If there is no starred + % zero in the row containing this primed zero, Go to Step 5. + % Otherwise, cover this row and uncover the column containing + % the starred zero. Continue in this manner until there are no + % uncovered zeros left. Save the smallest uncovered value and + % Go to Step 6. + %************************************************************************** + cR = find(~coverRow); + cC = find(~coverColumn); + rIdx = cR(rIdx); + cIdx = cC(cIdx); + Step = 6; + while ~isempty(cIdx) + uZr = rIdx(1); + uZc = cIdx(1); + primeZ(uZr) = uZc; + stz = starZ(uZr); + if ~stz + Step = 5; + break; + end + coverRow(uZr) = true; + coverColumn(stz) = false; + z = rIdx==uZr; + rIdx(z) = []; + cIdx(z) = []; + cR = find(~coverRow); + z = dMat(~coverRow,stz) == minR(~coverRow) + minC(stz); + rIdx = [rIdx(:);cR(z)]; + cIdx = [cIdx(:);stz(ones(sum(z),1))]; + end + if Step == 6 + % ************************************************************************* + % STEP 6: Add the minimum uncovered value to every element of each covered + % row, and subtract it from every element of each uncovered column. + % Return to Step 4 without altering any stars, primes, or covered lines. + %************************************************************************** + [minval,rIdx,cIdx]=outerplus(dMat(~coverRow,~coverColumn),minR(~coverRow),minC(~coverColumn)); + minC(~coverColumn) = minC(~coverColumn) + minval; + minR(coverRow) = minR(coverRow) - minval; + else + break + end + end + %************************************************************************** + % STEP 5: + % Construct a series of alternating primed and starred zeros as + % follows: + % Let Z0 represent the uncovered primed zero found in Step 4. + % Let Z1 denote the starred zero in the column of Z0 (if any). + % Let Z2 denote the primed zero in the row of Z1 (there will always + % be one). Continue until the series terminates at a primed zero + % that has no starred zero in its column. Unstar each starred + % zero of the series, star each primed zero of the series, erase + % all primes and uncover every line in the matrix. Return to Step 3. + %************************************************************************** + rowZ1 = find(starZ==uZc); + starZ(uZr)=uZc; + while rowZ1>0 + starZ(rowZ1)=0; + uZc = primeZ(rowZ1); + uZr = rowZ1; + rowZ1 = find(starZ==uZc); + starZ(uZr)=uZc; + end +end + +% Cost of assignment +rowIdx = find(validRow); +colIdx = find(validCol); +starZ = starZ(1:nRows); +vIdx = starZ <= nCols; +assignment(rowIdx(vIdx)) = colIdx(starZ(vIdx)); +pass = assignment(assignment>0); +pass(~diag(validMat(assignment>0,pass))) = 0; +assignment(assignment>0) = pass; +cost = trace(costMat(assignment>0,assignment(assignment>0))); + +function [minval,rIdx,cIdx]=outerplus(M,x,y) +ny=size(M,2); +minval=inf; +for c=1:ny + M(:,c)=M(:,c)-(x+y(c)); + minval = min(minval,min(M(:,c))); +end +[rIdx,cIdx]=find(M==minval); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/myLinExtrap.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/myLinExtrap.m new file mode 100644 index 0000000000000000000000000000000000000000..4f1e2e60b8793bfa472b71825a6401561cb77b21 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/myLinExtrap.m @@ -0,0 +1,26 @@ +function yi=myLinExtrap(Y,steps) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% only takes two element vectors Y +if length(Y)~=2, error('Y must be of length 2'); end + + +n=Y(1); m=diff(Y); + +if steps<0 + xi=steps:-1; +else + xi=(1:steps)+1; +end + +yi = m*xi + n; + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/parseDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/parseDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..3480587e514e9fd56dc963c11243b893318bd8c3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/parseDetections.m @@ -0,0 +1,119 @@ +function [detections, nDets]=parseDetections(sceneInfo,frames) +% read detection file and create a struct array +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt +nDets=0; + +detfile = sceneInfo.detfile; +% first determine the type +[pathstr, filename, ~] = fileparts(detfile); +% is there a .mat file available? +matfile=fullfile(pathstr,[filename '.mat']); +% if exist(matfile,'file') +% load(matfile,'detections'); +% detections = setDetectionPositions(detections); +% % check if all info is available +% if (~isfield(detections,'xp') || ... +% ~isfield(detections,'yp') || ... +% ~isfield(detections,'sc') || ... +% ~isfield(detections,'wd') || ... +% ~isfield(detections,'ht')) +% error('detections must have fields xp,yp,sc,wd,ht'); +% end +% +% if nargin==2 +% detections=detections(frames); +% end +% +% % count detections +% if ~nDets +% for t=1:length(detections),nDets=nDets+length(detections(t).xp);end +% end +% +% return; +% end + +%% now parse +detectionSet = load(detfile); +if(1) + newdetections = detectionAddNoise(detectionSet); +end + +cnt = numel(sceneInfo.frameNums); +detections(cnt).bx=[]; +detections(cnt).by=[]; +detections(cnt).xp=[]; +detections(cnt).yp=[]; +detections(cnt).ht=[]; +detections(cnt).wd=[]; +detections(cnt).sc=[]; + +detections(cnt).xi=[]; +detections(cnt).yi=[]; +for t = 1:numel(sceneInfo.frameNums); + if(~mod(t,100)) + fprintf('.'); + end + idxObj = find(detectionSet(:, 5) == t); + nObjects = numel(idxObj); + bx =[];by=[];xp=[];yp=[]; + ht=[];wd=[];sc=[]; + xi=[];yi=[]; + for j = 1:nObjects + loc = detectionSet(idxObj(j), 1:4); +% score = detectionSet(idxObj(j), 7); + left = loc(1); top = loc(2); + width = loc(3)-left+1;height = loc(4)-top+1; + xis = left + width/2; + yis = top + height; + bx = cat(2, bx, left); + by=cat(2, by, top); + xp=cat(2, xp, xis); + yp=cat(2, xp, yis); + ht=cat(2, ht, height); + wd=cat(2, wd, width); + sc=cat(2, sc, 1); + xi=cat(2, xi, xis); + yi=cat(2, yi, yis); + end + detections(t).bx=bx; + detections(t).by=by; + detections(t).xp=xp; + detections(t).yp=yp; + detections(t).ht=ht; + detections(t).wd=wd; + detections(t).sc=sc; + + detections(t).xi=xi; + detections(t).yi=yi; + + nDets=nDets+length(xi); +end + + +%% set xp and yp accordingly +detections = setDetectionPositions(detections); + +% save detections in a .mat file +save(matfile,'detections'); + +end + +function detections=setDetectionPositions(detections) +% set xp,yp to xi,yi if tracking is in image (2d) +% set xp,yp to xw,yi if tracking is in world (3d) + F = length(detections); + + for t=1:F + detections(t).xp=detections(t).xi; + detections(t).yp=detections(t).yi; + end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/parseGT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/parseGT.m new file mode 100644 index 0000000000000000000000000000000000000000..309e82887abf389bf0d92264f4c81ee04acb3eab --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/parseGT.m @@ -0,0 +1,64 @@ +function gtInfo=parseGT(gtfile) +% read ground truth bounding boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +% first determine the type +[~, ~, fileext]=fileparts(gtfile); + +% for now, we can only read CVML schema +if strcmpi(fileext,'.xml'); +else error('Unknown type of detections file.'); +end + +%% now parse +xDoc=xmlread(gtfile); + +allFrames=xDoc.getElementsByTagName('frame'); +F=allFrames.getLength; +frameNums=zeros(1,F); + + +%% +for t=1:F + if ~mod(t,20), fprintf('.'); end + % what is the frame + frame=str2double(allFrames.item(t-1).getAttribute('number')); + frameNums(t)=frame; + + objects=allFrames.item(t-1).getElementsByTagName('object'); + Nt=objects.getLength; + for i=0:Nt-1 + id=str2double(objects.item(i).getAttribute('id')); + if id<1, error('uh oh. IDs should be positive'); end + box=objects.item(i).getElementsByTagName('box'); + h=str2double(box.item(0).getAttribute('h')); + w=str2double(box.item(0).getAttribute('w')); + xc=str2double(box.item(0).getAttribute('xc')); + yc=str2double(box.item(0).getAttribute('yc')); + + % foot position + gtInfo.X(t,id)=xc; gtInfo.Y(t,id)=yc+h/2; + gtInfo.H(t,id)=h; gtInfo.W(t,id)=w; + end +end + +gtInfo.frameNums=frameNums; +% remove zero columns +notEmpty=~~sum(gtInfo.X); +gtInfo.X=gtInfo.X(:,notEmpty); +gtInfo.Y=gtInfo.Y(:,notEmpty); +gtInfo.W=gtInfo.W(:,notEmpty); +gtInfo.H=gtInfo.H(:,notEmpty); + + +% fprintf('all read\n'); + + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/parseVehicleGT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/parseVehicleGT.m new file mode 100644 index 0000000000000000000000000000000000000000..c6af75d426cc74efe727c342e0c3c97f00ef7db8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/parseVehicleGT.m @@ -0,0 +1,36 @@ +function gtInfo = parseVehicleGT(gtfile, frameNums) +% read ground truth bounding boxes +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +%% now parse +gt = load(gtfile); +for t = frameNums + idx = find(gt(:,5) == t); + for i = 1:numel(idx) + h = gt(idx(i), 4) - gt(idx(i), 2) + 1; + w = gt(idx(i), 3) - gt(idx(i), 1) + 1; + xc = gt(idx(i), 1) + w/2; + yc = gt(idx(i), 2) + h/2; + id = gt(idx(i), 6); + % foot position + gtInfo.X(t,id)=xc; gtInfo.Y(t,id)=yc+h/2; + gtInfo.H(t,id)=h; gtInfo.W(t,id)=w; + end +end + +gtInfo.frameNums = frameNums; +% remove zero columns +notEmpty = ~~sum(gtInfo.X); +gtInfo.X = gtInfo.X(:,notEmpty); +gtInfo.Y = gtInfo.Y(:,notEmpty); +gtInfo.W = gtInfo.W(:,notEmpty); +gtInfo.H = gtInfo.H(:,notEmpty); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/pdfcrop.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/pdfcrop.m new file mode 100644 index 0000000000000000000000000000000000000000..08a8e427e01bd46c317fa3afaf61e337288e1319 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/pdfcrop.m @@ -0,0 +1,3 @@ +function pdfcrop(pdffile) + eval(sprintf('!pdfcrop %s %s >& /dev/null',pdffile,pdffile)); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/plotDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/plotDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..9cc7d63d4dcdfd98e6576f8dbc0b0113f0817625 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/plotDetections.m @@ -0,0 +1,61 @@ +function plotDetections(plot3d, limits) +% plot detections as dots +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global detections sceneInfo + +hold on +% axis equal + +dets=detections; +F=size(dets,2); +detcol=[.6 .6 .6]; +maxFrames=200; +% plot3d=1; + +% imshow(imread('/storage/databases/PETS2009/Crowd_PETS09/S3/Multiple_Flow/Time_12-43/View_001/frame_0026.jpg')); + +if ~exist('plot3d','var'), plot3d=0; end + +if plot3d + for t=1:min(F,maxFrames) +% t +% t*ones(1,length(dets(t).xp)) +% pause + plot3(dets(t).xp,dets(t).yp,t*ones(1,length(dets(t).xp)),'.','color',detcol); + +% pause(.01) + end +% view(3) +% zlim([0 min(F,maxFrames)]); +else + for t=1:F + plot(dets(t).xp,dets(t).yp,'.','color',detcol); + end + +end + +if exist('limits','var') + if length(limits)==4 || length(limits)==6 + xlim(limits(1:2)); + ylim(limits(3:4)); +% if length(limits)==6 +% zlim(limits(5:6)); +% end + else + error('limits must be 4 or 6 long vector'); + end +else + xlim(sceneInfo.trackingArea(1:2)); + ylim(sceneInfo.trackingArea(3:4)); +end + +pause(0.001); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/postProcessState.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/postProcessState.m new file mode 100644 index 0000000000000000000000000000000000000000..75eefed3d4c8950da89b4591a6f31e8bfc7083d7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/postProcessState.m @@ -0,0 +1,29 @@ +function stateInfo=postProcessState(stateInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global opt sceneInfo + + +if opt.track3d && opt.cutToTA + stateInfo=cutStateToTrackingArea(stateInfo); +end + +% if we tracked on image, Xi = X +if ~opt.track3d + stateInfo.Xi=stateInfo.X; stateInfo.Yi=stateInfo.Y; +% otherwise project back +else + stateInfo.Xgp=stateInfo.X; stateInfo.Ygp=stateInfo.Y; + [stateInfo.Xi, stateInfo.Yi]=projectToImage(stateInfo.X,stateInfo.Y,sceneInfo); +end + +%% get bounding boxes from corresponding detections +stateInfo=getBBoxesFromState(stateInfo); +% stateInfo=getBBoxesFromPrior(stateInfo); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/prepFigure.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/prepFigure.m new file mode 100644 index 0000000000000000000000000000000000000000..27443be17e1e3b690c8d3b28ed6cfcc44fb01ee0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/prepFigure.m @@ -0,0 +1,39 @@ +function prepFigure() +% prepare figure for showing state +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sceneInfo opt; + +% figh=findobj('type','figure','name','optimization'); + +% if isempty(figh), figh=figure('name','optimization'); end +% set(figh); + +clf; +hold on; +box on + +if ~opt.track3d + set(gca,'Ydir','reverse'); +end +xlim(sceneInfo.trackingArea(1:2)) +ylim(sceneInfo.trackingArea(3:4)) +if ~opt.track3d + ylim([sceneInfo.imTopLimit sceneInfo.trackingArea(4)]); +end + +zlim([0 length(sceneInfo.frameNums)]) + +view(-78,4) +if ~opt.track3d + view(-40,10); +end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printFinalEvaluation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printFinalEvaluation.m new file mode 100644 index 0000000000000000000000000000000000000000..6d99b03b0073658a9fa79002085ae48f6e53e38f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printFinalEvaluation.m @@ -0,0 +1,30 @@ +function printFinalEvaluation(res_path, res_mat_name, cutgtFile, frame_end) + +% load gtInfo +load(cutgtFile); +% load stateInfo +left = load([res_path res_mat_name '_LX.txt']); +top = load([res_path res_mat_name '_LY.txt']); +right = load([res_path res_mat_name '_RX.txt']); +down = load([res_path res_mat_name '_RY.txt']); +stateInfo = []; +h = down - top; +w = right - left; +xc = left + w/2; +yc = top + h/2; +% foot position +stateInfo.X = xc; +stateInfo.Y = yc+h/2; +stateInfo.H = h; +stateInfo.W = w; +stateInfo.F = frame_end; +stateInfo.frameNums = 1:frame_end; +stateInfo.Xgp = stateInfo.X; +stateInfo.Ygp = stateInfo.Y; +stateInfo.Xi = stateInfo.X; +stateInfo.Yi = stateInfo.Y; + +% print result +printMessage(1,'\nEvaluation 2D:\n'); +[metrics, metricsInfo]=CLEAR_MOT(gtInfo,stateInfo); +printMetrics(metrics,metricsInfo,1); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printMessage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printMessage.m new file mode 100644 index 0000000000000000000000000000000000000000..bc6b7d8f3bc92fea3d77c7185445c603db3b0aee --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printMessage.m @@ -0,0 +1,11 @@ +function printMessage(L,F,varargin) +% print a formatted string as F with values from varargin and debug level L +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +fprintf(F,varargin{:}); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printMetrics.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printMetrics.m new file mode 100644 index 0000000000000000000000000000000000000000..6b8a7929c06d6193c3a6a58b66858ea9ee234965 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printMetrics.m @@ -0,0 +1,43 @@ +function printMetrics(metrics, metricsInfo, dispHeader,dispMetrics,padChar) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +namesToDisplay=metricsInfo.names.long; +widthsToDisplay=metricsInfo.widths.long; +formatToDisplay=metricsInfo.format.long; + +namesToDisplay=metricsInfo.names.short; +widthsToDisplay=metricsInfo.widths.short; +formatToDisplay=metricsInfo.format.short; + +if nargin<3, dispHeader=1; end +if nargin<4 + dispMetrics=1:length(metrics); +end +if nargin<5 + padChar={' ',' ','|',' ',' ',' ','|',' ',' ',' ','| ',' ',' ',' '}; +end + +if dispHeader + for m=dispMetrics + printString=sprintf('fprintf(''%%%is%s'',char(namesToDisplay(m)))',widthsToDisplay(m),char(padChar(m))); + eval(printString) + end + fprintf('\n'); +end + +for m=dispMetrics + printString=sprintf('fprintf(''%%%i%s%s'',metrics(m))',widthsToDisplay(m),char(formatToDisplay(m)),char(padChar(m))); + eval(printString) +end + +% if standard, new line +if nargin<4 + fprintf('\n'); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printSceneInfo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printSceneInfo.m new file mode 100644 index 0000000000000000000000000000000000000000..a06683f310651afbaca7ba0e8a767ecf4e9dc939 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/printSceneInfo.m @@ -0,0 +1,43 @@ +function printSceneInfo() +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. +% prints information about the scene + +% sceneInfo.targetSize=10; % target 'radius' +% +% +% % sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S2','L1','Time_12-34','View_001',filesep); % 23 +% sceneInfo.imgFolder=fullfile(dbfolder,dataset,'Crowd_PETS09','S3','Multiple_Flow','Time_12-43','View_001',filesep); % 80 +% +% sceneInfo.imgFileFormat='frame_%04d.jpg'; +% sceneInfo.frameNums=1:107; +% % sceneInfo.frameNums=0:794; +% [sceneInfo.imgHeight, sceneInfo.imgWidth, ~]= ... +% size(imread([sceneInfo.imgFolder sprintf(sceneInfo.imgFileFormat,sceneInfo.frameNums(1))])); +% sceneInfo.trackingArea=[1 sceneInfo.imgWidth 1 sceneInfo.imgHeight]; % tracking area +% +% %% load detections +% detections=parseDetections(detfile); fr=1:length(detections); +% % fr=1:50; detections=detections(fr); % !!!!!!! REMOVE +% F=size(detections,2); +% stateInfo.F=F; % number of frames +% +% +global sceneInfo + + +%% +% printMessage(1,'Sequence: \t%s\n',sceneInfo.seqName); +printMessage(2, 'Frames: ...... %i\n',length(sceneInfo.frameNums)); +printMessage(2, 'Image size: .. %i x %i\n',sceneInfo.imgWidth,sceneInfo.imgHeight) + +% sceneInfo + +%% +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/projectToGroundPlane.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/projectToGroundPlane.m new file mode 100644 index 0000000000000000000000000000000000000000..b51522119bb738eae46b2fe90930d43d1aca9e74 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/projectToGroundPlane.m @@ -0,0 +1,22 @@ +function [Xgp Ygp]=projectToGroundPlane(Xi, Yi, sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +[F N]=size(Xi); +Xgp=zeros(size(Xi)); +Ygp=zeros(size(Xi)); + +for t=1:F + extar=find(Xi(t,:)); + for id=extar + [Xgp(t,id) Ygp(t,id) zw]=imageToWorld(Xi(t,id), Yi(t,id), sceneInfo.camPar); + end +end + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/projectToImage.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/projectToImage.m new file mode 100644 index 0000000000000000000000000000000000000000..97d5f7fdb9142e4217853da0b834e11a728adb0f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/projectToImage.m @@ -0,0 +1,19 @@ +function [Xi Yi]=projectToImage(X,Y,sceneInfo) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +Z=zeros(size(X)); +camPar=sceneInfo.camPar; +[mR mT]=getRotTrans(camPar); +[Xi Yi]=allWorldToImage_mex(X,Y,Z, ... + camPar.mGeo.mDpx, camPar.mGeo.mDpy, ... + camPar.mInt.mSx, camPar.mInt.mCx, camPar.mInt.mCy, camPar.mInt.mFocal, camPar.mInt.mKappa1,... + mR,mT); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/readIDL.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/readIDL.m new file mode 100644 index 0000000000000000000000000000000000000000..6e94f840fdbc5223ab1e4eada6f90623db9f3800 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/readIDL.m @@ -0,0 +1,60 @@ +% Return IDL structure for given filename +% +% INPUT +% filename filename of IDL file +% +% OUTPUT +% idl IDL structure, consisting of +% idl.img - array of images +% idl.bb - array of array of bounding box coordinates +% idl.score - array of array of scores for boxes + +function idl=readIDL(filename) + +fid=fopen(filename); +idl.bb=[]; +idl.img=[]; +idl.score=[]; + +i=1; +bbnum=0; +while 1 + tline = fgetl(fid); + if ~ischar(tline), break, end + tline = strrep(tline, ',', ' '); %replace commas with spaces + colon=strfind(tline,':'); %all colons + + if isempty(colon) + point = strfind(tline,'";'); + if length(point) > 0 + idl(i).img=tline(2:point(1)-1); %filename + i = i + 1; + continue + else + break + end + end + + bb_idx=[(strfind(tline,'(')+1)' (strfind(tline,')')-1)'];%positions of bb start and stop + + idl(i).img=tline(2:colon(1)-2); %filename + for k=1:size(bb_idx,1) + idl(i).bb(end+1,:)=str2num(tline(bb_idx(k,1):bb_idx(k,2))); % next bb + end + + if length(colon)>1 %there are scores in the file ... + for k=1:size(bb_idx,1)-1 + idl(i).score(end+1) = str2num(tline(colon(k+1)+1:(bb_idx(k+1,1)-2))); %next score + end + idl(i).score(end+1) = str2num(tline(colon(length(colon))+1:length(tline)-1)); + else + idl(i).score = 1*ones(1,size(bb_idx,1)); + end + + i=i+1; + bbnum = bbnum + size(bb_idx,1); +end +fclose(fid); + +% fprintf('%d bounding boxes loaded.', bbnum); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/reopenFig.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/reopenFig.m new file mode 100644 index 0000000000000000000000000000000000000000..dcfc4b09cfad39ea91e1f6a9dae423f639d08a35 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/reopenFig.m @@ -0,0 +1,14 @@ +function reopenFig(figname) +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +close(findobj('type','figure','name',figname)) +figure('name',figname); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/vectorToMatrices.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/vectorToMatrices.m new file mode 100644 index 0000000000000000000000000000000000000000..e55ee05fcf2009ca50793f343d17431c14c3451d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/H2T/utils/vectorToMatrices.m @@ -0,0 +1,38 @@ +function [X Y]=vectorToMatrices(x,stateInfo) +% transforms the state vector X +% to matrix representation X and Y +% X and Y are FxN matrices +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +F=stateInfo.F; N=stateInfo.N; +% +X=zeros(F,N); % x-positions +Y=zeros(F,N); % y-positions + +% naive implementation +% targetsExist=stateInfo.targetsExist; +% +% xind=1; +% for i=1:N +% frames=targetsExist(i,1):targetsExist(i,2); +% nFrames=numel(frames); +% X(frames,i)=(x(xind:2:xind+2*nFrames-1)); +% +% Y(frames,i)=(x(xind+1:2:xind+2*nFrames)); +% xind=xind+nFrames*2; +% end + + +% vectorized implementation +tiInd=find(stateInfo.tiToInd); +X(tiInd)=x(1:2:end); +Y(tiInd)=x(2:2:end); + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/README.md b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/README.md new file mode 100644 index 0000000000000000000000000000000000000000..37c10edfea307f4f68c770286133f9d9ae76dbb5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/README.md @@ -0,0 +1,21 @@ +# How to run the SMOT code? + + (1) Clone the code. It will create a smot directory. + + (2) Download the data from [here](http://coe.neu.edu/~cdicle/data/smot_data.zip) and extract it in smot directory. so that you have directory structure like, + + smot> + smot_core + smot_data + smot_test + smot_util + + (3) Check if the dataset path is set correctly in file smot/smot_test/test_smot_batch.m + + (4) Run test_smot_batch.m + + (5) Please cite to the paper + + C. Dicle, M. Sznaier, O. Camps, "The Way They Move: Tracking Targets with Similar Appearance", ICCV 2013. + + [Link to the paper](http://coe.neu.edu/~cdicle/papers/dicle_iccv13.pdf) \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/run_tracker.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/run_tracker.m new file mode 100644 index 0000000000000000000000000000000000000000..b5dbcc649daba37e586e35e42db25482747e2016 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/run_tracker.m @@ -0,0 +1,21 @@ +function [stateInfo, speed] = run_tracker(curSequence, baselinedetections) + +% set random generator +rng('default'); + +%% set parameters +param.similarity_method = 'ihtls'; +param.min_s = 1e-2; % minimum similarity for tracklets +param.mota_th = 0.5; % we want the detections to stay in width/2. +param.debug = false; +param.hor = 30; +param.eta_max = 2; + +%% multi-object tracking +% load detection +idlDetections = txt2idl(baselinedetections, curSequence.frameNums); +% run tracking +[itlf, etime] = smot_associate(idlDetections, param); +speed = numel(curSequence.frameNums)/etime; +% save output for noiseless case +stateInfo = saveResults(itlf, idlDetections, curSequence); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/associate_itl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/associate_itl.m new file mode 100644 index 0000000000000000000000000000000000000000..23ad3240e099eb15cabc5533e08c9353284d7c88 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/associate_itl.m @@ -0,0 +1,93 @@ +function itl = associate_itl(itl,param,horizon) + +N = size(itl,2); + +if nargin == 3 + hormin = horizon(1); + hormax = horizon(2); +else + hormin = -inf; + hormax = +inf; +end + + +% Get the active tracklets in the horizon +itlh = get_itl_horizon(itl,horizon); + +% eliminate very small itls +len = [itlh.length]; +itlh(len<=2) = []; + +if ~isempty(itlh) + % Do merging in the horizon + dN = 1; + + while dN > 0 + if param.debug + figure(11) + drawitl(itlh) + end + + + % Compute similarities + [S,itlh] = compute_itl_similarity_matrix(itlh,param.similarity_method,param.eta_max); + + + % Compute associations + % 1) Use minus similarity, because lapjv solves minimization problem. + assign = generalizedLinearAssignment(-S,-param.min_s); + + + % Do associations + itlh = process_itl_associations(itlh,assign,param); + + Nnew = size(itlh,2); + dN = N - Nnew; + N = Nnew; + + if param.debug + figure(11) + drawitl(itlh) + end + + end + + % merge with real tracklets + itl = set_itl_horizon(itl,itlh,horizon); + + +end + + + + + + + + +% +% function A = compute_itl_associations(S,minS) +% +% % 1) Use minus similarity, because lapjv solves minimization problem. +% A = generalizedLinearAssignment(-S,-minS); +% +% % N = size(S,2); +% +% % 1) Use minus similarity, because lapjv solves minimization problem. +% % 2) Use slack variables to relax sum(X)==1, so if there are very low +% % similarities they will be omitted. Only confident associations will be +% % processed +% +% % S = [S ones(N,N)*minS ]; +% % S = [S; ones(N,2*N)*minS ]; +% % [A,C] = lapjv(-S); +% % A = A(1:N); +% % A(A>N) = 0; +% % 35; +% +% + + + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/compute_itl_similarity_matrix.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/compute_itl_similarity_matrix.m new file mode 100644 index 0000000000000000000000000000000000000000..afc103926ad7260af73ca7af1d117704346dba19 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/compute_itl_similarity_matrix.m @@ -0,0 +1,43 @@ +function [S itl]= compute_itl_similarity_matrix(itl, method, eta_max) + +N = size(itl,2); + +% HEURISTIC: compute a max gap (this is good for speed) +l = [itl.length]; +max_gap = mean(l(l>1))/2; + + +% HEURISTIC: max displacement rate +max_slope = 0; +for i=1:N + dx = abs(itl(i).data(:,1:end-1) - itl(i).data(:,2:end)); + norm_dx = sum(dx.^2).^(1/2); + max_slope = max([max_slope norm_dx]); +end + +% DEBUG +% fprintf('max gap: %.0f\n',max_gap); +% fprintf('max dxy: %.0f\n',max_slope); + + + +% add rank field to the itl structure +% we will use it +if ~isfield(itl,'rank') + itl(1).rank = []; +end +S = -inf*ones(N,N); +for i=1:N + for j=1:N + if i==j + s = -inf; + else +% [s ri rj rij]= similarity_itl_hstln(itl(i),itl(j),eta_max,'maxgap',max_gap,'maxslope',max_slope); + [s ri rj rij] = similarity_itl(itl(i),itl(j),eta_max,'method',method,'maxgap',max_gap,'maxslope',max_slope); + itl(i).rank = ri; + itl(j).rank = rj; + end + + S(i,j) = s; + end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/fast-hstln/fast_hstln_mo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/fast-hstln/fast_hstln_mo.m new file mode 100644 index 0000000000000000000000000000000000000000..c3793056214a2eb9c7ab022e499f7f24234c1498 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/fast-hstln/fast_hstln_mo.m @@ -0,0 +1,202 @@ +function [u_hat,eta,x,mu_eta] = fast_hstln_mo(u,R,varargin) +% function [u_hat,eta,x] = hstln_mo(u,R,x0,Omega) +% +% Hankel Structured Total Least Squares (HSTLN) +% Fits an order R system to the input vector using HSTLN formula +% (A+E)x = b+f +% +% Inputs: +% U: D times N input vector (D: dimension N: length) +% R: order of the fit +% x0 (Optional): initial AR coefficients +% Omega(Optional): 0/1 sampling vector(use this if you miss +% data samples or do not trust some of them) +% Outputs: +% U_h: D times N output vector (filtered output) +% eta: corrections (negative estimated noise) +% x: AR coefficients +% +% +% +% Written by Caglayan Dicle, 07/22/11 based on the paper: +% I. Park, L. Zhang and J.B. Rosen "Low rank approximation of +% a Hankel matrix by structured total least norm" + +[D_u,N_u] = size(u); + +% Default parameters +defTol = 1e-7; +defMaxIter = 100; +defOmega = ones(1,N_u); +defx0 = []; +defEta = zeros(D_u,N_u); +w = 1e8; + + +% Check user input parameters +p = inputParser; + +addParamValue(p,'tol',defTol,@isnumeric); +addParamValue(p,'maxiter',defMaxIter,@isnumeric); +addParamValue(p,'omega',defOmega,@(x) (isnumeric(x) & ~isempty(x)) ); +addParamValue(p,'x0',defx0,@isnumeric); +addParamValue(p,'eta',defEta,@isnumeric); + +parse(p,varargin{:}); + +tol = p.Results.tol; +maxiter = p.Results.maxiter; +Omega = p.Results.omega; +x0 = p.Results.x0; +eta = p.Results.eta; + + + +nc = R+1; +nr = (N_u-nc+1)*D_u; + +% use indexing for hankels +hi = [1:D_u*N_u]; +hi = reshape(hi,[D_u N_u]); +hi = hankel_mo(hi,[nr nc]); + + + + +% make the input sequence hankel +% Ab = mex_hankel_mo(u,[nr nc]); +Ab = u(hi); % fast indexing (hopefully) +% [Ab,d] = hankel_mo(u,[nr nc]); + + +% WARNING: check this!!! +d = ones(1,N_u); + +A = Ab(:,1:end-1); +b = Ab(:,end); + + +% initializations +% WARNING. Pay attention below. eta overwrites x0. +% if ~isequal(eta,eta*0) +% Ef = hankel_mo(eta,[nr nc]); +% E = Ef(:,1:end-1); +% f = Ef(:,end); +% x0 = (A+E)\(b+f); +% end + +if ~isempty(x0) + x = x0; +else + x = A\b; +end + +P1 = [zeros(nr,R*D_u) eye(nr,nr) ]; +P1 = sparse(P1); +% P0 = [eye((N_u-1)*D_u) zeros((N_u-1)*D_u,D_u)]; + +eta = reshape(eta,[D_u*N_u 1]); + + +% if ~isempty(Omega) + % remember D is multiplying eta + D = diag(reshape(repmat(Omega,[D_u 1]),size(eta))); + D = sparse(D); +% D = diag(reshape(repmat(1./d.*Omega,[D_u 1]),size(eta))); % this gives same importance to all samples +% else +% D = diag(reshape(repmat(ones(1,N_u),[D_u 1]),size(eta))); +% end +% else +% D = eye(N_u*D_u); +% D = diag(reshape(repmat(d,[D_u 1]),size(eta))); +% D = diag(reshape(repmat(1./d,[D_u 1]),size(eta))); + +% end +%!!! +Yrow = zeros(1,D_u*(N_u-1)); +YP0 = sparse(nr,D_u*N_u); +ti = 1:nr+1:nr*nr; +% E = zeros(nr,nc-1); + +M = sparse(nr+D_u*N_u,D_u*N_u+R); + +lastwarn(''); +for iter=1:maxiter + + % form matrices +% E = hankel_mo(reshape(eta,size(u)),[nr nc-1]); + E = eta(hi(:,1:end-1)); % fast indexing (hopefully) + + % TODO: construct this better + for j=1:R + YP0(ti+ (j-1)*D_u*nr) = x(j); + end + +% Yrow(1:D_u:D_u*R) = x'; +% Y = toeplitz([Yrow(1,1);zeros(nr-1,1)], Yrow ); + % Y*P0 = [Y|0] +% YP0 = [Y zeros(nr,D_u)]; + + + f = eta(end-nr+1:end); + + % compute r + r = b+f - (A+E)*x; + + % form M +% M = [ w*(P1-YP0) -w*(A+E);... +% D zeros(N_u*D_u,R) ]; +% M = sparse(M); + M(1:nr,1:D_u*N_u) = w*(P1-YP0); + M(1:nr,D_u*N_u+1:D_u*N_u+nc-1) = -w*(A+E); + M(nr+1:end,1:D_u*N_u) = D; + + % solve minimization problem + try + dparam = M\(-[w*r;D*eta]); + error(lastwarn); + catch err + [warnmsg,~] = lastwarn; + if isequal(warnmsg,'MATLAB:rankDeficientMatrix') +% if ~isempty(lastwarn) + lastwarn(''); + break; + end + end +% end + + % update parameters + deta = dparam(1:N_u*D_u,1); + dx = dparam(N_u*D_u+1:end,1); + + eta = eta + deta; + x = x +dx; + + % check convergence +% norm_func = norm([w*r;D*eta]); + norm_dparam = norm(dparam); + +% fprintf('iteration:%d norm_dparam:%g norm_func:%g\n',iter,norm_dparam,norm_func); + + if 0 + figure(11) +% plot([u' (u+reshape(eta,size(u)))']); + plot(u','k.');hold on; + plot(u+reshape(eta,size(u))','g-'); + end + + if norm_dparam = hormax); +f = ~f; +itlh = itl(f); +id = [1:N]; +id = id(f); + +for n=1:size(itlh,2) + % check start + si = max(hormin - itlh(n).t_start, 0); + ei = max(itlh(n).t_end - hormax, 0); + + itlh(n).data = itlh(n).data(:,1+si:end-ei); + itlh(n).omega = itlh(n).omega(1+si:end-ei); + itlh(n).t_start = max(itlh(n).t_start, hormin); + itlh(n).t_end = min(itlh(n).t_end, hormax); + itlh(n).length = itlh(n).t_end - itlh(n).t_start + 1; + +end + +% add id field which will be useful putting back the horizon +if ~isempty(id) + id = num2cell(id); + [itlh.id] = deal(id{:}); +end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/growitl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/growitl.m new file mode 100644 index 0000000000000000000000000000000000000000..e023d8327003e221d063ad31b786cf3321bd8dfe --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/growitl.m @@ -0,0 +1,72 @@ +function itl = growitl(itl,max_D) + +N_itl = size(itl,2); + +done = false; +l = []; +% TODO: write this loop better +while ~done + + % find length 1 itls +% idx1 = find(itl.length==1); + + 35; + + + + + + + for i=1:N_itl + for j=1:N_itl + gap = (itl(j).t_start - itl(i).t_end) - 1; + if gap == 0 + if itl(i).length == 1 && itl(j).length > 1 + % grow to past + xy_j = itl(j).data(:,2:-1:1); + xy_i = itl(i).data; + % order 1 comprasion + xy_i_hat = 2*xy_j(:,2) - xy_j(:,1); + d = sum((xy_i - xy_i_hat).^2); + if d < max_D + itl(j) = mergeitl(itl(i),itl(j)); + itl(i).t_start = -inf; + itl(i).t_end = -inf; + l = [l i]; % add to delete list +% N_itl = N_itl-1; +% done = false; + end + elseif itl(i).length > 1 && itl(j).length == 1 + % grow to future + xy_j = itl(j).data; + xy_i = itl(i).data(:,end-1:end); + % order 1 comprasion + xy_j_hat = 2*xy_i(:,2) - xy_i(:,1); + d = sum((xy_j - xy_j_hat).^2); + if d < max_D + itl(i) = mergeitl(itl(i),itl(j)); + itl(j).t_start = -inf; + itl(j).t_end = -inf; + l = [l j]; % add to delete list +% N_itl = N_itl-1; +% done = false; + end + else + % if they are both length 1 + % do nothing + end + end + end + end + + if isempty(l) + done = true; + else + itl(l) = []; + l = []; + N_itl = size(itl,2); + end + +% dN_itl = N_itl - size(itl,2); +% N_itl = size(itl_2); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/mergeitl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/mergeitl.m new file mode 100644 index 0000000000000000000000000000000000000000..475333686a20547c8d773debebef56f4efa290ad --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/mergeitl.m @@ -0,0 +1,54 @@ +function itl1 = mergeitl(itl1,itl2,param) + +% merge itl1-->itl2 1: past 2: future + +% or itl2 into itl1 + +gap = itl2.t_start - itl1.t_end - 1; +rank12 = []; + +interpolation = 2; +% end-to-end +if gap >= 0 + + % do an interpolation temporarily. This will be overwritten, it mainly + % serves visual purposes. + switch interpolation + case 1 % just put nan + int_xy = nan(2,gap); + itl1.data = [itl1.data int_xy itl2.data]; + case 2 % first order interpolation + dxy = (itl1.data(:,end) - itl2.data(:,1) )/(gap+1); + int_xy = itl1.data(:,end)*ones(1,gap) - dxy * [1:gap]; + itl1.data = [itl1.data int_xy itl2.data]; + case 3 % min rank interpolation + xy12 = [itl1.data zeros(2,gap) itl2.data]; + omega12 = [itl1.omega zeros(1,gap) itl2.omega]; + [xy12_hat,~,~,rank12] = incremental_hstln_mo(xy12,param.eta_max,... + 'omega',omega12,... + 'minrank',min(itl1.rank,itl2.rank),... + 'maxrank',itl1.rank+itl2.rank); +% int_xy = xy12_hat(:,itl1.length+1:itl1.length+gap); +% t_xy = [itl1.xy zeros(2,gap) itl2.xy]; + itl1.data = bsxfun(@times,xy12,omega12) + bsxfun(@times,xy12_hat,(1-omega12)); + end + + % itl1.rect = [itl1.rect int_rect itl2.rect]; + itl1.t_end = itl2.t_end; + itl1.length = itl1.length + itl2.length + gap; + + % itl1.xy_end = itl2.xy_end; + itl1.omega = [itl1.omega zeros(1,gap) itl2.omega]; + +% into +elseif (itl2.t_start > itl1.t_start ) && (itl2.t_end < itl1.t_end) + rt_start = itl2.t_start - itl1.t_start + 1; + rt_end = rt_start + itl2.length - 1; + + itl1.data(:,rt_start:rt_end) = itl2.data; + itl1.omega(rt_start:rt_end) = itl2.omega; +end + +if isfield(itl1,'rank') + itl1.rank = rank12; +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/process_itl_associations.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/process_itl_associations.m new file mode 100644 index 0000000000000000000000000000000000000000..eb98ee603820b75a03d314d23edc5804c764cd23 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/process_itl_associations.m @@ -0,0 +1,20 @@ +function itl = process_itl_associations(itl,assign,param) + +% take a copy of A. We will manipulate it. +assign_0 = assign; +for i=1:length(assign) + + j = i; + while assign(j)~=0 + % merge two itls considering the gap in between + itl(i) = mergeitl(itl(i),itl(assign(j)),param); + % book keep the id of merges + itl(i).id = [itl(i).id itl(assign(j)).id]; + % next + jnext = assign(j); + assign(j) = 0; + j = jnext; + end +end +assign = assign_0; +itl(assign(assign>0)) = []; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/set_itl_horizon.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/set_itl_horizon.m new file mode 100644 index 0000000000000000000000000000000000000000..86ede71e4ee92c75275f4baab42d6e37512067bb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/set_itl_horizon.m @@ -0,0 +1,22 @@ +function itl_dst = set_itl_horizon(itl_dst,itl_src,horizon) + +Nh = size(itl_src,2); + +hormin = horizon(1); +hormax = horizon(2); + +% WARNING: I am remerging the tracklets (inefficient coding) +idklog = []; +for n=1:Nh + K = length(itl_src(n).id); + if K>1 + id1 = itl_src(n).id(1); + for k = 2:K + idk = itl_src(n).id(k); + itl_dst(id1) = mergeitl(itl_dst(id1),itl_dst(idk)); + idklog = [idklog idk]; + end + end +end + +itl_dst(idklog) = []; diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/similarity_itl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/similarity_itl.m new file mode 100644 index 0000000000000000000000000000000000000000..48410034705561f891e56f4495070177d99eaab0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/similarity_itl.m @@ -0,0 +1,88 @@ +function [s r1 r2 r12] = similarity_itl(itl1,itl2,eta_max,varargin) + + +defMaxHorizon = inf; +defMaxGap = inf; +defMaxSlope = inf; +defMethod = 'ihtls'; + +% Check user input parameters +p = inputParser; + +addParamValue(p,'maxhorizon',defMaxHorizon,@isnumeric); +addParamValue(p,'maxgap',defMaxGap,@isnumeric); +addParamValue(p,'maxslope',defMaxSlope,@isnumeric); +addParamValue(p,'method',defMethod,@ischar); +parse(p,varargin{:}); + + +hor_max = p.Results.maxhorizon; +gap_max = p.Results.maxgap; +slope_max = p.Results.maxslope; +method = p.Results.method; + + + +% check if they are compatible +% two options +% 1) if itl2 comes later than itl1 +% 2) if itl2 goes into itl1 + +%% Individual Ranks +r1 = itl1.rank; +r2 = itl2.rank; +r12 = inf; +s = -inf; +r12 = inf; + +% If they are both very short tracklets they are unreliable +if itl1.length <= 2 && itl2.length <= 2 + return; +end + + +%% Joint Rank + +gap = itl2.t_start - itl1.t_end - 1; +slope = norm(itl2.data(:,1) - itl1.data(:,end),'fro')/(gap+1); + +% HEURISTIC: avoid very large gaps, very sharp slopes + +if gap >= 0 && gap < gap_max && slope < (slope_max*2) + % itl2 comes after itl1 + + [s r1 r2 r12] = smot_similarity(itl1.data,itl2.data,eta_max,... + 'gap',gap,... + 'rank1',itl1.rank,'rank2',itl2.rank,... + 'omega1',itl1.omega,'omega2',itl2.omega,... + 'method',method); + + + + + + +elseif 0 & (itl2.t_start > itl1.t_start ) && (itl2.t_end < itl1.t_end) + % itl2 may be a missing part for itl1 + % check omegas now + rt_start = itl2.t_start - itl1.t_start + 1; + rt_end = rt_start + itl2.length - 1; + if sum(itl1.omega(rt_start:rt_end)==0) == itl2.length + % compute the joint rank + rmax = r1+r2; + + % TODO: Rewrite the following + [s r1 r2 r12] = smot_similarity([itl1.data(:,1:rt_start-1) itl2.data itl1.data(:,rt_end+1:end)],eta_max,... + 'gap',gap,... + 'rank1',itl1.rank,'rank2',itl2.rank,... + 'omega1',itl1.omega,'omega2',itl2.omega); + + %'omega',[itl1.omega(1:rt_start-1) itl2.omega itl1.omega(rt_end+1:end)]); + + + end + + +else + +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/similarity_itl_hstln.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/similarity_itl_hstln.m new file mode 100644 index 0000000000000000000000000000000000000000..fc29015edd6f03d1e0e0ee4d21ad72c9e3c1fcd0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/similarity_itl_hstln.m @@ -0,0 +1,108 @@ +function [s r1 r2 r12] = similarity_itl_hstln(itl1,itl2,eta_max,varargin) + +defMaxHorizon = inf; +defMaxGap = inf; +defMaxSlope = inf; + +% Check user input parameters +p = inputParser; + +addParamValue(p,'maxhorizon',defMaxHorizon,@isnumeric); +addParamValue(p,'maxgap',defMaxGap,@isnumeric); +addParamValue(p,'maxslope',defMaxGap,@isnumeric); +parse(p,varargin{:}); + + +hor_max = p.Results.maxhorizon; +gap_max = p.Results.maxgap; +slope_max = p.Results.maxslope; + + +% check if they are compatible +% two options +% 1) if itl2 comes later than itl1 +% 2) if itl2 goes into itl1 + +%% Individual Ranks +% check if they have ranks computed +if isempty(itl1.rank) + if itl1.length <= 2 + r1 = itl1.length; + else + xy = itl1.xy; + xy(isnan(xy)) = 0; + [~,~,~,r1] = incremental_hstln_mo(xy,eta_max,'omega',itl1.omega); + end +else + r1 = itl1.rank; +end + +if isempty(itl2.rank) + if itl2.length <= 2 + r2 = itl2.length; + else + xy = itl2.xy; + xy(isnan(xy)) = 0; + [~,~,~,r2] = incremental_hstln_mo(xy,eta_max,'omega',itl2.omega); + end +else + r2 = itl2.rank; +end + +s = -inf; +r12 = inf; + +% If they are both very short tracklets they are unreliable +if itl1.length <= 2 && itl2.length <= 2 + return; +end + + +%% Joint Rank + +gap = itl2.t_start - itl1.t_end - 1; +slope = norm(itl2.xy(:,1) - itl1.xy(:,end),'fro')/(gap+1); + +if gap >= 0 && gap < gap_max && slope < (slope_max*2) + % itl2 comes after itl1 + + + % compute joint rank + rmax = r1+r2; + [~,~,~,r12] = incremental_hstln_mo([itl1.xy zeros(2,gap) itl2.xy],eta_max,... + 'minrank',max(r1,r2),... + 'maxrank',rmax,... + 'omega',[itl1.omega zeros(1,gap) itl2.omega]); + +% s = (r1+r2)/r12 - 1; +% s = max(r1,r2)/r12; + s = 1 / (1+r12-max(r1,r2)); + + +elseif (itl2.t_start > itl1.t_start ) && (itl2.t_end < itl1.t_end) + % itl2 may be a missing part for itl1 + % check omegas now + rt_start = itl2.t_start - itl1.t_start + 1; + rt_end = rt_start + itl2.length - 1; + if sum(itl1.omega(rt_start:rt_end)==0) == itl2.length + % compute the joint rank + rmax = r1+r2; + [~,~,~,r12] = incremental_hstln_mo([itl1.xy(:,1:rt_start-1) itl2.xy itl1.xy(:,rt_end+1:end)],eta_max,... + 'minrank',max(r1,r2),... + 'maxrank',rmax,... + 'omega',[itl1.omega(1:rt_start-1) itl2.omega itl1.omega(rt_end+1:end)]); + +% s = (r1+r2)/r12 - 1; +% s = max(r1,r2)/r12; + s = 1 / (1+r12-max(r1,r2)); + 35; + + end + + +else + +end + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/similarity_itl_nucnorm.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/similarity_itl_nucnorm.m new file mode 100644 index 0000000000000000000000000000000000000000..818ce8db8f781d43a8b338025be3d4ba9d790127 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/similarity_itl_nucnorm.m @@ -0,0 +1,71 @@ +function [s r1 r2 r12] = similarity_itl_hstln(itl1,itl2,eta_max,varargin) + +defMaxHorizon = inf; +defMaxGap = inf; + +% Check user input parameters +p = inputParser; + +addParamValue(p,'maxhorizon',defMaxHorizon,@isnumeric); +addParamValue(p,'maxgap',defMaxGap,@isnumeric); +parse(p,varargin{:}); + + +hor_max = p.Results.maxhorizon; +gap_max = p.Results.maxgap; + + +% check if they are compatible +% two options +% 1) if itl2 comes later than itl1 +% 2) if itl2 goes into itl1 + +% check if they have ranks computed +if isempty(itl1.rank) + if itl1.length < 2 + r1 = 1; + else + [~,~,~,r1] = incremental_hstln_mo(itl1.xy,eta_max,'omega',itl1.omega); + end +else + r1 = itl1.rank; +end + +if isempty(itl2.rank) + if itl2.length < 2 + r2 = 1; + else + [~,~,~,r2] = incremental_hstln_mo(itl2.xy,eta_max,'omega',itl2.omega); + end +else + r2 = itl2.rank; +end + +s = -inf; +r12 = inf; + + +gap = itl2.t_end - itl1.t_start - 1; + +if gap >= 0 && gap < gap_max + % itl2 comes after itl1 + + % compute joint rank + rmax = r1+r2; + [~,~,~,r12] = incremental_hstln_mo([itl1.xy zeros(2,gap) itl2.xy],eta_max,... + 'minrank',min(r1,r2),... + 'maxrank',rmax,... + 'omega',[itl1.omega zeros(1,gap) itl2.omega]); + + s = (r1+r2)/r12 - 1; + + +elseif (itl2.t_start > itl1.t_start ) && (itl2.t_end < itl1.t_end) + % itl2 may be a missing part for itl1 + % check omegas now + 35; +else + +end + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_associate.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_associate.m new file mode 100644 index 0000000000000000000000000000000000000000..b5cba1c6607b6bc47ed9e4cee6bae89fba7bbbaf --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_associate.m @@ -0,0 +1,84 @@ +function [itl, etime]= smot_associate(idl,param) + +tic; +T = size(idl,2); +W = param.hor; + + +% generate initial tracklets +if isfield(param,'mu') + itl = idl2itl_psu(idl,param.conflict_ratio,param.mu); +else + itl = idl2itl(idl); +end + +% FIX: Naming data is more appropriate than xy, because we might have +% multidimensions +% itl.data = itl.xy; +% itl = rmfield(itl,'xy'); + +% grow the tracklets +if 1 + itl = growitl(itl,param.eta_max); +end + + +% WARNING: Poor coding practice below. for loops might be combined in a +% better way. + +% Do windowed stitching + +% PASS I +% fprintf('pass 1 is in progress\n'); +for t = 1:W:T-1 + + if param.debug + figure(2) + drawitl(itl); + end + + % apply association + % FIX: eliminate very small tracklets, we do not need them. + % They are error prone at this stage + len = [itl.length]; + itl(len<=2) = []; + itl = associate_itl(itl,param,[t t+W-1]); +end +% PASS II +% fprintf('pass 2 is in progress\n'); +for t = floor(W/2):W:T-1 + + if param.debug + figure(2) + drawitl(itl); + end + + % apply association + % FIX: eliminate very small tracklets, we do not need them. + % They are error prone at this stage + len = [itl.length]; + itl(len<=2) = []; + itl = associate_itl(itl,param,[t t+W-1]); +end + + +% PASS III +% Last pass with a twice the horizon +% fprintf('final pass, might take more time than previous passes!\n'); +W = W*2; +for t = 1:W:T-1 + + if param.debug + figure(2) + drawitl(itl); + end + + % apply association + % FIX: eliminate very small tracklets, we do not need them. + % They are error prone at this stage + len = [itl.length]; + itl(len<=4) = []; + itl = associate_itl(itl,param,[t t+W-1]); +end + +etime = toc; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_associate_idl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_associate_idl.m new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_associate_itl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_associate_itl.m new file mode 100644 index 0000000000000000000000000000000000000000..00476e9d870e64c64df84ee9a34b00e646c01745 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_associate_itl.m @@ -0,0 +1,97 @@ +function [itl etime]= smot_associate_itl(itl,param) + +tic; + +W = param.hor; +T_start = min([itl.t_start]); +T_end = max([itl.t_end]); + + + +% WARNING: Poor coding practice below. for loops might be combined in a +% better way. + +% Do windowed stitching + +% PASS I +fprintf('pass 1 is in progress\n'); +for t = T_start : W : T_end-1 + +if param.debug +figure(2) +drawitl(itl); +end + +% apply association +% FIX: eliminate very small tracklets, we do not need them. +% They are error prone at this stage + +len = [itl.length]; +itl(len<=2) = []; + +itl = associate_itl(itl,param,[t t+W-1]); + +end + + +% PASS II +fprintf('pass 2 is in progress\n'); +for t = T_start+floor(W/2)-1 : W : T_end-1 + +if param.debug +figure(2) +drawitl(itl); +end + +% apply association + +% FIX: eliminate very small tracklets, we do not need them. +% They are error prone at this stage + +len = [itl.length]; +itl(len<=2) = []; + +itl = associate_itl(itl,param,[t t+W-1]); + +end + +if 0 +% PASS III +% Last pass with a twice the horizon +fprintf('final pass, might take more time than previous passes!\n'); +W = W*2; +for t = T_start : W : T_end-1 + +if param.debug +figure(2) +drawitl(itl); +end + +% apply association + +% FIX: eliminate very small tracklets, we do not need them. +% They are error prone at this stage + +len = [itl.length]; +itl(len<=4) = []; + +itl = associate_itl(itl,param,[t t+W-1]); + +end + +end + +etime = toc; +% % do a final association among windows +% % FIX: eliminate very small tracklets, we do not need them. +% % They are error prone at this stage +% len = [itl.length]; +% itl(len<=2) = []; +% +% itl = associate_itl(itl,param); +% +% figure(1) +% drawidl(idl); +% +% figure(2) +% drawitl(itl); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_rank_admm.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_rank_admm.m new file mode 100644 index 0000000000000000000000000000000000000000..0fdf0262b36e4383845ea1c73eabd73c175e64a2 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_rank_admm.m @@ -0,0 +1,55 @@ +function R = smot_rank_admm(x,eta,varargin) + +[D,N] = size(x); + +nr = ceil(N/(D+1))*D; +nc = N - ceil(N/(D+1))+1; + +defMaxRank = min([nr nc]); +defMinRank = 1; +defOmega = ones(1,N); +defLambda = 0.1; + +% Check user input parameters +p = inputParser; + +addParamValue(p,'maxrank',defMaxRank,@isnumeric); +addParamValue(p,'minrank',defMinRank,@isnumeric); +addParamValue(p,'omega',defOmega,(@(x) (isnumeric(x)|islogical(x)))); +addParamValue(p,'lambda',defLambda,@isnumeric); +parse(p,varargin{:}); + + +R_max = p.Results.maxrank; +R_max = min([nr nc R_max]); +R_min = p.Results.minrank; +omega = p.Results.omega; +lambda = p.Results.lambda; + + +% if omega has a 0 needs inpainting +if sum(omega==0)>0 + % do inpainting + % mustafa's code requires scaling to (0-1) +% maxx = max(x(:)); +% tx = x/maxx; +% tx_hat = l2_fastalm_mo(tx,lambda,'omega',omega); +% x = tx_hat*maxx; + x = l2_fastalm_mo(x,lambda,'omega',omega); +% [x ~] = cvx_min_hankel_rank_con(x,eta,omega); + 35; +end + + +H = hankel_mo(x,[0 R_max]); + +s = svd(H); +R = sum(s>eta); + +% I am not sure if necessary +% if RR_max +% warning('rank out of range!'); +% end +R = max(R_min,R); +R = min(R_max,R); + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_rank_ihtls.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_rank_ihtls.m new file mode 100644 index 0000000000000000000000000000000000000000..944e9ffbb5b52ff9f11fff11963311e131187f1f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_rank_ihtls.m @@ -0,0 +1,70 @@ +function R = smot_rank_ihtls(u,eta_max,varargin) + +[D_u,N_u] = size(u); + +nr = ceil(N_u/(D_u+1))*D_u; +nc = N_u - ceil(N_u/(D_u+1))+1; + +defMaxRank = min([nr nc]); +defMinRank = 1; +defOmega = ones(1,N_u); + +% Check user input parameters +p = inputParser; + +addParamValue(p,'maxrank',defMaxRank,@isnumeric); +addParamValue(p,'minrank',defMinRank,@isnumeric); +addParamValue(p,'omega',defOmega,@isnumeric); +parse(p,varargin{:}); + + +R_max = p.Results.maxrank; +R_max = min([nr nc R_max]); +R_min = p.Results.minrank; +Omega = p.Results.omega; + +% TRY to estimate minimum rank(save time) +% WARNING: This might be problematic because this does not consider missing +% values! +H = hankel_mo(u); +s = svd(H); +HnormFrosq = sum(s.^2); +Hnorm2sq = s(1).^2; +HnormNucsq = sum(s)^2; +R_FroI2 = floor(HnormFrosq/Hnorm2sq); +R_NucIFro = floor(HnormNucsq/HnormFrosq); +R_Heuristic = 0; %sum(s>s(1)*0.1); % useless + +% if (R_min < R_FroI2) || (R_min0 + % do inpainting + [x ~] = cvx_min_hankel_rank_con(x,eta,omega); + 35; +end + + +H = hankel_mo(x,[0 R_max]); + +s = svd(H); +R = sum(s>eta); + +% I am not sure if necessary +if RR_max +% warning('rank out of range!'); +end +R = max(R_min,R); +R = min(R_max,R); + + + + +function [xhat g] = cvx_min_hankel_rank_uncon(x,eta,omega) + +[D,N] = size(x); +Ngap = sum(omega==0); + +nr = ceil(N/(D+1))*D; +nc = N - ceil(N/(D+1))+1; + +xhat = x; + + +cvx_quiet(true); +cvx_clear; +cvx_begin sdp + + + + variable g(D,Ngap); % missing variables in x + variable Y(nr,nr) symmetric; + variable Z(nc,nc) symmetric; + + % interleaving knowns with unknowns + idx = [1:N]; + idx(omega==0) = [N+1:N+Ngap]; + xgap = [x g]; + xhat = xgap(:,idx); + + + + H = cvx_hankel_mo(xhat,[nr nc]); + + minimize trace(Y) + trace(Z); + subject to + [Y H;H' Z]>=0; + + +cvx_end +cvx_quiet(false); + + +35; + + +function [xhat g] = cvx_min_hankel_rank_con(x,eta,omega) + +[D,N] = size(x); +Ngap = sum(omega==0); + +nr = ceil(N/(D+1))*D; +nc = N - ceil(N/(D+1))+1; + +cvx_quiet(true); +cvx_clear; +cvx_begin sdp + + variable xhat(D,N); % missing variables in x + variable Y(nr,nr) symmetric; + variable Z(nc,nc) symmetric; + + % interleaving knowns with unknowns +% idx = [1:N]; +% idx(omega==0) = [N+1:N+Ngap]; +% xgap = [x g]; +% xhat = xgap(:,idx); + + + + H = cvx_hankel_mo(xhat,[nr nc]); + + minimize trace(Y) + trace(Z); + subject to + [Y H;H' Z]>=0; + norm((x-xhat).*(ones(D,1)*omega),'fro')/sum(omega) <= eta; +cvx_end +cvx_quiet(false); + +g = []; +35; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_similarity.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_similarity.m new file mode 100644 index 0000000000000000000000000000000000000000..5f36f2ed8d98aee1082fa8a1179cfb55a831180d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_similarity.m @@ -0,0 +1,140 @@ +function [s rank1 rank2 rank12] = smot_similarity(x1,x2,eta,varargin) + +% INPUTS: +% x1: trajectory 1 DxT (past) +% x2: trajectory 2 DxT (future) +% D: dimension of the signal +% T: length of the signal +% eta: noise estimate (std of noise) +% +% OPTIONS: +% gap : gap between x1 and x2 +% omega1 : used for unknown points in the trajectory +% omega2 : used for unknown points in the trajectory +% rank1 : rank of x1. if known saves time. +% rank2 : rank of x2. if known saves time. +% type : distance type (hstln default) +% qcheck : quick check if trajectories are dynamically compatible. +% qcheck may void some real pairs. + + + +[D1 T1 ]= size(x1); +[D2 T2 ]= size(x2); + + +% Some error checks +if D1 ~= D2 + error('Input dimensions do not agree. They should have same number of columns!'); +end + + +% Do usual parameter parsing + +% Defaults +% defMaxRank = min([nr nc]); +% defMinRank = 1; +defGap = 0; +defOmega1 = ones(1,T1); +defOmega2 = ones(1,T1); +defRank1 = 0; +defRank2 = 0; +defMethod = 'ihtls'; +defQCheck = false; +% defRankFunc = @smot_rank_ihtls; + + + + +% Check user input parameters +p = inputParser; + +addParamValue(p,'gap',defGap,@isnumeric); +addParamValue(p,'omega1',defOmega1,@isnumeric); +addParamValue(p,'omega2',defOmega2,@isnumeric); +addParamValue(p,'rank1',defRank1,@isnumeric); +addParamValue(p,'rank2',defRank2,@isnumeric); +addParamValue(p,'method',defMethod,@ischar); +addParamValue(p,'qcheck',defQCheck,@islogical); +parse(p,varargin{:}); + +gap = p.Results.gap; +omega1 = p.Results.omega1; +omega2 = p.Results.omega2; +rank1 = p.Results.rank1; +rank2 = p.Results.rank2; +method = p.Results.method; +qcheck = p.Results.qcheck; + +% smot_rank_func = @smot_rank_ihtls; +% smot_rank_func = @smot_rank_tao; + +rank1 = []; +rank2 = []; +rank12 = []; + +switch lower(method) + case {'ihtls','ip','admm'} + % TODO: set rank func here + smot_rank_func = str2func(['smot_rank_' method]); + % Compute rank1 + if isempty(rank1) + rank1 = smot_rank_func(x1,eta,'omega',omega1); + end + % Compute rank2 + if isempty(rank2) + rank2 = smot_rank_func(x2,eta,'omega',omega2); + end + + % try early elimination + if qcheck + nr = min(T1-rank1,T2-rank2); + % round + nr = floor(nr/D1)*D1; + H1 = hankel_mo(x1,[nr 0]); + H2 = hankel_mo(x2,[nr 0]); + + rank12 = sum(svd([H1 H2])>eta); + + if rank12 > (rank1+rank2) + s = -inf; + return; + end + end + + + + % Compute joint rank + x12 = [x1 zeros(D1,gap) x2]; + omega12 = [omega1 zeros(1,gap) omega2]; + rank12 = smot_rank_func(x12,eta,'omega',omega12,... + 'minrank',min(rank1,rank2),... + 'maxrank',rank1+rank2); + + + % Compute similarity measure +% drank = rank12-max(rank1,rank2); + % FIX: Sometimes drank<0 +% drank = max(0,drank); +% s = 1 / (1+drank); + % TAO + s = (rank1+rank2)/rank12 - 1; + % TRY +% drank = rank12-max(rank1,rank2); +% s = 1 - drank/min(rank1,rank2); + + if s < 1e-5 + s = -inf; + end + + + case 'binlong' + s = smot_similarity_binlong(x1,x2,gap); +% case 'svd', +% case 'subspace', +% case 'cordeilla', +% case 'grammian', +end + + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_similarity_binlong.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_similarity_binlong.m new file mode 100644 index 0000000000000000000000000000000000000000..aa726ad3f7a6ade9d1c36d7fffef5e2ab291114c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/smot_similarity_binlong.m @@ -0,0 +1,58 @@ +function s = smot_similarity_binlong(x1,x2,gap) + + + +[D1, N1] = size(x1); +[D2, N2] = size(x2); + +if D1 ~= D2 + error('Input dimensions do not agree. They should have same number of columns!'); +end + +%%%% TRYYY +% extend the data with time tag +x1 = [x1;1:N1]; +x2 = [x2;N1+gap+(1:N2)]; +D1 = D1+1; +D2 = D2+1; +%%%%% TRYYYYY + +% compute max column size +N = max(N1,N2); +D = D1; +nr = ceil(N/(D+1))*D; +nc = N - ceil(N/(D+1))+1; + +% check if row size agrees with short tracklet +nr = min([nr N1 N2]); +nr = floor(nr/D)*D; + +% form the Hankel matrices +% hankel_mo will automatically calculate number of columns +H1 = hankel_mo(x1,[nr 0]); +H2 = hankel_mo(x2,[nr 0]); +% H12 = [H1 H2]; + +H1h = H1 / norm(H1*H1','fro').^(1/2); +H2h = H2 / norm(H2*H2','fro').^(1/2); + +[U1 S1 V1] = svd(H1h); +[U2 S2 V2] = svd(H2h); + +% TRY 1 +U1h = U1*S1; +U2h = U2*S2; +s = subspace(U1h,U2h); + +% TRY 2 + + +% H12h = H12 / norm(H12*H12','fro'); + +% if N1>N2 +% H1h = H1 / norm(H1*H1','fro'); +% s = norm(H12h*H12h' + H1h*H1h'); +% else +% H2h = H2 / norm(H2*H2','fro'); +% s = norm(H12h*H12h' + H2h*H2h'); +% end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/test_grammian_rank.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/test_grammian_rank.m new file mode 100644 index 0000000000000000000000000000000000000000..188cb032c7273184d29585def4def59c318070e5 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_core/test_grammian_rank.m @@ -0,0 +1,17 @@ +N = 5; +x = [1:N]; +omega = ones(1,N); + +% x(5) = 0; +% omega(5) = 0; +x(4) = 0; +omega(4) = 0; + +Hx = hankel_mo(x); +Ho = hankel_mo(omega); + +Gx = Hx'*Hx; +Go = Ho'*Ho; + +svd(Hx) +svd(Gx./Go) \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/initialize_smot.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/initialize_smot.m new file mode 100644 index 0000000000000000000000000000000000000000..c26946ea3af6653eccee422b27a7ce747d8678b0 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/initialize_smot.m @@ -0,0 +1,105 @@ +%% COMMON PARAMETERS +param.similarity_method = method; +param.min_s = 1e-2; % minimum similarity for tracklets +param.mota_th = 0.5; % we want the detections to stay in width/2. +param.debug = false; + +%% DATASET + +seqPath = [datasetPath '/' seqName '/img']; +itlName = [datasetPath '/' seqName '/' seqName '.itl']; +savePath = [datasetPath '/' seqName '/' method ]; +if ~exist(savePath,'dir') && saveOutput + mkdir(savePath) +end + +% SMOT dataset +if ~isempty(strfind(['dribbling,slalom,juggling,crowd,acrobats,firebirds,seagulls,balls,tud-crossing,tud-campus'],seqName)) + % get the information about the sequence + itl0 = loaditl(itlName); +end + +% PSU dataset +if ~isempty(strfind(['psu-sparse,psu-dense'],seqName)) + switch(seqName(5:end)) + case 'sparse', segi = 1; + case 'dense', segi = 3; + end + [X,Y,targetIDs] = read_traj_block(segi,keyId,0,10,datasetPath); + itl0 = psu2itl(X,Y,targetIDs); +end + +% convert itls to idl +idl0 = itl2idl(itl0); + + +%% PARAMETERS + +switch seqName +%%%% SMOT dataset (Labelled with pdollars tool) + + case 'dribbling', + param.hor = 40; param.eta_max = 3; + case 'slalom', + param.hor = 80; param.eta_max = 3; + case 'juggling', + param.hor = 40; param.eta_max = 3; + case 'crowd', + param.hor = 60; param.eta_max = 3/2; + case 'acrobats' + param.hor = 40; param.eta_max = 3/2; + case 'firebirds' + param.hor = 40; param.eta_max = 3; + case 'seagulls' + param.hor = 40; param.eta_max = 3; + case 'balls' + param.hor = 40; param.eta_max = 3/2; + case 'tud-crossing' + param.hor = 60; param.eta_max = 3/8; + case 'tud-campus' + param.hor = 60; param.eta_max = 3/4; +%%%% SMOT dataset (Labelled with pdollars tool) + + +%%%% PSU HUB dataset + case 'psu-sparse', + param.hor = 60; param.eta_max = 3/2; param.conflict_ratio = 3/2; param.mu = 25; + case 'psu-dense', + param.hor = 60; param.eta_max = 3/2; param.conflict_ratio = 3/2; param.mu = 25; +%%%% PSU HUB dataset + otherwise + error('Unknown sequence!'); +end + +if isequal(method,'ksp') + + error('KSP method is not supported in shared version. Sorry!'); + % executable for ksp + kspRun = '/home/caglayan/research/code/c/work/epfl_ksp/ksp1_1/ksp'; + param.ksp_run = kspRun; + + % get the image width height + hseq = seqreader(seqPath); + param.img.width = hseq.Width; + param.img.height = hseq.Height; + clear hseq; + + % temporary ksp setup file folder + kspConfPath = [ datasetPath '/' seqName '/ksp_conf' ]; + if ~exist(kspConfPath,'dir') && saveOutput + mkdir(kspConfPath); + end + INPUT_FORMAT = [ kspConfPath '/prob_f%05d.dat']; + param.input_format = INPUT_FORMAT; + param.ksp_conf_path = kspConfPath; + + % parameters to play + N_GRID_X = 64; % Grid size + N_GRID_Y = 64; + param.grid.nx = N_GRID_X; + param.grid.ny = N_GRID_Y; + + DEPTH = 3; + param.depth = DEPTH; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/saveResults.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/saveResults.m new file mode 100644 index 0000000000000000000000000000000000000000..2965bb6f1b57042002ee36b513bda90864b370c7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/saveResults.m @@ -0,0 +1,77 @@ +function stateInfo = saveResults(itlfResult, detections, curSequence) + +num_frame = length(curSequence.frameNums); +num_obj = length(itlfResult); +stateInfo = []; + +stateInfo.F = num_frame; +stateInfo.X = zeros(num_frame,num_obj); +stateInfo.Y = zeros(num_frame,num_obj); +stateInfo.frameNums = 1:num_frame; +stateInfo.Xgp = zeros(num_frame,num_obj); +stateInfo.Ygp = zeros(num_frame,num_obj); +stateInfo.Xi = zeros(num_frame,num_obj); +stateInfo.Yi = zeros(num_frame,num_obj); +stateInfo.H = zeros(num_frame,num_obj); +stateInfo.W = zeros(num_frame,num_obj); +left = zeros(num_frame,num_obj); +top = zeros(num_frame,num_obj); +right = zeros(num_frame,num_obj); +down = zeros(num_frame,num_obj); + +for i = 1:num_obj + Obj = itlfResult(i); + cnt = 0; + fr = []; + newLoc = []; + for frame = Obj.t_start:Obj.t_end + cnt = cnt + 1; + loc = Obj.data(:,cnt); + if(~isempty(detections(frame).xy)) + dist = pdist2(loc',detections(frame).xy); + id = dist == min(dist); + pos = detections(frame).rect(id,:); + if(dist(id)==0) + State(1) = pos(1) + pos(3)/2; + State(2) = pos(2) + pos(4)/2; + State(3) = pos(3); + State(4) = pos(4); + else + State(1) = loc(1); + State(2) = loc(2); + State(3) = pos(3); + State(4) = pos(4); + end + + % i: Label + % frame: frame index + stateInfo.X(frame,i) = State(1); + stateInfo.Y(frame,i) = State(2)+State(4)/2; + stateInfo.Xgp(frame,i) = State(1); % X position + stateInfo.Ygp(frame,i) = State(2); % Y position + stateInfo.Xi(frame,i) = State(1); + stateInfo.Yi(frame,i) = State(2)+State(4)/2; + stateInfo.W(frame,i) = State(3); % Width + stateInfo.H(frame,i) = State(4); % Height + + left(frame,i) = State(1)-State(3)/2; + top(frame,i) = State(2)-State(4)/2; + right(frame,i) = State(1)+State(3)/2; + down(frame,i) = State(2)+State(4)/2; + if(dist(id)~=0) + fr = cat(2, fr, frame); + newLoc = cat(1, newLoc, loc'); + end + end + end + if(~isempty(fr)) + idx = setdiff(Obj.t_start:Obj.t_end, fr); + idxi = fr-Obj.t_start+1; + idy = stateInfo.W(idx,i); + idyi = interp1(idx-Obj.t_start+1, idy, idxi,'linear'); + stateInfo.W(fr,i) = idyi; + idy = stateInfo.H(idx,i); + idyi = interp1(idx-Obj.t_start+1, idy, idxi,'linear'); + stateInfo.H(fr,i) = idyi; + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/test_smot_batch.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/test_smot_batch.m new file mode 100644 index 0000000000000000000000000000000000000000..bcc731da3bf7d4e1cdd77d8340827d42c3ec0d8b --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/test_smot_batch.m @@ -0,0 +1,85 @@ +% This is the batch testing script for smot code. +clear,clc,close all; +% add path +addpath(genpath('../')); + +% set random generator +rng(1233245); +saveOutput = false; +% Datasets to be tested +dataSets = {'slalom'};%,'juggling','crowd','acrobats','seagulls',... +% 'balls','tud-crossing','tud-campus'}; +datasetPath = '../smot_data'; + +% Method to be tested +% NOTE: IP method requires CVX to run, and a lot of patience! +methods = {'ihtls','admm','ip'}; +method = methods{1}; + +% Noise type to be tested +noiseType = {'fn','fp'}; +noise_tag = noiseType{1}; + +% Noise levels +fn = [0:0]; % I put this here for demo purposes. To obtain results with + % noise uncomment the next line. +% fn = [0.0:0.06:0.3]; +fp = [0.0:0.1:0.5]; +N = length(fn); + +% Number of trials per noise level. +TRIALS = 1; + +%% +% noise base +noisebase.fn = 0.0; +noisebase.fp = 0.0; +noisebase.gn = 0; +% mota base +motbase.fn = 0; +motbase.fp = 0; +motbase.mme = 0; +motbase.g = 0; +motbase.mota = 0; +motbase.mmerat = 0; +for i = 1:size(dataSets,2) + seqName = dataSets{i}; + % the following script will load a lot of variables. See the file for + % more details. + initialize_smot(); + for n=1:N + for t = 1:TRIALS + fprintf('Processing Dataset:%s Method:%s Noise:%0.2f|%0.2f Trial:%d\n', seqName,method,fp(n),fn(n),t); + fprintf('---------------------------------------\n'); + if n==1 && t>1 + % noiseless case is same for all trials. copy. + itlf{t,n} = itlf{1,n}; + etime(t,n) = etime(1,n); + mot(t,n) = mot(1,n); + else + noise(n).fp = fp(n); + noise(n).fn = fn(n); + noise(n).gn = 0; + [idlp, fp_idl{t,n}, fn_idl{t,n}] = idladdnoise(idl0,noise(n)); + % do the stitching + [itlf{t,n}, etime(t,n)] = smot_associate(idlp,param); + fprintf('Process time: %g \n\n',etime(t,n)); + % compute mota + fprintf('Computing MOT metrics \n'); + mot(t,n) = smot_clear_mot_fp(itl0,itlf{t,n},fp_idl{t,n},param.mota_th); + fprintf('\n'); + end + % save output for noiseless case + if (n==1) && (t==1) + showitl(itlf{t,n},seqPath,'tail',5); + % the below line is useful if you want to save the output +% showitl(itlf{t,n},seqPath,'tail',5,'saveoutput',savePath); + end + end + end + % save variables + if(saveOutput) + saveResultName = sprintf('%s/%s_%s_%s.mat',savePath,seqName,method,noise_tag); + save(saveResultName,'param','seqName','method','noise','mot','itlf','etime','fp_idl','fn_idl'); + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/test_smot_batch_.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/test_smot_batch_.m new file mode 100644 index 0000000000000000000000000000000000000000..627c038eedc44a8995619e5fcb885f23ea550aac --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_test/test_smot_batch_.m @@ -0,0 +1,84 @@ +% This is the batch testing script for smot code. +clear,clc,close all; + +% add path +addpath(genpath('.')); + +% set random generator +rng(1233245); +saveOutput = false; +% Datasets to be tested +dataSets = {'slalom'};%,'juggling','crowd','acrobats','seagulls',... +% 'balls','tud-crossing','tud-campus'}; +datasetPath = 'smot_data'; + +% Method to be tested +% NOTE: IP method requires CVX to run, and a lot of patience! +methods = {'ihtls','admm','ip'}; +method = methods{1}; + +% Noise type to be tested +noiseType = {'fn','fp'}; +noise_tag = noiseType{1}; + +% Noise levels +fn = [0]; % I put this here for demo purposes. To obtain results with + % noise uncomment the next line. +% fn = [0.0:0.06:0.3]; +fp = [0.0:0.1:0.5]; +N = length(fn); + +% Number of trials per noise level. +TRIALS = 1; + +%% +% noise base +noisebase.fn = 0.0; +noisebase.fp = 0.0; +noisebase.gn = 0; +% mota base +motbase.fn = 0; +motbase.fp = 0; +motbase.mme = 0; +motbase.g = 0; +motbase.mota = 0; +motbase.mmerat = 0; +for i = 1:size(dataSets,2) + seqName = dataSets{i}; + % the following script will load a lot of variables. See the file for + % more details. + initialize_smot(); + for n=1:N + for t = 1:TRIALS + fprintf('Processing Dataset:%s Method:%s Noise:%0.2f|%0.2f Trial:%d\n', seqName,method,fp(n),fn(n),t); + fprintf('---------------------------------------\n'); + if n==1 && t>1 + % noiseless case is same for all trials. copy. + itlf{t,n} = itlf{1,n}; + etime(t,n) = etime(1,n); + mot(t,n) = mot(1,n); + else + noise(n).fp = fp(n); + noise(n).fn = fn(n); + noise(n).gn = 0; + [idlp, fp_idl{t,n}, fn_idl{t,n}] = idladdnoise(idl0,noise(n)); + % do the stitching + [itlf{t,n}, etime(t,n)] = smot_associate(idlp,param); + fprintf('Process time: %g \n\n',etime(t,n)); + % compute mota + fprintf('Computing MOT metrics \n'); + mot(t,n) = smot_clear_mot_fp(itl0,itlf{t,n},fp_idl{t,n},param.mota_th); + fprintf('\n'); + end + % save output for noiseless case + if (n==1) && (t==1) + stateInfo = showTrackingResult(itlf{t,n}, seqPath, idl0); + end + end + end + % save variables + if(saveOutput) + saveResultName = sprintf('%s/%s_%s_%s.mat',savePath,seqName,method,noise_tag); + save(saveResultName,'param','seqName','method','noise','mot','itlf','etime','fp_idl','fn_idl'); + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/cell2itl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/cell2itl.m new file mode 100644 index 0000000000000000000000000000000000000000..f50858180b9b4fc7beb3201f28e0302ab6b29592 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/cell2itl.m @@ -0,0 +1,13 @@ +function itl = cell2itl(cell_tracks) + +N = size(cell_tracks,1); + +% TODO: pre allocate for itl + +for n=1:N + itl(n).t_start = min(cell_tracks{n}(:,1)); + itl(n).t_end = max(cell_tracks{n}(:,1)); + itl(n).length = itl(n).t_end - itl(n).t_start +1; + itl(n).omega = ones(1,itl(n).length); + itl(n).data = cell_tracks{n}(:,2:end)'; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/cvx_hankel_mo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/cvx_hankel_mo.m new file mode 100644 index 0000000000000000000000000000000000000000..fbd3a5e9e5d1bdea4aea86e0ba67fd3c6df98862 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/cvx_hankel_mo.m @@ -0,0 +1,21 @@ +function H = cvx_hankel_mo(L,nrnc) + +[dim N] = size(L); + +if nargin<2 + % nr = ceil(N/2)*dim; + nr = ceil(N/(dim+1))*dim; + nc = N - ceil(N/(dim+1))+1; +else + nr = nrnc(1); + nc = nrnc(2); +end + +cidx = [0 : nc-1 ]; +ridx = [1 : nr]'; + +H = ridx(:,ones(nc,1)) + dim*cidx(ones(nr,1),:); % Hankel subscripts +t = L(:); + +H = reshape( cvx_subsref( t, H( : ) ), size( H ) ); + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/distance_sq.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/distance_sq.m new file mode 100644 index 0000000000000000000000000000000000000000..e01fe58821fea6207ac1fa20de506788ad3526c1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/distance_sq.m @@ -0,0 +1,13 @@ +function distance = distance_sq(X,Y) + +% X and Y is DxN + +NY = size(Y,2); +NX = size(X,2); + + +X2 = sum(X.^2,1); +Y2 = sum(Y.^2,1); + + +distance = repmat(X2',1,NY) + repmat(Y2,NX,1) - 2*X'*Y; diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/drawitl2D.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/drawitl2D.m new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/drawitl3D.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/drawitl3D.m new file mode 100644 index 0000000000000000000000000000000000000000..5f0de6d8ddc28bcadb1cd8d14f5403c192c3fc15 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/drawitl3D.m @@ -0,0 +1,52 @@ +function drawitl3D(itl,dims) + +% user may pick two dimensions to plot over time. if it is not input +% the default will be first two dimensions. +if nargin <2 + dims = (1:2); +else + if length(dims)~=2 + error('number of selected plot dimensions must be 2!'); + end +end + + +N_itl = size(itl,2); + +for n=1:N_itl + + + t = (itl(n).t_start:1:itl(n).t_end); + xy = itl(n).data(dims,:); + + + + omega = itl(n).omega; + xy1 = xy; + xy0 = xy; + t1 = t; + t0 = t; + + % the following is to avoid choppy trajectories + % and keep the continuity with inpainting + % the inpainted parts will be shown in red + domega = conv(omega,[1 1 1],'same'); + xy1(:,domega==0) = nan; + t1(domega==0) = nan; + xy0(:,omega==1) = nan; + t0(omega==1) = nan; + + % plot + plot3(t1,xy1(1,:),xy1(2,:),'b-',... + t0,xy0(1,:),xy0(2,:),'r-x'); hold on; + + +% text(itl(n).t_start,itl(n).xy_start(dim),int2str(n)); +end + +xlabel('time'); +ylabel(['dimension ' num2str(dims(1))]); +zlabel(['dimension ' num2str(dims(2))]); + +hold off; +grid on; diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/generalizedLinearAssignment.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/generalizedLinearAssignment.m new file mode 100644 index 0000000000000000000000000000000000000000..0b71ee2fdcdbce410ca0f0d7f54b8794ac71e258 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/generalizedLinearAssignment.m @@ -0,0 +1,23 @@ +function A = generalizedLinearAssignment(D,slackD) +[M N] = size(D); +% N = size(D,2); +if nargin <2 + slackD = 1e-2; +end + +% WARNING: lapjv does not like inf values +% change inf values with something large +D(D==inf) = 1e15; + +% Use slack variables to relax sum(X)==1,if they are very high they will be +% ommited. + +D = [D ones(M,M)*slackD ]; +D = [D; ones(N,N+M)*slackD ]; +[A,C] = lapjv(D); +A = A(1:M); +A(A>N) = 0; +35; + +% TODO: Compute cost accordingly + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/get_itl_rects.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/get_itl_rects.m new file mode 100644 index 0000000000000000000000000000000000000000..ce592638f0bbd6537e678190ba1846faff572b70 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/get_itl_rects.m @@ -0,0 +1,18 @@ +function [idx,rects] = get_itl_rects(itl,t) + +id = [itl.id]; +t_start = [itl.t_start]; +t_end = [itl.t_end]; +f = (t_start <= t) & (t <= t_end); +tidx = find(f==1); + +rects = []; +idx = []; + +for i=1:size(tidx,2) + if itl(tidx(i)).omega(t-itl(tidx(i)).t_start+1 ) + rect = itl(tidx(i)).rect(:, t-itl(tidx(i)).t_start+1 ); + rects = [rects rect]; + idx = [idx id(tidx(i))]; + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/getitlxywh.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/getitlxywh.m new file mode 100644 index 0000000000000000000000000000000000000000..d05c44a82c088dd997bee10f2173c3b66260e619 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/getitlxywh.m @@ -0,0 +1,38 @@ +function [idx,xys,rects] = getitlxywh(itl,t) + +id = [itl.id]; +t_start = [itl.t_start]; +t_end = [itl.t_end]; +f = (t_start <= t) & (t <= t_end); +tidx = find(f==1); + +rects = []; +xys = []; +idx = []; + + + +if isfield(itl,'rect') + + for i=1:size(tidx,2) + if itl(tidx(i)).omega(t-itl(tidx(i)).t_start+1 ) + + rect = itl(tidx(i)).rect(:, t-itl(tidx(i)).t_start+1 ); + rects = [rects rect]; + idx = [idx id(tidx(i))]; + end + end + if ~isempty(rects) + xys = rects(1:2,:) + rects(3:4,:)/2; + end + +else + for i=1:size(tidx,2) + if itl(tidx(i)).omega(t-itl(tidx(i)).t_start+1 ) + + xy = itl(tidx(i)).data(:, t-itl(tidx(i)).t_start+1 ); + xys = [xys xy]; + idx = [idx id(tidx(i))]; + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/hankel_mo.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/hankel_mo.m new file mode 100644 index 0000000000000000000000000000000000000000..a97e321ea929b207d9c4686312db687ba4733bcb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/hankel_mo.m @@ -0,0 +1,75 @@ +function varargout = hankel_mo(L,nrnc) + + +% H = hankel_mo(X); +% +% [H,D] = hankel_mo(X,nrnc); +% +% X: Data DIMS x N +% nrnc: size of hankel matrix nr x nc +% D: weight of each block in hankel matrix +% +% treat every column as a observation +% form a multi output hankel e.g. +% | c1 c2 c3 | +% H = | c2 c3 c4 | +% | c3 c4 c5 | + + +[dim N] = size(L); + +if dim>N + warning('DIMS>N. Make sure X is DIMSxN (row vector)!') +end + +if nargin<2 + % nr = ceil(N/2)*dim; + nr = ceil(N/(dim+1))*dim; + nc = N - ceil(N/(dim+1))+1; +else + if(nrnc(1)==0) + % user input num of columns compute number of rows + nc = nrnc(2); + nr = (N-nc+1)*dim; + end + if(nrnc(2)==0) + % user input num of rows compute number of cols + nr = nrnc(1); + nc = N - nr/dim + 1; + if mod(nr,dim)~=0 + error('Number of rows must be a multiple of input dimension'); + end + end + if (nrnc(1)>0 && nrnc(2)>0) + nr = nrnc(1); + nc = nrnc(2); + end +end + +if nargout == 2 + nb = nr/dim; + l = min(nb,nc); + D = [1:l-1 l*ones(1,N-2*l+2) l-1:-1:1]; +end + + +% nc = N - ceil(N/(dim+1))+1; +% nc = N - (nr/dim)+1; + + + +cidx = [0 : nc-1 ]; +ridx = [1 : nr]'; + +H = ridx(:,ones(nc,1)) + dim*cidx(ones(nr,1),:); % Hankel subscripts +t = L(:); + +temp.type = '()'; +temp.subs = {H(:)}; +H = reshape( subsref( t, temp ), size( H ) ); + +if nargout <= 1 + varargout = {H}; +elseif nargout == 2 + varargout = {H,D}; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/idl2itl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/idl2itl.m new file mode 100644 index 0000000000000000000000000000000000000000..302616bcd219c5915c55c304c67e1fdb3bc0957e --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/idl2itl.m @@ -0,0 +1,198 @@ +function itl = idl2itl(idl,RATIO) + +if nargin <2 + RATIO = 3; % closeness ratio +end +% else nargin == 3 && isempty(RATIO) +% RATIO = 3; +% end + +T = size(idl,2); +D = cell(1,T); +B = cell(1,T); + +%% PASS 1) Find associations +t2 = []; +lastminD2 = 0; +for t = 1:T-1 + Nt = size(idl(t).xy,1); + Ntp1 = size(idl(t+1).xy,1); + + % If there are detections for current frame + if Nt > 0 + B{t} = zeros(Nt,1); + end + + % If there are detections for both current and next frame + if Nt > 0 && Ntp1 > 0 + xy1 = idl(t).xy'; + xy2 = idl(t+1).xy'; + + D{t} = distance_sq(xy1,xy2).^(1/2); + + if t==101 + 35; + end + + + % check first/second ratio + [Dsorted,idx] = sort(D{t},2); + if size(xy2,2)>1 + r = Dsorted(:,2)./Dsorted(:,1); + f = r>RATIO; + lastminD2 = min(Dsorted(:,2)); + elseif lastminD2 >0 + % WARNING: Very weird heuristic + % if there is no double detection to check ratio + % used the last min second distance + r = lastminD2./Dsorted(:,1); + f = r>RATIO; +% Ds1(:,1) < MAX_D + else + % We do not have any clue about the ratios + % label them as individual detections + % following stages will take care of them + r = 0*Dsorted(:,1); + f = r>RATIO; + end + + B{t} = idx(:,1).*f; + + + % check double assignments + nu = nonunique(B{t}); + if ~isempty(nu) + for n=1:length(nu) + if nu(n)>0 + B{t}(B{t}==nu(n)) = 0; + end + end + end + + + + + + end +end +B{T} = zeros(Ntp1,1); + +% DEBUG CHECK +for t=1:T + if length(B{t})~=size(idl(t).xy,1) + warning('Association Problem'); + end +end + +35; + +%% PASS 2) Link detections to tracklets +% F = B; % Processed/Unprocessed Flag +n = 1; +for t=1:T + + for ind=1:size(B{t},1) + if B{t}(ind) > -1 +% while sum(F{t}>-1) ~= 0 + % get the next tracklet start point (first nonzero index) +% ind = find(F{t}>-1,1); + + + + % get the measurements + [xy,B] = getxychain(idl,B,t,ind); + + % form the itl + l = size(xy,2); + itl(n).t_start = t; + itl(n).t_end = t+l-1; + itl(n).length = l; + itl(n).omega = ones(1,l); + itl(n).data = xy; + + n = n+1; + + end + end +end + +% DEBUG CHECK +Nidlpts = 0; +for t=1:T + Nidlpts = Nidlpts + size(idl(t).xy,1); +end +Nitlpts = 0; +for k=1:n-1 + Nitlpts = Nitlpts + itl(k).length; +end + +if Nidlpts ~=Nitlpts + warning('Missing detections in itl formation'); +end + +35; + + + + + + +%% Utility functions +% bind the detections +function [xy,B] = getxychain(idl,B,t,ind) + +T = size(idl,2); +tfirst = t; +xy = zeros(2,T); +% xy = []; + + +while t <= T && ind>0 %B{t}(ind) ~=0 + +% xy =[xy idl(t).xy(ind,:)']; + xy(:,t) = idl(t).xy(ind,:)'; + + indnext = B{t}(ind); + B{t}(ind) = -1; + + ind = indnext; + t = t+1; +end + +xy = xy(:,tfirst:t-1); + +% tlast = tfirst; +% xy(:,tlast) = idl(tlast).xy(ind,:)'; +% F{tlast}(ind) = -1; +% +% +% while tlast < T && B{tlast}(ind)~=0 +% bind = B{tlast}(ind); +% +% xy(:,tlast+1) = idl(tlast+1).xy(bind,:)'; +% F{tlast}(ind) = -1; +% +% ind = bind; +% tlast = tlast + 1; +% end +% +% F{tlast}(bind) = 0; + + + +% delete empty part +% xy = xy(:,tfirst:tlast); + + +% find repeated numbers in x +function n = nonunique(x) + +ux = unique(x); +if length(ux)==1 && length(x)>1 + n = ux; + return; +end +f = hist(x,ux); +n = ux(f>1); + + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/idladdnoise.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/idladdnoise.m new file mode 100644 index 0000000000000000000000000000000000000000..f9d409ee4721ed0f6a3306fcd4e73cf0d3fb35a7 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/idladdnoise.m @@ -0,0 +1,77 @@ +function [idl, fp_idl, fn_idl]= idladdnoise(idl,noise) + +% noise is a structure with three fields = { fn, fp, gn} +% noise.fn : false negatives +% noise.fp : false positives +% noise.gn : gaussian noise + +T = size(idl,2); +N = zeros(1,T); % number of detections per frame + +% idl sructures to keep log of modifications +aidl = struct('rect',[],'xy',[]); % added points +fp_idl = repmat(aidl,[1 T]); +fn_idl = fp_idl; % removed points + +% Analyze the video for statistics +XY = []; +WH = []; +for t=1:T + N(t) = size(idl(t).xy,1); + if N(t) > 0 + XY = [XY; idl(t).xy]; + WH = [WH; idl(t).rect(:,3:4)]; + end +end +XYmin = min(XY,[],1); +XYmax = max(XY,[],1); +WHmean = mean(WH); +WHstd = std(WH); +sumN = sum(N); +Nfn = floor(sumN*noise.fn); +Nfp = floor(sumN*noise.fp); + + +% false negatives +for n=1:Nfn + % pick a frame + t = randi(T,1); + % pick a detections + if N(t)>0 + k = randi(N(t),1); + % log it + fn_idl(t).xy = [fn_idl(t).xy;idl(t).xy(k,:)]; + fn_idl(t).rect = [fn_idl(t).rect;idl(t).rect(k,:)]; + % remove it + idl(t).xy(k,:) = []; + idl(t).rect(k,:) = []; + N(t) = N(t) - 1; + end +end + + +% false positives +for n=1:Nfp + % pick a frame + t = randi(T,1); + % add a detection + xy = rand(1,2).*(XYmax-XYmin) + XYmin; + wh = randn(1,2).*WHstd + WHmean; + rect = [xy-wh/2 wh]; + + % log it + fp_idl(t).xy = [fp_idl(t).xy;xy]; + fp_idl(t).rect = [fp_idl(t).rect;rect]; + + % add it to the data + idl(t).xy = [idl(t).xy; xy]; + idl(t).rect = [idl(t).rect; rect]; + N(t) = N(t) + 1; +end + +% inline noise +if noise.gn > 0 + for t=1:T + + end +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/itl2idl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/itl2idl.m new file mode 100644 index 0000000000000000000000000000000000000000..3afb97e8e4e09fcdf7bc4f0b9b0143416c582342 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/itl2idl.m @@ -0,0 +1,24 @@ +function idl = itl2idl(itl) + +% idl(t) is composed of 2 fields for now +% rect 4xN N many detections +% xy 2xN centroids + +if isempty(itl) + idl = []; + return; +end + +T_end = max([itl.t_end]); + +for t = 1:T_end + [idx,rects] = get_itl_rects(itl,t); + if ~isempty(rects) + xy = rects(1:2,:) + rects(3:4,:)/2; + else + xy = []; + end + idl(t).rect = rects'; + idl(t).xy = xy'; + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/lapjv.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/lapjv.m new file mode 100644 index 0000000000000000000000000000000000000000..ab38e794554f5329dd5e589e30247a819b795e60 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/lapjv.m @@ -0,0 +1,317 @@ +function [rowsol,cost,v,u,costMat] = lapjv(costMat,resolution) +% LAPJV Jonker-Volgenant Algorithm for Linear Assignment Problem. +% +% [ROWSOL,COST,v,u,rMat] = LAPJV(COSTMAT) returns the optimal column indices, +% ROWSOL, assigned to row in solution, and the minimum COST based on the +% assignment problem represented by the COSTMAT, where the (i,j)th element +% represents the cost to assign the jth job to the ith worker. +% Other output arguments are: +% v: dual variables, column reduction numbers. +% u: dual variables, row reduction numbers. +% rMat: the reduced cost matrix. +% +% For a rectangular (nonsquare) costMat, rowsol is the index vector of the +% larger dimension assigned to the smaller dimension. +% +% [ROWSOL,COST,v,u,rMat] = LAPJV(COSTMAT,resolution) accepts the second +% input argument as the minimum resolution to differentiate costs between +% assignments. The default is eps. +% +% Known problems: The original algorithm was developed for integer costs. +% When it is used for real (floating point) costs, sometime the algorithm +% will take an extreamly long time. In this case, using a reasonable large +% resolution as the second arguments can significantly increase the +% solution speed. +% +% See also munkres, Hungarian + +% version 1.0 by Yi Cao at Cranfield University on 3rd March 2010 +% version 1.1 by Yi Cao at Cranfield University on 19th July 2010 +% version 1.2 by Yi Cao at Cranfield University on 22nd July 2010 +% version 2.0 by Yi Cao at Cranfield University on 28th July 2010 +% version 2.1 by Yi Cao at Cranfield University on 13th August 2010 +% version 2.2 by Yi Cao at Cranfield University on 17th August 2010 + +% This Matlab version is developed based on the orginal C++ version coded +% by Roy Jonker @ MagicLogic Optimization Inc on 4 September 1996. +% Reference: +% R. Jonker and A. Volgenant, "A shortest augmenting path algorithm for +% dense and spare linear assignment problems", Computing, Vol. 38, pp. +% 325-340, 1987. + +% +% Examples +% Example 1: a 5 x 5 example +%{ +[rowsol,cost] = lapjv(magic(5)); +disp(rowsol); % 3 2 1 5 4 +disp(cost); %15 +%} +% Example 2: 1000 x 1000 random data +%{ +n=1000; +A=randn(n)./rand(n); +tic +[a,b]=lapjv(A); +toc % about 0.5 seconds +%} +% Example 3: nonsquare test +%{ +n=100; +A=1./randn(n); +tic +[a,b]=lapjv(A); +toc % about 0.2 sec +A1=[A zeros(n,1)+max(max(A))]; +tic +[a1,b1]=lapjv(A1); +toc % about 0.01 sec. The nonsquare one can be done faster! +%check results +disp(norm(a-a1)) +disp(b-b) +%} + +if nargin<2 + maxcost=min(1e16,max(max(costMat))); + resolution=eps(maxcost); +end +% Prepare working data +[rdim,cdim] = size(costMat); +M=min(min(costMat)); +if rdim>cdim + costMat = costMat'; + [rdim,cdim] = size(costMat); + swapf=true; +else + swapf=false; +end +dim=cdim; +costMat = [costMat;2*M+zeros(cdim-rdim,cdim)]; +costMat(costMat~=costMat)=Inf; +maxcost=max(costMat(costMat resolution + % change the reduction of the minmum column to increase the + % minimum reduced cost in the row to the subminimum. + v(j1) = v(j1) - (usubmin - umin); + else % minimum and subminimum equal. + if i0 > 0 % minimum column j1 is assigned. + % swap columns j1 and j2, as j2 may be unassigned. + j1 = j2; + i0 = colsol(j2); + end + end + % reassign i to j1, possibly de-assigning an i0. + rowsol(i) = j1; + colsol(j1) = i; + if i0 > 0 % ,inimum column j1 assigned easier + if usubmin - umin > resolution + % put in current k, and go back to that k. + % continue augmenting path i - j1 with i0. + free(k)=i0; + k=k-1; + else + % no further augmenting reduction possible + % store i0 in list of free rows for next phase. + numfree = numfree + 1; + free(numfree) = i0; + end + end + end +end + +% Augmentation Phase +% augment solution for each free rows +for f=1:numfree + freerow = free(f); % start row of augmenting path + % Dijkstra shortest path algorithm. + % runs until unassigned column added to shortest path tree. + d = costMat(freerow,:) - v; + pred = freerow(1,ones(1,dim)); + collist = 1:dim; + low = 1; % columns in 1...low-1 are ready, now none. + up = 1; % columns in low...up-1 are to be scaed for current minimum, now none. + % columns in up+1...dim are to be considered later to find new minimum, + % at this stage the list simply contains all columns. + unassignedfound = false; + while ~unassignedfound + if up == low % no more columns to be scaned for current minimum. + last = low-1; + % scan columns for up...dim to find all indices for which new minimum occurs. + % store these indices between low+1...up (increasing up). + minh = d(collist(up)); + up = up + 1; + for k=up:dim + j = collist(k); + h = d(j); + if h<=minh + if hmaxcost + cost=Inf; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/loaditl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/loaditl.m new file mode 100644 index 0000000000000000000000000000000000000000..28a1fdbeb00410ce817d45d51b96c1d5a46f0702 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/loaditl.m @@ -0,0 +1,22 @@ +function itl = loaditl(fileName) +fid = fopen(fileName,'r'); +N = fscanf(fid,'%d',1); + +for n=1:N + itl(n).id = fscanf(fid,'%d',1); + itl(n).t_start = fscanf(fid,'%d',1); + itl(n).t_end = fscanf(fid,'%d',1); + itl(n).length = itl(n).t_end - itl(n).t_start +1; + + rect = fscanf(fid,'%f',[itl(n).length 4])'; +% rect = reshape(rect,[4 itl(n).length]); + omega = fscanf(fid,'%d',itl(n).length); + itl(n).rect = rect; + itl(n).xy = rect(1:2,:) + rect(3:4,:)/2; + itl(n).omega = omega'; + +end + + +fclose(fid); + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/pdist2.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/pdist2.m new file mode 100644 index 0000000000000000000000000000000000000000..4eab14977f78f87ea4dea37346feb7eb46caab92 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/pdist2.m @@ -0,0 +1,191 @@ +% This function belongs to Piotr Dollar's Toolbox +% http://vision.ucsd.edu/~pdollar/toolbox/doc/index.html +% Please refer to the above web page for definitions and clarifications +% +% Calculates the distance between sets of vectors. +% +% Let X be an m-by-p matrix representing m points in p-dimensional space +% and Y be an n-by-p matrix representing another set of points in the same +% space. This function computes the m-by-n distance matrix D where D(i,j) +% is the distance between X(i,:) and Y(j,:). This function has been +% optimized where possible, with most of the distance computations +% requiring few or no loops. +% +% The metric can be one of the following: +% +% 'euclidean' / 'sqeuclidean': +% Euclidean / SQUARED Euclidean distance. Note that 'sqeuclidean' +% is significantly faster. +% +% 'chisq' +% The chi-squared distance between two vectors is defined as: +% d(x,y) = sum( (xi-yi)^2 / (xi+yi) ) / 2; +% The chi-squared distance is useful when comparing histograms. +% +% 'cosine' +% Distance is defined as the cosine of the angle between two vectors. +% +% 'emd' +% Earth Mover's Distance (EMD) between positive vectors (histograms). +% Note for 1D, with all histograms having equal weight, there is a simple +% closed form for the calculation of the EMD. The EMD between histograms +% x and y is given by the sum(abs(cdf(x)-cdf(y))), where cdf is the +% cumulative distribution function (computed simply by cumsum). +% +% 'L1' +% The L1 distance between two vectors is defined as: sum(abs(x-y)); +% +% +% USAGE +% D = pdist2( X, Y, [metric] ) +% +% INPUTS +% X - [m x p] matrix of m p-dimensional vectors +% Y - [n x p] matrix of n p-dimensional vectors +% metric - ['sqeuclidean'], 'chisq', 'cosine', 'emd', 'euclidean', 'L1' +% +% OUTPUTS +% D - [m x n] distance matrix +% +% EXAMPLE +% [X,IDX] = demoGenData(100,0,5,4,10,2,0); +% D = pdist2( X, X, 'sqeuclidean' ); +% distMatrixShow( D, IDX ); +% +% See also PDIST, DISTMATRIXSHOW + +% Piotr's Image&Video Toolbox Version 2.0 +% Copyright (C) 2007 Piotr Dollar. [pdollar-at-caltech.edu] +% Please email me if you find bugs, or have suggestions or questions! +% Licensed under the Lesser GPL [see external/lgpl.txt] + +function D = pdist2(X, Y, metric) + +if( nargin<3 || isempty(metric) ); metric=0; end; + +switch metric + case 'sqeuclidean' + D = distEucSq( X, Y ); + case {0, 'euclidean'} + D = sqrt(distEucSq( X, Y )); + case 'L1' + D = distL1( X, Y ); + case 'cosine' + D = distCosine( X, Y ); + case 'emd' + D = distEmd( X, Y ); + case 'chisq' + D = distChiSq( X, Y ); + otherwise + error(['pdist2 - unknown metric: ' metric]); +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function D = distL1( X, Y ) + +m = size(X,1); n = size(Y,1); +mOnes = ones(1,m); D = zeros(m,n); +for i=1:n + yi = Y(i,:); yi = yi( mOnes, : ); + D(:,i) = sum( abs( X-yi),2 ); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function D = distCosine( X, Y ) + +if( ~isa(X,'double') || ~isa(Y,'double')) + error( 'Inputs must be of type double'); end; + +p=size(X,2); +XX = sqrt(sum(X.*X,2)); X = X ./ XX(:,ones(1,p)); +YY = sqrt(sum(Y.*Y,2)); Y = Y ./ YY(:,ones(1,p)); +D = 1 - X*Y'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function D = distEmd( X, Y ) + +Xcdf = cumsum(X,2); +Ycdf = cumsum(Y,2); + +m = size(X,1); n = size(Y,1); +mOnes = ones(1,m); D = zeros(m,n); +for i=1:n + ycdf = Ycdf(i,:); + ycdfRep = ycdf( mOnes, : ); + D(:,i) = sum(abs(Xcdf - ycdfRep),2); +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function D = distChiSq( X, Y ) + +%%% supposedly it's possible to implement this without a loop! +m = size(X,1); n = size(Y,1); +mOnes = ones(1,m); D = zeros(m,n); +for i=1:n + yi = Y(i,:); yiRep = yi( mOnes, : ); + s = yiRep + X; d = yiRep - X; + D(:,i) = sum( d.^2 ./ (s+eps), 2 ); +end +D = D/2; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function D = distEucSq( X, Y ) + +%if( ~isa(X,'double') || ~isa(Y,'double')) + % error( 'Inputs must be of type double'); end; +m = size(X,1); n = size(Y,1); +%Yt = Y'; +XX = sum(X.*X,2); +YY = sum(Y'.*Y',1); +D = XX(:,ones(1,n)) + YY(ones(1,m),:) - 2*X*Y'; + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% function D = distEucSq( X, Y ) +%%%% code from Charles Elkan with variables renamed +% m = size(X,1); n = size(Y,1); +% D = sum(X.^2, 2) * ones(1,n) + ones(m,1) * sum(Y.^2, 2)' - 2.*X*Y'; + + +%%% LOOP METHOD - SLOW +% [m p] = size(X); +% [n p] = size(Y); +% +% D = zeros(m,n); +% onesM = ones(m,1); +% for i=1:n +% y = Y(i,:); +% d = X - y(onesM,:); +% D(:,i) = sum( d.*d, 2 ); +% end + + +%%% PARALLEL METHOD THAT IS SUPER SLOW (slower then loop)! +% % From "MATLAB array manipulation tips and tricks" by Peter J. Acklam +% Xb = permute(X, [1 3 2]); +% Yb = permute(Y, [3 1 2]); +% D = sum( (Xb(:,ones(1,n),:) - Yb(ones(1,m),:,:)).^2, 3); + + +%%% USELESS FOR EVEN VERY LARGE ARRAYS X=16000x1000!! and Y=100x1000 +% call recursively to save memory +% if( (m+n)*p > 10^5 && (m>1 || n>1)) +% if( m>n ) +% X1 = X(1:floor(end/2),:); +% X2 = X((floor(end/2)+1):end,:); +% D1 = distEucSq( X1, Y ); +% D2 = distEucSq( X2, Y ); +% D = cat( 1, D1, D2 ); +% else +% Y1 = Y(1:floor(end/2),:); +% Y2 = Y((floor(end/2)+1):end,:); +% D1 = distEucSq( X, Y1 ); +% D2 = distEucSq( X, Y2 ); +% D = cat( 2, D1, D2 ); +% end +% return; +% end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/seqreader.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/seqreader.m new file mode 100644 index 0000000000000000000000000000000000000000..f6c738da0d31dba99f80fa7e95e6fe5a08e0a650 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/seqreader.m @@ -0,0 +1,93 @@ +classdef seqreader < handle + properties(SetAccess = 'private', Hidden = true) + seqPath; + seqExt; + seqName; + seqNameRaw; + imageStartId; + imageCurrentId; + idStart; + idNumLen; + + end + + properties(SetAccess = 'private', GetAccess = 'public') + Width; + Height; + NumOfFrames; + CurrentPos; + CurrentImageName; + end + + methods + % constructor + function this = seqreader(inpath) + % find if it is a folder or file + ftype = exist(inpath,'file'); + if ftype==2 % file + [this.seqPath,this.seqName,this.seqExt] = fileparts(inpath); + + elseif ftype==7 % folder +% + [~,res] = system(['ls -1 ' inpath ' |egrep "\.png$|\.jpg$|\.jpeg$|\.ppm$"']);% + % get the first file + ind = strfind(res,char(10)); + + this.seqPath = inpath; + this.seqName = res(1:ind(1)-5); + this.seqExt = res(ind(1)-4:ind(1)-1); + 35; + else + error('Path does not exist!'); + end + + % find the sequence part of the file + this.idStart = regexp(this.seqName, '[0-9]+$'); + this.idNumLen = length(this.seqName)-this.idStart+1; + this.seqNameRaw = this.seqName(1:this.idStart-1); + this.imageStartId = str2double(this.seqName(this.idStart:end)); + this.imageCurrentId = this.imageStartId; + + + % generate the file name + imageName = [this.seqPath '/' this.seqNameRaw num2str(this.imageStartId,['%0' int2str(this.idNumLen) 'd']) this.seqExt]; + + % read the image + frame = imread(imageName); + + [this.Height, this.Width, D] = size(frame); + + this.CurrentImageName = imageName; + this.CurrentPos = 0; + + % find number of images + imageList = dir([this.seqPath '/' this.seqNameRaw '*' this.seqExt]); + this.NumOfFrames = size(imageList,1); + 35; + end + + % get next frame + function frame = grabFrame(this) + imageName = [this.seqPath '/' this.seqNameRaw num2str(this.imageCurrentId,['%0' int2str(this.idNumLen) 'd']) this.seqExt]; + + + % read the image + frame = imread(imageName); + + this.CurrentImageName = imageName; + this.CurrentPos = this.CurrentPos + 1; + this.imageCurrentId = this.imageCurrentId + 1; + + + end +% % seeks to the given frame. not accurate + function seek(this,pos) + this.CurrentPos = pos; + this.imageCurrentId = this.imageStartId + pos; + end + +% % needs destructor !!! +% function delete(this) +% end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/showitl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/showitl.m new file mode 100644 index 0000000000000000000000000000000000000000..d4999886bb9ed92ef2078f876e594fac82a75752 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/showitl.m @@ -0,0 +1,151 @@ +function showitl(itl,seqPath,varargin) + +defTail = 0; +defSavePath = ''; +defDrawRects = false; +defFixedWH = [-1 -1]; + +% Check user input parameters +p = inputParser; +addParamValue(p,'saveoutput',defSavePath,@ischar); +addParamValue(p,'tail',defTail,@isnumeric); +addParamValue(p,'rects',defDrawRects,@islogical); +addParamValue(p,'fixedwh',defFixedWH,@isnumeric); +parse(p,varargin{:}); + +tail = p.Results.tail; +saveFolder = p.Results.saveoutput; +drawRects = p.Results.rects; +fixedwh = p.Results.fixedwh; + +if fixedwh(1)>0 fixedwh(2)>0; + drawRects = true; + useFixedWH = true; +end + + +% fix if id field is missing +if ~isfield(itl,'id') + for k=1:size(itl,2) + itl(k).id = k; + end +end + + +% initializations for visuals +hFig = figure; +iptsetpref('ImshowBorder','tight'); +%hseq = seqreader(seqPath); +dataset = dir([seqPath '/*.jpg']); +colorSet = colormap('lines'); +lineSet = {'--','-'}; + +if ~isempty(saveFolder) + if ~exist(saveFolder) + mkdir(saveFolder); + end +end +% h = hseq.Height; +% w = hseq.Width; + +% sort the itl start and end times +[t_start, ind_start]= sort([itl.t_start]); +[t_end, ind_end]= sort([itl.t_end]); + +idx = []; +for t = 1:length(dataset)%hseq.NumOfFrames + % add starting tracklets + nidx = ind_start(t_start==t); + idx = [idx nidx]; + % delete ending tracklets + didx = ind_end(t_end==t); + for k=1:length(didx) + idx(idx==didx(k))=[]; + end + + img = imread([seqPath '/' dataset(t).name]);%grabFrame(hseq); + imshow(img); hold on; + + + for k=1:length(idx) + omega = itl(idx(k)).omega(t-itl(idx(k)).t_start+1); + colorid = mod(idx(k),64)+1; + + % FIX: Our objects do not have rectangles now + if drawRects + + if useFixedWH + xy = itl(idx(k)).xy(:,t-itl(idx(k)).t_start+1); + rect = [xy'-fixedwh/2 fixedwh]; + else + rect = itl(idx(k)).rect(:,t-itl(idx(k)).t_start+1); + end + + if rect(3)>0 && rect(4)>0 + rectangle('Position',rect,'EdgeColor',colorSet(colorid,:),... + 'LineWidth',6,'LineStyle',lineSet{omega+1}); + rectangle('Position',[rect(1:2)+2 rect(3:4)-4],'EdgeColor',[0 0 0],... + 'LineWidth',3); + rectangle('Position',[rect(1:2)+4 rect(3:4)-8],'EdgeColor',[1 1 1],... + 'LineWidth',3); + + end + text(rect(1)+15,rect(2)+15,int2str(idx(k)),'Color',colorSet(colorid,:),'FontSize',18); + end + + + + if tail > 0 + xy = itl(idx(k)).data(:,... + max(t-itl(idx(k)).t_start - tail,1)... + :t-itl(idx(k)).t_start+1); + plot(xy(1,:),xy(2,:),'Color',colorSet(colorid,:),'LineWidth',6); + end + + end + hold off; drawnow; + + % save output + if ~isempty(saveFolder) + frame = getframe(hFig); + [~,imgName,imgExt] = fileparts(hseq.CurrentImageName); + imgFullName = [saveFolder '/' imgName imgExt]; +% display(['saving ' imgFullName]); + imwrite(frame.cdata,imgFullName); + end + + +end + +% for t = 1:hseq.NumOfFrames +% +% img = grabFrame(hseq); +% imshow(img); hold on; +% +% [idx,rects] = get_itl_rects(itl,t); +% +% for k=1:length(idx) +% rect = rects(:,k); +% colorid = mod(idx(k),256)+1; +% rectangle('Position',rect,'EdgeColor',colorSet(colorid,:),'LineWidth',3); +% text(rect(1)+5,rect(2)+5,int2str(idx(k)),'Color',colorSet(colorid,:),'FontSize',18); +% +% if tail>0 +% +% end +% end +% hold off; +% drawnow; +% +% +% +% if ~isempty(saveFolder) +% frame = getframe(hFig); +% [~,imgName,imgExt] = fileparts(hseq.CurrentImageName); +% imgFullName = [saveFolder '/' imgName imgExt]; +% display(['saving ' imgFullName]); +% imwrite(frame.cdata,imgFullName); +% end +% +% end + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/smot_clear_mot.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/smot_clear_mot.m new file mode 100644 index 0000000000000000000000000000000000000000..f6b103aa4500ca4b2e4d98bbe974f6990b0855dc --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/smot_clear_mot.m @@ -0,0 +1,159 @@ +function mot = smot_clear_mot(itl0,itlh,intthresh) + +% itl0: original (ground truth) tracklet labels +% itlh: hypothesis tracklet labels +% intthresh: intersection threshold +Nmax = size(itl0,2); +M = zeros(Nmax,1); % correspondence list for original +% NHmax = size(itlh,2); +% H = zeros(NHmax,1); % correspondence list for hypothesis +T_end = max([itl0.t_end]); + +% FIX: the hypothesis tracklets do not have id field +for n=1:size(itlh,2) + itlh(n).id = n; +end + +% FIX: start ground truth id's from 1. +for n=1:size(itl0,2) + itl0(n).id = n; +end + +% WARNING: Use below with caution. It may be completely wrong. +% FIX: make inpaintings part of tracklets to avoid wrong false negatives +for n=1:size(itlh,2) + itlh(n).omega = ones(size(itlh(n).omega)); +end + + +mme = 0;fp = 0;fn = 0; +g = 0; +for t = 1:T_end + + % Ground truth has rectangles of detections + [oidx,oxy,orects] = getitlxywh(itl0,t); + % Hypothesis only have xy + [hidx,hxy,hrects] = getitlxywh(itlh,t); + + No = size(oidx,2); + Nh = size(hidx,2); + + + % find correspondences + if Nh > 0 && No >0 % if they are not both empty + W_mean = mean(orects(3,:)); + th = intthresh *W_mean; %threshold + c = find_correspondences(oxy,hxy,th); + else + c = zeros(1,No); + end + + + + Na = sum(c>0); % number of assigned + % if there are more hypothesis than assigned they are false positive + fp = fp + (Nh - Na); + + if(Nh-Na) >0 + 35; + end + + % if there are objects which could not be assigned they are false + % negative (misses) + if No > Na + 35; + end + fn = fn + (No - Na); + + if 0 & (No-Na)>0 + figure(51);clf; + for i=1:size(orects,2) + rectangle('Position',orects(:,i),'EdgeColor','r'); + end + figure(52);clf; + for i=1:size(hrects,2) + rectangle('Position',hrects(:,i),'EdgeColor','b'); + end + + + 35; + end + + % correspondences for this time spot +% [oidx' hidx(c)'] % debug + + + + for n = 1:size(oidx,2) + + if c(n) > 0 + if M(oidx(n)) == 0 && sum(M==hidx(c(n))) == 0 % first assignment + M(oidx(n)) = hidx(c(n)); + elseif M(oidx(n)) ~= hidx(c(n)) % mismatch (label changed) + % clear other assignments + M(M==hidx(c(n))) = 0; + % update with new assignment + M(oidx(n)) = hidx(c(n)); + mme = mme + 1; + end + end + + % check for switches +% if ((t == itl0(oidx(n)).t_start) || (M(oidx(n)) == 0)) && c(n)>0 +% M(oidx(n)) = hidx(c(n)); +% elseif c(n)>0 +% if M(oidx(n)) == hidx(c(n)) +% else +% M(oidx(n)) = hidx(c(n)); +% mme = mme + 1; +% end +% end + end + + + g = g + No; +end +% ATTENTION: we did not compute false positives. +mota = 1 - (mme+fn+fp)/g; +mmerat = 1 - mme/g; +% fprintf(' mme:%g\n fn:%g\n fp:%g\n mota:%g\n mmeratio:%g\n ',mme,fn,fp,mota,mmerat); +fprintf('mme:%3g\tfn:%3g\tfp:%3g\tmota:%0.4f\n',mme,fn,fp,mota); + + +mot.fn = fn; +mot.fp = fp; +mot.mme = mme; +mot.g = g; +mot.mota = mota; +mot.mmerat = mmerat; + +35; + + + + + + + + + +function tidx = itl_tidx(itl) +T = max([itl.t_end]); +tidx = cell(1,T); +for i=1:size(itl,2) + for t = itl(i).t_start:itl(i).t_end + tidx{t} = [tidx{t} i]; + end +end + +function c = find_correspondences(oxy,hxy,th) + +% oxy : ground truth xy +% hxy : hypothesis xy + +% find the correspondences +D = distance_sq(oxy,hxy).^(1/2); + +% we want detections within a radius +D(D>th) = 1e8; % munkres does not like inf +c = munkres(D); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/smot_clear_mot_fp.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/smot_clear_mot_fp.m new file mode 100644 index 0000000000000000000000000000000000000000..a44f35453dbb44fe1abde7e98e4e92fc82d32d89 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/smot_clear_mot_fp.m @@ -0,0 +1,178 @@ +function mot = smot_clear_mot_fp(itl0,itlh,idlfp,intthresh) + +% itl0: original (ground truth) tracklet labels +% itlh: hypothesis tracklet labels +% intthresh: intersection threshold +Nmax = size(itl0,2); +M = zeros(Nmax,1); % correspondence list for original +% NHmax = size(itlh,2); +% H = zeros(NHmax,1); % correspondence list for hypothesis +T_end = max([itl0.t_end]); + +% FIX: the hypothesis tracklets do not have id field +for n=1:size(itlh,2) + itlh(n).id = n; +end + +% FIX: start ground truth id's from 1. +for n=1:size(itl0,2) + itl0(n).id = n; +end + +% WARNING: Use below with caution. It may be completely wrong. +% FIX: make inpaintings part of tracklets to avoid wrong false negatives +for n=1:size(itlh,2) + itlh(n).omega = ones(size(itlh(n).omega)); +end + + +mme = 0;fp = 0;fn = 0; +g = 0; +for t = 1:T_end + + % Ground truth has rectangles of detections + [oidx,oxy,orects] = getitlxywh(itl0,t); + % Hypothesis only have xy + [hidx,hxy,hrects] = getitlxywh(itlh,t); + + % get false positives + fxy = idlfp(t).xy'; + + No = size(oidx,2); + Nh = size(hidx,2); + + + % find correspondences + if Nh > 0 && No >0 % if they are not both empty + W_mean = mean(orects(3,:)); + th = intthresh *W_mean; %threshold + c = find_correspondences(oxy,hxy,th); + else + c = zeros(1,No); + end + + + + Na = sum(c>0); % number of assigned + % if there are more hypothesis than assigned they are false positive + if ~isempty(fxy) && ~isempty(hxy) + p = find_correspondences(fxy,hxy,3); + fp = fp + sum(p>0); + if any(p>0) + 35; + end + 35; + end +% fp = fp + (Nh - Na); + + if(Nh-Na) >0 + 35; + end + + % if there are objects which could not be assigned they are false + % negative (misses) + if No > Na + 35; + end + fn = fn + (No - Na); + + if 0 & (No-Na)>0 + figure(51);clf; + for i=1:size(orects,2) + rectangle('Position',orects(:,i),'EdgeColor','r'); + end + figure(52);clf; + for i=1:size(hrects,2) + rectangle('Position',hrects(:,i),'EdgeColor','b'); + end + + + 35; + end + + % correspondences for this time spot +% [oidx' hidx(c)'] % debug + + + + for n = 1:size(oidx,2) + + if c(n) > 0 + if M(oidx(n)) == 0 && sum(M==hidx(c(n))) == 0 % first assignment + M(oidx(n)) = hidx(c(n)); + elseif M(oidx(n)) ~= hidx(c(n)) % mismatch (label changed) + % clear other assignments + M(M==hidx(c(n))) = 0; + % update with new assignment + M(oidx(n)) = hidx(c(n)); + mme = mme + 1; + end + end + + % check for switches +% if ((t == itl0(oidx(n)).t_start) || (M(oidx(n)) == 0)) && c(n)>0 +% M(oidx(n)) = hidx(c(n)); +% elseif c(n)>0 +% if M(oidx(n)) == hidx(c(n)) +% else +% M(oidx(n)) = hidx(c(n)); +% mme = mme + 1; +% end +% end + end + + + g = g + No; +end +% ATTENTION: we did not compute false positives. +mota = 1 - (mme+fn+fp)/g; +mmerat = 1 - mme/g; +% fprintf(' mme:%g\n fn:%g\n fp:%g\n mota:%g\n mmeratio:%g\n ',mme,fn,fp,mota,mmerat); +fprintf('mme:%3g\tfn:%3g\tfp:%3g\tmota:%0.4f\n',mme,fn,fp,mota); + + +mot.fn = fn; +mot.fp = fp; +mot.mme = mme; +mot.g = g; +mot.mota = mota; +mot.mmerat = mmerat; + +35; + + + + + + + + + +function tidx = itl_tidx(itl) +T = max([itl.t_end]); +tidx = cell(1,T); +for i=1:size(itl,2) + for t = itl(i).t_start:itl(i).t_end + tidx{t} = [tidx{t} i]; + end +end + +function c = find_correspondences(oxy,hxy,th) + +% oxy : ground truth xy +% hxy : hypothesis xy + +% find the correspondences +D = distance_sq(oxy,hxy).^(1/2); +maxD = max(D(:)); +% FIX: augment D with one correct assignment +% to make munkres work right +% D = [D 1e8*ones(size(D,1),1)]; +% D = [D; 1e8*ones(1,size(D,2))]; +% D(end,end) = 0; + +% we want detections within a radius +D(D>th) = maxD*10; % munkres does not like inf +% c = munkres(D); +c = generalizedLinearAssignment(D,maxD*5); +35; diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/smot_data_converter.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/smot_data_converter.m new file mode 100644 index 0000000000000000000000000000000000000000..140004defaf493444a011a8da3d1dae3e745bca3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/smot_data_converter.m @@ -0,0 +1,55 @@ +%% SMOT detection data converter +clc, clear; +addpath('smot_util\'); +datasetPath = 'smot_data\'; +seqName = 'slalom'; +format = '.txt'; +seqPath = [datasetPath '\' seqName '\img']; +itlName = [datasetPath '\' seqName '\' seqName '.itl']; +savePath = [datasetPath '\' seqName '\' seqName format ]; + + +% SMOT dataset +if ~isempty(strfind(['dribbling,slalom,juggling,crowd,acrobats,firebirds,seagulls,balls,tud-crossing,tud-campus'],seqName)) + % get the information about the sequence + itlData = loaditl(itlName); +end + +% Convert to the detection results. +itlData = itl2idl(itlData); + +% Open the detection saving files. +fid = fopen(savePath, 'w+'); + +nCount = 0; + +% Data size +[~,nitem] = size(itlData); +% Save the detections. +for fr = 1:nitem + dets = itlData(1,fr).rect; + [nbox, ~] = size(dets); + for n = 1:nbox; + if nCount < 10 + % Print number of detections. + fprintf(fid, '0000'); + fprintf(fid, '%d,', nCount); + elseif nCount < 100 && nCount >= 10 + fprintf(fid, '000'); + fprintf(fid, '%d,', nCount); + elseif nCount < 1000 && nCount >= 100 + fprintf(fid, '00'); + fprintf(fid, '%d,', nCount); + elseif nCount < 10000 && nCount >= 1000 + fprintf(fid, '0'); + fprintf(fid, '%d,', nCount); + end + + fprintf(fid, '%d,', fr); + % left,top,right,bottom + fprintf(fid, '%f,%f,%f,%f',dets(n,1),dets(n,2),dets(n,1)+dets(n,3)/2,dets(n,2)+dets(n,4)/2); + fprintf(fid, '\n'); + nCount = nCount + 1; + end +end +fclose(fid); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/txt2idl.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/txt2idl.m new file mode 100644 index 0000000000000000000000000000000000000000..ea0d988f3941d03e1d9935d2c128138b677bc781 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/IHTLS/smot_util/txt2idl.m @@ -0,0 +1,9 @@ +function idlDetections = txt2idl(detections, frameNums) + +idlDetections = struct('rect',[],'xy',[]); +for i = frameNums + idx = detections(:,1) == i; + curDet = detections(idx, 3:7); + idlDetections(i).rect = curDet(:,1:4); + idlDetections(i).xy = cat(2, (curDet(:,1)+curDet(:,3))/2, (curDet(:,2)+curDet(:,4))/2); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/filter_parameters.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/filter_parameters.m new file mode 100644 index 0000000000000000000000000000000000000000..c20edcd72aa4ba23e9ec4fe7311bef660c0b246a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/filter_parameters.m @@ -0,0 +1,32 @@ +% filter parameters + +% Modeling +% paramters for object motion +param.F = [1 0 1 0 0 0; + 0 1 0 1 0 0; + 0 0 1 0 0 0; + 0 0 0 1 0 0; + 0 0 0 0 1 0; + 0 0 0 0 0 1]; +% ETH +param.Q = 1*[5 0 0 0;0 5 0 0;0 0 10 0;0 0 0 15].^2; +param.R = [1 0 0 0;0 1 0 0;0 0 3 0;0 0 0 3].^2; +param.G = [1/2 0 0 0; + 0 1/2 0 0; + 1 0 0 0; + 0 1 0 0; + 0 0 1 0; + 0 0 0 1]; +param.H = [1 0 0 0 0 0;0 1 0 0 0 0;0 0 0 0 1 0;0 0 0 0 0 1]; +param.P = [2 0 0 0 0 0;0 2 0 0 0 0;0 0 2 0 0 0;0 0 0 2 0 0;0 0 0 0 2 0;0 0 0 0 0 2].^2; + + +% paramters for relational function +param.Fr = [1 0 1 0;0 1 0 1;0 0 1 0;0 0 0 1]; +param.Qr = [1 0;0 1].^2; +param.Rr = [5 0;0 5].^2; +param.Gr = [1/2 0; + 0 1/2; + 1 0; + 0 1]; +param.Hr = [1 0 0 0;0 1 0 0]; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/KF_prediction_iccv.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/KF_prediction_iccv.m new file mode 100644 index 0000000000000000000000000000000000000000..ea192edc1b7f90f2c448395b5e811c3227d2ab6a --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/KF_prediction_iccv.m @@ -0,0 +1,9 @@ +function [var_xp]=KF_prediction_iccv(var_xp,F,Q,G) +X = var_xp.X; +P = var_xp.P; + +X = F*X; +P = F*P*F' +G*Q*G'; + +var_xp.X = X; +var_xp.P = P; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/KF_prediction_iccv2.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/KF_prediction_iccv2.m new file mode 100644 index 0000000000000000000000000000000000000000..b71dff1daac23eca75625e01f7df6e1e0b8af930 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/KF_prediction_iccv2.m @@ -0,0 +1,5 @@ +function [X,P]=KF_prediction_iccv2(X,P,F,Q,G) + +X = F*X; +P = F*P*F' +G*Q*G'; + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/KF_update_iccv.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/KF_update_iccv.m new file mode 100644 index 0000000000000000000000000000000000000000..944b559933ff5095af2786c07abfd9128a300cca --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/KF_update_iccv.m @@ -0,0 +1,20 @@ +function [var_xp]=KF_update_iccv(meas,var_xp,R,H) + +N = size(var_xp.X,1); + +X = var_xp.X; +P = var_xp.P; + +% cov_dist = diag(meas(3:4)/2 + X(5:6)/2).^2; +% Rcov = [cov_dist, zeros(2,2);zeros(2,2), R(3:4,3:4)]; + +% S = H*P*H' + Rcov; +S = H*P*H' + R; +K = P*H'*inv(S); +X = X + K*(meas-H*X); +P = (eye(N)-K*H)*P; + + +var_xp.X = X; +var_xp.P = P; +% var_xp.X_set = [var_xp.X_set X]; \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/munkres.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/munkres.m new file mode 100644 index 0000000000000000000000000000000000000000..c150740ddc41c87a35fbe636f346db0953c75555 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/other_codes/munkres.m @@ -0,0 +1,154 @@ +function [assignment,cost] = munkres(costMat) +% MUNKRES Munkres Assign Algorithm +% +% [ASSIGN,COST] = munkres(COSTMAT) returns the optimal assignment in ASSIGN +% with the minimum COST based on the assignment problem represented by the +% COSTMAT, where the (i,j)th element represents the cost to assign the jth +% job to the ith worker. +% + +% This is vectorized implementation of the algorithm. It is the fastest +% among all Matlab implementations of the algorithm. + +% Examples +% Example 1: a 5 x 5 example +%{ +[assignment,cost] = munkres(magic(5)); +[assignedrows,dum]=find(assignment); +disp(assignedrows'); % 3 2 1 5 4 +disp(cost); %15 +%} +% Example 2: 400 x 400 random data +%{ +n=400; +A=rand(n); +tic +[a,b]=munkres(A); +toc % about 6 seconds +%} + +% Reference: +% "Munkres' Assignment Algorithm, Modified for Rectangular Matrices", +% http://csclab.murraystate.edu/bob.pilgrim/445/munkres.html + +% version 1.0 by Yi Cao at Cranfield University on 17th June 2008 + +assignment = false(size(costMat)); +cost = 0; + +costMat(costMat~=costMat)=Inf; +validMat = costMat3) + N = 1:Size-1; + + Trans1 = state(:,Size)-state(:,Size-N(1)); + Trans2 = state(:,Size-N(1))-state(:,Size-N(2)); + Trans3 = state(:,Size-N(2))-state(:,Size-N(3)); + + Trans = 0.33*Trans1 + 0.33*Trans2 + 0.33*Trans3; +else + + N = 1:Size-1; + + Trans1 = state(:,Size)-state(:,Size-N(1)); + Trans2 = state(:,Size-N(1))-state(:,Size-N(2)); + + Trans = 0.5*Trans1 + 0.5*Trans2; +end diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/detection_conversion.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/detection_conversion.m new file mode 100644 index 0000000000000000000000000000000000000000..83d92dcf985931b7ed58d73fb5c202919cb29b06 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/detection_conversion.m @@ -0,0 +1,37 @@ +function [Detect, Detection_App, NofDet, det_bbox] = detection_conversion(observation, f, opt, framergb) + + + +%% Input conversion +det_bbox = observation{f}.bbox; +% det_bbox = [left upper X, left upper Y, Width, Height]; +% det_bbox: N (# of detections) by M (detection dimension) +det_hist = {}; +for i=1:size(det_bbox,1) + d_bbox_rgb = img_crop(det_bbox(i,:),framergb, 128, 64); + d_bbox_hsv = double(rgb2hsv(d_bbox_rgb)); + h_crop = d_bbox_hsv(:,:,1); s_crop = d_bbox_hsv(:,:,2); v_crop = d_bbox_hsv(:,:,3); + + d_h_feat = hist(h_crop(:),64)/(128*64); + d_s_feat = hist(s_crop(:),64)/(128*64); + d_v_feat = hist(v_crop(:),64)/(128*64); + d_all_feat = [d_h_feat(:); d_s_feat(:); d_v_feat(:)]/3; + det_hist{i} = d_all_feat(:); +end + + +%% Detection Conversion +Detect=[]; Idx = 0; +Detection_App = {}; % Input Detection Appearance (HSV histogram) +NofDet = size(det_bbox,1); +for i=1:NofDet + if(det_bbox(i,1)>-1*opt.img_margin_u && det_bbox(i,2)>-opt.img_margin_u && fix(det_bbox(i,1) + det_bbox(i,3))= opt.s_size(1) && Size_H <= opt.s_size(3)) + Idx = Idx + 1; + Detect = [Detect; det_bbox(i,:)]; % Detection Input + Detection_App{Idx} = det_hist{i}; + end + end +end +NofDet = Idx; % Number of detections \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/img_crop.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/img_crop.m new file mode 100644 index 0000000000000000000000000000000000000000..8c6862f65ed4dc35bce550a5d682a5b2f892a437 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/img_crop.m @@ -0,0 +1,11 @@ +function d_bbox = img_crop(ss,img, hei, wid) + +ss = fix(ss); +A = max(ss(2),1); +B = min(ss(2)+ss(4),size(img,1)); +C = max(ss(1),1); +D = min(ss(1)+ss(3),size(img,2)); + + + +d_bbox = imresize(img(A:B, C:D,:),[hei wid]); diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/init_relation_func_Cart.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/init_relation_func_Cart.m new file mode 100644 index 0000000000000000000000000000000000000000..9f6f94ce4bf77ec4ccbd274572782372e11d44c3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/init_relation_func_Cart.m @@ -0,0 +1,9 @@ +function [Var] = init_relation_func_Cart(s1,s2) + + +diff_s = s1-s2; +TransX = diff_s(1); +TransY = diff_s(2); +Var.X = [TransX TransY 0 0]'; +Var.P = [2 0 0 0;0 2 0 0;0 0 2 0;0 0 0 2].^2; + diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/match_initialization.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/match_initialization.m new file mode 100644 index 0000000000000000000000000000000000000000..3aafa7130792034b717f9344ce31a605d07c36da --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/match_initialization.m @@ -0,0 +1,106 @@ +function [InitObj, InitObj_Hist, Match_Init, Match_Init_Hist] = match_initialization(new_set, new_set_hist, Match_Init, Match_Init_Hist, f, opt) + + +% % Match_Init: matched set in initialization step +% % new_set: new set of detections +InitObj = {}; % Object for initialization +InitObj_Hist = {}; % Object for initialization + + + +% Match_Init: matched set in initialization step +% new_set: new set of detections +idx = 0; idx_a = []; idx_c = []; +InitObj = {}; % Object for initialization +InitObj_Hist = {}; % Object for initialization +if(isempty(Match_Init) && ~isempty(new_set)) + for i=1:size(new_set,2) + idx = idx + 1; + Match_Init{idx} = [new_set(1:4,i);f;idx]; + Match_Init_Hist{idx} = new_set_hist{i}; + end +elseif(~isempty(Match_Init) && ~isempty(new_set)) + MS = size(Match_Init,2); NS = size(new_set,2); + for i=1:MS + m_state = Match_Init{i}(1:4,end); + Cost = 1000; selidx = 0; + for j=1:NS + if(sum(idx_a==j)~=1) + n_state = new_set(1:4,j); + thresh_dist = norm([n_state(3), n_state(3)]); + dist_cost = norm(m_state(1:2)-n_state(1:2)); + if(dist_cost < thresh_dist*0.5) + h_ratio = abs(m_state(4) - n_state(4))/(m_state(4) + n_state(4)); + if(h_ratio < 0.2) + if(Cost>h_ratio) + Cost = h_ratio; + selidx = j; + idx_c = [idx_c i]; + end + end + end + end + end + if(selidx~=0) + idx = idx + 1; + idx_a = [idx_a selidx]; + % Associated + add_set = [new_set(1:4,selidx);f;Match_Init{i}(5,end)]; + Match_Init{i} = [Match_Init{i},add_set]; + Match_Init_Hist{i} = new_set_hist{selidx}; % Histogram + end + end + + + % Rearrange + idx_c = unique(idx_c); + match_set_temp ={}; + match_set_hist_temp = {}; + idx_n=0; + for i=1:MS + if(sum(idx_c==i)) + idx_n = idx_n + 1; + Size = size(Match_Init{i},2); + match_set_temp{idx_n} = [Match_Init{i}(1:5,:);idx_n*ones(1,Size)]; + match_set_hist_temp{idx_n} = Match_Init_Hist{i}; + end + end + + Match_Init = match_set_temp; + Match_Init_Hist = match_set_hist_temp; + % Not associated + for i=1:NS + if(sum(idx_a==i)~=1) + idx = size(Match_Init,2) + 1; + Match_Init{idx} = [new_set(1:4,i);f;idx]; + Match_Init_Hist{idx} = new_set_hist{i}; + end + end +else + % there is no new set of detections + % remove all + Match_Init = {}; + Match_Init_Hist = {}; +end + + +% Selecting the matched set for initialization +Match_Init_temp = {}; +Match_Init_Hist_temp = {}; +if(~isempty(Match_Init)) + idx = 0; idx_n = 0; + for i = 1:size(Match_Init,2) + Size = size(Match_Init{i},2); + if(Size >= opt.init_frames) + idx = idx + 1; + InitObj{idx} = Match_Init{i}; + InitObj_Hist{idx} = Match_Init_Hist{i}; + else + idx_n = idx_n + 1; + Match_Init_temp{idx_n} = [Match_Init{i}(1:5,:);idx_n*ones(1,Size)]; + Match_Init_Hist_temp{idx_n} = Match_Init_Hist{i}; + end + end + Match_Init = Match_Init_temp; + Match_Init_Hist = Match_Init_Hist_temp; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/object_initialization.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/object_initialization.m new file mode 100644 index 0000000000000000000000000000000000000000..d93ee959bbd936d5383398f0921003534c0c9abb --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/object_initialization.m @@ -0,0 +1,126 @@ +function [Track, NewT, param] = object_initialization(InitObj, InitObj_Hist, Track, NewT, param) + + +% Object Initialization +% Initialization of Track +if(isempty(Track) && ~isempty(InitObj)) + idx = 0; + for i = 1:size(InitObj,2) + idx = idx + 1; + param.MAX_LAB = param.MAX_LAB + 1; + + NewT = [NewT idx]; + % state + SSS = InitObj{i}(1:4,:); % States (Left upper X, Left upper Y, Width, Height) + % left upper and right bottom + S = SSS(1:2,:) + SSS(3:4,:)/2; + [Trans] = compute_translation(S); + Track{idx}.states = [SSS(1:2,:)+SSS(3:4,:)/2; SSS(3:4,:); repmat(Trans,1,size(S,2))]; % (Cen X, Cen Y, Width, Height) + % Track{idx}.states_result = Track{idx}.states; + State = [S(1:2,end);Trans;SSS(3:4,end)]; % State (X,Y,tX,tY,W,H) + Track{idx}.X = State; % State (X,Y,tX,tY,W,H) + Track{idx}.Xp = State; % Predicted State (X,Y,tX,tY,W,H) + Track{idx}.P = param.P; % Covariance (X,Y,tX,tY,W,H) + Track{idx}.Pp = param.P; % Predicted Covariance (X,Y,tX,tY,W,H) + % frame information + Track{idx}.frame = InitObj{i}(5,:); % history of frame + Track{idx}.sframe = InitObj{i}(5,1); % starting frame + + % Appearance (HSV) + Track{idx}.HSV = InitObj_Hist{i}; + Track{idx}.Appearance = InitObj_Hist{i}(:,1); + % RMN + % track link information GRAPH + Track{idx}.graph = []; + Track{idx}.link = []; + + % Graph weight + Track{idx}.graph_weight = []; + + % state from other nodes + Track{idx}.graph_x = State; % node state + + % an associated detection + Track{idx}.detection = [State(1),State(2),State(5),State(6)]'; + + % a probability associated with detection + Track{idx}.asso_spatial = []; + Track{idx}.asso_hist = []; + + % Track survival + Track{idx}.survival = 1; + + % label + Track{idx}.lab = param.MAX_LAB; + + %Track unreliable + Track{idx}.unreliable = 0; + + % Track confidence in 3 levels + Track{idx}.confidence = 2; + + Track{idx}.not_detected = 0; + + Track{idx}.re_detected = 0; + end +elseif(~isempty(Track) && ~isempty(InitObj)) + for i = 1:size(InitObj,2) + idx = length(Track) + 1; + NewT = [NewT idx]; + param.MAX_LAB = param.MAX_LAB + 1; + + % state + SSS = InitObj{i}(1:4,:); % States (Left upper X, Left upper Y, Width, Height) + % left upper and right bottom + S = SSS(1:2,:) + SSS(3:4,:)/2; + [Trans] = compute_translation(S); + Track{idx}.states = [SSS(1:2,:)+SSS(3:4,:)/2; SSS(3:4,:); repmat(Trans,1,size(S,2))]; % (Cen X, Cen Y, Width, Height) + % Track{idx}.states_result = Track{idx}.states; + State = [S(1:2,end);Trans;SSS(3:4,end)]; % State (X,Y,tX,tY,W,H) + Track{idx}.X = State; % State (X,Y,tX,tY,W,H) + Track{idx}.Xp = State; % Predicted State (X,Y,tX,tY,W,H) + Track{idx}.P = param.P; % Covariance (X,Y,tX,tY,W,H) + Track{idx}.Pp = param.P; % Predicted Covariance (X,Y,tX,tY,W,H) + % frame information + Track{idx}.frame = InitObj{i}(5,:); % history of frame + Track{idx}.sframe = InitObj{i}(5,1); % starting frame + + % Appearance (HSV) + Track{idx}.HSV = InitObj_Hist{i}; + Track{idx}.Appearance = InitObj_Hist{i}(:,1); + + % RMN + % track link information GRAPH + Track{idx}.graph = []; + Track{idx}.link = []; + + % Graph weight + Track{idx}.graph_weight = []; + + % state from other nodes + Track{idx}.graph_x = State; % node state + + % an associated detection + Track{idx}.detection = [State(1),State(2),State(5),State(6)]'; + + % a probability associated with detection + Track{idx}.asso_spatial = []; + Track{idx}.asso_hist = []; + + % Track survival + Track{idx}.survival = 1; + + % label + Track{idx}.lab = param.MAX_LAB; + + %Track unreliable + Track{idx}.unreliable = 0; + + % Track confidence in 3 levels + Track{idx}.confidence = 2; + + Track{idx}.not_detected = 0; + + Track{idx}.re_detected = 0; + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/prediction_rmn.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/prediction_rmn.m new file mode 100644 index 0000000000000000000000000000000000000000..24e8573729a6b25a572e9431005cb580fc1320c3 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/prediction_rmn.m @@ -0,0 +1,97 @@ +function [Track] = prediction_rmn(Track, RMN, param) + +% Node motion +for i=1:length(Track) + State = Track{i}.X; + P = Track{i}.P; + [State,P] = KF_prediction_iccv2(State, P, param.F, param.Q, param.G); % Prediction + Track{i}.Xp = State; + Track{i}.Pp = P; +end + +% relative motion from neighbor objects +for i=1:length(Track) + GP = Track{i}.graph; % node index to i-th Track + s_node = Track{i}.Xp; % predicted state of the node + graph_x_prev = Track{i}.graph_x; + + % Track{i}.graph = []; + Track{i}.graph_x = []; + Track{i}.graph_x = s_node(1:6); TN = s_node(3:4); WH = s_node(5:6); + lab1 = Track{i}.lab; % the node target label + graph_weight_idx = i; + for j=1:size(GP,2) % Insert states from relationa function + idx = GP(j); % the neighbor node index + state_o = Track{idx}.Xp; % the neighbor node state + lab2 = Track{idx}.lab; % the neighbor node target label + Rtrans = param.Fr*RMN(lab1,lab2).state.X; % relational translation + trans_state = state_o(1:4)+ Rtrans(1:4); + T_state = [trans_state; WH]; % Transfered state + % is it within the image ? + Track{i}.graph_x = [Track{i}.graph_x, T_state]; + graph_weight_idx = [graph_weight_idx, idx]; + end + + % Check link + graph_weight_idx_prev = Track{i}.graph_weight; + not_equal = 0; + + if(size(graph_weight_idx_prev,2) ~= size(graph_weight_idx,2) || isempty(graph_weight_idx_prev)) + not_equal = 1; + else + for j=1:size(graph_weight_idx_prev,2) + if(graph_weight_idx_prev(2,j)~=graph_weight_idx(j)) + not_equal = 1; + end + end + end + + + graph_weight_val = Track{i}.graph_weight; + if(isempty(graph_weight_val) || not_equal==1) + % Graph weight + Track{i}.graph_weight = [1/size(graph_weight_idx,2)*ones(1,size(graph_weight_idx,2));graph_weight_idx]; + else + Track{i}.graph_weight = [graph_weight_val(1,:);graph_weight_idx]; + end + + +end + + + +% Partintion of Tracks in terms of positions +% Position threshold comute by two objects width and height from its centers +for i=1:length(Track) + idx = 0; + state = Track{i}.graph_x; % [X, Y, tX, tY, W, H] + s_i = [state(1:2,:); state(5:6,:)]; %[left upper X, Y, W, H] + Track{i}.partition = []; + for j=1:length(Track) + state = Track{j}.graph_x; % [X, Y, tX, tY, W, H] + s_j = [state(1:2,:); state(5:6,:)]; %[left upper X, Y, W, H] + if(i==j) + Track{i}.partition = [Track{i}.partition, j]; + else + idx = idx + 1; + Over_Mat = zeros(size(s_i,2),size(s_j,2)); + for i2 = 1:size(s_i,2) + for j2 = 1:size(s_j,2) + XY_i = s_i(1:2,i2); WH_i = s_i(3:4,i2)/2; + XY_j = s_j(1:2,j2); WH_j = s_j(3:4,j2)/2; + + Wid = (WH_i(1)+WH_j(1)); Hei = (WH_i(2)+WH_j(2)); + Thresh = 2*sqrt(Wid^2 + Wid^2); + + Dist = norm(XY_i-XY_j)/Thresh; + Over_Mat(i2,j2) = Dist; + end + end + MinVal = min(min(Over_Mat)); + if MinVal < 1 + Track{i}.partition = [Track{i}.partition, j]; % Track numbers in the i-th track partition + end + end + end + +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/rmn_initialization.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/rmn_initialization.m new file mode 100644 index 0000000000000000000000000000000000000000..e7de5688908e131be2d56e9e134866b6a60f45e9 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/rmn_initialization.m @@ -0,0 +1,54 @@ +function [RMN, Track] = rmn_initialization(Track,param,f) + + +for i = 1:length(Track) + state1 = Track{i}.states; + frame1 = Track{i}.frame; + num1 = size(frame1,2); + lab1 = Track{i}.lab; + for j = 1:length(Track) + lab2 = Track{j}.lab; + if(lab1~=lab2) + state2 = Track{j}.states; + frame2 = Track{j}.frame; + num2 = size(frame2,2); + RMN(lab1,lab2).set = []; + + num_frame = min(num1,num2); + flagk = 1; + + for k= 1 : num_frame + s1 = state1(1:2,num1 - num_frame + k); s2 = state2(1:2,num2 - num_frame + k); + f1 = frame1(num1 - num_frame + k); f2 = frame2(num2 - num_frame + k); + if(f1==f2) + if(flagk==1) + % initialization + [Var] = init_relation_func_Cart(s1,s2); + flagk = 0; + else + % Kalman filtering + Dist = s1 - s2; + meas = [Dist(1) Dist(2)]'; + [Var] = KF_prediction_iccv(Var,param.Fr,param.Qr,param.Gr); % Prediction + [Var] = KF_update_iccv(meas,Var,param.Rr,param.Hr); % Update + end + end + end + %% modify + if(~isfield('Var', 'X')) + diff_s = s1-s2; + TransX = diff_s(1); + TransY = diff_s(2); + Var.X = [TransX TransY 0 0]'; + end + Var.P = [2 0 0 0;0 2 0 0;0 0 2 0;0 0 0 2].^2; + Size = [state1(3,end);state2(3,end);state1(4,end);state2(4,end)]; + RMN(lab1,lab2).frames = f; + RMN(lab1,lab2).set = [RMN(lab1,lab2).set, Var.X]; +% RMN(lab1,lab2).size = Size; + RMN(lab1,lab2).state = Var; % Relational Function (input lab2-th state, output: lab1-th state) + Track{i}.graph = [Track{i}.graph, j]; % Graph initialization + Track{i}.link = [Track{i}.link, j]; + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/rmn_observation.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/rmn_observation.m new file mode 100644 index 0000000000000000000000000000000000000000..9b8f8595460357ba2382b7a7fe9d2189cc81793f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/rmn_observation.m @@ -0,0 +1,40 @@ +function [RMN] = rmn_observation(Track, RMN) + +% initialization +for i=1:length(Track) + lab1 = Track{i}.lab; + for j=1:length(Track) + lab2 = Track{j}.lab; + RMN(lab1,lab2).MeasSet = []; + end +end +for i=1:length(Track) + lab1 = Track{i}.lab; + det1 = Track{i}.detection; + if(~isempty(det1)) +% det1 = det1(1:2) + det1(3:4)/2; + for j=1:length(Track) + lab2 = Track{j}.lab; + if(lab1~=lab2) + det2 = Track{j}.detection; + if(~isempty(det2)) % 1st case +% det2 = det2(1:2) + det2(3:4)/2; + MeasSet = det1(1:2) - det2(1:2); + for k=1:length(Track) + lab3 = Track{k}.lab; + if(lab2~=lab3) + est3 = Track{k}.X; + det3 = Track{k}.detection; + if( ~isempty(det3)) % 1st case +% det3 = det3(1:2) + det3(3:4)/2; + Meas_Ele = det1(1:2) - (det2(1:2) - det3(1:2) + est3(1:2)); + MeasSet = [MeasSet, Meas_Ele]; + end + end + end + RMN(lab1,lab2).MeasSet = MeasSet; + end + end + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/rmn_update.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/rmn_update.m new file mode 100644 index 0000000000000000000000000000000000000000..5bca170d3aab9eb39829093d59b72df2cc0afd7f --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/rmn_update.m @@ -0,0 +1,149 @@ +function [RMN,Track] = rmn_update(Track,RMN,NewT, opt, param,f) + + +Q = param.Qr; + +for i = 1:(length(Track)-size(NewT,2)) + state1 = Track{i}.X; + lab1 = Track{i}.lab; % relational function index + Det1 = Track{i}.detection; + Track{i}.link = []; + for j=1:(length(Track) - size(NewT,2)) + state2 = Track{j}.X; + lab2 = Track{j}.lab; % relational function index + Det2 = Track{j}.detection; + + if(lab1~=lab2) + if(~isempty(RMN(lab1,lab2).state)) % if relation_func is empty + % update in 3 cases + % 1) both tracks (nodes) are associated with one of current detections -> link + % 2) a root track is associated with one of current detections -> link + % 3) a root track is not associated with any of current detections -> link failure + Var = RMN(lab1,lab2).state; + if(~isempty(RMN(lab1,lab2).MeasSet)) % 1st case + + MeasSet = RMN(lab1,lab2).MeasSet; + +% [Q] = instant_Q(RMN(lab1,lab2).set,param.Qr); + + [Var] = KF_prediction_iccv(Var,param.Fr,Q,param.Gr); % Prediction + Xp = Var.X; + Pp = Var.P; + + Yp = inv(Pp); + yp = Yp*Xp; + + + sumI = zeros(4,4); + sumi = zeros(4,1); +% for kk=1:size(MeasSet,2) +% if(kk==1) +% R = param.Rr; +% else +% R = 2^2*param.Rr; +% end +% +% sumI = sumI + param.Hr'*inv(R)*param.Hr; +% sumi = sumi + param.Hr'*inv(R)*MeasSet(:,kk); +% end + + for kk=1:1 + if(kk==1) + R = param.Rr; + else + R = 2^2*param.Rr; + end + + sumI = sumI + param.Hr'*inv(R)*param.Hr; + sumi = sumi + param.Hr'*inv(R)*MeasSet(:,kk); + end + + + Y = Yp + sumI; + y = yp + sumi; + + Var.P = inv(Y); + Var.X = Var.P*y; + + + + if(Track{i}.not_detected ==1 || Track{j}.not_detected ==1) + Var.X = [Var.X(1), Var.X(2), 0, 0]'; + Var.P = diag([Var.P(1,1),Var.P(1,1),2*Var.P(3,3),2*Var.P(4,4)]'); + end + + + + RMN(lab1,lab2).state = Var; % Relational Function upper (input lab2-th state, output: lab1-th state) + RMN(lab1,lab2).frames = [RMN(lab1,lab2).frames, f]; + RMN(lab1,lab2).set = [RMN(lab1,lab2).set, Var.X]; + Track{i}.graph = [Track{i}.graph, j]; + Track{i}.link = [Track{i}.link, j]; + + elseif(isempty(Det1) && ~isempty(Det2)) % 2nd case + % [Q] = instant_Q(RMN(lab1,lab2).set,param.Qr); + [Var] = KF_prediction_iccv(Var,param.Fr,Q,param.Gr); % Prediction + % Store new updated data + RMN(lab1,lab2).state = Var; % Relational Function upper (input lab2-th state, output: lab1-th state) + RMN(lab1,lab2).frames = [RMN(lab1,lab2).frames, f]; + RMN(lab1,lab2).set = [RMN(lab1,lab2).set, Var.X]; + Track{i}.graph = [Track{i}.graph, j]; + + elseif(~isempty(Det1) && isempty(Det2)) % 3rd case +% [Q] = instant_Q(RMN(lab1,lab2).set,param.Qr); + [Var] = KF_prediction_iccv(Var,param.Fr,Q,param.Gr); % Prediction + % Store new updated data + RMN(lab1,lab2).state = Var; % Relational Function upper (input lab2-th state, output: lab1-th state) + RMN(lab1,lab2).frames = [RMN(lab1,lab2).frames, f]; + RMN(lab1,lab2).set = [RMN(lab1,lab2).set, Var.X]; + Track{i}.link = [Track{i}.link, j]; + + elseif(~isempty(Det1) && ~isempty(Det2)) +% [Q] = instant_Q(RMN(lab1,lab2).set,param.Qr); + [Var] = KF_prediction_iccv(Var,param.Fr,Q,param.Gr); % Prediction + % Store new updated data + RMN(lab1,lab2).state = Var; % Relational Function upper (input lab2-th state, output: lab1-th state) + RMN(lab1,lab2).frames = [RMN(lab1,lab2).frames, f]; + RMN(lab1,lab2).set = [RMN(lab1,lab2).set, Var.X]; + end + else % if relation_func is empty ? + if(~isempty(Det1) && ~isempty(Det2)) + state1 = Track{i}.states; N1 = size(state1,2); + state2 = Track{j}.states; N2 = size(state2,2); + + RMN(lab1,lab2).set = []; + if(opt.init_frames==5) + IDX = [5 4 3 2 1 0]; + elseif(opt.init_frames==4) + IDX = [4 3 2 1 0]; + elseif(opt.init_frames==3) + IDX = [3 2 1 0]; + elseif(opt.init_frames==2) + IDX = [2 1 0]; + end + + for k=1:opt.init_frames+1 + idx1 = N1 - IDX(k); idx2 = N2 - IDX(k); + s1 = state1(1:2,idx1); s2 = state2(1:2,idx2); + if(k==1) + % initialization + [Var] = init_relation_func_Cart(s1,s2); + else + % Kalman filtering + Dist = s1 - s2; + meas = [Dist(1) Dist(2)]'; + [Var] = KF_prediction_iccv(Var,param.Fr,param.Qr,param.Gr); % Prediction + [Var] = KF_update_iccv(meas,Var,param.Rr,param.Hr); % Update + end + end + Var.P = [2 0 0 0;0 2 0 0;0 0 2 0;0 0 0 2].^2; + RMN(lab1,lab2).state = Var; % Relational Function (input lab2-th state, output: lab1-th state) + RMN(lab1,lab2).frames = [RMN(lab1,lab2).frames, f]; + RMN(lab1,lab2).set = [RMN(lab1,lab2).set, Var.X]; + Track{i}.graph = [Track{i}.graph, j]; % Graph initialization + Track{i}.link = [Track{i}.link, j]; + end + end + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/track_management.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/track_management.m new file mode 100644 index 0000000000000000000000000000000000000000..8acb71871e6c71a903c7c82fc90c613091c5917c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/track_management.m @@ -0,0 +1,17 @@ +function [Track] = track_management(Track) + +Track_temp = Track; +Track = {}; +idx = 0; +for i=1:length(Track_temp) + if(Track_temp{i}.survival ==1) + idx = idx + 1; + Track{idx} = Track_temp{i}; + end +end +% Graph (Link) initialization +for i=1:length(Track) + Track{i}.graph = []; + Track{i}.link = []; + Track{i}.graph_x = []; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/track_smooth.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/track_smooth.m new file mode 100644 index 0000000000000000000000000000000000000000..ca448cb81e8f36f722f6d6ef8b0104cbc2629ca8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/track_smooth.m @@ -0,0 +1,20 @@ +function [Track] = track_smooth(Track) + +for i=1:length(Track) + re_detected = Track{i}.re_detected; + if(re_detected == 1) + SizeN = size(Track{i}.states,2); + State_p = Track{i}.states(:,SizeN-1); + State_c = Track{i}.states(:,end); + frame_p = Track{i}.frame(SizeN-1); + frame_c = Track{i}.frame(SizeN); + + translation_link = (State_c - State_p)/(frame_c - frame_p); + frame_w = (1:(frame_c - frame_p)); + State_link = repmat(State_p,1,frame_c - frame_p) + repmat(frame_w,6,1).*repmat(translation_link,1,frame_c - frame_p); + frame_link = repmat(frame_p,1,frame_c - frame_p) + frame_w; + + Track{i}.states = [Track{i}.states(:,1:SizeN-1),State_link]; + Track{i}.frame = [Track{i}.frame(:,1:SizeN-1),frame_link]; + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/track_update_rmn.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/track_update_rmn.m new file mode 100644 index 0000000000000000000000000000000000000000..3c90e270e427e822dda5ab6d565c46f16aba8fd8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/rmn_function/track_update_rmn.m @@ -0,0 +1,76 @@ +function [Track] = track_update_rmn(Track, frame, opt, param, f) + + +for i = 1:length(Track) + Gp_x = Track{i}.graph_x; % predicted states from self motion and relational function + P = Track{i}.Pp; % predicted covariance + s_asso = Track{i}.asso_spatial; + Det = Track{i}.detection; + graph_weight = Track{i}.graph_weight; + + if(~isempty(Det) && max(s_asso)>=opt.PASCAL_Th) % Update with observations (Smoothness) + + + graph_weight(1,:) = graph_weight(1,:).*s_asso'; + graph_weight(1,:) = graph_weight(1,:)/sum(graph_weight(1,:)); + Track{i}.graph_weight = graph_weight; + + % select the most reliable node or neighbor + [max_val, max_idx] = max(s_asso); + x_max = Gp_x(:,max_idx); + cov_dist = diag(Det(3:4)/2 + x_max(5:6)/2).^2; + R = [cov_dist, zeros(2,2);zeros(2,2), param.R(3:4,3:4)]; + S = param.H*P*param.H' + R; + K = P*param.H'*inv(S); + x = x_max + K*(Det - param.H*x_max); + P = P - K*S*K'; + + Track{i}.X = x; + Track{i}.P = P; + + xstate = [x(1:2); x(5); x(6); x(3:4)]; % [center u, v, w, h, ut, vt] + + + Track{i}.states = [Track{i}.states, xstate]; + Track{i}.frame = [Track{i}.frame, f]; + + + % Learning (ON) + Track{i}.learn_on = 1; + + + if(Track{i}.not_detected == 0) % If the object is detected at the previous frame. + Track{i}.re_detected = 0; + else % If the object is not detected at the previous frame. + Track{i}.re_detected = 1; + end + + Track{i}.not_detected = 0; + + if(Track{i}.unreliable >0) + Track{i}.unreliable = 0; + end + x = param.F*x; + xu = x(1:2)-x(5:6)/2; xb = x(1:2)+x(5:6)/2; + if(xu(1)<1-opt.margin_u || xu(2)<1-opt.margin_v || xb(1)>opt.imgsz(2)+opt.margin_u || xb(2)>opt.imgsz(1)+opt.margin_v) % Out of View + Track{i}.survival = 0; + Track{i}.learn_on = 0; + Track{i}.graph_weight = []; + end + else % If detections are not associated + Track{i}.X = Track{i}.Xp; + Track{i}.P = Track{i}.Pp; + Track{i}.graph_weight = []; + x = Track{i}.X; + xstate = [x(1:2); x(5:6); x(3:4)]; + Track{i}.unreliable = Track{i}.unreliable + 1; + Track{i}.learn_on = 0; + Track{i}.not_detected = 1; + Track{i}.re_detected = 0; + x = param.F*x; + xu = x(1:2)-x(5:6)/2; xb = x(1:2)+x(5:6)/2; + if(xu(1)<1-opt.margin_u || xu(2)<1-opt.margin_v || xb(1)>opt.imgsz(2)+opt.margin_u || xb(2)>opt.imgsz(1)+opt.margin_v || Track{i}.unreliable > opt.max_gap) % Out of View + Track{i}.survival = 0; + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/run_tracker.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/run_tracker.m new file mode 100644 index 0000000000000000000000000000000000000000..1f6d8e481ca395a9d039f6beda94c6eee84a72ba --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/trackers/RMOT/run_tracker.m @@ -0,0 +1,217 @@ +function [stateInfo, speed] = run_tracker(curSequence, baselinedetections) +% Bayesian Multi-Object Tracking Using Motion Context from Multiple Objects (WACV2015) +% Last updated date: 2015. 04. 08 +% Copyright (C) 2015 Ju Hong Yoon, jh.yoon82@gmail.com +% All rights reserved. + +% Parameters +opt.display = false; +opt.print = false; +opt.s_size = [0, 0, 10000]; % height size for MOT +opt.d_ratio = [1,1]; % detection ratio (for width/height) +opt.cost_threshold = 2.5; +opt.cost_threshold2 = 2.5; +opt.PASCAL_Th = 0.1; % 0.2 +opt.Height_Th = 0.8; +opt.App_Th = 0.2; % 0.2 +opt.Hist_Th = 0.8; +opt.max_gap = 30; +opt.margin_u = 50; +opt.margin_v = 10000; +opt.learn = 0.9; +opt.app_off = 0; +opt.img_margin_u = 50; + +%% multi-object tracking +imgFolder = curSequence.imgFolder; +dataset = curSequence.dataset; + +% Sequence size +frame = imread([imgFolder dataset(1).name]); +[hs, ws, dims] = size(frame); +opt.imgsz = [hs,ws,dims]; % height size, width size, dimension +opt.init_frames = 4; +% Modeling +% filter parameters for motion and detection +filter_parameters(); + +% Data seqeunce +observation = parseDetection(baselinedetections, curSequence.frameNums); +Match_Init = {}; +Match_Init_Hist = {}; +Track = {}; +param.MAX_LAB = 0; +RMN = []; +dcStartTime = tic; +for fidx = 1:length(curSequence.frameNums) + f = curSequence.frameNums(fidx); + % frame index + frame = imread([imgFolder dataset(fidx).name]); + if(curSequence.frameNums(1) <= 1) + finput = fidx; + else + finput = f; + end + % Detection Conversion + [Detect, Detection_App] = detection_conversion(observation, finput, opt, frame); + % Tracking by Data Association + new_set = Detect'; % (detection dimension by number of detections) + new_set_hist = Detection_App; + % Initialization of Event + for i=1:length(Track) + Track{i}.Assignment = {}; + Track{i}.AssignmentCost = {}; + Track{i}.Penalty = {}; + Track{i}.EventCost = []; + end + % Current Track Label + if(~isempty(Track)) + Current_Label = zeros(1,length(Track)); + for i=1:length(Track) + Lab = Track{i}.lab; + Current_Label(i) = Lab; + end + end + % Initialization for Track Association + for i=1:length(Track) + Track{i}.detection = {}; + Track{i}.asso_spatial = {}; + end + %% Hierachical Search + associated_idx = []; + used_track_idx = []; + det_asso_idx = []; + [Cost2ndMat] = Cost_RMN(Track, RMN, new_set, new_set_hist, opt, param); + if(~isempty(Track) && ~isempty(new_set)) + [Assignment2, AssignCost] = munkres(Cost2ndMat); + for i=1:length(Track) + idx_m = find(Assignment2(i,:)==1); + if(Cost2ndMat(i,idx_m) < opt.cost_threshold2-eps) + Track{i}.detection = [new_set(1:2,idx_m)+new_set(3:4,idx_m)/2;new_set(3:4,idx_m)]; % associated (Track Label;Detection Label) + Track{i}.HSV = new_set_hist{idx_m}; + Track{i}.asso_spatial = 0.5; + det_asso_idx = [det_asso_idx, idx_m]; % collecting associated detections + associated_idx = [associated_idx, idx_m]; % Associated detection label + used_track_idx = unique([used_track_idx, i]); + end + end + end + % Smoothing + if(~isempty(Track)) + [Track] = track_update_rmn(Track, frame, opt, param, f); + [Track] = track_smooth(Track); + end + % Track save + if(~isempty(Track)) + for i=1:length(Track) + if(Track{i}.survival == 0) + Lab = Track{i}.lab; + Track_Save{Lab} = [Track{i}.states(1:4,:);Track{i}.frame]; + end + end + end + if(fidx==length(curSequence.frameNums)) + for i=1:length(Track) + Lab = Track{i}.lab; + Track_Save{Lab} = [Track{i}.states(1:4,:);Track{i}.frame]; + end + end + % Removing Associated detection + if(~isempty(det_asso_idx)) + new_set(:,det_asso_idx) = []; % remove assoicated detections + Idx = 0; + new_set_hist_temp = new_set_hist; + new_set_hist = {}; + for i=1:size(new_set_hist_temp,2) + if(sum(det_asso_idx==i)==0) + Idx = Idx + 1; + new_set_hist{Idx} = new_set_hist_temp{i}; + end + end + end + % Track Management + [Track] = track_management(Track); + % Matching for Initialization + [InitObj, InitObj_Hist, Match_Init, Match_Init_Hist] = match_initialization(new_set, new_set_hist, Match_Init, Match_Init_Hist, f, opt); + % Object Initialization + NewT = []; % New Track Index + [Track, NewT, param] = object_initialization(InitObj, InitObj_Hist, Track, NewT, param); + % RMN Update/Constructing RMN Observation + if(~isempty(RMN) && ~isempty(Track)) + [RMN] = rmn_observation(Track, RMN); + end + % Relative Motion Network Update + if(isempty(RMN) && ~isempty(Track) && ~isempty(NewT)) + if(length(Track)>1) + [RMN, Track] = rmn_initialization(Track, param, f); + end + elseif(~isempty(RMN) && ~isempty(Track)) + % RMN Update + [RMN, Track] = rmn_update(Track, RMN, NewT, opt, param, f); + if(~isempty(NewT)) % if NewTs exist + [RMN, Track] = adding_new_rmn(Track, NewT, RMN, opt, param, f); + end + end + % Track Link + for i=1:length(Track) + Track{i}.link = unique(Track{i}.link); + end + % Prediction Based on RMN + if(~isempty(Track)) + [Track] = prediction_rmn(Track, RMN, param); + end +end +%% Save tracking results for evaluation +speed = length(curSequence.frameNums)/toc(dcStartTime); +num_frame = length(curSequence.frameNums); +if(exist('Track_Save','var')) + num_obj = size(Track_Save,2); +else + num_obj = 1; +end +stateInfo = []; +stateInfo.F = curSequence.frameNums(end); +stateInfo.X = zeros(num_frame,num_obj); +stateInfo.Y = zeros(num_frame,num_obj); +stateInfo.targetsExist = zeros(num_obj,2); +stateInfo.tiToInd = zeros(num_frame,num_obj); +stateInfo.stateVec = []; +stateInfo.frameNums = curSequence.frameNums; +stateInfo.Xgp = zeros(num_frame,num_obj); +stateInfo.Ygp = zeros(num_frame,num_obj); +stateInfo.Xi = zeros(num_frame,num_obj); +stateInfo.Yi = zeros(num_frame,num_obj); +stateInfo.H = zeros(num_frame,num_obj); +stateInfo.W = zeros(num_frame,num_obj); + +if(exist('Track_Save','var')) + stateInfo.N = size(Track_Save,2); + idx = 1; + for i = 1:size(Track_Save,2) + Obj = Track_Save{i}; + for o=1:size(Obj,2) + State = Obj(:,o); + if(curSequence.frameNums(1)==0) + frame = State(5) + 1; + else + frame = State(5); + frame = frame - curSequence.frameNums(1) + 1; + end + State = State(1:4); + + % i: Label + % frame: frame index + stateInfo.tiToInd(frame,i) = idx; + stateInfo.stateVec = [stateInfo.stateVec;State(1)]; + stateInfo.X(frame,i) = State(1); + stateInfo.Y(frame,i) = State(2)+State(4)/2; + stateInfo.Xgp(frame,i) = State(1); % X position + stateInfo.Ygp(frame,i) = State(2); % Y position + stateInfo.Xi(frame,i) = State(1); + stateInfo.Yi(frame,i) = State(2)+State(4)/2; + stateInfo.H(frame,i) = State(4); % Width + stateInfo.W(frame,i) = State(3); % Height + idx = idx + 2; + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/checkOptions.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/checkOptions.m new file mode 100644 index 0000000000000000000000000000000000000000..bb9b4af4ce5529944a865e245304a8498e0210fc --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/checkOptions.m @@ -0,0 +1,95 @@ +function options = checkOptions(options) + +global tracker + +%% initial display +disp('************************************************************************************'); +disp('* Welcome to the UA-DETRAC MOT Toolkit v1.1! *'); +disp('* This is the official detection/tracking evaluation kit for the DETection and *'); +disp('* tRACking (DETRAC) Benchmark (http://detrac-db.rit.albany.edu/). *'); +disp('* More details can be found in the paper "UA-DETRAC: A New Benchmark and Protocol *'); +disp('* for Multi-Object Detection and Tracking". *'); +disp('* The UA-DETRAC Group @Copyright 2017 *'); +disp('************************************************************************************'); + +%% check command lines +if(nnz(ismember({'Detection','Tracking'},options.evaluateType)) == 0) + error('error in type of evaluation!'); +end +if(nnz(ismember({'DETRAC-Test','DETRAC-Test-Beginner','DETRAC-Test-Experienced','DETRAC-Train','DETRAC-Free'},options.evaluateSeqs)) == 0) + error('error in sequences for evaluation!'); +end +if(nnz(ismember({'DETRAC-MOT','CLEAR-MOT'},options.motmetric)) == 0) + error('error in MOT metric!'); +end + +%% check the tracker for evaluation +if(strcmp(options.evaluateType, 'Tracking')) + flagtracker = false; + folders = dir('trackers\'); + for i = 3:length(folders) + nameFolds = folders(i).name; + if(ismember(tracker.trackerName, nameFolds)) + flagtracker = true; + break; + end + end + if(~flagtracker) + error('error in the tracker name!'); + end +end + +%% check the detector for evaluation +if(strcmp(options.evaluateType, 'Detection') || strcmp(options.evaluateType, 'Tracking')) + flagdetector = true; + folders = dir(options.detPath); + nameFolds = []; + for i = 3:length(folders) + nameFolds{i-2} = folders(i).name; + end + for j = 1:length(options.detectorSet) + detectorName = options.detectorSet{j}; + if(nnz(ismember(detectorName, nameFolds))==0) + flagdetector = false; + break; + end + end + if(~flagdetector) + error('error in the detector name!'); + end +end + +%% check the sequences for evaluation +if(options.printEvaluationForEachSeq || options.printEvaluationForWholeSet) + fidTestSeq = fopen('evaluation\seqs\testlist-full.txt'); + testSeqs = []; + idSeq = 0; + while(~feof(fidTestSeq)) + % Data seqeunce + seqName = fgetl(fidTestSeq); + idSeq = idSeq + 1; + testSeqs{idSeq} = seqName; + end + fclose(fidTestSeq); + + fidSeq = fopen(options.seqPath); + while(~feof(fidSeq)) + % Data seqeunce + seqName = fgetl(fidSeq); + if(ismember(seqName, testSeqs)) + disp(['Warinig: the sequence ' seqName ' belongs to the DETRAC-test set, and no groundtruth files are avaliable!']); + disp('The evaluation is not avaliable!'); + options.printEvaluationForEachSeq = false; % if the groundtruh files are avalible, print the evaluation result for each sequence calculated by the CLEAR-MOT measure + options.printEvaluationForWholeSet = false; % if the groundtruh files are avalible, print the evaluation result for all the evaluated sequences calculated by options.motmetric + options.printDetectionEval = false; % if the groundtruh files are avalible, print the evaluation result for detection + options.showDetectionCurve = false; % show the detection PR curve when using DETRAC-MOT measure + end + end + fclose(fidSeq); +end + +%% check the mot metric +if(numel(options.detectionThreshold) == 1 && strcmp(options.motmetric, 'DETRAC-MOT')) + disp('Waring: If only one detection score threshold is selected, the DETRAC-MOT measure is not avalible. We should employ the CLEAR-MOT measure.'); + options.motmetric = 'CLEAR-MOT'; +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/deleteFolder.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/deleteFolder.m new file mode 100644 index 0000000000000000000000000000000000000000..8f37aceb359fe8189c59fe2819a4166040e9a40d --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/deleteFolder.m @@ -0,0 +1,13 @@ +function deleteFolder(filePath) + +Dirs = dir(filePath); +for i = 1:length(Dirs) + % remove directory and all contents + if(Dirs(i).isdir && ~strcmp(Dirs(i).name,'.') && ~strcmp(Dirs(i).name,'..')) + rmdir([filePath Dirs(i).name],'s'); + % delete the files in corresponding directory + elseif(~strcmp(Dirs(i).name,'.') && ~strcmp(Dirs(i).name,'..')) + delete([filePath Dirs(i).name]); + end +end +rmdir(filePath); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/genCutDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/genCutDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..4b3e3d7af20366b06727cfb30a790d74634a86e8 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/genCutDetections.m @@ -0,0 +1,8 @@ +function baselinedetections = genCutDetections(detections, idxDetections) + +baselinedetections = detections(idxDetections,:); +frameNums = unique(baselinedetections(:,1)); +for k = 1:length(frameNums) + curLine = find(baselinedetections(:,1) == frameNums(k)); + baselinedetections(curLine,2) = 1:numel(curLine); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/loadDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/loadDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..52280d1e648c0a0ddb570c955d0076085b8d21bf --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/loadDetections.m @@ -0,0 +1,7 @@ +function detections = loadDetections(detFile) + +if(~exist(detFile, 'file')) + error('no detection files'); +else + detections = load(detFile); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/parseDetections.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/parseDetections.m new file mode 100644 index 0000000000000000000000000000000000000000..d80a4cae3bc8201ade91390575db777089276b27 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/parseDetections.m @@ -0,0 +1,84 @@ +function detections = parseDetections(baselinedetections, frameNums) +% read detection file and create a struct array +% +% (C) Anton Andriyenko, 2012 +% +% The code may be used free of charge for non-commercial and +% educational purposes, the only requirement is that this text is +% preserved within the derivative work. For any other purpose you +% must contact the authors for permission. This code may not be +% redistributed without written permission from the authors. + +global sequences + +cnt = numel(frameNums); +detections(cnt).bx=[]; +detections(cnt).by=[]; +detections(cnt).xp=[]; +detections(cnt).yp=[]; +detections(cnt).ht=[]; +detections(cnt).wd=[]; +detections(cnt).sc=[]; + +detections(cnt).xi=[]; +detections(cnt).yi=[]; +for t = frameNums + cnt = t+1; + idxObj = find(baselinedetections(:,1) == t); + nObjects = numel(idxObj); + bx =[];by=[];xp=[];yp=[]; + ht=[];wd=[];sc=[]; + xi=[];yi=[]; + for j = 1:nObjects + loc = baselinedetections(idxObj(j), 3:6); + score = baselinedetections(idxObj(j), 7); + left = loc(1); + top = loc(2); + width = loc(3); + height = loc(4); + xis = left + width/2; + yis = top + height; + bx = cat(2, bx, left); + by=cat(2, by, top); + xp=cat(2, xp, xis); + yp=cat(2, xp, yis); + ht=cat(2, ht, height); + wd=cat(2, wd, width); + sc=cat(2, sc, score); + xi=cat(2, xi, xis); + yi=cat(2, yi, yis); + end + detections(cnt).bx=bx; + detections(cnt).by=by; + detections(cnt).xp=xp; + detections(cnt).yp=yp; + detections(cnt).ht=ht; + detections(cnt).wd=wd; + detections(cnt).sc=sc; + + detections(cnt).xi=xi; + detections(cnt).yi=yi; +end + +%% set xp and yp accordingly +detections = setDetectionPositions(detections); +end + +function detections = setDetectionPositions(detections) + % set xp,yp to xi,yi if tracking is in image (2d) + % set xp,yp to xw,yi if tracking is in world (3d) + global options + F = length(detections); + if(options.track3d) + assert(isfield(detections,'xw') && isfield(detections,'yw'), 'for 3D tracking detections must have fields ''xw'' and ''yw'''); + for t = 1:F + detections(t).xp=detections(t).xw; + detections(t).yp=detections(t).yw; + end + else + for t = 1:F + detections(t).xp=detections(t).xi; + detections(t).yp=detections(t).yi; + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/parseFolderName.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/parseFolderName.m new file mode 100644 index 0000000000000000000000000000000000000000..c621ebc5c9bb7115619c71d7e4449f62b6792b4c --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/parseFolderName.m @@ -0,0 +1,9 @@ +function folderName = parseFolderName(scoreSet) + +folderName = cell(1, length(scoreSet)); +fid = fopen('thresh.txt','w'); +for i = 1:length(scoreSet) + folderName{i} = sprintf('%.1f',scoreSet(i)); + fprintf(fid,'%s\n',folderName{i}); +end +fclose(fid); \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/parseGT.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/parseGT.m new file mode 100644 index 0000000000000000000000000000000000000000..cdbef4c7bc8460f3422b44244b081ddf96470dbe --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/parseGT.m @@ -0,0 +1,92 @@ +function gtInfo = parseGT(gtFile, imgHeight, imgWidth, frameNums) +%% parse the ground truth + +% first determine the type +[pathstr, filename, fileext] = fileparts(gtFile); +pathstr_mat = [pathstr(1:end-3) 'MAT']; +createPath(pathstr_mat); +% is there a .mat file available? +matfile = fullfile(pathstr_mat, [filename '.mat']); +if(exist(matfile,'file')) + % check for the variable gtInfo + fileInfo = who('-file', matfile); + varExists = 0; + cnt = 0; + while(~varExists && cnt1 + for i=1:length(data.sequence.ignored_region.box) + ignored_region = cat(1, ignored_region, [str2double(data.sequence.ignored_region.box{1, i}.Attributes.left)... + str2double(data.sequence.ignored_region.box{1, i}.Attributes.top)... + str2double(data.sequence.ignored_region.box{1, i}.Attributes.width)... + str2double(data.sequence.ignored_region.box{1, i}.Attributes.height)]); + end + else + %if region has only one box + ignored_region = cat(1, ignored_region, [str2double(data.sequence.ignored_region.box.Attributes.left)... + str2double(data.sequence.ignored_region.box.Attributes.top)... + str2double(data.sequence.ignored_region.box.Attributes.width)... + str2double(data.sequence.ignored_region.box.Attributes.height)]); + end +end +%% frame +for j=1:length(data.sequence.frame) + num = str2double(data.sequence.frame{1, j}.Attributes.num); + for jj = 1:length(data.sequence.frame{1, j}.target_list.target) + if length(data.sequence.frame{1, j}.target_list.target)>1 + + id = str2double(data.sequence.frame{1, j}.target_list.target{1, jj}.Attributes.id); + orientation = str2double(data.sequence.frame{1, j}.target_list.target{1, jj}.attribute.Attributes.orientation); + speed = str2double(data.sequence.frame{1, j}.target_list.target{1, jj}.attribute.Attributes.speed); + trajectory = str2double(data.sequence.frame{1, j}.target_list.target{1, jj}.attribute.Attributes.trajectory_length); + truncation_ratio = str2double(data.sequence.frame{1, j}.target_list.target{1, jj}.attribute.Attributes.truncation_ratio); + vehicle_type = data.sequence.frame{1, j}.target_list.target{1, jj}.attribute.Attributes.vehicle_type; + density=str2double(data.sequence.frame{1, j}.Attributes.density); + switch(vehicle_type) + case 'car' + vehicle_type = 1; + case 'bus' + vehicle_type = 2; + case 'truck' + vehicle_type = 3; + case 'van' + vehicle_type = 4; + case 'others' + vehicle_type = 5; + end + bheight = str2double(data.sequence.frame{1, j}.target_list.target{1, jj}.box.Attributes.height); + bwidth = str2double(data.sequence.frame{1, j}.target_list.target{1, jj}.box.Attributes.width); + bleft = str2double(data.sequence.frame{1, j}.target_list.target{1, jj}.box.Attributes.left); + btop = str2double(data.sequence.frame{1, j}.target_list.target{1, jj}.box.Attributes.top); + try + Occ = data.sequence.frame{1, j}.target_list.target{1, jj}.occlusion; + if(length(Occ.region_overlap)<2) + occlusion = cat(1, occlusion, [num id bleft btop bwidth bheight str2double( Occ.region_overlap.Attributes.occlusion_id) ... + str2double(Occ.region_overlap.Attributes.occlusion_status) str2double(Occ.region_overlap.Attributes.left),str2double( Occ.region_overlap.Attributes.top) ... + str2double(Occ.region_overlap.Attributes.width), str2double( Occ.region_overlap.Attributes.height)]); + else + for k =1:length(Occ.region_overlap) + occlusion = cat(1, occlusion, [num id bleft btop bwidth bheight , str2double( Occ.region_overlap{k}.Attributes.occlusion_id) ... + str2double(Occ.region_overlap{k}.Attributes.occlusion_status) str2double(Occ.region_overlap{k}.Attributes.left),str2double( Occ.region_overlap{k}.Attributes.top) ... + str2double(Occ.region_overlap{k}.Attributes.width), str2double( Occ.region_overlap{k}.Attributes.height)]); + end + end + catch + + end + gt = cat(1, gt, [bleft btop bwidth bheight num id sence_weather camera_state density trajectory... + orientation speed vehicle_type truncation_ratio]); + else + + id = str2double(data.sequence.frame{1, j}.target_list.target.Attributes.id); + + orientation = str2double(data.sequence.frame{1, j}.target_list.target.attribute.Attributes.orientation); + speed = str2double(data.sequence.frame{1, j}.target_list.target.attribute.Attributes.speed); + trajectory = str2double(data.sequence.frame{1, j}.target_list.target.attribute.Attributes.trajectory_length); + truncation_ratio = str2double(data.sequence.frame{1, j}.target_list.target.attribute.Attributes.truncation_ratio); + vehicle_type = data.sequence.frame{1, j}.target_list.target.attribute.Attributes.vehicle_type; + density=str2double(data.sequence.frame{1, j}.Attributes.density); + switch(vehicle_type) + case 'car' + vehicle_type = 1; + case 'bus' + vehicle_type = 2; + case 'truck' + vehicle_type = 3; + case 'van' + vehicle_type = 4; + case 'others' + vehicle_type = 5; + end + bheight = str2double(data.sequence.frame{1, j}.target_list.target.box.Attributes.height); + bwidth = str2double(data.sequence.frame{1, j}.target_list.target.box.Attributes.width); + bleft = str2double(data.sequence.frame{1, j}.target_list.target.box.Attributes.left); + btop = str2double(data.sequence.frame{1, j}.target_list.target.box.Attributes.top); + try + Occ = data.sequence.frame{1, j}.target_list.target.occlusion; + if(length(Occ.region_overlap)<2) + occlusion = cat(1, occlusion, [num id bleft btop bwidth bheight , str2double( Occ.region_overlap.Attributes.occlusion_id) ... + str2double(Occ.region_overlap.Attributes.occlusion_status) str2double(Occ.region_overlap.Attributes.left),str2double( Occ.region_overlap.Attributes.top) ... + str2double(Occ.region_overlap.Attributes.width), str2double( Occ.region_overlap.Attributes.height)]); + else + for k =1:length(Occ.region_overlap) + occlusion = cat(1, occlusion, [num id bleft btop bwidth bheight str2double( Occ.region_overlap{k}.Attributes.occlusion_id) ... + str2double(Occ.region_overlap{k}.Attributes.occlusion_status) str2double(Occ.region_overlap{k}.Attributes.left),str2double( Occ.region_overlap{k}.Attributes.top) ... + str2double(Occ.region_overlap{k}.Attributes.width), str2double( Occ.region_overlap{k}.Attributes.height)]); + end + end + catch + + end + + gt = cat(1, gt, [bleft btop bwidth bheight num id sence_weather camera_state density trajectory... + orientation speed vehicle_type truncation_ratio]); + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/xml2struct.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/xml2struct.m new file mode 100644 index 0000000000000000000000000000000000000000..720714b6d088718b2e6dfaa904fee1dec76e7039 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/xml2struct.m @@ -0,0 +1,183 @@ +function [s] = xml2struct(file) +%Convert xml file into a MATLAB structure +% [ s ] = xml2struct( file ) +% +% A file containing: +% +% Some text +% Some more text +% Even more text +% +% +% Will produce: +% s.XMLname.Attributes.attrib1 = "Some value"; +% s.XMLname.Element.Text = "Some text"; +% s.XMLname.DifferentElement{1}.Attributes.attrib2 = "2"; +% s.XMLname.DifferentElement{1}.Text = "Some more text"; +% s.XMLname.DifferentElement{2}.Attributes.attrib3 = "2"; +% s.XMLname.DifferentElement{2}.Attributes.attrib4 = "1"; +% s.XMLname.DifferentElement{2}.Text = "Even more text"; +% +% Please note that the following characters are substituted +% '-' by '_dash_', ':' by '_colon_' and '.' by '_dot_' +% +% Written by W. Falkena, ASTI, TUDelft, 21-08-2010 +% Attribute parsing speed increased by 40% by A. Wanner, 14-6-2011 +% Added CDATA support by I. Smirnov, 20-3-2012 +% +% Modified by X. Mo, University of Wisconsin, 12-5-2012 + + if (nargin < 1) + clc; + help xml2struct + return + end + + if isa(file, 'org.apache.xerces.dom.DeferredDocumentImpl') || isa(file, 'org.apache.xerces.dom.DeferredElementImpl') + % input is a java xml object + xDoc = file; + else + %check for existance + if (exist(file,'file') == 0) + %Perhaps the xml extension was omitted from the file name. Add the + %extension and try again. + if (isempty(strfind(file,'.xml'))) + file = [file '.xml']; + end + + if (exist(file,'file') == 0) + error(['The file ' file ' could not be found']); + end + end + %read the xml file + xDoc = xmlread(file); + end + + %parse xDoc into a MATLAB structure + s = parseChildNodes(xDoc); + +end + +% ----- Subfunction parseChildNodes ----- +function [children,ptext,textflag] = parseChildNodes(theNode) + % Recurse over node children. + children = struct; + ptext = struct; textflag = 'Text'; + if hasChildNodes(theNode) + childNodes = getChildNodes(theNode); + numChildNodes = getLength(childNodes); + + for count = 1:numChildNodes + theChild = item(childNodes,count-1); + [text,name,attr,childs,textflag] = getNodeData(theChild); + + if (~strcmp(name,'#text') && ~strcmp(name,'#comment') && ~strcmp(name,'#cdata_dash_section')) + %XML allows the same elements to be defined multiple times, + %put each in a different cell + if (isfield(children,name)) + if (~iscell(children.(name))) + %put existsing element into cell format + children.(name) = {children.(name)}; + end + index = length(children.(name))+1; + %add new element + children.(name){index} = childs; + if(~isempty(fieldnames(text))) + children.(name){index} = text; + end + if(~isempty(attr)) + children.(name){index}.('Attributes') = attr; + end + else + %add previously unknown (new) element to the structure + children.(name) = childs; + if(~isempty(text) && ~isempty(fieldnames(text))) + children.(name) = text; + end + if(~isempty(attr)) + children.(name).('Attributes') = attr; + end + end + else + ptextflag = 'Text'; + if (strcmp(name, '#cdata_dash_section')) + ptextflag = 'CDATA'; + elseif (strcmp(name, '#comment')) + ptextflag = 'Comment'; + end + + %this is the text in an element (i.e., the parentNode) + if (~isempty(regexprep(text.(textflag),'[\s]*',''))) + if (~isfield(ptext,ptextflag) || isempty(ptext.(ptextflag))) + ptext.(ptextflag) = text.(textflag); + else + %what to do when element data is as follows: + %Text More text + + %put the text in different cells: + % if (~iscell(ptext)) ptext = {ptext}; end + % ptext{length(ptext)+1} = text; + + %just append the text + ptext.(ptextflag) = [ptext.(ptextflag) text.(textflag)]; + end + end + end + + end + end +end + +% ----- Subfunction getNodeData ----- +function [text,name,attr,childs,textflag] = getNodeData(theNode) + % Create structure of node info. + + %make sure name is allowed as structure name + name = toCharArray(getNodeName(theNode))'; + name = strrep(name, '-', '_dash_'); + name = strrep(name, ':', '_colon_'); + name = strrep(name, '.', '_dot_'); + + attr = parseAttributes(theNode); + if (isempty(fieldnames(attr))) + attr = []; + end + + %parse child nodes + [childs,text,textflag] = parseChildNodes(theNode); + + if (isempty(fieldnames(childs)) && isempty(fieldnames(text))) + %get the data of any childless nodes + % faster than if any(strcmp(methods(theNode), 'getData')) + % no need to try-catch (?) + % faster than text = char(getData(theNode)); + text.(textflag) = toCharArray(getTextContent(theNode))'; + end + +end + +% ----- Subfunction parseAttributes ----- +function attributes = parseAttributes(theNode) + % Create attributes structure. + + attributes = struct; + if hasAttributes(theNode) + theAttributes = getAttributes(theNode); + numAttributes = getLength(theAttributes); + + for count = 1:numAttributes + %attrib = item(theAttributes,count-1); + %attr_name = regexprep(char(getName(attrib)),'[-:.]','_'); + %attributes.(attr_name) = char(getValue(attrib)); + + %Suggestion of Adrian Wanner + str = toCharArray(toString(item(theAttributes,count-1)))'; + k = strfind(str,'='); + attr_name = str(1:(k(1)-1)); + attr_name = strrep(attr_name, '-', '_dash_'); + attr_name = strrep(attr_name, ':', '_colon_'); + attr_name = strrep(attr_name, '.', '_dot_'); + attributes.(attr_name) = str((k(1)+2):(end-1)); + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/xml2txt.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/xml2txt.m new file mode 100644 index 0000000000000000000000000000000000000000..d8db7647f2ceefe15ae8427d50b3581b4f1e89c1 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/xml2txt.m @@ -0,0 +1,209 @@ +function detections = xml2txt(xml_File_Name) +%% this funtion change xml file to N*6 matrix +%% input: xml_File_Name +%% output: detections matrix in txt format. + +% convert xml to struct +struct = xml2struct(xml_File_Name); + +detections = []; +for iframe=1:length(struct.sequence.frame) + frame = str2double(struct.sequence.frame{1, iframe}.Attributes.num); + if(length(struct.sequence.frame{1, iframe}.detection)>1) + for idetector = 1:length(struct.sequence.frame{1, iframe}.detection) + num = str2double(struct.sequence.frame{1, iframe}.detection{1, idetector}.Attributes.num); + left = str2double(struct.sequence.frame{1, iframe}.detection{1, idetector}.box.Attributes.left); + top = str2double(struct.sequence.frame{1, iframe}.detection{1, idetector}.box.Attributes.top); + height = str2double(struct.sequence.frame{1, iframe}.detection{1, idetector}.box.Attributes.height); + width = str2double(struct.sequence.frame{1, iframe}.detection{1, idetector}.box.Attributes.width); + score = str2double(struct.sequence.frame{1, iframe}.detection{1, idetector}.box.Attributes.score); + detections = cat(1,detections,[frame num left top width height score]); + end + else + num = str2double(struct.sequence.frame{1, iframe}.detection.Attributes); + left = str2double(struct.sequence.frame{1, iframe}.detection.box.Attributes.left); + top = str2double(struct.sequence.frame{1, iframe}.detection.box.Attributes.top); + height = str2double(struct.sequence.frame{1, iframe}.detection.box.Attributes.height); + width = str2double(struct.sequence.frame{1, iframe}.detection.box.Attributes.width); + score = str2double(struct.sequence.frame{1, iframe}.detection.box.Attributes.score); + detections = cat(1,detections,[frame num left top width height score]); + end +end + +end + +function s = xml2struct(file) +%Convert xml file into a MATLAB structure +% +% A file containing: +% +% Some text +% Some more text +% Even more text +% +% +% Will produce: +% s.XMLname.Attributes.attrib1 = "Some value"; +% s.XMLname.Element.Text = "Some text"; +% s.XMLname.DifferentElement{1}.Attributes.attrib2 = "2"; +% s.XMLname.DifferentElement{1}.Text = "Some more text"; +% s.XMLname.DifferentElement{2}.Attributes.attrib3 = "2"; +% s.XMLname.DifferentElement{2}.Attributes.attrib4 = "1"; +% s.XMLname.DifferentElement{2}.Text = "Even more text"; +% +% Please note that the following characters are substituted +% '-' by '_dash_', ':' by '_colon_' and '.' by '_dot_' +% +% Written by W. Falkena, ASTI, TUDelft, 21-08-2010 +% Attribute parsing speed increased by 40% by A. Wanner, 14-6-2011 +% Added CDATA support by I. Smirnov, 20-3-2012 +% +% Modified by X. Mo, University of Wisconsin, 12-5-2012 + + if(nargin < 1) + clc; + help xml2struct + return + end + + if(isa(file, 'org.apache.xerces.dom.DeferredDocumentImpl') || isa(file, 'org.apache.xerces.dom.DeferredElementImpl')) + % input is a java xml object + xDoc = file; + else + % check for existance + if(exist(file,'file') == 0) + % Perhaps the xml extension was omitted from the file name. Add the + % extension and try again. + if(isempty(strfind(file,'.xml'))) + file = [file '.xml']; + end + if (exist(file,'file') == 0) + error(['The file ' file ' could not be found']); + end + end + % read the xml file + xDoc = xmlread(file); + end + + % parse xDoc into a MATLAB structure + s = parseChildNodes(xDoc); + +end + +% ----- Subfunction parseChildNodes ----- +function [children, ptext, textflag] = parseChildNodes(theNode) + % Recurse over node children. + children = struct; + ptext = struct; textflag = 'Text'; + if hasChildNodes(theNode) + childNodes = getChildNodes(theNode); + numChildNodes = getLength(childNodes); + + for count = 1:numChildNodes + theChild = item(childNodes,count-1); + [text, name, attr, childs, textflag] = getNodeData(theChild); + + if(~strcmp(name,'#text') && ~strcmp(name,'#comment') && ~strcmp(name,'#cdata_dash_section')) + %XML allows the same elements to be defined multiple times, + %put each in a different cell + if(isfield(children,name)) + if (~iscell(children.(name))) + %put existsing element into cell format + children.(name) = {children.(name)}; + end + index = length(children.(name))+1; + %add new element + children.(name){index} = childs; + if(~isempty(fieldnames(text))) + children.(name){index} = text; + end + if(~isempty(attr)) + children.(name){index}.('Attributes') = attr; + end + else + %add previously unknown (new) element to the structure + children.(name) = childs; + if(~isempty(text) && ~isempty(fieldnames(text))) + children.(name) = text; + end + if(~isempty(attr)) + children.(name).('Attributes') = attr; + end + end + else + ptextflag = 'Text'; + if (strcmp(name, '#cdata_dash_section')) + ptextflag = 'CDATA'; + elseif (strcmp(name, '#comment')) + ptextflag = 'Comment'; + end + + %this is the text in an element (i.e., the parentNode) + if(~isempty(regexprep(text.(textflag),'[\s]*',''))) + if (~isfield(ptext,ptextflag) || isempty(ptext.(ptextflag))) + ptext.(ptextflag) = text.(textflag); + else + %what to do when element data is as follows: + %Text More text + + %put the text in different cells: + % if (~iscell(ptext)) ptext = {ptext}; end + % ptext{length(ptext)+1} = text; + + %just append the text + ptext.(ptextflag) = [ptext.(ptextflag) text.(textflag)]; + end + end + end + + end + end +end + +% ----- Subfunction getNodeData ----- +function [text, name, attr, childs, textflag] = getNodeData(theNode) + % Create structure of node info. + + %make sure name is allowed as structure name + name = toCharArray(getNodeName(theNode))'; + name = strrep(name, '-', '_dash_'); + name = strrep(name, ':', '_colon_'); + name = strrep(name, '.', '_dot_'); + + attr = parseAttributes(theNode); + if (isempty(fieldnames(attr))) + attr = []; + end + + %parse child nodes + [childs, text, textflag] = parseChildNodes(theNode); + + if(isempty(fieldnames(childs)) && isempty(fieldnames(text))) + %get the data of any childless nodes + % faster than if any(strcmp(methods(theNode), 'getData')) + % no need to try-catch (?) + % faster than text = char(getData(theNode)); + text.(textflag) = toCharArray(getTextContent(theNode))'; + end +end + +% ----- Subfunction parseAttributes ----- +function attributes = parseAttributes(theNode) + % Create attributes structure. + attributes = struct; + if(hasAttributes(theNode)) + theAttributes = getAttributes(theNode); + numAttributes = getLength(theAttributes); + + for count = 1:numAttributes + %Suggestion of Adrian Wanner + str = toCharArray(toString(item(theAttributes,count-1)))'; + k = strfind(str,'='); + attr_name = str(1:(k(1)-1)); + attr_name = strrep(attr_name, '-', '_dash_'); + attr_name = strrep(attr_name, ':', '_colon_'); + attr_name = strrep(attr_name, '.', '_dot_'); + attributes.(attr_name) = str((k(1)+2):(end-1)); + end + end +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/zipDetectionResults.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/zipDetectionResults.m new file mode 100644 index 0000000000000000000000000000000000000000..74bffdf6a7395093669c3c196bac09ce78cea1af --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/zipDetectionResults.m @@ -0,0 +1,21 @@ +function zipDetectionResults(detectorSet, realList) + +global options + +if(ismember(options.evaluateSeqs, {'DETRAC-Test', 'DETRAC-Test-Beginner', 'DETRAC-Test-Experienced'})) + disp(['Saving detection results in ' options.evaluateSeqs ' level...']); + for idDet = 1:length(detectorSet) + detectorName = detectorSet{idDet}; + resPath = [detectorName '\']; + if(~isdir(resPath)) + mkdir(resPath); + end + for k = 1:length(realList) + resname = [realList{k} '_Det_' detectorName '.txt']; + copyfile([options.detPath detectorName '/' resname], [resPath resname]); + end + zip([date '_' detectorName '_' options.evaluateSeqs '_detection_results.zip'], [resPath '*.txt']); + deleteFolder(resPath); + end + disp(['Detection results in ' options.evaluateSeqs ' level are saved.']); +end \ No newline at end of file diff --git a/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/zipTrackingResults.m b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/zipTrackingResults.m new file mode 100644 index 0000000000000000000000000000000000000000..9ce5eae1230ed85f14a522b807d56625f4e6c939 --- /dev/null +++ b/DETRAC/DETRAC-MOT-toolkit/DETRAC-MOT-toolkit/utils/zipTrackingResults.m @@ -0,0 +1,61 @@ +function zipTrackingResults(trackerName, detectorName) + +global options sequences + +if(ismember(options.evaluateSeqs, {'DETRAC-Test', 'DETRAC-Test-Beginner', 'DETRAC-Test-Experienced'})) + disp(['Saving tracking results in ' options.evaluateSeqs ' level...']); + resPath = ['results\' trackerName '\']; + if(~isdir(resPath)) + mkdir(resPath); + end + if(strcmp(options.motmetric, 'CLEAR-MOT')) + if(~isdir([trackerName '\'])) + mkdir([trackerName '\']); + end + disp([trackerName '+' detectorName '-->The evaluted thresholds are: ' num2str(options.detectionThreshold)]); + thre = input('Please input one specific threshold of detection score to submit:\n'); + flag = false; + while(~ismember(thre, options.detectionThreshold)) + disp([trackerName '+' detectorName '-->The evaluted thresholds are: ' num2str(options.detectionThreshold)]); + thre = input('Error in threshold! Please input again:\n'); + for k = 1:length(sequences) + seqName = sequences{k}.seqName; + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_LX.txt'], [trackerName '\' seqName '_LX.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_LY.txt'], [trackerName '\' seqName '_LY.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_W.txt'], [trackerName '\' seqName '_W.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_H.txt'], [trackerName '\' seqName '_H.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_speed.txt'], [trackerName '\' seqName '_speed.txt']); + end + zip([date '_' trackerName '_' detectorName '_' options.evaluateSeqs '_CLEAR_tracking_results.zip'], [trackerName '\']); + flag = true; + end + if(~flag) + for k = 1:length(sequences) + seqName = sequences{k}.seqName; + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_LX.txt'], [trackerName '\' seqName '_LX.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_LY.txt'], [trackerName '\' seqName '_LY.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_W.txt'], [trackerName '\' seqName '_W.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_H.txt'], [trackerName '\' seqName '_H.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_speed.txt'], [trackerName '\' seqName '_speed.txt']); + end + zip([date '_' trackerName '_' detectorName '_' options.evaluateSeqs '_CLEAR_tracking_results.zip'], [trackerName '\']); + end + else + for thre = options.detectionThreshold + if(~isdir([trackerName '\' sprintf('%.1f', thre) '\'])) + mkdir([trackerName '\' sprintf('%.1f', thre) '\']); + end + for k = 1:length(sequences) + seqName = sequences{k}.seqName; + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_LX.txt'], [trackerName '\' sprintf('%.1f', thre) '\' seqName '_LX.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_LY.txt'], [trackerName '\' sprintf('%.1f', thre) '\' seqName '_LY.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_W.txt'], [trackerName '\' sprintf('%.1f', thre) '\' seqName '_W.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_H.txt'], [trackerName '\' sprintf('%.1f', thre) '\' seqName '_H.txt']); + copyfile([resPath detectorName '\' sprintf('%.1f', thre) '\' seqName '_speed.txt'], [trackerName '\' sprintf('%.1f', thre) '\' seqName '_speed.txt']); + end + zip([date '_' trackerName '_' detectorName '_' options.evaluateSeqs '_DETRAC_tracking_results.zip'], [trackerName '\']); + end + end + deleteFolder([trackerName '\']); + disp(['Tracking results in ' options.evaluateSeqs ' level are saved.']); +end \ No newline at end of file