使用指针遍历图像

来源:互联网 发布:网络劫持判断 编辑:程序博客网 时间:2024/03/29 02:37
#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;}

0 0
原创粉丝点击