<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="exhaustive_best_rectangle1_fixed_scale">
<interface>
<io>
<par name="RegionSeg" base_type="iconic" dimension="0"/>
</io>
<ic>
<par name="Rows" base_type="ctrl" dimension="0"/>
<par name="Columns" base_type="ctrl" dimension="0"/>
<par name="InitWidth" base_type="ctrl" dimension="0"/>
<par name="InitHeight" base_type="ctrl" dimension="0"/>
<par name="initial_box_coordinate" base_type="ctrl" dimension="0"/>
<par name="best_overlap" base_type="ctrl" dimension="0"/>
</ic>
<oc>
<par name="best_overlapOut" base_type="ctrl" dimension="0"/>
<par name="best_box_coordinate" 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>
<c>* This procedure loops over all rectangles with center points (Rows,Columns) \
  (with fixed Width == InitWidth, Height == InitHeight and \
  Angle == initial_box_coordinate[4]) and computes the overlap with respect to RegionSeg. \
  The best result is returned.</c>
<c></c>
<c>* We are sampling rectangle1, we move the Row,Columns to the top left corner.</c>
<c>* Since we were less strict on the ROI beforehand, we can round the Rows and still</c>
<c>* be sure to check all possible boxes</c>
<l>Rows := round(Rows - (InitHeight-1)/2.0)</l>
<l>Columns := round(Columns - (InitWidth-1)/2.0)</l>
<c></c>
<c>* convert box coordinates to rectangle1 parameters</c>
<l>get_system ('clip_region', Information)</l>
<l>set_system ('clip_region', 'false')</l>
<l>gen_rectangle_b (Rectangle, initial_box_coordinate)</l>
<l>smallest_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)</l>
<c></c>
<l>best_overlapOut := best_overlap</l>
<l>BestRow1 := Row1</l>
<l>BestColumn1 := Column1</l>
<l>BestRow2 := Row2</l>
<l>BestColumn2 := Column2</l>
<l>NumPoints := |Rows|</l>
<l>for Idx := 0 to NumPoints-1 by 1</l>
<c>    * Get the Row and Column coordinates and check the overlap. If its</c>
<c>    * better than what we have, then keep the coordinates</c>
<l>    Row1 := Rows[Idx]</l>
<l>    Column1 := Columns[Idx]</l>
<l>    Row2 := Row1 + InitHeight - 1</l>
<l>    Column2 := Column1 + InitWidth - 1</l>
<l>    rectangle1_bb_overlap (RegionSeg, Row1, Column1, Row2, Column2, overlap)</l>
<l>    if (overlap &gt; best_overlapOut)</l>
<l>        best_overlapOut := overlap</l>
<l>        BestRow1 := Row1</l>
<l>        BestColumn1 := Column1</l>
<l>        BestRow2 := Row2</l>
<l>        BestColumn2 := Column2</l>
<l>    endif</l>
<l>endfor</l>
<c>* Convert the output to BoxCoordinates</c>
<l>convert_rectangle1_params_to_box_coordinates (BestRow1, BestColumn1, BestRow2, \
                                              BestColumn2, best_box_coordinate)</l>
<l>set_system ('clip_region', Information)</l>
<l>return ()</l>
</body>
<docu id="exhaustive_best_rectangle1_fixed_scale">
<parameters>
<parameter id="Columns"/>
<parameter id="InitHeight"/>
<parameter id="InitWidth"/>
<parameter id="RegionSeg"/>
<parameter id="Rows"/>
<parameter id="best_box_coordinate"/>
<parameter id="best_overlap"/>
<parameter id="best_overlapOut"/>
<parameter id="initial_box_coordinate"/>
</parameters>
</docu>
</procedure>
</hdevelop>
