Please note the changed security model in Silverlight 5, which is a big bummer. My Silverlight MVP friend Morten wrote a few true words about it here.
As usual you can find a list of the samples on the project site and also get the code there.
SLARToolkit is a flexible Augmented Reality library for Silverlight with the aim to make real time Augmented Reality applications with Silverlight as easy and fast as possible. It can be used with Silverlight's Webcam API or with any other CaptureSource or a WriteableBitmap. SLARTookit is based on the established NyARToolkit and ARToolkit.
Performance FLARManager: Not good enough for action gamesBoth toolkits use the same marker-based AR algorithms from the ARToolkit.
Performance SLARToolkit: Very fast and accurate marker tracking
SLARToolkit is a flexible marker-based Augmented Reality library for Silverlight and Windows Phone with the aim to make real time Augmented Reality applications with Silverlight as easy and fast as possible. It can be used with Silverlight's Webcam API or with any other CaptureSource, WriteableBitmap or with the Windows Phone's PhotoCamera. SLARTookit is based on the established NyARToolkit and ARToolkit.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
// Initialize the webcam
photoCamera = new PhotoCamera();
photoCamera.Initialized += PhotoCameraInitialized;
isInitialized = false;
// Fill the Viewport Rectangle with the VideoBrush
var vidBrush = new VideoBrush();
vidBrush.SetSource(photoCamera);
Viewport.Fill = vidBrush;
// Start timer
dispatcherTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(50) };
dispatcherTimer.Tick += (sender, e1) => Detect();
dispatcherTimer.Start();
}
void Detect()
{
if (!isInitialized)
{
return;
}
// Update buffer size
var pixelWidth = photoCamera.PreviewBufferResolution.Width;
var pixelHeight = photoCamera.PreviewBufferResolution.Height;
if (buffer == null || buffer.Length != pixelWidth * pixelHeight)
{
buffer = new byte[pixelWidth * pixelHeight];
}
// Grab snapshot
photoCamera.GetPreviewBufferY(buffer);
// Detect
var dr = arDetector.DetectAllMarkers(buffer, pixelWidth, pixelHeight);
// Calculate the projection matrix
if (dr.HasResults)
{
// Center at origin of the 256x256 controls
var centerAtOrigin = Matrix3DFactory.CreateTranslation(-128, -128, 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;
// Viewport transformation
var viewport = Matrix3DFactory.CreateViewportTransformation(pixelWidth, pixelHeight);
// Calculate the final transformation matrix by using the camera projection matrix
var m = Matrix3DFactory.CreateViewportProjection(world, Matrix3D.Identity, arDetector.Projection, viewport);
// Apply the final transformation matrix to the controls
var matrix3DProjection = new Matrix3DProjection { ProjectionMatrix = m };
Txt.Projection = matrix3DProjection;
Img.Projection = matrix3DProjection;
}
}
void PhotoCameraInitialized(object sender, CameraOperationCompletedEventArgs e)
{
// Initialize the Detector
arDetector = new GrayBufferMarkerDetector();
// Load the marker pattern. It has 16x16 segments and a width of 80 millimeters
var marker = Marker.LoadFromResource("data/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(photoCamera.PreviewBufferResolution.Width, photoCamera.PreviewBufferResolution.Height, 1, 4000, marker);
isInitialized = true;
}
SLARToolkit is a flexible Augmented Reality library for Silverlight with the aim to make real time Augmented Reality applications with Silverlight as easy and fast as possible. It can be used with Silverlight's Webcam API or with any other CaptureSource or a WriteableBitmap. SLARTookit is based on the established NyARToolkit and ARToolkit.
SLARToolkit is a flexible Augmented Reality library for Silverlight with the aim to make real time Augmented Reality applications with Silverlight as easy and fast as possible. It can be used with Silverlight's Webcam API or with any other CaptureSource or a WriteableBitmap. SLARTookit is based on the established NyARToolkit and ARToolkit. SLARToolkit uses a dual license model and could be used for open or closed source applications under certain conditions. See the License page for details.Features: