c++的一些常用语句

本文介绍C++中使用标准输入输出流进行数据交互的方法,包括如何利用cout输出字符串和变量值,以及如何通过cin接收用户输入。此外,还详细讲解了OpenCV中的imread函数,用于从文件读取图像,并解释了不同参数设置下图像颜色类型的变化,以及如何计算灰度图像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、cout:输出字符串

int a=100;

cout<<"a="<<a<<endl;

//控制台输出字符串“a=”,同时紧接着输出变量a的值100

//endl是换行

//需要iostream.h支持

2、cin:输入字符串

int b;

cin>>b;

//控制台中将整形数据传到变量b中

//需要iostream.h支持

3、imread:读取图片

//Loads an image from a file. 从文件中读取图像。

Mat imread(const string& filename, int flags )

>>Parameters: 参数:

  • filename – Name of file to be loaded. 文件名
  • flags –

    Flags specifying the color type of a loaded image:

    • >0 Return a 3-channel color image 返回一个三通道的图像
    • =0 Return a grayscale image 返回灰度图像
    • <0 Return the loaded image as is. Note that in the current implementation the alpha channel, if any, is stripped from the output image. For example, a 4-channel RGBA image is loaded as RGB if flag>=0

>>当flags==0时,可以通过a*R+b*G+c*B=value_grey可以求出RGB的三个权重分别为:

a=76/255=0.298

b=150/255=0.588

c=29/255=0.114

所以可以算出一个像素点的灰度值为:grey=0.298*red+0.588*green+0.114*blue

其中,red ∈(0,255),green ∈(0,255),blue ∈(0,255)

4、

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值