【问题标题】:Visual Studio - Imread system cannot find the file specifiedVisual Studio - Imread 系统找不到指定的文件
【发布时间】:2019-11-21 07:24:33
【问题描述】:

我在使用 OpenCV for Visual Studio 2017 读取图像时遇到很大问题

我的程序在它确实存在时无法找到我的图像(我多次检查它确实存在于我的 E:/ 驱动器上)。我已将图像放在相对路径、绝对路径上,但无论我尝试什么似乎都无关紧要,它仍然无法找到图像。我还将图像与 .exe 程序放在同一个文件夹中,并将其添加为资源等。

 Mat img = imread("E:\\test.jpg", 0);
 Mat img = imread("E:/test.jpg", 0);
 Mat img = imread("E:\test.jpg", 0);
 Mat img = imread("test.jpg", 0);

以上所有示例都返回了所提供图像中的错误。

这些是我的导入:

  #include "opencv2/core/core.hpp"
  #include "opencv2/highgui/highgui.hpp"
  #include "opencv2/imgproc/imgproc.hpp"
  #include <iostream>
  #include <math.h>

我尝试了一些可能的修复方法,但它们根本不起作用。我假设我的问题与 Visual Studio 相关,而不是 OpenCV(我的 OpenCV 已正确安装)。我的项目设置中的设置是否错误?还是我的问题与其他问题有关?

构建错误:

1>------ Build started: Project: Alphatree, Configuration: Debug x64 ------
1>main.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread@cv@@YA?AVMat@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function main
1>E:\In-company research project\In-company-research\ConsoleApplication4\Alphatree.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "ConsoleApplication4.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

【问题讨论】:

  • Visual Studio 找不到您的程序,这与您的图像无关。它甚至编译成功了吗?
  • 是的,它编译成功,但是构建失败。每当我删除 Imread 时,程序都可以正常工作,并且编译/构建/运行成功
  • 什么是构建错误?
  • 我在正文中添加了构建错误

标签: c++ visual-studio opencv


【解决方案1】:

我已经解决了这个问题,问题是我没有包含 OpenCV 提供的每个库,而是只使用了 3 个。现在我包含了程序工作的每个库,请注意这些是调试库!

opencv_calib3d411d.lib
opencv_core411d.lib
opencv_dnn411d.lib
opencv_features2d411d.lib
opencv_flann411d.lib
opencv_gapi411d.lib
opencv_highgui411d.lib
opencv_imgcodecs411d.lib
opencv_imgproc411d.lib
opencv_ml411d.lib
opencv_objdetect411d.lib
opencv_photo411d.lib
opencv_stitching411d.lib
opencv_video411d.lib
opencv_videoio411d.lib

【讨论】:

  • 请注意,您只需要 opencv_highgui411d.lib、opencv_videoio411d.lib、opencv_imgcodecs411d.lib 即可修复您的错误。
猜你喜欢
  • 2017-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-01
  • 1970-01-01
  • 2021-08-08
相关资源
最近更新 更多