1 void gl(const Mat &image,Mat& result)
2 {
3 result.create(image.size(),image.type());
4 int nr=image.rows;
5 int nc=image.cols*image.channels();
6 for(int i=1;i<nr-1;i++)
7 {
8 const uchar* up_line=image.ptr<uchar>(i-1);//指向上一行
9 const uchar* mid_line=image.ptr<uchar>(i);//当前行
10 const uchar* down_line=image.ptr<uchar>(i+1);//下一行
11 uchar* cur_line=result.ptr<uchar>(i);
12 for(int j=1;j<nc-1;j++)
13 {
14 cur_line[j]=saturate_cast<uchar>(5*mid_line[j]-mid_line[j-1]-mid_line[j+1]-
15 up_line[j]-down_line[j]);
16 }
17 }
19 result.row(0).setTo(Scalar(0));
20 result.row(result.rows-1).setTo(Scalar(0));
21 result.col(0).setTo(Scalar(0));
22 result.col(result.cols-1).setTo(Scalar(0));
23 }
1 void gl(const Mat& image,Mat& outImage,int div)
2 {
3 outImage.create(image.size(),image.type());
4 MatConstIterator_<Vec3b> it_in=image.begin<Vec3b>();
5 MatConstIterator_<Vec3b> itend_in=image.end<Vec3b>();
6 MatIterator_<Vec3b> it_out=outImage.begin<Vec3b>();
7 MatIterator_<Vec3b> itend_out=outImage.end<Vec3b>();
8 while(it_in!=itend_in)
9 {
10 (*it_out)[0]=(*it_in)[0]/div*div+div/2;
11 (*it_out)[1]=(*it_in)[1]/div*div+div/2;
12 (*it_out)[2]=(*it_in)[2]/div*div+div/2;
13 it_in++;
14 it_out++;
15 }
16 }
43 void colorReduce7(cv::Mat &image, int div = 64)
144 {
145 int nl = image.rows;
146 int nc = image.cols;
147
148 //遍历图像的每个像素
149 for(int j=0; j<nl ;++j)
150 {
151 for(int i=0; i<nc; ++i)
152 {
153 image.at<cv::Vec3b>(j,i)[0] = image.at<cv::Vec3b>(j,i)[0]/div*div + div/2;
154 image.at<cv::Vec3b>(j,i)[1] = image.at<cv::Vec3b>(j,i)[1]/div*div + div/2;
155 image.at<cv::Vec3b>(j,i)[2] = image.at<cv::Vec3b>(j,i)[2]/div*div + div/2;
156 }
157 }
158 }