Visual Studio 上的 OpenCV 设置问题

met*_*urg 0 configuration opencv visual-studio visual-c++

我正在尝试在 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);
}
Run Code Online (Sandbox Code Playgroud)

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

在“属性->配置属性->链接器->输入->附加依赖项”中,我提供了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.
Run Code Online (Sandbox Code Playgroud)

我对自己的想法无所适从。我对 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)
Run Code Online (Sandbox Code Playgroud)

Per*_*lam 5

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

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

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

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,请保留它,将 vc10 用于 Visual Studio 2010。

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最后表示调试库,如果您不使用调试模式,请不要使用带“d”的库。我添加了非常基本的库,您可能需要根据您的代码添加更多库。

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

您的代码应该没有任何抱怨地构建。但是在运行时,你应该得到一个关于缺少 dll的错误。

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