java - 使用 CannyEdgeDetection.java 的输出文件中没有边缘

标签 java bufferedimage edge-detection

使用默认值以及网站上第一个示例中的相同源图像:http://www.tomgibara.com/computer-vision/canny-edge-detector我得到一个纯黑色图像作为我的 out.jpg。尺寸正确,但未检测到边缘。

有人可以告诉我如何复制第一个示例吗?

我的代码:

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;

public class CannyCmd
{

    public static void main(String args[])
    {

        BufferedImage img = null;

        try
        {
            img = ImageIO.read(new File("in.jpg"));
        }
        catch (Exception e)
        {
          e.printStackTrace();
          System.exit(1);
        }


        CannyEdgeDetector detector = new CannyEdgeDetector();
        detector.setSourceImage(img);
        detector.process();
        BufferedImage edges = detector.getEdgesImage();

        File saveFile = new File("out.jpg");

        try 
        {
            ImageIO.write(edges, "jpg", saveFile);
        } 
        catch (IOException ex) {} 

    }
}

最佳答案

 File saveFile = new File("out.png"); 
 ImageIO.write(edges, "png", saveFile);

关于java - 使用 CannyEdgeDetection.java 的输出文件中没有边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16653955/

相关文章:

Java BufferedImage 灰度到RGB转换

c++ - 边缘检测/角度

graphviz - 如何控制 graphviz 中的节点放置(即避免边缘交叉)

python - OpenCV canny 边缘检测在理想正方形上无法正常工作

java - Eclipse 字体看起来很奇怪

java - Java中序列化的目的是什么?

java - 防止 Java XML Web 服务中的枚举

java - 用递归算法画分形

java - 如何使用 BITMASK 透明度创建 BufferedImage?

java - 从 BufferedImage 到 SWT Image 的转换