OpenCV官方文档研究(一)Mat

首先自我介绍一下,我是一名大三在校生,原本主要掌握的是J2EE,擅长SpringMVC+Spring+Hibernate框架。今年想有空多研究点高级的东西,于是选择了图像处理。今天是我第一天写博客,这篇是我第二篇博文。希望大家能够支持我哦!


The copy operators will only copy the headers and the pointer to the large matrix, not the data itself.
Mat复制操作只复制头和矩阵的指针,不包括数据本身


Mat A, C;   // creates just the header parts
A = imread(argv[1], CV _ LOAD _ IMAGE _ COLOR);  // here we’ll know the method used (allocate matrix)
Mat B(A);   // Use the copy constructor
C = A;   // Assignment operator

上面三个对象都指向同一个矩阵!

Sometimes you will want to copy the matrix itself too, so OpenCV provides the clone() and copyTo() functions.
如果想复制矩阵数据,用clone()或copyTo()。


Mat F = A.clone();
Mat G;
A.copyTo(G);

RGB is the most common as our eyes use something similar, but keep in mind that the OpenCV display system uses BGR colors.
OpenCV使用的颜色空间是BGR,与RGB在存储顺序上不同!


color space reduction 颜色空间缩减

Inew = Iold/n*n uchar table[256]; for (int i = 0; i < 256; ++i) table[i] = (uchar)(divideWith*(i/divideWith)); **先生成表再通过查询赋值会提高效率!** MatIterator _ it, end; for( it = I.begin(), end = I.end(); it != end; ++it) { ( * it)[0] = table[( * it)[0]]; ( * it)[1] = table[( * it)[1]]; ( * it)[2] = table[( * it)[2]]; } OpenCV提供了LUT()来达到相同的效果。 Mat lookUpTable(1, 256, CV _ 8U); uchar * p = lookUpTable.data; for( int i = 0; i < 256; ++i) p[i] = table[i];

LUT(I, lookUpTable, J); //I is our input image and J the output one


获取运行时间

double t = (double)getTickCount(); // do something ... t = ((double)getTickCount() - t)/getTickFrequency(); cout << "Times passed in seconds: " << t << endl;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值