标签:style blog class code c java
1 #include <opencv2\highgui\highgui.hpp> 2 #include <opencv2\imgproc\imgproc.hpp> 3 #include <opencv2\core\core.hpp> 4 5 void colorReduce(cv::Mat& img, int div=64); 6 7 8 int main() 9 { 10 cv::Mat img_orginal = cv::imread("F:\\images\\boldt.jpg"); 11 cv::Mat img_altered = img_orginal.clone(); 12 13 colorReduce(img_altered); 14 15 cv::namedWindow("orignal"); 16 cv::imshow("orignal", img_orginal); 17 cv::namedWindow("altered"); 18 cv::imshow("altered", img_altered); 19 20 cv::waitKey(); 21 22 return 0; 23 } 24 25 void colorReduce(cv::Mat& img, int div) 26 { 27 int n = cv::log(static_cast<double>(div)) / cv::log(2.0); 28 int mask = 0xFF << n; 29 30 // 方式一: 31 //cv::Mat_<cv::Vec3b>::iterator it = img.begin<cv::Vec3b>(); 32 // 方式二: 33 cv::MatIterator_<cv::Vec3b> it = img.begin<cv::Vec3b>(); 34 for(; it!=img.end<cv::Vec3b>(); it++) 35 { 36 (*it)[0] = (*it)[0] & mask + div / 2; 37 (*it)[1] = (*it)[1] & mask + div / 2; 38 (*it)[2] = (*it)[2] & mask + div / 2; 39 } 40 }
opencv学习笔记(03)——遍历图像(迭代器法),布布扣,bubuko.com
标签:style blog class code c java
原文地址:http://www.cnblogs.com/takeaction/p/3735248.html