发布时间:2022-08-18 18:16
本文是在上一篇博文[Ubuntu 16.04下静态编译OpenCV 3.4.14集成OpenCL调用Intel® HD Graphics NEO实现GPU加速]驱动了Intel® HD Graphics NEO的基础上进行的。
1 GPU devices are detected.
name: Intel(R) Gen9 HD Graphics NEO
available: 1
imageSupport: 1
OpenCL_C_Version: OpenCL C 2.0
本来顺便把Java调用的Jar包也编译出来了,但发现竟然没有UMat
…
查了OpenCV3.4的官方文档,确实没有关于UMat
的说明。Stack Overflow上有类似的疑问opencv-transparent-api-umat-is-missing
使用Github上的JavaCV开源实现即可。
在pom.xml
添加如下内容
<dependency>
<groupId>org.bytedecogroupId>
<artifactId>javacv-platformartifactId>
<version>1.5.6version>
dependency>
import org.bytedeco.opencv.opencv_core.*;
import static org.bytedeco.opencv.global.opencv_core.*;
import static org.bytedeco.opencv.global.opencv_imgproc.*;
import static org.bytedeco.opencv.global.opencv_imgcodecs.*;
public class App
{
public static void main(String[] args)
{
long start = 0l, end = 0l;
Mat image = imread("./Lena.png"); // 随便找了一张图片
Mat src0 = new Mat(20000, 20000, CV_8UC3); // 将图片大小放大到20000×20000
resize(image, src0, new Size(20000, 20000));
UMat src1 = new UMat(20000, 20000, CV_8UC3);
src0.copyTo(src1);
// Mat
start = System.currentTimeMillis();
blur(src0, src0, new Size(1, 1));
end = System.currentTimeMillis();
System.out.println("Mat running times:" + (end - start) + "ms");
// UMat
start = end = 0l;
start = System.currentTimeMillis();
blur(src1, src1, new Size(1, 1));
end = System.currentTimeMillis();
System.out.println("UMat running times:" + (end - start) + "ms");
}
}
Mat running times:884ms
UMat running times:1ms