Skip to content

Commit

Permalink
バージョン設定を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
kaorun55 committed Jan 2, 2012
1 parent ed7614b commit d9f088f
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 2 deletions.
30 changes: 30 additions & 0 deletions OpenNI_Advent_Calendar_2011/SkeletonCpp/SamplesConfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<OpenNI>
<Licenses>
<License vendor="PrimeSense" key="0KOIk2JeIBYClPWVnMoRKn5cdY4=" />
</Licenses>
<Log writeToConsole="false" writeToFile="false">
<!-- 0 - Verbose, 1 - Info, 2 - Warning, 3 - Error (default) -->
<LogLevel value="1"/>
<Masks>
<Mask name="ALL" on="false"/>
</Masks>
<Dumps>
</Dumps>
</Log>
<ProductionNodes>
<Node type="Image" name="Image1">
<Configuration>
<MapOutputMode xRes="640" yRes="480" FPS="30"/>
</Configuration>
</Node>
<Node type="Depth" name="Depth1">
<Configuration>
<MapOutputMode xRes="640" yRes="480" FPS="30"/>
</Configuration>
</Node>
<Node type="Scene"/>
<Node type="User"/>
<Node type="Gesture"/>
<Node type="Hands"/>
</ProductionNodes>
</OpenNI>
20 changes: 20 additions & 0 deletions OpenNI_Advent_Calendar_2011/SkeletonCpp/SkeletonCpp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SkeletonCpp", "SkeletonCpp.vcxproj", "{807CEF70-3AA4-4134-9723-A918E93CEC22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{807CEF70-3AA4-4134-9723-A918E93CEC22}.Debug|Win32.ActiveCfg = Debug|Win32
{807CEF70-3AA4-4134-9723-A918E93CEC22}.Debug|Win32.Build.0 = Debug|Win32
{807CEF70-3AA4-4134-9723-A918E93CEC22}.Release|Win32.ActiveCfg = Release|Win32
{807CEF70-3AA4-4134-9723-A918E93CEC22}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
86 changes: 86 additions & 0 deletions OpenNI_Advent_Calendar_2011/SkeletonCpp/SkeletonCpp.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{807CEF70-3AA4-4134-9723-A918E93CEC22}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>SkeletonCpp</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="openni-1.4.0.2.props" />
<Import Project="opencv-2.3.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="openni-1.4.0.2.props" />
<Import Project="opencv-2.3.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="ソース ファイル">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="ヘッダー ファイル">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="リソース ファイル">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>ソース ファイル</Filter>
</ClCompile>
</ItemGroup>
</Project>
161 changes: 161 additions & 0 deletions OpenNI_Advent_Calendar_2011/SkeletonCpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// Windows の場合はReleaseコンパイルにすると
// 現実的な速度で動作します
#include <iostream>
#include <stdexcept>
#include <vector>

#include <opencv2/opencv.hpp>

#include <XnCppWrapper.h>

// ユーザー検出
void XN_CALLBACK_TYPE UserDetected( xn::UserGenerator& generator, XnUserID nId, void* pCookie )
{
std::cout << "ユーザー検出:" << nId << " " << generator.GetNumberOfUsers() << "人目" << std::endl;

generator.GetSkeletonCap().RequestCalibration(nId, TRUE);
}

// キャリブレーションの終了
void XN_CALLBACK_TYPE CalibrationEnd(xn::SkeletonCapability& capability, XnUserID nId, XnBool bSuccess, void* pCookie)
{
// キャリブレーション成功
if ( bSuccess ) {
std::cout << "キャリブレーション成功。ユーザー:" << nId << std::endl;
capability.StartTracking(nId);
}
// キャリブレーション失敗
else {
std::cout << "キャリブレーション失敗。ユーザー:" << nId << std::endl;
}
}

int main (int argc, char * argv[])
{
try {
cv::Ptr< IplImage > camera = 0;

// コンテキストの初期化
xn::Context context;
XnStatus rc = context.InitFromXmlFile("SamplesConfig.xml");
if (rc != XN_STATUS_OK) {
throw std::runtime_error(xnGetStatusString(rc));
}

// イメージジェネレータの作成
xn::ImageGenerator image;
rc = context.FindExistingNode(XN_NODE_TYPE_IMAGE, image);
if (rc != XN_STATUS_OK) {
throw std::runtime_error(xnGetStatusString(rc));
}

// デプスジェネレータの作成
xn::DepthGenerator depth;
rc = context.FindExistingNode(XN_NODE_TYPE_DEPTH, depth);
if (rc != XN_STATUS_OK) {
throw std::runtime_error(xnGetStatusString(rc));
}

// デプスの座標をイメージに合わせる
depth.GetAlternativeViewPointCap().SetViewPoint(image);

// ユーザーの作成
xn::UserGenerator user;
rc = context.FindExistingNode( XN_NODE_TYPE_USER, user );
if ( rc != XN_STATUS_OK ) {
throw std::runtime_error( xnGetStatusString( rc ) );
}

// スケルトン・トラッキングをサポートしているか確認
if (!user.IsCapabilitySupported(XN_CAPABILITY_SKELETON)) {
throw std::runtime_error("ユーザー検出をサポートしてません");
}

// キャリブレーションにポーズが必要
xn::SkeletonCapability skeleton = user.GetSkeletonCap();
if ( skeleton.NeedPoseForCalibration() ) {
throw std::runtime_error("最新のOpenNIをインストールしてください");
}

// ユーザー認識のコールバックを登録
// キャリブレーションのコールバックを登録
XnCallbackHandle userCallbacks, calibrationCallbacks;
user.RegisterUserCallbacks(&::UserDetected, 0, 0, userCallbacks);
skeleton.RegisterCalibrationCallbacks( 0, &::CalibrationEnd, 0, calibrationCallbacks );

// ユーザートラッキングで、すべてをトラッキングする
//XN_SKEL_PROFILE_ALL すべてをトラッキングする
//XN_SKEL_PROFILE_UPPER 上半身をトラッキングする
//XN_SKEL_PROFILE_LOWER 下半身をトラッキングする
//XN_SKEL_PROFILE_HEAD_HANDS 頭と手をトラッキングする
skeleton.SetSkeletonProfile(XN_SKEL_PROFILE_ALL);

// カメラサイズのイメージを作成(8bitのRGB)
XnMapOutputMode outputMode;
image.GetMapOutputMode(outputMode);
camera = ::cvCreateImage(cvSize(outputMode.nXRes, outputMode.nYRes), IPL_DEPTH_8U, 3);
if (!camera) {
throw std::runtime_error("error : cvCreateImage");
}

// メインループ
while (1) {
// すべてのノードの更新を待つ
context.WaitAndUpdateAll();

// 画像データの取得
xn::ImageMetaData imageMD;
image.GetMetaData(imageMD);

// ユーザーデータの取得
xn::SceneMetaData sceneMD;
user.GetUserPixels(0, sceneMD);

// カメラ画像の表示
memcpy( camera->imageData, imageMD.Data(), camera->imageSize );

// スケルトンの描画
XnUserID users[15];
XnUInt16 userCount = 15;
user.GetUsers(users, userCount);
for (int i = 0; i < userCount; ++i) {
if ( !skeleton.IsTracking( users[i] ) ) {
continue;
}

for ( int j = (int)XN_SKEL_HEAD; j <= (int)XN_SKEL_RIGHT_FOOT; ++j ) {
if ( !skeleton.IsJointAvailable( (XnSkeletonJoint)j ) ) {
continue;
}

// 各箇所の座標を取得する
XnSkeletonJointPosition joint;
skeleton.GetSkeletonJointPosition(users[i], (XnSkeletonJoint)j, joint);
if ( joint.fConfidence < 0.5 ) {
continue;
}

// 座標を変換する
XnPoint3D pt = joint.position;
depth.ConvertRealWorldToProjective( 1, &pt, &pt );
cvCircle( camera, cvPoint(pt.X, pt.Y), 10, cvScalar( 255, 0, 0 ), -1 );
}
}

::cvCvtColor(camera, camera, CV_RGB2BGR);
::cvShowImage("KinectImage", camera);

// キーイベント
char key = cvWaitKey(10);
// 終了する
if (key == 'q') {
break;
}
}
}
catch (std::exception& ex) {
std::cout << ex.what() << std::endl;
}

return 0;
}
16 changes: 16 additions & 0 deletions OpenNI_Advent_Calendar_2011/SkeletonCpp/opencv-2.3.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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>C:\OpenCV2.3\build\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\OpenCV2.3\build\x86\vc10\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opencv_core230.lib;opencv_highgui230.lib;opencv_imgproc230.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
16 changes: 16 additions & 0 deletions OpenNI_Advent_Calendar_2011/SkeletonCpp/openni-1.4.0.2.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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>$(OPEN_NI_INCLUDE);$(XN_NITE_INSTALL_PATH)\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(OPEN_NI_LIB);$(XN_NITE_INSTALL_PATH)\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>OpenNI.lib;XnVNITE_1_5_0.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
20 changes: 20 additions & 0 deletions get_version/get_version.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "get_version", "get_version.vcxproj", "{F643B2B7-38B5-4FCF-964C-227973475437}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F643B2B7-38B5-4FCF-964C-227973475437}.Debug|Win32.ActiveCfg = Debug|Win32
{F643B2B7-38B5-4FCF-964C-227973475437}.Debug|Win32.Build.0 = Debug|Win32
{F643B2B7-38B5-4FCF-964C-227973475437}.Release|Win32.ActiveCfg = Release|Win32
{F643B2B7-38B5-4FCF-964C-227973475437}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading

0 comments on commit d9f088f

Please sign in to comment.