OpenCV with Visual Studio 2008
If you are and absolute beginner or have failed in setting up OpenCV (Open Computer Vision Library version 2.2) with Microsoft Visual Studio 2008 in a Windows environment. Well, here are the “baby steps” for you in getting this done with no hassle, with pictorial aid. The content of this article is free to share in any way as you wish for any good purpose.

Note: If you are an experienced user I suggest you to follow the instructions in the official Willogarage site.

(I have done this in Windows 7 Platform, but will probably work in other similar platforms)

The whole process can be broken down into three main tasks:

  • Install and build the OpenCV 2.2 library with CMake
  • Compiling the library with Visual Studio
  • Configuring the project required to use OpenCV

That’s it…

If you are confident in installing OpenCV and CMake skip the content until the next horiz0ntal line. Else continue reading.

(Please do not hesitate to mention anything that I might have mentioned wrong in this article)

Install and build the OpenCV 2.2 library with CMake

  • Assuming you have already installed Microsoft Visual Studio 2008, we proceed with the installation of OpenCV 2.2
    • Download OpenCV version 2.2 from here.
    • Following is the pictures for the installation just for the sake of completion.
    • OpenCV_setup

      OpenCV Installation

      Accept the License Agreement

      Be generous by letting all to use this : Add OpenCV to the system path

      Choose the Install Location : I have put it directly on C: drive (with respect…)Start Menu Folder : You decide as you want…Components : Let me go with “Full” this time…

    • Well that’s it: Go ahead and click “install” and give some seconds to the installer to do the work.
    •  After completion move to the next step of building the OpenCV project.
      • Now if you have already some experience with earlier OpenCV versions like OpenCV 1.o, this you might it strange compiling the library, but if we look on the bright that is the beauty of going open source; giving us the change to involve and customize the library.
      • Before compiling the library we have to build the solution using CMake.
  • Install CMake
    • Download CMake from here.
    • CMake 2.8 Setup Wizard : Click next…

      License Agreement : “I Agree”

      Install Options: My selection was: Add CMake to the system PATH for all users

      Install Location: I have put it under ‘Program Files’

      Start Menu Folder: Well, as you wish…

    • Now click ‘Install’ and give some seconds till the things get done with CMake.
    • Next we use CMake to build our project solution of OpenCV, remember: we need to compile it…
  • Build the OpenCV 2.2 library solution with CMake

Run the CMake GUI from programs menu.

Selecting CMake GUI

CMake GUI

Now we have to browse for the source code, i.e. OpenCV 2.2 folder…

it will give…

CMake GUI with the source folder

Then we have to give the place where to build the binaries… what I have done was to create a sub-folder inside the source folder under the name ‘vs2008’. (You can put any name and use any destination, but make sure you remember all).

A simple copy paste to avoid any typo…

CMake GUI with destination folder

Then select “Configure” command button… as the destination folder has not been created it will give the following message.

Message to verify creating a new folder. (Select “Yes”)

Then we need to select specify the Generator for our project.  In this situation I have used Visual Studio 2008 as my Generator.

Specify the generator for the project.

However if you are using a different Visual Studio Version, make sure that you select the correct version from the drop down list.

Select the correct version from the drop down list.

Now the CMake GUI will look like…

The CMake GUI after the configuration.

Now if you want you can make any changes to the list, but in this setup I did not do any modification and to make sure the configuration has been done properly I press the “configuration” command button for the second time as well. It will update and display the new values in red.

After success configuration all the red marks should be gone and “Configuration done” text should appear at the bottom of the text field in CMake GUI.

Then we can generate the binaries by clicking the “Generate” command button.

Generating done.

After successful configuration and generation of binaries, the “Configuration done” and “Generation done” should appear at the bottom of the text field in CMake GUI.

By this stage, we have successfully completed building the OpenCV 2.2 library solution file. The next stage is to compile it and “actually build solution” 🙂 .

  • Compiling the library with Visual Studio
    • Open Visual Studio 2008

      Opening MS Visual Studio 2008

      Visual Studio 2008

    • Then browse for the OpenCV2.2 solution that we created in the previous stage.

      Browsing for solution file…

    • Select OpenCV(.sln) Visual Studio Solution file.

      Select OpenCV(.sln)

    • It will give…

      Visual Studio IDE with opened OpenCV solution

    • Let’s first select Debug from the menu. (if you want you can select first Release and then Debug also)

      Selecting “debug” 

    • Then select “Build Solution” from the menu or just press “F7

      Select “Build Solution”

    • Then it starts “Compiling”

      Compiling…

    • Successful compiling should give build succeededoutput without any fails.

      Output after the first compile…

    • However in my situation I had to compile for the second time, i.e. Rebuild the solution to get a good output.

      Rebuild succeeded…

    • Once we successfully compile and build solution the “Debug” folder should appear under both “bin” and “lib” directories.

      “Debug” in “bin”

      “Debug” in “lib”

    • Now we can again compile with “Release” and successful completion of it will give “Release” folders in both “bin” and “lib”…

      “Release” in “bin”

      “Release” in “lib”

After completing this we can close the solution

Closing the solution

  • Setup Environment Variables.
    • Before start using OpenCV we have to let the machine know where the binaries are.

      In windows start menu, right click on “Computer” and go to “Properties”

      Select “Advanced system settings”

      In “System Properties” select “Environment Variables

      Select “Environment Variables”

Under Environment Variables, select the variable “PATH”  and then click on the “Edit” command button to change the value.

“Edit” the “PATH” variable

Add the destination of the binary files of Debug and Release, i.e. path to “Debug” and “Release” folders in “bin” directory.

In this situation we have added “C:\OpenCV2.2\vs2008\bin\Debug;C:\OpenCV2.2\vs2008\bin\Release” to the system path.

Note: a semi-colon should separate each variable  value.

Adding the path of “Debug” and “Release” folders to “path” “value”

Now the computer knows where the binaries are. Let’s move on to  configuring the Visual Studio IDE and how to start using OpenCV2.2

(I wrote the previous section of the article in 2011 and upon the request of the mark and merzouk, I thought of completing the rest of the article at least in as a draft. Please note that it’s easier for me to make a mistake as I’m looking at these after almost two years. All the material written before this comment is highly confident, but for the following part you have to pay extra attention.)

Following I just present the screenshots that I captured while creating a new project.

  Configuring the project required to use OpenCV (i.e. Creating a new project)

  • First Configure the IDE

  • CN_001_2011-04-09_2022

    CN_002_2011-04-09_2023CN_003_2011-04-09_2024CN_003_Sub_1_2011-04-09_2028CN_004_2011-04-09_2025CN_005_2011-04-09_2026CN_006_2011-04-09_2029CN_007_2011-04-09_2029CN_008_2011-04-09_2030







































































































































































































































































































































































































































































































































  • Then create a new project
    (Also this shows if you try to build it without setting linker it’ll give an error, so complete the next few steps before building the solution)
    N_001_2011-04-09_2010N_002_2011-04-09_2011N_003_2011-04-09_2012N_004_2011-04-09_2013N_005_2011-04-09_2013N_006_2011-04-09_2013N_007_2011-04-09_2014N_008_2011-04-09_2014N_009_2011-04-09_2015N_010_2011-04-09_2016N_011_Build_Error_2011-04-09_2020

    The error msg

    The error msg

    N_012_2011-04-09_2057

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Include directories (you can do this step even before writing the code, once you create the new project, again as I remember)

    D_1_2011-04-09_2059D_2_2011-04-09_2058D_3_2011-04-09_2100D_4_2011-04-09_2101

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Setting the linker
    L_1_correct_one_selecting_the_project_2011-04-09_2037L_2_2011-04-09_2036L_3_2011-04-09_2038L_4_2011-04-09_2038

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Compile the code (and it all should be good, hopefully)

    As I said check the last few steps carefully as I have forgotten most of it.

    Wish you all the best…










Nguồn: https://rangadabarera.wordpress.com/opencv-with-visual-studio/


11/3/2020 10:08:30 AM