OpenCV报错


OpenCV官方栗子执行报错:
Running DetectFaceDemo
Detected 0 faces Writing faceDetection.png *libpng warning: Image width is zero in IHDR libpng warning: Image height is zero in IHDR libpng error: Invalid IHDR data*
 原因:路径问题,java代码getPath()返回的路径前面多个/,c++中不识别,解决方法如下。
System.out.println("\nRunning DetectFaceDemo");
// Create a face detector from the cascade file in the resources
// directory.
CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("/lbpcascade_frontalface.xml").getPath());
Mat image = Imgcodecs.imread(getClass().getResource("/lena.png").getPath());

 修改为:

final URI xmlUri = getClass().getResource("/lbpcascade_frontalface.xml").toURI();
final CascadeClassifier faceDetector = new CascadeClassifier(new File(xmlUri).getAbsolutePath());
final URI imageUri = getClass().getResource("/4.jpg").toURI();
Mat image = Imgcodecs.imread(new File(imageUri).getAbsolutePath());


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM