opencv 中对一个像素的rgb值或像素值进行操作的几个常用小办法【转】
You can access the Image pixels in many ways:
1. One using the Inbuilt macro
2. One using the pointer to the image data
3. Getting the raw data from the image.
============================================================
Method 1: Using Inbuilt macro:
CV_IMAGE_ELEM( image_header, elemtype, y, x_Nc )
Suppose, we have 8-bit 1-channel image I (IplImage* img):
I(x,y) ~ CV_IMAGE_ELEM( img, uchar, y, x);
Suppose, we have 8-bit 3-channel image I (IplImage* img):
I(x,y)blue ~ CV_IMAGE_ELEM( img, uchar, y, x*3);
I(x,y)green ~ CV_IMAGE_ELEM( img, uchar, y, x*3+1);
I(x,y)red ~ CV_IMAGE_ELEM( img, uchar, y, x*3+2);
============================================================
Method 2: Using pointer to the image data:
Suppose, we have 8-bit 1-channel image I (IplImage* img):
I(x,y) ~ ((uchar*)(img->imageData + img->widthStep*y))[x]
Suppose, we have 8-bit 3-channel image I (IplImage* img):
I(x,y)blue ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3]
I(x,y)green ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+1]
I(x,y)red ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+2]
============================================================
Method 3: Using the raw data:
uchar *data;
cvGetRawData(img, (uchar**)&data);
I(x, y) = data[x*img->Width + y]
对于rgb图像
读入像素RGB
int B = CV_IMAGE_ELEM(img, unsigned char, row, col*3+0);
int G = CV_IMAGE_ELEM(img, unsigned char, row, col*3+1);
int R = CV_IMAGE_ELEM(img, unsigned char, row, col*3+2);
写入像素RGB
CV_IMAGE_ELEM(img, unsigned char, row, col*3+0) = 90;
CV_IMAGE_ELEM(img, unsigned char, row, col*3+1) = 90;
CV_IMAGE_ELEM(img, unsigned char, row, col*3+2) = 90;
修改单个像素,再说得详细点,
1.3通道时:CV_IMAGE_ELEM(image, unsigned char, i, j*3+k) = gray_val; //0<=k<3
2.单通道时:CV_IMAGE_ELEM(image, unsigned char, i, j) = gray_val;
3.通用方法:CvScalar s;
s=cvGet2D(img,i,j); // get the (i,j) pixel value
s.val[0]=111; //单通道就只有这个有效
s.val[1]=111;
s.val[2]=111;
cvSet2D(img,i,j,s);//set the (i,j) pixel value
CV_IMAGE_ELEM的方法比cvGet2D,cvSet2D快了十倍左右(据说)
转自:http://blog.csdn.net/lkbwx/article/details/5548416
opencv 中对一个像素的rgb值或像素值进行操作的几个常用小办法【转】的更多相关文章
- 判断是否是同一人的方法——equals()?在Person类中提供一个比较的方法compare()返回boolean值?对象自己和自己比?
判断是否是同一人的方法——equals() 不能直接用per1==per2,这不是对象内容的比较而是存放对象地址的值得比较 在Person类中提供一个比较的方法compare()返回boolean值 ...
- eclipse 中main()函数中的String[] args如何使用?通过String[] args验证账号密码的登录类?静态的主方法怎样才能调用非static的方法——通过生成对象?在类中制作一个方法——能够修改对象的属性值?
eclipse 中main()函数中的String[] args如何使用? 右击你的项目,选择run as中选择 run configuration,选择arguments总的program argu ...
- opencv中CV_IMAGE_ELEM的用法读取每个像素
可以使用OpenCV定义的宏来提取象素值假设灰度图像image,存取其i行j列的象素可以这样:CV_IMAGE_ELEM(image, uchar,y, x)如果是彩色图像就是CV_IMAGE_ELE ...
- 前端JQuery中获取一个div下的多个id值
获取所有的Id值,方法是通过div.class获取全局的值,然后再提取具体的Id值 方法一:用for循环,因为$("div.class")获取的是一个数组,通过循环读取出数组中的每 ...
- spring boot-controller中的一个方法获取其他方法返回的值
@RequestMapping("/test") public String getData() { return "redirect:/other";} re ...
- opencv中的.at方法
opencv中的.at方法是用来获取图像像素值得函数: interpolation:差值 histogram:直方图
- 图像金字塔及其在 OpenCV 中的应用范例(下)
前言 本文将主要讲解如何使用 OpenCV 实现图像分割,这也是图像金字塔在 OpenCV 中的一个重要应用. 关于图像分割 在计算机视觉领域,图像分割(Segmentation)指的是将数字图像细分 ...
- opencv中的更通用的形态学
为了处理更为复杂的情况,opencv中还支持更多的形态学变换. 形态学名称 操作过程 操作名称 是否需要temp参数 开操作 open open(src)=先腐蚀,后膨胀 CV_MOP_OPEN 否 ...
- 从ACM中删除一个已经创建的Library
从ACM中删除一个已经创建的Library,无法通过界面操作,须要手工从DB中删除.须要删除的表记录有: RECENTUPDATE 找到字段Name等于该libraryName的那条记录删除掉 del ...
随机推荐
- 关于rails里集成测试assert_template的写法
assert_template后面只能跟随模板文件名,不能跟随命名路径.比如routes.rb: get 'login' => 'sessions#new' 在集成测试用例里,只能写成asser ...
- stringstream操纵string小总结
1 split字符串 之前在用C#写代码的时候,用过split函数,可以把一个字符串根据某个分隔符分成若干个字符串数组.在用C++操纵字符串的时候,我一直使用很笨的遍历的方法.为此,我问候过很多次C+ ...
- cacti监控mysql
cacti监控mysql 2013-09-25 16:21:43 分类: LINUX 原文地址:cacti监控mysql 作者:baochenggood cacti监控mysql 1 下载cacti监 ...
- maven-shade-plugin
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> ...
- 【JSP】JSP基础学习记录(四)—— Servlet
序: 众所周知JSP的基础也就是Servlet,如果单纯用Servlet类来响应用户的HTTP请求可以吗?答案是肯定的.JSP中的9个内置对象只是自动帮我们初始化的,没有他们一样可以实现web.只是工 ...
- ASP.NET Web API 简介
ASP.NET MVC 4 包含了 ASP.NET Web API, 这是一个创建可以连接包括浏览器.移动设备等多种客户端的 Http 服务的新框架, ASP.NET Web API 也是构建 RES ...
- ORA-01858: 在要求输入数字处找到非数字字符
数据库 date 字段问题 insert into WK_RE_LE (DACL_FILE_ID,DACL_GROUP_ID,BDCDYH,DACL_LENGTH,ISVALID,DACL ...
- python基础(三)序列
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 谢谢thunder424纠错 sequence 序列 sequence(序列)是一 ...
- ELK Kafka json to elk
Logstash配置 input { kafka { zk_connect => "127.0.0.1:2181" topic_id => "clus ...
- ELF Format 笔记(六)—— 字符串表
ilocker:关注 Android 安全(新入行,0基础) QQ: 2597294287 字符串表中包含若干以 null 结尾的字符串,这些字符串通常是 symbol 或 section 的名字.当 ...