แพ็คเกจ org.opencv.imgproc ของไลบรารี Java OpenCV มีคลาสที่ชื่อImgproc
ในการวาดวงกลม คุณต้องเรียกใช้ circle() วิธีการของคลาสนี้ วิธีนี้ยอมรับพารามิเตอร์ต่อไปนี้ -
-
วัตถุ Mat ที่แสดงภาพที่จะวาดวงกลม
-
วัตถุจุดแทนจุดศูนย์กลางของวงกลม
-
ตัวแปรจำนวนเต็มแสดงรัศมีของวงกลม
-
วัตถุสเกลาร์ที่แสดงสีของวงกลม (BGR)
-
จำนวนเต็มแสดงถึงความหนาของวงกลม (ค่าเริ่มต้น 1)
ตัวอย่าง
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 DrawingCircle {
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
String file ="D:\\images\\blank.jpg";
Mat src = Imgcodecs.imread(file);
//Drawing a Circle
Point center = new Point(300, 200);
int radius = 100;
Scalar color = new Scalar(64, 64, 64);
int thickness = 10;
Imgproc.circle (src, center, radius, color, thickness);
//Saving and displaying the image
Imgcodecs.imwrite("circle.jpg", src);
HighGui.imshow("Drawing a Circle", src);
HighGui.waitKey();
}
} ผลลัพธ์
ในการดำเนินการ โปรแกรมดังกล่าวจะสร้างหน้าต่างต่อไปนี้ -
