Earn 9,000 ($90.00)
Adapt a C++ implementation for Android
Bounty Description
Face Alignment Implementation for Android Integration
We have a C++ implementation that crops and aligns a face from an image based on 5 facial landmarks.
Current Implementation
The code takes the following inputs:
Target image filepath
Five facial landmarks (coordinates of eyes, nose, mouth corners)
Output crop size (default 112×112 pixels)
Filepath to write the cropped image to
Sample Input: ./face_alignment input.jpg output.jpg 112 76.77 150.33 141.15 130.50 111.25 180.37 108.10 217.14 159.93 199.44
This processes input.jpg using the 5 landmarks (each with x,y coordinates) and outputs a 112×112 aligned face to output.jpg.
Dependencies
The only external dependency it uses is OpenCV.
Requirements
Adapt this C++ implementation for Android:
Create JNI bindings to call the code from Kotlin
Set up CMake configuration for proper compilation with Android NDK
Include the necessary OpenCV Android SDK components
The android app already has an OpenCV dependency…explore if this can be reused
Implement using Direct ByteBuffer approach for maximum performance
Modify the implementation to:
Accept image data via Direct ByteBuffer rather than filesystem paths
Include image dimensions (width and height) as parameters
Return processed image data as Direct ByteBuffer for zero-copy transfer
Handle errors gracefully with appropriate status codes/exceptions
Ensure proper memory management to avoid leaks or excessive GC pressure
Performance considerations:
Use ByteBuffer.allocateDirect() for zero-copy access between Java and C++
Avoid any file I/O operations during image processing
Minimize memory copies between Java and native code
Utilize env->GetDirectBufferAddress() for direct memory access in C++
Configure buffer byte order correctly with ByteOrder.nativeOrder()
Deliverables:
Android library (.aar) with the native implementation
Sample Android application demonstrating usage
Integration documentation with usage examples
Performance benchmarks comparing with file-based approach
The final implementation should:
Be thread-safe
Run on a background thread to avoid UI freezing
Support Android API level 21 and above
Follow Android-specific best practices for native code
Properly release native resources to prevent memory leaks
Handle concurrent processing requests safely
Include comprehensive error handling with specific error codes