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

opencv学习笔记(01)——操作图像的像素

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

标签:style   blog   class   c   code   java   

bubuko.com,布布扣
 1 #include <opencv2\core\core.hpp>
 2 #include <opencv2\highgui\highgui.hpp>
 3 #include <opencv2\imgproc\imgproc.hpp>
 4 #include <iostream>
 5 
 6 
 7 void salt(cv::Mat& image, int n)
 8 {
 9 
10     for(int k=0; k<n; k++)
11     {
12 
13         int i = rand() % image.cols;        
14         int j = rand() % image.rows;        
15 
16         // 灰度图像
17         if(image.channels() == 1)
18         {
19             cv::Mat_<uchar> img = image;
20             img(j,i) = 255;            
21         }else{// 彩色图像 
22             cv::Mat_<cv::Vec3b> img = image;
23             //image.at<cv::Vec3b>(j,i)[0] = 255;            
24             //image.at<cv::Vec3b>(j,i)[1] = 255;            
25             //image.at<cv::Vec3b>(j,i)[2] = 255;            
26 
27             img(j,i)[0] = 255;            
28             img(j,i)[1] = 255;            
29             img(j,i)[2] = 255;            
30         }
31 
32     }
33 
34 }
35 
36 
37 int main(int argc, char** argv)
38 {
39 
40     cv::Mat img = cv::imread("F:\\images\\boldt.jpg");    
41     cv::Mat img2 = img.clone();    
42 
43     double duration;
44     duration = static_cast<double>(cv::getTickCount());
45 
46     salt(img, 3000);    
47 
48     duration = static_cast<double>(cv::getTickCount()) - duration;
49     duration /= cv::getTickFrequency();
50 
51     cv::namedWindow("original");    
52     cv::imshow("original", img);
53     cv::namedWindow("altered");    
54     cv::imshow("altered", img2);
55 
56     std::cout << duration << std::endl;
57 
58     cv::waitKey(0);
59     return 0;
60 
61 }
bubuko.com,布布扣

 

opencv学习笔记(01)——操作图像的像素,布布扣,bubuko.com

opencv学习笔记(01)——操作图像的像素

标签:style   blog   class   c   code   java   

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

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