博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OpenCV基本数据类型
阅读量:2225 次
发布时间:2019-05-09

本文共 2069 字,大约阅读时间需要 6 分钟。

Point_

[cpp] 
  1. typedef Point_<int> Point2i;  
  2. typedef Point2i Point;  
  3. typedef Point_<float> Point2f;  
  4. typedef Point_<double> Point2d;  

Point3_

[cpp] 
  1. typedef Point3_<int> Point3i;  
  2. typedef Point3_<float> Point3f;  
  3. typedef Point3_<double> Point3d;  

Size_

[html] 
  1. typedef Size_<int> Size2i;  
  2. typedef Size2i Size;  
  3. typedef Size_<float> Size2f;  

Rect_

[cpp] 
  1. typedef Rect_<int> Rect;  

Matx

[cpp] 
  1. typedef Matx<float,1,2> Matx12f;  
  2. typedef Matx<double,1,2> Matx12d;  
  3. ...  

Vec

[cpp] 
  1. typedef Vec<uchar, 2> Vec2b;  
  2. typedef Vec<short,3> Vec3s;  
  3. typedef Vec<int, 4> Vec4i;  
  4. typddef Vec<float,6> Vec6i;  
  5. ...  

Scalar_

[cpp] 
  1. typedef Scalar_<double> Scalar;  

Range

[cpp] 
  1. class Range  
  2. {  
  3. public:  
  4. ...  
  5. int start, end;  
  6. };  

ex:取A的全部行,和 1到179列
[cpp] 
  1. Mat A = imread("b.jpg", CV_LOAD_IMAGE_COLOR);  
  2. Mat B = A(Range::all(), Range(1, 180));  

Mat

创建复杂的矩阵

[cpp] 
  1. // make a 7x7 complex matrix filled with 1+3j.  
  2. Mat M(7,7,CV_32FC2,Scalar(1,3));  
  3. // and now turn M to a 100x60 15-channel 8-bit matrix.  
  4. // The old content will be deallocated  
  5. M.create(100,60,CV_8UC(15));  
多维数组

[cpp] 
  1. // create a 100x100x100 8-bit array  
  2. int sz[] = {100, 100, 100};  
  3. Mat bigCube(3, sz, CV_8U, Scalar::all(0));  
矩阵行操作

[cpp] 
  1. // add the 5-th row, multiplied by 3 to the 3rd row  
  2. M.row(3) = M.row(3) + M.row(5)*3;  

矩阵列操作

[cpp] 
  1. // now copy the 7-th column to the 1-st column  
  2. // M.col(1) = M.col(7); // this will not work  
  3. Mat M1 = M.col(1);  
  4. M.col(7).copyTo(M1);  

locateROI使用

[cpp] 
  1. Mat A = Mat::eye(10, 10, CV_32S);  
  2. // extracts A columns, 1 (inclusive) to 3 (exclusive).  
  3. Mat B = A(Range::all(), Range(1, 3));  
  4. // extracts B rows, 5 (inclusive) to 9 (exclusive).  
  5. // that is, C ~ A(Range(5, 9), Range(1, 3))  
  6. Mat C = B(Range(5, 9), Range::all());  
  7. Size size; Point ofs;  
  8. C.locateROI(size, ofs);  
  9. // size will be (width=10,height=10) and the ofs will be (x=1, y=5)  

矩阵元素访问:

指针加[ ] 

[cpp] 
  1. int sum = 0;  
  2.     Mat M = Mat::eye(20, 20, CV_8UC1);  
  3.     for (int i=0; i < M.rows; i++)  
  4.     {  
  5.         const uchar* mi = M.ptr<uchar>(i);  
  6.         for (int j=0; j < M.cols; j++)  
  7.         {  
  8.             sum += mi[j];  
  9.         }  
  10.     }  

迭代

[cpp] 
  1. MatConstIterator_<uchar> it = M.begin<uchar>(), it_end = M.end<uchar>();  
  2. for (; it != it_end; ++it)  
  3.     sum += *it;  

转载地址:http://dvofb.baihongyu.com/

你可能感兴趣的文章
用深度神经网络处理NER命名实体识别问题
查看>>
用 RNN 训练语言模型生成文本
查看>>
RNN与机器翻译
查看>>
用 Recursive Neural Networks 得到分析树
查看>>
RNN的高级应用
查看>>
TensorFlow-7-TensorBoard Embedding可视化
查看>>
轻松看懂机器学习十大常用算法
查看>>
一个框架解决几乎所有机器学习问题
查看>>
特征工程怎么做
查看>>
机器学习算法应用中常用技巧-1
查看>>
机器学习算法应用中常用技巧-2
查看>>
通过一个kaggle实例学习解决机器学习问题
查看>>
决策树的python实现
查看>>
Sklearn 快速入门
查看>>
了解 Sklearn 的数据集
查看>>
用ARIMA模型做需求预测
查看>>
推荐系统
查看>>
TensorFlow-11-策略网络
查看>>
浅谈 GBDT
查看>>
如何选择优化器 optimizer
查看>>