Opencvクラス単純解析:Point

5201 ワード

定義#テイギ#
ポイントの定義は実際には別名にすぎません.以下のように、最終的にはPoint_テンプレートから得られます.
typedef Point_<int> Point2i;
typedef Point_ Point2l;
typedef Point_<float> Point2f;
typedef Point_<double> Point2d;
typedef Point2i Point

以下、Point_テンプレート1を簡単に分析する.Point_は、座標′x′及び′y′によって指定する2 D点のテンプレートクラスである.クラスの例は、C構造体、CvPoint、CvPoint 2 D 32 fと交換可能であり、また、浮動小数点座標から整数座標への変換は四捨五入で行う変換オペレータがあり、通常、変換は各座標に対してこの操作を用いる.上記の宣言にリストされているクラスメンバーに加えて、ポイントについて次の操作を行います.
    pt1 = pt2 + pt3;
    pt1 = pt2 - pt3;
    pt1 = pt2 * a;
    pt1 = a * pt2;
    pt1 = pt2 / a;
    pt1 += pt2;
    pt1 -= pt2;
    pt1 *= a;
    pt1 /= a;
    double value = norm(pt); // L2 norm
    pt1 == pt2;
    pt1 != pt2;

template<typename _Tp> class Point_
{
public:
    typedef _Tp value_type;

    //      
    Point_();
    Point_(_Tp _x, _Tp _y);
    Point_(const Point_& pt);
    Point_(const Size_<_tp>& sz);
    Point_(const Vec<_tp class="hljs-number">2>& v);

    Point_& operator = (const Point_& pt);
    //         
    template<typename _Tp2> operator Point_<_tp2>() const;

    //      C   
    operator Vec<_tp class="hljs-number">2>() const;

    //  
    _Tp dot(const Point_& pt) const;
    //           
    double ddot(const Point_& pt) const;
    //  /   
    double cross(const Point_& pt) const;
    //            
    bool inside(const Rect_<_tp>& r) const;
    _Tp x; //  x  
    _Tp y; //  y  
};

使用例:
...

int main(int argc, char *argv[]){

    Point2f a(0.3f, 0.2f), b(0.1f, 0.4f);
    Point pt = (a + b)*10.f;
    cout << "pt: "<< pt.x << ", " << pt.y << endl;

    double aa = a.ddot(b);  // 0.3 x 0.1 + 0.2 x 0.4 = 0.03 + 0.08 = 0.11
    double bb = a.cross(b); //        

    cout << "aa: "<< aa << endl;
    cout << "bb: "<< bb << endl;
    return 0;
}

出力結果:
pt: 4, 6
aa: 0.11
bb: 0.1