Camera

The SmartEyeglass device provides a built-in camera which enables users to take still pictures and record videos from the user’s point of view.

The camera sensor data is available through the SmartEyeglass API. Your app can use the camera raw data for image processing, or to store still pictures or JPEG streams on the host device.

This guide tells you how to:

  • Listen to camera events.
  • Set the camera mode, quality and resolution.
  • Trigger the camera programmatically to capture still pictures or to stream JPEG images.

The basics

To get started working with the camera, set up a project using the SampleCameraExtension as a base; see more about creating SmartEyeglass projects in the How to create your first SmartEyeglass project tutorial.

Register for Camera API usage

You will use the Camera API, defined in the SmartEyeglassControlUtils class, to control the camera. In order to use this API, you must declare this specific permission in your Android manifest. In the AndroidManifest.xml file in your project, make sure you include this element:

<uses-permission android:name="com.sony.smarteyeglass.permission.CAMERA" />

You must also register the Control API version with the HostApp. Your class that extends RegistrationInformation must get the version of this API:

@Override
public int getRequiredControlApiVersion() {
    return 4;
}

The SampleCameraExtension project does both of these things. If you don’t use this sample as a base, make sure you do the same.

Listen to camera events

Before programmatically triggering the camera shutter you need to start listening to various camera events, which you will receive after a picture has been captured. To do this, you need to instantiate SmartEyeglassControlUtils in your ControlExtension implementation:

class SampleCameraControl extends ControlExtension {

    private final Context mContext;
    private final SmartEyeglassControlUtils mSmartEyeglassControlUtils;

    SampleCameraControl(final String hostAppPackageName, final Context context) {
        super(context, hostAppPackageName);
        this.mContext = context;
        this.mSmartEyeglassControlUtils = new SmartEyeglassControlUtils(
		context, hostAppPackageName, mSmartEyeglassEventListener);
    }
}

The mSmartEyeglassEventListener is an instance of a class that implements the event callbacks. Choose which events you want to listen to, and define handlers for them. For the full list, see documentation of the SmartEyeglassEventListener class.

private final SmartEyeglassEventListener mSmartEyeglassEventListener =
 new MySmartEyeglassEventListener();

 class MySmartEyeglassEventListener extends SmartEyeglassEventListener {
 @Override
 public void onCameraReceived(CameraEvent event) {
 }
 @Override
 public void onCameraErrorReceived(int error) {
 }
 @Override
 public void onCameraReceivedFile(String filePath) {
 }

 }

Set the camera mode

You must use the SmartEyeglassControlUtils.setCameraMode() method to set the mode before you do any other camera configuration. You must then complete all configuration operations (such as setting a file path) before actually taking a picture.

When setting the camera mode, you also specify the JPEG quality and a resolution that is appropriate to the mode.

mSmartEyeglassControlUtils.setCameraMode(jpegQuality, resolution, mode);
jpegQuality SmartEyeglassControl.Intents.EXTRA_JPEG_QUALITY constant.

  • One of Standard, Fine, or Superfine
resolution A SmartEyeglassControl.Intents.EXTRA_RESOLUTION constant.

  • For still images, 3M, 1M, VGA or QVGA
  • For image stream modes, QVGA.
mode A SmartEyeglassControl.Intents.EXTRA_CAMERA_MODE constant.

These are the possible modes:

  • Still modes: Still, Still to file
  • Image stream modes: JPEG stream low rate, JPEG stream high rate

Image stream modes

The  JPEG stream modes are supported only when the High Performance power mode is on—that is, when there is a Wireless LAN connection between the SmartEyeglass device and its host Android device. For details of how to set the power mode, see the Settings guide. If you try to use the streaming JPEG camera modes over a Bluetooth connection, the resulting data is corrupted.

The low rate for image streaming is 7.5 FPS. The high rate is 15 FPS.

Take a still picture

After all setup and configuration is complete, you can trigger the camera shutter programmatically:

mSmartEyeglassControlUtils.requestCameraCapture();

The result of this action depends on the mode you have set and the callback you have registered in your event listener.

Still mode: This code snippet illustrates how a callback can access and process image data sent to onCameraReceived callback when the camera mode is set to CAMERA_MODE_STILL.

@Override
 public void onCameraReceived(CameraEvent <em>event</em>) {

Bitmap bitmap = null;

byte[] data = null;

// Index indicates data type: 0 for picture data

if(event.getIndex() == 0) {

if((event.getData() != null) && ((event.getData().length) > 0)) {

data = event.getData();

bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

// Process the bitmap...

}

}

}

Still-to-file mode: When the camera mode is set to CAMERA_MODE_STILL_TO_FILE, the captured picture is directly stored to the host-device memory. Before taking a picture using this mode , you must configure a destination file path by calling StartCamera (filePath). When you have triggered the capture operation, your onCameraReceivedFile callback receives path of the captured image:

@Override
public void onCameraReceivedFile(String filePath) { … }

The picture is taken in color, but if you show it on the SmartEyeglass device, it is displayed in monochrome.

Start and stop image streaming

After all setup and configuration is complete, use the following functions to begin and end JPEG streaming programmatically:

mSmartEyeglassControlUtils.startCamera([filePath]);
mSmartEyeglassControlUtils.stopCamera();

If you specify a destination file path as an optional parameter in the start function, captured images are written directly to that file. If you omit the filePath parameter, the captured results are passed to your onCameraReceived callback when you stop the capture operation.

Learn from the code example

For a more complete example of how to use the SmartEyeglass camera, see the SampleCameraExtension sample project in the /samples folder of the SmartEyeglass SDK.

Comments 0

Sort by:

Showing 0 of 0 comments. Show all comments