简体   繁体   English

如何在Google Vision Camera Source上设置矩形对焦区域?

[英]How to set a rectangular focus area on Google Vision Camera Source?

I'm currently having problems with Google vision. 我目前在Google视觉方面遇到问题。 There is nothing wrong with the library actually, its works great. 实际上,该库没有任何问题,它的作品很棒。 All what I'm trying to accomplish now is set a rectangular area where the CameraSource will focus only on. 我现在要完成的所有工作都设置为一个矩形区域,CameraSource仅将其聚焦。 The aim is try to capture text within that particular rectangular box only. 目的是尝试仅捕获该特定矩形框中的文本。 I've tried many examples on StackOverflow but they all didn't seem to work. 我在StackOverflow上尝试了许多示例,但它们似乎都没有用。 My current working code with the Google Vision ( 11.8.0 ) is 我目前在Google Vision(11.8.0)中的工作代码是

cameraView = findViewById(R.id.surfaceview);
        output = findViewById(R.id.output);

        TextRecognizer textRecognizer = new TextRecognizer.Builder(ScanVoucher.this).build();

        if(!textRecognizer.isOperational()) {
            show_alert("Text Recognition not supported on this device");
        } else {

            cameraSource = new CameraSource.Builder(ScanVoucher.this, textRecognizer)
                    .setAutoFocusEnabled(true)
                    .setFacing(CameraSource.CAMERA_FACING_BACK)
                    .setRequestedFps(2.0f)
                    .setRequestedPreviewSize(300, 300)
                    .build();

            cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
                @Override
                public void surfaceCreated(SurfaceHolder surfaceHolder) {
                    try {
                        cameraSource.start(cameraView.getHolder());
                    } catch (IOException e) {
                        show_alert("Unable to access camera");
                    } catch (SecurityException e) {
                        finish();
                    } catch(Exception e) {
                        //Kill
                        finish();
                    }
                }

                @Override
                public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {

                }

                @Override
                public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
                    cameraSource.stop();
                }
            });

            textRecognizer.setProcessor(new Detector.Processor<TextBlock>() {
                @Override
                public void release() {

                }

                @Override
                public void receiveDetections(Detector.Detections<TextBlock> detections) {
                    final SparseArray<TextBlock> items = detections.getDetectedItems();

                    if(items.size() != 0) {
                        output.post(new Runnable() {
                            @Override
                            public void run() {
                                StringBuilder builder = new StringBuilder();

                                for(int i = 0; i < items.size(); i++) {
                                    TextBlock item = items.valueAt(i);
                                    builder.append(item.getValue());
                                }

                                try {
                                    output.setText(builder.toString());
                                } catch (Exception e) {
                                    output.setText(e.getMessage());
                                }

                            }
                        });
                    }
                }
            });
        }

As I said, everything works great. 正如我所说,一切都很好。 Wondering how I could set the rectangular box like preview area so that the camera only captures text with the box just like the QR or bar code scanner apps. 我想知道如何设置矩形框(如预览区域),以便相机仅像QR或条形码扫描仪应用程序一样使用该框捕获文本。 Thanks in advance. 提前致谢。

Please dont abandon project.. You can Reset your .setRequestedPreviewSize(80, 24) to fit. 请不要放弃项目。.您可以重置.setRequestedPreviewSize(80,24)以使其适合。 for me, this only captures the first text line. 对我来说,这仅捕获第一行文本。 i hope you see this 我希望你看到这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM