The org.opencv.imgproc แพ็คเกจของไลบรารี Java OpenCV มีคลาสชื่อ Imgproc คลาสนี้มีเมธอดชื่อ circle() เมื่อใช้สิ่งนี้ คุณสามารถวาดวงกลมบนรูปภาพได้ วิธีการนี้มีพารามิเตอร์ดังต่อไปนี้ -
-
วัตถุ Mat ที่แสดงภาพที่จะวาดวงกลม
-
วัตถุจุดแทนจุดศูนย์กลางของวงกลม
-
ตัวแปรจำนวนเต็มแสดงรัศมีของวงกลม
-
วัตถุสเกลาร์ที่แสดงสีของวงกลม (BGR)
-
จำนวนเต็มแสดงถึงความหนาของวงกลม (ค่าเริ่มต้น 1)
หากคุณผ่าน Imgproc.FILLED เป็นประเภทเส้น วิธีนี้จะสร้าง/วาดวงกลมที่เติมสี
ตัวอย่าง
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 DrawingFilledCircle {
public static void main(String args[]) {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//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 a Circle
Point center = new Point(300, 200);
int radius =100;
Scalar color = new Scalar(64, 64, 64);
int thickness = Imgproc.FILLED;
Imgproc.circle (src, center, radius, color, thickness);
//Saving and displaying the image
Imgcodecs.imwrite("arrowed_line.jpg", src);
HighGui.imshow("Drawing a circle", src);
HighGui.waitKey();
}
} ผลลัพธ์
ในการดำเนินการ โปรแกรมดังกล่าวจะสร้างหน้าต่างต่อไปนี้ -
