【问题标题】:Trouble with OpenCV setup on Visual StudioVisual Studio 上的 OpenCV 设置问题
【发布时间】:2014-10-19 19:16:36
【问题描述】:

我正在尝试在 64 位 Windows 7 系统中使用 Microsoft Visual Studio 2008 设置一个简单的 OpenCV 项目。我没有系统管理员权限,因此我不能在这里重新安装 OpenCV。

但是,我确实有 OpenCV 的 bin、include 和 lib 目录,它们是在类似的平台上编译的。

我启动了一个“Visual C++ -> General -> Empty Project”并创建了一个 .cpp 文件,内容如下:

#include <opencv/cv.h>
#include <opencv/highgui.h>
void main()
{
    cv::Mat frame = cv::imread("D:\\Images\\lena.bmp");
    cv::imwrite("D:\\lena_bw.bmp",frame);
}

在'Property->Configuration Property->C/C++->General->Additional Include Directories'中,我提供了OpenCV的'include'目录的链接。

在'Property->Configuration Property->Linker->Input->Additional Dependencies'中,我提供了opencv_core230.lib、opencv_highgui230.lib、opencv_imgproc230.lib等的路径

代码构建良好,但是当我运行它时,我得到:

Unhandled exception at 0x734761e7 in OpenCVTest.exe: 0xC0000005: Access violation reading location 0xcccccccc.

No symbols are loaded for any call stack frame. The source code cannot be displayed.

我自己的想法无处可去。我对 Visual Studio 平台有点陌生。

请帮我找出一种方法来完成这项工作。

++++++++++++++++++++++++++++++++++++++++++++++++++ +

在“发布”模式下运行时,在编译过程中出现以下错误:

1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray@cv@@QAE@ABVMat@1@@Z)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPAX@Z)
1>HelloOpenCV.obj : error LNK2001: 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@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate@Mat@cv@@QAEXXZ)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "bool __cdecl cv::imwrite(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &,class std::vector<int,class std::allocator<int> > const &)" (?imwrite@cv@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV_InputArray@1@ABV?$vector@HV?$allocator@H@std@@@3@@Z)

【问题讨论】:

  • 你是否在debug进行项目,如果是,请将其更改为Release,然后再次设置include,lib等。如果你想继续工作在debug 模式下,添加调试库,即 opencv_core230.lib 应该有 opencv_core230d.lib。
  • 尝试了发布和调试...仍然没有运气。
  • 你还需要为库添加路径,属性->配置属性->C/C++->常规->库目录OR属性->配置属性->C /C++->链接器->附加库依赖->添加包含lib的目录,路径应该有点像:..\OpenCV\build\x64\vc9\lib如果vc不行就试试vc10。
  • 请检查我的问题的更新...我尝试添加 lib 目录,但没有区别。

标签: visual-studio opencv visual-c++ configuration


【解决方案1】:

我正在为您提供不需要管理员权限的详细设置说明。避免在C盘做事。

1) 启动 VS2010 并选择“新建项目...”。

2) 选择“Empty Project”,输入名称,选择放置项目的位置。按“确定”。

3) 现在我们从头开始创建了一个项目。是时候链接这些库并让我们的项目使用 OpenCV。 通过单击下面的选项卡切换到属性管理器。如果找不到该选项卡,您可以从菜单视图访问属性管理器。

4) 默认属性是针对 32 位系统的(注意 Win32 后缀),因为您使用的是 64 位系统,从现在开始我将介绍 64 位系统的配置。 如果您的已经是 x64 或者您想使用 32 位开发,请离开此步骤。 从“构建”菜单中,选择“配置管理器”。在“活动解决方案平台”下,Win32 应该默认选择。单击它并选择“新建...”。 选择“x64”作为新平台,然后选择 Win32 来复制设置。确保选中“创建新项目平台”。

5) INCLUDE 在“Common Properties” -> “C/C++” -> “General”下,编辑“Additional Include Directories”并添加浏览此路径以添加“..\OpenCV\build\include”。请务必选择“build”文件夹下的“include”文件夹,而不是任何其他“include”文件夹。

6) LINK LIB 在“Common Properties” -> “Linker” -> “General”下,编辑“Additional Library Directories”并添加“..\OpenCV\build\x64\vc9\lib”。这里“x64”代表 64 位系统,如果您使用 32 位,请将其更改为 x86。 “vc9”代表 Visual C++ 2008,假设您使用的是 VS2008,请保留它,对于 Visual Studio 2010 使用 vc10。

7) LIB INPUT 在“Common Properties” -> “Linker” -> “Input”下,编辑“Additional Dependencies”并添加以下lib文件:

[用于调试]

opencv_core242d.lib

opencv_highgui242d.lib

opencv_imgproc242d.lib

[发布]

opencv_core242.lib

opencv_highgui242.lib

opencv_imgproc242.lib

这里,命名为:LibName_Version_Debug.lib 即opencv_imgproc242d.lib是opencv_imgproc是库名,242是opencv版本,d最后表示调试库,如果你没有使用debug模式,不要'不要使用带有“d”的库。 我已经添加了非常基本的库,您可能需要根据您的代码添加更多。

8) 除链接库文件名外,“发布”配置的步骤相同。你只需要去掉点之前的“d”字母。

您的代码应该在没有任何抱怨的情况下构建。但是在运行时,您应该会收到关于 缺少 dll 的错误消息。

9) DLL 在您的项目文件夹中找到 exe/output,根据您的开发模式,它的名称应该是 release/debug,它应该有一个输出的 exe 文件。从“..\OpenCV\build\x64\vc9\bin”(对于 x64)或“..\OpenCV\build\x64\vc9\bin”复制 dll 文件(如果使用调试模式,则以字母“d”结尾) (对于 32 位)和该文件夹。

【讨论】:

  • 感谢您的回复。反正我修好了。这是我做错的地方:在“通用属性”->“链接器”->“输入”中,我提供了.lib 文件的完全限定路径。相反,我只使用名称,并将 lib 文件放在项目的根目录中,它起作用了!
  • 感谢您的帮助。 :)
  • openCV 3.2最新版本,opencv_world320.lib和opencv_world320d.lib只需要执行以上步骤
【解决方案2】:

在 opencv300 中,您需要 opencv_imgcodecs300.lib 用于 imread()/imwrite()。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-17
    • 1970-01-01
    • 2011-10-24
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    相关资源
    最近更新 更多