《opencv入门教程》(迭代器遍历)
2015-07-08 20:27
357 查看
#include<iostream> #include<opencv2/opencv.hpp> using namespace std; using namespace cv; int main(){ Mat grayim(600,800,CV_8UC1); Mat colorim(600, 800, CV_8UC3); MatIterator_<uchar> graybegin, grayend; MatIterator_<Vec3b> colorbegin, colorend; for (graybegin = grayim.begin<uchar>(), grayend = grayim.end<uchar>(); graybegin != grayend; ++graybegin){ *graybegin = rand() % 255; } //遍历所有的像素,设置像素值 for (colorbegin = colorim.begin<Vec3b>(), colorend = colorim.end<Vec3b>(); colorbegin != colorend; ++colorbegin){ (*colorbegin)[0] = rand() % 255; (*colorbegin)[1] = rand() % 255; (*colorbegin)[2] = rand() % 255; } imshow("image1", grayim); imshow("image2", colorim); waitKey(0); }
注意迭代器绑定的时候:
graybegin = grayim.begin<uchar>(), grayend = grayim.end<uchar>()
<pre name="code" class="cpp">colorbegin = colorim.begin<Vec3b>(), colorend = colorim.end<Vec3b>()
注意是有类型说明的,或者uchar或者Vec3b
相关文章推荐
- linux centos使用xrdp远程界面登陆
- linux centos使用xrdp远程界面登陆
- 在Mac下配置php开发环境:Apache+php+MySql
- 查看ecshop广告位对应的广告详细信息
- linux 查看系统信息命令(比较全)
- linux-redhat6.4驱动无线网卡rtl8188eu
- linux-redhat6.4驱动无线网卡rtl8188eu
- 模块编译Makefile解析
- mysql+nginx+php
- linux开机自动连接无线网络
- 写一个 docker 打击一系列手册
- [转]开发大型高负载类网站应用的几个要点
- Linux C语言程序设计(三)——函数的理解与自定义
- [转]LAMP 系统性能调优,第 1 部分: 理解 LAMP 架构
- 打开linux的framebuffer
- linux 开启支持FrameBuffer--解决打开/dev/fb0失败的问题
- Centos 6.5 RedHat 6 安装mysql
- Ubuntu如何搭建Django与Flup和Nginx环境?
- vmware安装CentOS6.4详细步骤
- S3C2440 Linux下的I2C驱动以及I2C体系下对EEPROM进行读写操作。