<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.1" halcon_version="13.0">
<procedure name="levenberg_marquardt_bb">
<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="h" 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> * 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>* First we construct an upper and lower boundary</c>
<l>smallest_rectangle2 (RegionSeg, Row, Column, Phi, Length1, Length2)</l>
<l>smallest_rectangle1 (RegionSeg, Row1, Column1, Row2, Column2)</l>
<l>box_coordinate_upper := [Row2,Column2,Length1*2+1, Length2*2+1,180.0]</l>
<c>* For now the lower bound is just a random guess</c>
<l>* box_coordinate_lower := box_coordinate_upper /2</l>
<l>box_coordinate_lower[0:1] := [Row1,Column1]</l>
<l>box_coordinate_lower[2:3] := box_coordinate_upper[2:3]/16.0</l>
<l>box_coordinate_lower[4] := -180.0</l>
<c>*</c>
<l>EPS := 0.000000001</l>
<l>NumIter := 2000</l>
<c>*</c>
<l>region_bb_overlap (RegionSeg, initial_box_coordinate, overlap_initial)</l>
<l>tuple_gen_const (NumIter, 0.0,Overlaps)</l>
<l>overlap := overlap_initial</l>
<l>Overlaps[0] := overlap</l>
<l>box_coordinate := initial_box_coordinate</l>
<c>*</c>
<l>for Index := 1 to NumIter by 1</l>
<l>    Lambda := 0.0</l>
<c>    * Define the gradient step. Setting a value to 0 prevents its optimization</c>
<l>    levenberg_marquardt_step (RegionSeg, Lambda, box_coordinate, h, box_coordinate_upper,\
                              box_coordinate_lower, EPS, box_coordinate)</l>
<l>    gen_rectangle_b (Rectangle, box_coordinate)</l>
<l>    region_bb_overlap (RegionSeg, box_coordinate, overlap)</l>
<l>    Overlaps[Index] := overlap</l>
<c>    *</c>
<c>    ****************</c>
<c>    * Display</c>
<c>    ****************</c>
<l>    if (Display)</l>
<l>        set_system ('flush_graphic', 'false')</l>
<l>        dev_clear_window ()</l>
<l>        disp_region_alpha (RegionSeg, '#00ff00', 90)</l>
<l>        disp_region_alpha (Rectangle, '#ffff00', 90)</l>
<l>        set_system ('flush_graphic', 'true')</l>
<l>        disp_message (WindowHandle, 'overlap: ' + overlap, 'window', 12, 12, 'black', 'true')</l>
<l>    endif</l>
<l>endfor</l>
<l>best_box_coordinate := box_coordinate</l>
<l>best_overlap := overlap</l>
<c></c>
<l>return ()</l>
</body>
<docu id="levenberg_marquardt_bb">
<parameters>
<parameter id="Display"/>
<parameter id="Rectangle"/>
<parameter id="RegionSeg"/>
<parameter id="WindowHandle"/>
<parameter id="best_box_coordinate"/>
<parameter id="best_overlap"/>
<parameter id="h"/>
<parameter id="initial_box_coordinate"/>
</parameters>
</docu>
</procedure>
</hdevelop>
