MIX 2011: Sensor and Camera Access in the Next Version of Windows Phone

15 באפריל 2011

אין תגובות

This session was delivered by Mark Paley, Principal Lead Program Manager from Microsoft.

IMG_20110414_091553

The next version of Windows Phone will support a few new sensors, like Gyro and Compass sensors.
Mark started the session by showing several camera and sensors demo.

Some common usage scenario:

  • Sudoku solver
  • Barcode scanner
  • Custom photo application
  • etc.

IMG_20110414_090552

So, what sensors are supported?

  1. Accelerometer – standard on all windows phone devices, provides acceleration data over 3 axis
  2. Compass – gives magnetic heading
  3. Gyroscope – gives rotation velocity (in radians per second) over 3 axis

Mark showed a simple compass application:

IMG_20110414_090927

And explained the compass measures bearing coordinate system.

IMG_20110414_091054

Then Mark presented the new Motion sensor, which is basically all the sensors combined with some math and an easy interface.

IMG_20110414_091210

The motion sensor is the recommended sensor to use, if available.

What it does is it combines the data from all 3 sensors (gyro, compass, accelerometer) to give more accurate information. Since every sensor has it’s own (different) stability problems, we can use all the data combined to eliminate correct the data.

Mark also showed a nice demo of using the motion sensor and how it improves the stability of the measured data.

The motion sensor provides its data in 3 representation:

  • Euler angles
  • Rotation matrix
  • Quaternion

All the sensors have similar API. They all got an IsSupported property, i.e. Accelerometer.IsSupported, Compass.IsSupported, Gyroscope.IsSupported

To use any of the sensors, one needs to create an instance of the sensor, register for the CurrentValueChanged event and start the sensor by using the Start() method.

The compass sometimes needs calibration and thus has a Calibrate event which is raised when needed.

Also, all sensors have a TimeBetweenUpdates setting which controls how often does the event gets generated.

The accelerometer sensor also supported a polling mode where one can use the property accelerometer.IsDataValid and get the current value using accelerometer.CurrnetValue.

Then, Mark showed another demo, this time using the motion sensor and XNA.

So, when you shouldn't use the motion sensor?

  1. When you want data specific to the sensor reading
  2. When you want to do advanced usages like custom motion algorithms or gestures detection
  3. When Motion.IsSupported is false. Note, the motion sensor will work even without a hardware gyroscope sensor

Next, Mark started to talk about the camera sensor.

He showed some demos and presented two ways of using the camera sensor:

  1. Using the PhotoCamera class, which is new in the next version of Windows Phone
  2. Using Silverlight 4 WebCam API, ported from desktop SL, with a few features specific for phone

So, when should you use each API?

You should use the PhotoCamera class when you:

  1. Want to take high resolution photos
  2. Want to handle the hardware camera button
  3. Want to handle focus and flash

You should use the WebCam API when you:

  1. Want to reuse Silverlight 4 knowledge
  2. Want to easily target desktop and phone
  3. Want to record video and audio into a file

Next Mark showed another camera demo, using the PhotoCamera class which has the following APIs:

  • ButtonHalfPress event – raised when the camera hardware button is half pressed
  • ButtonFullPress event – raised when the camera hardware button is fully pressed
  • ButtonRelease event – raised when the camera hardware button is released
  • CaptureCompleted event – raised when the capture of an image is completed
  • camera.Focus() method – will cause the camera to focus
  • camera.CaptureImage() method – will starts to capture an image from the camera sensor

A few more things that are good to know:

  • Most scenarios requires hardware for debugging, only accelerometer and location have an emulator
  • Motion sensors will try to return a result, even if not all 3 sensors exists
  • The camera video output is MP4

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it
הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים