Wolfram Language

Traitement d'images et de signaux

Réalité augmentée aux objets en rotation

ImageDisplacements capte le champ de flux optique dans une séquence vidéo en temps réel. À travers la boucle , vous pouvez détecter un mouvement d'une main tournant devant votre appareil photo intégré. Ainsi, vous pouvez augmenter ou diminuer le temps d'une horloge virtuelle dans un exemple de réalité augmentée.

La boucle d'un champ vectoriel détermine la quantité inhérente de rotation.

In[1]:=
Click for copyable input
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"];
Montrer l'entrée complète de Wolfram Language
In[2]:=
Click for copyable input
(* Convert the incoming video frames to gray scale and swap left and \ right to mimic a mirror image. *) preProcessFrame = img \[Function] ImageReflect[ColorConvert[img, "Grayscale"], Left -> Right];

Le code complet de cet exemple de réalité augmentée est moins d'une page.

In[3]:=
Click for copyable input
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} ] ]
Jouer l'animation
Arrêter l'annimation

Exemples connexes

de en es ja ko pt-br ru zh