SATCHのLiteバージョンとフルバージョンの顔検出を組み合わせてみる
今年は、007の50周年記念ということで、
2Dコンテンツ素材は、映画のオープニングで出てくる、ライフリング・マーク。
007には関心なくても、どっかで見た事あるんじゃないでしょうか?
顔検出には、TESTSのtestFaceTrackingAutoinitにあるトラッカーを使います。
手順
今回は、SATCHでの制作の仕方を書いてみます。
こんなことをやってみようと....。
工程は3つ。
1:SATCH Studio Liteでダミー・トラッキングして2Dコンテンツの表示シナリオを作成。
2:シナリオのトラッカーをtestFaceTrackingAutoinitのものと入れ替える。
3:SATCH Studioのフルバージョンでシナリオを読んで、Luaコードを書き換える。
TOP
1:SATCH Studio Liteでダミー・トラッキングして2Dコンテンツの表示シナリオを作成
SATCH Studio Liteの使い方はここを参照。
SATCH StudioのLiteバージョンを使ってみる
起動前に、以下のファイルを所定のフォルダーに入れておきます。
トラキング用画像
今回はトラッキング・ダミーとして使うのですが、以下のようなファイルを使ってみます。
(本当はなんでもいいんですけど....)
左クリックして、元画像のサイズを使います。
SATCHStudioLite/resources/trackerに保存しておきます。
2Dコンテンツ画像
お約束の画像です。
左クリックして、元画像のサイズを使います。
SATCHStudioLite/resources/2dContentsに保存しておきます。
Liteを起動して、以下のページの手順でシナリオを作成します。
SATCH StudioのLiteバージョンを使ってみる
以上
TOP
2:シナリオのトラッカーをtestFaceTrackingAutoinitのものと入れ替える
SATCH Developer siteのサンプルから、testFaceTrackingAutoinitをダウンロード。
解凍してfacetrackerAutoinitフォルダーを確認。
facetrackerAutoinitフォルダー内の「testFaceTrackingAutoinit_tracker.xml」ファイルの名前を「tracker.xml」に変更。
facetrackerAutoinitフォルダー名を「tracker」に変更。
1:で作ったシナリオのtrackerフォルダーを、これと入れ替えます。
以上
TOP
3:SATCH Studioのフルバージョンでシナリオを読んで、Luaコードを書き換える
SATCH Studioのフルバージョン版を起動して、シナリオを読み込みます。
シナリオがオリジナルと異なっているので、Scaleが変わっています。
Object Editorで「model2D_1」を選んで、Scale値を500位に設定して、Set initial valuesをクリック。
Luaコードを変更します。
元のままでは、2Dオブジェクトがお顔に追随してしまいます。今回は検出したら2Dオブジェクトを固定にしたままにします。
変更をかけるLuaはmainです。
Outlinerからmainというluascriptを右クリックで選んで、Open in Lua Editorを選択。
変数に以下のようなものを追加。
local current_pos = Vector3() local ini_count = 0 local ini_x = 0 local ini_y = 0 local ini_z = 0
最後の方にある、main routineを探して以下のように変更。
コメントアウトというワードと追加というワードの部分を参照。
--main routine
repeat
isCommand, command = componentInterface:pullCommand()
if isCommand then
handleCommand(command)
end
if isSVInit == false then
--check requireMode of startTracking. 4th param.
err_ret, g_trackingIndex = MLTPlugin:startTracking(g_trackerPath, 0, camera)
err_ret,status = MLTPlugin:getTrackingStatus(g_trackingIndex)
err_ret, g_targetCount = MLTPlugin:getTargetCount(g_trackingIndex)
isSVInit = true
end
for iTargetIndex =1, g_targetCount do
err_ret, status = MLTPlugin:getTargetStatus(g_trackingIndex, iTargetIndex-1)
if status > 0 then
err_ret = MLTPlugin:getTargetPos(g_trackingIndex, iTargetIndex-1, position, orientation)
err_ret, kfIndex = MLTPlugin:getRecognizedKeyFrameIndex(g_trackingIndex, iTargetIndex-1)
local luaIndex = kfIndex+1
local itemId = (targets[luaIndex]['itemId'] ~= null) and targets[luaIndex]['itemId'] or 0
g_targetIndex = iTargetIndex-1
trackingCallback(jsNotify, itemId, iTargetIndex-1, kfIndex, position, orientation)
tFlag = true
g_keyFrame = kfIndex
-- If another target is detected, the target is stopped playing.
for i =1, #targets do
if i~= luaIndex then
if targets[i]['onPlay'] then
if(targets[i]['ref'] ~= null and targets[i]['isScenette']) then
if targets[i]['ref']:getAnimationCount() > 0 then
anim = targets[i]['ref']:getAnimation(0)
anim:stop()
end
end
if targets[i]['sound']~=null then
targets[i]['sound']:stop()
end
if targets[i]['object']~=null then
targets[i]['object']:setVisible(false)
end
targets[i]['onPlay'] = false
end
end
end
if targets[luaIndex]['status'] ~= false then
if targets[luaIndex]['sound']~=null and targets[luaIndex]['onPlay']~=true then
LOG(luaIndex.." is play sound")
targets[luaIndex]['sound']:play()
end
-- The recognized target is started playing.
if targets[luaIndex]['object']~=null then
if not targets[luaIndex]['object']:getVisible() then
targets[luaIndex]['object']:setVisible(true)
if targets[luaIndex]['has2d'] then
setTextureToPlane(targets[luaIndex]['plane2d'], targets[luaIndex]['texture'])
end
if(targets[luaIndex]['ref'] ~= null and targets[luaIndex]['isScenette']) then
if targets[luaIndex]['ref']:getAnimationCount() > 0 then
anim = targets[luaIndex]['ref']:getAnimation(0)
anim:setLoop(true)
anim:play()
end
end
end
targets[luaIndex]['object']:setScale(targets[luaIndex]["scale"])
--コメントアウト
--targets[luaIndex]['object']:setPosition(position+targets[luaIndex]["pOffset"], camera)
--targets[luaIndex]['object']:setOrientation(orientation*targets[luaIndex]["qOffset"], camera)
--追加
current_pos = position+targets[luaIndex]["pOffset"]
if ini_count == 0 then
ini_x = current_pos:getX()
ini_y = current_pos:getY()
ini_z = current_pos:getZ()
ini_count = ini_count + 1
end
if ini_count ~= 0 then
current_pos:setX(ini_x)
current_pos:setY(ini_y)
--80という値は補正値で、たいした意味はありません
current_pos:setZ(ini_z - 80)
end
targets[luaIndex]['object']:setPosition(current_pos, camera)
end
targets[luaIndex]['onPlay'] = true
else
--LOG("targets["..luaIndex.."] is not active")
end
else
-- If any targets aren't detected
--追加
ini_count = 0
for i =1, #targets do
if targets[i]['onPlay'] then
if(targets[i]['ref'] ~= null and targets[i]['isScenette'])then
if targets[i]['ref']:getAnimationCount() > 0 then
anim = targets[i]['ref']:getAnimation(0)
anim:stop()
end
end
if targets[i]['sound']~=null then
targets[i]['sound']:stop()
end
if targets[i]['object'] ~= null then
targets[i]['object']:setVisible(false)
end
position:set(0, 0, 0)
orientation:set(0, 0, 0, 0)
targets[i]['onPlay'] = false
end
end
if tFlag == true then
local luaIndex = g_keyFrame +1;
if luaIndex > 0 and luaIndex <= #targets then
position:set(0, 0, 0)
orientation:set(0, 0, 0, 0)
local itemId = (targets[luaIndex]['itemId'] ~= null) and targets[luaIndex]['itemId'] or 0
trackingCallback(jsNotify, itemId, iTargetIndex-1, -1, position, orientation)
else
eventCallback(0, "ERROR", OUT_OF_ARRAY, "OUT_OF_ARRAY at Lua unFocusFlow : index "..luaIndex, "")
end
tFlag = false;
end
g_keyFrame = -1
end
end
until coroutine.yield()
こんな感じです。
TOP
おまけ
007でコンテンツを作る場合のおまけ素材(for Boy's Life)。
ワルサー PPK モデル
007ロゴ
TOP
トップページ| サイトマップ|