बारकोड को पहचानने और डिकोड करने के लिए, ML Kit का इस्तेमाल किया जा सकता है.
सुविधा | अनबंडल किया गया | बंडल किए गए |
---|---|---|
लागू करना | मॉडल को Google Play Services के ज़रिए डाइनैमिक तरीके से डाउनलोड किया जाता है. | मॉडल को बिल्ड टाइम में, आपके ऐप्लिकेशन से स्टैटिक तौर पर लिंक किया जाता है. |
ऐप्लिकेशन का साइज़ | साइज़ में करीब 200 केबी की बढ़ोतरी होती है. | साइज़ में करीब 2.4 एमबी की बढ़ोतरी हुई है. |
डेटा लेयर में इवेंट बनाने की प्रोसेस में लगने वाला समय | पहली बार इस्तेमाल करने से पहले, मॉडल को डाउनलोड होने में समय लग सकता है. | मॉडल तुरंत उपलब्ध हो जाता है. |
इसे आज़माएं
- इस एपीआई के इस्तेमाल का उदाहरण देखने के लिए, सैंपल ऐप्लिकेशन का इस्तेमाल करें.
- इस एपीआई को शुरू से लेकर आखिर तक लागू करने के लिए, Material Design Showcase ऐप्लिकेशन देखें.
शुरू करने से पहले
अपने प्रोजेक्ट-लेवल की
build.gradle
फ़ाइल में, पक्का करें कि आपने Google की Maven रिपॉज़िटरी कोbuildscript
औरallprojects
, दोनों सेक्शन में शामिल किया हो.अपने मॉड्यूल की ऐप्लिकेशन-लेवल की gradle फ़ाइल में, ML Kit Android लाइब्रेरी के लिए डिपेंडेंसी जोड़ें. यह फ़ाइल आम तौर पर
app/build.gradle
होती है. अपनी ज़रूरतों के हिसाब से, इनमें से कोई एक डिपेंडेंसी चुनें:मॉडल को अपने ऐप्लिकेशन के साथ बंडल करने के लिए:
dependencies { // ... // Use this dependency to bundle the model with your app implementation 'com.google.mlkit:barcode-scanning:17.3.0' }
Google Play Services में मॉडल का इस्तेमाल करने के लिए:
dependencies { // ... // Use this dependency to use the dynamically downloaded model in Google Play Services implementation 'com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.1' }
अगर आपको Google Play services में मॉडल का इस्तेमाल करना है, तो अपने ऐप्लिकेशन को इस तरह कॉन्फ़िगर किया जा सकता है कि Play Store से ऐप्लिकेशन इंस्टॉल होने के बाद, मॉडल अपने-आप डिवाइस पर डाउनलोड हो जाए. इसके लिए, अपने ऐप्लिकेशन की
AndroidManifest.xml
फ़ाइल में यह एलान जोड़ें:<application ...> ... <meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="barcode" > <!-- To use multiple models: android:value="barcode,model2,model3" --> </application>
Google Play services ModuleInstallClient API के ज़रिए, मॉडल की उपलब्धता की जांच की जा सकती है. साथ ही, डाउनलोड करने का अनुरोध किया जा सकता है.
अगर आपने इंस्टॉल-टाइम मॉडल डाउनलोड करने की सुविधा चालू नहीं की है या डाउनलोड करने का अनुरोध नहीं किया है, तो स्कैनर को पहली बार चलाने पर मॉडल डाउनलोड हो जाता है. डाउनलोड पूरा होने से पहले किए गए अनुरोधों से कोई नतीजा नहीं मिलता.
इनपुट इमेज के लिए दिशा-निर्देश
-
बारकोड को सटीक तरीके से पढ़ने के लिए, ML Kit को ऐसी इमेज की ज़रूरत होती है जिनमें बारकोड मौजूद हों. साथ ही, बारकोड को दिखाने के लिए पिक्सल का सही डेटा मौजूद हो.
पिक्सेल डेटा की खास ज़रूरी शर्तें, बारकोड के टाइप और उसमें कोड किए गए डेटा की मात्रा, दोनों पर निर्भर करती हैं. ऐसा इसलिए, क्योंकि कई बारकोड अलग-अलग साइज़ के पेलोड के साथ काम करते हैं. आम तौर पर, बारकोड की सबसे छोटी यूनिट कम से कम 2 पिक्सल चौड़ी होनी चाहिए. साथ ही, 2 डाइमेंशन वाले कोड के लिए, यह 2 पिक्सल लंबी होनी चाहिए.
उदाहरण के लिए, EAN-13 बारकोड में बार और स्पेस होते हैं. इनकी चौड़ाई 1, 2, 3 या 4 यूनिट होती है. इसलिए, EAN-13 बारकोड इमेज में बार और स्पेस की चौड़ाई कम से कम 2, 4, 6, और 8 पिक्सल होनी चाहिए. EAN-13 बारकोड की कुल चौड़ाई 95 यूनिट होती है. इसलिए, बारकोड की चौड़ाई कम से कम 190 पिक्सल होनी चाहिए.
PDF417 जैसे डेंसर फ़ॉर्मैट को ML Kit से सही तरीके से पढ़ने के लिए, ज़्यादा पिक्सल डाइमेंशन की ज़रूरत होती है. उदाहरण के लिए, PDF417 कोड में एक लाइन में ज़्यादा से ज़्यादा 34 "शब्द" हो सकते हैं. हर शब्द की चौड़ाई 17 यूनिट होती है. इसलिए, लाइन की चौड़ाई कम से कम 1156 पिक्सल होनी चाहिए.
-
इमेज के फ़ोकस सही न होने से, स्कैनिंग की सटीकता पर असर पड़ सकता है. अगर आपके ऐप्लिकेशन को सही नतीजे नहीं मिल रहे हैं, तो उपयोगकर्ता से इमेज को फिर से कैप्चर करने के लिए कहें.
-
सामान्य ऐप्लिकेशन के लिए, हमारा सुझाव है कि आप ज़्यादा रिज़ॉल्यूशन वाली इमेज उपलब्ध कराएं. जैसे, 1280x720 या 1920x1080. इससे बारकोड को कैमरे से ज़्यादा दूरी से भी स्कैन किया जा सकता है.
हालांकि, जिन ऐप्लिकेशन में कम समय में जवाब देना ज़रूरी होता है उनमें कम रिज़ॉल्यूशन पर इमेज कैप्चर करके परफ़ॉर्मेंस को बेहतर बनाया जा सकता है. हालांकि, इसके लिए यह ज़रूरी है कि बारकोड, इनपुट इमेज का ज़्यादातर हिस्सा हो. रीयल-टाइम परफ़ॉर्मेंस को बेहतर बनाने के लिए सलाह भी देखें.
1. बारकोड स्कैनर को कॉन्फ़िगर करना
अगर आपको पता है कि आपको कौनसे बारकोड फ़ॉर्मैट पढ़ने हैं, तो बारकोड डिटेक्टर की स्पीड को बेहतर बनाया जा सकता है. इसके लिए, आपको इसे सिर्फ़ उन फ़ॉर्मैट का पता लगाने के लिए कॉन्फ़िगर करना होगा.उदाहरण के लिए, सिर्फ़ ऐज़्टेक कोड और क्यूआर कोड का पता लगाने के लिए, यहां दिए गए उदाहरण की तरह BarcodeScannerOptions
ऑब्जेक्ट बनाएं:
Kotlin
val options = BarcodeScannerOptions.Builder() .setBarcodeFormats( Barcode.FORMAT_QR_CODE, Barcode.FORMAT_AZTEC) .build()
Java
BarcodeScannerOptions options = new BarcodeScannerOptions.Builder() .setBarcodeFormats( Barcode.FORMAT_QR_CODE, Barcode.FORMAT_AZTEC) .build();
इन फ़ॉर्मैट का इस्तेमाल किया जा सकता है:
- Code 128 (
FORMAT_CODE_128
) - Code 39 (
FORMAT_CODE_39
) - कोड 93 (
FORMAT_CODE_93
) - Codabar (
FORMAT_CODABAR
) - EAN-13 (
FORMAT_EAN_13
) - EAN-8 (
FORMAT_EAN_8
) - आईटीएफ़ (
FORMAT_ITF
) - UPC-A (
FORMAT_UPC_A
) - UPC-E (
FORMAT_UPC_E
) - क्यूआर कोड (
FORMAT_QR_CODE
) - PDF417 (
FORMAT_PDF417
) - ऐज़टेक (
FORMAT_AZTEC
) - डेटा मैट्रिक्स (
FORMAT_DATA_MATRIX
)
बंडल किए गए मॉडल 17.1.0 और अनबंडल किए गए मॉडल 18.2.0 से, enableAllPotentialBarcodes()
को कॉल किया जा सकता है. इससे सभी संभावित बारकोड दिखेंगे, भले ही उन्हें डिकोड न किया जा सके. इसका इस्तेमाल, ज़्यादा जानकारी का पता लगाने के लिए किया जा सकता है. उदाहरण के लिए, कैमरे को ज़ूम इन करके, बाउंडिंग बॉक्स में मौजूद किसी भी बारकोड की साफ़ इमेज पाई जा सकती है.
Kotlin
val options = BarcodeScannerOptions.Builder() .setBarcodeFormats(...) .enableAllPotentialBarcodes() // Optional .build()
Java
BarcodeScannerOptions options = new BarcodeScannerOptions.Builder() .setBarcodeFormats(...) .enableAllPotentialBarcodes() // Optional .build();
Further on, starting from bundled library 17.2.0 and unbundled library 18.3.0, a new feature called auto-zoom has been introduced to further enhance the barcode scanning experience. With this feature enabled, the app is notified when all barcodes within the view are too distant for decoding. As a result, the app can effortlessly adjust the camera's zoom ratio to the recommended setting provided by the library, ensuring optimal focus and readability. This feature will significantly enhance the accuracy and success rate of barcode scanning, making it easier for apps to capture information precisely.
To enable auto-zooming and customize the experience, you can utilize the
setZoomSuggestionOptions()
method along with your
own ZoomCallback
handler and desired maximum zoom
ratio, as demonstrated in the code below.
Kotlin
val options = BarcodeScannerOptions.Builder() .setBarcodeFormats(...) .setZoomSuggestionOptions( new ZoomSuggestionOptions.Builder(zoomCallback) .setMaxSupportedZoomRatio(maxSupportedZoomRatio) .build()) // Optional .build()
Java
BarcodeScannerOptions options = new BarcodeScannerOptions.Builder() .setBarcodeFormats(...) .setZoomSuggestionOptions( new ZoomSuggestionOptions.Builder(zoomCallback) .setMaxSupportedZoomRatio(maxSupportedZoomRatio) .build()) // Optional .build();
zoomCallback
is required to be provided to handle whenever the library
suggests a zoom should be performed and this callback will always be called on
the main thread.
The following code snippet shows an example of defining a simple callback.
Kotlin
fun setZoom(ZoomRatio: Float): Boolean { if (camera.isClosed()) return false camera.getCameraControl().setZoomRatio(zoomRatio) return true }
Java
boolean setZoom(float zoomRatio) { if (camera.isClosed()) { return false; } camera.getCameraControl().setZoomRatio(zoomRatio); return true; }
maxSupportedZoomRatio
is related to the camera hardware, and different camera
libraries have different ways to fetch it (see the javadoc of the setter
method). In case this is not provided, an
unbounded zoom ratio might be produced by the library which might not be
supported. Refer to the
setMaxSupportedZoomRatio()
method
introduction to see how to get the max supported zoom ratio with different
Camera libraries.
When auto-zooming is enabled and no barcodes are successfully decoded within
the view, BarcodeScanner
triggers your zoomCallback
with the requested
zoomRatio
. If the callback correctly adjusts the camera to this zoomRatio
,
it is highly probable that the most centered potential barcode will be decoded
and returned.
A barcode may remain undecodable even after a successful zoom-in. In such cases,
BarcodeScanner
may either invoke the callback for another round of zoom-in
until the maxSupportedZoomRatio
is reached, or provide an empty list (or a
list containing potential barcodes that were not decoded, if
enableAllPotentialBarcodes()
was called) to the OnSuccessListener
(which
will be defined in step 4. Process the image).
2. Prepare the input image
To recognize barcodes in an image, create anInputImage
object
from either a Bitmap
, media.Image
, ByteBuffer
, byte array, or a file on
the device. Then, pass the InputImage
object to the
BarcodeScanner
's process
method.
You can create an InputImage
object from different sources, each is explained below.
Using a media.Image
To create an InputImage
object from a media.Image
object, such as when you capture an image from a
device's camera, pass the media.Image
object and the image's
rotation to InputImage.fromMediaImage()
.
If you use the
CameraX library, the OnImageCapturedListener
and
ImageAnalysis.Analyzer
classes calculate the rotation value
for you.
Kotlin
private class YourImageAnalyzer : ImageAnalysis.Analyzer { override fun analyze(imageProxy: ImageProxy) { val mediaImage = imageProxy.image if (mediaImage != null) { val image = InputImage.fromMediaImage(mediaImage, imageProxy.imageInfo.rotationDegrees) // Pass image to an ML Kit Vision API // ... } } }
Java
private class YourAnalyzer implements ImageAnalysis.Analyzer { @Override public void analyze(ImageProxy imageProxy) { Image mediaImage = imageProxy.getImage(); if (mediaImage != null) { InputImage image = InputImage.fromMediaImage(mediaImage, imageProxy.getImageInfo().getRotationDegrees()); // Pass image to an ML Kit Vision API // ... } } }
अगर आपको ऐसी कैमरा लाइब्रेरी का इस्तेमाल नहीं करना है जिससे इमेज के रोटेशन डिग्री का पता चलता है, तो डिवाइस के रोटेशन डिग्री और डिवाइस में कैमरा सेंसर के ओरिएंटेशन से, इमेज के रोटेशन डिग्री का हिसाब लगाया जा सकता है:
Kotlin
private val ORIENTATIONS = SparseIntArray() init { ORIENTATIONS.append(Surface.ROTATION_0, 0) ORIENTATIONS.append(Surface.ROTATION_90, 90) ORIENTATIONS.append(Surface.ROTATION_180, 180) ORIENTATIONS.append(Surface.ROTATION_270, 270) } /** * Get the angle by which an image must be rotated given the device's current * orientation. */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Throws(CameraAccessException::class) private fun getRotationCompensation(cameraId: String, activity: Activity, isFrontFacing: Boolean): Int { // Get the device's current rotation relative to its "native" orientation. // Then, from the ORIENTATIONS table, look up the angle the image must be // rotated to compensate for the device's rotation. val deviceRotation = activity.windowManager.defaultDisplay.rotation var rotationCompensation = ORIENTATIONS.get(deviceRotation) // Get the device's sensor orientation. val cameraManager = activity.getSystemService(CAMERA_SERVICE) as CameraManager val sensorOrientation = cameraManager .getCameraCharacteristics(cameraId) .get(CameraCharacteristics.SENSOR_ORIENTATION)!! if (isFrontFacing) { rotationCompensation = (sensorOrientation + rotationCompensation) % 360 } else { // back-facing rotationCompensation = (sensorOrientation - rotationCompensation + 360) % 360 } return rotationCompensation }
Java
private static final SparseIntArray ORIENTATIONS = new SparseIntArray(); static { ORIENTATIONS.append(Surface.ROTATION_0, 0); ORIENTATIONS.append(Surface.ROTATION_90, 90); ORIENTATIONS.append(Surface.ROTATION_180, 180); ORIENTATIONS.append(Surface.ROTATION_270, 270); } /** * Get the angle by which an image must be rotated given the device's current * orientation. */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private int getRotationCompensation(String cameraId, Activity activity, boolean isFrontFacing) throws CameraAccessException { // Get the device's current rotation relative to its "native" orientation. // Then, from the ORIENTATIONS table, look up the angle the image must be // rotated to compensate for the device's rotation. int deviceRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int rotationCompensation = ORIENTATIONS.get(deviceRotation); // Get the device's sensor orientation. CameraManager cameraManager = (CameraManager) activity.getSystemService(CAMERA_SERVICE); int sensorOrientation = cameraManager .getCameraCharacteristics(cameraId) .get(CameraCharacteristics.SENSOR_ORIENTATION); if (isFrontFacing) { rotationCompensation = (sensorOrientation + rotationCompensation) % 360; } else { // back-facing rotationCompensation = (sensorOrientation - rotationCompensation + 360) % 360; } return rotationCompensation; }
इसके बाद, media.Image
ऑब्जेक्ट और रोटेशन डिग्री की वैल्यू को InputImage.fromMediaImage()
में पास करें:
Kotlin
val image = InputImage.fromMediaImage(mediaImage, rotation)
Java
InputImage image = InputImage.fromMediaImage(mediaImage, rotation);
फ़ाइल यूआरआई का इस्तेमाल करना
किसी फ़ाइल यूआरआई से InputImage
ऑब्जेक्ट बनाने के लिए, ऐप्लिकेशन के कॉन्टेक्स्ट और फ़ाइल यूआरआई को InputImage.fromFilePath()
पर पास करें. यह तब काम आता है, जब आपको उपयोगकर्ता को उसकी गैलरी ऐप्लिकेशन से कोई इमेज चुनने के लिए प्रॉम्प्ट करना हो. इसके लिए, ACTION_GET_CONTENT
इंटेंट का इस्तेमाल करें.
Kotlin
val image: InputImage try { image = InputImage.fromFilePath(context, uri) } catch (e: IOException) { e.printStackTrace() }
Java
InputImage image; try { image = InputImage.fromFilePath(context, uri); } catch (IOException e) { e.printStackTrace(); }
ByteBuffer
या ByteArray
का इस्तेमाल करना
ByteBuffer
या ByteArray
से InputImage
ऑब्जेक्ट बनाने के लिए, सबसे पहले इमेज के रोटेशन डिग्री का हिसाब लगाएं. इसके लिए, media.Image
इनपुट के लिए पहले बताई गई प्रोसेस का इस्तेमाल करें.
इसके बाद, बफ़र या ऐरे के साथ InputImage
ऑब्जेक्ट बनाएं. साथ ही, इमेज की ऊंचाई, चौड़ाई, कलर एन्कोडिंग फ़ॉर्मैट, और रोटेशन डिग्री भी सेट करें:
Kotlin
val image = InputImage.fromByteBuffer( byteBuffer, /* image width */ 480, /* image height */ 360, rotationDegrees, InputImage.IMAGE_FORMAT_NV21 // or IMAGE_FORMAT_YV12 ) // Or: val image = InputImage.fromByteArray( byteArray, /* image width */ 480, /* image height */ 360, rotationDegrees, InputImage.IMAGE_FORMAT_NV21 // or IMAGE_FORMAT_YV12 )
Java
InputImage image = InputImage.fromByteBuffer(byteBuffer, /* image width */ 480, /* image height */ 360, rotationDegrees, InputImage.IMAGE_FORMAT_NV21 // or IMAGE_FORMAT_YV12 ); // Or: InputImage image = InputImage.fromByteArray( byteArray, /* image width */480, /* image height */360, rotation, InputImage.IMAGE_FORMAT_NV21 // or IMAGE_FORMAT_YV12 );
Bitmap
का इस्तेमाल करना
Bitmap
ऑब्जेक्ट से InputImage
ऑब्जेक्ट बनाने के लिए, यह एलान करें:
Kotlin
val image = InputImage.fromBitmap(bitmap, 0)
Java
InputImage image = InputImage.fromBitmap(bitmap, rotationDegree);
इमेज को Bitmap
ऑब्जेक्ट के तौर पर दिखाया गया है. साथ ही, इसे घुमाने की डिग्री भी दिखाई गई है.
3. BarcodeScanner का इंस्टेंस पाना
Kotlin
val scanner = BarcodeScanning.getClient() // Or, to specify the formats to recognize: // val scanner = BarcodeScanning.getClient(options)
Java
BarcodeScanner scanner = BarcodeScanning.getClient(); // Or, to specify the formats to recognize: // BarcodeScanner scanner = BarcodeScanning.getClient(options);
4. इमेज को प्रोसेस करना
इमेज कोprocess
तरीके से पास करें:
Kotlin
val result = scanner.process(image) .addOnSuccessListener { barcodes -> // Task completed successfully // ... } .addOnFailureListener { // Task failed with an exception // ... }
Java
Task<List<Barcode>> result = scanner.process(image) .addOnSuccessListener(new OnSuccessListener<List<Barcode>>() { @Override public void onSuccess(List<Barcode> barcodes) { // Task completed successfully // ... } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { // Task failed with an exception // ... } });
5. बारकोड से जानकारी पाना
अगर बारकोड पहचानने की प्रोसेस पूरी हो जाती है, तोBarcode
ऑब्जेक्ट की सूची, सक्सेस लिसनर को पास की जाती है. हर Barcode
ऑब्जेक्ट, इमेज में पहचाने गए बारकोड को दिखाता है. हर बारकोड के लिए, आपको इनपुट इमेज में उसके बाउंडिंग कोऑर्डिनेट मिल सकते हैं. साथ ही, बारकोड से कोड किया गया रॉ डेटा भी मिल सकता है. अगर बारकोड स्कैनर, बारकोड में कोड किए गए डेटा का टाइप पता लगा लेता है, तो आपको पार्स किए गए डेटा वाला ऑब्जेक्ट मिल सकता है.
उदाहरण के लिए:
Kotlin
for (barcode in barcodes) { val bounds = barcode.boundingBox val corners = barcode.cornerPoints val rawValue = barcode.rawValue val valueType = barcode.valueType // See API reference for complete list of supported types when (valueType) { Barcode.TYPE_WIFI -> { val ssid = barcode.wifi!!.ssid val password = barcode.wifi!!.password val type = barcode.wifi!!.encryptionType } Barcode.TYPE_URL -> { val title = barcode.url!!.title val url = barcode.url!!.url } } }
Java
for (Barcode barcode: barcodes) { Rect bounds = barcode.getBoundingBox(); Point[] corners = barcode.getCornerPoints(); String rawValue = barcode.getRawValue(); int valueType = barcode.getValueType(); // See API reference for complete list of supported types switch (valueType) { case Barcode.TYPE_WIFI: String ssid = barcode.getWifi().getSsid(); String password = barcode.getWifi().getPassword(); int type = barcode.getWifi().getEncryptionType(); break; case Barcode.TYPE_URL: String title = barcode.getUrl().getTitle(); String url = barcode.getUrl().getUrl(); break; } }
रीयल-टाइम परफ़ॉर्मेंस को बेहतर बनाने के लिए सलाह
अगर आपको रीयल-टाइम ऐप्लिकेशन में बारकोड स्कैन करने हैं, तो सबसे अच्छे फ़्रेमरेट पाने के लिए, इन दिशा-निर्देशों का पालन करें:
-
कैमरे के नेटिव रिज़ॉल्यूशन पर इनपुट कैप्चर न करें. कुछ डिवाइसों पर, नेटिव रिज़ॉल्यूशन पर इनपुट कैप्चर करने से बहुत बड़ी (10 से ज़्यादा मेगापिक्सल) इमेज बनती हैं. इससे बहुत कम समय में इमेज प्रोसेस होती है, लेकिन इससे सटीक नतीजे नहीं मिलते. इसके बजाय, कैमरे से सिर्फ़ उतना साइज़ मांगें जितना बारकोड का पता लगाने के लिए ज़रूरी है. यह आम तौर पर दो मेगापिक्सल से ज़्यादा नहीं होता.
अगर स्कैन करने की स्पीड आपके लिए ज़रूरी है, तो इमेज कैप्चर करने के रिज़ॉल्यूशन को और कम किया जा सकता है. हालांकि, ऊपर बताई गई बारकोड के कम से कम साइज़ की ज़रूरी शर्तों का ध्यान रखें.
अगर आपको स्ट्रीमिंग वीडियो के फ़्रेम के क्रम से बारकोड की पहचान करनी है, तो हो सकता है कि पहचान करने वाला टूल, फ़्रेम के हिसाब से अलग-अलग नतीजे दे. आपको तब तक इंतज़ार करना चाहिए, जब तक आपको एक ही वैल्यू की लगातार सीरीज़ न मिल जाए. इससे आपको यह पक्का करने में मदद मिलेगी कि आपको अच्छा नतीजा मिल रहा है.
ITF और CODE-39 के लिए, चेकसम डिजिट का इस्तेमाल नहीं किया जा सकता.
- अगर
Camera
याcamera2
एपीआई का इस्तेमाल किया जाता है, तो डिटेक्टर को किए जाने वाले कॉल को थ्रॉटल करें. अगर डिटेक्टर के चालू होने के दौरान कोई नया वीडियो फ़्रेम उपलब्ध होता है, तो फ़्रेम को छोड़ दें. उदाहरण के लिए, क्विकस्टार्ट सैंपल ऐप्लिकेशन मेंVisionProcessorBase
क्लास देखें. - अगर
CameraX
API का इस्तेमाल किया जाता है, तो पक्का करें कि बैकप्रेशर की रणनीति को डिफ़ॉल्ट वैल्यूImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
पर सेट किया गया हो. इससे यह पक्का होता है कि एक बार में सिर्फ़ एक इमेज का विश्लेषण किया जाएगा. अगर विश्लेषण करने वाले टूल के व्यस्त होने पर ज़्यादा इमेज जनरेट होती हैं, तो उन्हें अपने-आप हटा दिया जाएगा. साथ ही, उन्हें डिलीवरी के लिए लाइन में नहीं लगाया जाएगा. विश्लेषण की जा रही इमेज को ImageProxy.close() फ़ंक्शन कॉल करके बंद करने के बाद, अगली नई इमेज डिलीवर की जाएगी. - अगर आपको इनपुट इमेज पर ग्राफ़िक ओवरले करने के लिए, डिटेक्टर के आउटपुट का इस्तेमाल करना है, तो पहले ML Kit से नतीजे पाएं. इसके बाद, इमेज को रेंडर करें और एक ही चरण में ओवरले करें. यह हर इनपुट फ़्रेम के लिए, डिसप्ले सर्फ़ेस पर सिर्फ़ एक बार रेंडर होता है. उदाहरण के लिए, क्विकस्टार्ट सैंपल ऐप्लिकेशन में
CameraSourcePreview
औरGraphicOverlay
क्लास देखें. - Camera2 API का इस्तेमाल करने पर, इमेज को
ImageFormat.YUV_420_888
फ़ॉर्मैट में कैप्चर करें. अगर Camera API के पुराने वर्शन का इस्तेमाल किया जा रहा है, तो इमेज कोImageFormat.NV21
फ़ॉर्मैट में कैप्चर करें.
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-09-04 (UTC) को अपडेट किया गया.