博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
opencv Mat.at
阅读量:6994 次
发布时间:2019-06-27

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

opencv c++ mat获取像素及像素赋值

For accessing pixel's channel value :

for (int i = 0; i < image.cols; i++) {    for (int j = 0; j < image.rows; j++) {        Vec3b intensity = image.at
(j, i); for(int k = 0; k < image.channels(); k++) { uchar col = intensity.val[k]; } }}

 

For changing a pixel value of a channel :

uchar pixValue;for (int i = 0; i < image.cols; i++) {    for (int j = 0; j < image.rows; j++) {        Vec3b &intensity = image.at
(j, i); for(int k = 0; k < image.channels(); k++) { // calculate pixValue intensity.val[k] = pixValue; } }}

附录:引用

http://www.cppblog.com/gtwdaizi/articles/38521.html

C++返回引用类型

A& a(){ return *this;} 就生成了一个固定地址的指针,并把指针带给你
但A a() { return *this;}会生成一个临时对象变量,并把这个临时变量给你
这样就多了一步操作
当返回一个变量时,会产生拷贝。当返回一个引用时,不会发生拷贝,你可以将引用看作是一个变量的别名,就是其他的名字,引用和被引用的变量其实是一个东西,只是有了两个名字而已。
问题的关键是,当你想要返回一个引用而不是一个拷贝时,你要确保这个引用的有效性,比如:
int & fun() { int a; a=10; return a; }
这样是不行的,因为a会在fun退出时被销毁,这时返回的a的引用是无效的。
这种情况下,如果fun的返回类型不是int & 而是int就没有问题了。

指针的引用
GetNearestFontInTwips(CFont *&aFont, const TFontSpec &aFontSpec);
第一个参数aFont是一个指针, 前面加上*&表示指针的引用, 其实可以如下看待这个方式(CFont*) &aFont, 这就一目了然了.

 

// image.at返回的是引用,将引用赋值到intensity Vec3b intensity = image.at
(j, i);//intensity是image.at返回的引用的另一个别名 Vec3b &intensity = image.at
(j, i);

 

 

 

 

转载于:https://www.cnblogs.com/guoqiaojin/p/3204958.html

你可能感兴趣的文章
react生命周期函数
查看>>
XMPP使用简介--登录
查看>>
java中synchronized关键字分析
查看>>
thymeleaf 学习笔记(转)
查看>>
在centos搭建php和python的apns2环境
查看>>
tree状数据叶子节点与根节点等的递归转换
查看>>
self.title,那么self.navigationItem.title和self.tabBarItem.title
查看>>
/etc/fstab 文件如何填写(转)
查看>>
js实现oss文件上传及一些问题
查看>>
python多线程总结
查看>>
《iOS应用开发攻略》试读样章
查看>>
什么是依赖注入?
查看>>
linux find 大小
查看>>
C++走向远洋——59(项目三、图形面积、抽象类)
查看>>
消费Dubbo服务介绍
查看>>
ArcGIS中的WKID
查看>>
python--time库的使用
查看>>
Zookeeper-实战
查看>>
《c++ concurrency in action》读书笔记1
查看>>
关于51单片机电子时钟精度的问题
查看>>