我正在尝试使用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);
首先,是否有原因不使用
Imgproc.Sobel(Mat src, Mat dst, int ddepth, int dx, int dy);
我不确定此处使用的Java语法。put
S的块何时执行?是否假定您定义的MAT子类的构造函数的一部分?话虽如此,假设这可以做到它的外观,那么您的输出文件类型可能未正确指定;destinationPath
的值是多少?
您是否尝试过在替代图像查看器中打开保存的文件以确定是ShowImage()
代码还是故障的保存文件?
您是否尝试过在十六进制编辑器中打开保存的文件,以查看其看起来"明智"的值还是所有零是?