回転するオブジェクトの拡張現実
ImageDisplacementsは,ビデオシーケンス内のオプティカルフロー場をリアルタイムで捉える.回転
を通して,組込みカメラ前方の回転する針の動きを検知することができる.したがって,拡張現実の例における仮想時計の時間を進めたり戻したりすることができる.
ベクトル場の回転
は,回転の固有量を決定する.
In[1]:=

listCurl =
flow \[Function]
ListConvolve[{{0.5`, 0, -0.5`}},
flow[[All, All, 2]], {{1, 2}, {1, 2}}, "Fixed"] -
ListConvolve[{{-0.5`}, {0.`}, {0.5`}},
flow[[All, All, 1]], {{1, 2}, {1, 2}}, "Fixed"];
完全なWolfram言語入力を表示する
この拡張現実の例に使われるコードは全体でも1ページ未満である.
In[3]:=

DynamicModule[
{frames, flow, curl, mask, time = 0, W = 320, H = 240, w = 240,
h = 160, r = 64},
(* specify a sensitive image region *)
mask = ImageCompose[
ConstantImage[0, {W, H}],
ImageAdjust[Image[GaussianMatrix[r/2]]],
{w, h}
];
(* initialize the optical flow acquisition *)
frames = Table[preProcessFrame@CurrentImage[], {2}];
flow = First@ImageDisplacements[frames];
Graphics[
{Inset[
(* read and display camera image, determine the curl *)
Dynamic[
frames[[1]] = frames[[2]];
frames[[2]] = preProcessFrame@CurrentImage[];
flow = First@ImageDisplacements[frames, 0.7 flow];
curl = Image@listCurl@flow;
time -= 2 ImageMeasurements[curl, "Mean", Masking -> mask];
frames[[2]]
],
{0, 0}, {0, 0}, {W, H}
],
Inset[
(* display clock *)
Dynamic[
ClockGauge[
DatePlus[Date[], {Round[5 time, 5], "Minute"}],
GaugeStyle -> RGBColor[1, 0.75, 0],
LabelStyle -> White,
GaugeFaceStyle -> Opacity[0.1]
],
UpdateInterval -> 1
],
{w, h}, {0, 0}, {2 r, 2 r}
]
},
PlotRange -> {{0, W}, {0, H}},
ImageSize -> {W, H}
]
]
