Exemplo n.º 1
0
        private void Initialize()
        {
            try
            {
                // Init variables
                timedRotation = 0;
                Scale         = 0.4;
                Rotate        = 0;

                // Init capture source
                captureSource = new CaptureSource();
                captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

                // Desired format is 320 x 240 (good tracking results and performance)
                captureSource.VideoCaptureDevice.DesiredFormat = new VideoFormat(PixelFormatType.Unknown, 320, 240, 30);

                // Init AR
                markerSlar = Marker.LoadFromResource("data/Marker_SLAR_16x16segments_80width.pat", 16, 16, 80.0, "SLAR");
                markerL    = Marker.LoadFromResource("data/Marker_L_16x16segments_80width.pat", 16, 16, 80.0, "L");
                ArDetector = new CaptureSourceMarkerDetector(captureSource, 1, 4000, new List <Marker> {
                    markerSlar, markerL
                });
                AttachAREvent();

                // Init Rest
                projectionMatrix = Matrix3DFactory.CreatePerspectiveFieldOfViewRH(0.7, ViewportContainer.Width / ViewportContainer.Height, 1, 4000);
                this.DataContext = this;

                // Start all
                SetARObject();
                RunUpdate();
            }
            catch (Exception ex)
            {
                var builder = new StringBuilder();
                foreach (var sf in captureSource.VideoCaptureDevice.SupportedFormats)
                {
                    builder.AppendFormat("{0}: {1} x {2} @ {3} fps. Stride: {4}\r\n", sf.PixelFormat, sf.PixelWidth, sf.PixelHeight, sf.FramesPerSecond, sf.Stride);
                }
                MessageBox.Show("Error during initialization. Please make sure a default webcam was set.\r\nSupported formats:\r\n" + builder.ToString() + "\r\n\r\n" + ex.ToString(), "Error during init.", MessageBoxButton.OK);
                throw;
            }
        }