opencv编程笔记
2016-01-25 15:57
239 查看
1.读取、显示和保存图像 (imread、 imshow、 imwrite)
2.翻转 flip(image, result, 1);(正数-水平;0-垂直;负数-同时)
3.图像 赋值 和 拷贝:
image2 = result; //两个图像指向相同的数据
result.copyTo(image3); // 产生一个新的拷贝图像
4.存取图像 img.at(j, i)[0]=intensity
5.遍历图像(指针 ptr[],迭代器 Iterator,引用, LUT(I, lookUpTable, J))
补充:计时 t = (double)getTickCount();…;t = ((double)getTickCount() - t) / getTickFrequency();
高效:指针 ptr[]
安全:迭代器Iterator
引用
#include<iostream> #include<opencv2\opencv.hpp> using namespace std; using namespace cv; int main() { Mat image = imread("d:/img/1.jpg", 0); imshow("Image", image); waitKey(0); return 0; }
2.翻转 flip(image, result, 1);(正数-水平;0-垂直;负数-同时)
3.图像 赋值 和 拷贝:
image2 = result; //两个图像指向相同的数据
result.copyTo(image3); // 产生一个新的拷贝图像
4.存取图像 img.at(j, i)[0]=intensity
5.遍历图像(指针 ptr[],迭代器 Iterator,引用, LUT(I, lookUpTable, J))
补充:计时 t = (double)getTickCount();…;t = ((double)getTickCount() - t) / getTickFrequency();
高效:指针 ptr[]
Mat& ScanImageAndReduceC(Mat& I, const uchar* const table) { // accept only char type matrices CV_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; uchar* p; for( i = 0; i < nRows; ++i) { p = I.ptr<uchar>(i); for ( j = 0; j < nCols; ++j) { p[j] = table[p[j]]; } } return I; }
安全:迭代器Iterator
Mat& ScanImageAndReduceIterator(Mat& I, const uchar* const table) { // accept only char type matrices CV_Assert(I.depth() != sizeof(uchar)); const int channels = I.channels(); switch(channels) { case 1: { MatIterator_<uchar> it, end; for( it = I.begin<uchar>(), end = I.end<uchar>(); it != end; ++it) *it = table[*it]; break; } case 3: { MatIterator_<Vec3b> it, end; for( it = I.begin<Vec3b>(), end = I.end<Vec3b>(); it != end; ++it) { (*it)[0] = table[(*it)[0]]; (*it)[1] = table[(*it)[1]]; (*it)[2] = table[(*it)[2]]; } } } return I; }
引用
Mat& ScanImageAndReduceRandomAccess(Mat& I, const uchar* const table) { // accept only char type matrices CV_Assert(I.depth() != sizeof(uchar)); const int channels = I.channels(); switch(channels) { case 1: { for( int i = 0; i < I.rows; ++i) for( int j = 0; j < I.cols; ++j ) I.at<uchar>(i,j) = table[I.at<uchar>(i,j)]; break; } case 3: { Mat_<Vec3b> _I = I; for( int i = 0; i < I.rows; ++i) for( int j = 0; j < I.cols; ++j ) { _I(i,j)[0] = table[_I(i,j)[0]]; _I(i,j)[1] = table[_I(i,j)[1]]; _I(i,j)[2] = table[_I(i,j)[2]]; } I = _I; break; } } return I; }
相关文章推荐
- Note:This element neither has attached source nor attached Javadoc
- Note:This element neither has attached source nor attached Javadoc
- goldengate ERROR OGG-01172
- asprintf
- 离散傅里叶变换C++代码
- python备份mysql数据库并发送邮件
- c++之Unicode下vs中CString 转char*
- Java transient关键字使用小记
- Spark技术内幕:Stage划分及提交源代码分析
- Java注解编程指南
- Qt共享内存读写
- c++中的前向声明
- Eclipse自动补全功能和自动生成作者、日期注释等功能设置
- python 正则表达式
- go get安装第三方包的前提条件和步骤
- 20160125--集合Set-Map+总结
- Python Django 框架开发
- 运行phpize时出现:Cannot find autoconf. Please check your autoconf installation
- myeclise10 svn: E210004: Number is larger than maximum 解决方案
- 根据表名得到表信息,包括字段说明,生成C#类属性