【发布时间】: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);
【问题讨论】: