├── .editorconfig ├── .gitattributes ├── .gitignore ├── .nvmrc ├── .watchmanconfig ├── .yarnrc ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── android ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── facerecognitionsdk │ │ ├── FaceRecognitionSdkPackage.kt │ │ ├── FaceRecognitionSdkViewManager.kt │ │ ├── FaceSDKModule.kt │ │ └── Utils.kt │ └── res │ └── layout │ └── camera_layout.xml ├── babel.config.js ├── example ├── .watchmanconfig ├── Gemfile ├── README.md ├── android │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── facerecognitionsdkexample │ │ │ │ └── ReactNativeFlipper.java │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── assets │ │ │ │ └── index.android.bundle │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── facerecognitionsdkexample │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ │ ├── drawable │ │ │ │ └── rn_edit_text_material.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ └── release │ │ │ └── java │ │ │ └── com │ │ │ └── facerecognitionsdkexample │ │ │ └── ReactNativeFlipper.java │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── libfacesdk │ │ ├── build.gradle │ │ └── facesdk.aar │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── ios │ ├── .xcode.env │ ├── FaceRecognitionSdkExample-Bridging-Header.h │ ├── FaceRecognitionSdkExample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── FaceRecognitionSdkExample.xcscheme │ ├── FaceRecognitionSdkExample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.mm │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ └── main.m │ ├── FaceRecognitionSdkExampleTests │ │ ├── FaceRecognitionSdkExampleTests.m │ │ └── Info.plist │ ├── File.swift │ └── Podfile ├── jest.config.js ├── metro.config.js ├── package-lock.json ├── package.json ├── react-native.config.js ├── src │ ├── AboutPage.tsx │ ├── App.tsx │ ├── FaceRecognitionPage.tsx │ ├── MainPage.tsx │ ├── Person.tsx │ ├── PersonView.tsx │ ├── ResultPage.tsx │ ├── SettingsPage.tsx │ └── assets │ │ ├── ic_arrow_left.png │ │ ├── ic_camera.png │ │ ├── ic_clear_all.png │ │ ├── ic_delete.png │ │ ├── ic_email.png │ │ ├── ic_github.png │ │ ├── ic_kby.png │ │ ├── ic_liveness.png │ │ ├── ic_restore.png │ │ ├── ic_skype.png │ │ ├── ic_sparkles.png │ │ ├── ic_telegram.png │ │ ├── ic_whatsapp.png │ │ ├── info_icon.png │ │ ├── person_add_icon.png │ │ ├── person_search_icon.png │ │ └── settings_icon.png └── yarn.lock ├── face-recognition-sdk.podspec ├── ios ├── FaceRecognitionSdk-Bridging-Header.h ├── FaceRecognitionSdk.xcodeproj │ └── project.pbxproj ├── FaceRecognitionSdkViewManager.h ├── FaceRecognitionSdkViewManager.m ├── FaceRecognitionSdkViewManager.mm ├── FaceRecognitionSdkViewManager.swift ├── FaceSDKModule.h ├── FaceSDKModule.mm ├── NativeCamera.h ├── NativeCamera.mm ├── UIImageExtension.h ├── UIImageExtension.mm └── facesdk.framework │ ├── Headers │ ├── facesdk.h │ └── facesdk_api.h │ ├── Info.plist │ ├── Modules │ └── module.modulemap │ ├── _CodeSignature │ └── CodeResources │ ├── detection.bin │ ├── detection.param │ ├── facesdk │ ├── landmark.bin │ ├── landmark.param │ ├── liveness.bin │ ├── recognize.bin │ └── recognize.param ├── lefthook.yml ├── package.json ├── scripts └── bootstrap.js ├── src ├── __tests__ │ └── index.test.tsx └── index.tsx ├── tsconfig.build.json ├── tsconfig.json ├── turbo.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | example/ios/Pods 46 | 47 | # Ruby 48 | example/vendor/ 49 | 50 | # node.js 51 | # 52 | node_modules/ 53 | npm-debug.log 54 | yarn-debug.log 55 | yarn-error.log 56 | 57 | # BUCK 58 | buck-out/ 59 | \.buckd/ 60 | android/app/libs 61 | android/keystores/debug.keystore 62 | 63 | # Expo 64 | .expo/ 65 | 66 | # Turborepo 67 | .turbo/ 68 | 69 | # generated by bob 70 | lib/ 71 | 72 | .github/ 73 | 74 | example/.bundle/ 75 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 16.18.1 2 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | # Override Yarn command so we can automatically setup the repo on running `yarn` 2 | 3 | yarn-path "scripts/bootstrap.js" 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, caste, color, religion, or sexual 11 | identity and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the overall 27 | community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or advances of 32 | any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email address, 36 | without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | [INSERT CONTACT METHOD]. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series of 87 | actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or permanent 94 | ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within the 114 | community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.1, available at 120 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 121 | 122 | Community Impact Guidelines were inspired by 123 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 124 | 125 | For answers to common questions about this code of conduct, see the FAQ at 126 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 127 | [https://www.contributor-covenant.org/translations][translations]. 128 | 129 | [homepage]: https://www.contributor-covenant.org 130 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 131 | [Mozilla CoC]: https://github.com/mozilla/diversity 132 | [FAQ]: https://www.contributor-covenant.org/faq 133 | [translations]: https://www.contributor-covenant.org/translations 134 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are always welcome, no matter how large or small! 4 | 5 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md). 6 | 7 | ## Development workflow 8 | 9 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: 10 | 11 | ```sh 12 | yarn 13 | ``` 14 | 15 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development. 16 | 17 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. 18 | 19 | To start the packager: 20 | 21 | ```sh 22 | yarn example start 23 | ``` 24 | 25 | To run the example app on Android: 26 | 27 | ```sh 28 | yarn example android 29 | ``` 30 | 31 | To run the example app on iOS: 32 | 33 | ```sh 34 | yarn example ios 35 | ``` 36 | 37 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 38 | 39 | ```sh 40 | yarn typecheck 41 | yarn lint 42 | ``` 43 | 44 | To fix formatting errors, run the following: 45 | 46 | ```sh 47 | yarn lint --fix 48 | ``` 49 | 50 | Remember to add tests for your change if possible. Run the unit tests by: 51 | 52 | ```sh 53 | yarn test 54 | ``` 55 | 56 | To edit the Objective-C or Swift files, open `example/ios/FaceRecognitionSdkExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > face-recognition-sdk`. 57 | 58 | To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `face-recognition-sdk` under `Android`. 59 | 60 | 61 | ### Commit message convention 62 | 63 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 64 | 65 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 66 | - `feat`: new features, e.g. add new method to the module. 67 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 68 | - `docs`: changes into documentation, e.g. add usage example for the module.. 69 | - `test`: adding or updating tests, e.g. add integration tests using detox. 70 | - `chore`: tooling changes, e.g. change CI config. 71 | 72 | Our pre-commit hooks verify that your commit message matches this format when committing. 73 | 74 | ### Linting and tests 75 | 76 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 77 | 78 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 79 | 80 | Our pre-commit hooks verify that the linter and tests pass when committing. 81 | 82 | ### Publishing to npm 83 | 84 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 85 | 86 | To publish new versions, run the following: 87 | 88 | ```sh 89 | yarn release 90 | ``` 91 | 92 | ### Scripts 93 | 94 | The `package.json` file contains various scripts for common tasks: 95 | 96 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 97 | - `yarn typecheck`: type-check files with TypeScript. 98 | - `yarn lint`: lint files with ESLint. 99 | - `yarn test`: run unit tests with Jest. 100 | - `yarn example start`: start the Metro server for the example app. 101 | - `yarn example android`: run the example app on Android. 102 | - `yarn example ios`: run the example app on iOS. 103 | 104 | ### Sending a pull request 105 | 106 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github). 107 | 108 | When you're sending a pull request: 109 | 110 | - Prefer small pull requests focused on one change. 111 | - Verify that linters and tests are passing. 112 | - Review the documentation to make sure it looks good. 113 | - Follow the pull request template when opening a pull request. 114 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 115 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 kby-ai 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 | 5 |

6 | 7 | ### Our facial recognition algorithm is globally top-ranked by NIST in the FRVT 1:1 leaderboards. badge 8 | [Latest NIST FRVT evaluation report 2024-12-20](https://pages.nist.gov/frvt/html/frvt11.html) 9 | 10 | ![FRVT Sheet](https://github.com/user-attachments/assets/16b4cee2-3a91-453f-94e0-9e81262393d7) 11 | 12 | #### 🆔 ID Document Liveness Detection - Linux - [Here](https://web.kby-ai.com) badge 13 | #### 🤗 Hugging Face - [Here](https://huggingface.co/kby-ai) 14 | #### 📚 Product & Resources - [Here](https://github.com/kby-ai/Product) 15 | #### 🛟 Help Center - [Here](https://docs.kby-ai.com) 16 | #### 💼 KYC Verification Demo - [Here](https://github.com/kby-ai/KYC-Verification-Demo-Android) 17 | #### 🙋‍♀️ Docker Hub - [Here](https://hub.docker.com/u/kbyai) 18 | 19 | # FaceRecognition-React-Native 20 | 21 | ## Overview 22 | 23 | This repository demonstrates both `face liveness detection` and `face recognition` technology for `React-Native` on `Android` and `iOS` platforms. 24 | 25 | > In this repository, we integrated `KBY-AI`'s `face liveness detection` and `face recognition` technology into the `React-Native` project for both `Android` and `iOS`.
26 | ### ◾FaceSDK(Mobile) Details 27 | 28 | | Basic | 🔽 Standard | Premium | 29 | |------------------|------------------|------------------| 30 | | Face Detection | Face Detection | Face Detection | 31 | | Face Liveness Detection | Face Liveness Detection | Face Liveness Detection | 32 | | Pose Estimation | Pose Estimation | Pose Estimation | 33 | | | Face Recognition | Face Recognition | 34 | | | | 68 points Face Landmark Detection | 35 | | | | Face Quality Calculation | 36 | | | | Face Occlusion Detection | 37 | | | | Eye Closure Detection | 38 | | | | Age, Gender Estimation | 39 | 40 | ### ◾FaceSDK(Mobile) Product List 41 | | No. | Repository | SDK Details | 42 | |------------------|------------------|------------------| 43 | | 1 | [Face Liveness Detection - Android](https://github.com/kby-ai/FaceLivenessDetection-Android) | Basic SDK | 44 | | 2 | [Face Liveness Detection - iOS](https://github.com/kby-ai/FaceLivenessDetection-iOS) | Basic SDK | 45 | | 3 | [Face Recognition + Face Liveness Detection - Android](https://github.com/kby-ai/FaceRecognition-Android) | Standard SDK | 46 | | 4 | [Face Recognition + Face Liveness Detection - iOS](https://github.com/kby-ai/FaceRecognition-iOS) | Standard SDK | 47 | | 5 | [Face Recognition + Face Liveness Detection - Flutter](https://github.com/kby-ai/FaceRecognition-Flutter) | Standard SDK | 48 | | 6 | [Face Recognition + Face Liveness Detection - Ionic-Cordova](https://github.com/kby-ai/FaceRecognition-Ionic-Cordova) | Standard SDK | 49 | | ➡️ | [Face Recognition + Face Liveness Detection - React-Native](https://github.com/kby-ai/FaceRecognition-React-Native) | Standard SDK | 50 | | 8 | [Face Attribute - Android](https://github.com/kby-ai/FaceAttribute-Android) | Premium SDK | 51 | | 9 | [Face Attribute - iOS](https://github.com/kby-ai/FaceAttribute-iOS) | Premium SDK | 52 | | 10 | [Face Attribute - Flutter](https://github.com/kby-ai/FaceAttribute-Flutter) | Premium SDK | 53 | 54 | > To get `Face SDK(server)`, please visit products [here](https://github.com/kby-ai/Product).
55 | 56 | ## Try with Demo App 57 | 58 | ### Google Play 59 | 60 | 61 | 62 | 63 | 64 | ### App Store 65 | 66 | 67 | 68 | 69 | 70 | ## Performance Video 71 | 72 | You can visit our YouTube video [here](https://www.youtube.com/watch?v=HpDggnWsG1c) to see how well our demo app works.

73 | [![Face Recognition Android](https://img.youtube.com/vi/HpDggnWsG1c/0.jpg)](https://www.youtube.com/watch?v=HpDggnWsG1c) 74 | 75 | 76 | ## Screenshots 77 | 78 |

79 | 80 | 81 | 82 |

83 | 84 |

85 | 86 | 87 | 88 | 89 |

90 | 91 | ## SDK License 92 | 93 | The face recognition project relies on `KBY-AI`'s SDK, which requires a license for each `application ID`. 94 | 95 | - The code below shows how to use the license: https://github.com/kby-ai/FaceRecognition-React-Native/blob/170b598257d015302ac87106d9022bbab8831248/example/src/MainPage.tsx#L17-L34 96 | 97 | - To request a license, please contact us:
98 | 🧙`Email:` contact@kby-ai.com
99 | 🧙`Telegram:` [@kbyai](https://t.me/kbyai)
100 | 🧙`WhatsApp:` [+19092802609](https://wa.me/+19092802609)
101 | 🧙`Discord:` [KBY-AI](https://discord.gg/CgHtWQ3k9T)
102 | 🧙`Teams:` [KBY-AI](https://teams.live.com/l/invite/FBAYGB1-IlXkuQM3AY)
103 | 104 | ## How To Run 105 | ### 1. Setting Up React-Native Development Environment 106 | Make sure you have `React-Native` installed.
107 | If you don't have `React-Native` installed, please follow the instructions provided in the official `React-Native` documentation [here](https://reactnative.dev/docs/environment-setup).
108 | ### 2. Running the Android App 109 | Run the following commands: 110 | ```bash 111 | yarn 112 | yarn example android 113 | ``` 114 | ### 3. Running the iOS App 115 | Run the following commands: 116 | ```bash 117 | yarn 118 | cd example 119 | yarn 120 | cd ios 121 | pod install 122 | ``` 123 | Please open the `FaceRecognitionSdkExample.xcworkspace` in `Xcode` and run the app. 124 | ## About SDK 125 | ### 1. Setup 126 | ### 1.1 Setting Up Face SDK 127 | > Android 128 | 129 | - Copy the SDK (folder: `libfacesdk`) to the folder `android` in your project path.
130 | - Add the SDK to the project in `settings.gradle` 131 | ```java 132 | include ':libfacesdk' 133 | ``` 134 | ### 2 API Usages 135 | #### 2.1 FaceSDKModule 136 | - Activate the `FaceSDKModule` by calling the `setActivation` method: 137 | ```kotlin 138 | var ret = await FaceSDKModule.setActivation("..."); 139 | console.log("set activation:", ret); 140 | ``` 141 | - Initialize the `FaceSDKModule` by calling the `initSDK` method: 142 | ```kotlin 143 | var ret = await FaceSDKModule.initSDK(); 144 | ``` 145 | - Set parameters using the `setParam` method: 146 | ```kotlin 147 | var ret = await FaceSDKModule.setParam(checkLivenessLevel); 148 | ``` 149 | - Extract faces using the `extractFaces` method: 150 | ```kotlin 151 | var faceBoxes = await FaceSDKModule.extractFaces(uri); 152 | ``` 153 | - Calculate the similarity between faces using the `similarityCalculation` method: 154 | ```kotlin 155 | const similarity = await FaceSDKModule.similarityCalculation( 156 | face.templates, 157 | person.templates 158 | ); 159 | ``` 160 | #### 2.2 FaceRecognitionSdkView 161 | - To build the native camera screen and process face detection, please refer to the [example/src/FaceRecognitionPage.tsx](https://github.com/kby-ai/FaceRecognition-React-Native/blob/main/example/src/FaceRecognitionPage.tsx) file in the repository. 162 | 163 | ```tsx 164 | 165 | ``` 166 | - To obtain the face detection results, use the following code: 167 | ```tsx 168 | const eventEmitter = new NativeEventEmitter(FaceSDKModule); 169 | let eventListener = eventEmitter.addListener('onFaceDetected', (event) => { 170 | setFaces(event); 171 | if (recognized == false) { 172 | identifyPerson(event); 173 | } 174 | }); 175 | ``` 176 | - To start and stop the camera, use the following code: 177 | ```tsx 178 | //Start Camera 179 | const startCamera = async () => { 180 | await FaceSDKModule.startCamera(); 181 | } 182 | 183 | //Stop Camera 184 | const stopCamera = async () => { 185 | await FaceSDKModule.stopCamera(); 186 | } 187 | ``` 188 | 189 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | // Buildscript is evaluated before everything else so we can't use getExtOrDefault 3 | def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["FaceRecognitionSdk_kotlinVersion"] 4 | 5 | repositories { 6 | google() 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | classpath "com.android.tools.build:gradle:7.2.1" 12 | // noinspection DifferentKotlinGradleVersion 13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 14 | } 15 | } 16 | 17 | def isNewArchitectureEnabled() { 18 | return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" 19 | } 20 | 21 | apply plugin: "com.android.library" 22 | apply plugin: "kotlin-android" 23 | 24 | 25 | def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') } 26 | 27 | if (isNewArchitectureEnabled()) { 28 | apply plugin: "com.facebook.react" 29 | } 30 | 31 | def getExtOrDefault(name) { 32 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["FaceRecognitionSdk_" + name] 33 | } 34 | 35 | def getExtOrIntegerDefault(name) { 36 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["FaceRecognitionSdk_" + name]).toInteger() 37 | } 38 | 39 | def isAGPVersionGreaterThan(version) { 40 | def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger() 41 | return agpVersion > version 42 | } 43 | 44 | android { 45 | if (isAGPVersionGreaterThan(7)) { 46 | namespace "com.facerecognitionsdk" 47 | } 48 | 49 | compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") 50 | 51 | defaultConfig { 52 | minSdkVersion getExtOrIntegerDefault("minSdkVersion") 53 | targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") 54 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() 55 | } 56 | buildTypes { 57 | release { 58 | minifyEnabled false 59 | } 60 | } 61 | 62 | lintOptions { 63 | disable "GradleCompatible" 64 | } 65 | 66 | compileOptions { 67 | sourceCompatibility JavaVersion.VERSION_1_8 68 | targetCompatibility JavaVersion.VERSION_1_8 69 | } 70 | 71 | } 72 | 73 | repositories { 74 | mavenCentral() 75 | google() 76 | } 77 | 78 | def kotlin_version = getExtOrDefault("kotlinVersion") 79 | 80 | dependencies { 81 | // For < 0.71, this will be from the local maven repo 82 | // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin 83 | //noinspection GradleDynamicVersion 84 | implementation "com.facebook.react:react-native:+" 85 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 86 | 87 | // implementation files('libs/facesdk.aar') 88 | implementation project(path: ':libfacesdk') 89 | implementation 'io.fotoapparat:fotoapparat:2.7.0' 90 | } 91 | 92 | if (isNewArchitectureEnabled()) { 93 | react { 94 | jsRootDir = file("../src/") 95 | libraryName = "FaceRecognitionSdkView" 96 | codegenJavaPackageName = "com.facerecognitionsdk" 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | FaceRecognitionSdk_kotlinVersion=1.7.0 2 | FaceRecognitionSdk_minSdkVersion=23 3 | FaceRecognitionSdk_targetSdkVersion=31 4 | FaceRecognitionSdk_compileSdkVersion=31 5 | FaceRecognitionSdk_ndkversion=21.4.7075529 6 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /android/src/main/java/com/facerecognitionsdk/FaceRecognitionSdkPackage.kt: -------------------------------------------------------------------------------- 1 | package com.facerecognitionsdk 2 | 3 | import com.facebook.react.ReactPackage 4 | import com.facebook.react.bridge.NativeModule 5 | import com.facebook.react.bridge.ReactApplicationContext 6 | import com.facebook.react.uimanager.ViewManager 7 | 8 | 9 | class FaceRecognitionSdkPackage : ReactPackage { 10 | override fun createNativeModules(reactContext: ReactApplicationContext): List { 11 | return listOf(FaceSDKModule(reactContext)) 12 | } 13 | 14 | override fun createViewManagers(reactContext: ReactApplicationContext): List> { 15 | return listOf(FaceRecognitionSdkViewManager(reactContext)) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /android/src/main/java/com/facerecognitionsdk/FaceRecognitionSdkViewManager.kt: -------------------------------------------------------------------------------- 1 | package com.facerecognitionsdk 2 | 3 | import android.R 4 | import android.graphics.Color 5 | import android.util.Log 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.widget.FrameLayout 9 | import android.widget.RelativeLayout 10 | import com.facebook.react.bridge.LifecycleEventListener 11 | import com.facebook.react.bridge.ReactApplicationContext 12 | import com.facebook.react.common.MapBuilder 13 | import com.facebook.react.uimanager.SimpleViewManager 14 | import com.facebook.react.uimanager.ThemedReactContext 15 | import com.facebook.react.uimanager.annotations.ReactProp 16 | import com.facebook.react.modules.core.DeviceEventManagerModule 17 | import com.facebook.react.bridge.Arguments 18 | import com.facebook.react.bridge.WritableArray 19 | import com.facebook.react.bridge.* 20 | import io.fotoapparat.Fotoapparat 21 | import io.fotoapparat.parameter.Resolution 22 | import io.fotoapparat.selector.front 23 | import io.fotoapparat.selector.back 24 | import io.fotoapparat.view.CameraView 25 | import io.fotoapparat.util.FrameProcessor 26 | import io.fotoapparat.preview.Frame 27 | import io.fotoapparat.configuration.CameraConfiguration 28 | import android.graphics.Bitmap 29 | import com.kbyai.facesdk.FaceBox 30 | import com.kbyai.facesdk.FaceDetectionParam 31 | import com.kbyai.facesdk.FaceSDK 32 | import java.io.ByteArrayOutputStream 33 | 34 | class FaceRecognitionSdkViewManager(private val reactContext: ReactApplicationContext): SimpleViewManager(), LifecycleEventListener{ 35 | 36 | private var frontFotoapparat: Fotoapparat? = null 37 | private var linearLayout: FrameLayout? = null 38 | private var dummyLayout: FrameLayout? = null 39 | private var cameraView: CameraView? = null 40 | private var cameraLens: Int = 0 41 | private var checkLivenessLevel: Int = 0 42 | 43 | init { 44 | reactContext.addLifecycleEventListener(this) 45 | FaceSDKModule.faceRecognitionSdkViewManager = this 46 | } 47 | 48 | override fun getName() = "FaceRecognitionSdkView" 49 | 50 | override fun createViewInstance(reactContext: ThemedReactContext): View { 51 | Log.e("TestEngine", "createViewInstance") 52 | linearLayout = FrameLayout(reactContext).apply { 53 | layoutParams = FrameLayout.LayoutParams( 54 | RelativeLayout.LayoutParams.MATCH_PARENT, 55 | RelativeLayout.LayoutParams.MATCH_PARENT 56 | ) 57 | setBackgroundColor(Color.parseColor("#000000")) 58 | 59 | cameraView = CameraView(reactContext).apply { 60 | layoutParams = FrameLayout.LayoutParams( 61 | ViewGroup.LayoutParams.MATCH_PARENT, 62 | ViewGroup.LayoutParams.MATCH_PARENT 63 | ) 64 | } 65 | addView(cameraView) 66 | 67 | // dummyLayout = FrameLayout(reactContext).apply { 68 | // layoutParams = FrameLayout.LayoutParams( 69 | // RelativeLayout.LayoutParams.MATCH_PARENT, 70 | // RelativeLayout.LayoutParams.MATCH_PARENT 71 | // ) 72 | // setBackgroundColor(Color.parseColor("#000000")) 73 | // } 74 | // addView(dummyLayout) 75 | 76 | frontFotoapparat = Fotoapparat.with(reactContext) 77 | .into(cameraView!!) 78 | .lensPosition(front()) 79 | .frameProcessor(SampleFrameProcessor()) 80 | .previewResolution { Resolution(1280, 720) } 81 | .build() 82 | } 83 | 84 | return linearLayout!! 85 | } 86 | 87 | override fun onDropViewInstance(view: View) { 88 | super.onDropViewInstance(view) 89 | 90 | frontFotoapparat?.stop() 91 | } 92 | @ReactProp(name = "color") 93 | fun setColor(view: View, color: String) { 94 | view.setBackgroundColor(Color.parseColor(color)) 95 | } 96 | 97 | @ReactProp(name = "livenessLevel") 98 | fun setLivenessLevel(view: View, livenessLevel: Int) { 99 | Log.e("TestEngine", "setLivenessLevel " + livenessLevel) 100 | this.checkLivenessLevel = livenessLevel 101 | 102 | startCamera() 103 | } 104 | 105 | @ReactProp(name = "cameraLens") 106 | fun setCameraLens(view: View, cameraLens: Int) { 107 | Log.e("TestEngine", "setCameraLens " + cameraLens) 108 | this.cameraLens = cameraLens 109 | } 110 | 111 | fun startCamera() { 112 | val configuration = CameraConfiguration() 113 | if(cameraLens == 1) { 114 | frontFotoapparat?.switchTo(lensPosition = front(), 115 | cameraConfiguration = configuration) 116 | } else { 117 | frontFotoapparat?.switchTo(lensPosition = back(), 118 | cameraConfiguration = configuration) 119 | } 120 | 121 | frontFotoapparat?.start() 122 | } 123 | 124 | fun stopCamera() { 125 | frontFotoapparat?.stop() 126 | } 127 | 128 | override fun onHostResume() { 129 | Log.e("TestEngine", "onHostResume") 130 | val configuration = CameraConfiguration() 131 | if(cameraLens == 1) { 132 | frontFotoapparat?.switchTo(lensPosition = front(), 133 | cameraConfiguration = configuration) 134 | } else { 135 | frontFotoapparat?.switchTo(lensPosition = back(), 136 | cameraConfiguration = configuration) 137 | } 138 | 139 | frontFotoapparat?.start() 140 | } 141 | 142 | override fun onHostPause() { 143 | Log.e("TestEngine", "onHostPause") 144 | frontFotoapparat?.stop() 145 | } 146 | 147 | override fun onHostDestroy() { 148 | Log.e("TestEngine", "onHostDestroy") 149 | } 150 | 151 | private fun sendEvent(reactContext: ReactApplicationContext, eventName: String, params: WritableArray?) { 152 | reactContext 153 | .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) 154 | .emit(eventName, params) 155 | } 156 | 157 | inner class SampleFrameProcessor : FrameProcessor { 158 | override fun invoke(frame: Frame) { 159 | 160 | var cameraMode = 7 161 | if (cameraLens == 0) { 162 | cameraMode = 6 163 | } 164 | 165 | val bitmap: Bitmap = FaceSDK.yuv2Bitmap(frame.image, frame.size.width, frame.size.height, cameraMode) 166 | 167 | val param = FaceDetectionParam() 168 | param.check_liveness = true 169 | param.check_liveness_level = checkLivenessLevel 170 | 171 | val faceBoxesMap: WritableArray = Arguments.createArray() 172 | var faceBoxes: List? = FaceSDK.faceDetection(bitmap, param) 173 | if (!faceBoxes.isNullOrEmpty()) { 174 | for (face in faceBoxes!!) { 175 | val faceImage = Utils.cropFace(bitmap, face) 176 | val templates = FaceSDK.templateExtraction(bitmap, face) 177 | 178 | val byteArrayOutputStream = ByteArrayOutputStream() 179 | faceImage.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream) 180 | val faceJpg: ByteArray = byteArrayOutputStream.toByteArray() 181 | 182 | val e: WritableMap = Arguments.createMap() 183 | e.putString("x1", face.x1.toString()) 184 | e.putString("y1", face.y1.toString()) 185 | e.putString("x2", face.x2.toString()) 186 | e.putString("y2", face.y2.toString()) 187 | e.putString("liveness", face.liveness.toString()) 188 | e.putString("yaw", face.yaw.toString()) 189 | e.putString("roll", face.roll.toString()) 190 | e.putString("pitch", face.pitch.toString()) 191 | e.putString("templates", Utils.byteArrayToBase64(templates)) 192 | e.putString("faceJpg", Utils.byteArrayToBase64(faceJpg)) 193 | e.putString("frameWidth", bitmap.width.toString()) 194 | e.putString("frameHeight", bitmap.height.toString()) 195 | faceBoxesMap.pushMap(e) 196 | } 197 | } 198 | // Log.e("TestEngine", "face detection: " + bitmap.width) 199 | sendEvent(reactContext, "onFaceDetected", faceBoxesMap) 200 | bitmap.recycle() 201 | } 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /android/src/main/java/com/facerecognitionsdk/FaceSDKModule.kt: -------------------------------------------------------------------------------- 1 | package com.facerecognitionsdk 2 | import android.content.ContentResolver 3 | import android.content.Context 4 | import android.graphics.Bitmap 5 | import android.graphics.BitmapFactory 6 | import android.net.Uri 7 | import android.util.Log 8 | import com.facebook.react.bridge.* 9 | import com.facebook.react.bridge.ReactApplicationContext 10 | import com.facebook.react.bridge.ReactContextBaseJavaModule 11 | import com.facebook.react.bridge.ReactMethod 12 | import com.kbyai.facesdk.FaceBox 13 | import com.kbyai.facesdk.FaceDetectionParam 14 | import com.kbyai.facesdk.FaceSDK 15 | import java.io.ByteArrayOutputStream 16 | import com.facebook.react.bridge.Arguments 17 | import com.facebook.react.bridge.WritableArray 18 | import com.facerecognitionsdk.Utils 19 | import android.util.Base64 20 | import com.facebook.react.modules.core.DeviceEventManagerModule 21 | 22 | class FaceSDKModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { 23 | 24 | private var checkLivenessLevel: Int = 0 25 | private var listenerCount = 0 26 | 27 | companion object { 28 | public var faceRecognitionSdkViewManager: FaceRecognitionSdkViewManager? = null 29 | } 30 | 31 | override fun getName() = "FaceSDKModule" 32 | 33 | override fun initialize() { 34 | super.initialize() 35 | } 36 | 37 | private fun sendEvent(reactContext: ReactApplicationContext, eventName: String, params: WritableArray?) { 38 | reactContext 39 | .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java) 40 | .emit(eventName, params) 41 | } 42 | 43 | @ReactMethod 44 | fun setActivation(license: String, promise: Promise){ 45 | val ret = FaceSDK.setActivation(license) 46 | 47 | promise.resolve(ret) 48 | } 49 | 50 | @ReactMethod 51 | fun initSDK(promise: Promise){ 52 | Log.d("FaceSDKModule", "initSDK") 53 | val reactContext: ReactApplicationContext = getReactApplicationContext() 54 | val context: Context = reactContext.getApplicationContext() 55 | val ret = FaceSDK.init(context.assets) 56 | promise.resolve(ret) 57 | } 58 | 59 | @ReactMethod 60 | fun setParam(checkLivenessLevel: Int, promise: Promise){ 61 | Log.d("FaceSDKModule", "setParam") 62 | this.checkLivenessLevel = checkLivenessLevel 63 | promise.resolve(0) 64 | } 65 | 66 | @ReactMethod 67 | fun extractFaces(imagePath: String, promise: Promise){ 68 | Log.d("FaceSDKModule", "extractFaces") 69 | val imageUri = Uri.parse(imagePath) 70 | val reactContext: ReactApplicationContext = getReactApplicationContext() 71 | val context: Context = reactContext.getApplicationContext() 72 | val faceBoxesMap: WritableArray = Arguments.createArray() 73 | 74 | val bitmap: Bitmap? = Utils.getCorrectlyOrientedImage(context, imageUri) 75 | if(bitmap != null) { 76 | val param = FaceDetectionParam() 77 | param.check_liveness = true 78 | param.check_liveness_level = checkLivenessLevel 79 | 80 | var faceBoxes: List? = FaceSDK.faceDetection(bitmap, param) 81 | if (!faceBoxes.isNullOrEmpty()) { 82 | for (face in faceBoxes!!) { 83 | val faceImage = Utils.cropFace(bitmap, face) 84 | val templates = FaceSDK.templateExtraction(bitmap, face) 85 | 86 | val byteArrayOutputStream = ByteArrayOutputStream() 87 | faceImage.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream) 88 | val faceJpg: ByteArray = byteArrayOutputStream.toByteArray() 89 | 90 | val e: WritableMap = Arguments.createMap() 91 | e.putString("x1", face.x1.toString()) 92 | e.putString("y1", face.y1.toString()) 93 | e.putString("x2", face.x2.toString()) 94 | e.putString("y2", face.y2.toString()) 95 | e.putString("liveness", face.liveness.toString()) 96 | e.putString("yaw", face.yaw.toString()) 97 | e.putString("roll", face.roll.toString()) 98 | e.putString("pitch", face.pitch.toString()) 99 | e.putString("templates", Utils.byteArrayToBase64(templates)) 100 | e.putString("faceJpg", Utils.byteArrayToBase64(faceJpg)) 101 | e.putString("frameWidth", bitmap.width.toString()) 102 | e.putString("frameHeight", bitmap.height.toString()) 103 | faceBoxesMap.pushMap(e) 104 | } 105 | } 106 | } 107 | 108 | promise.resolve(faceBoxesMap) 109 | } 110 | 111 | @ReactMethod 112 | fun similarityCalculation(templates1: String, templates2: String, promise: Promise) { 113 | val similarity = FaceSDK.similarityCalculation(Utils.base64ToByteArray(templates1), Utils.base64ToByteArray(templates2)) 114 | Log.e("KBY", "similarityCalculation" + similarity) 115 | promise.resolve(similarity) 116 | } 117 | 118 | @ReactMethod 119 | fun startCamera(promise: Promise) { 120 | Log.e("KBY", "start camera" + faceRecognitionSdkViewManager); 121 | faceRecognitionSdkViewManager?.startCamera() 122 | promise.resolve(0) 123 | } 124 | 125 | @ReactMethod 126 | fun stopCamera(promise: Promise) { 127 | Log.e("KBY", "stop camera"); 128 | faceRecognitionSdkViewManager?.stopCamera() 129 | promise.resolve(0) 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /android/src/main/java/com/facerecognitionsdk/Utils.kt: -------------------------------------------------------------------------------- 1 | package com.facerecognitionsdk 2 | 3 | import android.content.Context 4 | import android.database.Cursor 5 | import android.graphics.Bitmap 6 | import android.graphics.BitmapFactory 7 | import android.graphics.Matrix 8 | import android.net.Uri 9 | import android.provider.MediaStore 10 | import android.util.Base64 11 | import android.util.Log 12 | import com.kbyai.facesdk.FaceBox 13 | import android.media.ExifInterface 14 | import java.io.IOException 15 | import java.io.InputStream 16 | 17 | object Utils { 18 | 19 | fun cropFace(src: Bitmap, faceBox: FaceBox): Bitmap { 20 | val centerX = (faceBox.x1 + faceBox.x2) / 2 21 | val centerY = (faceBox.y1 + faceBox.y2) / 2 22 | val cropWidth = ((faceBox.x2 - faceBox.x1) * 1.4f).toInt() 23 | 24 | var cropX1 = centerX - cropWidth / 2 25 | var cropY1 = centerY - cropWidth / 2 26 | var cropX2 = centerX + cropWidth / 2 27 | var cropY2 = centerY + cropWidth / 2 28 | if (cropX1 < 0) cropX1 = 0 29 | if (cropX2 >= src.width) cropX2 = src.width - 1 30 | if (cropY1 < 0) cropY1 = 0 31 | if (cropY2 >= src.height) cropY2 = src.height - 1 32 | 33 | 34 | val cropScaleWidth = 200 35 | val cropScaleHeight = 200 36 | val scaleWidth = cropScaleWidth.toFloat() / (cropX2 - cropX1 + 1) 37 | val scaleHeight = cropScaleHeight.toFloat() / (cropY2 - cropY1 + 1) 38 | 39 | val m = Matrix() 40 | 41 | m.setScale(1.0f, 1.0f) 42 | m.postScale(scaleWidth, scaleHeight) 43 | val cropped = Bitmap.createBitmap(src, cropX1, cropY1, (cropX2 - cropX1 + 1), (cropY2 - cropY1 + 1), m, 44 | true /* filter */) 45 | return cropped 46 | } 47 | 48 | fun getOrientation(context: Context, photoUri: Uri): Int { 49 | val cursor: Cursor? = context.contentResolver.query(photoUri, 50 | arrayOf(MediaStore.Images.ImageColumns.ORIENTATION), null, null, null) 51 | 52 | if (cursor?.count != 1) { 53 | return -1 54 | } 55 | 56 | cursor.moveToFirst() 57 | return cursor.getInt(0) 58 | } 59 | 60 | @Throws(IOException::class) 61 | fun getCorrectlyOrientedImage(context: Context, photoUri: Uri): Bitmap { 62 | var rotate = 0 63 | val inputStream: InputStream? = context.contentResolver.openInputStream(photoUri) 64 | inputStream?.let { 65 | val exif = ExifInterface(it) 66 | val orientation = exif.getAttributeInt( 67 | ExifInterface.TAG_ORIENTATION, 68 | ExifInterface.ORIENTATION_NORMAL 69 | ) 70 | rotate = when (orientation) { 71 | ExifInterface.ORIENTATION_ROTATE_270 -> 270 72 | ExifInterface.ORIENTATION_ROTATE_180 -> 180 73 | ExifInterface.ORIENTATION_ROTATE_90 -> 90 74 | else -> 0 75 | } 76 | it.close() 77 | } 78 | 79 | var srcBitmap: Bitmap 80 | val isStream = context.contentResolver.openInputStream(photoUri) 81 | srcBitmap = BitmapFactory.decodeStream(isStream) 82 | isStream?.close() 83 | 84 | val matrix = Matrix() 85 | matrix.postRotate(rotate.toFloat()) 86 | return Bitmap.createBitmap( 87 | srcBitmap, 88 | 0, 89 | 0, 90 | srcBitmap.width, 91 | srcBitmap.height, 92 | matrix, 93 | true 94 | ) 95 | } 96 | 97 | fun byteArrayToBase64(byteArray: ByteArray): String { 98 | val base64ByteArray = Base64.encode(byteArray, Base64.DEFAULT) 99 | return String(base64ByteArray) 100 | } 101 | 102 | fun base64ToByteArray(base64String: String): ByteArray { 103 | return Base64.decode(base64String, Base64.DEFAULT) 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /android/src/main/res/layout/camera_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby ">= 2.6.10" 5 | 6 | gem 'cocoapods', '~> 1.12' 7 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli). 2 | 3 | # Getting Started 4 | 5 | >**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. 6 | 7 | ## Step 1: Start the Metro Server 8 | 9 | First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native. 10 | 11 | To start Metro, run the following command from the _root_ of your React Native project: 12 | 13 | ```bash 14 | # using npm 15 | npm start 16 | 17 | # OR using Yarn 18 | yarn start 19 | ``` 20 | 21 | ## Step 2: Start your Application 22 | 23 | Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app: 24 | 25 | ### For Android 26 | 27 | ```bash 28 | # using npm 29 | npm run android 30 | 31 | # OR using Yarn 32 | yarn android 33 | ``` 34 | 35 | ### For iOS 36 | 37 | ```bash 38 | # using npm 39 | npm run ios 40 | 41 | # OR using Yarn 42 | yarn ios 43 | ``` 44 | 45 | If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly. 46 | 47 | This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively. 48 | 49 | ## Step 3: Modifying your App 50 | 51 | Now that you have successfully run the app, let's modify it. 52 | 53 | 1. Open `App.tsx` in your text editor of choice and edit some lines. 54 | 2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes! 55 | 56 | For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes! 57 | 58 | ## Congratulations! :tada: 59 | 60 | You've successfully run and modified your React Native App. :partying_face: 61 | 62 | ### Now what? 63 | 64 | - If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps). 65 | - If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started). 66 | 67 | # Troubleshooting 68 | 69 | If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page. 70 | 71 | # Learn More 72 | 73 | To learn more about React Native, take a look at the following resources: 74 | 75 | - [React Native Website](https://reactnative.dev) - learn more about React Native. 76 | - [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment. 77 | - [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**. 78 | - [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts. 79 | - [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native. 80 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "com.facebook.react" 3 | 4 | /** 5 | * This is the configuration block to customize your React Native Android app. 6 | * By default you don't need to apply any configuration, just uncomment the lines you need. 7 | */ 8 | react { 9 | /* Folders */ 10 | // The root of your project, i.e. where "package.json" lives. Default is '..' 11 | // root = file("../") 12 | // The folder where the react-native NPM package is. Default is ../node_modules/react-native 13 | // reactNativeDir = file("../node_modules/react-native") 14 | // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen 15 | // codegenDir = file("../node_modules/@react-native/codegen") 16 | // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js 17 | // cliFile = file("../node_modules/react-native/cli.js") 18 | 19 | /* Variants */ 20 | // The list of variants to that are debuggable. For those we're going to 21 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'. 22 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. 23 | // debuggableVariants = ["liteDebug", "prodDebug"] 24 | 25 | /* Bundling */ 26 | // A list containing the node command and its flags. Default is just 'node'. 27 | // nodeExecutableAndArgs = ["node"] 28 | // 29 | // The command to run when bundling. By default is 'bundle' 30 | // bundleCommand = "ram-bundle" 31 | // 32 | // The path to the CLI configuration file. Default is empty. 33 | // bundleConfig = file(../rn-cli.config.js) 34 | // 35 | // The name of the generated asset file containing your JS bundle 36 | // bundleAssetName = "MyApplication.android.bundle" 37 | // 38 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' 39 | // entryFile = file("../js/MyApplication.android.js") 40 | // 41 | // A list of extra flags to pass to the 'bundle' commands. 42 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle 43 | // extraPackagerArgs = [] 44 | 45 | /* Hermes Commands */ 46 | // The hermes compiler command to run. By default it is 'hermesc' 47 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" 48 | // 49 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" 50 | // hermesFlags = ["-O", "-output-source-map"] 51 | } 52 | 53 | /** 54 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode. 55 | */ 56 | def enableProguardInReleaseBuilds = false 57 | 58 | /** 59 | * The preferred build flavor of JavaScriptCore (JSC) 60 | * 61 | * For example, to use the international variant, you can use: 62 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 63 | * 64 | * The international variant includes ICU i18n library and necessary data 65 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 66 | * give correct results when using with locales other than en-US. Note that 67 | * this variant is about 6MiB larger per architecture than default. 68 | */ 69 | def jscFlavor = 'org.webkit:android-jsc:+' 70 | 71 | android { 72 | ndkVersion rootProject.ext.ndkVersion 73 | 74 | compileSdkVersion rootProject.ext.compileSdkVersion 75 | 76 | namespace "com.facerecognitionsdkexample" 77 | defaultConfig { 78 | applicationId "com.facerecognitionsdkexample" 79 | minSdkVersion rootProject.ext.minSdkVersion 80 | targetSdkVersion rootProject.ext.targetSdkVersion 81 | versionCode 1 82 | versionName "1.0" 83 | } 84 | signingConfigs { 85 | debug { 86 | storeFile file('debug.keystore') 87 | storePassword 'android' 88 | keyAlias 'androiddebugkey' 89 | keyPassword 'android' 90 | } 91 | } 92 | buildTypes { 93 | debug { 94 | signingConfig signingConfigs.debug 95 | } 96 | release { 97 | // Caution! In production, you need to generate your own keystore file. 98 | // see https://reactnative.dev/docs/signed-apk-android. 99 | signingConfig signingConfigs.debug 100 | minifyEnabled enableProguardInReleaseBuilds 101 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 102 | } 103 | } 104 | } 105 | 106 | dependencies { 107 | // The version of react-native is set by the React Native Gradle Plugin 108 | implementation("com.facebook.react:react-android") 109 | // implementation project(path: ':libfacesdk') 110 | 111 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") 112 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 113 | exclude group:'com.squareup.okhttp3', module:'okhttp' 114 | } 115 | 116 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") 117 | if (hermesEnabled.toBoolean()) { 118 | implementation("com.facebook.react:hermes-android") 119 | } else { 120 | implementation jscFlavor 121 | } 122 | } 123 | 124 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 125 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/facerecognitionsdkexample/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.facerecognitionsdkexample; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 21 | import com.facebook.react.ReactInstanceEventListener; 22 | import com.facebook.react.ReactInstanceManager; 23 | import com.facebook.react.bridge.ReactContext; 24 | import com.facebook.react.modules.network.NetworkingModule; 25 | import okhttp3.OkHttpClient; 26 | 27 | /** 28 | * Class responsible of loading Flipper inside your React Native application. This is the debug 29 | * flavor of it. Here you can add your own plugins and customize the Flipper setup. 30 | */ 31 | public class ReactNativeFlipper { 32 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 33 | if (FlipperUtils.shouldEnableFlipper(context)) { 34 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 35 | 36 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 37 | client.addPlugin(new DatabasesFlipperPlugin(context)); 38 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 39 | client.addPlugin(CrashReporterPlugin.getInstance()); 40 | 41 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 42 | NetworkingModule.setCustomClientBuilder( 43 | new NetworkingModule.CustomClientBuilder() { 44 | @Override 45 | public void apply(OkHttpClient.Builder builder) { 46 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 47 | } 48 | }); 49 | client.addPlugin(networkFlipperPlugin); 50 | client.start(); 51 | 52 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 53 | // Hence we run if after all native modules have been initialized 54 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 55 | if (reactContext == null) { 56 | reactInstanceManager.addReactInstanceEventListener( 57 | new ReactInstanceEventListener() { 58 | @Override 59 | public void onReactContextInitialized(ReactContext reactContext) { 60 | reactInstanceManager.removeReactInstanceEventListener(this); 61 | reactContext.runOnNativeModulesQueueThread( 62 | new Runnable() { 63 | @Override 64 | public void run() { 65 | client.addPlugin(new FrescoFlipperPlugin()); 66 | } 67 | }); 68 | } 69 | }); 70 | } else { 71 | client.addPlugin(new FrescoFlipperPlugin()); 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 14 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/facerecognitionsdkexample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.facerecognitionsdkexample; 2 | 3 | import com.facebook.react.ReactActivity; 4 | import com.facebook.react.ReactActivityDelegate; 5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; 6 | import com.facebook.react.defaults.DefaultReactActivityDelegate; 7 | 8 | public class MainActivity extends ReactActivity { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | @Override 15 | protected String getMainComponentName() { 16 | return "FaceRecognitionSdkExample"; 17 | } 18 | 19 | /** 20 | * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link 21 | * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React 22 | * (aka React 18) with two boolean flags. 23 | */ 24 | @Override 25 | protected ReactActivityDelegate createReactActivityDelegate() { 26 | return new DefaultReactActivityDelegate( 27 | this, 28 | getMainComponentName(), 29 | // If you opted-in for the New Architecture, we enable the Fabric Renderer. 30 | DefaultNewArchitectureEntryPoint.getFabricEnabled()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/facerecognitionsdkexample/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.facerecognitionsdkexample; 2 | 3 | import android.app.Application; 4 | import com.facebook.react.PackageList; 5 | import com.facebook.react.ReactApplication; 6 | import com.facebook.react.ReactNativeHost; 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; 9 | import com.facebook.react.defaults.DefaultReactNativeHost; 10 | import com.facebook.soloader.SoLoader; 11 | import java.util.List; 12 | 13 | public class MainApplication extends Application implements ReactApplication { 14 | 15 | private final ReactNativeHost mReactNativeHost = 16 | new DefaultReactNativeHost(this) { 17 | @Override 18 | public boolean getUseDeveloperSupport() { 19 | return BuildConfig.DEBUG; 20 | } 21 | 22 | @Override 23 | protected List getPackages() { 24 | @SuppressWarnings("UnnecessaryLocalVariable") 25 | List packages = new PackageList(this).getPackages(); 26 | // Packages that cannot be autolinked yet can be added manually here, for example: 27 | // packages.add(new MyReactNativePackage()); 28 | return packages; 29 | } 30 | 31 | @Override 32 | protected String getJSMainModuleName() { 33 | return "index"; 34 | } 35 | 36 | @Override 37 | protected boolean isNewArchEnabled() { 38 | return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 39 | } 40 | 41 | @Override 42 | protected Boolean isHermesEnabled() { 43 | return BuildConfig.IS_HERMES_ENABLED; 44 | } 45 | }; 46 | 47 | @Override 48 | public ReactNativeHost getReactNativeHost() { 49 | return mReactNativeHost; 50 | } 51 | 52 | @Override 53 | public void onCreate() { 54 | super.onCreate(); 55 | SoLoader.init(this, /* native exopackage */ false); 56 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 57 | // If you opted-in for the New Architecture, we load the native entry point for this app. 58 | DefaultNewArchitectureEntryPoint.load(); 59 | } 60 | ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FaceRecognitionSdkExample 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/app/src/release/java/com/facerecognitionsdkexample/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.facerecognitionsdkexample; 8 | 9 | import android.content.Context; 10 | import com.facebook.react.ReactInstanceManager; 11 | 12 | /** 13 | * Class responsible of loading Flipper inside your React Native application. This is the release 14 | * flavor of it so it's empty as we don't want to load Flipper. 15 | */ 16 | public class ReactNativeFlipper { 17 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 18 | // Do nothing as we don't want to initialize Flipper on Release. 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "33.0.0" 6 | minSdkVersion = 23 7 | compileSdkVersion = 33 8 | targetSdkVersion = 33 9 | 10 | // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. 11 | ndkVersion = "21.4.7075529" 12 | } 13 | repositories { 14 | google() 15 | mavenCentral() 16 | } 17 | dependencies { 18 | classpath("com.android.tools.build:gradle") 19 | classpath("com.facebook.react:react-native-gradle-plugin") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Version of flipper SDK to use with React Native 28 | FLIPPER_VERSION=0.182.0 29 | 30 | # Use this property to specify which architecture you want to build. 31 | # You can also override it from the CLI using 32 | # ./gradlew -PreactNativeArchitectures=x86_64 33 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 34 | 35 | # Use this property to enable support to the new architecture. 36 | # This will allow you to use TurboModules and the Fabric render in 37 | # your application. You should enable this flag either if you want 38 | # to write custom TurboModules/Fabric components OR use libraries that 39 | # are providing them. 40 | newArchEnabled=false 41 | 42 | # Use this property to enable or disable the Hermes JS engine. 43 | # If set to false, you will be using JSC instead. 44 | hermesEnabled=true 45 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | # Collect all arguments for the java command; 201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 202 | # shell script including quotes and variable substitutions, so put them in 203 | # double quotes to make sure that they get re-expanded; and 204 | # * put everything else in single quotes, so that it's not re-expanded. 205 | 206 | set -- \ 207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 208 | -classpath "$CLASSPATH" \ 209 | org.gradle.wrapper.GradleWrapperMain \ 210 | "$@" 211 | 212 | # Stop when "xargs" is not available. 213 | if ! command -v xargs >/dev/null 2>&1 214 | then 215 | die "xargs is not available" 216 | fi 217 | 218 | # Use "xargs" to parse quoted args. 219 | # 220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 221 | # 222 | # In Bash we could simply go: 223 | # 224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 225 | # set -- "${ARGS[@]}" "$@" 226 | # 227 | # but POSIX shell has neither arrays nor command substitution, so instead we 228 | # post-process each arg (as a line of input to sed) to backslash-escape any 229 | # character that might be a shell metacharacter, then use eval to reverse 230 | # that process (while maintaining the separation between arguments), and wrap 231 | # the whole thing up as a single "set" statement. 232 | # 233 | # This will of course break if any of these variables contains a newline or 234 | # an unmatched quote. 235 | # 236 | 237 | eval "set -- $( 238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 239 | xargs -n1 | 240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 241 | tr '\n' ' ' 242 | )" '"$@"' 243 | 244 | exec "$JAVACMD" "$@" 245 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /example/android/libfacesdk/build.gradle: -------------------------------------------------------------------------------- 1 | configurations.maybeCreate("default") 2 | artifacts.add("default", file('facesdk.aar')) -------------------------------------------------------------------------------- /example/android/libfacesdk/facesdk.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/android/libfacesdk/facesdk.aar -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'FaceRecognitionSdkExample' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | include ':libfacesdk' 5 | includeBuild('../node_modules/@react-native/gradle-plugin') 6 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FaceRecognitionSdkExample", 3 | "displayName": "FaceRecognitionSdkExample" 4 | } 5 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | presets: ['module:metro-react-native-babel-preset'], 6 | plugins: [ 7 | [ 8 | 'module-resolver', 9 | { 10 | extensions: ['.tsx', '.ts', '.js', '.json'], 11 | alias: { 12 | [pak.name]: path.join(__dirname, '..', pak.source), 13 | }, 14 | }, 15 | ], 16 | ], 17 | }; 18 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | # This `.xcode.env` file is versioned and is used to source the environment 2 | # used when running script phases inside Xcode. 3 | # To customize your local environment, you can create an `.xcode.env.local` 4 | # file that is not versioned. 5 | 6 | # NODE_BINARY variable contains the PATH to the node executable. 7 | # 8 | # Customize the NODE_BINARY variable here. 9 | # For example, to use nvm with brew, add the following line 10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use 11 | export NODE_BINARY=$(command -v node) 12 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExample.xcodeproj/xcshareddata/xcschemes/FaceRecognitionSdkExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : RCTAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExample/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | 5 | @implementation AppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 8 | { 9 | self.moduleName = @"FaceRecognitionSdkExample"; 10 | // You can add your custom initial props in the dictionary below. 11 | // They will be passed down to the ViewController used by React Native. 12 | self.initialProps = @{}; 13 | 14 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 15 | } 16 | 17 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 18 | { 19 | #if DEBUG 20 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 21 | #else 22 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 23 | #endif 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | FaceRecognitionSdkExample 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(MARKETING_VERSION) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(CURRENT_PROJECT_VERSION) 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | NSExceptionDomains 30 | 31 | localhost 32 | 33 | NSExceptionAllowsInsecureHTTPLoads 34 | 35 | 36 | 37 | 38 | NSLocationWhenInUseUsageDescription 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UIViewControllerBasedStatusBarAppearance 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExample/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExample/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExampleTests/FaceRecognitionSdkExampleTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface FaceRecognitionSdkExampleTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation FaceRecognitionSdkExampleTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction( 38 | ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 39 | if (level >= RCTLogLevelError) { 40 | redboxError = message; 41 | } 42 | }); 43 | #endif 44 | 45 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 46 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 47 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 48 | 49 | foundElement = [self findSubviewInView:vc.view 50 | matching:^BOOL(UIView *view) { 51 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 52 | return YES; 53 | } 54 | return NO; 55 | }]; 56 | } 57 | 58 | #ifdef DEBUG 59 | RCTSetLogFunction(RCTDefaultLogFunction); 60 | #endif 61 | 62 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 63 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /example/ios/FaceRecognitionSdkExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ios/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // FaceRecognitionSdkExample 4 | // 5 | 6 | import Foundation 7 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Resolve react_native_pods.rb with node to allow for hoisting 2 | # require Pod::Executable.execute_command('node', ['-p', 3 | # 'require.resolve( 4 | # "react-native/scripts/react_native_pods.rb", 5 | # {paths: [process.argv[1]]}, 6 | # )', __dir__]).strip 7 | 8 | def node_require(script) 9 | # Resolve script with node to allow for hoisting 10 | require Pod::Executable.execute_command('node', ['-p', 11 | "require.resolve( 12 | '#{script}', 13 | {paths: [process.argv[1]]}, 14 | )", __dir__]).strip 15 | end 16 | 17 | node_require('react-native/scripts/react_native_pods.rb') 18 | node_require('react-native-permissions/scripts/setup.rb') 19 | 20 | platform :ios, min_ios_version_supported 21 | prepare_react_native_project! 22 | 23 | setup_permissions([ 24 | 'Camera' 25 | ]) 26 | 27 | # If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set. 28 | # because `react-native-flipper` depends on (FlipperKit,...) that will be excluded 29 | # 30 | # To fix this you can also exclude `react-native-flipper` using a `react-native.config.js` 31 | # ```js 32 | # module.exports = { 33 | # dependencies: { 34 | # ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}), 35 | # ``` 36 | flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled 37 | 38 | linkage = ENV['USE_FRAMEWORKS'] 39 | if linkage != nil 40 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green 41 | use_frameworks! :linkage => linkage.to_sym 42 | end 43 | 44 | target 'FaceRecognitionSdkExample' do 45 | config = use_native_modules! 46 | 47 | # Flags change depending on the env values. 48 | flags = get_default_flags() 49 | 50 | use_react_native!( 51 | :path => config[:reactNativePath], 52 | # Hermes is now enabled by default. Disable by setting this flag to false. 53 | :hermes_enabled => flags[:hermes_enabled], 54 | :fabric_enabled => flags[:fabric_enabled], 55 | # Enables Flipper. 56 | # 57 | # Note that if you have use_frameworks! enabled, Flipper will not work and 58 | # you should disable the next line. 59 | :flipper_configuration => flipper_config, 60 | # An absolute path to your application root. 61 | :app_path => "#{Pod::Config.instance.installation_root}/.." 62 | ) 63 | 64 | target 'FaceRecognitionSdkExampleTests' do 65 | inherit! :complete 66 | # Pods for testing 67 | end 68 | 69 | post_install do |installer| 70 | # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 71 | react_native_post_install( 72 | installer, 73 | config[:reactNativePath], 74 | :mac_catalyst_enabled => false 75 | ) 76 | __apply_Xcode_12_5_M1_post_install_workaround(installer) 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /example/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'react-native', 3 | }; 4 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); 2 | const path = require('path'); 3 | const escape = require('escape-string-regexp'); 4 | const exclusionList = require('metro-config/src/defaults/exclusionList'); 5 | const pak = require('../package.json'); 6 | 7 | const root = path.resolve(__dirname, '..'); 8 | const modules = Object.keys({ ...pak.peerDependencies }); 9 | 10 | /** 11 | * Metro configuration 12 | * https://facebook.github.io/metro/docs/configuration 13 | * 14 | * @type {import('metro-config').MetroConfig} 15 | */ 16 | const config = { 17 | watchFolders: [root], 18 | 19 | // We need to make sure that only one version is loaded for peerDependencies 20 | // So we block them at the root, and alias them to the versions in example's node_modules 21 | resolver: { 22 | blacklistRE: exclusionList( 23 | modules.map( 24 | (m) => 25 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 26 | ) 27 | ), 28 | 29 | extraNodeModules: modules.reduce((acc, name) => { 30 | acc[name] = path.join(__dirname, 'node_modules', name); 31 | return acc; 32 | }, {}), 33 | }, 34 | 35 | transformer: { 36 | getTransformOptions: async () => ({ 37 | transform: { 38 | experimentalImportSupport: false, 39 | inlineRequires: true, 40 | }, 41 | }), 42 | }, 43 | }; 44 | 45 | module.exports = mergeConfig(getDefaultConfig(__dirname), config); 46 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FaceRecognitionSdkExample", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "start": "react-native start", 9 | "pods": "pod-install --quiet" 10 | }, 11 | "dependencies": { 12 | "@react-navigation/native": "^6.1.7", 13 | "@react-navigation/native-stack": "^6.9.13", 14 | "react": "18.2.0", 15 | "react-native": "0.72.1", 16 | "react-native-image-picker": "^5.6.0", 17 | "react-native-modal": "^13.0.1", 18 | "react-native-paper": "^5.9.1", 19 | "react-native-picker-select": "^8.0.4", 20 | "react-native-safe-area-context": "^4.7.0", 21 | "react-native-screens": "^3.22.1", 22 | "react-native-settings-list": "^1.8.0", 23 | "react-native-sqlite-storage": "^6.0.1" 24 | }, 25 | "devDependencies": { 26 | "@babel/core": "^7.20.0", 27 | "@babel/preset-env": "^7.20.0", 28 | "@babel/runtime": "^7.20.0", 29 | "@react-native/eslint-config": "^0.72.2", 30 | "@react-native/metro-config": "^0.72.7", 31 | "@types/metro-config": "^0.76.3", 32 | "babel-plugin-module-resolver": "^5.0.0", 33 | "metro-react-native-babel-preset": "0.76.5", 34 | "react-native-permissions": "^4.1.5" 35 | }, 36 | "engines": { 37 | "node": ">=16" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/react-native.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | dependencies: { 6 | [pak.name]: { 7 | root: path.join(__dirname, '..'), 8 | }, 9 | }, 10 | }; 11 | -------------------------------------------------------------------------------- /example/src/AboutPage.tsx: -------------------------------------------------------------------------------- 1 | // AboutPage.js 2 | import React from 'react'; 3 | import { View, Text, StyleSheet, Image, TouchableOpacity } from 'react-native'; 4 | 5 | const AboutPage = ({ navigation }) => { 6 | const goBackToHome = () => { 7 | navigation.goBack(); 8 | }; 9 | 10 | return ( 11 | 12 | 13 | 14 | 16 | 19 | 20 | 21 | KBY-AI Technology 22 | 23 | 24 | 25 | 26 | We are a leading provider of SDKs for advanced biometric authentication technology, including face recognition, liveness detection, and ID card recognition. 27 | 28 | 29 | In addition to biometric authentication solutions, we provide software development services for computer vision and mobile applications. 30 | 31 | 32 | With our team's extensive knowledge and proficiency in these areas, we can deliver exceptional results to our clients. 33 | 34 | 35 | If you're interested in learning more about how we can help you, please don't hesitate to get in touch with us today. 36 | 37 | Please contact us: 38 | 39 | 40 | Email: contact@kby-ai.com 41 | 42 | 43 | 44 | Skype: live:.cid.66e2522354b1049b 45 | 46 | 47 | 48 | Telegram: kbyai 49 | 50 | 51 | 52 | WhatsApp: +19092802609 53 | 54 | 55 | 56 | Github: https://github.com/kby-ai 57 | 58 | 59 | 60 | ); 61 | }; 62 | 63 | const styles = StyleSheet.create({ 64 | container: { 65 | flex: 1, 66 | backgroundColor: '#1C1B1F' 67 | }, 68 | appBar: { 69 | height: 60, 70 | backgroundColor: '#1C1B1F', 71 | justifyContent: 'center', 72 | alignItems: 'center', 73 | }, 74 | title: { 75 | marginLeft: 30, 76 | flex: 1, 77 | fontSize: 18, 78 | color: '#FFFFFF', 79 | }, 80 | body: { 81 | flex: 1, 82 | margin: 16, 83 | }, 84 | description: { 85 | marginBottom: 8, 86 | fontSize: 14, 87 | color: '#FFF', 88 | }, 89 | contact: { 90 | marginBottom: 8, 91 | fontSize: 14, 92 | fontWeight: 'bold', 93 | color: '#FFF', 94 | }, 95 | contactRow: { 96 | flexDirection: 'row', 97 | alignItems: 'center', 98 | marginBottom: 4, 99 | }, 100 | icon: { 101 | width: 24, 102 | height: 24, 103 | marginRight: 4, 104 | tintColor: '#FFFFFF', 105 | }, 106 | }); 107 | 108 | export default AboutPage; -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | import { StatusBar, StyleSheet, View } from 'react-native'; 4 | import { NavigationContainer } from '@react-navigation/native'; 5 | import { createNativeStackNavigator } from '@react-navigation/native-stack'; 6 | import { FaceRecognitionSdkView } from 'face-recognition-sdk'; 7 | import { IconButton } from 'react-native-paper'; 8 | import AboutPage from './AboutPage'; 9 | import MainPage from './MainPage'; 10 | import FaceRecognitionPage from './FaceRecognitionPage'; 11 | import SettingsPage from './SettingsPage'; 12 | import ResultPage from './ResultPage'; 13 | 14 | const Stack = createNativeStackNavigator(); 15 | 16 | export default function App() { 17 | const backButton = navigation => ( 18 | navigation.goBack()} 21 | /> 22 | ); 23 | 24 | return ( 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | ); 35 | // 36 | // 37 | // 38 | // ); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /example/src/FaceRecognitionPage.tsx: -------------------------------------------------------------------------------- 1 | // FaceRecognitionPage.js 2 | import React, { useEffect, useState, useRef } from 'react'; 3 | import { View, Text, StyleSheet, TouchableOpacity, Image, } from 'react-native'; 4 | import { FaceRecognitionSdkView, FaceSDKModule } from 'face-recognition-sdk'; 5 | import { check, request, PERMISSIONS, RESULTS } from 'react-native-permissions' 6 | import { NativeEventEmitter } from 'react-native'; 7 | import ResultPage from './ResultPage'; 8 | import { AppState, BackHandler } from 'react-native'; 9 | import { useIsFocused } from '@react-navigation/native'; 10 | 11 | const cameraPermission = Platform.select({ 12 | ios: PERMISSIONS.IOS.CAMERA, 13 | android: PERMISSIONS.ANDROID.CAMERA, 14 | }) 15 | 16 | const FaceRecognitionView = () => { 17 | const isFocused = useIsFocused(); 18 | const sdkViewRef = useRef(null); 19 | 20 | useEffect(() => { 21 | if (isFocused) { 22 | startCamera(); 23 | } else { 24 | stopCamera(); 25 | } 26 | 27 | return () => { 28 | if(isFocused) { 29 | stopCamera(); 30 | } 31 | }; 32 | }, [isFocused]); 33 | 34 | const startCamera = async () => { 35 | await FaceSDKModule.startCamera(); 36 | }; 37 | 38 | const stopCamera = async () => { 39 | await FaceSDKModule.stopCamera(); 40 | }; 41 | 42 | const handleViewLayout = () => { 43 | if (isFocused && sdkViewRef.current) { 44 | startCamera(); 45 | } else { 46 | stopCamera(); 47 | } 48 | }; 49 | 50 | return ( 51 | 52 | 53 | 59 | 60 | 61 | ); 62 | }; 63 | 64 | const FaceRecognitionPage = ({ navigation, route }) => { 65 | 66 | const { persons } = route.params; 67 | const [faces, setFaces] = useState([]); 68 | const [cameraShow, setCameraShow] = useState(false); 69 | const isFocused = useIsFocused(); 70 | 71 | var recognized = false; 72 | 73 | const goBackToHome = () => { 74 | navigation.goBack(); 75 | }; 76 | 77 | useEffect(() => { 78 | checkPermission(); 79 | 80 | const eventEmitter = new NativeEventEmitter(FaceSDKModule); 81 | let eventListener = eventEmitter.addListener('onFaceDetected', (event) => { 82 | setFaces(event); 83 | if (recognized == false) { 84 | identifyPerson(event); 85 | } 86 | }); 87 | 88 | if(isFocused) 89 | recognized = false; 90 | else 91 | recognized = true; 92 | 93 | return () => { 94 | eventListener.remove(); 95 | }; 96 | 97 | }, [isFocused]); 98 | 99 | const identifyPerson = async (curFaces) => { 100 | let maxSimilarity = -1; 101 | let maxSimilarityName = ""; 102 | let maxLiveness = -1; 103 | let maxYaw = -1; 104 | let maxRoll = -1; 105 | let maxPitch = -1; 106 | let enrolledFace, identifiedFace; 107 | 108 | try { 109 | if (curFaces.length > 0) { 110 | const face = curFaces[0]; 111 | 112 | for (const person of persons) { 113 | try { 114 | const similarity = await FaceSDKModule.similarityCalculation( 115 | face.templates, 116 | person.templates 117 | ); 118 | 119 | console.log('similarity', similarity); 120 | 121 | if (maxSimilarity < similarity) { 122 | maxSimilarity = similarity; 123 | maxSimilarityName = person.name; 124 | maxLiveness = face.liveness; 125 | maxYaw = face.yaw; 126 | maxRoll = face.roll; 127 | maxPitch = face.pitch; 128 | identifiedFace = face.faceJpg; 129 | enrolledFace = person.faceJpg; 130 | } 131 | } catch (error) { 132 | console.error('Error calculating similarity:', error); 133 | } 134 | } 135 | } 136 | } catch (error) { 137 | console.error('Error setting activation:', error); 138 | } 139 | 140 | if (maxSimilarity > 0.8 && maxLiveness > 0.7) { 141 | recognized = true; 142 | 143 | navigation.replace('Result', { enrolledFace, identifiedFace, maxSimilarityName, maxSimilarity, maxLiveness, maxYaw, maxRoll, maxPitch }); 144 | 145 | setFaces([]); 146 | } 147 | }; 148 | 149 | const checkPermission = async () => { 150 | const permissionStatus = await check(cameraPermission); 151 | handlePermissionStatus(permissionStatus); 152 | }; 153 | 154 | const requestPermission = async () => { 155 | const permissionStatus = await request(cameraPermission); 156 | handlePermissionStatus(permissionStatus); 157 | }; 158 | 159 | const handlePermissionStatus = (status) => { 160 | switch (status) { 161 | case RESULTS.UNAVAILABLE: 162 | break; 163 | case RESULTS.DENIED: 164 | requestPermission(); 165 | break; 166 | case RESULTS.GRANTED: 167 | setCameraShow(true); 168 | break; 169 | case RESULTS.BLOCKED: 170 | break; 171 | } 172 | }; 173 | 174 | return ( 175 | 176 | 177 | 178 | 180 | 183 | 184 | 185 | Face Recognition 186 | 187 | 188 | 189 | {cameraShow ? ( 190 | 191 | ) : ( 192 | 193 | Camera permission issue. 194 | 195 | )} 196 | 207 | 208 | 209 | 210 | 211 | ); 212 | }; 213 | 214 | const FacePainter = ({ faces, livenessThreshold }) => { 215 | const [viewDimensions, setViewDimensions] = useState({ width: 0, height: 0 }); 216 | 217 | const onLayout = (event) => { 218 | const { width, height } = event.nativeEvent.layout; 219 | setViewDimensions({ width, height }); 220 | }; 221 | 222 | const renderFaces = () => { 223 | return faces.map((face, index) => { 224 | const { x1, y1, x2, y2, frameWidth, frameHeight, liveness } = face; 225 | const xScale = frameWidth / viewDimensions.width; 226 | const yScale = frameHeight / viewDimensions.height; 227 | const isRealFace = liveness >= livenessThreshold; 228 | 229 | const rectStyle = isRealFace ? styles.realFaceRect : styles.spoofFaceRect; 230 | const textStyle = isRealFace ? styles.realFaceText : styles.spoofFaceText; 231 | const title = isRealFace ? `Real ${liveness}` : `Spoof ${liveness}`; 232 | 233 | return ( 234 | 235 | {title} 236 | 248 | 249 | ); 250 | }); 251 | }; 252 | 253 | return ( 254 | 255 | {renderFaces()} 256 | 257 | ); 258 | }; 259 | 260 | const styles = StyleSheet.create({ 261 | container: { 262 | flex: 1, 263 | backgroundColor: '#1C1B1F' 264 | }, 265 | appBar: { 266 | height: 70, 267 | backgroundColor: '#1C1B1F', 268 | justifyContent: 'center', 269 | alignItems: 'center', 270 | }, 271 | title: { 272 | marginLeft: 30, 273 | flex: 1, 274 | fontSize: 18, 275 | color: '#FFFFFF', 276 | }, 277 | body: { 278 | flex: 1, 279 | }, 280 | description: { 281 | marginBottom: 8, 282 | fontSize: 14, 283 | color: '#FFF', 284 | }, 285 | contact: { 286 | marginBottom: 8, 287 | fontSize: 14, 288 | fontWeight: 'bold', 289 | color: '#FFF', 290 | }, 291 | contactRow: { 292 | flexDirection: 'row', 293 | alignItems: 'center', 294 | marginBottom: 4, 295 | }, 296 | icon: { 297 | width: 24, 298 | height: 24, 299 | marginRight: 4, 300 | tintColor: '#FFFFFF', 301 | }, 302 | box: { 303 | flex: 1, 304 | marginVertical: 0, 305 | }, 306 | containerFace: { 307 | ...StyleSheet.absoluteFillObject, 308 | justifyContent: 'center', 309 | alignItems: 'center', 310 | }, 311 | faceRect: { 312 | position: 'absolute', 313 | borderWidth: 3, 314 | }, 315 | realFaceRect: { 316 | borderColor: '#00FF00', 317 | }, 318 | spoofFaceRect: { 319 | borderColor: '#FF0000', 320 | }, 321 | faceText: { 322 | position: 'absolute', 323 | fontSize: 20, 324 | }, 325 | realFaceText: { 326 | color: '#00FF00', 327 | }, 328 | spoofFaceText: { 329 | color: '#FF0000', 330 | }, 331 | }); 332 | 333 | export default FaceRecognitionPage; -------------------------------------------------------------------------------- /example/src/Person.tsx: -------------------------------------------------------------------------------- 1 | class Person { 2 | constructor(name, faceJpg, templates) { 3 | this.name = name; 4 | this.faceJpg = faceJpg; 5 | this.templates = templates; 6 | } 7 | 8 | static fromMap(data) { 9 | return new Person(data.name, data.faceJpg, data.templates); 10 | } 11 | 12 | toMap() { 13 | return { 14 | name: this.name, 15 | faceJpg: this.faceJpg, 16 | templates: this.templates, 17 | }; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /example/src/PersonView.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, Text, StyleSheet, Image, TouchableOpacity, FlatList } from 'react-native'; 3 | 4 | const PersonView = ({ personList, deletePerson }) => { 5 | const renderItem = ({ item, index }) => { 6 | return ( 7 | 11 | 12 | 16 | 17 | 18 | {item.name} 19 | 20 | 21 | deletePerson(index)}> 22 | 26 | 27 | 28 | 29 | ); 30 | }; 31 | 32 | return ( 33 | index.toString()} 37 | /> 38 | ); 39 | }; 40 | 41 | const styles = StyleSheet.create({ 42 | buttonIcon: { 43 | width: 24, 44 | height: 24, 45 | marginRight: 4, 46 | tintColor: '#FFFFFF', 47 | }, 48 | }); 49 | 50 | export default PersonView; 51 | -------------------------------------------------------------------------------- /example/src/ResultPage.tsx: -------------------------------------------------------------------------------- 1 | // ResultPage.js 2 | import React from 'react'; 3 | import { View, Text, StyleSheet, Image, TouchableOpacity } from 'react-native'; 4 | 5 | const ResultPage = ({ navigation, route }) => { 6 | 7 | const { enrolledFace, identifiedFace, maxSimilarityName, maxSimilarity, maxLiveness, maxYaw, maxRoll, maxPitch } = route.params; 8 | 9 | const goBackToHome = () => { 10 | navigation.goBack(); 11 | }; 12 | 13 | return ( 14 | 15 | 16 | 17 | 19 | 22 | 23 | 24 | Identify Result 25 | 26 | 27 | 28 | 29 | 30 | 31 | {enrolledFace ? ( 32 | 33 | 34 | Enrolled 35 | 36 | ) : ( 37 | 38 | )} 39 | {identifiedFace ? ( 40 | 41 | 42 | Identified 43 | 44 | ) : ( 45 | 46 | )} 47 | 48 | 49 | 50 | Identified: {maxSimilarityName} 51 | 52 | 53 | Similarity: {maxSimilarity} 54 | 55 | 56 | Liveness score: {maxLiveness} 57 | 58 | 59 | Yaw: {maxYaw} 60 | 61 | 62 | Roll: {maxRoll} 63 | 64 | 65 | Pitch: {maxPitch} 66 | 67 | 68 | 69 | 70 | ); 71 | }; 72 | 73 | const styles = StyleSheet.create({ 74 | container: { 75 | flex: 1, 76 | backgroundColor: '#1C1B1F' 77 | }, 78 | appBar: { 79 | height: 60, 80 | backgroundColor: '#1C1B1F', 81 | justifyContent: 'center', 82 | alignItems: 'center', 83 | }, 84 | title: { 85 | marginLeft: 30, 86 | flex: 1, 87 | fontSize: 18, 88 | color: '#FFFFFF', 89 | }, 90 | body: { 91 | flex: 1, 92 | margin: 16, 93 | }, 94 | description: { 95 | marginBottom: 8, 96 | fontSize: 14, 97 | color: '#FFF', 98 | }, 99 | contact: { 100 | marginBottom: 8, 101 | fontSize: 14, 102 | fontWeight: 'bold', 103 | color: '#FFF', 104 | }, 105 | contactRow: { 106 | flexDirection: 'row', 107 | alignItems: 'center', 108 | marginBottom: 4, 109 | }, 110 | icon: { 111 | width: 24, 112 | height: 24, 113 | marginRight: 4, 114 | tintColor: '#FFFFFF', 115 | }, 116 | }); 117 | 118 | export default ResultPage; -------------------------------------------------------------------------------- /example/src/SettingsPage.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | import { View, Text, StyleSheet, Image, Switch, TextInput, Button, Alert, TouchableOpacity } from 'react-native'; 3 | import SettingsList from 'react-native-settings-list'; 4 | import RNPickerSelect from 'react-native-picker-select'; 5 | import Modal from 'react-native-modal'; 6 | // import { Picker } from '@react-native-picker/picker'; 7 | // import AsyncStorage from '@react-native-async-storage/async-storage'; 8 | 9 | 10 | const SettingsPage = ({ navigation }) => { 11 | const [cameraLens, setCameraLens] = useState(false); 12 | const [livenessThreshold, setLivenessThreshold] = useState('0.7'); 13 | const [identifyThreshold, setIdentifyThreshold] = useState('0.8'); 14 | const [selectedLivenessLevel, setSelectedLivenessLevel] = useState(0); 15 | const [frontCameraValue, setFrontCameraValue] = useState(true); 16 | 17 | const livenessController = React.createRef(); 18 | const identifyController = React.createRef(); 19 | 20 | const livenessLevelNames = ['Best Accuracy', 'Light Weight']; 21 | 22 | const goBackToHome = () => { 23 | navigation.goBack(); 24 | }; 25 | 26 | 27 | useEffect(() => { 28 | loadSettings(); 29 | }, []); 30 | 31 | const loadSettings = async () => { 32 | // try { 33 | // const cameraLensValue = await AsyncStorage.getItem('camera_lens'); 34 | // const livenessLevelValue = await AsyncStorage.getItem('liveness_level'); 35 | // const livenessThresholdValue = await AsyncStorage.getItem('liveness_threshold'); 36 | // const identifyThresholdValue = await AsyncStorage.getItem('identify_threshold'); 37 | 38 | // setCameraLens(cameraLensValue === '1'); 39 | // setLivenessThreshold(livenessThresholdValue || '0.7'); 40 | // setIdentifyThreshold(identifyThresholdValue || '0.8'); 41 | // setSelectedLivenessLevel(livenessLevelValue ? parseInt(livenessLevelValue) : 0); 42 | // } catch (error) { 43 | // console.log('Error loading settings:', error); 44 | // } 45 | }; 46 | 47 | const restoreSettings = async () => { 48 | // try { 49 | // await AsyncStorage.setItem('first_write', '0'); 50 | // await initSettings(); 51 | // await loadSettings(); 52 | 53 | // Alert.alert('Default settings restored!'); 54 | // } catch (error) { 55 | // console.log('Error restoring settings:', error); 56 | // } 57 | }; 58 | 59 | const deleteAllPerson = async () => { 60 | 61 | }; 62 | 63 | const initSettings = async () => { 64 | // try { 65 | // const firstWrite = await AsyncStorage.getItem('first_write'); 66 | // if (!firstWrite) { 67 | // await AsyncStorage.setItem('first_write', '1'); 68 | // await AsyncStorage.setItem('camera_lens', '1'); 69 | // await AsyncStorage.setItem('liveness_level', '0'); 70 | // await AsyncStorage.setItem('liveness_threshold', '0.7'); 71 | // await AsyncStorage.setItem('identify_threshold', '0.8'); 72 | // } 73 | // } catch (error) { 74 | // console.log('Error initializing settings:', error); 75 | // } 76 | }; 77 | 78 | // const updateLivenessLevel = async (value) => { 79 | // // try { 80 | // // await AsyncStorage.setItem('liveness_level', value.toString()); 81 | // // } catch (error) { 82 | // // console.log('Error updating liveness level:', error); 83 | // // } 84 | // }; 85 | 86 | const updateCameraLens = async (value) => { 87 | // try { 88 | // await AsyncStorage.setItem('camera_lens', value ? '1' : '0'); 89 | // setCameraLens(value); 90 | // } catch (error) { 91 | // console.log('Error updating camera lens:', error); 92 | // } 93 | }; 94 | 95 | const updateLivenessThreshold = async () => { 96 | 97 | // try { 98 | // const doubleValue = parseFloat(livenessController.current.value); 99 | // if (!isNaN(doubleValue) && doubleValue >= 0 && doubleValue < 1.0) { 100 | // await AsyncStorage.setItem('liveness_threshold', livenessController.current.value); 101 | // setLivenessThreshold(livenessController.current.value); 102 | // } 103 | // } catch (error) { 104 | // console.log('Error updating liveness threshold:', error); 105 | // } 106 | }; 107 | 108 | const updateIdentifyThreshold = async () => { 109 | // try { 110 | // const doubleValue = parseFloat(identifyController.current.value); 111 | // if (!isNaN(doubleValue) && doubleValue >= 0 && doubleValue < 1.0) { 112 | // await AsyncStorage.setItem('identify_threshold', identifyController.current.value); 113 | // setIdentifyThreshold(identifyController.current.value); 114 | // } 115 | // } catch (error) { 116 | // console.log('Error updating identify threshold:', error); 117 | // } 118 | }; 119 | 120 | const showLivenessThresholdPicker = () => { 121 | Alert.prompt( 122 | 'Liveness thresholds', 123 | '', 124 | (text) => { 125 | setLivenessThreshold(text); 126 | console.log('You entered: ' + text); 127 | }, 128 | undefined, 129 | livenessThreshold 130 | ); 131 | }; 132 | 133 | const showLivenessLevelPicker = () => { 134 | 135 | }; 136 | 137 | const onFrontChanged = (value) => { 138 | setFrontCameraValue(value) 139 | } 140 | 141 | return ( 142 | 143 | 144 | 145 | 147 | 150 | 151 | 152 | Settings 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 163 | 164 | 165 | } 166 | title='Front' 167 | hasNavArrow={false} 168 | hasSwitch={true} 169 | switchState={frontCameraValue} 170 | switchOnValueChange={onFrontChanged} 171 | /> 172 | 173 | 176 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | ); 189 | }; 190 | 191 | const styles = StyleSheet.create({ 192 | container: { 193 | flex: 1, 194 | backgroundColor: '#1C1B1F' 195 | }, 196 | appBar: { 197 | height: 60, 198 | backgroundColor: '#1C1B1F', 199 | justifyContent: 'center', 200 | alignItems: 'center', 201 | }, 202 | title: { 203 | marginLeft: 30, 204 | flex: 1, 205 | fontSize: 18, 206 | color: '#FFFFFF', 207 | }, 208 | body: { 209 | flex: 1, 210 | margin: 16, 211 | }, 212 | description: { 213 | marginBottom: 8, 214 | fontSize: 14, 215 | color: '#FFF', 216 | }, 217 | contact: { 218 | marginBottom: 8, 219 | fontSize: 14, 220 | fontWeight: 'bold', 221 | color: '#FFF', 222 | }, 223 | contactRow: { 224 | flexDirection: 'row', 225 | alignItems: 'center', 226 | marginBottom: 4, 227 | }, 228 | icon: { 229 | width: 24, 230 | height: 24, 231 | marginRight: 4, 232 | tintColor: '#FFFFFF', 233 | }, 234 | containerAlert: { 235 | flex: 1, 236 | alignItems: 'center', 237 | justifyContent: 'center', 238 | }, 239 | label: { 240 | fontSize: 16, 241 | marginBottom: 10, 242 | }, 243 | button: { 244 | paddingVertical: 10, 245 | paddingHorizontal: 20, 246 | backgroundColor: 'blue', 247 | color: 'white', 248 | fontSize: 16, 249 | }, 250 | pickerContainer: { 251 | backgroundColor: 'white', 252 | padding: 20, 253 | borderRadius: 8, 254 | justifyContent: 'center', 255 | alignItems: 'center', 256 | }, 257 | settingsTile: { 258 | flexDirection: 'row', 259 | alignItems: 'center', 260 | marginBottom: 10, 261 | }, 262 | value: { 263 | marginLeft: 'auto', 264 | color: 'blue', 265 | }, 266 | }); 267 | 268 | const pickerStyles = StyleSheet.create({ 269 | inputIOS: { 270 | fontSize: 16, 271 | paddingVertical: 12, 272 | paddingHorizontal: 10, 273 | borderWidth: 1, 274 | borderColor: 'gray', 275 | borderRadius: 4, 276 | color: 'black', 277 | width: 200, 278 | }, 279 | inputAndroid: { 280 | fontSize: 16, 281 | paddingHorizontal: 10, 282 | paddingVertical: 8, 283 | borderWidth: 1, 284 | borderColor: 'gray', 285 | borderRadius: 8, 286 | color: 'black', 287 | width: 200, 288 | }, 289 | }); 290 | 291 | export default SettingsPage; 292 | -------------------------------------------------------------------------------- /example/src/assets/ic_arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_arrow_left.png -------------------------------------------------------------------------------- /example/src/assets/ic_camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_camera.png -------------------------------------------------------------------------------- /example/src/assets/ic_clear_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_clear_all.png -------------------------------------------------------------------------------- /example/src/assets/ic_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_delete.png -------------------------------------------------------------------------------- /example/src/assets/ic_email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_email.png -------------------------------------------------------------------------------- /example/src/assets/ic_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_github.png -------------------------------------------------------------------------------- /example/src/assets/ic_kby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_kby.png -------------------------------------------------------------------------------- /example/src/assets/ic_liveness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_liveness.png -------------------------------------------------------------------------------- /example/src/assets/ic_restore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_restore.png -------------------------------------------------------------------------------- /example/src/assets/ic_skype.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_skype.png -------------------------------------------------------------------------------- /example/src/assets/ic_sparkles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_sparkles.png -------------------------------------------------------------------------------- /example/src/assets/ic_telegram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_telegram.png -------------------------------------------------------------------------------- /example/src/assets/ic_whatsapp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/ic_whatsapp.png -------------------------------------------------------------------------------- /example/src/assets/info_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/info_icon.png -------------------------------------------------------------------------------- /example/src/assets/person_add_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/person_add_icon.png -------------------------------------------------------------------------------- /example/src/assets/person_search_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/person_search_icon.png -------------------------------------------------------------------------------- /example/src/assets/settings_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/example/src/assets/settings_icon.png -------------------------------------------------------------------------------- /face-recognition-sdk.podspec: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, "package.json"))) 4 | folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' 5 | 6 | Pod::Spec.new do |s| 7 | s.name = "face-recognition-sdk" 8 | s.version = package["version"] 9 | s.summary = package["description"] 10 | s.homepage = package["homepage"] 11 | s.license = package["license"] 12 | s.authors = package["author"] 13 | 14 | s.platforms = { :ios => "11.0" } 15 | s.source = { :git => "https://github.com/kby-ai/FaceRecognition-React-Native.git", :tag => "#{s.version}" } 16 | 17 | s.vendored_frameworks = "ios/**/facesdk.framework" 18 | 19 | s.source_files = "ios/**/*.{h,m,mm,swift}" 20 | 21 | # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0. 22 | # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79. 23 | if respond_to?(:install_modules_dependencies, true) 24 | install_modules_dependencies(s) 25 | else 26 | s.dependency "React-Core" 27 | 28 | # Don't install the dependencies when we run `pod install` in the old architecture. 29 | if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then 30 | s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" 31 | s.pod_target_xcconfig = { 32 | "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", 33 | "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", 34 | "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" 35 | } 36 | s.dependency "React-RCTFabric" 37 | s.dependency "React-Codegen" 38 | s.dependency "RCT-Folly" 39 | s.dependency "RCTRequired" 40 | s.dependency "RCTTypeSafety" 41 | s.dependency "ReactCommon/turbomodule/core" 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /ios/FaceRecognitionSdk-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "facesdk/facesdk.h" 3 | -------------------------------------------------------------------------------- /ios/FaceRecognitionSdk.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5E555C0D2413F4C50049A1A2 /* FaceRecognitionSdk.mm in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* FaceRecognitionSdk.mm */; }; 11 | F4FF95D7245B92E800C19C63 /* FaceRecognitionSdk.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* FaceRecognitionSdk.swift */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXCopyFilesBuildPhase section */ 15 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 16 | isa = PBXCopyFilesBuildPhase; 17 | buildActionMask = 2147483647; 18 | dstPath = "include/$(PRODUCT_NAME)"; 19 | dstSubfolderSpec = 16; 20 | files = ( 21 | ); 22 | runOnlyForDeploymentPostprocessing = 0; 23 | }; 24 | /* End PBXCopyFilesBuildPhase section */ 25 | 26 | /* Begin PBXFileReference section */ 27 | 134814201AA4EA6300B7C361 /* libFaceRecognitionSdk.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libFaceRecognitionSdk.a; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | B3E7B5891CC2AC0600A0062D /* FaceRecognitionSdk.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FaceRecognitionSdk.mm; sourceTree = ""; }; 29 | F4FF95D5245B92E700C19C63 /* FaceRecognitionSdk-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FaceRecognitionSdk-Bridging-Header.h"; sourceTree = ""; }; 30 | F4FF95D6245B92E800C19C63 /* FaceRecognitionSdk.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaceRecognitionSdk.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 134814211AA4EA7D00B7C361 /* Products */ = { 45 | isa = PBXGroup; 46 | children = ( 47 | 134814201AA4EA6300B7C361 /* libFaceRecognitionSdk.a */, 48 | ); 49 | name = Products; 50 | sourceTree = ""; 51 | }; 52 | 58B511D21A9E6C8500147676 = { 53 | isa = PBXGroup; 54 | children = ( 55 | F4FF95D6245B92E800C19C63 /* FaceRecognitionSdk.swift */, 56 | B3E7B5891CC2AC0600A0062D /* FaceRecognitionSdk.mm */, 57 | F4FF95D5245B92E700C19C63 /* FaceRecognitionSdk-Bridging-Header.h */, 58 | 134814211AA4EA7D00B7C361 /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | /* End PBXGroup section */ 63 | 64 | /* Begin PBXNativeTarget section */ 65 | 58B511DA1A9E6C8500147676 /* FaceRecognitionSdk */ = { 66 | isa = PBXNativeTarget; 67 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "FaceRecognitionSdk" */; 68 | buildPhases = ( 69 | 58B511D71A9E6C8500147676 /* Sources */, 70 | 58B511D81A9E6C8500147676 /* Frameworks */, 71 | 58B511D91A9E6C8500147676 /* CopyFiles */, 72 | ); 73 | buildRules = ( 74 | ); 75 | dependencies = ( 76 | ); 77 | name = FaceRecognitionSdk; 78 | productName = RCTDataManager; 79 | productReference = 134814201AA4EA6300B7C361 /* libFaceRecognitionSdk.a */; 80 | productType = "com.apple.product-type.library.static"; 81 | }; 82 | /* End PBXNativeTarget section */ 83 | 84 | /* Begin PBXProject section */ 85 | 58B511D31A9E6C8500147676 /* Project object */ = { 86 | isa = PBXProject; 87 | attributes = { 88 | LastUpgradeCheck = 0920; 89 | ORGANIZATIONNAME = Facebook; 90 | TargetAttributes = { 91 | 58B511DA1A9E6C8500147676 = { 92 | CreatedOnToolsVersion = 6.1.1; 93 | }; 94 | }; 95 | }; 96 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "FaceRecognitionSdk" */; 97 | compatibilityVersion = "Xcode 3.2"; 98 | developmentRegion = English; 99 | hasScannedForEncodings = 0; 100 | knownRegions = ( 101 | English, 102 | en, 103 | ); 104 | mainGroup = 58B511D21A9E6C8500147676; 105 | productRefGroup = 58B511D21A9E6C8500147676; 106 | projectDirPath = ""; 107 | projectRoot = ""; 108 | targets = ( 109 | 58B511DA1A9E6C8500147676 /* FaceRecognitionSdk */, 110 | ); 111 | }; 112 | /* End PBXProject section */ 113 | 114 | /* Begin PBXSourcesBuildPhase section */ 115 | 58B511D71A9E6C8500147676 /* Sources */ = { 116 | isa = PBXSourcesBuildPhase; 117 | buildActionMask = 2147483647; 118 | files = ( 119 | F4FF95D7245B92E800C19C63 /* FaceRecognitionSdk.swift in Sources */, 120 | B3E7B58A1CC2AC0600A0062D /* FaceRecognitionSdk.mm in Sources */, 121 | ); 122 | runOnlyForDeploymentPostprocessing = 0; 123 | }; 124 | /* End PBXSourcesBuildPhase section */ 125 | 126 | /* Begin XCBuildConfiguration section */ 127 | 58B511ED1A9E6C8500147676 /* Debug */ = { 128 | isa = XCBuildConfiguration; 129 | buildSettings = { 130 | ALWAYS_SEARCH_USER_PATHS = NO; 131 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 132 | CLANG_CXX_LIBRARY = "libc++"; 133 | CLANG_ENABLE_MODULES = YES; 134 | CLANG_ENABLE_OBJC_ARC = YES; 135 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 136 | CLANG_WARN_BOOL_CONVERSION = YES; 137 | CLANG_WARN_COMMA = YES; 138 | CLANG_WARN_CONSTANT_CONVERSION = YES; 139 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 140 | CLANG_WARN_EMPTY_BODY = YES; 141 | CLANG_WARN_ENUM_CONVERSION = YES; 142 | CLANG_WARN_INFINITE_RECURSION = YES; 143 | CLANG_WARN_INT_CONVERSION = YES; 144 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 145 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 146 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 147 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 148 | CLANG_WARN_STRICT_PROTOTYPES = YES; 149 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 150 | CLANG_WARN_UNREACHABLE_CODE = YES; 151 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 152 | COPY_PHASE_STRIP = NO; 153 | ENABLE_STRICT_OBJC_MSGSEND = YES; 154 | ENABLE_TESTABILITY = YES; 155 | "EXCLUDED_ARCHS[sdk=*]" = arm64; 156 | GCC_C_LANGUAGE_STANDARD = gnu99; 157 | GCC_DYNAMIC_NO_PIC = NO; 158 | GCC_NO_COMMON_BLOCKS = YES; 159 | GCC_OPTIMIZATION_LEVEL = 0; 160 | GCC_PREPROCESSOR_DEFINITIONS = ( 161 | "DEBUG=1", 162 | "$(inherited)", 163 | ); 164 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 165 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 166 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 167 | GCC_WARN_UNDECLARED_SELECTOR = YES; 168 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 169 | GCC_WARN_UNUSED_FUNCTION = YES; 170 | GCC_WARN_UNUSED_VARIABLE = YES; 171 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 172 | MTL_ENABLE_DEBUG_INFO = YES; 173 | ONLY_ACTIVE_ARCH = YES; 174 | SDKROOT = iphoneos; 175 | }; 176 | name = Debug; 177 | }; 178 | 58B511EE1A9E6C8500147676 /* Release */ = { 179 | isa = XCBuildConfiguration; 180 | buildSettings = { 181 | ALWAYS_SEARCH_USER_PATHS = NO; 182 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 183 | CLANG_CXX_LIBRARY = "libc++"; 184 | CLANG_ENABLE_MODULES = YES; 185 | CLANG_ENABLE_OBJC_ARC = YES; 186 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 187 | CLANG_WARN_BOOL_CONVERSION = YES; 188 | CLANG_WARN_COMMA = YES; 189 | CLANG_WARN_CONSTANT_CONVERSION = YES; 190 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 191 | CLANG_WARN_EMPTY_BODY = YES; 192 | CLANG_WARN_ENUM_CONVERSION = YES; 193 | CLANG_WARN_INFINITE_RECURSION = YES; 194 | CLANG_WARN_INT_CONVERSION = YES; 195 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 196 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 197 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 198 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 199 | CLANG_WARN_STRICT_PROTOTYPES = YES; 200 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 201 | CLANG_WARN_UNREACHABLE_CODE = YES; 202 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 203 | COPY_PHASE_STRIP = YES; 204 | ENABLE_NS_ASSERTIONS = NO; 205 | ENABLE_STRICT_OBJC_MSGSEND = YES; 206 | "EXCLUDED_ARCHS[sdk=*]" = arm64; 207 | GCC_C_LANGUAGE_STANDARD = gnu99; 208 | GCC_NO_COMMON_BLOCKS = YES; 209 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 210 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 211 | GCC_WARN_UNDECLARED_SELECTOR = YES; 212 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 213 | GCC_WARN_UNUSED_FUNCTION = YES; 214 | GCC_WARN_UNUSED_VARIABLE = YES; 215 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 216 | MTL_ENABLE_DEBUG_INFO = NO; 217 | SDKROOT = iphoneos; 218 | VALIDATE_PRODUCT = YES; 219 | }; 220 | name = Release; 221 | }; 222 | 58B511F01A9E6C8500147676 /* Debug */ = { 223 | isa = XCBuildConfiguration; 224 | buildSettings = { 225 | HEADER_SEARCH_PATHS = ( 226 | "$(inherited)", 227 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 228 | "$(SRCROOT)/../../../React/**", 229 | "$(SRCROOT)/../../react-native/React/**", 230 | ); 231 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 232 | OTHER_LDFLAGS = "-ObjC"; 233 | PRODUCT_NAME = FaceRecognitionSdk; 234 | SKIP_INSTALL = YES; 235 | SWIFT_OBJC_BRIDGING_HEADER = "FaceRecognitionSdk-Bridging-Header.h"; 236 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 237 | SWIFT_VERSION = 5.0; 238 | }; 239 | name = Debug; 240 | }; 241 | 58B511F11A9E6C8500147676 /* Release */ = { 242 | isa = XCBuildConfiguration; 243 | buildSettings = { 244 | HEADER_SEARCH_PATHS = ( 245 | "$(inherited)", 246 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 247 | "$(SRCROOT)/../../../React/**", 248 | "$(SRCROOT)/../../react-native/React/**", 249 | ); 250 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 251 | OTHER_LDFLAGS = "-ObjC"; 252 | PRODUCT_NAME = FaceRecognitionSdk; 253 | SKIP_INSTALL = YES; 254 | SWIFT_OBJC_BRIDGING_HEADER = "FaceRecognitionSdk-Bridging-Header.h"; 255 | SWIFT_VERSION = 5.0; 256 | }; 257 | name = Release; 258 | }; 259 | /* End XCBuildConfiguration section */ 260 | 261 | /* Begin XCConfigurationList section */ 262 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "FaceRecognitionSdk" */ = { 263 | isa = XCConfigurationList; 264 | buildConfigurations = ( 265 | 58B511ED1A9E6C8500147676 /* Debug */, 266 | 58B511EE1A9E6C8500147676 /* Release */, 267 | ); 268 | defaultConfigurationIsVisible = 0; 269 | defaultConfigurationName = Release; 270 | }; 271 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "FaceRecognitionSdk" */ = { 272 | isa = XCConfigurationList; 273 | buildConfigurations = ( 274 | 58B511F01A9E6C8500147676 /* Debug */, 275 | 58B511F11A9E6C8500147676 /* Release */, 276 | ); 277 | defaultConfigurationIsVisible = 0; 278 | defaultConfigurationName = Release; 279 | }; 280 | /* End XCConfigurationList section */ 281 | }; 282 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 283 | } 284 | -------------------------------------------------------------------------------- /ios/FaceRecognitionSdkViewManager.h: -------------------------------------------------------------------------------- 1 | #ifndef FACERECOGNITIONSDK_VIEW_MANAGER_H 2 | #define FACERECOGNITIONSDK_VIEW_MANAGER_H 3 | 4 | #import 5 | #import 6 | #import 7 | #import 8 | 9 | @class NativeCamera; 10 | 11 | @interface FaceRecognitionSdkViewManager : RCTViewManager 12 | 13 | +(void) startCamera; 14 | +(void) stopCamera; 15 | 16 | @property (nonatomic, strong) dispatch_queue_t sessionQueue; 17 | @property (nonatomic, strong) AVCaptureSession *session; 18 | @property (nonatomic, strong) AVCaptureDeviceInput *videoCaptureDeviceInput; 19 | @property (nonatomic, strong) id runtimeErrorHandlingObserver; 20 | @property (nonatomic, assign) NSInteger presetCamera; 21 | @property (nonatomic, strong) AVCaptureVideoPreviewLayer *previewLayer; 22 | @property (nonatomic, strong) NativeCamera *camera; 23 | 24 | 25 | - (void)initializeCaptureSessionInput:(NSString*)type; 26 | - (void)startSession; 27 | - (void)stopSession; 28 | 29 | @end 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /ios/FaceRecognitionSdkViewManager.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface RCT_EXTERN_MODULE(FaceRecognitionSdkViewManager, RCTViewManager) 4 | 5 | RCT_EXPORT_VIEW_PROPERTY(color, NSString) 6 | 7 | @end 8 | -------------------------------------------------------------------------------- /ios/FaceRecognitionSdkViewManager.swift: -------------------------------------------------------------------------------- 1 | // import AVFoundation 2 | 3 | // @objc(FaceRecognitionSdkViewManager) 4 | // class FaceRecognitionSdkViewManager: RCTViewManager { 5 | // @objc static var faceRecognitionView: FaceRecognitionSdkView? = nil 6 | 7 | // override func view() -> (FaceRecognitionSdkView) { 8 | // FaceRecognitionSdkViewManager.faceRecognitionView = FaceRecognitionSdkView() 9 | // return FaceRecognitionSdkViewManager.faceRecognitionView! 10 | // } 11 | 12 | // @objc override static func requiresMainQueueSetup() -> Bool { 13 | // return false 14 | // } 15 | 16 | // @objc static func startCamera() { 17 | // print("kkkk start camera") 18 | // } 19 | 20 | // @objc static func stopCamera() { 21 | // print("kkkk stop camera") 22 | // } 23 | // } 24 | 25 | // @objc(FaceRecognitionSdkView) 26 | // class FaceRecognitionSdkView : UIView { 27 | 28 | // // let frame: CGRect 29 | // let captureSession = AVCaptureSession() 30 | 31 | // var cameraLens: AVCaptureDevice.Position! 32 | // var cameraRunning: Bool = false 33 | // var cameraViewInited: Bool = false 34 | // var startTime: Double = 0 35 | 36 | // var cameraView : UIView! 37 | // let dummyLayout = CAShapeLayer() 38 | 39 | // override init(frame: CGRect) { 40 | // super.init(frame: frame) 41 | // print("Face recognition view initialized! frame: ", frame) 42 | 43 | // self.cameraView = UIView(frame: frame) 44 | // } 45 | 46 | // required init?(coder aDecoder: NSCoder) { 47 | // super.init(coder: aDecoder) 48 | 49 | // print("Face recognition view initialized 111!") 50 | // } 51 | 52 | // func startCamera() { 53 | 54 | // } 55 | 56 | // func stopCamera() { 57 | 58 | // } 59 | 60 | // // @objc var color: String = "" { 61 | // // didSet { 62 | // // self.backgroundColor = hexStringToUIColor(hexColor: color) 63 | // // } 64 | // // } 65 | 66 | // // func hexStringToUIColor(hexColor: String) -> UIColor { 67 | // // let stringScanner = Scanner(string: hexColor) 68 | 69 | // // if(hexColor.hasPrefix("#")) { 70 | // // stringScanner.scanLocation = 1 71 | // // } 72 | // // var color: UInt32 = 0 73 | // // stringScanner.scanHexInt32(&color) 74 | 75 | // // let r = CGFloat(Int(color >> 16) & 0x000000FF) 76 | // // let g = CGFloat(Int(color >> 8) & 0x000000FF) 77 | // // let b = CGFloat(Int(color) & 0x000000FF) 78 | 79 | // // return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: 1) 80 | // // } 81 | // } 82 | -------------------------------------------------------------------------------- /ios/FaceSDKModule.h: -------------------------------------------------------------------------------- 1 | // RCTCalendarModule.h 2 | #ifndef FACE_SDK_MODULE_H 3 | #define FACE_SDK_MODULE_H 4 | 5 | #import 6 | #import 7 | 8 | @interface FaceSDKModule : RCTEventEmitter 9 | 10 | @end 11 | 12 | 13 | #endif -------------------------------------------------------------------------------- /ios/FaceSDKModule.mm: -------------------------------------------------------------------------------- 1 | #import "facesdk/facesdk.h" 2 | #import "UIImageExtension.h" 3 | #import 4 | #import 5 | #import "FaceSDKModule.h" 6 | #import "FaceRecognitionSdkViewManager.h" 7 | 8 | int g_checkLivenessLevel = 0; 9 | 10 | 11 | @implementation FaceSDKModule 12 | RCT_EXPORT_MODULE(FaceSDKModule); 13 | 14 | RCT_EXPORT_METHOD(setActivation:(NSString *)license resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 15 | { 16 | printf("setActivation\n"); 17 | int ret = [FaceSDK setActivation:license]; 18 | resolve(@(ret)); 19 | } 20 | 21 | RCT_EXPORT_METHOD(initSDK: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 22 | { 23 | printf("initSDK\n"); 24 | int ret = [FaceSDK initSDK]; 25 | resolve(@(ret)); 26 | } 27 | 28 | RCT_EXPORT_METHOD(setParam: (int) checkLivenessLevel resolve: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 29 | { 30 | printf("setParam\n"); 31 | g_checkLivenessLevel = checkLivenessLevel; 32 | resolve(@(0)); 33 | } 34 | 35 | RCT_EXPORT_METHOD(extractFaces: (NSString*) imagePath resolve: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 36 | { 37 | printf("extract faces!\n"); 38 | NSURL* url = [NSURL URLWithString: imagePath]; 39 | NSData *data = [NSData dataWithContentsOfURL:url]; 40 | UIImage *image = [UIImage imageWithData:data]; 41 | NSMutableArray* faceBoxesMap = [[NSMutableArray alloc] init]; 42 | if(image != nil) { 43 | printf("image size: %f, %f\n", image.size.width, image.size.height); 44 | 45 | UIImage *fixedImage = [image fixOrientation]; 46 | NSArray *faceBoxes = [FaceSDK faceDetection:fixedImage]; 47 | 48 | for(FaceBox* faceBox in faceBoxes) { 49 | NSData* templates = [FaceSDK templateExtraction: fixedImage faceBox: faceBox]; 50 | if([templates length] == 0) continue; 51 | 52 | UIImage* faceImage = [fixedImage cropFaceWithFaceBox:faceBox]; 53 | NSData *faceJpg = UIImageJPEGRepresentation(faceImage, 1.0); 54 | 55 | NSMutableDictionary *e = [[NSMutableDictionary alloc] init]; 56 | [e setValue:[NSString stringWithFormat:@"%f", (float)faceBox.x1] forKey:@"x1"]; 57 | [e setValue:[NSString stringWithFormat:@"%f", (float)faceBox.y1] forKey:@"y1"]; 58 | [e setValue:[NSString stringWithFormat:@"%f", (float)faceBox.x2] forKey:@"x2"]; 59 | [e setValue:[NSString stringWithFormat:@"%f", (float)faceBox.y2] forKey:@"y2"]; 60 | [e setValue:[NSString stringWithFormat:@"%f", faceBox.liveness] forKey:@"liveness"]; 61 | [e setValue:[NSString stringWithFormat:@"%f", faceBox.yaw] forKey:@"yaw"]; 62 | [e setValue:[NSString stringWithFormat:@"%f", faceBox.roll] forKey:@"roll"]; 63 | [e setValue:[NSString stringWithFormat:@"%f", faceBox.pitch] forKey:@"pitch"]; 64 | [e setValue:[templates base64EncodedStringWithOptions: 0] forKey:@"templates"]; 65 | [e setValue:[faceJpg base64EncodedStringWithOptions: 0] forKey:@"faceJpg"]; 66 | [e setValue:[NSString stringWithFormat:@"%d", (int)fixedImage.size.width] forKey:@"frameWidth"]; 67 | [e setValue:[NSString stringWithFormat:@"%d", (int)fixedImage.size.height] forKey:@"frameHeight"]; 68 | 69 | [faceBoxesMap addObject:e]; 70 | } 71 | } 72 | 73 | resolve(faceBoxesMap); 74 | } 75 | 76 | RCT_EXPORT_METHOD(similarityCalculation: (NSString*) templates1 templates2: (NSString*) templates2 resolve: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 77 | { 78 | // Convert base64 strings to NSData objects 79 | NSData *data1 = [[NSData alloc] initWithBase64EncodedString:templates1 options:NSDataBase64DecodingIgnoreUnknownCharacters]; 80 | NSData *data2 = [[NSData alloc] initWithBase64EncodedString:templates2 options:NSDataBase64DecodingIgnoreUnknownCharacters]; 81 | 82 | // Check if NSData objects are valid 83 | if (data1 != nil && data2 != nil) { 84 | // Perform similarity calculation using FaceSDK (replace this with the actual method) 85 | float similarity = [FaceSDK similarityCalculation:data1 templates2:data2]; 86 | resolve(@(similarity)); 87 | } else { 88 | resolve(@(0.0f)); 89 | } 90 | } 91 | 92 | 93 | RCT_EXPORT_METHOD(startCamera: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 94 | { 95 | // printf("start camera %d\n", [FaceRecognitionSdkViewManager requiresMainQueueSetup]); 96 | [FaceRecognitionSdkViewManager startCamera]; 97 | resolve(@(0)); 98 | } 99 | 100 | RCT_EXPORT_METHOD(stopCamera: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) 101 | { 102 | // printf("stop camera %d\n", FaceRecognitionSdkViewManager.faceRecognitionView == nil); 103 | [FaceRecognitionSdkViewManager stopCamera]; 104 | resolve(@(0)); 105 | } 106 | 107 | FaceSDKModule* g_faceSDKModule = nil; 108 | - (id)init { 109 | printf("FaceModule init\n"); 110 | if ((self = [super init])) { 111 | g_faceSDKModule = self; 112 | } 113 | return self; 114 | } 115 | 116 | NSString *const kBeaconSighted = @"onFaceDetected"; 117 | 118 | - (NSDictionary *)constantsToExport { 119 | return @{ @"onFaceDetected": kBeaconSighted, 120 | }; 121 | } 122 | 123 | - (NSArray *)supportedEvents { 124 | return @[@"onFaceDetected" 125 | ]; 126 | } 127 | 128 | 129 | @end 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /ios/NativeCamera.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | #import 5 | #import 6 | #import 7 | #import 8 | #import 9 | 10 | //#import "FaceBox.h" 11 | 12 | @class FaceRecognitionSdkViewManager; 13 | 14 | @interface NativeCamera : UIView 15 | 16 | @property (nonatomic, copy) RCTBubblingEventBlock onFaceDetected; 17 | 18 | - (id)initWithManager:(FaceRecognitionSdkViewManager*)manager bridge:(RCTBridge *)bridge; 19 | @end 20 | -------------------------------------------------------------------------------- /ios/NativeCamera.mm: -------------------------------------------------------------------------------- 1 | 2 | #import "NativeCamera.h" 3 | #import "FaceRecognitionSdkViewManager.h" 4 | #import 5 | #import 6 | 7 | #import 8 | 9 | @interface NativeCamera () 10 | 11 | 12 | @property (nonatomic, weak) FaceRecognitionSdkViewManager *manager; 13 | @property (nonatomic, weak) RCTBridge *bridge; 14 | 15 | @end 16 | 17 | @implementation NativeCamera 18 | { 19 | } 20 | 21 | - (id)initWithManager:(FaceRecognitionSdkViewManager*)manager bridge:(RCTBridge *)bridge 22 | { 23 | 24 | if ((self = [super init])) { 25 | self.manager = manager; 26 | self.bridge = bridge; 27 | // [self.manager initializeCaptureSessionInput:AVMediaTypeVideo]; 28 | } 29 | return self; 30 | } 31 | 32 | - (void)layoutSubviews 33 | { 34 | [super layoutSubviews]; 35 | self.manager.previewLayer.frame = self.bounds; 36 | [self setBackgroundColor:[UIColor blackColor]]; 37 | [self.layer insertSublayer:self.manager.previewLayer atIndex:0]; 38 | } 39 | 40 | - (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex 41 | { 42 | [self insertSubview:view atIndex:atIndex + 1]; 43 | return; 44 | } 45 | 46 | - (void)removeReactSubview:(UIView *)subview 47 | { 48 | [subview removeFromSuperview]; 49 | return; 50 | } 51 | 52 | - (void)removeFromSuperview 53 | { 54 | // [self.manager stopSession]; 55 | [super removeFromSuperview]; 56 | } 57 | 58 | 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /ios/UIImageExtension.h: -------------------------------------------------------------------------------- 1 | #ifndef UIIMAGE_EXTENSION_H 2 | #define UIIMAGE_EXTENSION_H 3 | 4 | #import "facesdk/facesdk.h" 5 | 6 | @interface UIImage(Extensions) 7 | - (UIImage *)cropFaceWithFaceBox:(FaceBox *)faceBox; 8 | - (UIImage *)fixOrientation; 9 | - (UIImage *)rotateWithRadians:(CGFloat)radians; 10 | - (UIImage *)flipHorizontally; 11 | @end 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /ios/UIImageExtension.mm: -------------------------------------------------------------------------------- 1 | 2 | 3 | #import "UIImageExtension.h" 4 | 5 | @implementation UIImage (Extensions) 6 | 7 | - (UIImage *)cropFaceWithFaceBox:(FaceBox *)faceBox { 8 | CGFloat centerX = (faceBox.x1 + faceBox.x2) / 2; 9 | CGFloat centerY = (faceBox.y1 + faceBox.y2) / 2; 10 | CGFloat cropWidth = (faceBox.x2 - faceBox.x1) * 1.4; 11 | 12 | CGFloat cropX1 = centerX - (cropWidth / 2); 13 | CGFloat cropX2 = centerY - (cropWidth / 2); 14 | CGRect cropRect = CGRectMake(cropX1, cropX2, cropWidth, cropWidth); 15 | 16 | CGImageRef croppedImageRef = CGImageCreateWithImageInRect(self.CGImage, cropRect); 17 | UIImage *croppedImage = [UIImage imageWithCGImage:croppedImageRef]; 18 | CGImageRelease(croppedImageRef); 19 | 20 | UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(150, 150)]; 21 | UIImage *newImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) { 22 | [croppedImage drawInRect:CGRectMake(0, 0, 150, 150)]; 23 | }]; 24 | 25 | return newImage; 26 | } 27 | 28 | - (UIImage *)fixOrientation { 29 | if (self.imageOrientation == UIImageOrientationUp) { 30 | return self; 31 | } 32 | 33 | CGAffineTransform transform = CGAffineTransformIdentity; 34 | switch (self.imageOrientation) { 35 | case UIImageOrientationDown: 36 | case UIImageOrientationDownMirrored: 37 | transform = CGAffineTransformTranslate(transform, self.size.width, self.size.height); 38 | transform = CGAffineTransformRotate(transform, M_PI); 39 | break; 40 | 41 | case UIImageOrientationLeft: 42 | case UIImageOrientationLeftMirrored: 43 | transform = CGAffineTransformTranslate(transform, self.size.width, 0); 44 | transform = CGAffineTransformRotate(transform, M_PI_2); 45 | break; 46 | 47 | case UIImageOrientationRight: 48 | case UIImageOrientationRightMirrored: 49 | transform = CGAffineTransformTranslate(transform, 0, self.size.height); 50 | transform = CGAffineTransformRotate(transform, -M_PI_2); 51 | break; 52 | 53 | case UIImageOrientationUp: 54 | case UIImageOrientationUpMirrored: 55 | break; 56 | } 57 | 58 | switch (self.imageOrientation) { 59 | case UIImageOrientationUpMirrored: 60 | case UIImageOrientationDownMirrored: 61 | transform = CGAffineTransformTranslate(transform, self.size.width, 0); 62 | transform = CGAffineTransformScale(transform, -1, 1); 63 | break; 64 | 65 | case UIImageOrientationLeftMirrored: 66 | case UIImageOrientationRightMirrored: 67 | transform = CGAffineTransformTranslate(transform, self.size.height, 0); 68 | transform = CGAffineTransformScale(transform, -1, 1); 69 | break; 70 | 71 | case UIImageOrientationUp: 72 | case UIImageOrientationDown: 73 | case UIImageOrientationLeft: 74 | case UIImageOrientationRight: 75 | break; 76 | } 77 | 78 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 79 | CGContextRef context = CGBitmapContextCreate(NULL, self.size.width, self.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast); 80 | CGColorSpaceRelease(colorSpace); 81 | CGContextConcatCTM(context, transform); 82 | switch (self.imageOrientation) { 83 | case UIImageOrientationLeft: 84 | case UIImageOrientationLeftMirrored: 85 | case UIImageOrientationRight: 86 | case UIImageOrientationRightMirrored: 87 | CGContextDrawImage(context, CGRectMake(0, 0, self.size.height, self.size.width), self.CGImage); 88 | break; 89 | 90 | default: 91 | CGContextDrawImage(context, CGRectMake(0, 0, self.size.width, self.size.height), self.CGImage); 92 | break; 93 | } 94 | 95 | CGImageRef cgImage = CGBitmapContextCreateImage(context); 96 | UIImage *fixedImage = [UIImage imageWithCGImage:cgImage]; 97 | CGContextRelease(context); 98 | CGImageRelease(cgImage); 99 | 100 | return fixedImage; 101 | } 102 | 103 | - (UIImage *)rotateWithRadians:(CGFloat)radians { 104 | CGSize rotatedSize = CGRectApplyAffineTransform(CGRectMake(0, 0, self.size.width, self.size.height), CGAffineTransformMakeRotation(radians)).size; 105 | UIGraphicsBeginImageContext(rotatedSize); 106 | CGContextRef context = UIGraphicsGetCurrentContext(); 107 | CGContextTranslateCTM(context, rotatedSize.width / 2, rotatedSize.height / 2); 108 | CGContextRotateCTM(context, radians); 109 | [self drawInRect:CGRectMake(-self.size.width / 2, -self.size.height / 2, self.size.width, self.size.height)]; 110 | UIImage *rotatedImage = UIGraphicsGetImageFromCurrentImageContext(); 111 | UIGraphicsEndImageContext(); 112 | return rotatedImage ? rotatedImage : self; 113 | } 114 | 115 | - (UIImage *)flipHorizontally { 116 | UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale); 117 | CGContextRef context = UIGraphicsGetCurrentContext(); 118 | CGContextTranslateCTM(context, self.size.width, 0); 119 | CGContextScaleCTM(context, -1.0, 1.0); 120 | [self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)]; 121 | UIImage *flippedImage = UIGraphicsGetImageFromCurrentImageContext(); 122 | UIGraphicsEndImageContext(); 123 | return flippedImage; 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /ios/facesdk.framework/Headers/facesdk.h: -------------------------------------------------------------------------------- 1 | // 2 | // facesdk.h 3 | // facesdk 4 | // 5 | // Created by user on 4/12/23. 6 | // 7 | 8 | #import 9 | 10 | //! Project version number for facesdk. 11 | FOUNDATION_EXPORT double facesdkVersionNumber; 12 | 13 | //! Project version string for facesdk. 14 | FOUNDATION_EXPORT const unsigned char facesdkVersionString[]; 15 | 16 | // In this header, you should import all the public headers of your framework using statements like #import 17 | 18 | 19 | #include "facesdk_api.h" 20 | -------------------------------------------------------------------------------- /ios/facesdk.framework/Headers/facesdk_api.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | NS_ASSUME_NONNULL_BEGIN 5 | 6 | enum SDK_ERROR 7 | { 8 | SDK_SUCCESS = 0, 9 | SDK_LICENSE_KEY_ERROR = -1, 10 | SDK_LICENSE_APPID_ERROR = -2, 11 | SDK_LICENSE_EXPIRED = -3, 12 | SDK_NO_ACTIVATED = -4, 13 | SDK_INIT_ERROR = -5, 14 | }; 15 | 16 | @interface FaceBox : NSObject 17 | 18 | @property (nonatomic) int x1; 19 | @property (nonatomic) int y1; 20 | @property (nonatomic) int x2; 21 | @property (nonatomic) int y2; 22 | @property (nonatomic) float liveness; 23 | @property (nonatomic) float yaw; 24 | @property (nonatomic) float roll; 25 | @property (nonatomic) float pitch; 26 | @end 27 | 28 | @interface FaceSDK : NSObject 29 | 30 | +(int) setActivation: (NSString*) license; 31 | +(int) initSDK; 32 | +(NSMutableArray*) faceDetection: (UIImage*) image; 33 | +(NSData*) templateExtraction: (UIImage*) image faceBox: (FaceBox*) faceBox; 34 | +(float) similarityCalculation: (NSData*) templates1 templates2: (NSData*) templates2; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /ios/facesdk.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/ios/facesdk.framework/Info.plist -------------------------------------------------------------------------------- /ios/facesdk.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module facesdk { 2 | umbrella header "facesdk.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /ios/facesdk.framework/_CodeSignature/CodeResources: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | files 6 | 7 | Headers/facesdk.h 8 | 9 | iXedJdnTNjJdkav0lex0htXPBa8= 10 | 11 | Headers/facesdk_api.h 12 | 13 | nvq2BAwf5zwJ4Ztl7CQydAFcrZo= 14 | 15 | Info.plist 16 | 17 | fDY3c5UxWB5qjD9Cxy526l/nKwg= 18 | 19 | Modules/module.modulemap 20 | 21 | X8zglrv2quSgEMFeVf0TybJa6gA= 22 | 23 | detection.bin 24 | 25 | G52JYi47ACwak8HkEcpkm9zo1as= 26 | 27 | detection.param 28 | 29 | tHFm7ohczZG7KEtACVgRSjX3XIA= 30 | 31 | landmark.bin 32 | 33 | YwuxUSePlqnFEDLD95H35rgexRI= 34 | 35 | landmark.param 36 | 37 | HHZGt8b9GPLjgGplhK/7hcOW0Mo= 38 | 39 | liveness.bin 40 | 41 | qh1obYoGNe0LoyD5JBmUkdeYrEY= 42 | 43 | recognize.bin 44 | 45 | SViF2bgK4XlpoZCVL4WMJbPq6q8= 46 | 47 | recognize.param 48 | 49 | G2oZ25SbKg4KWk0aPL047vM/Rv0= 50 | 51 | 52 | files2 53 | 54 | Headers/facesdk.h 55 | 56 | hash2 57 | 58 | CEHWZwXGt6HTp0cWeGAWrhBufzotOw42QLbWl2FjbpE= 59 | 60 | 61 | Headers/facesdk_api.h 62 | 63 | hash2 64 | 65 | AzDRsIwSMWBPsvoOmXuBP3EefyILyncJlo/a6keydI0= 66 | 67 | 68 | Modules/module.modulemap 69 | 70 | hash2 71 | 72 | MPLn3hXOxK25/iaEZAyvAIf2qaUvsHUOWkHsaZrg7LY= 73 | 74 | 75 | detection.bin 76 | 77 | hash2 78 | 79 | aSBPVzW2w5vueXMHRoelxdPFfzE45CIHzJJfvcmNVVc= 80 | 81 | 82 | detection.param 83 | 84 | hash2 85 | 86 | yb/QW3dSgGun1LdCqss+oipjB11F0sE0NtewKSJibFo= 87 | 88 | 89 | landmark.bin 90 | 91 | hash2 92 | 93 | q59zkpnecoyeYz1houDmoVK0+ROe2x8l/0dtpqDC9Ic= 94 | 95 | 96 | landmark.param 97 | 98 | hash2 99 | 100 | nkGOHyOPviHWfG8E67n+geJfRcw+yc7qGU4famEpZNc= 101 | 102 | 103 | liveness.bin 104 | 105 | hash2 106 | 107 | 3XjsZ9HffijptH6kD8YcgXR9DwsM2tDsYTNDvdErRkE= 108 | 109 | 110 | recognize.bin 111 | 112 | hash2 113 | 114 | ljjc/uY3hbh6WrCw7Z+d/+k+SzcY5eobU33VJDpmG4c= 115 | 116 | 117 | recognize.param 118 | 119 | hash2 120 | 121 | kDIa3Db/MNtnTOFGFGQ1ZvrQfA8iAnM1hx/ZDYyci4A= 122 | 123 | 124 | 125 | rules 126 | 127 | ^.* 128 | 129 | ^.*\.lproj/ 130 | 131 | optional 132 | 133 | weight 134 | 1000 135 | 136 | ^.*\.lproj/locversion.plist$ 137 | 138 | omit 139 | 140 | weight 141 | 1100 142 | 143 | ^Base\.lproj/ 144 | 145 | weight 146 | 1010 147 | 148 | ^version.plist$ 149 | 150 | 151 | rules2 152 | 153 | .*\.dSYM($|/) 154 | 155 | weight 156 | 11 157 | 158 | ^(.*/)?\.DS_Store$ 159 | 160 | omit 161 | 162 | weight 163 | 2000 164 | 165 | ^.* 166 | 167 | ^.*\.lproj/ 168 | 169 | optional 170 | 171 | weight 172 | 1000 173 | 174 | ^.*\.lproj/locversion.plist$ 175 | 176 | omit 177 | 178 | weight 179 | 1100 180 | 181 | ^Base\.lproj/ 182 | 183 | weight 184 | 1010 185 | 186 | ^Info\.plist$ 187 | 188 | omit 189 | 190 | weight 191 | 20 192 | 193 | ^PkgInfo$ 194 | 195 | omit 196 | 197 | weight 198 | 20 199 | 200 | ^embedded\.provisionprofile$ 201 | 202 | weight 203 | 20 204 | 205 | ^version\.plist$ 206 | 207 | weight 208 | 20 209 | 210 | 211 | 212 | 213 | -------------------------------------------------------------------------------- /ios/facesdk.framework/detection.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/ios/facesdk.framework/detection.bin -------------------------------------------------------------------------------- /ios/facesdk.framework/facesdk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/ios/facesdk.framework/facesdk -------------------------------------------------------------------------------- /ios/facesdk.framework/landmark.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/ios/facesdk.framework/landmark.bin -------------------------------------------------------------------------------- /ios/facesdk.framework/landmark.param: -------------------------------------------------------------------------------- 1 | 7767517 2 | 15 15 3 | Input input 0 1 data 0=60 1=60 2=1 4 | Convolution Conv1 1 1 data Conv1 0=20 1=5 2=1 3=1 4=2 5=1 6=500 5 | ReLU ActivationReLU1 1 1 Conv1 ActivationReLU1 6 | Pooling Pool1 1 1 ActivationReLU1 Pool1 0=0 1=2 2=2 3=0 4=0 7 | Convolution Conv2 1 1 Pool1 Conv2 0=48 1=5 2=1 3=1 4=2 5=1 6=24000 8 | ReLU ActivationReLU2 1 1 Conv2 ActivationReLU2 9 | Pooling Pool2 1 1 ActivationReLU2 Pool2 0=0 1=2 2=2 3=0 4=0 10 | Convolution Conv3 1 1 Pool2 Conv3 0=64 1=3 2=1 3=1 4=0 5=1 6=27648 11 | ReLU ActivationReLU3 1 1 Conv3 ActivationReLU3 12 | Pooling Pool3 1 1 ActivationReLU3 Pool3 0=0 1=3 2=2 3=0 4=0 13 | Convolution Conv4 1 1 Pool3 Conv4 0=80 1=3 2=1 3=1 4=0 5=1 6=46080 14 | ReLU ActivationReLU4 1 1 Conv4 ActivationReLU4 15 | InnerProduct Dense1 1 1 ActivationReLU4 Dense1 0=512 1=1 2=655360 16 | ReLU ActivationReLU5 1 1 Dense1 ActivationReLU5 17 | InnerProduct Dense3 1 1 ActivationReLU5 Dense3 0=136 1=1 2=69632 18 | -------------------------------------------------------------------------------- /ios/facesdk.framework/liveness.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/ios/facesdk.framework/liveness.bin -------------------------------------------------------------------------------- /ios/facesdk.framework/recognize.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kby-ai/FaceRecognition-React-Native/b4dd71b10a1528de1bec4c7b781ca6f8f3d1b43c/ios/facesdk.framework/recognize.bin -------------------------------------------------------------------------------- /lefthook.yml: -------------------------------------------------------------------------------- 1 | pre-commit: 2 | parallel: true 3 | commands: 4 | lint: 5 | files: git diff --name-only @{push} 6 | glob: "*.{js,ts,jsx,tsx}" 7 | run: npx eslint {files} 8 | types: 9 | files: git diff --name-only @{push} 10 | glob: "*.{js,ts, jsx, tsx}" 11 | run: npx tsc --noEmit 12 | commit-msg: 13 | parallel: true 14 | commands: 15 | commitlint: 16 | run: npx commitlint --edit 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "face-recognition-sdk", 3 | "version": "0.1.0", 4 | "description": "face recognition, face liveness detection for react-native", 5 | "main": "lib/commonjs/index", 6 | "module": "lib/module/index", 7 | "types": "lib/typescript/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "files": [ 11 | "src", 12 | "lib", 13 | "android", 14 | "ios", 15 | "cpp", 16 | "*.podspec", 17 | "!lib/typescript/example", 18 | "!ios/build", 19 | "!android/build", 20 | "!android/gradle", 21 | "!android/gradlew", 22 | "!android/gradlew.bat", 23 | "!android/local.properties", 24 | "!**/__tests__", 25 | "!**/__fixtures__", 26 | "!**/__mocks__", 27 | "!**/.*" 28 | ], 29 | "scripts": { 30 | "test": "jest", 31 | "typecheck": "tsc --noEmit", 32 | "lint": "eslint \"**/*.{js,ts,tsx}\"", 33 | "prepack": "bob build", 34 | "release": "release-it", 35 | "example": "yarn --cwd example", 36 | "build:android": "cd example/android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a", 37 | "build:ios": "cd example/ios && xcodebuild -workspace FaceRecognitionSdkExample.xcworkspace -scheme FaceRecognitionSdkExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO", 38 | "bootstrap": "yarn example && yarn install && yarn example pods", 39 | "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build" 40 | }, 41 | "keywords": [ 42 | "react-native", 43 | "ios", 44 | "android" 45 | ], 46 | "repository": "https://github.com/kby-ai/FaceRecognition-React-Native", 47 | "author": "kby-ai (https://github.com/kby-ai)", 48 | "license": "MIT", 49 | "bugs": { 50 | "url": "https://github.com/kby-ai/FaceRecognition-React-Native/issues" 51 | }, 52 | "homepage": "https://github.com/kby-ai/FaceRecognition-React-Native#readme", 53 | "publishConfig": { 54 | "registry": "https://registry.npmjs.org/" 55 | }, 56 | "devDependencies": { 57 | "@commitlint/config-conventional": "^17.0.2", 58 | "@evilmartians/lefthook": "^1.5.0", 59 | "@react-native/eslint-config": "^0.73.1", 60 | "@release-it/conventional-changelog": "^5.0.0", 61 | "@types/jest": "^29.5.5", 62 | "@types/react": "^18.2.44", 63 | "commitlint": "^17.0.2", 64 | "del-cli": "^5.1.0", 65 | "eslint": "^8.51.0", 66 | "eslint-config-prettier": "^9.0.0", 67 | "eslint-plugin-prettier": "^5.0.1", 68 | "jest": "^29.7.0", 69 | "prettier": "^3.0.3", 70 | "react": "18.2.0", 71 | "react-native": "0.74.1", 72 | "react-native-builder-bob": "^0.20.0", 73 | "release-it": "^15.0.0", 74 | "turbo": "^1.10.7", 75 | "typescript": "^5.2.2" 76 | }, 77 | "resolutions": { 78 | "@types/react": "^18.2.44" 79 | }, 80 | "peerDependencies": { 81 | "react": "*", 82 | "react-native": "*" 83 | }, 84 | "packageManager": "yarn@3.6.1", 85 | "jest": { 86 | "preset": "react-native", 87 | "modulePathIgnorePatterns": [ 88 | "/example/node_modules", 89 | "/lib/" 90 | ] 91 | }, 92 | "commitlint": { 93 | "extends": [ 94 | "@commitlint/config-conventional" 95 | ] 96 | }, 97 | "release-it": { 98 | "git": { 99 | "commitMessage": "chore: release ${version}", 100 | "tagName": "v${version}" 101 | }, 102 | "npm": { 103 | "publish": true 104 | }, 105 | "github": { 106 | "release": true 107 | }, 108 | "plugins": { 109 | "@release-it/conventional-changelog": { 110 | "preset": "angular" 111 | } 112 | } 113 | }, 114 | "eslintConfig": { 115 | "root": true, 116 | "extends": [ 117 | "@react-native", 118 | "prettier" 119 | ], 120 | "rules": { 121 | "prettier/prettier": [ 122 | "error", 123 | { 124 | "quoteProps": "consistent", 125 | "singleQuote": true, 126 | "tabWidth": 2, 127 | "trailingComma": "es5", 128 | "useTabs": false 129 | } 130 | ] 131 | } 132 | }, 133 | "eslintIgnore": [ 134 | "node_modules/", 135 | "lib/" 136 | ], 137 | "prettier": { 138 | "quoteProps": "consistent", 139 | "singleQuote": true, 140 | "tabWidth": 2, 141 | "trailingComma": "es5", 142 | "useTabs": false 143 | }, 144 | "react-native-builder-bob": { 145 | "source": "src", 146 | "output": "lib", 147 | "targets": [ 148 | "commonjs", 149 | "module", 150 | [ 151 | "typescript", 152 | { 153 | "project": "tsconfig.build.json" 154 | } 155 | ] 156 | ] 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /scripts/bootstrap.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | const path = require('path'); 3 | const child_process = require('child_process'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const args = process.argv.slice(2); 7 | const options = { 8 | cwd: process.cwd(), 9 | env: process.env, 10 | stdio: 'inherit', 11 | encoding: 'utf-8', 12 | }; 13 | 14 | if (os.type() === 'Windows_NT') { 15 | options.shell = true; 16 | } 17 | 18 | let result; 19 | 20 | if (process.cwd() !== root || args.length) { 21 | // We're not in the root of the project, or additional arguments were passed 22 | // In this case, forward the command to `yarn` 23 | result = child_process.spawnSync('yarn', args, options); 24 | } else { 25 | // If `yarn` is run without arguments, perform bootstrap 26 | result = child_process.spawnSync('yarn', ['bootstrap'], options); 27 | } 28 | 29 | process.exitCode = result.status; 30 | -------------------------------------------------------------------------------- /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { 3 | requireNativeComponent, 4 | UIManager, 5 | Platform, 6 | type ViewStyle, 7 | NativeModules, 8 | } from 'react-native'; 9 | import PropTypes from 'prop-types' 10 | 11 | const LINKING_ERROR = 12 | `The package 'face-recognition-sdk' doesn't seem to be linked. Make sure: \n\n` + 13 | Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + 14 | '- You rebuilt the app after installing the package\n' + 15 | '- You are not using Expo Go\n'; 16 | 17 | type FaceRecognitionSdkProps = { 18 | color: string; 19 | style: ViewStyle; 20 | cameraLens: number; 21 | livenessLevel: number; 22 | }; 23 | 24 | const ComponentName = 'FaceRecognitionSdkView'; 25 | 26 | export const FaceRecognitionSdkView = 27 | UIManager.getViewManagerConfig(ComponentName) != null 28 | ? requireNativeComponent(ComponentName) 29 | : () => { 30 | throw new Error(LINKING_ERROR); 31 | }; 32 | 33 | export const {FaceSDKModule} = NativeModules; 34 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "extends": "./tsconfig", 4 | "exclude": ["example"] 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "paths": { 5 | "face-recognition-sdk": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "jsx": "react", 12 | "lib": ["esnext"], 13 | "module": "esnext", 14 | "moduleResolution": "node", 15 | "noFallthroughCasesInSwitch": true, 16 | "noImplicitReturns": true, 17 | "noImplicitUseStrict": false, 18 | "noStrictGenericChecks": false, 19 | "noUncheckedIndexedAccess": true, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "resolveJsonModule": true, 23 | "skipLibCheck": true, 24 | "strict": true, 25 | "target": "esnext", 26 | "verbatimModuleSyntax": true 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://turbo.build/schema.json", 3 | "pipeline": { 4 | "build:android": { 5 | "inputs": [ 6 | "package.json", 7 | "android", 8 | "!android/build", 9 | "src/*.ts", 10 | "src/*.tsx", 11 | "example/package.json", 12 | "example/android", 13 | "!example/android/.gradle", 14 | "!example/android/build", 15 | "!example/android/app/build" 16 | ], 17 | "outputs": [] 18 | }, 19 | "build:ios": { 20 | "inputs": [ 21 | "package.json", 22 | "*.podspec", 23 | "ios", 24 | "src/*.ts", 25 | "src/*.tsx", 26 | "example/package.json", 27 | "example/ios", 28 | "!example/ios/build", 29 | "!example/ios/Pods" 30 | ], 31 | "outputs": [] 32 | } 33 | } 34 | } 35 | --------------------------------------------------------------------------------