opencv在图片上显示文字和数字

官网的api先附上,有c++、python和c中的用法

https://docs.opencv.org/2.4.4/modules/core/doc/drawing_functions.html?highlight=puttext#void%20cvPutText(CvArr*%20img,%20const%20char*%20text,%20CvPoint%20org,%20const%20CvFont*%20font,%20CvScalar%20color)

putText

Draws a text string.

C++: void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false )

Python: cv2.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]]) → None

C: void cvPutText(CvArr* img, const char* text, CvPoint org, const CvFont* font, CvScalar color)

Python: cv.PutText(img, text, org, font, color) → None

Parameters:
  • img – Image.
  • text – Text string to be drawn.
  • org – Bottom-left corner of the text string in the image.
  • font – CvFont structure initialized using InitFont().
  • fontFace – Font type. One of  FONT_HERSHEY_SIMPLEX,  FONT_HERSHEY_PLAIN, FONT_HERSHEY_DUPLEX, FONT_HERSHEY_COMPLEX,  FONT_HERSHEY_TRIPLEX, FONT_HERSHEY_COMPLEX_SMALL, FONT_HERSHEY_SCRIPT_SIMPLEX, or  FONT_HERSHEY_SCRIPT_COMPLEX, where each of the font ID’s can be combined with  FONT_HERSHEY_ITALIC to get the slanted letters.
  • fontScale – Font scale factor that is multiplied by the font-specific base size.
  • color – Text color.
  • thickness – Thickness of the lines used to draw a text.
  • lineType – Line type. See the  line for details.
  • bottomLeftOrigin – When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.

The function putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by question marks. See getTextSize() for a text rendering code example.

所以,在c++的使用方法中,必须有六个参数,举个栗子?

#include “opencv2/imgproc/imgproc.hpp"
for(int i = 0; i < 8; ++i){
        cv::Point2f num =  number.pts[i];
        cv::putText(src, std::to_string(i), num, cv::FONT_HERSHEY_SIMPLEX,0.45, CV_RGB(255,230,0),1.8);
}

假设有一个number对象,里面的pts成员是一个cv::Point2f的数组,我们要在这组点的对应位子显示对应编号,插个图  

                                                                                            

src图像,std::to_string(i)将int转为string,字体类型 cv::FONT_HERSHEY_SIMPLEX,字体大小0.45,字体颜色CV_RGB(255,230,0),字体粗细1.8

 

  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值