<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="optimize_rectangle_overlap">
<interface>
<io>
<par name="RegionSeg" base_type="iconic" dimension="0"/>
</io>
<oo>
<par name="Rectangle" base_type="iconic" dimension="0"/>
</oo>
<ic>
<par name="initial_box_coordinate" base_type="ctrl" dimension="0"/>
<par name="Rotation" base_type="ctrl" dimension="0"/>
<par name="Scale" base_type="ctrl" dimension="0"/>
<par name="OptimizationMethod" base_type="ctrl" dimension="0"/>
<par name="Display" base_type="ctrl" dimension="0"/>
<par name="WindowHandle" base_type="ctrl" dimension="0"/>
</ic>
<oc>
<par name="best_overlap" base_type="ctrl" dimension="0"/>
<par name="best_box_coordinate" base_type="ctrl" dimension="0"/>
</oc>
</interface>
<body>
<c></c>
<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>* Check input parameters</c>
<c>**************************</c>
<l>if (OptimizationMethod == 'exhaustive')</l>
<c>    * OptimizationMethod == 'exhaustive' can</c>
<c>    * only estimate the best position at the moment</c>
<l>    if (Scale # false)</l>
<l>        throw('Exhaustive search for Scale not implemented yet')</l>
<l>    endif</l>
<l>    if (Rotation#false)</l>
<l>        throw('Exhaustive search for Rotation not implemented yet')</l>
<l>    endif</l>
<l>endif</l>
<c></c>
<c>************************</c>
<c>* Initialize variables</c>
<c>************************</c>
<l>if (OptimizationMethod == [])</l>
<c>    * Default optimization method:</c>
<l>    OptimizationMethod := 'gradient_descent'</l>
<l>endif</l>
<c>* b = [row, column, height, width, phi</c>
<l>best_box_coordinate := initial_box_coordinate</l>
<c></c>
<l>if (OptimizationMethod # 'exhaustive')</l>
<c>    * For all optimization methods we set the numerical difference</c>
<c>    * accuracy</c>
<c>    </c>
<c>    * Numerical difference step sizes</c>
<l>    h := [1,1,2,2,1]</l>
<c>    </c>
<c>    * Check if we should optimize the rotation:</c>
<l>    if (Rotation == false)</l>
<l>        h[4] := 0</l>
<l>    endif</l>
<c>    * Check if we should optimize the scale:</c>
<c>    * We could also ignore optimizing the scale by setting the width and height</c>
<c>    * derivate to 0 ...</c>
<l>    if (Scale == false)</l>
<l>        h[2:3] := 0</l>
<l>    endif</l>
<l>endif</l>
<c></c>
<c>*****************************</c>
<c>* Determine the best b....</c>
<c>*****************************</c>
<l>if (OptimizationMethod == 'gradient_descent') </l>
<c>    ********************</c>
<c>    * Gradient descent</c>
<c>    ********************</c>
<l>    gradient_descent_bb (RegionSeg, Rectangle, initial_box_coordinate, h, Display, \
                         WindowHandle, best_overlap, best_box_coordinate)</l>
<l>elseif (OptimizationMethod == 'levenberg')</l>
<c>    ***********************</c>
<c>    * Levenberg Marquardt</c>
<c>    ***********************</c>
<l>    levenberg_marquardt_bb (RegionSeg, Rectangle, initial_box_coordinate, h, Display, \
                            WindowHandle, best_overlap, best_box_coordinate)</l>
<l>elseif (OptimizationMethod == 'exhaustive')</l>
<c>    ********************</c>
<c>    * Exhaustive Search</c>
<c>    ********************</c>
<l>    exhaustive_search_bb (RegionSeg, Rectangle, initial_box_coordinate, Scale, Rotation, \
                   best_overlap, best_box_coordinate)</l>
<l>else</l>
<l>    throw('Optimization method not implemented')</l>
<l>endif</l>
<c></c>
<c></c>
<l>return ()</l>
</body>
<docu id="optimize_rectangle_overlap">
<parameters>
<parameter id="Display"/>
<parameter id="OptimizationMethod"/>
<parameter id="Rectangle"/>
<parameter id="RegionSeg"/>
<parameter id="Rotation"/>
<parameter id="Scale"/>
<parameter id="WindowHandle"/>
<parameter id="best_box_coordinate"/>
<parameter id="best_overlap"/>
<parameter id="initial_box_coordinate"/>
</parameters>
</docu>
</procedure>
</hdevelop>
