2. Augmented Reality
a live direct or indirect view of a physical,
real-world environment whose elements
are augmented (or supplemented) by
computer-generated sensory input such
as sound, video, graphics or GPS data
3.
4.
5. Why Augmented Reality?
ā¢ Presents data in a way that we are
accustomed to
ā¢ Can present a lot of data in multiple
ways
Useful
ā¢ Remember the Terminator, he was fun
right?
ā¢ Extends our senses
ā¢ Physical games are more fun
Fun
ā¢ Takes advantage of distinguishing
platform elements
Mobile Only
9. Video Camera
ā
Many resolutions (width and height) and
framerates
ā
Image ļ¬ltering controls
ā
Field of View
ā
High-performance code - be careful!
ā
8 x 106 pixels * 30 Hz =
240,000,000 pixels / second
It all starts here
10. Directly Accessing the Camera (iOS)
session = new AVCaptureSession ();āØ
session.SessionPreset = AVCaptureSession.PresetMedium;āØ
device = AVCaptureDevice.DefaultDeviceWithMediaType (AVMediaType.Video);āØ
device.LockForConfiguration(out error);āØ
device.ActiveVideoMinFrameDuration = new CMTime (1, 30);āØ
device.UnlockForConfiguration();āØ
input = AVCaptureDeviceInput.FromDevice (device, out error);āØ
session.AddInput (input);āØ
11. Getting Images (iOS)
output = new AVCaptureVideoDataOutput ();āØ
output.VideoSettings = new AVVideoSettings (CVPixelFormatType.CV32BGRA);āØ
queue = new DispatchQueue ("VideoCameraQueue");āØ
output.SetSampleBufferDelegateAndQueue (new VideoCameraDelegate { Camera = this } , queue);āØ
session.AddOutput (output);āØ
class VideoCameraDelegate : AVCaptureVideoDataOutputSampleBufferDelegateāØ
{āØ
public override void DidOutputSampleBuffer (AVCaptureOutput captureOutput,
CMSampleBuffer sampleBuffer, āØ
AVCaptureConnection connection)āØ
{āØ
try {āØ
var frame = ImageFromSampleBuffer (sampleBuffer);āØ
Camera.OnFrameCaptured (frame);āØ
sampleBuffer.Dispose ();āØ
} catch (Exception ex) {āØ
Debug.WriteLine (ex);āØ
}āØ
}āØ
}āØ
12. Field of View
public float FieldOfView {āØ
get {āØ
return device.ActiveFormat.VideoFieldOfView;āØ
}āØ
}
Field of View (FOV)
is the Visible Angle
14. Location Sensor
ā
Our friends Latitude & Longitude
ā
Altitude above sea level (sometimes)
ā
10m resolution, on a good day
ā
āBetterā with Wi-ļ¬
ā
āNot greatā indoors
ā
(There are alternatives such as
triangulation from known points)
Global Spherical Coordinates
16. Orientation Sensor
ā
Pitch, Roll, Yaw (3 numbers)
ā
Quaternion (4 numbers)
ā
4x4 Transformation Matrix (16
numbers)
A Variety of Formats
Pitch
Yaw
Roll
ā
Need a āreference orientationā or known
orientation from which to measure
Itās relativeā¦
20. Augmentation Techniques
Overlay 2D Annotations
ā¢ Heads Up Display
ā¢ Terminator
ā¢ Use OpenGL, SceneKit, MonoGame, ā¦
ā¢ Mixing virtual reality with augmented
Show 3D Virtual Objects
Distort Camera Image
ā¢ Enhance recognized and correlated objects
ā¢ Hot / Cold Maps
ā¢ Pixel perfect
ā¢ No lag
21. Aligning the Augmented View to the Video
Camera
A Pinhole Camera Model
ā¢ Simple
ā¢ Used by 3D renderers
ā¢ Only depends on Field of View
ā¢ āClose enoughā to the video camera
In a 3D Cartesian World
ā¢ Use 3D X, Y, Z coordinates instead of
Latitude, Longitude, Altitude
ā¢ Orient the camera by applying the
orientation transform
Projection
Matrix
ModelView
Matrix
24. ModelView Matrix - Two Techniques
ā¢ Very easy
ā¢ Not accurate
ā¢ High latency
ā¢ Best for outdoor unpredictable
environments
Location & Orientation
Sensors
ā¢ Very difļ¬cult
ā¢ Very accurate
ā¢ No latency
ā¢ Best for indoor or controlled
environments
Image Recognition
25. ModelView Matrix from Location & Orientation
public static Matrix4d GetModelView (Location location, Matrix4d orientation)āØ
{āØ
// 1. Calculate position in 3D cartesian world
// 2. Find āup"
// 3. Orient to face the north pole
// 4. Apply the device orientationāØ
}āØ
26. ModelView Matrix: Location to 3D Cartesian
ā¢ Center of earth is at (0, 0, 0)
ā¢ Does not rotate, the universe around it does
ā¢ Physically accurate
ā¢ X, Y, Z are generally unintelligible
Earth-centered, Earth-ļ¬xed
ā¢ Flatten the earth like a map
ā¢ X axis is East/West
ā¢ Y axis is North/South
ā¢ Z axis is Altitude
North, East, Up
27. ModelView Matrix: Location to 3D Cartesian (ECEF)
//āØ
// 1. Calculate position in 3D cartesian worldāØ
//āØ
var pos = location.Position;āØ
public Vector3d Position {āØ
get {āØ
var omega = ToRad * Longitude;āØ
var phi = ToRad * Latitude;āØ
var r = RadiusOfEarth + Altitude;āØ
āØ
return new Vector3d (āØ
r * Math.Cos(phi) * Math.Cos(omega),āØ
r * Math.Cos(phi) * Math.Sin(omega),āØ
r * Math.Sin(phi));āØ
}āØ
}
ā¢ (X, Y, Z)
28. ModelView Matrix: Up
//āØ
// 2. Find "up"āØ
//āØ
var up = location.Position;
up.Normalize ();āØ
ā¢ (0, 0, 0)
ā¢ (X, Y, Z)
Up
29. ModelView Matrix: Look at the North Pole
//āØ
// 3. Orient to face the north poleāØ
//āØ
var northPos = Location.NorthPole.Position;āØ
var northZAxis = (pos - northPos);āØ
northZAxis.Normalize ();āØ
var northYAxis = up;āØ
var northXAxis = Vector3d.Cross (northYAxis, northZAxis);āØ
northXAxis.Normalize ();āØ
northZAxis = Vector3d.Cross (northXAxis, northYAxis);āØ
northZAxis.Normalize ();āØ
var lookNorthI = new Matrix4d (āØ
new Vector4d(northXAxis),āØ
new Vector4d(northYAxis),āØ
new Vector4d(northZAxis),āØ
Vector4d.UnitW);āØ
Location NorthPole = new Location (90, 0, 0);
True North
ā¢ (X, Y, Z)
30. ModelView Matrix: Orient
//āØ
// 4. Apply the device orientationāØ
//āØ
var newOrient = new Matrix4d (āØ
-orientation.Column1,āØ
orientation.Column2,āØ
-orientation.Column0,āØ
Vector4d.UnitW);āØ
var newOrientI = newOrient;āØ
newOrientI.Transpose ();āØ
var modelViewI = (newOrientI * lookNorthI);āØ
modelViewI.Row3 = new Vector4d (pos.X, pos.Y, pos.Z, 1);
var modelView = modelViewI;āØ
modelView.Invert ();āØ
return modelView;
31. Location to 2D View
Projection
Matrix
ModelView
Matrix
3D
Worl
d
Point
2D
View
Point
x x =
(after a
perspective
divide)
32. Location to 2D View
public PointF LocationToView (Location location)āØ
{āØ
// Move location to 3D earthāØ
var pos3d = new Vector4d (location.Position, 1);āØ
āØ
// Camera modelāØ
var m = Matrix4d.Mult (modelViewMatrix, projectionMatrix);āØ
āØ
// Project into homogeneous 2D pointāØ
var pos2h = Vector4d.Transform (pos3d, m);āØ
āØ
// Perform the perspective divideāØ
var pos2 = pos2h / pos2h.W;āØ
āØ
// Stretch into our viewāØ
return new PointF (āØ
(float)((pos2.X + 1) * 0.5) * viewSize.Width,āØ
(float)((-pos2.Y + 1) * 0.5) * viewSize.HeightāØ
);āØ
}āØ
āØ
34. Same Math Can be Used to Make 3D
void SetOpenGLCamera ()āØ
{āØ
GL.MatrixMode (All.Projection);āØ
GL.LoadMatrix (ref projectionMatrix.Row0.X);
āØ
GL.MatrixMode (All.Modelview);āØ
GL.LoadMatrix (ref modelViewMatrix.Row0.X);āØ
}āØ
āØ