Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 draw an arrowed line in OpenCV using Java?
The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc this class provides various methods to process an input image. It provides a set of methods to draw geometrical shapes on images.
To draw an arrowed line you need to invoke the arrowedLine() method of this class. This method accepts the following parameters −
A Mat object representing the image on which the line is to be drawn.
Two Point objects representing the points between which the line is to be drawn.
A Scalar object representing the color of the line. (BGR)
An integer representing the thickness of the line(default:1).
Example
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.highgui.HighGui;
public class DrawingArrowedLine {
public static void main(String args[]) {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//Reading the source image in to a Mat object
Mat src = Imgcodecs.imread("D:\images\blank.jpg");
//Drawing an arrowed line
Point start = new Point(100, 200);
Point end = new Point(500, 200);
Scalar color = new Scalar(64, 64, 64);
int thickness = 10;
Imgproc.arrowedLine(src, start, end, color, thickness);
//Saving and displaying the image
Imgcodecs.imwrite("arrowed_line.jpg", src);
HighGui.imshow("Drawing an arrowed line", src);
HighGui.waitKey();
}
}
Output
On executing, the above program generates the following window −

Advertisements