캐니 에지 감지기는 기존 에지만 감지하고 페이지당 하나의 응답만 제공하며 에지 픽셀과 감지된 픽셀 사이의 거리를 최소화하므로 최적 감지기로 알려져 있습니다.
캐니() Imgproc 클래스의 메소드는 주어진 이미지에 캐니 에지 감지 알고리즘을 적용합니다. 이 방법은 -
를 받아들입니다.-
소스 및 대상 이미지를 나타내는 두 개의 매트 개체입니다.
-
임계값을 유지하기 위한 두 개의 이중 변수.
canny edge detector를 사용하여 주어진 이미지의 가장자리를 감지하려면 -
-
imread()를 사용하여 소스 이미지의 내용을 읽습니다. Imgcodecs 방법 수업.
-
cvtColor()를 사용하여 회색조 이미지로 변환합니다. Imgproc 메소드 수업.
-
blur()를 사용하여 결과(회색) 이미지를 흐리게 처리합니다. Imgproc 메소드 커널 값이 3인 클래스.
-
canny()를 사용하여 흐릿한 이미지에 canny edge 감지 알고리즘 적용 Imgproc 메소드 .
-
모든 값이 0인 빈 행렬을 만듭니다.
-
copyTo()를 사용하여 감지된 가장자리를 가장자리에 추가합니다. 매트 방법 수업.
예
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javafx.application.Application;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.stage.Stage;
import org.opencv.core.Core;
import org.opencv.core.Mat;
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 EdgeDetection extends Application {
public void start(Stage stage) throws IOException {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
String file ="D:\\Images\\win2.jpg";
Mat src = Imgcodecs.imread(file);
//Creating an empty matrices to store edges, source, destination
Mat gray = new Mat(src.rows(), src.cols(), src.type());
Mat edges = new Mat(src.rows(), src.cols(), src.type());
Mat dst = new Mat(src.rows(), src.cols(), src.type(), new Scalar(0));
//Converting the image to Gray
Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGB2GRAY);
//Blurring the image
Imgproc.blur(gray, edges, new Size(3, 3));
//Detecting the edges
Imgproc.Canny(edges, edges, 100, 100*3);
//Copying the detected edges to the destination matrix
src.copyTo(dst, edges);
//Converting matrix to JavaFX writable image
Image img = HighGui.toBufferedImage(dst);
WritableImage writableImage= SwingFXUtils.toFXImage((BufferedImage) img, null);
//Setting the image view
ImageView imageView = new ImageView(writableImage);
imageView.setX(10);
imageView.setY(10);
imageView.setFitWidth(575);
imageView.setPreserveRatio(true);
//Setting the Scene object
Group root = new Group(imageView);
Scene scene = new Scene(root, 595, 400);
stage.setTitle("Gaussian Blur Example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]) {
launch(args);
}
} 입력 이미지

출력
실행 시 위의 결과는 다음과 같이 출력됩니다. -
