码迷,mamicode.com
首页 > 其他好文 > 详细

opencv学习笔记(02)——遍历图像(指针法)

时间:2014-05-19 19:54:20      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   c   code   java   

bubuko.com,布布扣
#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 = image.ptr<uchar>(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;

}
bubuko.com,布布扣

 

opencv学习笔记(02)——遍历图像(指针法),布布扣,bubuko.com

opencv学习笔记(02)——遍历图像(指针法)

标签:style   blog   class   c   code   java   

原文地址:http://www.cnblogs.com/takeaction/p/3734559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!