#include "mainwindow.h"
#include <QApplication>
#include <iostream>
#include <string>
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>

using namespace cv;

void salt(cv::Mat image, int n) {
int i,j;
for (int k=0; k<n; k++) {
// rand()是随机数生成器
i= std::rand()%image.cols;
j= std::rand()%image.rows;
if (image.type() == CV_8UC1) { // 灰度图像
image.at<uchar>(j,i)= 255;
} else if (image.type() == CV_8UC3) { // 彩色图像
image.at<cv::Vec3b>(j,i)[0]= 255;
image.at<cv::Vec3b>(j,i)[1]= 255;
image.at<cv::Vec3b>(j,i)[2]= 255;
}
}
}
int main(int argc, char *argv[])
{

Mat image; //
image= imread("C:\\Users\\Administrator\\Desktop\\QTsucai\\result.jpg"); // 读取输入图像
if(image.empty()){
return 0;
}
salt(image,3000);
namedWindow("Original Image");
imshow("Original Image", image);
waitKey(20);
getchar();

return 0;
}