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