// 读取opencv人脸检测器
InputStream inputStream = *FaceUtils*.class.getClassLoader().getResourceAsStream("lbpcascade_frontalface.xml");
if (inputStream == null) {
throw new FileNotFoundException("Resource lbpcascade_frontalface.xml not found");
}
File tempFile = File.createTempFile("lbpcascade_frontalface", ".xml");
tempFile.deleteOnExit();
try (FileOutputStream out = new FileOutputStream(tempFile)) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
// 读取opencv人脸检测器
// CascadeClassifier cascade = new CascadeClassifier("F:\\HuaYi\\project\\community\\springboot\\src\\main\\resources\\lbpcascade_frontalface.xml");
CascadeClassifier cascade = new CascadeClassifier(tempFile.getAbsolutePath());
FaceUtils是当前文件,这个写法不管在什么地方都可以获得Resource下的文件