【问题标题】:Applying sobel filter on jpg picture with OpenCV 2.4.10 in Java在 Java 中使用 OpenCV 2.4.10 对 jpg 图片应用 sobel 过滤器
【发布时间】:2015-07-29 08:44:23
【问题描述】:

我正在尝试使用 Java 在 jpg 图片上添加 sobel 运算符。我在这里找到了示例:http://www.tutorialspoint.com/java_dip/applying_sobel_operator.htm 但它不起作用。相反,它打印黑色图像。有人可以向我解释我做错了什么吗?其他 imgproc 函数运行良好。

这是我的代码:

 Mat sourceImage = Highgui.imread(sourcePath,  Highgui.CV_LOAD_IMAGE_GRAYSCALE);
    Mat destinationImage = new Mat(sourceImage.rows(), sourceImage.cols(), sourceImage.type());

    Mat kernel = new Mat(kernelSize,kernelSize, CvType.CV_32F){
        {
           put(0,0,-1);
           put(0,1,0);
           put(0,2,1);

           put(1,0-2);
           put(1,1,0);
           put(1,2,2);

           put(2,0,-1);
           put(2,1,0);
           put(2,2,1);
        }
     };      

    Imgproc.filter2D(sourceImage, destinationImage, -1, kernel);          
    Highgui.imwrite(destinationPath, destinationImage);

    //display
    new ShowImage(sourcePath, sourceImage);
    new ShowImage(destinationPath, destinationImage);

【问题讨论】:

    标签: java opencv sobel


    【解决方案1】:

    首先,你不使用有什么原因

    Imgproc.Sobel(Mat src, Mat dst, int ddepth, int dx, int dy);
    

    我不确定这里使用的 Java 语法。 puts 的块什么时候执行?是否假定它是您定义的 Mat 子类的构造函数的一部分?话虽如此,假设这看起来像它打算做的那样,那么您的输出文件类型可能没有正确指定; destinationPath 的值是多少?

    您是否尝试在其他图像查看器中打开保存的文件以确定是ShowImage() 代码还是保存的文件有问题?

    您是否尝试过在十六进制编辑器中打开保存的文件以查看它是否具有“合理”的外观值或全为零?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-11
      • 2012-12-30
      • 1970-01-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      相关资源
      最近更新 更多