OpenCV 5.0.0
Open Source Computer Vision
読み込み中...
検索中...
見つかりません
🤖 AIによる機械翻訳(非公式) — これは OpenCV 5.0.0 公式リファレンス(英語)を AI (Claude) で自動翻訳したものです。訳に誤りを含む場合があります。正確な情報は 公式英語版(原文) を参照してください。
cv::Rect_< _Tp > クラステンプレート

2次元矩形のためのテンプレートクラス。 続き...

#include <opencv2/core/types.hpp>

Collaboration diagram for cv::Rect_< _Tp >:

公開型

typedef _Tp value_type
 

公開メンバ関数

 Rect_ ()
 デフォルトコンストラクタ
 
 Rect_ (_Tp _x, _Tp _y, _Tp _width, _Tp _height)
 
 Rect_ (const Point_< _Tp > &org, const Size_< _Tp > &sz)
 
 Rect_ (const Point_< _Tp > &pt1, const Point_< _Tp > &pt2)
 
 Rect_ (const Rect_ &r)=default
 
 Rect_ (Rect_ &&r) CV_NOEXCEPT=default
 
_Tp area () const
 矩形の面積(width*height)
 
Point_< _Tpbr () const
 右下のコーナー
 
template<typename _Tp2 >
bool contains (const Point_< _Tp2 > &pt) const
 矩形が点を含むかどうかを調べる
 
bool empty () const
 空であれば true
 
template<typename _Tp2 >
 operator Rect_< _Tp2 > () const
 別のデータ型への変換。
 
Rect_operator= (const Rect_ &r)=default
 
Rect_operator= (Rect_ &&r) CV_NOEXCEPT=default
 
Size_< _Tpsize () const
 矩形のサイズ(width, height)
 
Point_< _Tptl () const
 左上のコーナー
 

公開変数類

_Tp height
 矩形の高さ
 
_Tp width
 矩形の幅
 
_Tp x
 左上のコーナーのx座標
 
_Tp y
 左上のコーナーのy座標
 

詳細説明

template<typename _Tp>
class cv::Rect_< _Tp >

2次元矩形のためのテンプレートクラス。

以下のパラメータで記述される:

  • 左上のコーナーの座標。これはOpenCVにおける Rect_::xRect_::y のデフォルトの解釈である。ただし、独自のアルゴリズムではxとyを左下のコーナーから数えてもよい。
  • 矩形の幅と高さ。

OpenCVでは通常、矩形の上端と左端の境界は含まれるが、右端と下端の境界は含まれないと仮定する。例えば、メソッド Rect_::contains は次の場合に true を返す

\[x \leq pt.x < x+width, y \leq pt.y < y+height\]

OpenCVでは画像ROI上のほぼすべてのループ(ROIは Rect_<int> で指定される)は次のように実装される:

for(int y = roi.y; y < roi.y + roi.height; y++)
for(int x = roi.x; x < roi.x + roi.width; x++)
{
// ...
}
_Tp x
x coordinate of the top-left corner
Definition types.hpp:490
_Tp y
y coordinate of the top-left corner
Definition types.hpp:491

クラスメンバに加えて、矩形に対する以下の演算が実装されている:

  • \(\texttt{rect} = \texttt{rect} \pm \texttt{point}\) (矩形を一定のオフセットだけシフトする)
  • \(\texttt{rect} = \texttt{rect} \pm \texttt{size}\) (矩形を一定量だけ拡大または縮小する)
  • rect += point, rect -= point, rect += size, rect -= size (複合代入演算)
  • rect = rect1 & rect2 (矩形の交差)
  • rect = rect1 | rect2 (rect1とrect2を含む最小面積の矩形)
  • rect &= rect1, rect |= rect1 (および対応する複合代入演算)
  • rect == rect1, rect != rect1 (矩形の比較)

これは矩形に対する半順序を確立する方法の一例である(rect1 \(\subseteq\) rect2):

template<typename _Tp> inline bool
operator <= (const Rect_<_Tp>& r1, const Rect_<_Tp>& r2)
{
return (r1 & r2) == r1;
}
Template class for 2D rectangles.
Definition types.hpp:447
cv::GMat operator<=(const cv::GMat &lhs, const cv::GMat &rhs)

利便性のため、Rect_<> のエイリアスが利用できる: cv::Rect

samples/cpp/floodfill.cpp, samples/cpp/grabcut.cpp, samples/cpp/snippets/camshiftdemo.cpp, samples/cpp/snippets/falsecolor.cpp, samples/cpp/snippets/mask_tmpl.cpp, samples/cpp/snippets/stitching.cpp, samples/cpp/stitching_detailed.cpp, samples/dnn/classification.cpp, samples/dnn/object_detection.cpp, samples/dnn/segmentation.cpp, samples/facedetect.cpp, および samples/peopledetect.cpp

型定義メンバ詳解

◆ value_type

template<typename _Tp >
_Tp cv::Rect_< _Tp >::value_type

構築子と解体子の詳解

◆ Rect_() [1/6]

template<typename _Tp >
cv::Rect_< _Tp >::Rect_ ( )

デフォルトコンストラクタ

◆ Rect_() [2/6]

template<typename _Tp >
cv::Rect_< _Tp >::Rect_ ( _Tp _x,
_Tp _y,
_Tp _width,
_Tp _height )

◆ Rect_() [3/6]

template<typename _Tp >
cv::Rect_< _Tp >::Rect_ ( const Rect_< _Tp > & r)
default

◆ Rect_() [4/6]

template<typename _Tp >
cv::Rect_< _Tp >::Rect_ ( Rect_< _Tp > && r)
default

◆ Rect_() [5/6]

template<typename _Tp >
cv::Rect_< _Tp >::Rect_ ( const Point_< _Tp > & org,
const Size_< _Tp > & sz )

◆ Rect_() [6/6]

template<typename _Tp >
cv::Rect_< _Tp >::Rect_ ( const Point_< _Tp > & pt1,
const Point_< _Tp > & pt2 )

メンバ関数詳解

◆ area()

template<typename _Tp >
_Tp cv::Rect_< _Tp >::area ( ) const

矩形の面積(width*height)

samples/cpp/snippets/camshiftdemo.cpp.

◆ br()

template<typename _Tp >
Point_< _Tp > cv::Rect_< _Tp >::br ( ) const

右下のコーナー

samples/peopledetect.cpp.

◆ contains()

template<typename _Tp >
template<typename _Tp2 >
bool cv::Rect_< _Tp >::contains ( const Point_< _Tp2 > & pt) const
inline

矩形が点を含むかどうかを調べる

警告
OpenCV 4.11.0以降、Rect.contains()cv::Point2f / cv::Point2d の点で呼び出す場合、点は int に変換・丸めされない。
Rect_<int> r(0,0,500,500); Point_<float> pt(250.0f, 499.9f);
r.contains(pt) は false を返す。(OpenCV 4.10.0以前)
r.contains(pt) は true を返す。(OpenCV 4.11.0以降)
座標xとyで指定される2次元点のためのテンプレートクラス。
Definition types.hpp:163

◆ empty()

template<typename _Tp >
bool cv::Rect_< _Tp >::empty ( ) const

空であれば true

◆ operator Rect_< _Tp2 >()

template<typename _Tp >
template<typename _Tp2 >
cv::Rect_< _Tp >::operator Rect_< _Tp2 > ( ) const

別のデータ型への変換。

◆ operator=() [1/2]

template<typename _Tp >
Rect_ & cv::Rect_< _Tp >::operator= ( const Rect_< _Tp > & r)
default

◆ operator=() [2/2]

template<typename _Tp >
Rect_ & cv::Rect_< _Tp >::operator= ( Rect_< _Tp > && r)
default

◆ size()

template<typename _Tp >
Size_< _Tp > cv::Rect_< _Tp >::size ( ) const

矩形のサイズ(width, height)

samples/cpp/stitching_detailed.cpp.

◆ tl()

template<typename _Tp >
Point_< _Tp > cv::Rect_< _Tp >::tl ( ) const

左上のコーナー

samples/cpp/stitching_detailed.cpp, および samples/peopledetect.cpp

メンバ変数詳解

◆ height

◆ width

◆ x

◆ y


このクラス詳解は次のファイルから抽出されました: