opencv入门

  opencv是一个成熟的,比较全面的库,之前使用python时有接触过,属于高层调用,对于底层的实现一无所有,现在要查看opencv的原理了。 /usr/local/include/opencv4/opencv2/cvconfig.h,这是一个安装命令行的一个输出,可以看见opencv2和opencv4的关系非常紧密。

  opencv中最重要的概率应该是Mat,可以解释为图像容器。我们最常接触到的图像应该是Image文件,以及numpy中的张量,这些都有矩阵的影子。其实opencv作为一个指明和开放的库,其实有一些samples,很适合入门练手用。 

  使用xcode查看opencv的源码,查找相关类的定义还是很方便的,比如之前使用的Rect类:

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

    //! default constructor
    Rect_();
    Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
    Rect_(const Rect_& r);
    Rect_(Rect_&& r) CV_NOEXCEPT;
    Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
    Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);

    Rect_& operator = ( const Rect_& r );
    Rect_& operator = ( Rect_&& r ) CV_NOEXCEPT; // 移动赋值操作符,&&将亡值。c++11
    //! the top-left corner
    Point_<_Tp> tl() const;
    //! the bottom-right corner
    Point_<_Tp> br() const;

    //! size (width, height) of the rectangle
    Size_<_Tp> size() const;
    //! area (width*height) of the rectangle
    _Tp area() const;
    //! true if empty
    bool empty() const;

    //! conversion to another data type
    template<typename _Tp2> operator Rect_<_Tp2>() const;

    //! checks whether the rectangle contains the point
    bool contains(const Point_<_Tp>& pt) const;

    _Tp x; //!< x coordinate of the top-left corner
    _Tp y; //!< y coordinate of the top-left corner
    _Tp width; //!< width of the rectangle
    _Tp height; //!< height of the rectangle
};

typedef Rect_<int> Rect2i;

typedef Rect_<float> Rect2f;

typedef Rect_<double> Rect2d;

typedef Rect2i Rect;

  从这些的代码片段中也可以看到一些常见的c++代码风格。模板类,typedef的使用等,以及c++11中移动语义的使用。还可以看到Size_和Point_也是模板类,Rect_提供的实例方法不多。

参考资料:opencv中文社区:http://wiki.opencv.org.cn/index.php

     eclispe配置参考博文:https://blog.csdn.net/sjtu_edu_cn/article/details/49994287

     xcode配置参考博文:https://blog.csdn.net/u012905879/article/details/52808745

     mat定义的代码:https://github.com/opencv/opencv/blob/master/modules/core/src/matrix.cpp

 

原文地址:https://www.cnblogs.com/Robin008/p/12127885.html