[OpenCV Getting Started Guide] Article 1 install OpenCV

Source: Internet
Author: User
Tags vc9
[OpenCV Article 1] install OpenCV

This article describes how to download the OpenCV installer and how to install and configure OpenCV under VS2008. At last, it also describes a simple example of using OpenCV.

OpenCV Getting Started Guide series Article address: http://blog.csdn.net/morewindows/article/category/1291764

1. Download OpenCV

You can download it at http://www.opencv.org.cn/index.php/download. My V2.3.1 version is:

Http://www.opencv.org.cn/download/OpenCV-2.3.1-win-superpack.exe

After the download is complete, double-click to run the exe and select the output directory. I chose D: \ opencv. Then decompress the package to complete the installation. The installation process is shown in:

2. Configure OpenCV in my computer

In "my computer", right-click the "System Properties" dialog box, select "advanced", click "environment variables", and then edit path, in the "edit user variables" dialog box, enter the following three variable values. Use ";" to separate them.

D: \ opencv \ build \ x86 \ vc9 \ bin;

D: \ opencv \ build \ x86 \ mingw \ bin;

D: \ opencv \ build \ common \ tbb \ ia32 \ vc9;

3. Add OpenCV to VS2008

In VS2008, click "Tools", click "options", select "projects and Solutions", and manually add files to the database, you can import OpenCV to VS2008 by referencing and including files.

4. The first OpenCV Program

The following is the simplest use example of OpenCV, and its function is also very simple-loading and displaying image files. The Code is as follows:

// Display the image file # include <opencv2/opencv. hpp> using namespace std; # pragma comment (linker, "/subsystem: \" windows \ "/entry: \" mainCRTStartup \ "") int main () {const char * pstrImageName = "surf masters 001.jpg"; const char * pstrWindowsTitle = "OpenCV first program (http://blog.csdn.net/MoreWindows)"; // read image IplImage * pImage = cvLoadImage (pstrImageName, CV_LOAD_IMAGE_UNCHANGED); // create a window cvNamedWindow (pstrWindowsTitle, CV_WINDOW_AUTOSIZE); // display the image cvShowImage (pstrWindowsTitle, pImage) in the specified window; // wait for the key event waitcvkey (); cvDestroyWindow (pstrWindowsTitle); cvReleaseImage (& pImage); return 0 ;}

The main functions in the Code are described as follows:

 

1. Create a window cvNamedWindow

Function Name: cvNamedWindow
Function: create a window
Function prototype:
Int cvNamedWindow (const char * name, int flags = CV_WINDOW_AUTOSIZE );

Parameter description:
The first parameter indicates the window name. It is used to distinguish different windows and is displayed as the window title. The created windows can be referenced by their names.
The second parameter indicates the window property flag. Currently, the only supported flag is CV_WINDOW_AUTOSIZE. When this flag is set, you cannot manually change the window size. The window size is automatically adjusted to fit the displayed image.
The cvNamedWindow function creates a window where images and trackbar can be placed.

Note:
If a window with this name already exists, this function will not do anything.

 

2. display the image cvShowImage in the specified window

Function Name: cvShowImage
Function: displays an image in a specified window.
Function prototype:
Void cvShowImage (const char * name, const CvArr * image );
Parameter description:

The first parameter is the window name.
The second parameter is the displayed image.

3. Wait for the key event cvWaitKey

Function Name: cvWaitKey

Function: Waiting For button events

Function prototype:
Int cvWaitKey (int delay = 0 );
Parameter description:

The first parameter: the number of milliseconds of delay. When delay is <= 0, it indicates unlimited waiting.

Function return value:

If the specified time is exceeded,-1 is returned; otherwise, the value of the key is returned.

 

An error occurred while compiling !! The error message is as follows:

1> link...

1> opencv_test1.obj: error LNK2019: external symbol _ cvReleaseImage that cannot be parsed. This symbol is referenced in function _ main.

1> opencv_test1.obj: error LNK2019: the external symbol _ cvDestroyWindow that cannot be parsed. This symbol is referenced in function _ main.

1> opencv_test1.obj: error LNK2019: external symbol _ cvWaitKey that cannot be parsed. This symbol is referenced in function _ main.

1> opencv_test1.obj: error LNK2019: external symbol _ cvShowImage that cannot be parsed. This symbol is referenced in function _ main.

1> opencv_test1.obj: error LNK2019: the external symbol _ cvNamedWindow that cannot be parsed. This symbol is referenced in function _ main.

1> opencv_test1.obj: error LNK2019: external symbol _ cvLoadImage that cannot be parsed. This symbol is referenced in function _ main.

 

How can we solve this problem now? Since an error occurs during the link, it indicates that there must be a static library not found by the compiler. Therefore, in VS2008, click "project" and then "properties ", expand "configuration properties"> "linker"> "input" and add the following static files in "additional dependencies.

Opencv_core231d.lib using opencv_gpu231d.lib opencv_highgui231d.lib opencv_imgproc231d.lib using opencv_ml231d.lib using opencv_ts231d.lib opencv_video231d.lib

 

Compilation is successful. Shows the program running result:

Haha, cool surfing ~~

 

The following lists the OpenCV Getting Started Guide directories for your convenience.

1. [OpenCV Getting Started Guide] Article 1 install OpenCV

2. [OpenCV Getting Started Guide] Article 2 Scaling Images

3. [OpenCV Getting Started Guide] Part 3 "Canny edge detection"

4. [OpenCV Getting Started Guide] Article 4 binarization of images

5. [OpenCV Getting Started Guide] Chapter 5 contour detection

6. [OpenCV Getting Started Guide] section 6 contour detection

7. [OpenCV Getting Started Guide] Article 7 Line Segment Detection and Circle Detection

8. Chapter 8 grayscale histogram in [OpenCV Getting Started Guide]

9. [OpenCV Getting Started Guide] Article 9 grayscale histogram equalization

10. [OpenCV Getting Started Guide] Article 10 color histogram equalization

11. [OpenCV Getting Started Guide] 11th mouse drawing

12. [OpenCV Getting Started Guide] Article 12th cannot run OpenCV programs?

13. [OpenCV Getting Started Guide] 13th facial recognition

14. [OpenCV Getting Started Guide] 14th Haartraining is coming soon

 

Reprinted please indicate the source, original address: http://blog.csdn.net/morewindows/article/details/8225783

OpenCV Getting Started Guide series Article address: http://blog.csdn.net/morewindows/article/category/1291764

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.