Skip to content

smallest_rectangle2SmallestRectangle2SmallestRectangle2smallest_rectangle2smallest_rectangle2🔗

説明🔗

smallest_rectangle2SmallestRectangle2SmallestRectangle2smallest_rectangle2smallest_rectangle2 — 領域を囲み任意の方向を持つ最小矩形を求める。

書式🔗

smallest_rectangle2( region Regions, out rectangle2.center.y Row, out rectangle2.center.x Column, out rectangle2.angle.rad Phi, out rectangle2.hwidth Length1, out rectangle2.hheight Length2 )void SmallestRectangle2( const HObject& Regions, HTuple* Row, HTuple* Column, HTuple* Phi, HTuple* Length1, HTuple* Length2 )static void HOperatorSet.SmallestRectangle2( HObject regions, out HTuple row, out HTuple column, out HTuple phi, out HTuple length1, out HTuple length2 )def smallest_rectangle2( regions: HObject ) -> Tuple[Sequence[float], Sequence[float], Sequence[float], Sequence[float], Sequence[float]]

def smallest_rectangle2_s( regions: HObject ) -> Tuple[float, float, float, float, float]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 )

void HRegion::SmallestRectangle2( HTuple* Row, HTuple* Column, HTuple* Phi, HTuple* Length1, HTuple* Length2 ) const

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

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 )

説明🔗

オペレーター smallest_rectangle2SmallestRectangle2は、領域を囲む最小の矩形、 すなわち領域を含むすべての矩形の中で最小の面積を持つ矩形を決定しま す。この矩形に対して、中心と傾斜と 2 つの辺長(の半分の長さ)が計 算されます。矩形の計算はピクセルの中心座標に基いて行われます。

領域を囲む最小矩形。矩形の計算はピクセルの中心座標に基いて行われます。 この章(Regions / Features)のドキュメント内に領域を囲む 最小矩形の辺長と方向が変化した場合のregionのイメージ図があります。

このオペレーターは、たとえば いくつかの領域の背景 (たとえば、矩形 上にかかれたテキスト、あるいは矩形の印刷物) を見つける必要があると きに有効です。 smallest_rectangle2SmallestRectangle2 の出力パラメーターは、オペレーター disp_rectangle2DispRectangle2 と gen_rectangle2GenRectangle2 に対する入 力として直接使用できます。

2 つ以上の領域が Regionsregionsregions に入力されると、その結果は Tuple に保存されます。この Tuple 内のインデックスは、入力領域のイ ンデックスに対応します。空の領域の場合、他の動作が設定されていなけ れば(set_systemSetSystem 参照)すべてのパラメーターは 0.0 となりま す。

実行情報🔗

実行情報
  • マルチスレッドタイプ: リエントラント(非排他なオペレーターと並列に動作)

  • マルチスレッドスコープ: グローバル(他のスレッドから呼び出される可能性あり)

  • tupleレベルで自動的に並列演算処理を実施

パラメーター🔗

Regionsregionsregions (input_object) region(-array) → objectHObjectHRegionHObjectHobject

対象となる領域

Rowrowrow (output_control) rectangle2.center.y(-array) → (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

中心の行座標

Columncolumncolumn (output_control) rectangle2.center.x(-array) → (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

中心の列座標

Phiphiphi (output_control) rectangle2.angle.rad(-array) → (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

矩形の方向(弧測度)

制限: -pi / 2 < Phi && Phi <= pi / 2

Length1length1length_1 (output_control) rectangle2.hwidth(-array) → (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

矩形の長辺の半分の長さ

制限: Length1 >= 0.0

Length2length2length_2 (output_control) rectangle2.hheight(-array) → (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

矩形の短辺の半分の長さ

制限: Length2 >= 0.0 && Length2 <= Length1

例🔗

(HDevelop)


read_image(Image,'fabrik')
regiongrowing(Image,Regions,5,5,6,100)
smallest_rectangle2(Regions,Row,Column,Phi,Length1,Length2)
gen_rectangle2(Rectangle,Row,Column,Phi,Length1,Length2)
dev_set_draw ('margin')
dev_display(Rectangle)
(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)\;
}

複雑性🔗

\(F\) を領域の面積で、\(N\) を凸面の輪郭の点をサポートする数であるとす ると、実行時間は \(O(\sqrt{F} + N^2)\) となります。

結果🔗

入力が空でない場合、オペレーター smallest_rectangle2SmallestRectangle2 は、 値 2 (H_MSG_TRUE) を返します。入力が空だった場合(入力画像が得られない場合) の動作は、オペレーター set_system('no_object_result',<Result>) で設定されます。 空の領域の場合(領域が空集合である場合)の動作は、オペレーター set_system('empty_region_result',<Result>) を通して設定さ れます。 必要に応じて、例外が発生します。

他のオペレーターとの組み合わせ🔗

組み合わせ

前処理の候補

thresholdThreshold, regiongrowingRegiongrowing, connectionConnection, runlength_featuresRunlengthFeatures

後処理の候補

disp_rectangle2DispRectangle2, gen_rectangle2GenRectangle2

他の選択候補

elliptic_axisEllipticAxis, smallest_rectangle1SmallestRectangle1

関連項目

smallest_circleSmallestCircle, set_shapeSetShape

モジュール🔗

Foundation