91.204.201 computing iv visual c++ 2010 introduction with opencv 2.4.3 example xinwen fu

31
91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

Upload: claribel-watson

Post on 11-Jan-2016

222 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

91.204.201 Computing IV

Visual C++ 2010 Introduction with OpenCV 2.4.3 Example

Xinwen Fu

Page 2: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Reading Assignment Chapter one of the tutorials

By Dr. Xinwen Fu 2

http://finance.yahoo.com/news/the-college-degrees-with-the-highest-starting-salaries-204949790.html

Page 3: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Outline Installing and configuring Visual Studio

2010 to run an OpenCV example Visual studio concepts Tips of using Visual C++ Example code

By Dr. Xinwen Fu 3

Page 4: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Demo http://www.youtube.com/watch?v=cgo0UitHfp8

4

Page 5: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

How to install OpenCV 2.4.3 on Visual Studio 2010 OpenCV for Windows

Version 2.4.3 Visit http://kylehounslow.com/?

page_id=75 for source code: there is some bug

Some copy and pastables:Additional Include Directories: $(OPENCV_BUILD)\includeAdditional Library Directories: $(OPENCV_BUILD)\x86\vc10\lib

By Dr. Xinwen Fu 5

Page 6: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

How to install OpenCV 2.4.3 on Visual Studio 2010 (Cont’d) Debug Additional Dependencies:

opencv_core243d.libopencv_imgproc243d.libopencv_highgui243d.libopencv_ml243d.libopencv_video243d.libopencv_features2d243d.libopencv_calib3d243d.lib

Release Additional Dependencies (same thing but without 'd' at the end):opencv_core243.libopencv_imgproc243.libopencv_highgui243.libopencv_ml243.libopencv_video243.libopencv_features2d243.libopencv_calib3d243.lib

By Dr. Xinwen Fu 6

Page 7: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Differences between .dll , .lib, .h files? .h - header file

a source file containing declarations (as opposed to .cpp .cxx etc. containing implementations)

.lib - static library may contain code or just links to a dynamic library compiled code that you link with your program The static library is included in your .exe at link

time. .dll - dynamic library

Just like a static one but you need to deploy it with your .exe file because its loaded at run time

By Dr. Xinwen Fu 7

Page 8: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Configuration tips No need of care about your systems is 64

bits or 32 bits 32 bits applications can run on 64 bits

machines without problems

Use 32 bits OpenCV library

By Dr. Xinwen Fu 8

Page 9: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Troubleshooting If it does not work following the video

tutorial, you must have done one of the steps wrong Double check it

By Dr. Xinwen Fu 9

Page 10: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Outline Installing and configuring Visual Studio

2010 to run an OpenCV example Visual studio concepts Tips of using Visual C++ Example code

By Dr. Xinwen Fu 10

Page 11: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Solutions and Projects Visual Studio provides two containers to help you

efficiently manage the items that are required by your development effort, such as references, data connections, folders, and files. These containers are called solutions and projects.

Visual Studio provides Solution Folders to organize related projects into groups and then perform actions on those groups of projects. Solution Explorer, an interface for viewing and managing

these containers and their associated items, is part of the integrated development environment (IDE).

By Dr. Xinwen Fu 11

Page 12: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Items Items can be files and other parts of your project

such as references, data connections, or folders In Solution Explorer, items can be organized

as project items, which are items that compose your project, such as forms, source files, and classes within a project in Solution Explorer.

as solution items for files that are applicable to your solution as a whole in the Solution Items folder of Solution Explorer.

as miscellaneous files that are not associated with either a project or a solution and that can be displayed in a Miscellaneous Files folder

By Dr. Xinwen Fu 12

Page 13: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Solutions as Containers Visual Studio implements conceptual containers called

solutions and projects to enable the integrated development environment (IDE) to apply its wide range of tools, designers, templates, and settings

Visual Studio automatically generates a solution when you create a new project

By Dr. Xinwen Fu 13

Page 14: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Advantages Solutions allow you to concentrate on developing

and deploying your projects, instead of sorting through all the details of managing project files, components, and objects.

Each Visual Studio solution allows you to: Work on multiple projects within same instance of IDE. Work on items using settings and options that apply to

an entire set of projects. Use Solution Explorer to help develop and deploy your

application. Manage additional files opened outside the context of a

solution or project.

By Dr. Xinwen Fu 14

Page 15: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Definition Files Visual Studio stores the definition for a solution in

two files: .sln and .suo In previous versions of Visual Studio, you might have

noticed the group (.vbg) or workspace (.dsw) files in Visual Basic and Visual C++, respectively.

The solution definition file (.sln) stores the metadata that defines your solution: Projects that are associated with the solution. Items available at the solution level that are not

associated with a particular project. Solution build configurations that set which project

configurations to apply in each type of build.

By Dr. Xinwen Fu 15

Page 16: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Definition Files (Cont’d) The metadata stored in the .suo file as you

construct a solution and set its properties is used to customize the IDE whenever the solution is active.

By Dr. Xinwen Fu 16

Page 17: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Projects as Containers To help you to organize and perform common tasks on the

items that you are developing, Visual Studio projects are used as containers within a solution to logically manage, build, and debug the items that comprise your application.

The output of a project is usually an executable program (.exe), a dynamic-link library (.dll) file or a module, among others.

By Dr. Xinwen Fu 17

Page 18: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Create a Visual Studio Solution1. In Visual Studio, click File, point to New, and

then click Project.2. In the New Project dialog box, in the

Project types pane, click Other Project Types, and then click Visual Studio Solutions.

3. In the Templates pane, click Blank Solution.

4. Enter the name of your project in the Name field, and then click OK.

By Dr. Xinwen Fu 18

Page 19: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Outline Installing and configuring Visual Studio

2010 to run an OpenCV example Visual studio concepts Tips of using Visual C++ Example code

By Dr. Xinwen Fu 19

Page 20: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Align C++ code in VS 2010 Often code is copied into a .cpp file and

the formatting is lost

Reformatting the code – within vc++ Edit -> Advanced -> Format Selection

By Dr. Xinwen Fu 20

Page 21: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Enable Line Numbers in Visual C++/C# 2010

Tools -> Options -> Text Editor -> C/C++ -> check Line Numbers -> OK

By Dr. Xinwen Fu 21

Page 22: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

StartUp project in a soluton Select a StartUp project and click to debug it

Right click the project and select it

By Dr. Xinwen Fu 22

Page 23: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Debugging with command-line parameters in Visual Studio In VS 2008, 2010, or 2012, right-click the

project, choose properties, go to the Debugging section there is a box for command line arguments

By Dr. Xinwen Fu 23

Page 24: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Zoom in/out with Visual Studio 2010 editor Zoom in, Ctrl+Shift+period Zoom out, Ctrl+Shift+comma

By Dr. Xinwen Fu 24

Page 25: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Change the color of ink of Powerpoint Change the color of ink before starting a slide show

On the Slide Show menu, click Set Up Show. In the Pen color box, click the color you want, and then click OK.

Change the ink color during a slide show On the Slide Show toolbar, click or tap the pointer arrow, point to Ink

Color, and then click the color you want. Note   Changing the color of the ink during the slide show affects the ink

for the ballpoint and felt tip pens only. Change the color of ink on a Tablet PC

Select the ink you want to format. On the Ink Drawing and Writing or Ink Annotations toolbar, tap Select

Objects. Tap the ink. Sizing handles and an outline of the ink shapes indicate that the ink is

selected. On the Ink Drawing and Writing or Ink Annotations toolbar, tap the

arrow next to Line Color. Tap the color you want to use.

Tip After you select a color, the Line Color button displays that color. You can

apply the same color again to any ink selection by clicking or tapping Line Color again.

By Dr. Xinwen Fu 25

Page 26: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

Outline Installing and configuring Visual Studio

2010 to run an OpenCV example Visual studio concepts Tips of using Visual C++ Example code

By Dr. Xinwen Fu 26

Page 27: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UMLBy Dr. Xinwen Fu 27

OpenCV 2 ExampleDisplayImage.cpp

Page 28: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

1. #include <opencv\cv.h>2. #include <opencv\highgui.h>3. #include <iostream>

4. using namespace std;5. using namespace cv;

6. int main(){7. Mat m;

8. VideoCapture cap;9. cap.open(0);10. cout<<cap.isOpened()<<endl;

11. namedWindow("window",1);

12. while(1){13. cap>>m;14. imshow("window",m);15. waitKey(33);16. }

17. return 0;18. }

By Dr. Xinwen Fu 28

Video Capture Example

Page 29: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UMLBy Dr. Xinwen Fu 29

OpenCV 1 Example

Page 30: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

cv Namespace All OpenCV classes and functions are in the cv namespace. Therefore, to access this functionality from your code, use

the cv:: specifier or using namespace cv; directive:1. #include "opencv2/core/core.hpp"2. ...3. cv::Mat H = cv::findHomography(points1, points2, CV_RANSAC,

5);4. ...

or1. #include "opencv2/core/core.hpp"2. using namespace cv;3. ...4. Mat H = findHomography(points1, points2, CV_RANSAC, 5 );5. ...

By Dr. Xinwen Fu 30

Page 31: 91.204.201 Computing IV Visual C++ 2010 Introduction with OpenCV 2.4.3 Example Xinwen Fu

CS@UML

References Application Development in Visual Studio

By Dr. Xinwen Fu 31