问题描述
我是 OpenCV 的新手。我正在尝试对图像应用高斯滤波器。下面的 java 代码对一个图像工作正常,但对于我机器中相同或其他位置的所有其他图像,它会引发错误。
static int width = 49;
static int height = 49;
public static void gausianBlur(){
try {
long startTime = System.currentTimeMillis();
nu.pattern.OpenCV.loadShared();
File f = new File("/Users/shankysharma/Desktop/login.png");
System.out.println("is file exists?: " + f.exists() + " path: " + f.getAbsolutePath());
//Reading the Image from the file and storing it in to a Matrix object
Mat src = Imgcodecs.imread(f.getAbsolutePath());
//Creating an empty matrix to store the result
//Mat dst = new Mat();
Mat dst = new Mat(src.rows(),src.cols(),src.type());
System.out.println(src + " rows: " + src.rows());
Imgproc.GaussianBlur(src,dst,new Size(width,height),0);
Imgcodecs.imwrite(gausian_output + "_" + width + "x" + height + ".png",dst);
long endTme = System.currentTimeMillis();
System.out.println("Image processed for gausian blur. Total time : " + (endTme-startTime) + " milliseconds");
} catch (Exception e) {
System.out.println("Error:" + e.getMessage());
}
}
输出:
is file exists?: true path: /Users/shankysharma/Desktop/login.png
Mat [ -1*-1*CV_8UC1,isCont=false,isSubmat=false,nativeObj=0x7fa6f9c16030,dataAddr=0x0 ] rows: 0
Error:cv::Exception: OpenCV(4.3.0) /Users/jason/Projects/openpnp/opencv/opencv/opencv-4.3.0/modules/imgproc/src/smooth.dispatch.cpp:606: error: (-215:Assertion failed) !_src.empty() in function 'GaussianBlur'
我正在使用 opencv maven 库:
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>4.3.0-3</version>
</dependency>
加载图像 (Mat src = Imgcodecs.imread(f.getAbsolutePath());
) 时似乎存在问题,因为未创建 src
矩阵。但不确定根本原因是什么。我检查了图片的名称和位置,没问题。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)