
- 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 draw markers on an image using Java OpenCV library?
You can draw makers on an image using the drawMarker() method of the org.opencv.imgproc.Imgproc class. This method accepts the following parameters −
img − A Mat object representing the input image.
position − An object of the class Point to specify the position of the marker.
color − An object of the class Scalar to specify the color of the marker.
markerType − An integer constant specifying the type of the marker.
size − An integer value specifying the size of the marker.
thickness − An integer value specifying the thickness of the marker.
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 DrawingMarkers { 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\elephant.jpg"; Mat src = Imgcodecs.imread(file); //Preparing color and position of the marker Scalar color = new Scalar(0, 0, 125); Point point = new Point(150, 260); //Drawing marker Imgproc.drawMarker(src, point, color, Imgproc.MARKER_SQUARE, 150, 8, Imgproc.LINE_8); HighGui.imshow("Drawing Markers", src); HighGui.waitKey(); } }
Input Image
Output
On executing the above program generates the following window −
- Related Articles
- How to draw geometrical shapes on image using OpenCV Java Library?
- How to draw Image Contours using Java OpenCV library?
- How to create a watermark on 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 add noise to an image using Java OpenCV library?
- How to add text to an image using Java OpenCV library?
- How to add borders to an image using Java OpenCV library?
- Draw rectangle on an image using OpenCV
- Draw an ellipse on an image using OpenCV
- How to detect faces in an image using Java OpenCV library?
- Draw a line on an image using OpenCV
- How to draw polylines on an image in OpenCV using Python?
- How to find Image Contours using Java OpenCV library?
- How to alter the contrast of an image using Java OpenCV library?

Advertisements