SlideShare a Scribd company logo
1 of 19
KINECTでライトセーバー作ってみた
自己紹介+前置き
1. HN:domitry
2. 二年で部長をやっているものです。
3. 担当はプログラミング。
4. 去年一年間はhtmlやjQueryでホームページを作ってみたり、C#でWpfを弄
   くってみたりと色々迷走してました。
5. 学園祭にはKinect+OpenNIで人物検出をするプログラムを出しました。
何をやるのか
1.Kinectからリアルタイムで送られてくる画像と深度データから手に持った棒
  を検出し、その上にライトセーバーをオーバーレイして表示する。
2. (↓イメージ画像)
何故ライトセーバーなのか
1.スターウォーズep1リメイク版の予告編でライトセーバーを使ったアクショ
  ンがかっこよかったから
2.学園祭用にKinectを買ってあったから
3. 複雑なアルゴリズムを使う様な難しいシロモノを作りたかったから
4. (ぶっちゃけ)元ネタがあったから ↓




  出展:YouTube (http://www.youtube.com/watch?v=3EeJCln5KYg)
これのどこが難しいのか
1.直線検出のためのアルゴリズムは数あれど、ほとんどがRGB画像用で処理が
  重く、リアルタイムで処理するのに適していない。
2. 元ネタ動画の人はもちろんソース公開などしていない。
3. よってアルゴリズムは自分で考えないと行けない。
4. Kinect Hackはごく最近始まったので情報が少なく、そのほとんどは英語であ
     る。
使ったもの
1. Microsoft VisualC# 2010 Professional + KinectSDK
2. Kinect for Xbox360
3. ホームセンターで購入した棒切れ(1mくらい)
検出方法1
1. プレイヤーまでの距離は公式SDKで取得できる。
2. その付近の距離にある点のみを抜き出すと、その中に棒も含まれているは
    ず。
3. 実際にテストプログラムでプレイヤーの深度付近の点だけ抜き出してみた↓
検出方法1
1. 棒も含まれているであろう点の集合を抜き出すことに成功した。
2. ここで検出する棒の条件を挙げてみる。
 a.手の平の中心を始点とした直線
 b.方向は手のひらからひじまでの方向とは全く違う
3. プレイヤーの骨格は取得できるので、aの条件は簡単に反映することができ
    る。




        棒の方向




          腕の方向
検出方法1
1. SDKで検出できる点の中で使えそうなのは以下の二点。(手のひらと手首)
2. 選んだ点の内、手のひらの点から一定距離の点を選び出す。
3. そして下図のベクトルを考える。
4. 青いベクトルの内、その単位ベクトルと赤いベクトルの単位ベクトルとの内
   積がcos60°以上のものはおそらく腕の一部なので除外する。
検出方法1
1. 以上の条件で実際に試してみた。
2. めちゃくちゃわかりにくいが黄色が条件を満たした点、青色が除外された
   点。
検出方法1
1. その後、選ばれた点と手のひらの点を結んだ直線と他の点との距離を求め、
   距離が一定範囲内に収まった点の数をカウントする。
2. カウントした数が一番多かったものが一番もっともらしい直線。

 y




 0                                 x
検出方法1
1. この方法で一応棒を検出することに成功した。
2. これもかなりわかりにくいが下図の黄土色の線がそれ。
検出方法1の問題点
1.精度が低い(50%くらいしか当たらない)
2.処理が重すぎる(検出を始めたらユーザーの動きがカックカク)
3.以上の問題点を軽減しようと修正を繰り返したが、速度は改善されても精
  度が なかなかよくならなかった。
検出方法2
1.煮詰まったので何か見つからないかと思い再び元ネタの動画を見てみる。
 ここで大変な記述を発見。




     この人OpenCV使ってるwwww
検出方法2
1. OpenCVの何が悪いのか。
2. OpenCVとはRGB画像用のライブラリ。つまり、この動画のプログラムでは
   Kinectの深度データを使って棒を検出しているわけではない。
3. これじゃあ普通すぎる…つーかそれでできるんかい!! (爆
検出方法2
1. そこでOpenCVを使ってRGB画像での直線検出も併用することに。
2. 調べてみたところハフ変換というものがあるらしい。
3. ハフ変換では元の画像を二層化した後、関数にその画像を渡して直線を検出
   してもらう。




  出展:opencv v2.1 documentation (http://opencv.jp/opencv-2.1/cpp/feature_detection.html)
~ここでお詫び~
1. このスライドを書いているのが 3/30 21:16
2. ハフ変換を調べたのが同日20:10
3. マメ会は3/31 13:00~
4. つまり … 終わんね\(^o^)/オワタ
5. というわけでハフ変換についてはこれ以上書けません…
6. 今日は徹夜する予定ですがそれでも実装が終わるかどうかわかりませんw
デモ
#ifdef CODING_FINISHED
   demoProgram();
#else
   kenbuTime();
#endif
最後に
1. 来年度はいよいよ受験なのでプログラミングは一時休止します。
2. C言語をなんとか思い出すところから始めて、この2年間でプログラミングの
   腕は割と上達したんじゃないかと思います。
3. プログラミング以外にもこのクラブではいろいろなことが学べたと思いま
   す。
4. 1年生の皆さんがんばってください!

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Kinectでライトセーバー作ってみた