[英]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.