您的位置:首页 > 其它

使用指针遍历图像

2014-04-14 14:43 190 查看
#include<opencv2\core\core.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<iostream>
using namespace std;
using namespace cv;
//颜色缩减函数
void colorReduce(cv::Mat &image,int div=64)
{
int nl=image.rows;
int nc=image.cols*image.channels();
for(int j=0;j<nl;j++)
{
uchar* data=image.ptr<uchar>(j);
for(int i=0;i<nc;i++)
{
data[i]=data[i]/div*div+div/2;
}
}
}
int main()
{
cv::Mat image=cv::imread("d:\\test\\opencv\\img.jpg");
colorReduce(image);
cv::namedWindow("output");
cv::imshow("output",image);
waitKey(0);
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: