putText()를 사용하여 이미지에 텍스트를 추가할 수 있습니다. org.opencv.imgproc.Imgproc 클래스의 메소드 . 이 메서드는 지정된 이미지에서 지정된 텍스트를 렌더링합니다. 그것은 받아들입니다 -
-
소스 이미지를 저장할 빈 매트 개체입니다.
-
원하는 텍스트를 지정하는 문자열 개체입니다.
-
텍스트의 위치를 지정하는 Point 개체입니다.
-
텍스트의 글꼴을 지정하는 정수 상수입니다.
-
글꼴별 기본 크기를 곱한 배율입니다.
-
텍스트의 색상을 지정하는 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 AddingText {
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\\shapes.jpg";
Mat src = Imgcodecs.imread(file);
//Preparing the arguments
String text = "JavaFX 2D shapes";
Point position = new Point(170, 280);
Scalar color = new Scalar(0, 0, 255);
int font = Imgproc.FONT_HERSHEY_SIMPLEX;
int scale = 1;
int thickness = 3;
//Adding text to the image
Imgproc.putText(src, text, position, font, scale, color, thickness);
//Displaying the resultant Image
HighGui.imshow("Contours operation", src);
HighGui.waitKey();
}
} 입력 이미지

출력
