Sample app to demonstrate OpenCV Face detection with video from device in Compose.
OpenCvFaceDetection.webm
On my test device Samsung M21:
- Extracting frame avg. 20ms
- Face Detecting:
- 1920*1080: 400ms
- 640*360: 75ms
- Converting the frame to bitmap avg. 8ms
-
Download the "Android" package from OpenCV
-
Extract the the zip file and copy "sdk" folder into root directory of your project
-
File -> New -> Import module -> Select the "sdk" module & name it ":openCV"
You may get errors here, just follow the steps here
-
Update "settings.gradle" file
settings.gradle
pluginManagement { repositories { google { content { includeGroupByRegex("com\\.android.*") includeGroupByRegex("com\\.google.*") includeGroupByRegex("androidx.*") } } mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } rootProject.name = "OpenCVFaceDetection" <---- YOUR PROJECT NAME include(":app") include(":openCV") project(":openCV").projectDir = File(rootDir, "sdk/")
-
Update "build.gradle (Module :openCV)" file
build.gradle (Module :openCV)
... minSdkVersion 24 (same as your main module) targetSdkVersion 34 (same as your main module) add: kotlinOptions { jvmTarget = "1.8" (same as your main module) } ...
-
Import openCV in your main module
build.gradle (Module :app)
... implementation (fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) implementation (project(":openCV"))
-
Download the latest version of onnx file for face detection and place it in res/raw
Current latest face_detection_yunet_2023mar.onnx
Note: don't pick the file with "_int8.onnx" ending
You need custom made app/feature?
If you like my work please support me, Thank you.
MIT License
Copyright (c) 2023 DarkWhite220
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.