Barcode Scanner doesn't work on Glass GDK

2019-05-22 20:34发布

I am new to Glass GDK development and I have a problem with scanning a barcode. I have followed this(http://blog.wombatsoftware.de/2014/01/running-zxing-qr-code-engine-on-google.html) post but my barcode scanner still doesn't work. it looks like a photo attached. I had a look also on BarcodeEye project but I don't understand how can I integrate it with my project. Can you please help me?

CameraConfiguration

   public void googleGlassInit(Camera camera) {
      Camera.Parameters params = camera.getParameters();
      params.setPreviewFpsRange(30000, 30000);
      params.setPreviewSize(640,360);
      camera.setParameters(params);
    }
    void setTorch(Camera camera, boolean newSetting) {
        Camera.Parameters parameters = camera.getParameters();
        doSetTorch(parameters, newSetting, false);
        camera.setParameters(parameters);
        googleGlassInit(camera); // added this line
       // googleGlassXE10WorkAround(camera);
    }
...

MainActivity.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
         intent.setPackage("com.google.zxing.client.android");
         intent.putExtra("SCAN_MODE","QR_CODE_MODE");
         startActivityForResult(intent,0);  

        }

        //when a QR code is read, it will send a result code 
            protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
             if (requestCode == 0 && resultCode == RESULT_OK){
                String contents = data.getStringExtra("SCAN_RESULT");
                Card card1 = new Card(this);
                card1.setText(contents);
                card1.setFootnote("zxing");
                View card1View = card1.getView();
                setContentView(card1View);
            //    setDisplayCard(card1);

            }
            super.onActivityResult(requestCode, resultCode, data);

    }

enter image description here


2条回答
别忘想泡老子
2楼-- · 2019-05-22 21:21

In CameraConfiguraionManager you also need to add googleGlassInit(camera) in setDesiredCameraParameters.

parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
camera.setParameters(parameters);
googleGlassInit(camera); // added this line

Camera.Parameters afterParameters = camera.getParameters();
Camera.Size afterSize = afterParameters.getPreviewSize();

I hope this help you! This works for me :)

PD: I also use 640x360 so that shouldn't be a problem.

查看更多
太酷不给撩
3楼-- · 2019-05-22 21:36

Google Glass unfortunately does not actually support all of the frame rate / resolution combinations that it implies that it does within the supported camera parameters it exposes. If you choose settings that are not actually supported, you get a display like this often.

This got a lot better in XE16.2 but still happens for high resolutions.

You can take some inspiration from the camera config in this port of the Barcode Scanner app from the original project to Glass, which works:

https://github.com/zxing/zxing/blob/master/glass/src/com/google/zxing/client/glass/CameraConfigurationManager.java

1280 x 720 at 10fps seems fine.

查看更多
登录 后发表回答