其他分享
首页 > 其他分享> > Qt Opencv 生成白胡椒图

Qt Opencv 生成白胡椒图

作者:互联网

 1 Mat imgMat = imread("swan.jpg", IMREAD_COLOR);
 2 //    cvtColor(imgMat, imgMat, COLOR_BGR2GRAY);   //  转为灰度图
 3     Mat m;
 4     imgMat(Rect(1200,1200, 1000, 800)).copyTo(m);
 5 
 6     int n = 1000 * 800 * 0.05;   //  0.5%白噪点
 7 
 8     for(int k = 0; k < n; k++)
 9     {
10         int i = QRandomGenerator::global()->bounded(m.rows);
11         int j = QRandomGenerator::global()->bounded(m.cols);
12 
13         if(m.channels() == 1)
14             m.at<uchar>(i, j) = 255;
15         else
16         {
17             m.at<Vec3b>(i, j)[0] = 255;
18             m.at<Vec3b>(i, j)[1] = 255;
19             m.at<Vec3b>(i, j)[2] = 255;
20         }
21     }
22 
23     imshow("!", m);

 

标签:Qt,imgMat,int,global,1200,Opencv,白胡椒,Mat,255
来源: https://www.cnblogs.com/GEEK-ZHAO/p/15144601.html