बारकोड को पहचानने और उसे डिकोड करने के लिए, ML Kit का इस्तेमाल किया जा सकता है.
सुविधा | अनबंडल किए गए | बंडल किए गए |
---|---|---|
कार्यान्वयन | मॉडल को Google Play services की मदद से, डाइनैमिक रूप से डाउनलोड किया जाता है. | बिल्ड के दौरान, मॉडल आपके ऐप्लिकेशन से स्टैटिक रूप से लिंक होता है. |
ऐप्लिकेशन का साइज़ | साइज़ करीब 200 केबी बढ़ जाता है. | करीब 2.4 एमबी साइज़ बढ़ जाता है. |
प्रोसेस शुरू होने का समय | पहली बार इस्तेमाल करने से पहले, मॉडल के डाउनलोड होने तक इंतज़ार करना पड़ सकता है. | मॉडल तुरंत उपलब्ध हो जाता है. |
इसे आज़माएं
- एपीआई के इस्तेमाल का उदाहरण देखने के लिए, सैंपल ऐप्लिकेशन इस्तेमाल करें.
- इस एपीआई को पूरी तरह लागू करने के लिए, मटीरियल डिज़ाइन शोकेस ऐप्लिकेशन देखें.
वेब कंटेनर इंस्टॉल करने से पहले
प्रोजेक्ट-लेवल की
build.gradle
फ़ाइल में, पक्का करें कि आपनेbuildscript
औरallprojects
, दोनों सेक्शन में Google की Maven रिपॉज़िटरी को शामिल किया हो.अपने मॉड्यूल की ऐप्लिकेशन-लेवल की 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.2.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.0' }
अगर आपने 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 पिक्सल लंबी होनी चाहिए.
उदाहरण के लिए, EAN-13 बारकोड बार और स्पेस से बने होते हैं जिनकी चौड़ाई 1, 2, 3 या 4 यूनिट होती है. इसलिए, EAN-13 बारकोड इमेज में बार और स्पेस होते हैं और इनकी चौड़ाई कम से कम 2, 4, 6, और 8 पिक्सल होती है. EAN-13 बारकोड कुल 95 यूनिट चौड़ा होता है. इसलिए, बारकोड कम से कम 190 पिक्सल चौड़ा होना चाहिए.
PDF417 जैसे डेंसर फ़ॉर्मैट में, एमएल किट को सही तरीके से पढ़ने के लिए ज़्यादा पिक्सल डाइमेंशन की ज़रूरत होती है. उदाहरण के लिए, PDF417 कोड में एक लाइन में 17 यूनिट चौड़े "शब्द" हो सकते हैं. आम तौर पर, इनकी चौड़ाई कम से कम 1156 पिक्सल होनी चाहिए.
-
इमेज का खराब फ़ोकस, स्कैन करने की सटीक जानकारी पर असर डाल सकता है. अगर आपके ऐप्लिकेशन को स्वीकार किए जाने वाले नतीजे नहीं मिलते हैं, तो उपयोगकर्ता को इमेज दोबारा कैप्चर करने के लिए कहें.
-
आम तौर पर इस्तेमाल किए जाने वाले ऐप्लिकेशन के लिए, ज़्यादा रिज़ॉल्यूशन वाली इमेज उपलब्ध कराएं. जैसे, 1280x720 या 1920x1080. इससे बारकोड को कैमरे से ज़्यादा दूरी से स्कैन किया जा सकता है.
हालांकि, जिन ऐप्लिकेशन में इंतज़ार का समय बहुत ज़्यादा ज़रूरी होता है उनमें कम रिज़ॉल्यूशन वाली इमेज कैप्चर करके, परफ़ॉर्मेंस को बेहतर बनाया जा सकता है. हालांकि, यह ज़रूरी है कि इनपुट इमेज के ज़्यादातर हिस्से में बारकोड डाला गया हो. रीयल-टाइम में परफ़ॉर्मेंस को बेहतर बनाने के लिए सलाह भी देखें.
1. बारकोड स्कैनर को कॉन्फ़िगर करें
अगर आपको पता है कि आपको किस बारकोड फ़ॉर्मैट में पढ़ने की उम्मीद है, तो बारकोड डिटेक्टर को उसकी स्पीड बढ़ाने के लिए, उसे सिर्फ़ उन फ़ॉर्मैट का पता लगाने के लिए कॉन्फ़िगर करें.उदाहरण के लिए, सिर्फ़ Aztec कोड और क्यूआर कोड का पता लगाने के लिए, 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();
ये फ़ॉर्मैट इस्तेमाल किए जा सकते हैं:
- कोड 128 (
FORMAT_CODE_128
) - कोड 39 (
FORMAT_CODE_39
) - कोड 93 (
FORMAT_CODE_93
) - कोडाबार (
FORMAT_CODABAR
) - EAN-13 (
FORMAT_EAN_13
) - EAN-8 (
FORMAT_EAN_8
) - आईटीएफ़ (
FORMAT_ITF
) - यूपीसी-ए (
FORMAT_UPC_A
) - यूपीसी-ई (
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
एपीआई का इस्तेमाल करने पर, पक्का करें कि बैक प्रेशर स्ट्रेटजी अपनी डिफ़ॉल्ट वैल्यूImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
पर सेट हो. इससे यह गारंटी मिलती है कि विश्लेषण के लिए एक बार में सिर्फ़ एक इमेज डिलीवर की जाएगी. अगर एनालाइज़र के व्यस्त होने पर और इमेज बनती हैं, तो वे अपने-आप हट जाएंगी और डिलीवरी के लिए तैयार नहीं की जाएंगी. जिस इमेज की जांच की जा रही है उसे ImageProxy.close() को कॉल करके बंद करने के बाद, अगली इमेज डिलीवर की जाएगी.- अगर इनपुट इमेज पर ग्राफ़िक ओवरले करने के लिए, डिटेक्टर के आउटपुट का इस्तेमाल किया जाता है, तो सबसे पहले एमएल किट से नतीजा पाएं. इसके बाद, एक ही चरण में इमेज और ओवरले को रेंडर करें. यह हर इनपुट फ़्रेम के लिए,
डिसप्ले प्लैटफ़ॉर्म पर सिर्फ़ एक बार रेंडर होता है. उदाहरण के लिए, क्विकस्टार्ट सैंपल ऐप्लिकेशन में
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 एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2024-07-12 (UTC) को अपडेट किया गया.