#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;
}
使用指针遍历图像
最新推荐文章于 2025-07-01 14:50:09 发布