first step:
Download and install the win version of the OpenCV package
URL: https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.9/opencv-2.4.9.exe/download
Step 2:
Configure environment variables
Computer->Right-click Properties->Advanced System Settings->Environment Variables->Find Path in the System Variables bar->Edit->Add the following code (do not overwrite the previous one, please note the semicolon between each piece of code):
C:\OpenCV\opencv\build\x64\vc10\bin;
C:\OpenCV\opencv\build\x86\vc10\bin
format is: disk\filename\build\x64 is 64-bit x86 is 32-bit\vc10 is VS2010 and so on \bin
, please edit and modify according to your own situation
third step:
Project Include Directory Settings
- File -> New Project -> Win32 Console Application and Name Select Path -> Click Next Check Empty Project on Application Settings Page
- After completing the above steps, a project has been created;
- In solution explorer right click source file -> add -> new item -> selected C++ file click add
- In the menu bar, click View -> Property Manager -> Click the arrow in front of the Debug|Win32 file -> Microsoft.Cpp.Win32.userDirectories Right click Properties
- After opening the property page, select General Properties->VC++ Directories->Include Directories to add:
C:\OpenCV\opencv\build\include;
C:\OpenCV\opencv\build\include\opencv;
C:\OpenCV\opencv\build\ include\opencv2;
please edit and modify according to your own situation
Configuration of the project library directory
After opening the property page, select General Properties->VC++ Directory->Library Directory and add:
D:\Program Files\OpenCV\opencv\build\x86\vc10\bin;
please edit and modify according to your own situation, it is recommended to use x86
the fourth step:
Link library configuration
- In the menu bar, click View -> Property Manager -> Click the arrow in front of the Debug|Win32 file -> Microsoft.Cpp.Win32.userDirectories Right click Properties
After opening the properties page, select Common Properties->Linker->Input->Additional Dependencies and add:
//debug配置添加: opencv_calib3d249d.lib opencv_contrib249d.lib opencv_core249d.lib opencv_features2d249d.lib opencv_flann249d.lib opencv_gpu249d.lib opencv_highgui249d.lib opencv_imgproc249d.lib opencv_legacy249d.lib opencv_ml249d.lib opencv_objdetect249d.lib opencv_ts249d.lib opencv_video249d.lib //release配置添加: opencv_calib3d249.lib opencv_contrib249.lib opencv_core249.lib opencv_features2d249.lib opencv_flann249.lib opencv_gpu249.lib opencv_highgui249.lib opencv_imgproc249.lib opencv_legacy249.lib opencv_ml249.lib opencv_objdetect249.lib opencv_ts249.lib opencv_video249.lib
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
the fifth step:
Test if the configuration is successful
Change the name of any jpg image to 1 and add it to the project file where the source file .cpp is stored, that is, in the same folder as the source file.
Copy enter the following code
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img=imread("1.jpg");
imshow("Javis",img);
waitKey(6000);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
The picture is displayed normally, and the configuration is complete.
Error note:
- Is the image storage location correct?
- Is the file configuration path correct?
- Additional dependencies add if missing