首页 > 代码库 > opencv学习笔记(02)——遍历图像(指针法)
opencv学习笔记(02)——遍历图像(指针法)
#include <opencv2\core\core.hpp> #include <opencv2\highgui\highgui.hpp> #include <opencv2\imgproc\imgproc.hpp> #include <iostream> void colorReduce(cv::Mat& image, int div=64) { int nr = image.rows; int nc = image.cols * image.channels(); int n = static_cast<int>( cv::log(static_cast<double>(div)) / cv::log(2.0) ); uchar mask = 0xFF << n; for(int i=0; i<nr; i++) { uchar* data = http://www.mamicode.com/image.ptr(i); for(int j=0; j<nc; j++) { //*data++ = *data - *data % div + div / 2; *data++ = (*data & mask) + div / 2; } } } int main(int argc, char** argv) { cv::Mat img = cv::imread("F:\\images\\boldt.jpg"); cv::Mat img2 = img.clone(); double duration; duration = static_cast<double>(cv::getTickCount()); colorReduce(img2); duration = static_cast<double>(cv::getTickCount()) - duration; duration /= cv::getTickFrequency(); cv::namedWindow("original"); cv::imshow("original", img); cv::namedWindow("altered"); cv::imshow("altered", img2); std::cout << duration << std::endl; cv::waitKey(0); return 0; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。