Skip to content

Using OpenCv's Android Camera2(JavaCamera2View) with OpenCV 4.10.0

License

Notifications You must be signed in to change notification settings

onuralpszr/CvCamera-Mobile

Repository files navigation

CvCamera-Mobile

Utilizing OpenCV with Android's Camera2 API through JavaCamera2View

MIT JDK Kotlin Gradle Android-Gradle-Plugin OpenCV Spotless Conventional Commits android-studio 🚀 Android CI 🚀 Build and Release pre-commit.ci status snyk-security CodeFactor

appOverview.png appOverview2.png

This android project is barebone setting up OpenCV 4.13.0 (and other 4.x.y versions) for Android in Android Studio with Native Development Kit (NDK) support. Android NDK enables you to implement your OpenCV image processing pipeline in C++ and call that C++ code from Android Kotlin/Java code through JNI (Java Native Interface). This provides a live camera feed with the ability to dynamically switch between front and back cameras. It includes a custom cvFpsMeter for enhanced text visibility. Also features a basic setup for Android NDK and OpenCV, as well as a CV filter with a toggle button for camera switching.

How to use this repository

  1. Download and Install Android Studio

  2. Install NDK and CMake

  3. Ensure you have JDK 21 installed (required for this project)

  4. Clone this repository as an Android Studio project :

    • In Android Studio, click on File -> New -> Project from Version Control -> Git
    • Paste this repository Github URL, choose a project directory and click next.
  5. Install OpenCV Android release :

    • Download OpenCV 4.13.0 Android release or download latest available Android release on OpenCV website.

    • Unzip downloaded file and put OpenCV-android-sdk directory next your project and rename folder opencvsdk4130. If you want to place somewhere else please change path in settings.gradle

    • Optional(For linux) you can run setupOpenCV_4x.sh for automatic download and setup gradle file for opencv

  6. Sync Gradle and run the application on your Android Device!

Features

  • Version Catalog: Dependencies are centrally managed in gradle/libs.versions.toml.
  • Kotlin DSL: Build scripts migrated to .kts for better type safety and IDE support.
  • Spotless: Enforced code formatting with ktlint. Run ./gradlew spotlessApply to format code.
  • OpenCV Version Update: The OpenCV version was updated multiple times, with the latest being 4.13.0.
  • Camera Switch: Added the ability to switch between the front and back camera.
  • SetupOpenCV Script: Introduced a script for setting up OpenCV.
  • Custom cvFpsMeter: Implemented a custom cvFpsMeter for bigger text and different color choice.
  • Material3 Theme: Added configurations for the Material3 theme.
  • UI Overhaul: The user interface was significantly updated, and strings were added.
  • Timber Logging: Added Timber logging for fpsMeter and ExtendedJavaCamera2View.
  • Android NDK - OpenCV Basic Setup: Implemented a basic setup for Android NDK and OpenCV.
  • CV Filter with Toggle Button: Added a basic CV filter with a toggle button to switch between the front and back camera.
  • Face Detection: Refactored Face Detection logic into a dedicated FaceDetector class.

Keywords

Kotlin, OpenCV 4, Android, Android Studio, Native, NDK, JNI, C++, Version Catalog, Kotlin DSL, Spotless

Sponsor this project

 

Packages

No packages published

Contributors 6