Home >Java >javaTutorial >How to draw lines with arrows in OpenCV using Java?
The org.opencv.imgproc package of the Java OpenCV library contains a class called Imgproc, which provides various methods to process input images. It provides a set of methods for drawing geometric shapes on images.
To draw a line with an arrow, you need to call the arrowedLine() method of this class. The method accepts the following parameters:
A Mat object representing the image on which the line is to be drawn.
Point object representing two points between lines.
A Scalar object representing the line color. (BGR)
An integer representing the thickness of the line (default: 1).
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(); } }
Execute the above After the procedure, the following window will be generated −
The above is the detailed content of How to draw lines with arrows in OpenCV using Java?. For more information, please follow other related articles on the PHP Chinese website!