คุณสามารถวาดผู้สร้างบนภาพโดยใช้ drawMarker() วิธีการของ org.opencv.imgproc.Imgproc ระดับ. วิธีนี้ยอมรับพารามิเตอร์ต่อไปนี้ -
-
img − วัตถุ Mat ที่แสดงภาพอินพุต
-
ตำแหน่ง − วัตถุของคลาส ชี้ เพื่อระบุตำแหน่งของเครื่องหมาย
-
สี − วัตถุของคลาส Scalar เพื่อระบุสีของเครื่องหมาย
-
ประเภทเครื่องหมาย − ค่าคงที่จำนวนเต็มที่ระบุประเภทของเครื่องหมาย
-
ขนาด − ค่าจำนวนเต็มที่ระบุขนาดของมาร์กเกอร์
-
ความหนา − ค่าจำนวนเต็มที่ระบุความหนาของมาร์กเกอร์
ตัวอย่าง
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 DrawingMarkers {
public static void main(String args[]) throws Exception {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//Reading the contents of the image
String file ="D:\\Images\\elephant.jpg";
Mat src = Imgcodecs.imread(file);
//Preparing color and position of the marker
Scalar color = new Scalar(0, 0, 125);
Point point = new Point(150, 260);
//Drawing marker
Imgproc.drawMarker(src, point, color, Imgproc.MARKER_SQUARE, 150, 8, Imgproc.LINE_8);
HighGui.imshow("Drawing Markers", src);
HighGui.waitKey();
}
} ใส่รูปภาพ

ผลลัพธ์
ในการดำเนินการโปรแกรมข้างต้นจะสร้างหน้าต่างต่อไปนี้ -
