SmartJavaAI Documentation

repository·master·Indexed 21 days ago

https://github.com/geekwenjie/smartjavaai

A lightweight, offline Java toolbox that simplifies the integration of AI models into Java and Android applications. It abstracts complex frameworks like PyTorch, TensorFlow, ONNX, and Paddle into a simple API. Supported capabilities include face recognition (detection, liveness, attributes, and expressions), OCR (text, table, and license plate recognition), computer vision (object detection and segmentation), machine translation, and speech processing (ASR and TTS).

Tokens
5.8K
Snippets
7
Records
31
Agent score
75%

What's inside SmartJavaAI

  1. Overview of SmartJavaAI

    master

    SmartJavaAI is a lightweight, free, and offline AI toolbox designed specifically for Java developers. It aims to provide a zero-threshold experience for integrating AI algorithms into Java projects, following the philosophy of being 'as easy to use as Hutool'.

    Key features include:

    • Zero-threshold integration: Call complex functions like face recognition, object detection, and OCR without needing to understand underlying AI implementations.
    • Multi-framework support: Leverages DJL (Deep Java Library) and JNI-based C++/Python algorithms to support PyTorch, TensorFlow, ONNX, and Paddle.
    • Offline capabilities: Designed for offline use, making it suitable for privacy-sensitive or disconnected environments.
    • Android Support: Offers a commercial Android SDK for mobile-specific offline face recognition needs.
  2. Supported AI Capabilities in SmartJavaAI

    master

    SmartJavaAI provides a comprehensive suite of AI capabilities across vision, text, and speech. Key features include:

    Vision

    • Face Recognition: Detection, 5-point landmark localization, 512-dimension feature extraction, 1:1 and 1:N matching, face attribute detection (gender, age, mask, etc.), silent liveness detection, expression recognition, and quality assessment. Supports vector databases like milvus or sqlite for face libraries.
    • Object Detection & Classification: Integrated models including YOLOv5, YOLOv8, YOLOv11, YOLOv12, and TensorFlow Object Detection. Supports custom model loading.
    • Segmentation: Semantic segmentation (DeepLabV3) and Instance segmentation (YOLOv8-seg, YOLOv11-seg, Mask R-CNN).
    • Specialized Vision: OBB (Oriented Bounding Box) detection via YOLOv11-obb, Pose Estimation (YOLOv8-pose, YOLOv11-pose), Zero-shot detection (YOLOv8s_worldv2, owlv2_base_patch16), and CLIP (image/text feature extraction for cross-modal search).
    • OCR (Optical Character Recognition): Powered by PaddleOCR 3.0 (PP-OCRv5, PP-OCRv4). Supports table recognition (SLANet_plus), arbitrary angle recognition, Chinese license plate recognition, and ID card field extraction.

    Text & Speech

    • Machine Translation: Integrated NLLB-200 model supporting 200+ languages.
    • Speech Recognition (ASR): OpenAI Whisper (100 languages), Vosk, and Sherpa-ONNX.
    • Speech Synthesis (TTS): Sherpa-ONNX supporting Chinese, dialects, Cantonese, English, German, etc.
    • Action Recognition: Supports 400 human actions from the KINETICS400 dataset.
  3. Core capabilities of SmartJavaAI Android SDK

    master

    The SmartJavaAI Android version is a high-performance, fully offline facial recognition solution designed for mobile devices. It does not require an internet connection to function. The SDK consists of four core modules:

    1. Face Detection: Locating faces within an image or video stream.
    2. Face Registration: Enrolling new faces into the system.
    3. Face Comparison (1:1): Verifying if two faces belong to the same person.
    4. Face Search (1:N): Searching for a specific face within a database of multiple faces.
  4. Explore SmartJavaAI capabilities

    master

    SmartJavaAI provides a comprehensive suite of AI algorithms designed for Java developers. The supported capabilities include:

    Face & Biometrics

    • Face Detection: 5-point facial landmark localization.
    • Face Recognition: 1:1 face comparison (with alignment) and 1:N face recognition (including registration, database querying, and deletion).
    • Face ID Verification: Verifying identity via face and ID card matching.
    • Face Attribute Detection: Gender, Age, Mask detection, Eye closeness, and Face pose estimation.
    • Face Liveness Detection: Supports both image and video liveness checks.
    • Facial Expression Recognition: Detection of 7 different facial expressions.

    Computer Vision

    • Image Classification: General image categorization.
    • Object Detection: Supports video streams (RTSP, camera, video files) and custom model training.
    • Segmentation: Semantic Segmentation and Instance Segmentation.
    • Specialized Detection: Person detection, Action recognition, Oriented Bounding Boxes (OBB) detection, and Zero-Shot Object Detection (via YOLO-World).
    • Pose Estimation: Human pose tracking.
    • CLIP: Multimodal capabilities including text-to-image, image-to-image, and image-to-text search.

    OCR & Document Intelligence

    • Text Recognition: Supports arbitrary angles, printed text, and handwriting.
    • Table Structure Recognition: Extracting data from tables.
    • License Plate Recognition: Single/double layer detection and color recognition.
    • IDCard Recognition: Front and back side recognition with structured JSON output.

    NLP & Audio

    • Machine Translation: Translation between 200+ languages.
    • Speech Recognition (ASR): Supports 100+ languages and real-time recognition.
    • Speech Synthesis (TTS): Text-to-speech capabilities.
  5. Project Structure of the Translation Example

    master

    The translation example is organized as follows:

    └── main
        ├── java
        │   └── smartai
        │       └── examples
        │           └── nlp
        │               └── translation 机器翻译
        │                   └── TranslationDemo.java 
        └── resources
            └── logback.xml

    Core logic resides in TranslationDemo.java, and logging configuration is handled by logback.xml in the resources folder.

    └── main
        ├── java
        │   └── smartai
        │       └── examples
        │           └── nlp
        │               └── translation 机器翻译
        │                   └── TranslationDemo.java 
        └── resources
            └── logback.xml
  6. Explore Speech ASR and TTS example implementations

    master

    The speech-examples project contains several implementations for speech processing:

    • ASR (Automatic Speech Recognition):
      • SherpaAsrDemo.java: Demonstrates speech recognition using the sherpa-onnx engine.
      • SpeechRecognizeDemo.java: Demonstrates speech recognition using other available models.
    • TTS (Text-to-Speech):
      • TtsDemo.java: Demonstrates speech synthesis (converting text to speech).

    Detailed usage instructions and functional descriptions can be found in the comments at the top of each Java file.

  7. Explore SmartJavaAI functional examples

    master

    The examples directory contains several standalone Maven projects demonstrating specific capabilities of the SmartJavaAI library. You can use these as templates for your own implementation:

    • face-example: Demonstrates face detection and face recognition.
    • vision-example: Demonstrates general computer vision tasks including object detection, object segmentation, and image classification.
    • ocr-example: Demonstrates Optical Character Recognition (OCR), text recognition, and license plate recognition.
    • translate-example: Demonstrates machine translation capabilities.
    • speech-example: Demonstrates speech recognition (STT) and speech synthesis (TTS).
  8. Available Example Modules

    master

    The examples directory provides the following functional modules:

    • face-example: Face detection, face recognition, etc.
    • vision-example: General vision tasks like object detection, segmentation, and image classification.
    • ocr-example: OCR text recognition, license plate recognition, etc.
    • translate-example: Machine translation.
    • speech-example: Speech recognition (ASR) and speech synthesis (TTS).
  9. Explore Face Recognition capabilities in SmartJavaAI

    master

    The face-example project provides Java implementation examples for various facial analysis scenarios using the SmartJavaAI SDK. Key capabilities include:

    • Face Detection (facedet): Detects faces in images or video streams and provides bounding boxes.
    • Face Recognition (facerec): Supports 1:1 verification and 1:N searching by extracting facial features and managing a face library.
    • Liveness Detection (liveness): Determines if a face is a real person using static images or camera video streams.
    • Face Attribute Detection (attribute): Detects attributes such as gender and age.
    • Expression Recognition (expression): Recognizes 7 types of expressions (e.g., neutral, happy, sad).
    • Face Quality Assessment (quality): Evaluates image quality based on brightness, clarity, completeness, pose, and resolution.
  10. Modular Components of SmartJavaAI

    master

    SmartJavaAI is organized into modular components. You can include specific modules based on your requirements or import the all module to include everything.

    Available Modules:

    • common: Basic utility module used by all algorithm modules.
    • bom: Dependency management module.
    • face: Face recognition and processing features.
    • vision: General vision features (e.g., object detection).
    • ocr: Optical Character Recognition features.
    • translate: Machine translation features.
    • speech: Speech features (includes ASR and TTS).

    Usage Pattern: To minimize dependency footprint, import only the specific modules you need. To get the full suite, use the all module.

  11. Compare AI Integration Approaches

    master

    When choosing an AI integration strategy for Java, SmartJavaAI positions itself as a high-level, easy-to-use alternative to other common methods:

    SchemeTechnical CharacteristicsProsCons
    OpenCVTraditional image processingJava interfaces, lightweight, rich communityLow accuracy (60-75%), requires local environment
    Commercial SDKsClosed-source solutionsOut-of-the-box, complete docs, offline livenessHigh cost, annual updates required, code is opaque
    Cloud APIsSaaS-basedZero deployment, high concurrency, auto-updatesNetwork latency (200-800ms), usage fees, data security risks
    Python HybridCross-language callsIntegrates PyTorch/TF, high accuracyDual-language maintenance, IPC performance loss (30%+), complex error handling
    JNI/JNALow-level cross-languageHigh performance (C/C++), can be wrapped in JARHigh development cost, complex JNI, poor cross-platform compatibility
    DJL FrameworkDeep Learning frameworkPure Java, supports 99%+ pretrained modelsRequires DL knowledge, complex model loading/preprocessing/postprocessing
    SmartJavaAIJava DL ToolkitSupports mainstream DL frameworks, rich out-of-the-box APIs, easy to use, single JAR integrationNone listed
  12. Understand the SmartJavaAI value proposition

    master

    SmartJavaAI is designed to bridge the gap between the Python-centric AI ecosystem (PyTorch/TensorFlow) and Java engineering environments. It addresses two main pain points:

    1. Ecosystem Fragmentation: Resolves the disconnect between mainstream deep learning frameworks (Python-based) and Java business logic.
    2. Integration Complexity: Replaces scattered, inconsistently encapsulated AI solutions with a unified, low-barrier interface.

    Key Features:

    • Out-of-the-box: Call complex algorithms with as little as two lines of code.
    • Multi-Engine Support: Compatible with PyTorch, TensorFlow, MXNet, and ONNX Runtime.
    • Cross-Platform: Supports Windows, Linux, and macOS on both x86 and ARM architectures.