How do I integrate QR code reading application to Sony SmartEyeGlass?

175 Views Asked by At

We are developing an application for Sony SmartEyeGlass. Firstly, we created it with Android Studio and android tablet.Now, we are working with Sample Camera Extension sample to integrate it our Project. But there is a lot of details. Someone can help about this subject?

1

There are 1 best solutions below

5
On

The Sample Camera extension is a great place to start building your QR code reader. In the SampleCameraControl.java there is a function called cameraEventOperation. In this function you will see an example of how to pull the camera data down in to a bitmap. Here is the code for reference:

private void cameraEventOperation(CameraEvent event) {

    if ((event.getData() != null) && ((event.getData().length) > 0)) {
        data = event.getData();
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
    }

You can take this data and send it to your QR code reader to scan for QR codes. Let me know if this helps!

----- Update ----

You can use a function like this to pass a bitmap to the Google Zxing library. Use should put this in something like an Async task:

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
import com.google.zxing.FormatException;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.RGBLuminanceSource;
import com.google.zxing.Reader;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
//This function sends the provided bitmap to Google Zxing
public static String readBarcodeImage(Bitmap bMap) {
    String contents = null;

    int[] intArray = new int[bMap.getWidth()*bMap.getHeight()];  
    //copy pixel data from the Bitmap into the 'intArray' array  
    bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());  

    LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(), intArray);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    Reader reader = new MultiFormatReader();// use this otherwise ChecksumException
    try {

        Hashtable<DecodeHintType,Object> hints=new Hashtable<DecodeHintType,Object>();
        hints.put(DecodeHintType.TRY_HARDER,Boolean.TRUE);

        Vector<BarcodeFormat> decodeFormats = new Vector<BarcodeFormat>();

        decodeFormats.add(BarcodeFormat.QR_CODE);

        hints.put(DecodeHintType.POSSIBLE_FORMATS,decodeFormats);

        Result result = reader.decode(bitmap, hints);
        BarcodeFormat format = result.getBarcodeFormat();
        contents = result.getText() + " : "+format.toString();

    } catch (NotFoundException e) { e.printStackTrace(); } 
    catch (ChecksumException e) { e.printStackTrace(); }
    catch (FormatException e) { e.printStackTrace(); }
    return contents;
}