Java OpenCV 라이브러리의 org.opencv.imgproc 패키지에는 Imgproc이라는 클래스가 포함되어 있습니다. 타원을 그리려면 ellipse()를 호출해야 합니다. 이 클래스의 메소드. 이 메소드는 다음 매개변수를 받아들입니다 -
-
타원이 그려질 이미지를 나타내는 Mat 개체입니다.
-
RotatedRect 개체(타원은 이 사각형에 내접하여 그려집니다.)
-
Rectangle(BGR)의 색상을 나타내는 Scalar 객체입니다.
-
Rectangle의 두께를 나타내는 정수(기본값:1).
예시
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.RotatedRect; import org.opencv.core.Scalar; import org.opencv.core.Size; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class DrawingEllipse { 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 Ellipse RotatedRect box = new RotatedRect(new Point(300, 200), new Size(260, 180), 180); Scalar color = new Scalar(64, 64, 64); int thickness = 10; Imgproc.ellipse (src, box, color, thickness); //Saving and displaying the image Imgcodecs.imwrite("arrowed_line.jpg", src); HighGui.imshow("Drawing an ellipse", src); HighGui.waitKey(); } }
출력
실행 시 위의 프로그램은 다음과 같은 창을 생성합니다. -