The Zen of Python,by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea — let’s do more of those!


#include <iostream> 
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <random>

using namespace std;

void salt(cv::Mat image, int n) {

  // C++11的随机数生成器
  std::default_random_engine generator;
                randomRow(0, image.rows - 1);
                randomCol(0, image.cols - 1);

  int i,j;
  for (int k=0; k<n; k++) {

    // 随机生成图形位置
    i= randomCol(generator);
    j= randomRow(generator);
    if (image.type() == CV_8UC1) { // 灰度图像
      // 单通道8位图像<uchar>(j,i)= 255;
    } else if (image.type() == CV_8UC3) { // 彩色图像
      // 3通道图像<cv::Vec3b>(j,i)[0]= 255;<cv::Vec3b>(j,i)[1]= 255;<cv::Vec3b>(j,i)[2]= 255;

int main()
    // 打开图像
    cv::Mat image= cv::imread("test.jpg",1);
    // 调用函数以添加噪声
    // 显示结果




#include <iostream>
#include <opencv2/core.hpp>
// 读写图像和视频的函数以及一些用户交互函数模块
#include <opencv2/highgui.hpp>
// 包含主要的图像处理函数模块
#include <opencv2/imgproc.hpp>

using namespace std;

int main()
	// 创建一个空图像对象
	cv::Mat image;
	 * @param const cv:String 文件名称
	 * @param int flags 读入图像时转换成三通道彩色图像或灰度图
	image= cv::imread("test.bmp", cv::IMREAD_GRAYSCALE);
        // 等待按键