Frame frame = null;
OpenCVFrameConverter cv = new OpenCVFrameConverter.ToMat();
// 只抓取图像画面
if((frame = grabber.grabImage()) != null) {
Mat src = cv.convertToOrgOpenCvCoreMat(frame);
try {
Mat target = new Mat();//二值化后的图像
Imgproc.threshold(src, target, 30, 255, Imgproc.THRESH_BINARY| Imgproc.THRESH_OTSU );//灰度图像二值化
Imgcodecs.imwrite(output, target);
} catch (Exception e) {
e.printStackTrace();
}
}
grabber.close();//close包含stop和release方法
本来想着从frame中提取mat,然后进行二值转换,但是二值转换需要的是org.opencv.core.mat,从frame中拿到的却是org.bytedeco.opencv.opencv_core,看了网友们的博客,需要用OpenCVFrameConverter进行转换,也不知道哪里出问题了,运行到OpenCVFrameConverter初始化的时候就报错。下面是报错的内容,其实也挺简单就是缺包,但网上就是找不到相关的包,求指点一二。
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopenblas_nolapack in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1631)
at org.bytedeco.javacpp.Loader.load(Loader.java:1265)
at org.bytedeco.javacpp.Loader.load(Loader.java:1109)
at org.bytedeco.openblas.global.openblas_nolapack.<clinit>(openblas_nolapack.java:12)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.bytedeco.javacpp.Loader.load(Loader.java:1176)
at org.bytedeco.javacpp.Loader.load(Loader.java:1125)
at org.bytedeco.javacv.OpenCVFrameConverter.<clinit>(OpenCVFrameConverter.java:43)