OpenCV에서는 puttext() 함수를 사용하여 이미지에 텍스트를 넣을 수 있습니다. 이 함수는
프로그램에서 이미지를 로드하는 대신 흰색으로 행렬을 채운 다음 해당 행렬에 텍스트를 넣습니다. 매트릭스에서 텍스트의 시작점, 텍스트의 글꼴, 글꼴의 색상 및 글꼴의 두께를 정의해야 합니다.
이 방법의 기본 구문은 다음과 같습니다 -
구문
putText(image, "Text in Images", text_position,FONT_HERSHEY_COMPLEX, font_size,font_Color, font_weight);
다음 프로그램은 OpenCV에서 이미지에 텍스트를 넣는 방법을 보여줍니다.
예시
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<string>
using namespace cv;
using namespace std;
int main() {
Mat image=Mat(400, 400, CV_8UC3, Scalar(255, 255, 255));//Creating an empty matrix filled with white color//
Point text_position(80, 80);//Declaring the text position//
int font_size = 1;//Declaring the font size//
Scalar font_Color(0, 0, 0);//Declaring the color of the font//
int font_weight = 2;//Declaring the font weight//
putText(image, "Text in Images", text_position,FONT_HERSHEY_COMPLEX, font_size,font_Color, font_weight);//Putting the text in the matrix//
imshow("Image", image);//Showing the image//
waitKey(0);//Wait for Keystroke//
return 0;
} 출력
