"OpenCV Getting Started Guide" first installment OpenCV

Source: Internet
Author: User
Tags vc9

"OpenCV First" installation OpenCV

This article mainly describes how to download the OPENCV installation program, how to install the configuration under VS2008 OpenCV, the article finally introduced a simple sample using OPENCV.

the O Pencv Getting Started Guide series article address: http://blog.csdn.net/morewindows/article/category/1291764

A Download of OpenCV

To be able to Http://www.opencv.org.cn/index.php/Download , and then select a newer version number to download. I'm under the V2.3.1 version number, which is:

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

After downloading, double click Execute exe, select output folder, I choose D:\opencv. Then the decompression is complete and installed. The installation steps for example are as seen in:

Two Configure OPENCV on My Computer

Right-click on "My Computer" to pop up the "System Properties" dialog, select "Advanced" and then "environment variables", then edit path, enter the following three entries in the variable value of the Edit User Variable dialog box, and note the ";" to separate.

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

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

D:\OPENCV\OPENCV\BUILD\COMMON\TBB\IA32\VC9;

Three Add OpenCV to VS2008

In VS2008 , click "Tools", then "Options", then select "Project and Solution", manually add the library files, reference files and include files can be completed OpenCV in VS2008 import.  

Four First OPENCV Program

The following is the simplest example of OpenCV use, and the function is very easy--to load the image file and display it. The code is as follows:

Display image file # include <opencv2/opencv.hpp>using namespace std; #pragma comment (linker, "/subsystem:\" windows\ "/ Entry:\ "Maincrtstartup\" ") int main () {const char *pstrimagename =" Surf master 001.jpg "; const char *pstrwindowstitle =" OPENCV First Program (http://blog.csdn.net/MoreWindows) ";//Read the image from a file iplimage *pimage = Cvloadimage (Pstrimagename, Cv_load_ image_unchanged);//Create Form Cvnamedwindow (Pstrwindowstitle, cv_window_autosize);//Display an image in the specified form cvshowimage ( Pstrwindowstitle, pimage);//wait for key event Cvwaitkey (); Cvdestroywindow (Pstrwindowstitle); Cvreleaseimage (&pImage); return 0;}

The main functions in the code are explained below:

1. Create a form Cvnamedwindow

function Name: Cvnamedwindow
function function: Create a form
Function Prototypes:
int Cvnamedwindow(const char* name, int flags=cv_window_autosize);

Description of the parameters:
The first parameter represents the name of the form, which is used to distinguish between different forms and is displayed as a form title. The forms that are created can be referenced by their names.
the second parameter represents the form property flag. The only sign of support right now is cv_window_autosize. When this flag is set, the user cannot manually change the size of the form, and the size of the form is actively adjusted to fit the displayed image.
The Cvnamedwindow function creates a form that can place images and TrackBar .

Attention:
Assuming that the name already exists on the form, this function will not do whatever it is.

2. Displays the image in the specified form cvshowimage

function Name: Cvshowimage
function Function: Display an image in the specified form
Function Prototypes:
void cvshowimage (const char* name, const cvarr* image);
Description of the parameters:

first number of parameters: the name of the form.
second parameter: the image being displayed.

3. Wait for key event Cvwaitkey

Function name:cvwaitkey

function function: Wait for key event

Function Prototypes:
int Cvwaitkey (int delay=0);
Description of the parameters:

first number of parameters: the number of milliseconds to delay when delay<=0 indicates an infinite wait.

function return value:

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

Compile, even error!! Error messages such as the following:

1> is linking ...

1>opencv_test1.obj:error LNK2019: unresolved external symbol _cvreleaseimage, which is referenced in function _main

1>opencv_test1.obj:error LNK2019: unresolved external symbol _cvdestroywindow, which is referenced in function _main

1>opencv_test1.obj:error LNK2019: unresolved external symbol _cvwaitkey, which is referenced in function _main

1>opencv_test1.obj:error LNK2019: unresolved external symbol _cvshowimage, which is referenced in function _main

1>opencv_test1.obj:error LNK2019: unresolved external symbol _cvnamedwindow, which is referenced in function _main

1>opencv_test1.obj:error LNK2019: unresolved external symbol _cvloadimage, which is referenced in function _main

Now how to solve the problem? Since it was a link-time error, there must be a static library that was not found by the compiler. So we click "Project" in the VS2008 , then "Properties", expand "Configuration Properties"--"linker" and "input" in "Additional dependencies" to add such as the following static file.

Opencv_calib3d231d.lib opencv_contrib231d.lib opencv_core231d.lib opencv_features2d231d.lib opencv_flann231d.lib Opencv_gpu231d.lib opencv_highgui231d.lib opencv_imgproc231d.lib opencv_legacy231d.lib opencv_ml231d.lib opencv_ Objdetect231d.lib Opencv_ts231d.lib Opencv_video231d.lib

Re-compile, success. The program executes the results for example as seen in:

Oh, very cool surfing ~ ~

The OpenCV Getting Started folder is listed below for easy viewing.

1."OpenCV Getting Started Guide" first installment OpenCV"

2."TheOpenCV Getting Started Guide" second zoom image

3."OpenCV Getting Started Guide" the third Canny edge detection

4.Two value of the fourth image of the "OpenCV Getting Started Guide"

5."OpenCV Getting Started Guide" fifth outline inspection

6."OpenCV Getting Started Guide" sixth outline of the test

7."OpenCV Getting Started Guide" seventh segment detection and inspection of The Circle

8."OpenCV Primer" Eighth grayscale histogram

9."OpenCV Getting Started Guide" nineth grayscale histogram equalization

Tenth : Color histogram equalization, "OpenCV Getting Started Guide"

The11th mouse drawing of the "OpenCV Getting Started Guide"

12th of the"OpenCV Getting Started Guide" cannot execute the OpenCV program? "

"TheOpenCV Primer", 13th human face recognition

"TheOpenCV Getting Started Guide" 14th haartraining"will be announced soon ."

Reprint please indicate 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" first installment 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.