opencvputtext c++
时间: 2023-09-11 13:07:27 浏览: 127
The cv::putText() function in OpenCV is used to draw text on an image. It has the following syntax in C++:
void cv::putText(
InputOutputArray img,
const String& text,
Point org,
int fontFace,
double fontScale,
Scalar color,
int thickness = 1,
int lineType = LINE_8,
bool bottomLeftOrigin = false
);
Where,
- img: Input/output image where the text is to be drawn.
- text: Text string to be drawn.
- org: Bottom-left corner of the text string in the image.
- fontFace: Font type (e.g. FONT_HERSHEY_SIMPLEX, FONT_HERSHEY_PLAIN, etc.).
- fontScale: Font scale factor.
- color: Text color.
- thickness: Thickness of the lines used to draw the text.
- lineType: Type of the line used to draw the text (e.g. LINE_8, LINE_AA).
- bottomLeftOrigin: Flag indicating whether the text origin should be at the bottom-left corner of the text string (true) or at the top-left corner (false).
Example usage:
```
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img(500, 500, CV_8UC3, Scalar(255, 255, 255));
putText(img, "Hello, world!", Point(100, 100), FONT_HERSHEY_SIMPLEX,
1.0, Scalar(0, 0, 255), 2, LINE_AA);
imshow("Image", img);
waitKey(0);
return 0;
}
```
This example creates a 500x500 white image and draws the text "Hello, world!" in red using the FONT_HERSHEY_SIMPLEX font. The text is centered at (100, 100) with a font scale of 1.0 and a thickness of 2. The LINE_AA line type is used to draw anti-aliased lines. The resulting image is displayed and the program waits for a key press before exiting.
阅读全文