OpenCV--How to scan images, lookup tables and time measurement with OpenCV
来源:互联网 发布:中国大米进出口数据 编辑:程序博客网 时间:2024/05/20 13:16
一:学习目标
- How to go through each and every pixel of an image?
- How is OpenCV matrix values stored?
- How to measure the performance of our algorithm?
- What are lookup tables and why use them?
二:图像矩阵在内存中如何存储
2.1 图像容器Mat
Mat和Matlab里的数组格式有点像,但一般是二维向量,如果是灰度图,一般存放<uchar>类型;如果是RGB彩色图,存放<Vec3b>类型。
单通道灰度图数据存放格式:
多通道的图像中,每列并列存放通道数量的子列,如RGB三通道彩色图:
注意通道的顺序反转了:由RGB转化成了BGR。通常情况内存足够大的话图像的每一行是连续存放的,也就是在内存上图像的所有数据存放成一行,这中情况在访问时可以提供很大方便。可以用 isContinuous()函数来判断图像数组是否为连续的。
三:访问图像中的像素
3.1高效的方法:C操作符[ ]
最快的是直接用C风格的内存访问操作符[]来访问:
CvMat& ScanImageAndReduceC(CvMat& I,const uchar* const table){//accept only char type matricesCV_ASSERT(I.depth()!=sizeof(uchar));int channels=I.channels();int nRows=I.rows;int nCols=I.cols*channels;if (I.isContinuous()){nCols*=nRows;nRows=1;}int i,j;for (i=0;i<nRows;++i){p=I.ptr<uchar>(i);for (j=0;j<nCols;++j){p[j]=table[p[j]];}}return I;}
这种访问形式就是在每行定义一个指针,然后在内存上直接连续访问。如果整个数组在内存上都是连续存放的,那么只需要定义一个指针就可以访问所有的数据!如单通道的灰度图访问方式如下:
0 0
- OpenCV--How to scan images, lookup tables and time measurement with OpenCV
- How to scan images, lookup tables and time measurement with OpenCV
- opencv_tutorial 2.2 - How to scan Images,Lookup tables and time measurement with opencv
- OpenCV例程2 how to scan images
- How to use OpenCV to capture and display images from a camera
- How to Detect and Track Object With OpenCV
- OpenCV学习笔记二(scan images)
- 怎样扫描图片how to scan images
- How to write GIMP plugin with OpenCV
- How to use SCAN and node listeners with different ports?
- Converting between ROS images and OpenCV images
- 【opencv】,【matlab】How to connect Matlab with OpenCV on Windows7
- 【OpenCV】How to Use Tesseract with C++ or OpenCV
- First time play with JavaCV/OpenCV to detect faces
- How to install OpenCV
- 用 Python 和 OpenCV 检测图片上的条形码Detecting Barcodes in Images with Python and OpenCV
- How to make ROS and Opencv work together
- How to Install OpenCV 3.0 and Python 3.4+ on Ubuntu
- 撒旦法撒旦撒旦撒旦法撒旦撒反对撒旦法爱上爱上阿斯顿
- Hadoop安装配置
- 安素芳阿斯顿撒旦法撒旦撒反对阿斯顿飞洒
- 双方各发个别的的反光板
- JMS两种消息模型
- OpenCV--How to scan images, lookup tables and time measurement with OpenCV
- 爱上按时发达撒旦法撒旦撒旦法撒旦飞洒撒旦法撒旦倒萨
- JDBC 连接数据库 事物处理
- fakgkarjgkrajgkrjik
- 基础知识复习二 --- 指针(Jun18)
- [复习]C++中两种字符串的输入输出
- 阿道夫阿道夫阿斯顿啊法撒旦是发送到撒爱上撒
- 双方各等方面梵蒂冈发布会
- 测试Std:heap