OPenCV2 如何使用指针的方式遍历图像
来源:互联网 发布:网络连接不上错误651 编辑:程序博客网 时间:2024/04/25 15:31
Mat m=imread("...");
m.data;//图像的数据开始指针
m.ptr<类型>(Y)---m.ptr<uchar>(0) --- 一行的起始位置
连续存储 -- 每行的长度==图像的实际使用长度
非连续存储 --- 即 对每行尾部进行了补充,使其是4或8的整数倍(通常硬件需要,提高处理速度)
例如
uchar data[100];
Mat m(10,10,CV_8U1,data,12);//设置了行长度为12,实际=10;则行尾部需要添加2字节
判读是否为连续存储 m.isContinuous()
#include <Windows.h>#include <time.h>#include "opencv.hpp"using namespace cv;//void setAllWhite(Mat& src)//{//int x,y;////for (int y = 0; y < src.rows; y++)//{////uchar* p=src.ptr<uchar>(y);//for (int x = 0; x < src.cols; x++)//{//p[0]=255;//p[1]=255;//p[2]=255;////p+=3;//}////}////}//void setAllWhite(Mat& src)//{//int x,y;////int length=src.cols * src.channels();////for (int y = 0; y < src.rows; y++)//{////uchar* p=src.ptr<uchar>(y);//for (int x = 0; x < length; x++)//{//*(p++)=255;//}////}////}void setAllWhite(Mat& src){int x,y;for (int y = 0; y < src.rows; y++){Vec3b* p=src.ptr<Vec3b>(y);for (int x = 0; x < src.cols; x++)*(p++)=Vec3b(255,255,255);}////////////////////////}////////////////////////////////////void setAllWhiteE(Mat& src){uchar* p=src.data;int length=src.rows * src.cols * src.channels();while (length-->0)*(p++)=255;}void compareTime(Mat& src){int count=1000;long begin,end;begin=clock();while(count-->0)setAllWhite(src);end=clock();printf("(setAllWhite) time is %f \n",(double)(end-begin)/(double)CLOCKS_PER_SEC);count=1000;begin=clock();while(count-->0)setAllWhiteE(src);end=clock();printf("(setAllWhiteE) time is %f \n",(double)(end-begin)/(double)CLOCKS_PER_SEC);}int main(){Mat src = imread("C:\\Users\\Administrator\\Desktop\\1.jpg");compareTime(src);/*setAllWhiteE(src);imshow("xx",src);waitKey(0);*/return 0;}
0 0
- OPenCV2 如何使用指针的方式遍历图像
- openCV2使用指针的方式遍历图像image.ptr
- [OpenCV2]使用指针遍历图像
- 使用指针的方式遍历图像数据
- OpenCv2(图像的遍历)
- [OpenCV2]使用迭代器遍历指针
- opencv2系列图像的遍历
- 【opencv2】:图像元素的遍历
- 使用指针遍历图像
- OpenCV2编程手册笔记之 2.3指针遍历图像
- [OpenCV2]遍历图像的临近像素
- opencv2遍历图像程序
- OpenCV2学习笔记---指针方式历遍图像
- 如何使用迭代器遍历图像
- Opencv2系列学习笔记2(图像的遍历)
- opencv2中对图像ROI的理解及遍历操作
- OpenCV2 访问各个像素点的方法(图像遍历)
- Opencv2系列学习笔记2(图像的遍历)
- CocosGUITestMainLayer控件的使用
- PAT Advanced Level 1077
- java 8 New JavaScript Engine
- hebernate获取数据的方式(find,load,get)区别
- PAT Advanced Level 1078
- OPenCV2 如何使用指针的方式遍历图像
- PAT Advanced Level 1079
- note : create zip and add file to it
- PAT Advanced Level 1080
- 给我们组的女爷们儿写一篇。
- spring事务传播属性和事务隔离级别
- 做开发英语真的很重要!!!(半夜,吐槽)
- 【pygame游戏开发系列博客】使用pygame开发2d休闲游戏
- GCT考试通过后获得证书是双证还是单证?