コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: joaolimiere/Artigos
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            
            captureSource = new CaptureSource
                                {
                                    VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()
                                };

            var videoBrush = new VideoBrush();
            videoBrush.SetSource(captureSource);
            Viewport.Fill = videoBrush;

            markerDetector = new CaptureSourceMarkerDetector();
            var marker = Marker.LoadFromResource("Bola.pat", 64, 64, 80);
            markerDetector.Initialize(captureSource, 1d, 4000d, marker);

            markerDetector.MarkersDetected += (obj, args) =>
                                                  {
                                                      Dispatcher.BeginInvoke(() =>
                                                                                 {
                                                                                     var results = args.DetectionResults;
                                                                                     if (results.HasResults)
                                                                                     {
                                                                                         var centerAtOrigin =
                                                                                             Matrix3DFactory.
                                                                                                 CreateTranslation(
                                                                                                     -Imagem.ActualWidth*
                                                                                                     0.5,
                                                                                                     -Imagem.
                                                                                                          ActualHeight*
                                                                                                     0.5, 0);
                                                                                         var scale =
                                                                                             Matrix3DFactory.CreateScale
                                                                                                 (0.5, -0.5, 0.5);
                                                                                         var world = centerAtOrigin*
                                                                                                     scale*
                                                                                                     results[0].
                                                                                                         Transformation;
                                                                                         var vp =
                                                                                             Matrix3DFactory.
                                                                                                 CreateViewportTransformation
                                                                                                 (Viewport.ActualWidth,
                                                                                                  Viewport.ActualHeight);
                                                                                         var m =
                                                                                             Matrix3DFactory.
                                                                                                 CreateViewportProjection
                                                                                                 (world,
                                                                                                  Matrix3D.Identity,
                                                                                                  markerDetector.
                                                                                                      Projection, vp);
                                                                                         Imagem.Projection =
                                                                                             new Matrix3DProjection
                                                                                                 {ProjectionMatrix = m};
                                                                                     }
                                                                                 });
                                                  };
        }
コード例 #2
0
      private void InitializeDetector()
      {
         //  Initialize the Detector
         arDetector = new CaptureSourceMarkerDetector();
         
         // Load the marker pattern. It has 16x16 segments and a width of 80 millimeters
         var marker = Marker.LoadFromResource("Marker_SLAR_16x16segments_80width.pat", 16, 16, 80);
         
         // The perspective projection has the near plane at 1 and the far plane at 4000
         arDetector.Initialize(captureSource, 1, 4000, new List<Marker> { marker }, adaptive.IsChecked.Value);
         
         // Attach the AR detection event handler
         // The event is fired if at least one marker was detected
         arDetector.MarkersDetected += (s, me) =>
         {
            // Change to UI thread in order to manipulate the text control's projection
            Dispatcher.BeginInvoke(() =>
            {
               // Calculate the projection matrix
               var dr = me.DetectionResults;
               if (dr.HasResults)
               {
                  // Center at origin of the TextBlock
                  var centerAtOrigin = Matrix3DFactory.CreateTranslation(-Txt.ActualWidth * 0.5, -Txt.ActualHeight * 0.5, 0);
                  // Swap the y-axis and scale down by half
                  var scale = Matrix3DFactory.CreateScale(0.5, -0.5, 0.5);
                  // Calculate the complete transformation matrix based on the first detection result
                  var world = centerAtOrigin * scale * dr[0].Transformation;

                  // Calculate the final transformation matrix by using the camera projection matrix 
                  var vp = Matrix3DFactory.CreateViewportTransformation(Viewport.ActualWidth, Viewport.ActualHeight);
                  var m = Matrix3DFactory.CreateViewportProjection(world, Matrix3D.Identity, arDetector.Projection, vp);

                  // Apply the final transformation matrix to the TextBox
                  Txt.Projection = new Matrix3DProjection { ProjectionMatrix = m };
               }
            });
         };
      }