Skip to content

get_rectangle_poseGetRectanglePoseGetRectanglePoseget_rectangle_poseT_get_rectangle_pose🔗

説明🔗

get_rectangle_poseGetRectanglePoseGetRectanglePoseget_rectangle_poseT_get_rectangle_pose — 2次元画像平面に対する投影から矩形の3次元位置を推定する。

書式🔗

get_rectangle_pose( xld Contour, campar CameraParam, number Width, number Height, string WeightingMode, number ClippingFactor, out pose Pose, out number CovPose, out number Error )void GetRectanglePose( const HObject& Contour, const HTuple& CameraParam, const HTuple& Width, const HTuple& Height, const HTuple& WeightingMode, const HTuple& ClippingFactor, HTuple* Pose, HTuple* CovPose, HTuple* Error )static void HOperatorSet.GetRectanglePose( HObject contour, HTuple cameraParam, HTuple width, HTuple height, HTuple weightingMode, HTuple clippingFactor, out HTuple pose, out HTuple covPose, out HTuple error )def get_rectangle_pose( contour: HObject, camera_param: Sequence[Union[int, float, str]], width: MaybeSequence[float], height: MaybeSequence[float], weighting_mode: str, clipping_factor: float ) -> Tuple[Sequence[Union[int, float]], Sequence[float], Sequence[float]]

Herror T_get_rectangle_pose( const Hobject Contour, const Htuple CameraParam, const Htuple Width, const Htuple Height, const Htuple WeightingMode, const Htuple ClippingFactor, Htuple* Pose, Htuple* CovPose, Htuple* Error )

HPoseArray HXLD::GetRectanglePose( const HCamPar& CameraParam, const HTuple& Width, const HTuple& Height, const HString& WeightingMode, double ClippingFactor, HTuple* CovPose, HTuple* Error ) const

HPose HXLD::GetRectanglePose( const HCamPar& CameraParam, double Width, double Height, const HString& WeightingMode, double ClippingFactor, HTuple* CovPose, HTuple* Error ) const

HPose HXLD::GetRectanglePose( const HCamPar& CameraParam, double Width, double Height, const char* WeightingMode, double ClippingFactor, HTuple* CovPose, HTuple* Error ) const

HPose HXLD::GetRectanglePose( const HCamPar& CameraParam, double Width, double Height, const wchar_t* WeightingMode, double ClippingFactor, HTuple* CovPose, HTuple* Error ) const (Windows only)

HPoseArray HCamPar::GetRectanglePose( const HXLD& Contour, const HTuple& Width, const HTuple& Height, const HString& WeightingMode, double ClippingFactor, HTuple* CovPose, HTuple* Error ) const

HPose HCamPar::GetRectanglePose( const HXLD& Contour, double Width, double Height, const HString& WeightingMode, double ClippingFactor, HTuple* CovPose, HTuple* Error ) const

HPose HCamPar::GetRectanglePose( const HXLD& Contour, double Width, double Height, const char* WeightingMode, double ClippingFactor, HTuple* CovPose, HTuple* Error ) const

HPose HCamPar::GetRectanglePose( const HXLD& Contour, double Width, double Height, const wchar_t* WeightingMode, double ClippingFactor, HTuple* CovPose, HTuple* Error ) const (Windows only)

HPose[] HXLD.GetRectanglePose( HCamPar cameraParam, HTuple width, HTuple height, string weightingMode, double clippingFactor, out HTuple covPose, out HTuple error )

HPose HXLD.GetRectanglePose( HCamPar cameraParam, double width, double height, string weightingMode, double clippingFactor, out HTuple covPose, out HTuple error )

HPose[] HCamPar.GetRectanglePose( HXLD contour, HTuple width, HTuple height, string weightingMode, double clippingFactor, out HTuple covPose, out HTuple error )

HPose HCamPar.GetRectanglePose( HXLD contour, double width, double height, string weightingMode, double clippingFactor, out HTuple covPose, out HTuple error )

説明🔗

空間の矩形は、画像に一般の四角形として投影されます。 get_rectangle_poseGetRectanglePose はこの投影 (Contourcontourcontour) から矩形の位置 Poseposepose を決めます。

アルゴリズムは以下の通りです。まず、Contourcontourcontour は、4つ線分に 分割され、その交点はXLDオブジェクトの角とみなされます。内部カメラ パラメーター (CameraParamcameraParamcamera_param) を持つ角とともに、メートル単位の 矩形サイズ (Widthwidthwidth, Heightheightheight) を矩形位置の初期解として 使用します。それから、最後の Poseposepose が、画像内の矩形の再投影から XLDオブジェクト点の幾何学的距離を最小化し、非線形の最適化を行います。

オペレーターはエリアスキャンのピンホール(投影)カメラのみサポートします。 CameraParamcameraParamcamera_param がラインスキャンカメラやテレセントリックカメラを指定すると、 エラーを返します。(Calibration も参照してください。)

Widthwidthwidth と Heightheightheight が、それぞれの座標系で、\(x\) と \(y\) 次元の 矩形サイズを指定します。この座標系の基点が矩形の中心となります。\(z\) 軸は カメラから遠ざかる向きを指します。

引数 WeightingModeweightingModeweighting_mode と ClippingFactorclippingFactorclipping_factor がアルゴリズムの 外れ値の影響を軽減するために使用することができます。 WeightingModeweightingModeweighting_mode が、'tukey'"tukey" もしくは 'huber'"huber" に設定されると、 XLDオブジェクトの点が、それぞれ Tukey もしくは Huber の近似に基づき 重みが加えられます。このような場合、ロバストエラー統計は、外れ値を除いた 再投影された矩形から、XLDオブジェクト点の距離の標準偏差を推定するために 使用することができます。パラメーター ClippingFactorclippingFactorclipping_factor (標準偏差の倍率) が、減衰量を制御します。つまり、ClippingFactorclippingFactorclipping_factor 小さな値を選択すると、より外れ値を検出します。fit_line_contour_xldFitLineContourXld で、各重みモードのプロパティについて確認してください。 fit_line_contour_xldFitLineContourXld とは違い、矩形位置の推定する場合、 Huber の近似を推奨します。

出力🔗

結果の Poseposepose は code 0 であり (create_poseCreatePose を参照して ください。)、矩形の中心の位置を表します。以下の方法で、矩形の角の位置を 計算することができます:

 
set_origin_pose(Pose, Width/2, -Height/2, 0, PoseCorner1)SetOriginPose(Pose, Width/2, -Height/2, 0, PoseCorner1)SetOriginPose(Pose, Width/2, -Height/2, 0, PoseCorner1)set_origin_pose(Pose, Width/2, -Height/2, 0, PoseCorner1)set_origin_pose(Pose, Width/2, -Height/2, 0, PoseCorner1)
set_origin_pose(Pose, Width/2, Height/2, 0, PoseCorner2)SetOriginPose(Pose, Width/2, Height/2, 0, PoseCorner2)SetOriginPose(Pose, Width/2, Height/2, 0, PoseCorner2)set_origin_pose(Pose, Width/2, Height/2, 0, PoseCorner2)set_origin_pose(Pose, Width/2, Height/2, 0, PoseCorner2)
set_origin_pose(Pose, -Width/2, Height/2, 0, PoseCorner3)SetOriginPose(Pose, -Width/2, Height/2, 0, PoseCorner3)SetOriginPose(Pose, -Width/2, Height/2, 0, PoseCorner3)set_origin_pose(Pose, -Width/2, Height/2, 0, PoseCorner3)set_origin_pose(Pose, -Width/2, Height/2, 0, PoseCorner3)
set_origin_pose(Pose, -Width/2, -Height/2, 0, PoseCorner4)SetOriginPose(Pose, -Width/2, -Height/2, 0, PoseCorner4)SetOriginPose(Pose, -Width/2, -Height/2, 0, PoseCorner4)set_origin_pose(Pose, -Width/2, -Height/2, 0, PoseCorner4)set_origin_pose(Pose, -Width/2, -Height/2, 0, PoseCorner4)

矩形は、\(x\)、\(y\) と \(z\) 軸に対して左右対称であり、同一のXLD オブジェクトが、4つの異なる位置で矩形を表現することができます。 Poseposepose の角度は範囲 \([-90; 90]\) 度で正規化され、残り 4つの 可能性のある位置については、対応する軸の周りで、反転を合成することで 計算します:

 
* 注意: 以下のコードはget_rectangle_poseから返されるposeが
* code 0である場合のみ動作します。
*
* z軸周りの反転
PoseFlippedZ := Pose
PoseFlippedZ[5] := PoseFlippedZ[5]+180
* y軸周りの反転
PoseFlippedY := Pose
PoseFlippedY[4] := PoseFlippedY[4]+180
PoseFlippedY[5] := -PoseFlippedY[5]
* x軸周りの反転
PoseFlippedX := Pose
PoseFlippedX[3] := PoseFlippedX[3]+180
PoseFlippedX[4] := -PoseFlippedX[4]
PoseFlippedX[5] := -PoseFlippedX[5]

矩形が正方形 (Widthwidthwidth == Heightheightheight) ならば、選択位置の数が 8 になることに注意してください。

1つ以上のXLDオブジェクトが Contourcontourcontour に渡されると、 Widthwidthwidth と Heightheightheight の両方に対応する tuple の値が 同時に提供される必要があります。1つの値が 3つの引数にそれぞれ 与えられると、この値はそれぞれ処理されたXLDオブジェクトに適応されます。 位置は、各処理されたXLDオブジェクトを推定し、すべての位置が Poseposepose に連結されます。(以下のサンプルを参照してください。)

位置の精度🔗

推定される位置の精度は以下の 3 つの要因に依存します。

正確な位置を推定するために、考慮すべき点が 3 つあります。

比率 Widthwidthwidth/Heightheightheightを満たさなければ なりません。

\[\begin{eqnarray*}\frac{1}{3} < \textrm{Width}/\textrm{Height} < 3\end{eqnarray*}\]

この基準から算出される矩形オブジェクトの場合、その長い辺がその位置の 決定を促します。これは、長い矩形軸の周りの角度を推定するにあたり、 不安定な要因となります。極端なケースでは、1 つの次元が 0 であり、 矩形は実際には線分であり、その位置は推定することができません。

次に、XLDオブジェクトの各辺の長さは少なくとも 20 ピクセルは あることが望ましいです。輪郭の1 辺が 5 ピクセル以下の長さの場合、 エラーが返されます。

3番目に、XLDオブジェクトが 投影的にゆがんで見える ほど、 アルゴリズムは安定して動作します。そのため、画像平面への矩形の 傾き位置 w.r.t は正確に推定することができます。一方、カメラ画像 平面への矩形平行位置は、不安的になります。これについては、次の段落で 説明します。投影歪みを際立たせる為の経験則としては、カメラ座標系の \(x\) と \(y\) 次元でのサイズにおける矩形のサイズが、カメラからの \(z\) 方向の 距離の \(1/10th\) 以下にならないようにするというものがあります。

get_rectangle_poseGetRectanglePose は、2つの方法を推定された Poseposepose の 精度に適用します。Errorerrorerror はXLDオブジェクトの点と画像上に再投影 されたモデル化矩形間の平均ピクセルエラーです。Errorerrorerror が 0.5 を 変えた場合、アルゴリズムは適切に収束しないことを示し、結果として生じる Poseposepose は使用することができません CovPosecovPosecov_pose は最初の 6 エントリの Poseposepose の 6×6 の共分散行列を表す 36 のエントリを含みます。より長い矩形の軸について、上記に述べた場合の 角度の不安定性は、分散の絶対値と \(x\) 軸と \(y\) 軸 (CovPosecovPosecov_pose[21], CovPosecovPosecov_pose[28], CovPosecovPosecov_pose[22] == CovPosecovPosecov_pose[27]) の 周りでの回転の共分散が、0.05 を超えないことを確認することによって、 検出されます。さらに、異常に増加した共分散値や、特に分散 (指数 0, 7, 14, 21, 28 と 35 による CovPosecovPosecov_pose の対角線上の6 つの値)は、 Poseposepose の質の悪さを示します。

実行情報🔗

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

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

  • 並列演算処理には未対応

パラメーター🔗

Contourcontourcontour (input_object) xld(-array) → objectHObjectHXLDHObjectHobject

検出されるXLDオブジェクト

CameraParamcameraParamcamera_param (input_control) campar → (real / integer / string)HTuple (double / Hlong / HString)HCamPar, HTuple (double / int / long / string)Sequence[Union[int, float, str]]Htuple (double / Hlong / char*)

内部カメラパラメーター

Widthwidthwidth (input_control) number(-array) → (real)HTuple (double)HTuple (double)MaybeSequence[float]Htuple (double)

矩形の幅(メートル単位)

制限: Width > 0

Heightheightheight (input_control) number(-array) → (real)HTuple (double)HTuple (double)MaybeSequence[float]Htuple (double)

矩形の高さ(メートル単位)

制限: Height > 0

WeightingModeweightingModeweighting_mode (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

最適化フェーズの重みモード

初期値: 'nonweighted'"nonweighted"
値のリスト: 'huber', 'nonweighted', 'tukey'"huber", "nonweighted", "tukey"

ClippingFactorclippingFactorclipping_factor (input_control) number → (real)HTuple (double)HTuple (double)floatHtuple (double)

外れ値を削除する切り取り要因 (通常: 'huber'"huber"の場合 1.01.0 であり、 'tukey'"tukey"の場合 3.03.0)

初期値: 2.02.0
推奨値: 1.0, 1.5, 2.0, 2.5, 3.01.0, 1.5, 2.0, 2.5, 3.0
制限: ClippingFactor > 0

Poseposepose (output_control) pose(-array) → (real / integer)HTuple (double / Hlong)HPose, HTuple (double / int / long)Sequence[Union[int, float]]Htuple (double / Hlong)

矩形の3次元位置

要素数: Pose == 7*Contour

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

位置の値の共分散

要素数: CovPose == 36*Contour

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

最終誤差の実効値

要素数: Error == Contour

例🔗

(HDevelop)


* Process an image with several rectangles of the same size appearing
* as light objects.
RectWidth := 0.04
RectHeight := 0.025
gen_cam_par_area_scan_division (0.014, 830, 4.58e-006, 4.65e-006, \
                                509, 488, 800, 800, CameraParam)
read_image (Image, 'barcode/ean13/tea_box_01')
* Find light objects in the image.
mean_image (Image, ImageMean, 201, 201)
dyn_threshold (Image, ImageMean, Region, 5, 'light')
* Fill gaps in the objects.
fill_up (Region, RegionFillUp)
* Extract rectangular contours.
connection (RegionFillUp, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, ['area','rectangularity'], \
              'and', [50000,0.9], [640000,1])
boundary (SelectedRegions, RegionBorder, 'inner')
dilation_circle (RegionBorder, RegionDilation, 3.5)
* NOTE: for a real application, this step might require some additional
*       pre- or postprocessing.
reduce_domain (Image, RegionDilation, ImageReduced)
edges_sub_pix (ImageReduced, Edges, 'canny', 1, 20, 40)
* Get the pose of all contours found.
get_rectangle_pose (Edges, CameraParam, RectWidth, RectHeight, 'huber', 2, \
                    Poses, CovPose, Error)
NumPoses := |Poses|/7
for I := 0 to NumPoses-1 by 1
  Pose := Poses[I*7:I*7+6]
  * Use the Pose here.
  * ...
endfor

結果🔗

すべてのパラメーターが正しく、矩形の位置が正常に決定すると、 get_rectangle_poseGetRectanglePose は、値 2 (H_MSG_TRUE) を返します。与えられた XLDオブジェクトが、四角形 get_rectangle_poseGetRectanglePose として分割する ことができないならば、H_ERR_FIT_QUADRANGLE を返します。必要であれば、 例外が発生します。

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

組み合わせ

前処理の候補

edges_sub_pixEdgesSubPix

関連項目

get_circle_poseGetCirclePose, set_origin_poseSetOriginPose, camera_calibrationCameraCalibration

参考文献🔗

G.Schweighofer and A.Pinz: ``Robust Pose Estimation from a Planar Target’‘; Transactions on Pattern Analysis and Machine Intelligence (PAMI), 28(12):2024-2030, 2006

モジュール🔗

3D Metrology