<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="exhaustive_find_best_rectangle1">
<interface>
<io>
<par name="RegionSeg" base_type="iconic" dimension="0"/>
</io>
<ic>
<par name="SRectRow1" base_type="ctrl" dimension="0"/>
<par name="SRectRow2" base_type="ctrl" dimension="0"/>
<par name="MinHeight" base_type="ctrl" dimension="0"/>
<par name="SRectColumn1" base_type="ctrl" dimension="0"/>
<par name="SRectColumn2" base_type="ctrl" dimension="0"/>
<par name="MinWidth" base_type="ctrl" dimension="0"/>
</ic>
<oc>
<par name="best_overlap" base_type="ctrl" dimension="0"/>
<par name="best_row1" base_type="ctrl" dimension="0"/>
<par name="best_column1" base_type="ctrl" dimension="0"/>
<par name="best_row2" base_type="ctrl" dimension="0"/>
<par name="best_column2" 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>    best_overlap := 0.0</l>
<l>    best_row1 := 0</l>
<l>    best_column1 := 0</l>
<l>    best_row2 := 0</l>
<l>    best_column2 := 0</l>
<l>    for Row1 := SRectRow1 to SRectRow2-(MinHeight-1) by 1</l>
<l>        for Row2 := Row1+MinHeight-1 to SRectRow2 by 1</l>
<c>            * intersect RegionSeg with the stripe between Row1 and Row2</c>
<l>            gen_rectangle1 (Stripe, Row1, SRectColumn1, Row2, SRectColumn2)</l>
<l>            intersection (RegionSeg, Stripe, StripeIntersection)</l>
<c>            * Compute bounding rectangles of the connected components \
              of StripeIntersection. The left and right boundary of the best \
              rectangle touch one of these components each (though not \
              necessarily the same one).</c>
<l>            connection (StripeIntersection, ConnectedRegions)</l>
<l>            smallest_rectangle1 (ConnectedRegions, CCRow1, CCColumn1, \
                                 CCRow2, CCColumn2)</l>
<l>            if (Row1 &lt; min(CCRow1) or Row2 &gt; max(CCRow2))</l>
<l>                continue</l>
<l>            endif</l>
<c>            * Compute the possible column values</c>
<l>            ColValues := []</l>
<l>            for CCIndex := 0 to |CCColumn1|-1 by 1</l>
<l>                ColValues := [ColValues, [CCColumn1[CCIndex]:CCColumn2[CCIndex]]]</l>
<l>            endfor</l>
<l>            tuple_sort (ColValues, ColValues)</l>
<l>            tuple_uniq (ColValues, ColValues)</l>
<l>            NumColValues := |ColValues|</l>
<c>            * Loop over all possible column values</c>
<l>            for Column1Index := 0 to |ColValues|-1 by 1</l>
<c>                * If Column2Index &lt; Column1Index+MinWidth-1, the intersection \
                  of the rectangle with the region has smaller area than MinArea</c>
<l>                for Column2Index := Column1Index+(MinWidth-1) to |ColValues|-1 by 1</l>
<l>                    Column1 := ColValues[Column1Index]</l>
<l>                    Column2 := ColValues[Column2Index]</l>
<l>                    rectangle1_bb_overlap (RegionSeg, Row1, Column1, Row2, Column2, overlap)</l>
<l>                    if (overlap &gt; best_overlap)</l>
<l>                        best_overlap := overlap</l>
<l>                        best_row1 := Row1</l>
<l>                        best_column1 := Column1</l>
<l>                        best_row2 := Row2</l>
<l>                        best_column2 := Column2</l>
<l>                    endif</l>
<l>                endfor</l>
<l>            endfor</l>
<l>        endfor</l>
<l>    endfor</l>
<c>    </c>
<c>    </c>
<l>return ()</l>
</body>
<docu id="exhaustive_find_best_rectangle1">
<parameters>
<parameter id="MinHeight"/>
<parameter id="MinWidth"/>
<parameter id="RegionSeg"/>
<parameter id="SRectColumn1"/>
<parameter id="SRectColumn2"/>
<parameter id="SRectRow1"/>
<parameter id="SRectRow2"/>
<parameter id="best_column1"/>
<parameter id="best_column2"/>
<parameter id="best_overlap"/>
<parameter id="best_row1"/>
<parameter id="best_row2"/>
</parameters>
</docu>
</procedure>
</hdevelop>
