简体   繁体   English

在Visual Studio 2008上安装OpenCV 2.4.5

[英]Installation of OpenCV 2.4.5 on Visual Studio 2008

I'm having some difficulties trying to use OpenCV with visual studio 2008 (Professional Edition). 我在使用Visual Studio 2008(专业版)时尝试使用OpenCV遇到了一些困难。 I believe I've done everything necessary to run a OpenCV sample, but it crashes due to a run-time error. 我相信我已经完成了运行OpenCV示例所需的一切,但由于运行时错误导致崩溃。 This is driving me insane, I hope someone can help. 这让我疯了,我希望有人可以提供帮助。

But first things first. 但首先要做的事情。

My Installation Procedure 我的安装程序

  1. Downloaded OpenCV 2.4.5 from sourcefourge.net. 从sourcefourge.net下载OpenCV 2.4.5

  2. When prompted, I chose "Z:\\Games instalados\\OpenCV" as my "Extract to" option in the .exe downloaded from the above link. 出现提示时,我选择“Z:\\ Games instalados \\ OpenCV”作为从上面链接下载的.exe中的“Extract to”选项。

  3. Went to "Control Panel" -> "System" -> "Advanced System Settings", then clicked on the "Environment Variables" in the "Advanced" tab. 转到“控制面板” - >“系统” - >“高级系统设置”,然后单击“高级”选项卡中的“环境变量”。 In the "System Variables" box I highlighted "Path" and clicked on "Edit...". 在“系统变量”框中,我突出显示“路径”,然后单击“编辑...”。 In the new window I added to the end of the text in "Variable Value" my installation directory with a ";" 在新窗口中,我在“变量值”的文本末尾添加了一个带有“;”的安装目录 before it, namely ";Z:\\Games instalados\\OpenCV\\opencv\\build\\x86\\vc11\\bin" (without the double quotes). 在它之前,即“; Z:\\ Games instalados \\ OpenCV \\ opencv \\ build \\ x86 \\ vc11 \\ bin”(不带双引号)。 Here's a screenshot: 这是一个截图: 截图 .

  4. Created a new project in Visual Studio 2008: File -> New -> Project..., chose "Other Languages" -> "Visual C++ -> "Win32" as the project type; "Win32 Console Application" as the template. 在Visual Studio 2008中创建了一个新项目:File - > New - > Project ...,选择“Other Languages” - >“Visual C ++ - >”Win32“作为项目类型;”Win32 Console Application“作为模板。 新项目 Clicked "next" in the new window, then chose "Console Application", "Empty Project" and then "Finish". 在新窗口中单击“下一步”,然后选择“控制台应用程序”,“清空项目”,然后选择“完成”。 新窗户
  5. In the "Solution Explorer", right-clicked my program and chose "Properties". 在“解决方案资源管理器”中,右键单击我的程序并选择“属性”。 Then "Configuration Properties" -> "C/C++" -> "General", and on Additional Include Directories I've added: 然后“配置属性” - >“C / C ++” - >“常规”,以及我添加的其他包含目录:
    • Z:\\Games instalados\\OpenCV\\opencv\\build\\include Z:\\ Games instalados \\ OpenCV \\ opencv \\ build \\ include
    • Z:\\Games instalados\\OpenCV\\opencv\\build\\include\\opencv Z:\\ Games instalados \\ OpenCV \\ opencv \\ build \\ include \\ opencv
    • Z:\\Games instalados\\OpenCV\\opencv\\build\\include\\opencv2 " Z:\\ Games instalados \\ OpenCV \\ opencv \\ build \\ include \\ opencv2“ 附加包括
  6. Now in "Configuration Properties" -> "C/C++" -> "Linker" -> "General", in the "Additional Library Directories" I've added "Z:\\Games instalados\\OpenCV\\opencv\\build\\x86\\vc11\\lib". 现在在“配置属性” - >“C / C ++” - >“链接器” - >“常规”中,在“附加库目录”中我添加了“Z:\\ Games instalados \\ OpenCV \\ opencv \\ build \\ x86 \\ VC11 \\ LIB”。 附加图书馆
  7. Now in "Configuration Properties" -> "C/C++" -> "Linker" -> "Input", in the "Additional Dependencies" I've added: 现在在“配置属性” - >“C / C ++” - >“链接器” - >“输入”中,在“附加依赖项”中我添加了:
    • opencv_calib3d245.lib opencv_calib3d245.lib
    • opencv_contrib245.lib opencv_contrib245.lib
    • opencv_core245.lib opencv_core245.lib
    • opencv_features2d245.lib opencv_features2d245.lib
    • opencv_flann245.lib opencv_flann245.lib
    • opencv_gpu245.lib opencv_gpu245.lib
    • opencv_highgui245.lib opencv_highgui245.lib
    • opencv_imgproc245.lib opencv_imgproc245.lib
    • opencv_legacy245.lib opencv_legacy245.lib
    • opencv_ml245.lib opencv_ml245.lib
    • opencv_nonfree245.lib opencv_nonfree245.lib
    • opencv_objdetect245.lib opencv_objdetect245.lib
    • opencv_photo245.lib opencv_photo245.lib
    • opencv_stitching245.lib opencv_stitching245.lib
    • opencv_superres245.lib opencv_superres245.lib
    • opencv_ts245.lib opencv_ts245.lib
    • opencv_video245.lib opencv_video245.lib
    • opencv_videostab245.lib opencv_videostab245.lib
    • opencv_calib3d245d.lib opencv_calib3d245d.lib
    • opencv_contrib245d.lib opencv_contrib245d.lib
    • opencv_core245d.lib opencv_core245d.lib
    • opencv_features2d245d.lib opencv_features2d245d.lib
    • opencv_flann245d.lib opencv_flann245d.lib
    • opencv_gpu245d.lib opencv_gpu245d.lib
    • opencv_highgui245d.lib opencv_highgui245d.lib
    • opencv_imgproc245d.lib opencv_imgproc245d.lib
    • opencv_legacy245d.lib opencv_legacy245d.lib
    • opencv_ml245d.lib opencv_ml245d.lib
    • opencv_nonfree245d.lib opencv_nonfree245d.lib
    • opencv_objdetect245d.lib opencv_objdetect245d.lib
    • opencv_photo245d.lib opencv_photo245d.lib
    • opencv_stitching245d.lib opencv_stitching245d.lib
    • opencv_superres245d.lib opencv_superres245d.lib
    • opencv_ts245d.lib opencv_ts245d.lib
    • opencv_video245d.lib opencv_video245d.lib
    • opencv_videostab245d.lib (Please note that I didn't added "opencv_ffmpeg245.lib", despite what the screenshot shows). opencv_videostab245d.lib(请注意,我没有添加“opencv_ffmpeg245.lib”,尽管截图显示了)。 额外的依赖关系
  8. Right-clicked "Source Files" -> "Add" -> "Existing Item" and added the "Z:\\Games instalados\\OpenCV\\opencv\\samples\\cpp\\cout_mat.cpp" file. 右键单击“源文件” - >“添加” - >“现有项”,并添加“Z:\\ Games instalados \\ OpenCV \\ opencv \\ samples \\ cpp \\ cout_mat.cpp”文件。 添加了cout_mat

The Problem 问题

  1. Built the project, no problems here, "Build succeeded". 建立项目,这里没有问题,“构建成功”。
  2. "Debug" -> "Start Debugging". “Debug” - >“Start Debugging”。 The following appears: The error http://s8.postimg.org/wdkubk5o3/the_error.jpg Full size image for the error: http://s8.postimg.org/wdkubk5o3/the_error.jpg 出现以下内容: 错误http://s8.postimg.org/wdkubk5o3/the_error.jpg错误的全尺寸图像: http//s8.postimg.org/wdkubk5o3/the_error.jpg

I've also tried with the hough lines sample, but it didn't worked as well (even with the image in the same folder as the .exe imread() wouldn't find the image). 我也尝试过hough lines示例,但是效果不好(即使与.exe imread()相同的文件夹中的图像也找不到图像)。

Any help would be greatly appreciated. 任何帮助将不胜感激。

If I've not made some of the installation steps clear enough, please post a comment. 如果我没有明确说明某些安装步骤,请发表评论。

Reason this question is suited for stackoverflow.com 原因这个问题适合stackoverflow.com

I've detailed a full installation procedure (from scratch) for the latest release of OpenCV to be used with Visual Studio 2008. If anyone solves this question we will have a complete, working tutorial for anyone having the same necessity (use latest OpenCV with visual studio 2008), and possibly (because of the depth in the installation procedure) a general guide for installing the latest OpenCV with most Visual Studio versions (not just the 2008, since the tutorial wouldn't change much, and the reader could easily adapt it). 我已经详细介绍了一个完整的安装程序(从头开始),用于与Visual Studio 2008一起使用的OpenCV的最新版本。如果有人解决了这个问题,我们将为具有相同必要性的任何人提供完整的工作教程(使用最新的OpenCV与visual studio 2008),并且可能(由于安装过程的深度)一般指南,用于安装最新的OpenCV与大多数Visual Studio版本(不仅仅是2008年,因为教程不会有太大变化,读者可以很容易适应它)。

I would suggest if you want to test proper installation of opencv. 我建议你是否要测试opencv的正确安装。 Just load a simple.jpg image in opencv and display it. 只需在opencv中加载simple.jpg图像并显示它。 If this works then you can start debugging the program which is crashing. 如果这样可行,那么您可以开始调试崩溃的程序。 You can debug it by successively enabling the cout. 您可以通过连续启用cout来调试它。 May be first just enable the default cout in example cout_mat.cpp and comment rest of it. 可能首先在示例cout_mat.cpp中启用默认cout并对其余部分进行注释。
Here is the simple load program you can try to test your installation. 这是您可以尝试测试安装的简单加载程序。

int main(int argc, char*argv[])
{

    cvNamedWindow("My_Win", CV_WINDOW_AUTOSIZE);
    IplImage *img = cvLoadImage("C:\\vid_an2\\Desert.jpg", CV_LOAD_IMAGE_UNCHANGED );

    std::cout<<"Info About Image"<<std::endl;

    std::cout<<"Size of Image "<<img->nSize<<std::endl;
    std::cout<<"Image channels "<<img->nChannels<<std::endl;
    std::cout<<"Image Width "<<img->width<<std::endl;
    std::cout<<"Image Height "<<img->height<<std::endl;
    std::cout<<"Image Depth "<<img->depth<<std::endl;
    std::cout<<"Image WidhtStep "<<img->widthStep<<std::endl;
    std::cout<<"Image Size "<<img->imageSize<<std::endl;

    cvShowImage("My_Win", img);

    cvWaitKey(0);

    // Free the resources.
    cvDestroyAllWindows();
    cvReleaseImage(&img);
return 0;
}

Since you are using VS2008, change Z:\\Games instalados\\OpenCV\\opencv\\build\\x86\\vc11 to Z:\\Games instalados\\OpenCV\\opencv\\build\\x86\\vc9 . 由于您使用的是VS2008, Z:\\Games instalados\\OpenCV\\opencv\\build\\x86\\vc11Z:\\Games instalados\\OpenCV\\opencv\\build\\x86\\vc9 The vc11 folder is for VS2012, vc9 is for VS2008. vc11文件夹用于VS2012,vc9用于VS2008。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM