<?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 trackers within the input file</c>
<c>* amd calculate their relative and abolsut IoU</c>
<c>*</c>
<c>* Currently works or DAVIS and vot2016 datasets</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>FileName := 'tracker_boxes.csv'</l>
<c></c>
<c>* ['kcf','dsst','ccot','lgt','ant','l1apg']</c>
<l>Tracker := 'lgt'</l>
<c></c>
<c>* FLAG to switch the display on and off </c>
<l>Display := true</l>
<c></c>
<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>
<l>TrackerColor := '#00ff00'</l>
<c>*</c>
<c>*******************************************************</c>
<c>* Walk through the directory</c>
<c>*******************************************************</c>
<l>dev_update_off ()</l>
<l>dev_close_window ()</l>
<l>dev_open_window (0, 0, 512, 512, 'black', WindowHandle)</l>
<l>dev_open_window (0, 705, 300, 300, 'black', WindowHandle1)</l>
<l>get_system ('clip_region', ClipRegion)</l>
<l>set_system ('clip_region', 'false')</l>
<c>*</c>
<l>ColSeparator := ';'</l>
<l>StringQuote  := '"'</l>
<c>*</c>
<l>list_files (ImageFolder, 'directories', ImageFolders)</l>
<l>for Idx := 0 to |ImageFolders|-1 by 1</l>
<l>    InputFile := ImageFolders[Idx] + FileName</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>    HeaderCategoriesOut := [HeaderCategories,'theoretical_box_no_scale',\
                            'box_axis_aligned','theoretical_box_rot']</l>
<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>
<l>    tuple_find (HeaderCategories, 'theoretical_smallest_rectangle1', SmallestRect1Idx)</l>
<l>    tuple_find (HeaderCategories, 'tracker_' + Tracker, TrackerIdx)</l>
<c>    *</c>
<c>    * Clear Bounding Box Overlaps</c>
<l>    MaxOverlapNoScale:= []</l>
<l>    MaxOverlapNoRotation:= []</l>
<l>    MaxOverlapRect2:= []</l>
<l>    MaxOverlapSmallestRect1:= []</l>
<l>    MaxOverlapTracker := []</l>
<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>
<l>        mvtec_string_to_tuple (number(Obj[TrackerIdx]), box_coordinate_tracker)</l>
<c></c>
<l>        SegmentationFile := number(Obj[SegmemtationFileIdx])</l>
<c>        *</c>
<c>        ****************</c>
<c>        * Read Image</c>
<c>        ****************</c>
<l>        read_image (Image, ImageFolders[Idx] + ImageName)</l>
<c>        </c>
<c>        ************************</c>
<c>        * Read Segmentation</c>
<c>        ************************</c>
<l>        handle_NaN_box_coordinate (box_coordinate_tracker, box_coordinate_tracker)</l>
<c></c>
<c>        </c>
<l>        SegmentationPath := ImageFolders[Idx] + 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>
<l>        gen_rectangle_b (TrackerRegion, box_coordinate_tracker)</l>
<c>   </c>
<c>        ************</c>
<c>        * Display  *</c>
<c>        ************</c>
<l>        if (Display)</l>
<l>            dev_set_window (WindowHandle)    </l>
<l>            set_system ('flush_graphic', 'false')</l>
<l>            dev_display (Image)</l>
<l>            disp_region_alpha (RectangleNoScale, NoScaleColor, 30)</l>
<l>            disp_region_alpha (RectangleNoRotation, NoRotColor, 30)</l>
<l>            disp_region_alpha (Rectangle2, Rect2Color, 30)</l>
<l>            disp_region_alpha (SmallestRectangle1, SmallestRect1Color, 30)</l>
<l>            disp_region_alpha (TrackerRegion, TrackerColor, 70)</l>
<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 (WindowHandle, (ImageIdx+1) + '/' + NumImages, 'window', 12, 12, 'black', 'true')</l>
<l>*         stop()</l>
<c>        </c>
<c>        * Remember the overlaps</c>
<l>        bb_overlap (RegionSeg, RectangleNoScale, overlap_no_scale)</l>
<l>        bb_overlap (RegionSeg, RectangleNoRotation, overlap_no_rotiation)</l>
<l>        bb_overlap (RegionSeg, Rectangle2, overlap_rect2)</l>
<l>        bb_overlap (RegionSeg, SmallestRectangle1, overlap_smallest_rect1)</l>
<l>        bb_overlap (RegionSeg, TrackerRegion, overlap_tracker)</l>
<c>        *        </c>
<l>        MaxOverlapNoScale[ImageIdx]:= overlap_no_scale</l>
<l>        MaxOverlapNoRotation[ImageIdx]:= overlap_no_rotiation</l>
<l>        MaxOverlapRect2[ImageIdx]:= overlap_rect2</l>
<l>        MaxOverlapSmallestRect1[ImageIdx]:= overlap_smallest_rect1</l>
<l>        MaxOverlapTracker[ImageIdx]:= overlap_tracker</l>
<l>*         stop()</l>
<l>    endfor</l>
<c>    * Plot the results</c>
<l>    dev_set_window (WindowHandle1)</l>
<l>    dev_clear_window ()</l>
<l>    plot_tuple (WindowHandle1, [1:|MaxOverlapNoScale|], MaxOverlapNoScale, ['frameID'], ['BB overlap'], [NoScaleColor], ['start_y','end_y'], [0.0,1.0])</l>
<l>    plot_tuple (WindowHandle1, [1:|MaxOverlapNoRotation|], MaxOverlapNoRotation, ['frameID'], ['BB overlap'], [NoRotColor], ['start_y','end_y'], [0.0,1.0])</l>
<l>    plot_tuple (WindowHandle1, [1:|MaxOverlapRect2|], MaxOverlapRect2, ['frameID'], ['BB overlap'], [Rect2Color], ['start_y','end_y'], [0.0,1.0])   </l>
<l>    plot_tuple (WindowHandle1, [1:|MaxOverlapSmallestRect1|], MaxOverlapSmallestRect1, ['frameID'], ['BB overlap'], [SmallestRect1Color], ['start_y','end_y'], [0.0,1.0])   </l>
<l>    plot_tuple (WindowHandle1, [1:|MaxOverlapTracker|], MaxOverlapTracker, ['frameID'], ['BB overlap'], [TrackerColor], ['start_y','end_y'], [0.0,1.0])   </l>
<l>    stop()</l>
<l>endfor</l>
<c>*</c>
<l>set_system ('clip_region', ClipRegion)</l>
<c></c>
</body>
<docu id="main">
<parameters/>
</docu>
</procedure>
</hdevelop>
