Convert Figma logo to code with AI

googlesamples logoandroid-vision

Deprecated: The Mobile Vision API is now a part of ML Kit: Check out this repo:

2,926
1,731
2,926
322

Top Related Projects

TensorFlow examples

Migrated:

Firebase Quickstart Samples for Android

ARCore SDK for Android Studio

Repository for OpenCV's extra modules

Quick Overview

The googlesamples/android-vision repository is a collection of sample Android applications demonstrating the use of Google's Mobile Vision APIs. These samples showcase various computer vision capabilities, including face detection, barcode scanning, and text recognition, implemented in Android applications.

Pros

  • Provides practical, ready-to-use examples of Mobile Vision API implementation
  • Covers multiple vision-related tasks (face detection, barcode scanning, text recognition)
  • Well-documented code with comments explaining key concepts
  • Regularly updated to reflect the latest API changes and best practices

Cons

  • Some samples may not be fully optimized for performance in production environments
  • Limited to Google's Mobile Vision APIs, not covering other computer vision libraries
  • Requires Google Play Services to function, which may not be available on all devices
  • Some examples may be outdated as the Mobile Vision API has been largely superseded by ML Kit

Code Examples

  1. Face Detection:
val detector = FaceDetector.Builder(context)
    .setTrackingEnabled(true)
    .setLandmarkType(FaceDetector.ALL_LANDMARKS)
    .setMode(FaceDetector.FAST_MODE)
    .build()

val frame = Frame.Builder().setBitmap(bitmap).build()
val faces = detector.detect(frame)

This code sets up a face detector and processes a bitmap image to detect faces.

  1. Barcode Scanning:
val barcodeDetector = BarcodeDetector.Builder(context)
    .setBarcodeFormats(Barcode.QR_CODE)
    .build()

val frame = Frame.Builder().setBitmap(bitmap).build()
val barcodes = barcodeDetector.detect(frame)

This example creates a barcode detector specifically for QR codes and scans a bitmap image.

  1. Text Recognition:
val textRecognizer = TextRecognizer.Builder(context).build()

val frame = Frame.Builder().setBitmap(bitmap).build()
val textBlocks = textRecognizer.detect(frame)

This code snippet sets up a text recognizer and processes a bitmap image to detect text blocks.

Getting Started

  1. Clone the repository:

    git clone https://github.com/googlesamples/android-vision.git
    
  2. Open the project in Android Studio.

  3. Select the specific sample you want to run (e.g., face detection, barcode scanning).

  4. Build and run the selected sample on an Android device or emulator.

  5. Ensure that Google Play Services is installed and up-to-date on the target device.

Note: Some samples may require additional setup or API keys. Refer to the specific sample's README for detailed instructions.

Competitor Comparisons

TensorFlow examples

Pros of tensorflow/examples

  • Broader scope, covering various machine learning tasks beyond just vision
  • More actively maintained with frequent updates and contributions
  • Includes examples for multiple platforms and frameworks (not just Android)

Cons of tensorflow/examples

  • May be more complex for beginners due to its extensive coverage
  • Less focused on Android-specific implementations
  • Requires more setup and dependencies for running examples

Code Comparison

android-vision (Face Detection):

FaceDetector detector = new FaceDetector.Builder(getApplicationContext())
    .setTrackingEnabled(false)
    .setLandmarkType(FaceDetector.ALL_LANDMARKS)
    .setMode(FaceDetector.FAST_MODE)
    .build();

tensorflow/examples (Object Detection):

detector = hub.load("https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2")
boxes, scores, classes, num_detections = detector(image)

Both repositories provide valuable resources for developers working with computer vision and machine learning. android-vision focuses specifically on Android implementations of vision-related tasks, while tensorflow/examples offers a broader range of machine learning examples across various platforms. The choice between the two depends on the specific needs of the project and the developer's familiarity with TensorFlow and Android development.

Migrated:

Pros of android-Camera2Basic

  • Focuses specifically on the Camera2 API, providing a more in-depth exploration of modern Android camera features
  • Simpler and more straightforward codebase, making it easier for beginners to understand camera implementation
  • Includes a comprehensive README with detailed explanations of Camera2 API concepts

Cons of android-Camera2Basic

  • Limited in scope compared to android-vision, which covers a broader range of vision-related features
  • Lacks advanced image processing and computer vision capabilities
  • May not be as actively maintained or updated as android-vision

Code Comparison

android-Camera2Basic:

private void createCameraPreviewSession() {
    try {
        SurfaceTexture texture = mTextureView.getSurfaceTexture();
        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
        Surface surface = new Surface(texture);

android-vision:

private void createCameraSource() {
    Context context = getApplicationContext();
    FaceDetector detector = new FaceDetector.Builder(context)
            .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
            .build();

The code snippets highlight the different focus areas of each repository. android-Camera2Basic emphasizes camera setup and preview, while android-vision demonstrates integration with advanced vision features like face detection.

Firebase Quickstart Samples for Android

Pros of quickstart-android

  • Covers a broader range of Firebase services, including authentication, database, and cloud functions
  • More frequently updated, with recent commits and active maintenance
  • Provides comprehensive examples for integrating Firebase into Android apps

Cons of quickstart-android

  • Focused solely on Firebase, limiting its scope compared to android-vision's broader ML capabilities
  • May have a steeper learning curve for developers new to Firebase ecosystem
  • Requires Firebase account and setup, which might not be suitable for all projects

Code Comparison

android-vision:

TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
Frame imageFrame = new Frame.Builder()
        .setBitmap(imageBitmap)
        .build();
SparseArray<TextBlock> textBlocks = textRecognizer.detect(imageFrame);

quickstart-android:

FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance()
        .getOnDeviceTextRecognizer();
Task<FirebaseVisionText> result = detector.processImage(image)
        .addOnSuccessListener(firebaseVisionText -> {
            // Task completed successfully
        });

Both repositories offer valuable resources for Android developers. android-vision provides a wider range of computer vision and machine learning capabilities, while quickstart-android focuses on Firebase integration, offering a more comprehensive suite of cloud-based services. The choice between them depends on the specific needs of your project and whether you want to leverage Firebase's ecosystem or stick with more general Android vision capabilities.

ARCore SDK for Android Studio

Pros of arcore-android-sdk

  • Focuses specifically on Augmented Reality (AR) development
  • Provides more advanced 3D tracking and environmental understanding
  • Offers a comprehensive SDK for building AR experiences

Cons of arcore-android-sdk

  • Limited to AR applications, less versatile than android-vision
  • Requires more powerful hardware to run effectively
  • Steeper learning curve for developers new to AR

Code Comparison

android-vision example (face detection):

FaceDetector detector = new FaceDetector.Builder(getApplicationContext())
    .setTrackingEnabled(false)
    .setLandmarkType(FaceDetector.ALL_LANDMARKS)
    .setMode(FaceDetector.FAST_MODE)
    .build();

arcore-android-sdk example (placing an object in AR):

Anchor anchor = hitResult.createAnchor();
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arSceneView.getScene());
TransformableNode andy = new TransformableNode(arSceneView.getTransformationSystem());
andy.setParent(anchorNode);
andy.setRenderable(andyRenderable);
andy.select();

Both repositories offer valuable tools for Android developers, but they serve different purposes. android-vision provides a broader range of computer vision capabilities, while arcore-android-sdk specializes in AR development with more advanced features for 3D tracking and environmental understanding.

Repository for OpenCV's extra modules

Pros of opencv_contrib

  • Broader scope: Covers a wide range of computer vision tasks beyond just Android
  • More active development: Frequent updates and contributions from a large community
  • Extensive documentation and examples for various platforms

Cons of opencv_contrib

  • Steeper learning curve: Requires more in-depth knowledge of computer vision concepts
  • Higher resource requirements: May be overkill for simple Android-specific vision tasks

Code Comparison

android-vision:

Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<Face> faces = faceDetector.detect(frame);

opencv_contrib:

cv::Mat image = cv::imread("image.jpg");
std::vector<cv::Rect> faces;
face_cascade.detectMultiScale(image, faces);

Summary

opencv_contrib offers a more comprehensive computer vision toolkit suitable for various platforms, while android-vision focuses specifically on Android development. opencv_contrib provides more flexibility and features but requires more expertise, whereas android-vision is more accessible for Android-specific tasks. The code examples demonstrate the difference in complexity and language used (Java for android-vision, C++ for opencv_contrib).

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Android Vision API Samples

The Mobile Vision API is now a part of ML Kit. We strongly encourage you to try it out, as it comes with new capabilities like on-device image labeling! Also, note that we ultimately plan to wind down the Mobile Vision API, with all new on-device ML capabilities released via ML Kit. Check out this codelab to use the vision APIs in ML Kit.

This sample has been deprecated/archived meaning it's read-only and it's no longer actively maintained (more details on archiving can be found here).

For other related samples, check out the new github.com/android/user-interface-samples repo. Thank you!