<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="main">
<interface/>
<body>
<c> * Copyright (c) MVTec Software GmbH.  All rights reserved.</c>
<c> *</c>
<c> * All use of this software is subject to the terms of the revised BSD</c>
<c> * license.  You should have received a copy of this license along</c>
<c> * with this source code in a file named "license.txt."</c>
<c> </c>
<c>*************************************</c>
<c>* Read in theoretical trackers (csv) and</c>
<c>* write out the avergae results to FileNameOverlaps. Works</c>
<c>* for DAVIS and vot2016</c>
<c>*************************************</c>
<c></c>
<c>*******************************************************</c>
<c>* Setup Filenames and Flags</c>
<c>*******************************************************</c>
<c>* Set the path (relative or absolut) to the ROOT of VOT or DAVIS data here</c>
<c>* Set the location of the images relative to the ROOT path here</c>
<c>* for  DAVIS '480p' and '1080p' are possible</c>
<l>ImageFolder := '../../data/DAVIS/DAVIS/JPEGImages/' + '480p'</l>
<l>ImageFolder :=  '../../data/votseg/images'</l>
<c></c>
<c>* Set the name of groundtruth file</c>
<l>FileNameGT := 'tracker_boxes.csv'</l>
<l>FileNameOverlaps := 'box_overlaps.csv'</l>
<l>FileNameAvgOverlaps := '../avg_box_overlaps.csv'</l>
<c></c>
<c>* FLAGS to determine which results to write</c>
<l>WriteOverlaps := false</l>
<l>WriteAvgOverlaps := false</l>
<c></c>
<c>* FLAG to switch the display on and off </c>
<l>Display := true</l>
<c></c>
<c>*******************************************************</c>
<c>* Setup Trackers</c>
<c>*******************************************************</c>
<c>* We store them in vectors, where we categorize due to their abilities</c>
<l>TrackersNoScale := {['tracker_kcf']}</l>
<l>TrackersNoRotation := {['tracker_dsst', 'tracker_ccot', 'tracker_ant', 'tracker_l1apg']}</l>
<l>TrackersRect2 := {['tracker_lgt']}</l>
<c>*</c>
<c>*******************************************************</c>
<c>* Walk through the directory</c>
<c>*******************************************************</c>
<l>dev_update_off ()</l>
<l>dev_close_window ()</l>
<c>* Window to display the actual tracker result live</c>
<l>dev_open_window (0, 0, 400, 400, 'black', WindowHandleDisplay)</l>
<c>*Windows for comparison of trackers with no scale</c>
<l>dev_open_window (0, 410, 400, 400, 'black', WindowHandleNoScaleAbs)</l>
<l>dev_open_window (460, 410, 400, 400, 'black', WindowHandleNoScaleRel)</l>
<c>*Windows for comparison of trackers with no rotation but with scale</c>
<l>dev_open_window (0, 820, 400, 400, 'black', WindowHandleNoRotationAbs)</l>
<l>dev_open_window (460, 820, 400, 400, 'black', WindowHandleNoRotationRel)</l>
<c>*Windows for comparison of trackers with Rectangle2 output (scale + rotation)</c>
<l>dev_open_window (0, 1230, 400, 400, 'black', WindowHandleRect2Abs)</l>
<l>dev_open_window (460, 1230, 400, 400, 'black', WindowHandleRect2Rel)</l>
<c></c>
<c>* To prevent regions being clipped at the image border, we set </c>
<c>* 'clip_region' to false</c>
<l>get_system ('clip_region', ClipRegion)</l>
<l>set_system ('clip_region', 'false')</l>
<c></c>
<c>* The display colors for the different theoretical tracker:</c>
<l>NoScaleColor := '#ffff00'</l>
<l>NoRotColor := '#f08080'</l>
<l>Rect2Color := '#0000ff'</l>
<l>* SmallestRect1Color := '#ff0000'</l>
<c>* We use different green colors for the trackers</c>
<l>TrackerColors := ['#556B2F', '#808000', '#00ff00', '#7FFF00', '#6B8E23', '#00FF7F','#FF7F50','#FFA07A','#FFD700']</l>
<l>ColSeparator := ';'</l>
<l>StringQuote  := '"'</l>
<c>*</c>
<l>list_files (ImageFolder, 'directories', ImageFolders)</l>
<l>CSVDataOut := []</l>
<l>CSVInfoOut := []</l>
<c>* Initialize CSV data for storing average overlaps if necessary</c>
<l>if (WriteAvgOverlaps)</l>
<l>    AvgOverlapsHeader := ['SequenceIdx', 'SequenceName', 'NumFrames', 'avg_theoretical_box_no_scale']</l>
<c>    * NoScale</c>
<l>    for Jdx := 0 to |TrackersNoScale.at(0)|-1 by 1</l>
<l>        AvgOverlapsHeader := [AvgOverlapsHeader, TrackersNoScale.at(0)[Jdx] + '_avg_iou_abs']</l>
<l>        AvgOverlapsHeader := [AvgOverlapsHeader, TrackersNoScale.at(0)[Jdx] + '_avg_iou_rel']</l>
<l>    endfor</l>
<c>    * NoRotation</c>
<l>    AvgOverlapsHeader := [AvgOverlapsHeader, 'avg_theoretical_box_no_rotation']</l>
<l>    for Jdx := 0 to |TrackersNoRotation.at(0)|-1 by 1</l>
<l>        AvgOverlapsHeader := [AvgOverlapsHeader, TrackersNoRotation.at(0)[Jdx] + '_avg_iou_abs']</l>
<l>        AvgOverlapsHeader := [AvgOverlapsHeader, TrackersNoRotation.at(0)[Jdx] + '_avg_iou_rel']</l>
<l>    endfor</l>
<c>    * Rect2</c>
<l>    AvgOverlapsHeader := [AvgOverlapsHeader, 'avg_theoretical_box_rot']</l>
<l>    for Jdx := 0 to |TrackersRect2.at(0)|-1 by 1</l>
<l>        AvgOverlapsHeader := [AvgOverlapsHeader, TrackersRect2.at(0)[Jdx] + '_avg_iou_abs']</l>
<l>        AvgOverlapsHeader := [AvgOverlapsHeader, TrackersRect2.at(0)[Jdx] + '_avg_iou_rel']</l>
<l>    endfor</l>
<l>    mvtec_csv_append_row ([], [], AvgOverlapsHeader, CSVDataAvgOverlaps, CSVInfoAvgOverlaps)</l>
<l>endif</l>
<c></c>
<l>for FolderIdx := 0 to |ImageFolders|-1 by 1</l>
<l>    InputFile := ImageFolders[FolderIdx] + FileNameGT</l>
<c>    * Read the Groundtruth Data</c>
<l>    mvtec_csv_read_data (InputFile, ColSeparator, StringQuote, CSVData, CSVInfo)</l>
<l>    mvtec_csv_get_row(CSVData,CSVInfo,0,HeaderCategories)</l>
<l>    mvtec_csv_get_attribute (CSVInfo, 'rows', Rows)</l>
<l>    NumImages := Rows-1</l>
<c>    *</c>
<l>    tuple_find (HeaderCategories, 'Sequence', SequenceIdx)</l>
<l>    tuple_find (HeaderCategories, 'ImageFile', ImageFileIdx)</l>
<l>    tuple_find (HeaderCategories, 'SegmentationFile', SegmemtationFileIdx)</l>
<l>    tuple_find (HeaderCategories, 'theoretical_box_no_scale', NoScaleIdx)</l>
<l>    tuple_find (HeaderCategories, 'theoretical_box_axis_aligned', NoRotationIdx)</l>
<l>    tuple_find (HeaderCategories, 'theoretical_box_rot', Rect2Idx)</l>
<c>    *</c>
<c>    * Check if the tracker information is there and get the Column idx within csv-file</c>
<c>    * NoScale</c>
<l>    TrackersIdxs := []</l>
<l>    for Jdx := 0 to |TrackersNoScale.at(0)|-1 by 1</l>
<l>        tuple_find (HeaderCategories, TrackersNoScale.at(0)[Jdx], TrackerIdx)</l>
<l>        if (TrackerIdx == -1)</l>
<l>            throw('No results for ' + TrackersNoScale.at(0)[Jdx])</l>
<l>        else</l>
<l>            TrackersIdxs := [TrackersIdxs, TrackerIdx]</l>
<l>        endif</l>
<l>    endfor</l>
<l>    TrackersNoScale.at(1) := TrackersIdxs</l>
<c>    * NoRotation</c>
<l>    TrackersIdxs := []</l>
<l>    for Jdx := 0 to |TrackersNoRotation.at(0)|-1 by 1</l>
<l>        tuple_find (HeaderCategories, TrackersNoRotation.at(0)[Jdx], TrackerIdx)</l>
<l>        if (TrackerIdx == -1)</l>
<l>            throw('No results for ' + TrackersNoRotation.at(0)[Jdx])</l>
<l>        else</l>
<l>            TrackersIdxs := [TrackersIdxs, TrackerIdx]</l>
<l>        endif</l>
<l>    endfor</l>
<l>    TrackersNoRotation.at(1) := TrackersIdxs</l>
<c>    * Rect2</c>
<l>    TrackersIdxs := []</l>
<l>    for Jdx := 0 to |TrackersRect2.at(0)|-1 by 1</l>
<l>        tuple_find (HeaderCategories, TrackersRect2.at(0)[Jdx], TrackerIdx)</l>
<l>        if (TrackerIdx == -1)</l>
<l>            throw('No results for ' + TrackersRect2.at(0)[Jdx])</l>
<l>        else</l>
<l>            TrackersIdxs := [TrackersIdxs, TrackerIdx]</l>
<l>        endif</l>
<l>    endfor</l>
<l>    TrackersRect2.at(1) := TrackersIdxs</l>
<c>    *</c>
<c>    * Clear Bounding Box Overlaps</c>
<l>    OverlapsNoScale:= []</l>
<l>    OverlapsNoRotation:= []</l>
<l>    OverlapsRect2:= []</l>
<l>    OverlapsSmallestRect1:= []</l>
<c>    *</c>
<c>    * Reset measures</c>
<l>    NormedIouNoRotation := []</l>
<l>    NormedIouRect2 := []</l>
<l>    NormedIouNoScale := []</l>
<l>    NormedIouSmallestRect1 := []</l>
<c>    </c>
<c>    * Reset overlaps and measures for trackers</c>
<l>    for Jdx := 0 to |TrackersNoScale.at(0)|-1 by 1</l>
<c>        * these labels are always overwritten, but we don't care</c>
<l>        TrackersNoScale.at(3 + |TrackersNoScale.at(0)|) := 'bb_overlaps'</l>
<l>        TrackersNoScale.at(4 + |TrackersNoScale.at(0)| + Jdx) := []</l>
<l>        TrackersNoScale.at(4 + 2 * |TrackersNoScale.at(0)|) := 'normed_iou_no_scale'</l>
<l>        TrackersNoScale.at(5 + 2 * |TrackersNoScale.at(0)| + Jdx) := []</l>
<l>    endfor</l>
<l>    for Jdx := 0 to |TrackersNoRotation.at(0)|-1 by 1</l>
<c>        * these labels are always overwritten, but we don't care</c>
<l>        TrackersNoRotation.at(3 + |TrackersNoRotation.at(0)|) := 'bb_overlaps'</l>
<l>        TrackersNoRotation.at(4 + |TrackersNoRotation.at(0)| + Jdx) := []</l>
<l>        TrackersNoRotation.at(4 + 2 * |TrackersNoRotation.at(0)|) := 'normed_iou_no_rotation'</l>
<l>        TrackersNoRotation.at(5 + 2 * |TrackersNoRotation.at(0)| + Jdx) := []</l>
<l>    endfor</l>
<l>        for Jdx := 0 to |TrackersRect2.at(0)|-1 by 1</l>
<c>        * these labels are always overwritten, but we don't care</c>
<l>        TrackersRect2.at(3 + |TrackersRect2.at(0)|) := 'bb_overlaps'</l>
<l>        TrackersRect2.at(4 + |TrackersRect2.at(0)| + Jdx) := []</l>
<l>        TrackersRect2.at(4 + 2 * |TrackersRect2.at(0)|) := 'normed_iou_rot'</l>
<l>        TrackersRect2.at(5 + 2 * |TrackersRect2.at(0)| + Jdx) := []</l>
<l>    endfor</l>
<c>    </c>
<c>    * Reset current row CSVAvgOverlaps if necessary</c>
<l>    if (WriteAvgOverlaps)</l>
<l>        mvtec_string_tuple_to_string (FolderIdx, 'd', SequenceIdxStr)</l>
<c>        * Get the SequenceName from the first image-entry (assume it stays constant)</c>
<l>        mvtec_csv_get_row(CSVData,CSVInfo,1,Obj)</l>
<l>        Sequence := Obj[SequenceIdx]</l>
<l>        AvgOverlapsRow := [SequenceIdxStr, Sequence, NumImages]</l>
<l>    endif</l>
<c>    </c>
<c>    </c>
<c>    ******************************************************</c>
<c>    * Walk through csv file and display the Groundtruth</c>
<c>    ******************************************************</c>
<l>    for ImageIdx := 0 to NumImages-1 by 1</l>
<l>        mvtec_csv_get_row(CSVData,CSVInfo,ImageIdx+1,Obj)</l>
<l>        Sequence := Obj[SequenceIdx]</l>
<l>        ImageName := Obj[ImageFileIdx]</l>
<l>        mvtec_string_to_tuple (number(Obj[NoScaleIdx]), box_coordinate_no_scale)</l>
<l>        mvtec_string_to_tuple (number(Obj[NoRotationIdx]), box_coordinate_no_rotation)</l>
<l>        mvtec_string_to_tuple (number(Obj[Rect2Idx]), box_coordinate_rect2)</l>
<l>*         mvtec_string_to_tuple (number(Obj[SmallestRect1Idx]), box_coordinate_smallest_rectangle1)</l>
<c>        * get coordinates of Trackers</c>
<c>        * NoScale</c>
<l>        TrackersNoScale.at(2) := 'current_box_coordinates'</l>
<l>        for Jdx := 0 to |TrackersNoScale.at(0)|-1 by 1</l>
<l>            mvtec_string_to_tuple (number(Obj[TrackersNoScale.at(1)[Jdx]]), box_coordinate_tracker)</l>
<l>            handle_NaN_box_coordinate (box_coordinate_tracker, box_coordinate_tracker)</l>
<l>            TrackersNoScale.at(3+Jdx) := box_coordinate_tracker</l>
<l>        endfor</l>
<c>        * NoRotation</c>
<l>        TrackersNoRotation.at(2) := 'current_box_coordinates'</l>
<l>        for Jdx := 0 to |TrackersNoRotation.at(0)|-1 by 1</l>
<l>            mvtec_string_to_tuple (number(Obj[TrackersNoRotation.at(1)[Jdx]]), box_coordinate_tracker)</l>
<l>            handle_NaN_box_coordinate (box_coordinate_tracker, box_coordinate_tracker)</l>
<l>            TrackersNoRotation.at(3+Jdx) := box_coordinate_tracker</l>
<l>        endfor</l>
<c>        * Rect2</c>
<l>        TrackersRect2.at(2) := 'current_box_coordinates'</l>
<l>        for Jdx := 0 to |TrackersRect2.at(0)|-1 by 1</l>
<l>            mvtec_string_to_tuple (number(Obj[TrackersRect2.at(1)[Jdx]]), box_coordinate_tracker)</l>
<l>            handle_NaN_box_coordinate (box_coordinate_tracker, box_coordinate_tracker)</l>
<l>            TrackersRect2.at(3+Jdx) := box_coordinate_tracker</l>
<l>        endfor</l>
<l>        SegmentationFile := number(Obj[SegmemtationFileIdx])</l>
<c>        *</c>
<c>        ****************</c>
<c>        * Read Image</c>
<c>        ****************</c>
<l>        read_image (Image, ImageFolders[FolderIdx] + ImageName)</l>
<c>        </c>
<c>        ************************</c>
<c>        * Read Segmentation</c>
<c>        ************************</c>
<l>        SegmentationPath := ImageFolders[FolderIdx] + SegmentationFile</l>
<c>        * The images folder may be a link. We compress it for linix</c>
<l>        compress_path_linux (SegmentationPath, SegmentationPath)</l>
<l>        read_image (Segmentation, SegmentationPath)</l>
<l>        threshold (Segmentation, RegionSeg, 1, 255)</l>
<l>        gen_rectangle_b (RectangleNoScale, box_coordinate_no_scale)</l>
<l>        gen_rectangle_b (RectangleNoRotation, box_coordinate_no_rotation)</l>
<l>        gen_rectangle_b (Rectangle2, box_coordinate_rect2)</l>
<l>*         gen_rectangle_b (SmallestRectangle1, box_coordinate_smallest_rectangle1)</l>
<c>   </c>
<c>        ************</c>
<c>        * Display  *</c>
<c>        ************</c>
<l>        if (Display)</l>
<l>            dev_set_window (WindowHandleDisplay)    </l>
<l>            set_system ('flush_graphic', 'false')</l>
<l>            dev_display (Image)</l>
<l>            disp_region_alpha (RectangleNoScale, NoScaleColor, 70)</l>
<l>            disp_region_alpha (RectangleNoRotation, NoRotColor, 70)</l>
<l>            disp_region_alpha (Rectangle2, Rect2Color, 70)</l>
<l>*             disp_region_alpha (SmallestRectangle1, SmallestRect1Color, 70)</l>
<c>            * Display tracker results</c>
<l>            TrackerColorIdx := 0</l>
<c>            * NoScale</c>
<l>            for Jdx := 0 to |TrackersNoScale.at(0)|-1 by 1</l>
<l>                gen_rectangle_b(TrackerResult, TrackersNoScale.at(3+Jdx))</l>
<l>                disp_region_alpha (TrackerResult, TrackerColors[TrackerColorIdx], 70)</l>
<l>                TrackerColorIdx := TrackerColorIdx + 1</l>
<l>            endfor</l>
<c>            * NoRotation</c>
<l>            for Jdx := 0 to |TrackersNoRotation.at(0)|-1 by 1</l>
<l>                gen_rectangle_b(TrackerResult, TrackersNoRotation.at(3+Jdx))</l>
<l>                disp_region_alpha (TrackerResult, TrackerColors[TrackerColorIdx], 70)</l>
<l>                TrackerColorIdx := TrackerColorIdx + 1</l>
<l>            endfor</l>
<c>            * Rect2</c>
<l>            for Jdx := 0 to |TrackersRect2.at(0)|-1 by 1</l>
<l>                gen_rectangle_b(TrackerResult, TrackersRect2.at(3+Jdx))</l>
<l>                disp_region_alpha (TrackerResult, TrackerColors[TrackerColorIdx], 70)</l>
<l>                TrackerColorIdx := TrackerColorIdx + 1</l>
<l>            endfor</l>
<c>            * Draw Segmentation</c>
<l>            dev_set_draw ('margin')</l>
<l>            dev_set_line_width (2)</l>
<l>            dev_set_color ('black')</l>
<l>            dev_display (RegionSeg)</l>
<l>            set_system ('flush_graphic', 'true')</l>
<l>            dev_display (RegionSeg)       </l>
<l>        endif</l>
<l>        disp_message (WindowHandleDisplay, (ImageIdx+1) + '/' + NumImages, 'window', 12, 12, 'black', 'true')       </l>
<c>        *</c>
<c>        ******************************</c>
<c>        * Theoretical Tracker Results</c>
<c>        ******************************</c>
<c>        * Remember the overlaps</c>
<l>        bb_overlap (RegionSeg, RectangleNoScale, overlap_no_scale)</l>
<l>        bb_overlap (RegionSeg, RectangleNoRotation, overlap_no_rotation)</l>
<l>        bb_overlap (RegionSeg, Rectangle2, overlap_rect2)</l>
<l>*         bb_overlap (RegionSeg, SmallestRectangle1, overlap_smallest_rect1)</l>
<l>        OverlapsNoScale[ImageIdx]:= overlap_no_scale</l>
<l>        OverlapsNoRotation[ImageIdx]:= overlap_no_rotation</l>
<l>        OverlapsRect2[ImageIdx]:= overlap_rect2</l>
<l>*         OverlapsSmallestRect1[ImageIdx]:= overlap_smallest_rect1</l>
<c>        *</c>
<c>        *******************</c>
<c>        * Measures</c>
<c>        *******************</c>
<c>        * go through trackers and store the results</c>
<c>        * NoScale</c>
<l>        for Jdx := 0 to |TrackersNoScale.at(0)|-1 by 1</l>
<c>            * Calculate and add current bb_overlap to array</c>
<l>            gen_rectangle_b(TrackerResult, TrackersNoScale.at(3+Jdx))</l>
<l>            bb_overlap (RegionSeg, TrackerResult, overlap_tracker)</l>
<c>            * Store absolute value</c>
<l>            TrackersNoScale.at(4 + |TrackersNoScale.at(0)| + Jdx) := [TrackersNoScale.at(4 + |TrackersNoScale.at(0)| + Jdx), overlap_tracker]</l>
<c>            * calculate normed_iou_no_scale</c>
<l>            if (overlap_no_scale &gt; 0.0)</l>
<l>                normed_iou_no_scale := min2(1.0, overlap_tracker/overlap_no_scale)</l>
<l>            else</l>
<l>                normed_iou_no_scale := 1.0</l>
<l>            endif</l>
<c></c>
<l>            TrackersNoScale.at(5 + 2 * |TrackersNoScale.at(0)| + Jdx) := [TrackersNoScale.at(5 + 2 * |TrackersNoScale.at(0)| + Jdx), normed_iou_no_scale]</l>
<l>        endfor</l>
<c>        * NoRotation</c>
<l>        for Jdx := 0 to |TrackersNoRotation.at(0)|-1 by 1</l>
<c>            * Calculate and add current bb_overlap to array</c>
<l>            gen_rectangle_b(TrackerResult, TrackersNoRotation.at(3+Jdx))</l>
<l>            bb_overlap (RegionSeg, TrackerResult, overlap_tracker)</l>
<c>            * Store absolute value</c>
<l>            TrackersNoRotation.at(4 + |TrackersNoRotation.at(0)| + Jdx) := [TrackersNoRotation.at(4 + |TrackersNoRotation.at(0)| + Jdx), overlap_tracker]</l>
<c>            * calculate normed_iou_no_rotation</c>
<l>            if (overlap_no_rotation &gt; 0.0)</l>
<l>                normed_iou_no_rotation := min2(1.0, overlap_tracker/overlap_no_rotation)</l>
<l>            else</l>
<l>                normed_iou_no_rotation := 1.0</l>
<l>            endif</l>
<l>            TrackersNoRotation.at(5 + 2 * |TrackersNoRotation.at(0)| + Jdx) := [TrackersNoRotation.at(5 + 2 * |TrackersNoRotation.at(0)| + Jdx), normed_iou_no_rotation]</l>
<l>        endfor</l>
<c>        * Rect2</c>
<l>        for Jdx := 0 to |TrackersRect2.at(0)|-1 by 1</l>
<c>            * Calculate and add current bb_overlap to array</c>
<l>            gen_rectangle_b(TrackerResult, TrackersRect2.at(3+Jdx))</l>
<l>            bb_overlap (RegionSeg, TrackerResult, overlap_tracker)</l>
<c>            * Store absolute value</c>
<l>            TrackersRect2.at(4 + |TrackersRect2.at(0)| + Jdx) := [TrackersRect2.at(4 + |TrackersRect2.at(0)| + Jdx), overlap_tracker]</l>
<c>            * calculate normed_iou_rect2</c>
<l>            if (overlap_rect2 &gt; 0.0)</l>
<l>                normed_iou_rect2 := min2(1.0, overlap_tracker/overlap_rect2)</l>
<l>            else</l>
<l>                normed_iou_rect2 := 1.0</l>
<l>            endif</l>
<l>            TrackersRect2.at(5 + 2 * |TrackersRect2.at(0)| + Jdx) := [TrackersRect2.at(5 + 2 * |TrackersRect2.at(0)| + Jdx), normed_iou_rect2]</l>
<l>        endfor</l>
<c>        </c>
<c>        * Normalized intersection over union overlap for smallest rectangle1</c>
<l>*         if (find(Measures,'normed_avg_iou_smallest_rectangle1') # -1)</l>
<l>*             if (overlap_smallest_rect1 &gt; 0.0)</l>
<l>*                 NormedIouSmallestRect1[ImageIdx] := overlap_tracker/overlap_smallest_rect1</l>
<l>*             else</l>
<l>*                 NormedIouSmallestRect1[ImageIdx] := 1.0</l>
<l>*             endif</l>
<l>*         endif</l>
<c>        *        </c>
<l>    endfor</l>
<c>    *******************</c>
<c>    * Plot the results</c>
<c>    *******************</c>
<l>    TrackerColorIdx := 0</l>
<c>    *</c>
<c>    * NoScale</c>
<c>    *</c>
<l>    dev_set_window (WindowHandleNoScaleAbs)</l>
<l>    dev_clear_window ()</l>
<l>    plot_tuple (WindowHandleNoScaleAbs, [1:|OverlapsNoScale|], OverlapsNoScale, ['frameID'], ['BB overlap'], [NoScaleColor], ['start_y','end_y'], [0.0,1.0])</l>
<c>    * calculate and display theoretical best average IoU</c>
<l>    average_optimized_iou_no_scale := mean(OverlapsNoScale)</l>
<l>    if (WriteAvgOverlaps)</l>
<l>        AvgOverlapsRow := [AvgOverlapsRow, average_optimized_iou_no_scale]</l>
<l>    endif</l>
<l>    dev_disp_text ('average_iou_no_scale, theoretical no_scale: ' + average_optimized_iou_no_scale, 'window', 200,  12, 'black', [], [])</l>
<l>    dev_set_window (WindowHandleNoScaleRel)</l>
<l>    dev_clear_window ()</l>
<l>    for Jdx := 0 to |TrackersNoScale.at(0)|-1 by 1</l>
<c>        * Plot absolute and relative bb_overlaps</c>
<l>        plot_tuple (WindowHandleNoScaleAbs, [1:|OverlapsNoScale|], TrackersNoScale.at(4 + |TrackersNoScale.at(0)| + Jdx), ['frameID'], ['BB overlap'], [TrackerColors[TrackerColorIdx]], ['start_y','end_y'], [0.0,1.0])</l>
<l>        plot_tuple (WindowHandleNoScaleRel, [1:|OverlapsNoScale|], TrackersNoScale.at(5 + 2 * |TrackersNoScale.at(0)| + Jdx), ['frameID'], ['BB overlap'], [TrackerColors[TrackerColorIdx]], ['start_y','end_y'], [0.0,1.0])</l>
<c>        * calculate and display average absolute iou value</c>
<l>        dev_set_window (WindowHandleNoScaleAbs)</l>
<l>        average_iou_no_scale := mean(TrackersNoScale.at(4 + |TrackersNoScale.at(0)| + Jdx))</l>
<l>        dev_disp_text ('average_iou_no_scale, ' + TrackersNoScale.at(0)[Jdx] + ': ' + average_iou_no_scale, 'window', 200 + (Jdx+1) * 20, 12, TrackerColors[TrackerColorIdx], [], [])</l>
<c>        * calculate and display average normed iou value</c>
<l>        dev_set_window (WindowHandleNoScaleRel)</l>
<l>        average_normed_iou_no_scale := mean(TrackersNoScale.at(5 + 2 * |TrackersNoScale.at(0)| + Jdx))</l>
<l>        dev_disp_text ('average_normed_iou_no_scale, ' + TrackersNoScale.at(0)[Jdx] + ': ' + average_normed_iou_no_scale, 'window', 200 + Jdx * 20, 12, TrackerColors[TrackerColorIdx], [], [])</l>
<l>        TrackerColorIdx := TrackerColorIdx + 1</l>
<l>        if (WriteAvgOverlaps)</l>
<l>            AvgOverlapsRow := [AvgOverlapsRow, average_iou_no_scale, average_normed_iou_no_scale]</l>
<l>        endif</l>
<l>    endfor</l>
<c>    *</c>
<c>    * NoRotation</c>
<c>    *</c>
<l>    dev_set_window (WindowHandleNoRotationAbs)</l>
<l>    dev_clear_window ()</l>
<l>    plot_tuple (WindowHandleNoRotationAbs, [1:|OverlapsNoRotation|], OverlapsNoRotation, ['frameID'], ['BB overlap'], [NoRotColor], ['start_y','end_y'], [0.0,1.0])</l>
<c>    * calculate and display theoretical best average IoU</c>
<l>    average_optimized_iou_no_rotation := mean(OverlapsNoRotation)</l>
<l>    if (WriteAvgOverlaps)</l>
<l>        AvgOverlapsRow := [AvgOverlapsRow, average_optimized_iou_no_rotation]</l>
<l>    endif</l>
<l>    dev_disp_text ('average_iou_no_rotation, theoretical no_rotation: ' + average_optimized_iou_no_rotation, 'window', 200,  12, 'black', [], [])</l>
<l>    dev_set_window (WindowHandleNoRotationRel)</l>
<l>    dev_clear_window ()</l>
<l>    for Jdx := 0 to |TrackersNoRotation.at(0)|-1 by 1</l>
<c>        * Plot absolute and relative bb_overlaps</c>
<l>        plot_tuple (WindowHandleNoRotationAbs, [1:|OverlapsNoRotation|], TrackersNoRotation.at(4 + |TrackersNoRotation.at(0)| + Jdx), ['frameID'], ['BB overlap'], [TrackerColors[TrackerColorIdx]], ['start_y','end_y'], [0.0,1.0])</l>
<l>        plot_tuple (WindowHandleNoRotationRel, [1:|OverlapsNoRotation|], TrackersNoRotation.at(5 + 2 * |TrackersNoRotation.at(0)| + Jdx), ['frameID'], ['BB overlap'], [TrackerColors[TrackerColorIdx]], ['start_y','end_y'], [0.0,1.0])</l>
<c>        * calculate and display average absolute iou value</c>
<l>        dev_set_window (WindowHandleNoRotationAbs)</l>
<l>        average_iou_no_rotation := mean(TrackersNoRotation.at(4 + |TrackersNoRotation.at(0)| + Jdx))</l>
<l>        dev_disp_text ('average_iou_no_rotation, ' + TrackersNoRotation.at(0)[Jdx] + ': ' + average_iou_no_rotation, 'window', 200 + (Jdx+1) * 20, 12, TrackerColors[TrackerColorIdx], [], [])</l>
<c>        * calculate and display average normed iou value</c>
<l>        dev_set_window (WindowHandleNoRotationRel)</l>
<l>        average_normed_iou_no_rotation := mean(TrackersNoRotation.at(5 + 2 * |TrackersNoRotation.at(0)| + Jdx))</l>
<l>        dev_disp_text ('average_normed_iou_no_rotation, ' + TrackersNoRotation.at(0)[Jdx] + ': ' + average_normed_iou_no_rotation, 'window', 200 + Jdx * 20, 12, TrackerColors[TrackerColorIdx], [], [])</l>
<l>        TrackerColorIdx := TrackerColorIdx + 1</l>
<l>        if (WriteAvgOverlaps)</l>
<l>            AvgOverlapsRow := [AvgOverlapsRow, average_iou_no_rotation, average_normed_iou_no_rotation]</l>
<l>        endif</l>
<l>    endfor</l>
<c>    *</c>
<c>    * Rect2</c>
<c>    *</c>
<l>    dev_set_window (WindowHandleRect2Abs)</l>
<l>    dev_clear_window ()</l>
<l>    plot_tuple (WindowHandleRect2Abs, [1:|OverlapsRect2|], OverlapsRect2, ['frameID'], ['BB overlap'], [Rect2Color], ['start_y','end_y'], [0.0,1.0])   </l>
<c>   * calculate and display theoretical best average IoU</c>
<l>    average_optimized_iou_rect2 := mean(OverlapsRect2)</l>
<l>    if (WriteAvgOverlaps)</l>
<l>        AvgOverlapsRow := [AvgOverlapsRow, average_optimized_iou_rect2]</l>
<l>    endif</l>
<l>    dev_disp_text ('average_iou_rect2, theoretical rect2: ' + average_optimized_iou_rect2, 'window', 200,  12, 'black', [], [])</l>
<l>    dev_set_window (WindowHandleRect2Rel)</l>
<l>    dev_clear_window ()</l>
<l>    for Jdx := 0 to |TrackersRect2.at(0)|-1 by 1</l>
<c>        * Plot absolute and relative bb_overlaps</c>
<l>        plot_tuple (WindowHandleRect2Abs, [1:|OverlapsRect2|], TrackersRect2.at(4 + |TrackersRect2.at(0)| + Jdx), ['frameID'], ['BB overlap'], [TrackerColors[TrackerColorIdx]], ['start_y','end_y'], [0.0,1.0])</l>
<l>        plot_tuple (WindowHandleRect2Rel, [1:|OverlapsRect2|], TrackersRect2.at(5 + 2 * |TrackersRect2.at(0)| + Jdx), ['frameID'], ['BB overlap'], [TrackerColors[TrackerColorIdx]], ['start_y','end_y'], [0.0,1.0])</l>
<c>        * calculate and display average absolute iou value</c>
<l>        dev_set_window (WindowHandleRect2Abs)</l>
<l>        average_iou_rect2 := mean(TrackersRect2.at(4 + |TrackersRect2.at(0)| + Jdx))</l>
<l>        dev_disp_text ('average_iou_rect2, ' + TrackersRect2.at(0)[Jdx] + ': ' + average_iou_rect2, 'window', 200 + (Jdx+1) * 20, 12, TrackerColors[TrackerColorIdx], [], [])</l>
<c>        * calculate and display average normed iou value</c>
<l>        dev_set_window (WindowHandleRect2Rel)</l>
<l>        average_normed_iou_rect2 := mean(TrackersRect2.at(5 + 2 * |TrackersRect2.at(0)| + Jdx))</l>
<l>        dev_disp_text ('average_normed_iou_rect2, ' + TrackersRect2.at(0)[Jdx] + ': ' + average_normed_iou_rect2, 'window', 200 + Jdx * 20, 12, TrackerColors[TrackerColorIdx], [], [])</l>
<l>        TrackerColorIdx := TrackerColorIdx + 1</l>
<l>        if (WriteAvgOverlaps)</l>
<l>            AvgOverlapsRow := [AvgOverlapsRow, average_iou_rect2, average_normed_iou_rect2]</l>
<l>        endif</l>
<l>    endfor</l>
<c>    *</c>
<c>    * append average csv row to csv if necessary</c>
<l>    if (WriteAvgOverlaps)</l>
<l>        mvtec_csv_append_row (CSVDataAvgOverlaps, CSVInfoAvgOverlaps, AvgOverlapsRow, CSVDataAvgOverlaps, CSVInfoAvgOverlaps)</l>
<l>    endif</l>
<c>    *</c>
<c>    *************************</c>
<c>    * Write out the overlaps</c>
<c>    *************************</c>
<l>    if (WriteOverlaps)</l>
<c>        * Copy some basic columns</c>
<c>        * Sequence</c>
<l>        mvtec_csv_get_column (CSVData, CSVInfo, 0, 'false', SequenceCol)</l>
<l>        mvtec_csv_append_column ([], [], SequenceCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<c>        * ImageFile</c>
<l>        mvtec_csv_get_column (CSVData, CSVInfo, 1, 'false', ImageFileCol)</l>
<l>        mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, ImageFileCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<c>        * SegmentationFile</c>
<l>        mvtec_csv_get_column (CSVData, CSVInfo, 2, 'false', SegmentationFileCol)</l>
<l>        mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, SegmentationFileCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<c>        *</c>
<c>        * Theoretical Tracker Overlaps</c>
<c>        *</c>
<c>        * NoScale</c>
<l>        mvtec_string_tuple_to_string (OverlapsNoScale, '.3f', OverlapsNoScaleStr)</l>
<l>        NoScaleCol := ['theoretical_box_no_scale', OverlapsNoScaleStr]</l>
<l>        mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, NoScaleCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<c>        * NoRotation</c>
<l>        mvtec_string_tuple_to_string (OverlapsNoRotation, '.3f', OverlapsNoRotationStr)</l>
<l>        NoRotationCol := ['theoretical_box_no_rotation', OverlapsNoRotationStr]</l>
<l>        mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, NoRotationCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<c>        * Rect2</c>
<l>        mvtec_string_tuple_to_string (OverlapsRect2, '.3f', OverlapsRect2Str)</l>
<l>        Rect2Col := ['theoretical_box_rot', OverlapsRect2Str]</l>
<l>        mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, Rect2Col, CSVDataOverlaps, CSVInfoOverlaps)</l>
<c>        *</c>
<c>        * NoScale tracker overlaps</c>
<c>        *</c>
<l>        for Jdx := 0 to |TrackersNoScale.at(0)|-1 by 1</l>
<c>            * absolute IoU    </c>
<l>            mvtec_string_tuple_to_string (TrackersNoScale.at(4 + |TrackersNoScale.at(0)| + Jdx), '.3f', OverlapsTrackerStr)</l>
<l>            TrackerCol := [TrackersNoScale.at(0)[Jdx] + '_iou_abs', OverlapsTrackerStr]</l>
<l>            mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, TrackerCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<c>            * relative IoU</c>
<l>            mvtec_string_tuple_to_string (TrackersNoScale.at(5 + 2 * |TrackersNoScale.at(0)| + Jdx), '.3f', OverlapsTrackerStr)</l>
<l>            TrackerCol := [TrackersNoScale.at(0)[Jdx] + '_iou_rel', OverlapsTrackerStr]</l>
<l>            mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, TrackerCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<l>        endfor</l>
<c>        *</c>
<c>        * NoRotation tracker overlaps</c>
<c>        *</c>
<l>        for Jdx := 0 to |TrackersNoRotation.at(0)|-1 by 1</l>
<c>            * absolute IoU    </c>
<l>            mvtec_string_tuple_to_string (TrackersNoRotation.at(4 + |TrackersNoRotation.at(0)| + Jdx), '.3f', OverlapsTrackerStr)</l>
<l>            TrackerCol := [TrackersNoRotation.at(0)[Jdx] + '_iou_abs', OverlapsTrackerStr]</l>
<l>            mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, TrackerCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<c>            * relative IoU</c>
<l>            mvtec_string_tuple_to_string (TrackersNoRotation.at(5 + 2 * |TrackersNoRotation.at(0)| + Jdx), '.3f', OverlapsTrackerStr)</l>
<l>            TrackerCol := [TrackersNoRotation.at(0)[Jdx] + '_iou_rel', OverlapsTrackerStr]</l>
<l>            mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, TrackerCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<l>        endfor        </l>
<c>        *</c>
<c>        * Rect2 tracker overlaps</c>
<c>        *</c>
<l>        for Jdx := 0 to |TrackersRect2.at(0)|-1 by 1</l>
<c>            * absolute IoU    </c>
<l>            mvtec_string_tuple_to_string (TrackersRect2.at(4 + |TrackersRect2.at(0)| + Jdx), '.3f', OverlapsTrackerStr)</l>
<l>            TrackerCol := [TrackersRect2.at(0)[Jdx] + '_iou_abs', OverlapsTrackerStr]</l>
<l>            mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, TrackerCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<c>            * relative IoU</c>
<l>            mvtec_string_tuple_to_string (TrackersRect2.at(5 + 2 * |TrackersRect2.at(0)| + Jdx), '.3f', OverlapsTrackerStr)</l>
<l>            TrackerCol := [TrackersRect2.at(0)[Jdx] + '_iou_rel', OverlapsTrackerStr]</l>
<l>            mvtec_csv_append_column (CSVDataOverlaps, CSVInfoOverlaps, TrackerCol, CSVDataOverlaps, CSVInfoOverlaps)</l>
<l>        endfor</l>
<c>        *</c>
<c>        * Write out csv-data</c>
<l>        mvtec_csv_write_data (CSVDataOverlaps, CSVInfoOverlaps, ImageFolders[FolderIdx] + FileNameOverlaps, ColSeparator)</l>
<l>    endif</l>
<c>    *</c>
<c>    *****************************</c>
<c>    * Done with current sequence</c>
<c>    *****************************</c>
<l>    stop()</l>
<l>endfor</l>
<c>*</c>
<c>*****************************</c>
<c>* Done with all sequences</c>
<c>*****************************</c>
<c>* Write out the average scequence overlaps</c>
<l>if (WriteAvgOverlaps)</l>
<c>    * Calculate the mean-values over the sequences</c>
<l>    AvgOverlapsRow := ['', 'MEAN VALUES']</l>
<c>    * Get the total number of frames</c>
<l>    mvtec_csv_get_column (CSVDataAvgOverlaps, CSVInfoAvgOverlaps, 2, 'true', NumFrames)</l>
<l>    TotalNumFrames := sum(NumFrames)</l>
<l>    AvgOverlapsRow := [AvgOverlapsRow, TotalNumFrames]</l>
<l>    for Jdx := 3 to CSVInfoAvgOverlaps[3]-1 by 1</l>
<c>        * get the column and calculate the weighted mean</c>
<l>        mvtec_csv_get_column (CSVDataAvgOverlaps, CSVInfoAvgOverlaps, Jdx, 'true', DataColumn)</l>
<c>        * we have to calculate the weighted average with respect to the number of frames per sequence</c>
<l>        tuple_mult (DataColumn, real(NumFrames)/TotalNumFrames, MeanValue)</l>
<l>        MeanValue := sum(MeanValue)</l>
<l>        mvtec_string_tuple_to_string (MeanValue, '.3f', MeanValueStr)</l>
<l>        AvgOverlapsRow := [AvgOverlapsRow, MeanValueStr]</l>
<l>    endfor</l>
<l>    mvtec_csv_append_row (CSVDataAvgOverlaps, CSVInfoAvgOverlaps, AvgOverlapsRow, CSVDataAvgOverlaps, CSVInfoAvgOverlaps)</l>
<l>    mvtec_csv_write_data (CSVDataAvgOverlaps, CSVInfoAvgOverlaps, ImageFolders[Jdx-1] + FileNameAvgOverlaps, ColSeparator)</l>
<l>endif</l>
<l>set_system ('clip_region', ClipRegion)</l>
<c></c>
</body>
<docu id="main">
<parameters/>
</docu>
</procedure>
</hdevelop>
