Faking 3D with 2D tracking data is something that I've long wanted to implement for use with my front facing laptop camera. A first step to solving this would be dynamically setting the viewpoint according to the movement of your head.
Edit:
To clarify, I'm looking for an answer like the code I'm giving below. The reason I ask is because there were a number of problems with my own solution:
- The method used is not sensitive enough
- It is far too slow
- Not robust to background movement
So a real answer to this question might use some fancy bit of machine vision, or interface with opencv face tracking libraries, or something else entirely. Here is a video of this technique applied sucessfully: http://www.youtube.com/watch?v=7saRtCUgbNI
ClusterMean[x_, 0, _] := Mean[x];
ClusterMean[{x_}, n_, frac_] := x;
ClusterMean[x_, n_, frac_] :=
With[{m = Mean[x], sd = StandardDeviation[x]},
With[{x2 = Select[x, Norm[Norm[# - m]/sd] < frac &]},
If[x2 == {}, Mean[x], ClusterMean[x2, n - 1, frac]]]];
$ytrim = $xtrim = {1, All};
SmallCurrentImage[] := ImageTake[CurrentImage[], $ytrim, $xtrim];
$first = SmallCurrentImage[];
FaceOffset[center : {_, _}] :=
Module[{mean, img1, img2, matches}, mean = {0, 0};
img1 = $first;
$currentimage = img2 = SmallCurrentImage[];
$matches = matches = ImageCorrespondingPoints[img1, img2];
mean = MapThread[Subtract, matches];
If[mean == {}, center, ClusterMean[mean, 1, 0.8]]
]
center = {0, 0}; center2 = {0, 0}; $first = SmallCurrentImage[];
Dynamic[
If[CurrentValue["MouseOver"], center = FaceOffset[center];
center2 = center2*0.5 + center*0.5;];
Refresh[
Labeled[
Refresh[
Graphics3D[{PolyhedronData["RhombicHexecontahedron",
"Faces"]},
ViewPoint ->
Refresh[5*Normalize[Prepend[-center2/80, -1]],
TrackedSymbols :> {center}], SphericalRegion -> True,
RotationAction -> "Clip"],
None], {Show[$currentimage,
Graphics[{Red, MapThread[Line[{#1, #2}] &, $matches]}]],
Button["Reset View", ($first = SmallCurrentImage[];
center2 = {0, 0};), Appearance -> "Palette",
ImageSize -> Automatic]}, {Left, {Bottom, Right}}],
TrackedSymbols :> {center}]]