2013-07-24 openCV v1 - · PDF fileWindows 7 Home Premium, 32 bits

30
Install OpenCV Our resources Get OpenCV Set PATH variable Set MVS properties 36 โครงการสถิติประยุกต์เพื่อชุมชน

Transcript of 2013-07-24 openCV v1 - · PDF fileWindows 7 Home Premium, 32 bits

Page 1: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

Install OpenCV

• Our resources

• Get OpenCV

• Set PATH variable

• Set MVS properties

36โครงการสถิติประยุกต์เพื่อชุมชน

Page 2: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

Our resources

โครงการสถิติประยุกต์เพื่อชุมชน

• All screen captures are based on

◦ Windows 7 Home Premium, 32 bits

◦ Microsoft Visual Studio 2010 (a.k.a. MVS version 10)

◦ OpenCV 2.4.5 for windows operating system

INSTALL OPENCV

37

Page 3: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

Set MVS properties

The rest of this section

โครงการสถิติประยุกต์เพื่อชุมชน

Set PATH variable

Get OpenCV • Download your copy of OpenCV(free)

• Add OpenCV to your system’s PATH

• This is to ensure that there will be no missing-DLL errors

• Set property sheets of your MVS project

• Repeat this for every new project created OR try using Add Existing Property Sheet in MVS

INSTALL OPENCV

38

Page 4: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

โครงการสถิติประยุกต์เพื่อชุมชน

Get OpenCV

Full video tutorial (English)http://www.youtube.com/watch?v=cgo0UitHfp8

INSTALL OPENCV

39

Page 5: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

• Download the latest OpenCV

◦ http://opencv.org/downloads.html

◦ OpenCV 2.4.5 for Windows• Size: 266 MB• Released date: 11 APR 2013

◦ OpenCV 2.4.6 for Windows• Size: 291 MB• Released date: 3 JUL 2013

โครงการสถิติประยุกต์เพื่อชุมชน 40

INSTALL OPENCV > GET OPENCV

Page 6: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

41โครงการสถิติประยุกต์เพื่อชุมชน

Extract the installation package to some location, for example, C:\Program Files\opencv245

Double click

Downloaded file

INSTALL OPENCV > GET OPENCV

Page 7: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

42โครงการสถิติประยุกต์เพื่อชุมชน

Double click

Inside the folder C:\Program Files\opencv245

INSTALL OPENCV > GET OPENCV

Page 8: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

โครงการสถิติประยุกต์เพื่อชุมชน

Set PATH variable

Full video tutorial (English)http://www.youtube.com/watch?v=cgo0UitHfp8

INSTALL OPENCV

43

Page 9: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

44โครงการสถิติประยุกต์เพื่อชุมชน

1. Start > Computer > System properties > Advanced system settings > Environment Variables

INSTALL OPENCV > SET PATH VARIABLE

Page 10: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

45โครงการสถิติประยุกต์เพื่อชุมชน

2. System variables > New > Insert the following values and click OK

◦ Variable name: OPENCV_VER◦ Variable value: 245

INSTALL OPENCV > SET PATH VARIABLE

Page 11: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

46โครงการสถิติประยุกต์เพื่อชุมชน

3. System variables > New > Insert the following values and click OK

◦ Variable name: OPENCV_BUILD◦ Variable value: C:\Program Files\opencv245\build

INSTALL OPENCV > SET PATH VARIABLE

Page 12: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

47โครงการสถิติประยุกต์เพื่อชุมชน

4. System variables > choose Path in the list > click Edit button

5. Append either ; %OPENCV_BUILD%\x86\vc10\bin; or; C:\Program Files\opencv245\build\x86\vc10\bin; to the Variable value textbox

◦ Replace “x86” by “x64” if you use 64-bit Microsoft Visual Studio◦ Replace “vc10” by your version of Visual Studio (i.e., “vc9” for MVS

2008, “vc10” for MVS 2010, “vc11” for MVS 2012)

INSTALL OPENCV > SET PATH VARIABLE

Page 13: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

48โครงการสถิติประยุกต์เพื่อชุมชน

6. Restart your computer to finish all changes

INSTALL OPENCV > SET PATH VARIABLE

Page 14: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

49โครงการสถิติประยุกต์เพื่อชุมชน

• Other solutions of the “xxx.dll is missing” problem

◦ Copy all DLLs to C:\Windows\System32OR

◦ Copy all DLLs to the same directory as the *.exe

INSTALL OPENCV > SET PATH VARIABLE

Page 15: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

โครงการสถิติประยุกต์เพื่อชุมชน

Set MVS properties

Full video tutorial (English)http://www.youtube.com/watch?v=cgo0UitHfp8

INSTALL OPENCV

50

Page 16: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

51โครงการสถิติประยุกต์เพื่อชุมชน

1. Open Microsoft Visual Studio 2010

2. New project > Visual C++ > Win 32 Console Application◦ Insert the name of the project, for example, myNewOpenCV◦ Application settings > select Empty project > click Finish

INSTALL OPENCV > SET MVS PROPERTIES

Page 17: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

52โครงการสถิติประยุกต์เพื่อชุมชน

3. In Solution Explorer panel > Choose tab named Property Manager – myNewOpenCV

◦ If this tab is not there, choose View > Property Manager in the main menu

4. Right click at Debug | Win32 > select Add New Project Property Sheet …

◦ Insert the name OPENCV_DEBUG and click Add

INSTALL OPENCV > SET MVS PROPERTIES

Page 18: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

53โครงการสถิติประยุกต์เพื่อชุมชน

5. Back to the Property Manager tab◦ Right click at OPENCV_DEBUG > select Properties

INSTALL OPENCV > SET MVS PROPERTIES

Page 19: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

54โครงการสถิติประยุกต์เพื่อชุมชน

6. Common Properties > VC++ Directories◦ Include Directories > Edit > add $(OPENCV_BUILD)\include◦ Library Directories > Edit > add $(OPENCV_BUILD)\x86\vc10\lib

INSTALL OPENCV > SET MVS PROPERTIES

Page 20: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

55โครงการสถิติประยุกต์เพื่อชุมชน

7. Common Properties > C/C++◦ Additional Include Directories > Edit > add a new item of

$(OPENCV_BUILD)\include

INSTALL OPENCV > SET MVS PROPERTIES

Page 21: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

56โครงการสถิติประยุกต์เพื่อชุมชน

8. Common Properties > Linker > General◦ Additional Library Directories > Edit > add a new item of

$(OPENCV_BUILD)\x86\vc10\lib

INSTALL OPENCV > SET MVS PROPERTIES

Page 22: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

57โครงการสถิติประยุกต์เพื่อชุมชน

9. Common Properties > Linker > Input◦ Additional Dependencies > Edit > add the following items

• opencv_core$(OPENCV_VER)d.lib• opencv_imgproc$(OPENCV_VER)d.lib• opencv_highgui$(OPENCV_VER)d.lib• opencv_ml$(OPENCV_VER)d.lib• opencv_video$(OPENCV_VER)d.lib• opencv_features2d$(OPENCV_VER)d.lib• opencv_calib3d$(OPENCV_VER)d.lib• opencv_objdetect$(OPENCV_VER)d.lib• opencv_contrib$(OPENCV_VER)d.lib• opencv_legacy$(OPENCV_VER)d.lib• opencv_flann$(OPENCV_VER)d.lib

“*d.lib” means “debug”

INSTALL OPENCV > SET MVS PROPERTIES

Page 23: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

58โครงการสถิติประยุกต์เพื่อชุมชน

10. Click Apply and OK to exit the window of OPENCV_DEBUG Property Pages

11. In Windows Explorer, make one copy of the OPENCV_DEBUG.props and rename it to OPENCV_RELEASE.props

◦ The created property sheet can be found in the directory where the project (*.vcxproj) is

INSTALL OPENCV > SET MVS PROPERTIES

Page 24: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

59โครงการสถิติประยุกต์เพื่อชุมชน

12. Back to the Property Manager tab◦ Right click at Release | Win32 > select Add Existing Property

Sheet > choose OPENCV_RELEASE.props > click Open

13. In Property Manager tab◦ Left click to expand Release | Win32 > right click at

OPENCV_RELEASE > select Properties

14. In Common Properties > Linker > Input > Additional Dependencies, change all names from *d.lib to *.lib

◦ Remove “d” which represents debug-version of *.lib

INSTALL OPENCV > SET MVS PROPERTIES

Page 25: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

60โครงการสถิติประยุกต์เพื่อชุมชน

◦ opencv_core$(OPENCV_VER).lib◦ opencv_imgproc$(OPENCV_VER).lib◦ opencv_highgui$(OPENCV_VER).lib◦ opencv_ml$(OPENCV_VER).lib◦ opencv_video$(OPENCV_VER).lib◦ opencv_features2d$(OPENCV_VER).lib◦ opencv_calib3d$(OPENCV_VER).lib◦ opencv_objdetect$(OPENCV_VER).lib◦ opencv_contrib$(OPENCV_VER).lib◦ opencv_legacy$(OPENCV_VER).lib◦ opencv_flann$(OPENCV_VER).lib

INSTALL OPENCV > SET MVS PROPERTIES

Page 26: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

61โครงการสถิติประยุกต์เพื่อชุมชน

15. Click Apply and OK to exit the window of OPENCV_RELEASE Property Pages

16. Solution Explorer > right click at Source Files◦ Add > New Item > C++ File > insert main in the Name

textbox > click Add

INSTALL OPENCV > SET MVS PROPERTIES

Page 27: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

62โครงการสถิติประยุกต์เพื่อชุมชน

17. Add the following codes to main.cpp

18. Try running the project in both debug and release modes

INSTALL OPENCV > SET MVS PROPERTIES

Use either / or \\ instead of \

program0.cpp

Page 28: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

63โครงการสถิติประยุกต์เพื่อชุมชน

INSTALL OPENCV > SET MVS PROPERTIES

Page 29: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

Alternative for step 9 and 14 (1/2)

64โครงการสถิติประยุกต์เพื่อชุมชน

• Common Properties > Linker > Input > Additional Dependencies◦ This can be specified programmatically◦ BUT these information will not be included in property sheets

// Head of the program#ifdef _DEBUG#pragma comment(lib,"opencv_core245d")#else#pragma comment(lib,"opencv_core245")#endif

// The rest of the program

Name of *.lib in debug version

Name of *.lib in release version

INSTALL OPENCV > SET MVS PROPERTIES

Page 30: 2013-07-24 openCV v1 -   · PDF fileWindows 7 Home Premium, 32 bits

65โครงการสถิติประยุกต์เพื่อชุมชน

#ifdef _DEBUG#pragma comment(lib,"opencv_core245d")#pragma comment(lib,"opencv_imgproc245d")#pragma comment(lib,"opencv_highgui245d")#pragma comment(lib,"opencv_ml245d")#pragma comment(lib,"opencv_video245d")#pragma comment(lib,"opencv_features2d245d")#pragma comment(lib,"opencv_calib3d245d")#pragma comment(lib,"opencv_objdetect245d")#pragma comment(lib,"opencv_contrib245d")#pragma comment(lib,"opencv_legacy245d")#pragma comment(lib,"opencv_flann245d")#else#pragma comment(lib,"opencv_core245")#pragma comment(lib,"opencv_imgproc245")#pragma comment(lib,"opencv_highgui245")#pragma comment(lib,"opencv_ml245")#pragma comment(lib,"opencv_video245")#pragma comment(lib,"opencv_features2d245")#pragma comment(lib,"opencv_calib3d245")#pragma comment(lib,"opencv_objdetect245")#pragma comment(lib,"opencv_contrib245")#pragma comment(lib,"opencv_legacy245")#pragma comment(lib,"opencv_flann245")#endif