#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\core\core.hpp> void colorReduce(cv::Mat& img, int div=); int main()
{
cv::Mat img_orginal = cv::imread("F:\\images\\boldt.jpg");
cv::Mat img_altered = img_orginal.clone(); colorReduce(img_altered); cv::namedWindow("orignal");
cv::imshow("orignal", img_orginal);
cv::namedWindow("altered");
cv::imshow("altered", img_altered); cv::waitKey(); return ;
} void colorReduce(cv::Mat& img, int div)
{
int n = cv::log(static_cast<double>(div)) / cv::log(2.0);
int mask = 0xFF << n; // 方式一:
//cv::Mat_<cv::Vec3b>::iterator it = img.begin<cv::Vec3b>();
// 方式二:
cv::MatIterator_<cv::Vec3b> it = img.begin<cv::Vec3b>();
for(; it!=img.end<cv::Vec3b>(); it++)
{
(*it)[] = (*it)[] & mask + div / ;
(*it)[] = (*it)[] & mask + div / ;
(*it)[] = (*it)[] & mask + div / ;
}
}

opencv学习笔记(03)——遍历图像(迭代器法)的更多相关文章

  1. OpenCV 学习笔记03 边界框、最小矩形区域和最小闭圆的轮廓

    本节代码使用的opencv-python 4.0.1,numpy 1.15.4 + mkl 使用图片为 Mjolnir_Round_Car_Magnet_300x300.jpg 代码如下: impor ...

  2. OpenCV 学习笔记03 findContours函数

    opencv-python   4.0.1 1 函数释义 词义:发现轮廓! 从二进制图像中查找轮廓(Finds contours in a binary image):轮廓是形状分析和物体检测和识别的 ...

  3. 【opencv学习笔记六】图像的ROI区域选择与复制

    图像的数据量还是比较大的,对整张图片进行处理会影响我们的处理效率,因此常常只对图像中我们需要的部分进行处理,也就是感兴趣区域ROI.今天我们来看一下如何设置图像的感兴趣区域ROI.以及对ROI区域图像 ...

  4. OpenCV 学习笔记03 boundingRect、minAreaRect、minEnclosingCircle、boxPoints、int0、circle、rectangle函数的用法

    函数中的代码是部分代码,详细代码在最后 1 cv2.boundingRect 作用:矩形边框(boundingRect),用于计算图像一系列点的外部矩形边界. cv2.boundingRect(arr ...

  5. OpenCV 学习笔记03 凸包convexHull、道格拉斯-普克算法Douglas-Peucker algorithm、approxPloyDP 函数

    凸形状内部的任意两点的连线都应该在形状里面. 1 道格拉斯-普克算法 Douglas-Peucker algorithm 这个算法在其他文章中讲述的非常详细,此处就详细撰述. 下图是引用维基百科的.ε ...

  6. OpenCV 学习笔记03 直线和圆检测

    检测边缘和轮廓不仅重要,还经常用到,它们也是构成其他复杂操作的基础. 直线和形状检测与边缘和轮廓检测有密切的关系. 霍夫hough 变换是直线和形状检测背后的理论基础.霍夫变化是基于极坐标和向量开展的 ...

  7. 【OpenCV学习笔记之一】图像加载,修改及保存

    加载图像(用cv::imread)imread功能是加载图像文件成为一个Mat对象 其中第一个参数表示图像文件名称第二个参数 表示加载的图像是什么类型 支持常见的三个参数值IMREAD_UNCHANG ...

  8. OpenCV 学习笔记03 drawContours函数

    opencv-python   4.0.1 轮廓的绘制或填充. cv2.drawContours(image, contours, contourIdx, color[, thickness[, li ...

  9. OpenCV 学习笔记03 threshold函数

    opencv-python   4.0.1 简介:该函数是对数组中的每一个元素(each array element)应用固定级别阈值(Applies a fixed-level threshold) ...

  10. 【opencv学习笔记五】一个简单程序:图像读取与显示

    今天我们来学习一个最简单的程序,即从文件读取图像并且创建窗口显示该图像. 目录 [imread]图像读取 [namedWindow]创建window窗口 [imshow]图像显示 [imwrite]图 ...

随机推荐

  1. Node.js module.exports和exports的区别

    require 用来加载代码,而 exports 和 module.exports 则用来导出代码,从接触node.js就不会它们两陌生,上代码: foo.js exports.a = functio ...

  2. Creating a Mono 3 RPM on CentOS

    Creating a Mono 3 RPM on CentOS A quick guide to creating an rpm of mono 3 from source, starting wit ...

  3. windows下使用VirtualEnv

    在开发Python应用程序的时候,有时会开发多个应用程序,那这些应用程序都会共用一个Python.如果应用A需要jinja 2.7,而应用B需要jinja 2.6怎么办?这种情况下,每个应用可能需要各 ...

  4. 用继承实现XYPoint和Circle两个类

    #import <Foundation/Foundation.h> @protocol show @required -(void)printOn; @end @interface XYP ...

  5. linux云计算集群架构学习笔记:rhel7基本命令操作

     1-3-RHEL7基本命令操作 1.1Linux终端介绍 Shell提示符 Bash Shell基本语法. 1.2基本命令的使用:ls.pwd.cd. 1.3查看系统和BIOS硬件时间. 1.4 L ...

  6. LeetCode 75

    Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of t ...

  7. poj 3264 RMQ

    直接写个RMQ就能过. #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  8. 虚拟机 VirtualBox 自制帮助文档

    初学 VirtualBox ,网络上教程很多,图片一张一张的费流量,讲得又比较散,于是花了一下午制作了此 CHM 帮助文档. 下载:(图片另存为--重命名为 RhinoC.rar --解压缩)

  9. 转:基于Webrtc的跨平台实时语音通信解决方案(讲座)

    转:http://edu.csdn.net/course/detail/320/

  10. linux信息查找

    问题: 1. 当使用一台linux机器的时候,常常需要确认当前所用操作系统的版本信息,内核信息等, 操作系统的版本信息可以通过以下命令完成,比如:lsb_release -a:cat /etc/iss ...