OpenCV 2.4 putText() and Scalar understanding

OpenCV 2.4 putText() and Scalar understanding

本文关键字:and Scalar understanding putText OpenCV      更新时间:2023-10-16

我在C++中使用OpenCV 2.4.11。我想在我的图片上显示带有putText()功能的文本。
例如:

putText(imageOutput,"x:",Point(pos[0],pos[1]),1,1,Scalar(255,0,0),2);

Scalar输入有什么作用?是否有替代输入而不是Scalar

您的代码:

putText(imageOutput,"x:",Point(pos[0],pos[1]),1,1,Scalar(255,0,0),2); 

您的问题:

标量函数有什么作用?

您正在创建一个标量对象,您可以在此处查看文档

如果要创建 BGR(全彩色)图像,则可以使用 Scalar(B,G,R) 初始化标量。但是,如果您只想要灰度图像,您需要做的就是使用灰度值对其进行初始化:

Scalar(greyScaleValue);

所以你的代码将是:

putText(imageOutput,"x:",Point(pos[0],pos[1]),1,1,Scalar(30),2); 

灰度值为 30。