- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to put a text in an image in OpenCV using C++?
In OpenCV, we can put some text in the image by using puttext() function. This function is defined in <imgproc.hpp> header. To put text in an image, we first need to declare the matrix which will load the image.
Instead of loading an image in our program, we have filled matrix with white color, and then we put the text in that matrix. We need to define the text's starting point in the matrix, the text's font, the font's color and the font's weight.
The basic syntax of this method is as follows −
Syntax
putText(image, "Text in Images", text_position,FONT_HERSHEY_COMPLEX, font_size,font_Color, font_weight);
The following program shows the way to put a text in an image in OpenCV.
Example
#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; }
Output
- Related Articles
- How to add text to an image using Java OpenCV library?
- How to save an Image in OpenCV using C++?
- How to rotate an image in OpenCV using C++?
- How to resize an image in OpenCV using Python?
- How to detect a triangle in an image using OpenCV Python?
- How to write an image to a file using OpenCV?
- How to blur faces in an image using OpenCV Python?
- How to detect eyes in an image using OpenCV Python?
- How to approximate a contour shape in an image using OpenCV Python?
- Cartooning an Image using OpenCV in Python?
- Detecting contours in an image using OpenCV
- How to detect faces in an image using Java OpenCV library?
- How to draw polylines on an image in OpenCV using Python?
- How to detect cat faces in an image in OpenCV using Python?
- How to convert an RGB image to HSV image using OpenCV Python?

Advertisements