在Visual C ++ 2010 Express中安装OpenCV 2.4.3 [英] Installing OpenCV 2.4.3 in Visual C++ 2010 Express

查看:84
本文介绍了在Visual C ++ 2010 Express中安装OpenCV 2.4.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在VC ++ 2010 Express下安装和使用OpenCV 2.4.3?

How do you install and use OpenCV 2.4.3 under VC++ 2010 Express?

推荐答案

1.安装OpenCV 2.4.3

首先,从sourceforge.net获取 OpenCV 2.4.3 .它是自解压的,因此只需双击即可开始安装.将其安装在目录中,例如 C:\ .

First, get OpenCV 2.4.3 from sourceforge.net. Its a self-extracting so just double click to start the installation. Install it in a directory, say C:\.

等待,直到提取所有文件.它将创建一个新目录 C:\opencv 包含OpenCV头文件,库,代码示例等.

Wait until all files get extracted. It will create a new directory C:\opencv which contains OpenCV header files, libraries, code samples, etc.

现在,您需要将目录 C:\opencv\build\x86\vc10\bin 添加到系统PATH.此目录包含运行代码所需的OpenCV DLL.

Now you need to add the directory C:\opencv\build\x86\vc10\bin to your system PATH. This directory contains OpenCV DLLs required for running your code.

打开控制面板系统高级系统设置高级标签→ 环境变量...

Open Control PanelSystemAdvanced system settingsAdvanced Tab → Environment variables...

在系统变量"部分,选择路径(1),编辑(2),然后键入 C:\opencv\build\x86\vc10\bin; (3),然后点击确定.

On the System Variables section, select Path (1), Edit (2), and type C:\opencv\build\x86\vc10\bin; (3), then click Ok.

在某些计算机上,您可能需要重新启动计算机以使系统识别环境路径变量.

On some computers, you may need to restart your computer for the system to recognize the environment path variables.

这将在您的计算机上完成OpenCV 2.4.3的安装.

This will completes the OpenCV 2.4.3 installation on your computer.

2.创建一个新项目并设置Visual C ++

打开Visual C ++,然后选择文件项目... Visual C ++ 空项目.为您的项目命名(例如:cvtest)并设置项目位置(例如:c:\projects).

Open Visual C++ and select FileNewProject...Visual C++Empty Project. Give a name for your project (e.g: cvtest) and set the project location (e.g: c:\projects).

点击确定. Visual C ++将创建一个空项目.

Click Ok. Visual C++ will create an empty project.

确保在解决方案配置组合框中选择调试".右键单击cvtest,然后选择属性 VC ++目录.

Make sure that "Debug" is selected in the solution configuration combobox. Right-click cvtest and select PropertiesVC++ Directories.

选择包括目录以添加新条目,然后键入 C:\opencv\build\include .

Select Include Directories to add a new entry and type C:\opencv\build\include.

点击确定以关闭对话框.

返回属性"对话框,选择库目录以添加新条目,然后键入 C:\opencv\build\x86\vc10\lib .

Back to the Property dialog, select Library Directories to add a new entry and type C:\opencv\build\x86\vc10\lib.

点击确定以关闭对话框.

返回属性对话框,选择链接器输入其他依赖项以添加新条目.在弹出对话框中,输入以下文件:

Back to the property dialog, select LinkerInputAdditional Dependencies to add new entries. On the popup dialog, type the files below:

opencv_calib3d243d.lib
opencv_contrib243d.lib
opencv_core243d.lib
opencv_features2d243d.lib
opencv_flann243d.lib
opencv_gpu243d.lib
opencv_haartraining_engined.lib
opencv_highgui243d.lib
opencv_imgproc243d.lib
opencv_legacy243d.lib
opencv_ml243d.lib
opencv_nonfree243d.lib
opencv_objdetect243d.lib
opencv_photo243d.lib
opencv_stitching243d.lib
opencv_ts243d.lib
opencv_video243d.lib
opencv_videostab243d.lib

请注意,文件名以"d"结尾(用于调试").还要注意,如果您安装了另一个版本的OpenCV(例如2.4.9),则这些文件名将以249d而不是243d(opencv_core249d.lib..etc)结尾.

Note that the filenames end with "d" (for "debug"). Also note that if you have installed another version of OpenCV (say 2.4.9) these filenames will end with 249d instead of 243d (opencv_core249d.lib..etc).

点击确定以关闭对话框.在项目属性对话框中,点击确定以保存所有设置.

Click Ok to close the dialog. Click Ok on the project properties dialog to save all settings.

注意:

这些步骤将为调试"解决方案配置Visual C ++.对于发布"解决方案(可选),您需要 重复添加OpenCV目录,然后在其他目录中 依存关系部分,请使用:

These steps will configure Visual C++ for the "Debug" solution. For "Release" solution (optional), you need to repeat adding the OpenCV directories and in Additional Dependencies section, use:

opencv_core243.lib
opencv_imgproc243.lib
...

opencv_core243.lib
opencv_imgproc243.lib
...

代替:

opencv_core243d.lib
opencv_imgproc243d.lib
...

opencv_core243d.lib
opencv_imgproc243d.lib
...

您已经完成了Visual C ++的设置,现在该编写真实的代码了.右键单击您的项目,然后选择添加新商品... Visual C ++ C ++文件.

You've done setting up Visual C++, now is the time to write the real code. Right click your project and select AddNew Item...Visual C++C++ File.

命名文件(例如:loadimg.cpp),然后点击确定.在编辑器中输入以下代码:

Name your file (e.g: loadimg.cpp) and click Ok. Type the code below in the editor:

#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat im = imread("c:/full/path/to/lena.jpg");
    if (im.empty()) 
    {
        cout << "Cannot load image!" << endl;
        return -1;
    }
    imshow("Image", im);
    waitKey(0);
}

上面的代码将加载 c:\full\path\to\lena.jpg 并显示图像.你可以 使用您喜欢的任何图像,只需确保图像的路径正确即可.

The code above will load c:\full\path\to\lena.jpg and display the image. You can use any image you like, just make sure the path to the image is correct.

键入F5来编译代码,它将在一个漂亮的窗口中显示图像.

Type F5 to compile the code, and it will display the image in a nice window.

这是您的第一个OpenCV程序!

And that is your first OpenCV program!

3.从这里去哪里?

现在您的OpenCV环境已经准备好了,下一步是什么?

Now that your OpenCV environment is ready, what's next?

  1. 转到示例目录→ c:\opencv\samples\cpp .
  2. 阅读并编译一些代码.
  3. 编写您自己的代码.

这篇关于在Visual C ++ 2010 Express中安装OpenCV 2.4.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆