Skip to content

contlengthContlengthContlengthcontlengthcontlength🔗

Short description🔗

contlengthContlengthContlengthcontlengthcontlength — Contour length of a region.

Signature🔗

contlength( region Regions, out real ContLength )void Contlength( const HObject& Regions, HTuple* ContLength )static void HOperatorSet.Contlength( HObject regions, out HTuple contLength )def contlength( regions: HObject ) -> Sequence[float]

def contlength_s( regions: HObject ) -> floatHerror contlength( const Hobject Regions, double* ContLength )

Herror T_contlength( const Hobject Regions, Htuple* ContLength )

HTuple HRegion::Contlength( ) const

HTuple HRegion.Contlength( )

Description🔗

The operator contlengthContlength calculates the total length of the contour (sum of all connection components of the region) for each region of Regionsregionsregions. The distance between two neighboring contour points parallel to the coordinate axes is rated 1, the distance in the diagonal is rated \(\sqrt{2}\).

In the documentation of this chapter (Regions / Features), you can find an image illustrating regions which vary in the length of their contours.

If more than one region is passed the numerical values of the contour length are stored in a tuple, the position of a value in the tuple corresponding to the position of the region in the input tuple. In case of an empty region the operator contlengthContlength returns the value 0.

Attention🔗

The contour of holes is not calculated.

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Automatically parallelized on tuple level.

Parameters🔗

Regionsregionsregions (input_object) region(-array) → objectHObjectHRegionHObjectHobject

Region(s) to be examined.

ContLengthcontLengthcont_length (output_control) real(-array) → (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Contour length of the input region(s).

Assertion: ContLength >= 0

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[])
{
  if (argc < 2)
  {
    cout << "Usage: " << argv[0] << " <# of regions> " << endl\;
    return (-1)\;
  }
 HWindow        w\;
  HRegionArray   reg\;
 int NumOfElements = atoi (argv[1])\;
 cout << "Draw " << NumOfElements << " regions " << endl\;
 for (int i=0\; i < NumOfElements\; i++)
  {
    reg[i] = w.DrawRegion ()\;
  }
 Tuple circ = reg.Circularity ()\;
  Tuple cont = reg.Contlength ()\;
 for (i = 0\; i < NumOfElements\; i++)
  {
    cout << "Circularity of " << i+1 << ". region = " << circ[i].D()\;
    cout << "\t\t Contour Length of" << i+1 <<
            ". region = " << cont[i].D() << endl\;
  }
 w.Click ()\;
  return(0)\;
}
(C++)
#include "HalconCpp.h"
#include <iostream>
using namespace HalconCpp\;

int main (int argc, char *argv[])
{
  HWindow        w(10,10,512,512)\;
  HRegion        reg\;
  int            NumOfElements = 3\;
 std::cout << "Draw " << NumOfElements << " regions " << std::endl\;
  GenEmptyObj(&reg)\;
  for (int i=0\; i < NumOfElements\; i++)
  {
    reg = reg.ConcatObj(w.DrawRegion())\;
  }
 HTuple circ = reg.Circularity ()\;
  HTuple cont = reg.Contlength ()\;
 for (int i = 0\; i < NumOfElements\; i++)
  {
    std::cout << "region " << i+1 << ": \tcircularity = " << circ[i].D() <<
                 "\tcontour length =" << cont[i].D() << std::endl\;
  }
  std::cout << "Click into the graphics window to end." << std::endl\;
  w.Click ()\;
  return(0)\;
}

Result🔗

The operator contlengthContlength 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>). If necessary an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

thresholdThreshold, regiongrowingRegiongrowing, connectionConnection

Possible successors

get_region_contourGetRegionContour

Alternatives

compactnessCompactness

See also

area_centerAreaCenter, get_region_contourGetRegionContour

Module🔗

Foundation