Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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. I am using
Google Play Services Vision
for this.
I have created the
TextRecognizer
instance like this:
var textRecognizer = new TextRecognizer.Builder(ApplicationContext).Build();
And, after creating this instance, you can now instantiate the CameraSource
like this:
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. However, I also want to have a BarcodeDetector
like this:
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!
Works OK for me to create a new CameraSource every time u switch between the detectors:
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");
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.