OpenCV 2.3インストール方法

インストール方法

  1. OpenCV-2.3.0-win-superpack.exe を適当に展開する
    • D:\software\Develop\library\OpenCV2.3
  2. Windows環境変数PATHにバイナリフォルダのパスを登録する
    • D:\software\Develop\library\OpenCV2.3\build\x86\vc10\bin
  3. サンプルコードで動作確認する
    • Visaul C++ 2010プロパティシートを作っておく
      • D:\software\Develop\library\OpenCV2.3\build\include
      • D:\software\Develop\library\OpenCV2.3\build\x86\vc10\lib
      • opencv_imgproc230d.lib;opencv_highgui230d.lib;opencv_core230d.lib
      • opencv_imgproc230.lib;opencv_highgui230.lib;opencv_core230.lib

サンプルコード

#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

int main ( int argc, char *argv[] )
{
	const char *ImageFile = "e:\\data\\image\\lena.png";
	const char *SaveName = "output.png";
	const char *WindowName = "view";
	const int ReturnErrorCode = -1;

	// 画像読込
	cv::Mat img = cv::imread ( ImageFile );
	if ( img.empty() )
	{
		std::cout << "画像読込失敗: " << ImageFile << std::endl;
		return ReturnErrorCode;
	}
	std::cout << "画像読込成功: " << ImageFile << std::endl;


	// 画像保存
	if ( cv::imwrite ( SaveName, img ) )
	{
		std::cout << "画像保存成功: " << SaveName << std::endl;
	}else{
		std::cout << "画像保存失敗: " << SaveName << std::endl;
	}

	// 画像表示
	cv::namedWindow ( WindowName );
	cv::imshow ( WindowName, img );
	cv::waitKey();

	return 0;
}

Visual C++ 2010プロパティシート

OpenCV-2.3-Debug.props
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup>
    <ClCompile>
      <AdditionalIncludeDirectories>D:\software\Develop\library\OpenCV2.3\build\include</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <AdditionalLibraryDirectories>D:\software\Develop\library\OpenCV2.3\build\x86\vc10\lib</AdditionalLibraryDirectories>
      <AdditionalDependencies>opencv_imgproc230d.lib;opencv_highgui230d.lib;opencv_core230d.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>
OpenCV-2.3-Release.props
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup>
    <ClCompile>
      <AdditionalIncludeDirectories>D:\software\Develop\library\OpenCV2.3\build\include</AdditionalIncludeDirectories>
    </ClCompile>
    <Link>
      <AdditionalLibraryDirectories>D:\software\Develop\library\OpenCV2.3\build\x86\vc10\lib</AdditionalLibraryDirectories>
      <AdditionalDependencies>opencv_imgproc230.lib;opencv_highgui230.lib;opencv_core230.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>