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?
Asked
Active
Viewed 165 times
1 Answers
0
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;
}

pg316
- 1,380
- 1
- 8
- 7
-
We are working with Zbar library. Can it be a problem for qr code reading? Because we didin't complete the Project. – Tuğçe Acar Jun 06 '16 at 08:15
-
Is it possible to send the Zbar library a bitmap to process? If so you should be able to use it with SmartEyeglass. What problem did you face? – pg316 Jun 06 '16 at 08:19
-
Zbar library is not use a bitmap.But _data_ variable type is a byte array , isn't it? So we are using a _data_ as byte array, not a bitmap. We tried to work with Zxing Library but it is more complicated than Zbar. If you help us to using Zxing, we can continue with it. Like a sample Project or code. – Tuğçe Acar Jun 06 '16 at 08:56
-
I just updated my answer with a sample of how to read a barcode using Google Zxing. Let me know if this helps – pg316 Jun 10 '16 at 07:20
-
Hey I tried to implement zxing as you described in your answer, but somehow I am not able to import the com.google.zxing libaries. It says cannot resolve Symbol "BarcodeFormat" for example thats for every zxing import... – stackg91 Jan 26 '17 at 14:30