博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
opencv之mat元素访问
阅读量:6922 次
发布时间:2019-06-27

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

  • 单通道mat元素访问:使用 img.at<float>(row,col)
1 #include 
2 #include
3 #include
4 #include
5 #include
6 7 using namespace std; 8 using namespace cv; 9 int main()10 {11 Mat img(3, 4, CV_32FC1, Scalar_
(12.625));12 13 cout<
<
< img.cols; col++)29 {30 cout<
(row,col)<<" ";31 }32 cout<

备注1:创建图像Mat时候可以用到

Mat img(3, 4, CV_32FC1, Scalar_
(12.625));3乘4的图片~Mat_
对应的是CV_8U,Mat_
对应的是CV_8S,Mat_
对应的是CV_32S,Mat_
对应的是CV_32F,Mat_
对应的是CV_64F,对应的数据深度如下: Scalar_<**>的**处填上对应的类型!! CV_8U - 8-bit unsigned integers ( 0..255 ) CV_8S - 8-bit signed integers ( -128..127 ) CV_16U - 16-bit unsigned integers ( 0..65535 ) CV_16S - 16-bit signed integers ( -32768..32767 ) CV_32S - 32-bit signed integers ( -2147483648..2147483647 ) CV_32F - 32-bit ?oating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN ) CV_64F - 64-bit ?oating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN )

备注2

因为单通道,所以上例访问元素时候对应写成
img.at
(row,col)
...

 

  • 多通道mat元素访问:
1 #include 
2 #include
3 #include
4 #include
5 #include
6 7 using namespace std; 8 using namespace cv; 9 int main()10 {11 Mat img(3, 4, CV_64FC2, Scalar_
(12.625,3.141592653));12 //Mat_(Vec)13 cout<
<
< img.cols; col++)28 {29 cout<
(row,col)[0]<<" "<
(row,col)[1]<<"\t";30 }31 cout<

 

 

备注3:创建图像Mat时候,注意点同上~

 

备注4:使用at时img.at<**>(row,col)的**处对应选项~

typedef Vec
Vec2b;typedef Vec
Vec3b;typedef Vec
Vec4b;typedef Vec
Vec2s;typedef Vec
Vec3s;typedef Vec
Vec4s;typedef Vec
Vec2w;typedef Vec
Vec3w;typedef Vec
Vec4w;typedef Vec
Vec2i;typedef Vec
Vec3i;typedef Vec
Vec4i;typedef Vec
Vec6i;typedef Vec
Vec8i;typedef Vec
Vec2f;typedef Vec
Vec3f;typedef Vec
Vec4f;typedef Vec
Vec6f;typedef Vec
Vec2d;typedef Vec
Vec3d;typedef Vec
Vec4d;typedef Vec
Vec6d;

 题外话:

我一次Mat img(3,4,CV8S,~)....而访问时候,用的img.at<int>(i,j)出现访存错误,我的本意是用CV32S,不对应就会出现访存错误。。。

转载于:https://www.cnblogs.com/LzKlyhPorter/p/4610247.html

你可能感兴趣的文章
javascript--运算符
查看>>
FPGA中亚稳态——让你无处可逃
查看>>
带你网络入门
查看>>
JMeter 线程组之Stepping Thread Group插件
查看>>
ETL过程
查看>>
jquery的性能优化
查看>>
谈谈持续集成,持续交付,持续部署之间的区别
查看>>
UICollectionView 头视图、 尾视图以及Cell自定制
查看>>
Centos中yum方式安装java
查看>>
for loop
查看>>
Linux常用命令详解(一) -- 处理目录常用命令
查看>>
指针变量的星号是靠近变量名还是靠近类型
查看>>
在线程中执行代码
查看>>
POJ 2299 Ultra-QuickSort【树状数组+离散化】
查看>>
神经网络损失函数公式解读
查看>>
Android Studio插件:PlantUML
查看>>
Nginx开发从入门到精通
查看>>
Jenkins配置手动发版
查看>>
横向图片轮播(如果一个项目里面只需用这一次,可以用这个插件,多次则不建议使用)...
查看>>
计算机存储单位KB,MB,GB,TB,PB,EB,ZB,YB后面是什么?
查看>>