官网的api先附上,有c++、python和c中的用法
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: |
|
---|
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