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=)
{
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=; i<nr; i++)
{
uchar* data = image.ptr<uchar>(i);
for(int j=; j<nc; j++)
{
//*data++ = *data - *data % div + div / 2;
*data++ = (*data & mask) + div / ;
}
} } 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();
return ; }
上一篇:TCP三次握手及释放连接详解(转)


下一篇:android6.0 Activity(四) Surface创建