首先自我介绍一下,我是一名大三在校生,原本主要掌握的是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;