
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to add text to an image using Java OpenCV library?
You can add text to an image using the putText() method of the org.opencv.imgproc.Imgproc class. This method renders the specified text in the given image. It accepts −
An empty mat object to store the source image.
A string object to specify the desired text.
A Point object specifying the position of the text.
Integer constant specifying the font of the text.
scale factor that is multiplied by the font-specific base size.
A Scalar object specifying the color of the text.
An integer value specifying the color of the text
Example
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class AddingText { public static void main(String args[]) throws Exception { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading the contents of the image String file ="D:\Images\shapes.jpg"; Mat src = Imgcodecs.imread(file); //Preparing the arguments String text = "JavaFX 2D shapes"; Point position = new Point(170, 280); Scalar color = new Scalar(0, 0, 255); int font = Imgproc.FONT_HERSHEY_SIMPLEX; int scale = 1; int thickness = 3; //Adding text to the image Imgproc.putText(src, text, position, font, scale, color, thickness); //Displaying the resultant Image HighGui.imshow("Contours operation", src); HighGui.waitKey(); } }
Input Image
Output
- Related Articles
- How to add noise to an image using Java OpenCV library?
- How to add borders to an image using Java OpenCV library?
- How to write an image using Java OpenCV library?
- How to flip an image using Java OpenCV library?
- How to detect faces in an image using Java OpenCV library?
- How to draw markers on an image using Java OpenCV library?
- How to find Image Contours using Java OpenCV library?
- How to draw Image Contours using Java OpenCV library?
- How to create a watermark on an image using Java OpenCV library?
- How to alter the contrast of an image using Java OpenCV library?
- How to alter the brightness of an image using Java OpenCV library?
- How to alter the sharpness of an image using Java OpenCV library?
- How to create a mirror image using Java OpenCV library?
- How to convert RGB image to HSV using Java OpenCV library?
- How to convert HSV to colored image using Java OpenCV library?

Advertisements