Home > Java > javaTutorial > body text

How to draw lines with arrows in OpenCV using Java?

王林
Release: 2023-08-20 14:41:09
forward
1203 people have browsed it

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.

drawn.
  • A Scalar object representing the line color. (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();
       }
    }
    Copy after login

    Output

    Execute the above After the procedure, the following window will be generated −

    How to draw lines with arrows in OpenCV using Java?

    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!

    Related labels:
    source:tutorialspoint.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template