码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV Mat 类型定义和赋值

时间:2014-09-06 08:35:12      阅读:981      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   div   sp   log   html   

详细介绍请参考官网相关部分链接:http://docs.opencv.org/doc/tutorials/core/mat_the_basic_image_container/mat_the_basic_image_container.html

1.一般的Mat定义方法:cv::Mat M(height,width,<Type>),例:

  cv::Mat M(480,640,CV_8UC3); 表示定义了一个480行640列的矩阵,矩阵的每个单元的由三个(C3:3 Channel)8位无符号整形(U Unsigned U8 8位)构成。

2.将已有数组赋给Mat矩阵的方法:

  cv::Mat M = cv::Mat(height,width,<Type>,data),例:

    float K[3][3] = {fc[0], 0, cc[0], 0, fc[1], cc[1], 0, 0, 1};    //摄像机内参数矩阵K
    cv::Mat mK = cv::Mat(3,3,CV_32FC1,K);    //内参数K Mat类型变量

3.类似matlab:zeros(),ones(),eyes()的初始化方法:

  cv::Mat M = cv::Mat::eye(height,width,<Type>)

  cv::Mat M = cv::Mat::ones(height,width,<Type>)

  cv::Mat M = cv::Mat::zeros(height,width,<Type>)

4.对于小矩阵给定数值的赋值方法:

  cv::Mat M = (cv::Mat_<Type>(height,width) << 0,-1,0,-1,5,-1,0,-1,0)

得到以下矩阵 M= 

        [0  -1  0

         -1  5  -1

         0  -1  0]

 

OpenCV Mat 类型定义和赋值

标签:style   blog   http   color   os   div   sp   log   html   

原文地址:http://www.cnblogs.com/xzd1575/p/3959113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!