opencv_worldxxx.dll 與執行時載入的版本不同(如專案設定 x64 卻放了 x86 DLL)。Copy to Output Directory)。opencv_imgcodecs 模組,導致 imread 回傳空 Mat 而非拋出異常;若程式碼未檢查 empty() 後續操作會崩潰。// 1. 印出完整路徑確認
std::string path = "test.jpg";
cv::Mat img = cv::imread(path);
if (img.empty()) {
std::cerr << "無法載入: " << cv::samples::findFile(path) << std::endl;
return -1;
}
// 2. 檢查 DLL 依賴:Dependency Walker / ldd 查看遺漏庫
// 3. 專案屬性 → Linker → Input → Additional Dependencies 確認版本一致
寫一個極簡主程式只呼叫 imread + imshow,若能跑通說明環境正常,再逐步加入專案代碼定位問題。