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 ...
随机推荐
- git pull/push项目的时候总是提示要输入用户名密码的解决方案
作者:白狼 出处:www.manks.top/article/git_tip_user_password 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否 ...
- servlet 学习(一)
一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...
- MySQL online ddl原理
背景 dba的日常工作肯定有一项是ddl变更,ddl变更会锁表,这个可以说是dba心中永远的痛,特别是执行ddl变更,导致库上大量线程处于“Waiting for meta data lock”状态的 ...
- html5 如何进行自定义属性的定义和查询
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>T ...
- 烂泥:ubuntu下配置msmtp+mutt发送邮件
本文由ilanniweb提供友情赞助,首发于烂泥行天下 想要获得更多的文章,可以关注我的微信ilanniweb. 本文主要介绍如何在Linux下使用msmtp+mutt发送邮件,当然Linux下发送邮 ...
- ubuntu下eclipse scala开发插件(Scala IDE for Eclipse)安装
1. 环境介绍 系统:ubuntu16.04(不过和系统版本关系不大) elipse:Neon.1aRelease (4.6.1) 2. 插件介绍 Scala IDE for eclipse是elip ...
- C++学习笔记【转载】
转载自:http://www.cnblogs.com/maowang1991/p/3290321.html 1.struct成员默认访问方式是public,而 class默认访问方式是private! ...
- linux线程同步(4)-自旋锁
自旋锁与互斥量功能一样,唯一一点不同的就是互斥量阻塞后休眠让出cpu,而自旋锁阻塞后不会让出cpu,会一直忙等待,直到得到锁!!! 自旋锁在用户态使用的比较少,在内核使用的比较多!自旋锁的使用场景:锁 ...
- plsql+绿色版oracle连接远程数据库配置及提示缺少msvcr71.dll解决方法
之前一直用的sqldeveloper连接oracle数据库,这个免费而且也是官方出品,除了体积略大启动略慢外,也没什么不好的.. 一次偶然机会决定试一下plsql,整理一下安装资料,需要本地oracl ...
- 说说React
一个组件,有自己的结构,有自己的逻辑,有自己的样式,会依赖一些资源,会依赖某些其他组件.比如日常写一个组件,比较常规的方式: 通过前端模板引擎定义结构 JS文件中写自己的逻辑 CSS中写组件的样式 通 ...