opencv学习(3)关于Mat类中的Scalar()

来源:互联网 发布:玻璃体混浊 知乎 编辑:程序博客网 时间:2024/05/16 10:30

Mat类中的Scalar()成员有什么用呢?先不急着看资料,看下有什么结果出现吧:先将里边的值设为0

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. #include <opencv2/core/core.hpp>  
  2. #include <opencv2/imgproc/imgproc.hpp>  
  3. #include <opencv2/highgui/highgui.hpp>  
  4.   
  5. using namespace cv;  
  6.   
  7. int main()  
  8. {  
  9.     Mat rawImg(600, 500, CV_8U, Scalar(0)); //这个Scalar函数有啥作用呢?,我们我猜想是灰度值  
  10.                                                 //Mat resultImg;  
  11.   
  12.     namedWindow("Raw Image");  
  13.     imshow("Raw Image", rawImg);  
  14.   
  15.     waitKey(0);  
  16.     destroyAllWindows();  
  17.   
  18.     imwrite("图像.jpg",rawImg);  
  19.   
  20.   
  21.     return 0;  
  22. }  

结果:

再设为scalar(255),结果:

没有设置边框,可以确定是全白的

再设为150,结果:

果然验证了是灰度值,但是为什么是scalar呢?为什么是标量呢?看看彩色图像吧

将程序做修改如下:

[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. Mat rawImg(600, 500, CV_8UC3, Scalar(255, 0, 0));  


然后运行,结果:

然后逐步将参数分别设为0,255,0,结果:

再设为0,0,255,结果:

原来scalar是将图像设置成单一灰度和颜色,怪不得叫scalar。明白了

1 0
原创粉丝点击