[Opencv Getting Started Guide] Article 1 install opencv

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

This article mainly introduces how to download the opencv installer and how to install and configure opencv under vs2008. Finally, it introduces 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 a new license number 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 downloading, double-click the EXE and select the Output Folder. I chose D: \ opencv. After decompression, the installation is completed. The installation steps are as follows:

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 in vs2008

In vs2008, click "Tools", click "options", select "project and solution", and manually add a library file, you can reference files and include files to complete the import of opencv in vs2008.

4. The first opencv Program

The following is an example of the simplest use of opencv. The function is also very easy-load and display 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 the form cvnamedwindow (pstrwindowstitle, cv_window_autosize); // display the image cvshowimage (pstrwindowstitle, pimage) in the specified form; // wait for the key event waitcvkey (); cvdestroywindow (pstrwindowstitle); cvreleaseimage (& pimage); Return 0 ;}

Explain the main functions in the Code:

 

1. Create a form cvnamedwindow

Function Name: cvnamedwindow
Function: create a form
Function prototype:
Int cvnamedwindow (const char * Name, int flags = cv_window_autosize );

Description of the number of shards:
The first number of dimensions indicates the name of the form. It is used to distinguish different forms and is displayed as the form title. The created forms can be referenced by their names.
The second number of dimensions indicates the form attribute flag. The only supported indicator is cv_window_autosize. When this flag is set, you cannot manually change the size of the form. The size of the form is automatically adjusted to fit the displayed image.
The cvnamedwindow function creates a form that can place images and trackbar.

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

 

2. display the image cvshowimage in the specified form

Function Name: cvshowimage
Function: displays an image in a specified form.
Function prototype:
Void cvshowimage (const char * Name, const cvarr * image );
Description of the number of shards:

The first number of arguments: the name of the form.
Second digit number: 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 );
Description of the number of shards:

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

Function return value:

If it exceeds the specified time,-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 the 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 to "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. The execution result of the program is as follows:

Haha, very cool surfing ~~

 

The following lists the opencv Getting Started Guide folders 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 "inspection on the edge of the well-being"

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

5. [opencv Getting Started Guide] Chapter 5 Outline Detection

6. [opencv Getting Started Guide] under section 6 contour detection

7. [opencv Getting Started Guide] Article 7 line segment checking and circular checking

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 execute opencv programs?

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

14. [opencv Getting Started Guide] 14th haartraining will be announced 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


[Opencv Getting Started Guide] Article 1 install opencv

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.