OpenCV 2.1 + Visual Studio 2008 @ Windows XP 32bit

时间:2022-07-25 06:41:32

Versions

  • os: Windows XP SP3 32bit
  • Visual Studio: 2008
  • OpenCV: 2.1

Prerequisites 

Windows Environment Variables

  • Right click on My Computer -> Properties -> Advanced -> Environment Variables -> System Variables
  • Add to Path: %OpenCV 2.1%\bin

VC++ Directories

  • Tools -> Options -> Project and Solutions -> VC++ Directories
  • For Platform "Win32" and "Executable Files" add: %OpenCV 2.1%\bin

  • For Platform "Win32" and "Include Files" add: %OpenCV 2.1%\include\opencv

  • For Platform "Win32" and "Library Files" add: %OpenCV 2.1%\lib

Creat a new Project

  • Files -> New -> Project...
  • Visual C++ -> Win32 -> Win32 Console Application
  • Name your projects

Linker

  • Right click on project -> Properties
  • For "Debug"
      • Configuration Porperties -> Linker -> Input
      • Add to Additional dependencies: cxcore210d.lib cv210d.lib highgui210d.lib
  • Configuration Porperties -> General
  • Change Character Set to: Use Multi-Byte Character Set
  • For "Release"
    • Configuration Porperties -> Linker -> Input
    • Add to Additional dependencies: cxcore210.lib cv210.lib highgui210.lib
    • Configuration Porperties -> General
    • Change Character Set to: Use Multi-Byte Character Set

Write "Hello World"

1 /* **********************************************************************
2 * OpenCV 2.0 测试例程
3 * 于仕琪 提供
4 ********************************************************************** */
5
6 #include " stdafx.h "
7 #include " highgui.h "
8
9 // 所有的以新风格命名的函数都在 cv 命名空间中
10 // 如果希望不要每次都输入 cv:: ,则可使用下面语句
11 // using namespace cv;
12
13 int _tmain( int argc, _TCHAR * argv[])
14 {
15
16 const char * imagename = " lena.jpg " ;
17
18 cv::Mat img = cv::imread(imagename); // Matlab风格的 cvLoadImage 函数的另一种调用
19 if (img.empty())
20 {
21 fprintf(stderr, " Can not load image %s\n " , imagename);
22 return - 1 ;
23 }
24
25 if ( ! img.data ) // 检查是否正确载入图像
26 return - 1 ;
27
28 cv::namedWindow( " image " , CV_WINDOW_AUTOSIZE); // 创建窗口
29 cv::imshow( " image " , img); // 显示图像
30
31 cv::waitKey();
32
33 return 0 ;
34 }

Reference