SlideShare a Scribd company logo
1 of 7
FaceControllMovie
顔の位置に合わせて動画をシフトさせて表示する
http://www.openprocessing.org/sketch/374655
高石武史
目的
• Processingを用いて
• 動画を再生
• 顔認識を行い
• 顔の位置に合わせて動画をシフトさせて表示する
基本的な考え方
• 動画横幅=画面x2 になるように調整(変更可)
• カメラ画像内での顔の位置に合わせて、動画をずらして表示
画面
動画
× 2 ∙
画面幅
動画幅
拡大した際に画面のサイズ
が違って見えることに注意
プログラム 1/3 (初期設定)
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
Capture video;
OpenCV opencv;
Movie movie;
float mScale;
void setup() {
size(1280,1024); // 画面サイズ
// webCamデバイスを開く
video = new Capture(this, 640/2, 480/2);
video.start(); // webcam スタート
// OpenCVによる顔認識
opencv = new OpenCV(this, 640/2, 480/2); // OpenCV で開く画像サイズの指定
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); // 検出器を正面顔に設定
// 動画ファイル
movie = new Movie(this, “test.mp4");
movie.loop(); // ループ再生開始
}
プログラム 2/3 (顔の認識と描画)
float ixShift=0.0, iyShift=0.0;
void draw() {
if(mScale>0) {
scale(mScale);
float h=height/mScale; float w=width/mScale; // 画面の縦横サイズのスケール変換 (mScale倍したために違って見える)
float ix0=(movie.width-w)/2; // 中心部を表示するためのオフセット (動画幅-画面幅[縮尺済み])/2
float iy0=(movie.height-h)/2;
opencv.loadImage(video); // OpenCVへの webCam画像の読み込み
Rectangle[] faces = opencv.detect(); // 顔認識(顔の入る長方形領域の情報取得)
if(faces.length>0) { // 認識された場合は No.0(最初のもの)の情報を採用
int ix = video.width - int(faces[0].x+faces[0].width/2); // 顔の中心の座標(左右鏡像反転)
int iy = int(faces[0].y+faces[0].height/2);
ixShift = map((ix-video.width/2), -video.width/2, video.width/2, -ix0,ix0); // 中心からのずれを動画の座標系へ変換
iyShift = map(-(iy-video.height/2), -video.height/2, video.height/2, -iy0,iy0);
}
image(movie,-ix0+ixShift,-iy0+iyShift); // シフトさせて表示
}
}
(0,0)
動画の表示位置について
(-ix0,-iy0) (-2*ix0,-iy0)
image(movie, -ix0+ixShift, -iy0+iyShift); // シフトさせて表示
プログラム 3/3 (イベント処理)
// webCamの次の画像が用意できた際の動作
void captureEvent(Capture c) {
c.read(); // 画像を読み込む
}
// movie の次の画像が用意できた際の動作
void movieEvent(Movie m) {
m.read(); // 画像を読み込む
mScale=2.0*width/movie.width; // 拡大倍率 2 ∙
画面幅
動画幅
}
void keyPressed()
{
switch( key )
{
case ' ': // reset the shift
ixShift=0;
break;
case ‘q’: // プログラム終了
exit();
break;
default: break;
}
}

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...
 

FaceControllMovie

  • 2. 目的 • Processingを用いて • 動画を再生 • 顔認識を行い • 顔の位置に合わせて動画をシフトさせて表示する
  • 3. 基本的な考え方 • 動画横幅=画面x2 になるように調整(変更可) • カメラ画像内での顔の位置に合わせて、動画をずらして表示 画面 動画 × 2 ∙ 画面幅 動画幅 拡大した際に画面のサイズ が違って見えることに注意
  • 4. プログラム 1/3 (初期設定) import gab.opencv.*; import processing.video.*; import java.awt.*; Capture video; OpenCV opencv; Movie movie; float mScale; void setup() { size(1280,1024); // 画面サイズ // webCamデバイスを開く video = new Capture(this, 640/2, 480/2); video.start(); // webcam スタート // OpenCVによる顔認識 opencv = new OpenCV(this, 640/2, 480/2); // OpenCV で開く画像サイズの指定 opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); // 検出器を正面顔に設定 // 動画ファイル movie = new Movie(this, “test.mp4"); movie.loop(); // ループ再生開始 }
  • 5. プログラム 2/3 (顔の認識と描画) float ixShift=0.0, iyShift=0.0; void draw() { if(mScale>0) { scale(mScale); float h=height/mScale; float w=width/mScale; // 画面の縦横サイズのスケール変換 (mScale倍したために違って見える) float ix0=(movie.width-w)/2; // 中心部を表示するためのオフセット (動画幅-画面幅[縮尺済み])/2 float iy0=(movie.height-h)/2; opencv.loadImage(video); // OpenCVへの webCam画像の読み込み Rectangle[] faces = opencv.detect(); // 顔認識(顔の入る長方形領域の情報取得) if(faces.length>0) { // 認識された場合は No.0(最初のもの)の情報を採用 int ix = video.width - int(faces[0].x+faces[0].width/2); // 顔の中心の座標(左右鏡像反転) int iy = int(faces[0].y+faces[0].height/2); ixShift = map((ix-video.width/2), -video.width/2, video.width/2, -ix0,ix0); // 中心からのずれを動画の座標系へ変換 iyShift = map(-(iy-video.height/2), -video.height/2, video.height/2, -iy0,iy0); } image(movie,-ix0+ixShift,-iy0+iyShift); // シフトさせて表示 } }
  • 7. プログラム 3/3 (イベント処理) // webCamの次の画像が用意できた際の動作 void captureEvent(Capture c) { c.read(); // 画像を読み込む } // movie の次の画像が用意できた際の動作 void movieEvent(Movie m) { m.read(); // 画像を読み込む mScale=2.0*width/movie.width; // 拡大倍率 2 ∙ 画面幅 動画幅 } void keyPressed() { switch( key ) { case ' ': // reset the shift ixShift=0; break; case ‘q’: // プログラム終了 exit(); break; default: break; } }