国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

操作像素------OpenCV2.4.11

2019-11-08 02:18:25
字體:
來源:轉載
供稿:網友

操作像素------OpenCV2.4.11

1、Mat類

Mat是一個n維矩陣類,聲明在<opencv2/core/core.hpp>中1711-2034行。

class CV_EXPORTS Mat{public:    //! default constructor    Mat();    //! constructs 2D matrix of the specified size and type    // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)    // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)    Mat(int rows, int cols, int type);    Mat(Size size, int type);    //! constucts 2D matrix and fills it with the specified value _s.    Mat(int rows, int cols, int type, const Scalar& s);    Mat(Size size, int type, const Scalar& s);	........    //! destructor - calls release()    ~Mat();    //! assignment Operators    Mat& operator = (const Mat& m);
      ............
     //! the same as above, with the pointer dereferencing    template<typename _Tp> _Tp& at(int i0=0);    template<typename _Tp> const _Tp& at(int i0=0) const;    template<typename _Tp> _Tp& at(int i0, int i1);    template<typename _Tp> const _Tp& at(int i0, int i1) const;    template<typename _Tp> _Tp& at(int i0, int i1, int i2);    template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const;    template<typename _Tp> _Tp& at(const int* idx);    template<typename _Tp> const _Tp& at(const int* idx) const;    template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);    template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;    //! special versions for 2D arrays (especially convenient for referencing image pixels)    template<typename _Tp> _Tp& at(Point pt);    template<typename _Tp> const _Tp& at(Point pt) const;
    ............    int flags;    //! the matrix dimensionality, >= 2    int dims;    //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions    int rows, cols;    //! pointer to the data    uchar* data;    ..............};

2、Scalar類

template<typename _Tp> class Scalar_ : public Vec<_Tp, 4>{public:    //! various constructors    Scalar_();    Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);    Scalar_(const CvScalar& s);    Scalar_(_Tp v0);    //! returns a scalar with all elements set to v0    static Scalar_<_Tp> all(_Tp v0);    //! conversion to the old-style CvScalar    operator CvScalar() const;    //! conversion to another data type    template<typename T2> operator Scalar_<T2>() const;    //! per-element PRoduct    Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;    // returns (v0, -v1, -v2, -v3)    Scalar_<_Tp> conj() const;    // returns true iff v1 == v2 == v3 == 0    bool isReal() const;};typedef Scalar_<double> Scalar;
template<typename _Tp, int cn> class Vec : public Matx<_Tp, cn, 1>{public:    typedef _Tp value_type;    enum { depth = DataDepth<_Tp>::value, channels = cn, type = CV_MAKETYPE(depth, channels) };    //! default constructor    Vec();      .........
    template<typename _T2> Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp);};
template<typename _Tp, int m, int n> class Matx{public:    typedef _Tp value_type;    typedef Matx<_Tp, (m < n ? m : n), 1> diag_type;    typedef Matx<_Tp, m, n> mat_type;    enum { depth = DataDepth<_Tp>::value, rows = m, cols = n, channels = rows*cols,           type = CV_MAKETYPE(depth, channels) };    //! default constructor    Matx();      .........
    //! extract the matrix row    Matx<_Tp, 1, n> row(int i) const;    //! extract the matrix column    Matx<_Tp, m, 1> col(int i) const;    _Tp val[m*n]; //< matrix elements};

3、獲取像素的亮度值

(1)獲取單通道灰度圖(類型 8UC1)的(x, y)位置處的像素值:

	Scalar intensity = img.at<uchar>(x, y);

intensity.val[0] 中保存從0到255的值

(2)獲取3通道圖像的(x, y)位置處的像素值:

	Vec3b intensity = img.at<Vec3b>(x, y);	uchar blue = intensity.val[0];	uchar green = intensity.val[1];	uchar red = intensity.val[2];

(3)處理浮點圖像(例如通對一個3通道圖像進行Sobel運算得到的浮點圖像):

	Vec3f intensity = img.at<Vec3f>(x, y);	float blue = intensity.val[0];	float green = intensity.val[1];	float red = intensity.val[2];

(4)像素值的修改:

	img.at<uchar>(x, y) = 128;

示例


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汝阳县| 时尚| 台江县| 突泉县| 从化市| 交城县| 绥滨县| 沁水县| 安庆市| 犍为县| 延吉市| 万载县| 白山市| 丰原市| 喀什市| 措美县| 铜川市| 弥渡县| 桂阳县| 滦南县| 汨罗市| 白朗县| 苗栗市| 台中县| 镇巴县| 乐山市| 类乌齐县| 秀山| 老河口市| 轮台县| 南安市| 大英县| 上饶市| 广河县| 天镇县| 泽州县| 富宁县| 安塞县| 陆良县| 公安县| 观塘区|