<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="exhaustive_find_best_rectangle1_fixed_scale">
<interface>
<io>
<par name="RegionSeg" base_type="iconic" dimension="0"/>
</io>
<ic>
<par name="initial_box_coordinate" base_type="ctrl" dimension="0"/>
<par name="InitWidth" base_type="ctrl" dimension="0"/>
<par name="InitHeight" base_type="ctrl" dimension="0"/>
</ic>
<oc>
<par name="best_box_coordinate" base_type="ctrl" dimension="0"/>
<par name="best_overlap" base_type="ctrl" dimension="0"/>
</oc>
</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>
<l>    smallest_rectangle1 (RegionSeg, Row1, Column1, Row2, Column2)</l>
<l>    gen_rectangle1 (MaxROI, Row1, Column1, Row2, Column2)</l>
<c>    * We can erode the MaxROI with the width/height of the current template.</c>
<c>    * We substract 3 to ensure we have the correct candidate with us and rather</c>
<c>    * do more work than loose it due to rounding</c>
<c>    * We need to ensure that the width and height of the erosion mask are at</c>
<c>    * least 1 since otherwise the output region would be empty.</c>
<l>    erosion_rectangle1 (MaxROI, ROI, max2(initial_box_coordinate[2]-3,1), \
                        max2(initial_box_coordinate[3]-3,1))</l>
<l>    get_region_points (ROI, Rows, Columns)</l>
<l>    best_overlap := 0.0</l>
<l>    best_box_coordinate := []</l>
<l>    NumPoints := |Rows|</l>
<l>    if (NumPoints&gt;0)</l>
<c>        * We divide the Rows and Cols into multiple threads and combine the results</c>
<l>        exhaustive_find_best_rectangle1_fixed_scale_parallel (RegionSeg, Rows, Columns, InitWidth, InitHeight, \
                                                              initial_box_coordinate, best_overlap, best_box_coordinate, best_overlap)</l>
<l>    else</l>
<c>        * The original rectangle is larger than the current region. We find out if</c>
<c>        * it is the height or the width which is causing our region to be empty</c>
<l>        CurrHeight := Row2-Row1+1</l>
<l>        CurrWidth := Column2-Column1+1</l>
<l>        if (CurrHeight &lt; InitHeight and CurrWidth &lt; InitWidth)</l>
<l>            area_center (MaxROI, _, Row, Column)</l>
<l>            best_box_coordinate := [Row,Column,InitWidth,InitHeight,initial_box_coordinate[4]]  </l>
<l>        elseif (CurrWidth &lt; InitWidth)</l>
<c>            * =&gt; Find the best row position of the rectangle</c>
<l>            gen_rectangle1 (Rectangle1, Row1+InitHeight/2-1, Column1+CurrWidth/2, \
                            Row2-InitHeight/2+1, Column1+CurrWidth/2)</l>
<l>            get_region_points (Rectangle1, Rows, Columns)</l>
<l>            best_overlap := 0.0</l>
<l>            best_box_coordinate := []</l>
<l>            exhaustive_best_rectangle1_fixed_scale (RegionSeg, Rows, Columns, InitWidth, InitHeight, initial_box_coordinate, \
                                                    best_overlap, best_overlap, best_box_coordinate)</l>
<l>        else</l>
<c>            * CurrHeight &lt; InitHeight</c>
<c>            * Find the best col position of the rectangle</c>
<l>            gen_rectangle1 (Rectangle1, Row1+CurrHeight/2, Column1+InitWidth/2-1, \
                            Row1+CurrHeight/2, Column2-InitWidth/2+1)</l>
<l>            get_region_points (Rectangle1, Rows, Columns)</l>
<l>            best_overlap := 0.0</l>
<l>            best_box_coordinate := []</l>
<l>            exhaustive_best_rectangle1_fixed_scale (RegionSeg, Rows, Columns, InitWidth, \
                                                    InitHeight, initial_box_coordinate, best_overlap, best_overlap, best_box_coordinate)</l>
<c>            </c>
<l>        endif</l>
<l>        region_bb_overlap (RegionSeg, best_box_coordinate, best_overlap)</l>
<l>    endif</l>
<c>    </c>
<l>return ()</l>
</body>
<docu id="exhaustive_find_best_rectangle1_fixed_scale">
<parameters>
<parameter id="InitHeight"/>
<parameter id="InitWidth"/>
<parameter id="RegionSeg"/>
<parameter id="best_box_coordinate"/>
<parameter id="best_overlap"/>
<parameter id="initial_box_coordinate"/>
</parameters>
</docu>
</procedure>
</hdevelop>
