Tag Archives: Programming

Install and Configure OpenCV2 in VS2010

OpenCV is a very useful C++ Computer Vision library. Since the pre-built superpack is available, and can be downloaded from here, the installation is rather simple. The problems begin when you’re trying to find different include/lib/bin directories and define them in Visual studio 2010.

  1. Download the latest version of the Superpack.
  2. Run the EXE file, and extract all the files to some directory, e.g., C:\OpenCV23
  3.  Find the subdirectory “build” inside your OpenCV directory. In this subdirectory, find the directory “bin” which is appropriate for your operational system and compiler, e.g., for 32bit VS2010: C:\OpenCV23\opencv\build\x86\vc10\bin
  4. Now you have to add some environmental variables. The instructions can be found here. Add the full path to the “bin” directory to the PATH variable.
  5. Add the variable: OpenCV_VER = 231     (where 231 is the full version number of your OpenCV (i.e., 2.3.1), without dots)
  6. Add the variable: OpenCV_PATH = C:\OpenCV23\opencv\build   (where the path should point to your “build” directory)
  7. Now, create the text file OpenCV_Debug.props:

<!–?xml version=”1.0″ encoding=”utf-8″?>
<Project ToolsVersion=”4.0″ xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″&gt;
<ImportGroup Label=”PropertySheets” />
<PropertyGroup Label=”UserMacros” />
<PropertyGroup>
<IncludePath>$(OpenCV_PATH)\include;$(IncludePath)
</PropertyGroup>
<PropertyGroup>
<LibraryPath>$(OpenCV_PATH)\x86\vc10\lib;$(LibraryPath)
</PropertyGroup>
<ItemDefinitionGroup>
<Link>
<AdditionalDependencies>opencv_core$(OpenCV_VER)d.lib;opencv_highgui$(OpenCV_VER)d.lib;opencv_imgproc$(OpenCV_VER)d.lib;opencv_features2d$(OpenCV_VER)d.lib;opencv_calib3d$(OpenCV_VER)d.lib;opencv_video$(OpenCV_VER)d.lib;opencv_objdetect$(OpenCV_VER)d.lib;%(AdditionalDependencies)
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>

and the file OpenCV_Release.props:

<!–?xml version=”1.0″ encoding=”utf-8″?>
<Project ToolsVersion=”4.0″ xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″&gt;
<ImportGroup Label=”PropertySheets” />
<PropertyGroup Label=”UserMacros” />
<PropertyGroup>
$(OpenCV_PATH)\include;$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;
</PropertyGroup>
<PropertyGroup>
$(OpenCV_PATH)\x86\vc10\lib;$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib
</PropertyGroup>
<ItemDefinitionGroup>
<Link>
<AdditionalDependencies>opencv_core$(OpenCV_VER).lib;opencv_highgui$(OpenCV_VER).lib;opencv_imgproc$(OpenCV_VER).lib;opencv_features2d$(OpenCV_VER).lib;opencv_calib3d$(OpenCV_VER).lib;opencv_video$(OpenCV_VER).lib;opencv_objdetect$(OpenCV_VER).lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>

8.   Create an empty Visual Studio console project.

9.  Add some new source file, like main.cpp

10. Copy the prop files you’ve created to the same directory.

11. In the property editor of VS (look for the property tab under the “Solution explorer” window) add the OpenCV_Debug.props property sheet to Debug | Win32, and OpenCV_Release.props to Release | Win32 (by clicking on + button).

That’s it.

Now, if you need to create a new OpenCV project, you should repeat the steps 8-11 only.

If you’d like to update your OpenCV installation to a new version, you should repeat the steps 4-6, and 8-11 only.

Advertisements

Install Python From the Source Code

Python logo

Image via Wikipedia

Installing Python in Windows 7 is simple, because a pre-built  Windows installer exists. The problem begins when you are trying to compile another Python based libraries, which are asking for e.g. python27_d.lib file. This file is absent, thus you have to build the Python source files from scratch. Python distribution includes SLN files for Visual Studio, but if you try to run them, you’ll get errors. The official explanations of the installation process in Windows … well, I can’t understand from there what to do with the errors.

Still, there is a simple enough solution:

  1. Install VS2008. This will not work for other versions.
  2. Install the Netwide Assembler: www.nasm.us , click on “DOWNLOAD” link, choose the latest stable version directory (not rc), click on “win32” directory, download and run the installer (e.g., http://www.nasm.us/pub/nasm/releasebuilds/2.09.10/win32/nasm-2.09.10-installer.exe). The program should be installed to C:\Program Files\NASM.
  3. Go to C:\Program Files\NASM\ and  rename the file nasm.exe to nasmw.exe.
  4. Install Cygwin from cygwin.com: Choose all default settings, except the addition of the following packages:
    1. curl
    2. cvs
    3. git
    4. subversion
    5. tcltk
    6. unzip
    7. zip
  5. Add to the PATH the directories C:\Program Files\NASM\ and C:\cygwin\bin: go to Control Panel, start searching for env…and choose “Edit the system environment variables” –>Environment Variables…–>Edit PATH variable.
  6. Download the Python source code from python.org site: e.g.  http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz
  7. Create directory: C:\Python27 and copy all the source files and sub-directories there. If everything is okay, you should see the directory C:\Python27\PCbuild.
  8. Run cmd as administrator: Start button–>All Programs–>Accessories–>Right click on Command Prompt–>Run as Administrator.
  9. In the open terminal write the following:
    1. cd C:\Python27
    2. .\tools\buildbot\build
  10. The Debug version of Python should be installed without errors.

Which programming languages should I learn (in addition to MATLAB)?

Introduction

I have to confess that I’m still looking for the “right” languages for me. First of all, I’m a scientist and not a programmer, and I DON’T want to be a programmer! On the other hand, writing algorithms and programming is what I do as a major part of my scientific life. Therefore, of course MATLAB is my first choice, and I know it well. But sometimes MATLAB is not enough. It is fine for scientific computations and proof of concept, but there are better ways to do other things.

I don’t need my programs to be portable, or to ship/sell them. All the projects are for personal use, or for the scientific community. Therefore I’m not concerned with compatibility problems.

Continue reading