Skip to content

zeus-10/edgedetect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Real-Time Edge Detection Viewer

An Android application that captures camera frames, processes them using OpenCV Canny edge detection in C++, and displays the results in real-time using OpenGL ES 2.0.

Core Features

  • Camera Feed Integration

    • Real-time camera capture using CameraX API
    • YUV420_888 format handling with proper stride management
    • Efficient frame processing with background threading
  • Frame Processing via OpenCV (C++)

    • Native C++ implementation using JNI bridge
    • Canny edge detection with Gaussian blur preprocessing
    • Morphological operations for edge enhancement
    • Optimized grayscale (Y-plane) processing
  • Real-time OpenGL ES Rendering

    • Custom OpenGL ES 2.0 renderer with vertex/fragment shaders
    • Efficient texture streaming and updates
    • Smooth real-time performance (10-15 FPS minimum)

Technical Implementation

  • Modular Architecture: Clean separation between Java UI, JNI bridge, and native processing
  • Memory Management: Proper resource cleanup and efficient buffer handling
  • Error Handling: Comprehensive error checking for OpenCV, OpenGL, and camera operations
  • Thread Safety: Background processing with UI thread synchronization

πŸ“· Screenshots

WhatsApp Image 2025-06-20 at 17 17 43_e514ea4f WhatsApp Image 2025-06-20 at 17 17 43_f3875020 WhatsApp Image 2025-06-20 at 17 17 42_a5ee27f1 WhatsApp Image 2025-06-20 at 17 17 43_5002a169 WhatsApp Image 2025-06-20 at 17 17 41_eb78951b WhatsApp Image 2025-06-20 at 17 17 42_7ed5b9fd WhatsApp Image 2025-06-20 at 17 17 44_b3cbcac3

The app displays:

  • White edges on black background showing detected object boundaries
  • Real-time processing of camera feed
  • Responsive edge detection when moving camera across objects

βš™ Setup Instructions

Prerequisites

  • Android Studio 4.2 or later
  • Android NDK 25.1.8937393 or later
  • Minimum SDK: API 21 (Android 5.0)
  • Target SDK: API 34

OpenCV Dependencies Setup

  1. Download OpenCV Android SDK

    # Download from https://opencv.org/releases/
    # Extract opencv-android-sdk.zip
  2. Copy OpenCV Files

    # Copy native libraries
    cp -r OpenCV-android-sdk/sdk/native/ app/src/main/cpp/opencv/
    
    # Copy Java wrapper (if using OpenCV Java API)
    cp -r OpenCV-android-sdk/sdk/java/ app/src/main/java/opencv/
  3. Project Structure

    app/src/main/
    β”œβ”€β”€ cpp/
    β”‚   β”œβ”€β”€ opencv/           # OpenCV native libraries
    β”‚   β”‚   β”œβ”€β”€ jni/
    β”‚   β”‚   └── libs/
    β”‚   β”œβ”€β”€ CMakeLists.txt
    β”‚   β”œβ”€β”€ native-lib.cpp
    β”‚   └── opencv_processor.cpp
    β”œβ”€β”€ java/com/example/edgedetector/
    β”‚   β”œβ”€β”€ MainActivity.java
    β”‚   β”œβ”€β”€ gl/
    β”‚   β”‚   β”œβ”€β”€ GLRenderer.java
    β”‚   β”‚   └── GLTextureView.java
    β”‚   └── jni/
    β”‚       └── OpenCVProcessor.java
    └── res/layout/
        └── activity_main.xml
    

Build Configuration

  1. Configure build.gradle (Module: app)

    android {
        ndkVersion "25.1.8937393"
        externalNativeBuild {
            cmake {
                path "src/main/cpp/CMakeLists.txt"
            }
        }
    }
  2. Build Project

    # In Android Studio
    Build β†’ Clean Project
    Build β†’ Rebuild Project
  3. Run on Device

    • Deploy to physical Android device (recommended for camera testing)
    • Grant camera permissions when prompted

Architecture Overview

Data Flow Pipeline

Camera β†’ ImageAnalysis β†’ JNI Bridge β†’ OpenCV C++ β†’ JNI Bridge β†’ OpenGL β†’ Display

Component Architecture

1. Java Layer (UI & Camera)

  • MainActivity: Orchestrates camera setup and lifecycle management
  • CameraX Integration: Handles camera permissions, configuration, and frame capture
  • GLTextureView: Custom OpenGL surface view for rendering processed frames

2. JNI Bridge Layer

  • OpenCVProcessor.java: Java interface for native method calls
  • native-lib.cpp: JNI implementation bridging Java and C++
  • Memory Management: Efficient byte array handling between Java and native code

3. Native Processing Layer (C++)

  • OpenCV Integration: Computer vision processing using OpenCV C++ API
  • Canny Edge Detection: Multi-stage edge detection algorithm
    • Gaussian blur for noise reduction
    • Canny algorithm with dual thresholding
    • Morphological operations for edge enhancement
  • Format Conversion: YUV to grayscale to RGB processing

4. Rendering Layer (OpenGL ES)

  • GLRenderer: Custom OpenGL ES 2.0 renderer
  • Shader Programs: Vertex and fragment shaders for texture mapping
  • Texture Streaming: Efficient real-time texture updates

Frame Processing Flow

  1. Camera Capture

    CameraX β†’ YUV420_888 ImageProxy β†’ Y-plane extraction
    
  2. Native Processing

    byte[] yData β†’ JNI β†’ cv::Mat β†’ GaussianBlur β†’ Canny β†’ cvtColor β†’ byte[]
  3. OpenGL Rendering

    byte[] β†’ ByteBuffer β†’ glTexImage2D β†’ Fragment Shader β†’ Screen
    

πŸ“¦ Dependencies

// Camera
implementation 'androidx.camera:camera-core:1.3.0'
implementation 'androidx.camera:camera-camera2:1.3.0'
implementation 'androidx.camera:camera-lifecycle:1.3.0'
implementation 'androidx.camera:camera-view:1.3.0'

// Native
// OpenCV C++ (included as native libraries)
// OpenGL ES 2.0 (system)
// Android NDK

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published