OpenCV 2.3.1インストール

http://opencv.willowgarage.com/wiki/
のDownloadからwin用のファイル(OpenCV-2.3.1-win-superpack.exe)をダウンロード。

実行するとファイルが展開される。

c:\opencv

に配置した。

dllが入っているディレクトリにPATHを通す。
Visual Studio 2010を使っているので、以下をPATHに追加した。

 C:\opencv\build\x86\vc10\bin

Visual Studio 2010での使い方

コンソールアプリケーションでプロジェクト新規作成。
プロジェクトのプロパティを開き、以下を設定する。

構成プロパティ > VC++ディレクトリ > インクルードディレクト

 C:\opencv\build\include

構成プロパティ > VC++ディレクトリ > ライブラリディレクト

 C:\opencv\build\x86\vc10\lib

構成プロパティ > リンカ > 追加の依存ファイル

 opencv_core231d.lib
 opencv_highgui231d.lib


http://opencv.willowgarage.com/wiki/VisualC%2B%2B
Building your own projects using OpenCV 2.2 in Visual Studio
に書いてあるソースをコピーして、プロジェクト名.cppに貼り付ける。

// OpenCV_Helloworld.cpp : Defines the entry point for the console application.
// Created for build/install tutorial, Microsoft Visual Studio and OpenCV 2.2.0

#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])
{
        // Open the file.
        IplImage *img = cvLoadImage("photo.jpg");
        if (!img) {
                printf("Error: Couldn't open the image file.\n");
                return 1;
        }

        // Display the image.
        cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE);
        cvShowImage("Image:", img);

        // Wait for the user to press a key in the GUI window.
        cvWaitKey(0);

        // Free the resources.
        cvDestroyWindow("Image:");
        cvReleaseImage(&img);
        
        return 0;
}

プロジェクトのディレクトリにphoto.jpgを用意しておく。
あとはビルドして実行する。