/// <summary>
 /// Creates a new detection result
 /// </summary>
 /// <param name="marker">A reference to the found marker.</param>
 /// <param name="confidence">The confidence / quality  of the result.</param>
 /// <param name="transformation">The transformation matrix for the marker.</param>
 /// <param name="square">The pixel coordinates where the square marker was found. </param>
 public DetectionResult(Marker marker, double confidence, Matrix3D transformation, Square square)
 {
    this.Marker          = marker;
    this.Confidence      = confidence;
    this.Transformation  = transformation;
    this.Square          = square;
 }
Example #2
0
 /// <summary>
 /// Creates a marker instance form the stream data.
 /// </summary>
 /// <param name="markerStream">The stream for the marker data.</param>
 /// <param name="segmentsX">The number of marker segments in x direction.</param>
 /// <param name="segmentsY">The number of marker segments in y direction.</param>
 /// <param name="width">The physical width of the marker in millimeters.</param>
 /// <returns>A new marker instance.</returns>
 public static Marker Load(Stream markerStream, int segmentsX, int segmentsY, double width)
 {
     // Load marker data with segments x segments pattern
     var marker = new Marker
     {
         SegmentsX = segmentsX,
         SegmentsY = segmentsY,
         Width = width,
         NyMarker = new NyARCode(segmentsX, segmentsY),
         RectOffset = new NyARRectOffset(),
     };
     marker.NyMarker.loadARPatt(markerStream);
     marker.RectOffset.setSquare(width);
     return marker;
 }
      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;
         }
      }
      private void UserControlLoaded(object sender, RoutedEventArgs e)
      {
         // Initialize the webcam
         captureSource = new CaptureSource {VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice()};

         // Desired format is 640 x 480 (good tracking results and performance)
         captureSource.VideoCaptureDevice.DesiredFormat = new VideoFormat(PixelFormatType.Unknown, 640, 480, 60);
         captureSource.CaptureImageCompleted += CaptureSourceCaptureImageCompleted;

         // Fill the Viewport Rectangle with the VideoBrush
         var vidBrush = new VideoBrush();
         vidBrush.SetSource(captureSource);
         Viewport.Fill = vidBrush;

         //  Conctruct the Detector
         arDetector = new BitmapMarkerDetector { Threshold = 200, JitteringThreshold = 1 };

         // Load the marker patterns. It has 16x16 segments and a width of 80 millimeters
         slarMarker = Marker.LoadFromResource("data/Marker_SLAR_16x16segments_80width.pat", 16, 16, 80);

         // Capture or transform periodically
         CompositionTarget.Rendering += (s, e2) =>
                                        {
                                           if (captureSource.State == CaptureState.Started)
                                           {
                                              captureSource.CaptureImageAsync();
                                           }
                                           else
                                           {
                                              Game.SetWorldMatrix(Balder.Math.Matrix.Identity);
                                           }
                                           if (Game.ParticleSystem.Particles != null && Game.ParticleSystem.Particles.Count > 0)
                                           {
                                           }
                                        };
      }
 /// <summary>
 /// Initializes the detector for single marker detection.
 /// </summary>
 /// <param name="width">The width of the bitmap that will be used for detection.</param>
 /// <param name="height">The height of the bitmap that will be used for detection.</param>
 /// <param name="nearPlane">The near view plane of the frustum.</param>
 /// <param name="farPlane">The far view plane of the frustum.</param>
 /// <param name="markers">Marker(s) that should be detected.</param>
 /// <param name="adaptive">Performs an adaptive bitmap thresholding if set to true. Default = false.</param>
 public void Initialize(int width, int height, double nearPlane, double farPlane, Marker[] markers, bool adaptive = false)
 {
    Initialize(width, height, nearPlane, farPlane, new List<Marker>(markers), adaptive);
 }
 /// <summary>
 /// Creates a new instance of the PatternMatcher with a marker.
 /// </summary>
 /// <param name="marker">A marker.</param>
 public PatternMatcher(Marker marker)
    : base(marker.NyMarker)
 {
    this.Marker = marker;
 }
      private void UserControlLoaded(object sender, RoutedEventArgs e)
      {
         // Initialize the webcam
         captureSource = new CaptureSource();
         captureSource.VideoCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

         // Desired format is 640 x 480 (good tracking results and performance)
         captureSource.VideoCaptureDevice.DesiredFormat = new VideoFormat(PixelFormatType.Unknown, 640, 480, 60);
         captureSource.CaptureImageCompleted += CaptureSourceCaptureImageCompleted;

         // Fill the Viewport Rectangle with the VideoBrush
         var vidBrush = new VideoBrush();
         vidBrush.SetSource(captureSource);
         Viewport.Fill = vidBrush;

         //  Conctruct the Detector
         arDetector = new BitmapMarkerDetector { Threshold = 200, JitteringThreshold = 1 };

         // Load the marker patterns. It has 16x16 segments and a width of 80 millimeters
         slarMarker = Marker.LoadFromResource("data/Marker_SLAR_16x16segments_80width.pat", 16, 16, 80);
         lMarker = Marker.LoadFromResource("data/Marker_L_16x16segments_80width.pat", 16, 16, 80);
      }