#include<iostream>
#include<opencv2/opencv.hpp>
#include<vector>
using namespace std;
using namespace cv;
void colorReduce(const Mat &srcImage, Mat &dstImage, int div);
int main()
{
Mat srcImage = imread("G:\\group.jpg");
Mat dstImage;
dstImage.create(srcImage.size(), srcImage.type());
colorReduce(srcImage, dstImage, 64);
imshow("【原图】", srcImage);
imshow("【颜色减缩图】", dstImage);
waitKey(0);
return 0;
}
void colorReduce(const Mat &srcImage, Mat &dstImage, int div)
{
srcImage.copyTo(dstImage);
Mat_<Vec3b>::iterator it = dstImage.begin<Vec3b>();
Mat_<Vec3b>::iterator itend = dstImage.end<Vec3b>();
while (it != itend)
{
(*it)[0] = (*it)[0] / div * div + div / 2;
(*it)[1] = (*it)[1] / div * div + div / 2;
(*it)[2] = (*it)[2] / div * div + div / 2;
++it;
}
}
Opencv用迭代器操作像素
最新推荐文章于 2022-10-25 17:21:28 发布