简体   繁体   English

是否可以使用 Google Play Vision 从一个 CameraSource 运行两个检测器

[英]Is it possible to run two detectors from one CameraSource with Google Play Vision

I have an app, on Android only and using Xamarin that I want to do text recognition (OCR) and barcode scanning at approximately the same time.我有一个应用程序,仅在Android使用Xamarin ,我想大约同时进行文本识别 (OCR) 和条形码扫描。 I am using Google Play Services Vision for this.为此,我正在使用Google Play Services Vision

I have created the TextRecognizer instance like this:我已经像这样创建了TextRecognizer实例:

var textRecognizer = new TextRecognizer.Builder(ApplicationContext).Build();

And, after creating this instance, you can now instantiate the CameraSource like this:并且,在创建此实例后,您现在可以像这样实例化CameraSource

cameraSource = new CameraSource.Builder(ApplicationContext, textRecognizer)
     .SetFacing(CameraFacing.Back)
     .SetRequestedPreviewSize(1280, 1024)
     .SetRequestedFps(2.0f)
     .SetAutoFocusEnabled(true)
     .Build();

As you can see, I had to pass the TextRecognizer instance into the CameraSource builder.如您所见,我必须将TextRecognizer实例传递到CameraSource构建器中。 However, I also want to have a BarcodeDetector like this:但是,我也想要一个像这样的BarcodeDetector

barcodeDetector = new BarcodeDetector.Builder(this)
   .SetBarcodeFormats(BarcodeFormat.Code128)
   .SetBarcodeFormats(BarcodeFormat.Code39)
   .SetBarcodeFormats(BarcodeFormat.Pdf417)
   .Build();

The camera source does not allow me to pass in both the text recognizer and the barcode detector.相机源不允许我同时传入文本识别器和条码检测器。 How can I achieve this?我怎样才能做到这一点?

Thanks!谢谢!

Mike麦克风

Works OK for me to create a new CameraSource every time u switch between the detectors:每次在检测器之间切换时,我都可以创建一个新的 CameraSource:

private void AssignAndStartCameraSource(Detector detector)
        {
            if (!detector.IsOperational)
            {
                // Note: The first time that an app using barcode API is installed on a device, GMS will
                // download a native library to the device in order to do detection.  Usually this
                // completes before the app is run for the first time.  But if that download has not yet
                // completed, then the above call will not detect any barcodes.
                //
                // IsOperational can be used to check if the required native library is currently
                // available.  The detector will automatically become operational once the library
                // download completes on device.
                Android.Util.Log.Warn(TAG, "Barcode detector dependencies are not yet available.");
            }

            cameraSource = new CameraSource.Builder(Application.Context, detector)
                .SetRequestedPreviewSize(_requestedPreviewHeight, _requestedPreviewWidth)
                .SetFacing(CameraFacing.Back)
                .SetRequestedFps(20.0f)
                .SetAutoFocusEnabled(true)
                .Build();

            startCameraSource();

            AppLoger.TrackEvent("End RunBarcodeScanner");
        }

暂无
暂无

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

相关问题 Google Vision API示例:让CameraSource成为焦点 - Google Vision API Samples: Get the CameraSource to Focus 从com.google.android.gms.vision.CameraSource访问相机并增加/降低预览亮度 - Accessing the Camera from com.google.android.gms.vision.CameraSource and Increasing/Decreasing the Preview Brightness Xamarin Google Play服务愿景如何在cameraSource中访问基础相机,以便将对焦模式设置为微距? - Xamarin google play service vision How do I access the underlying camera in a cameraSource so I can set the focus mode to macro? 开源Google Vision API CameraSource类是否已过期? - Is the Open Sourced Google Vision API CameraSource class Out-Dated? 在单个CameraSource(Google Mobile Vision)中实现FaceDetector和TextRecognizer - Implement FaceDetector and TextRecognizer in single CameraSource (Google Mobile Vision) 在CameraSource Google Mobile vision API中,setRequestedFps的含义是什么 - What is mean by setRequestedFps in CameraSource Google Mobile vision API Google Mobile Vision:没有CameraSource的FaceDetector性能不佳 - Google Mobile Vision: Poor FaceDetector performance without CameraSource 如何使用MediaRecorder和com.google.android.gms.vision.CameraSource录制视频? - How can I Record Video Using MediaRecorder and com.google.android.gms.vision.CameraSource? 如何通过Google APIs for Android在CameraSource中保存带有覆盖图像的图像? - How to save an image with an overlay on it in CameraSource from Google APIs for android? 从CameraSource裁剪脸部 - Crop face from the CameraSource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM