opencv_tutorial_code学习——建缩减表、计时、扫描图片
2017-11-24 09:10
330 查看
From tutorial_code\core\how_to_scan_images\how_to_scan_images.cpp
建缩减表方法:
int divideWith = 0;
stringstream s;
s << argv[2];
s >> divideWith;
if (!s || !divideWith)
{
cout << "Invalid number entered for dividing. " << endl;
return -1;
}
uchar table[256];
for (int i = 0; i < 256; ++i)
table[i] = (uchar)(divideWith * (i/divideWith));
计时方法:
double t;
t = (double)getTickCount();
/* do something */
t = ((double)getTickCount() - t)/getTickFrequency();
扫描图片方法一:
int channels = I.channels();
int nRows = I.rows;
int nCols = I.cols * channels;
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]];
}
}
扫描图片方法二:
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]];
}
}
}
扫描图片方法三:
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;
}
}
直接对图像进行查表处理方法:
Mat lookUpTable(1, 256, CV_8U);
uchar* p = lookUpTable.ptr();
for( int i = 0; i < 256; ++i)
p[i] = table[i];
for (int i = 0; i < times; ++i)
LUT(I, lookUpTable, J);
输入图像和输出图像结果:
建缩减表方法:
int divideWith = 0;
stringstream s;
s << argv[2];
s >> divideWith;
if (!s || !divideWith)
{
cout << "Invalid number entered for dividing. " << endl;
return -1;
}
uchar table[256];
for (int i = 0; i < 256; ++i)
table[i] = (uchar)(divideWith * (i/divideWith));
计时方法:
double t;
t = (double)getTickCount();
/* do something */
t = ((double)getTickCount() - t)/getTickFrequency();
扫描图片方法一:
int channels = I.channels();
int nRows = I.rows;
int nCols = I.cols * channels;
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]];
}
}
扫描图片方法二:
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]];
}
}
}
扫描图片方法三:
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;
}
}
直接对图像进行查表处理方法:
Mat lookUpTable(1, 256, CV_8U);
uchar* p = lookUpTable.ptr();
for( int i = 0; i < 256; ++i)
p[i] = table[i];
for (int i = 0; i < times; ++i)
LUT(I, lookUpTable, J);
输入图像和输出图像结果:
相关文章推荐
- opencv_tutorial_code学习——图片叠加
- OpenCV学习笔记:如何扫描图像、利用查找表和计时
- opencv_tutorial_code学习——seamless cloning无缝融合、局部颜色变换、去高光镜面反射、平滑纹理
- opencv_tutorial_code学习——角点检测方法
- 学习OpenCV范例(二)——OpenCV如何扫描图像、利用查找表和计时
- opencv_tutorial_code学习——opencv decolor效果
- opencv_tutorial_code学习——matchTemplate模板匹配
- opencv_tutorial_code学习——hdr_imaging
- opencv_tutorial_code学习——findContours&drawContours&画最小包围矩形&画最小包围圆
- opencv_tutorial_code学习——opencv1语句
- opencv_tutorial_code学习——moments()中心距&面积&边长
- opencv_tutorial_code学习——pointPolygonTest计算点到轮廓的距离
- opencv_tutorial_code学习——VideoWriter生成视频流
- opencv_tutorial_code学习——画椭圆、圆、填充矩形、直线
- opencv_tutorial_code学习——FloodFill漫水填充和物体选取
- opencv_tutorial_code学习——Mat创建方法
- OpenCV2.4.10之samples_cpp_tutorial-code_learn-----ImgTrans(图片边框与图片卷积)
- opencv2学习笔记(二)-OpenCV如何扫描图像、利用查找表和计时
- opencv学习(十)颜色缩减 // 查表 // 计时 // 访问像素的三个方法(指针/STL迭代器(待详细了解)/动态地址)//历遍图像的14种方法
- opencv_tutorial_code学习——equalizeHist直方图均衡化