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 ...
随机推荐
- Html5 dataset--自定义属性
dataset--自定义属性 HTMLElement.dataset data-*属性集 元素上保存数据 <div id="user" data-id="12345 ...
- Android简化xml sax解析
dom解析占用内存大(我这边需要解析各种各样的kml文件,有时4-5M的kml文件使用dom解析很多手机就内存溢出了),也需要引入第三方库,所以使用相对于节省内存很多.不需引入其他库的sax解析就是很 ...
- 十五天精通WCF——第四天 你一定要明白的通信单元Message
转眼你已经学了三天的wcf了,是不是很好奇wcf在传输层上面到底传递的是个什么鸟毛东西呢???应该有人知道是soap,那soap这叼毛长得是什么 样呢?这一篇我们来揭开答案... 一:soap到底长成 ...
- Linux IPC System V 共享内存
模型 #include<sys/types.h> #include<sys/ipc.h> #include<sys/shm.h> ftok() //获取key值 s ...
- centos7系统下安装nodejs开发环境
1)安装基础工具(if not exists) yum install -y net telnet tools vim wget ntp 2)同步系统时间(if necessary) ntpdate ...
- JAVA插入sql代码
插入数据 import java.sql.*; /** * @version 2012-02-22 * @author */ public class InsertDemo { public stat ...
- C 结构体位域
位域 : 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可.为了节省存储空间,并使处理简便,C语言又提供了一 ...
- js获得昨天前天明天时间以及setDate()
<script type="text/javascript"> function GetDateStr(AddDayCount) { var dd = new Date ...
- PCA原理与实践
在对数据进行预处理时,我们经常会遇到数据的维数非常之大,如果不进行相应的特征处理,那么算法的资源开销会很大,这在很多场景下是我们不能接受的.而对于数据的若干维度之间往往会存在较大的相关性,如果能将数据 ...
- [PHP]程序员技能栈
[PHP]程序员技能栈.md-/Users/zjh/Documents/我的文章/[PHP]程序员技能栈 html{font-family: sans-serif;-ms-text-size-adju ...