HALCON Reference Manual 10.0.2
Table of Contents / Regions / Features ClassesClassesClasses | | | Operators

smallest_rectangle2smallest_rectangle2smallest_rectangle2SmallestRectangle2SmallestRectangle2 (Operator)

Name

smallest_rectangle2smallest_rectangle2smallest_rectangle2SmallestRectangle2SmallestRectangle2 — Smallest surrounding rectangle with any orientation.

Signature

smallest_rectangle2(Regions : : : Row, Column, Phi, Length1, Length2)

Herror smallest_rectangle2(const Hobject Regions, double* Row, double* Column, double* Phi, double* Length1, double* Length2)

Herror T_smallest_rectangle2(const Hobject Regions, Htuple* Row, Htuple* Column, Htuple* Phi, Htuple* Length1, Htuple* Length2)

Herror smallest_rectangle2(Hobject Regions, double* Row, double* Column, double* Phi, double* Length1, double* Length2)

Herror smallest_rectangle2(Hobject Regions, HTuple* Row, HTuple* Column, HTuple* Phi, HTuple* Length1, HTuple* Length2)

double HRegion::SmallestRectangle2(double* Column, double* Phi, double* Length1, double* Length2) const

HTuple HRegionArray::SmallestRectangle2(HTuple* Column, HTuple* Phi, HTuple* Length1, HTuple* Length2) const

void HOperatorSetX.SmallestRectangle2(
[in] IHUntypedObjectX* Regions, [out] VARIANT* Row, [out] VARIANT* Column, [out] VARIANT* Phi, [out] VARIANT* Length1, [out] VARIANT* Length2)

VARIANT HRegionX.SmallestRectangle2(
[out] VARIANT* Column, [out] VARIANT* Phi, [out] VARIANT* Length1, [out] VARIANT* Length2)

static void HOperatorSet.SmallestRectangle2(HObject regions, out HTuple row, out HTuple column, out HTuple phi, out HTuple length1, out HTuple length2)

void HRegion.SmallestRectangle2(out HTuple row, out HTuple column, out HTuple phi, out HTuple length1, out HTuple length2)

void HRegion.SmallestRectangle2(out double row, out double column, out double phi, out double length1, out double length2)

Description

The operator smallest_rectangle2smallest_rectangle2smallest_rectangle2SmallestRectangle2SmallestRectangle2 determines the smallest surrounding rectangle of a region, i.e., the rectangle with the smallest area of all rectangles containing the region. For this rectangle the center, the inclination and the two radii are calculated.

The operator is applied when, for example, the location of a scenery of several regions (e.g., printed text on a rectangular paper or in rectangular print (justified lines)) must be found. The parameters of smallest_rectangle2smallest_rectangle2smallest_rectangle2SmallestRectangle2SmallestRectangle2 are chosen in such a way that they can be used directly as input for the operators disp_rectangle2disp_rectangle2disp_rectangle2DispRectangle2DispRectangle2 and gen_rectangle2gen_rectangle2gen_rectangle2GenRectangle2GenRectangle2.

If more than one region is passed in RegionsRegionsRegionsRegionsregions the results are stored in tuples, the index of a value in the tuple corresponding to the index of a region in the input. In case of empty region all parameters have the value 0.0 if no other behavior was set (see set_systemset_systemset_systemSetSystemSetSystem).

Parallelization

Parameters

RegionsRegionsRegionsRegionsregions (input_object)  region(-array) objectHRegionHRegionHRegionXHobject

Regions to be examined.

RowRowRowRowrow (output_control)  rectangle2.center.y(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Line index of the center.

ColumnColumnColumnColumncolumn (output_control)  rectangle2.center.x(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Column index of the center.

PhiPhiPhiPhiphi (output_control)  rectangle2.angle.rad(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Orientation of the surrounding rectangle (arc measure)

Assertion: ((- pi / 2) < Phi) && (Phi <= (pi / 2))

Length1Length1Length1Length1length1 (output_control)  rectangle2.hwidth(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

First radius (half length) of the surrounding rectangle.

Assertion: Length1 >= 0.0

Length2Length2Length2Length2length2 (output_control)  rectangle2.hheight(-array) HTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double)

Second radius (half width) of the surrounding rectangle.

Assertion: (Length2 >= 0.0) && (Length2 <= Length1)

Example (HDevelop)

read_image(Image,'fabrik')
open_window(0,0,-1,-1,'root','visible','',WindowHandle)
regiongrowing(Image,Seg,5,5,6,100)
smallest_rectangle2(Seg,Row,Column,Phi,Length1,Length2)
gen_rectangle2(Rectangle,Row,Column,Phi,Length1,Length2)
set_draw(WindowHandle,'margin')
disp_region(Rectangle,WindowHandle)

Example (HDevelop)

read_image(Image,'fabrik')
open_window(0,0,-1,-1,'root','visible','',WindowHandle)
regiongrowing(Image,Seg,5,5,6,100)
smallest_rectangle2(Seg,Row,Column,Phi,Length1,Length2)
gen_rectangle2(Rectangle,Row,Column,Phi,Length1,Length2)
set_draw(WindowHandle,'margin')
disp_region(Rectangle,WindowHandle)

Example (C++)

#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"
using namespace Halcon;

int main (int argc, char *argv[])
{
  Tuple    row, col, phi, len1, len2;

  HImage   img (argv[1]);
  HWindow  w;

  img.Display (w);

  HRegionArray  reg  = img.Regiongrowing (5, 5, 6.0, 100);
  HRegionArray  seg  = reg.SelectShape ("area", "and", 100.0, 1000.0);

  row = seg.SmallestRectangle2 (&col, &phi, &len1, &len2);

  HRegionArray rect = HRegionArray::GenRectangle2 (row, col, phi, len1, len2);

  w.SetDraw   ("margin");
  w.SetColor  ("green");   reg.Display (w);
  w.SetColor  ("blue");    seg.Display (w);
  w.SetColor  ("red");     rect.Display (w);
  w.Click ();

  return(0);
}

Example (HDevelop)

read_image(Image,'fabrik')
open_window(0,0,-1,-1,'root','visible','',WindowHandle)
regiongrowing(Image,Seg,5,5,6,100)
smallest_rectangle2(Seg,Row,Column,Phi,Length1,Length2)
gen_rectangle2(Rectangle,Row,Column,Phi,Length1,Length2)
set_draw(WindowHandle,'margin')
disp_region(Rectangle,WindowHandle)

Example (HDevelop)

read_image(Image,'fabrik')
open_window(0,0,-1,-1,'root','visible','',WindowHandle)
regiongrowing(Image,Seg,5,5,6,100)
smallest_rectangle2(Seg,Row,Column,Phi,Length1,Length2)
gen_rectangle2(Rectangle,Row,Column,Phi,Length1,Length2)
set_draw(WindowHandle,'margin')
disp_region(Rectangle,WindowHandle)

Complexity

If F is the area of the region and N is the number of supporting points of the convex hull, the runtime complexity is O(sqrt(F) + N^2).

Result

The operator smallest_rectangle2smallest_rectangle2smallest_rectangle2SmallestRectangle2SmallestRectangle2 returns the value 2 (H_MSG_TRUE) if the input is not empty. The behavior in case of empty input (no input regions available) is set via the operator set_system('no_object_result',<Result>)set_system("no_object_result",<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>). The behavior in case of empty region (the region is the empty set) is set via set_system('empty_region_result',<Result>)set_system("empty_region_result",<Result>)set_system("empty_region_result",<Result>)SetSystem("empty_region_result",<Result>)SetSystem("empty_region_result",<Result>). If necessary an exception is raised.

Possible Predecessors

thresholdthresholdthresholdThresholdThreshold, regiongrowingregiongrowingregiongrowingRegiongrowingRegiongrowing, connectionconnectionconnectionConnectionConnection, runlength_featuresrunlength_featuresrunlength_featuresRunlengthFeaturesRunlengthFeatures

Possible Successors

disp_rectangle2disp_rectangle2disp_rectangle2DispRectangle2DispRectangle2, gen_rectangle2gen_rectangle2gen_rectangle2GenRectangle2GenRectangle2

Alternatives

elliptic_axiselliptic_axiselliptic_axisEllipticAxisEllipticAxis, smallest_rectangle1smallest_rectangle1smallest_rectangle1SmallestRectangle1SmallestRectangle1

See also

smallest_circlesmallest_circlesmallest_circleSmallestCircleSmallestCircle, set_shapeset_shapeset_shapeSetShapeSetShape

Module

Foundation


Table of Contents / Regions / Features ClassesClassesClasses | | | Operators
HALCON Reference Manual 10.0.2 Copyright © 1996-2011 MVTec Software GmbH