forked from cdiddy77/react-native-mediapipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'cdiddy77:main' into main
- Loading branch information
Showing
106 changed files
with
7,385 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
.yarn/patches/react-native-vision-camera-npm-4.0.5-0f2bdc9daa.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
diff --git a/android/build.gradle b/android/build.gradle | ||
index d48bc32641758c29011dc8f1992015665390e02c..87caa57ac73c47b235bd046d75c1c880be9be489 100644 | ||
--- a/android/build.gradle | ||
+++ b/android/build.gradle | ||
@@ -1,5 +1,6 @@ | ||
import java.nio.file.Paths | ||
import com.android.Version | ||
+import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform | ||
|
||
def agpVersion = Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger() | ||
def androidManifestPath = agpVersion >= 7 ? 'src/main/AndroidManifest.xml' : 'src/hasNamespace/AndroidManifest.xml' | ||
@@ -90,11 +91,27 @@ if (hasWorklets) { | ||
def enableCodeScanner = safeExtGetBool('VisionCamera_enableCodeScanner', false) | ||
logger.warn("[VisionCamera] VisionCamera_enableCodeScanner is set to $enableCodeScanner!") | ||
|
||
+static def findTools(baseDir) { | ||
+ def basePath = baseDir.toPath().normalize() | ||
+ while (basePath) { | ||
+ def toolsPath = Paths.get(basePath.toString(), "tools") | ||
+ if (toolsPath.toFile().exists()) { | ||
+ return toolsPath.toString() | ||
+ } | ||
+ basePath = basePath.getParent() | ||
+ } | ||
+ throw new GradleException("react-native-vision-camera: Failed to find tools/ path!") | ||
+} | ||
+ | ||
+def toolsDir = findTools(projectDir) | ||
+ | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
+def os = DefaultNativePlatform.currentOperatingSystem; | ||
+ | ||
android { | ||
if (agpVersion >= 7) { | ||
namespace "com.mrousavy.camera" | ||
@@ -131,9 +148,17 @@ android { | ||
externalNativeBuild { | ||
cmake { | ||
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all" | ||
- arguments "-DANDROID_STL=c++_shared", | ||
- "-DNODE_MODULES_DIR=${nodeModules}", | ||
- "-DENABLE_FRAME_PROCESSORS=${enableFrameProcessors ? "ON" : "OFF"}" | ||
+ if (os.isWindows()) { | ||
+ arguments "-DANDROID_STL=c++_shared", | ||
+ "-DNODE_MODULES_DIR=${nodeModules}", | ||
+ "-DENABLE_FRAME_PROCESSORS=${hasWorklets ? "ON" : "OFF"}", | ||
+ "-DCMAKE_MAKE_PROGRAM=${toolsDir}\\windows\\ninja.exe", | ||
+ "-DCMAKE_OBJECT_PATH_MAX=1024" | ||
+ } else { | ||
+ arguments "-DANDROID_STL=c++_shared", | ||
+ "-DNODE_MODULES_DIR=${nodeModules}", | ||
+ "-DENABLE_FRAME_PROCESSORS=${hasWorklets ? "ON" : "OFF"}" | ||
+ } | ||
abiFilters (*reactNativeArchitectures()) | ||
} | ||
} | ||
diff --git a/android/src/main/java/com/mrousavy/camera/frameprocessors/VisionCameraProxy.kt b/android/src/main/java/com/mrousavy/camera/frameprocessors/VisionCameraProxy.kt | ||
index d697befefc1a1d5b8f21ae9b2925161d03b79306..8de418b0b3196000fa09990b1658bb4196a5c4f9 100644 | ||
--- a/android/src/main/java/com/mrousavy/camera/frameprocessors/VisionCameraProxy.kt | ||
+++ b/android/src/main/java/com/mrousavy/camera/frameprocessors/VisionCameraProxy.kt | ||
@@ -7,12 +7,14 @@ import com.facebook.jni.HybridData | ||
import com.facebook.proguard.annotations.DoNotStrip | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.UiThreadUtil | ||
+import com.facebook.react.common.annotations.FrameworkAPI | ||
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl | ||
import com.facebook.react.uimanager.UIManagerHelper | ||
import com.mrousavy.camera.core.ViewNotFoundError | ||
import com.mrousavy.camera.react.CameraView | ||
import java.lang.ref.WeakReference | ||
|
||
+@OptIn(FrameworkAPI::class) | ||
@Suppress("KotlinJniMissingFunction") // we use fbjni. | ||
class VisionCameraProxy(private val reactContext: ReactApplicationContext) { | ||
companion object { |
19 changes: 19 additions & 0 deletions
19
.yarn/patches/react-native-vision-camera-patch-cc9d789186.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
diff --git a/android/src/main/java/com/mrousavy/camera/frameprocessors/VisionCameraProxy.kt b/android/src/main/java/com/mrousavy/camera/frameprocessors/VisionCameraProxy.kt | ||
index d697befefc1a1d5b8f21ae9b2925161d03b79306..8de418b0b3196000fa09990b1658bb4196a5c4f9 100644 | ||
--- a/android/src/main/java/com/mrousavy/camera/frameprocessors/VisionCameraProxy.kt | ||
+++ b/android/src/main/java/com/mrousavy/camera/frameprocessors/VisionCameraProxy.kt | ||
@@ -7,12 +7,14 @@ import com.facebook.jni.HybridData | ||
import com.facebook.proguard.annotations.DoNotStrip | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.UiThreadUtil | ||
+import com.facebook.react.common.annotations.FrameworkAPI | ||
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl | ||
import com.facebook.react.uimanager.UIManagerHelper | ||
import com.mrousavy.camera.core.ViewNotFoundError | ||
import com.mrousavy.camera.react.CameraView | ||
import java.lang.ref.WeakReference | ||
|
||
+@OptIn(FrameworkAPI::class) | ||
@Suppress("KotlinJniMissingFunction") // we use fbjni. | ||
class VisionCameraProxy(private val reactContext: ReactApplicationContext) { | ||
companion object { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
android/src/main/java/com/reactnativemediapipe/facelandmarkdetection/ConvertHelpers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package com.reactnativemediapipe.facelandmarkdetection | ||
|
||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.bridge.WritableArray | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.bridge.WritableNativeArray | ||
import com.facebook.react.bridge.WritableNativeMap | ||
import com.google.mediapipe.tasks.components.containers.Category | ||
import com.google.mediapipe.tasks.components.containers.Classifications | ||
import com.google.mediapipe.tasks.components.containers.Connection | ||
import com.google.mediapipe.tasks.components.containers.NormalizedLandmark | ||
import com.google.mediapipe.tasks.vision.facelandmarker.FaceLandmarkerResult | ||
import com.mrousavy.camera.core.types.Orientation | ||
|
||
// Converts NormalizedLandmark to WritableMap | ||
fun normalizedLandmarkToWritableMap(landmark: NormalizedLandmark): WritableMap { | ||
val map = WritableNativeMap() | ||
map.putDouble("x", landmark.x().toDouble()) | ||
map.putDouble("y", landmark.y().toDouble()) | ||
map.putDouble("z", landmark.z().toDouble()) | ||
return map | ||
} | ||
|
||
// Converts TransformMatrix to WritableMap | ||
fun transformMatrixToWritableMap(matrix: FloatArray): WritableMap { | ||
val map = WritableNativeMap() | ||
val dataArray = WritableNativeArray() | ||
|
||
for (value in matrix) { | ||
dataArray.pushDouble(value.toDouble()) | ||
} | ||
|
||
map.putInt("rows", 4) | ||
map.putInt("columns", 4) | ||
map.putArray("data", dataArray) | ||
return map | ||
} | ||
|
||
// Converts Classifications to WritableMap | ||
fun classificationsToWritableMap(classification: Classifications): WritableMap { | ||
val map = WritableNativeMap() | ||
val categoriesArray = WritableNativeArray() | ||
|
||
classification.categories().forEach { category -> | ||
val categoryMap = WritableNativeMap() | ||
categoryMap.putString("label", category.categoryName()) | ||
categoryMap.putDouble("score", category.score().toDouble()) | ||
categoriesArray.pushMap(categoryMap) | ||
} | ||
|
||
map.putInt("headIndex", classification.headIndex()) | ||
classification.headName()?.let { | ||
map.putString("headName", it.toString()) | ||
} | ||
map.putArray("categories", categoriesArray) | ||
return map | ||
} | ||
|
||
fun categoryListToWritableMap(classification: List<Category>): WritableMap { | ||
val map = WritableNativeMap() | ||
val categoriesArray = WritableNativeArray() | ||
|
||
classification.forEach { category -> | ||
val categoryMap = WritableNativeMap() | ||
categoryMap.putString("label", category.categoryName()) | ||
categoryMap.putDouble("score", category.score().toDouble()) | ||
categoriesArray.pushMap(categoryMap) | ||
} | ||
|
||
map.putArray("categories", categoriesArray) | ||
return map | ||
} | ||
|
||
fun convertResultBundleToWritableMap(resultBundle: FaceLandmarkDetectorHelper.ResultBundle): WritableMap { | ||
val map = Arguments.createMap() | ||
val resultsArray = Arguments.createArray() | ||
resultBundle.results.forEach { result -> | ||
resultsArray.pushMap(faceLandmarkerResultToWritableMap(result)) | ||
} | ||
map.putArray("results", resultsArray) | ||
map.putInt("inputImageHeight", resultBundle.inputImageHeight) | ||
map.putInt("inputImageWidth", resultBundle.inputImageWidth) | ||
map.putInt("inputImageRotation", resultBundle.inputImageRotation) | ||
map.putDouble("inferenceTime", resultBundle.inferenceTime.toDouble()) | ||
return map | ||
} | ||
|
||
fun faceLandmarkerResultToWritableMap(result: FaceLandmarkerResult): WritableMap { | ||
val resultMap = WritableNativeMap() | ||
val landmarksArray = WritableNativeArray() | ||
val blendshapesArray = WritableNativeArray() | ||
val matricesArray = WritableNativeArray() | ||
|
||
result.faceLandmarks().forEach { face -> | ||
val faceArray = WritableNativeArray() | ||
face.forEach { landmark -> faceArray.pushMap(normalizedLandmarkToWritableMap(landmark)) } | ||
landmarksArray.pushArray(faceArray) | ||
} | ||
|
||
result.faceBlendshapes().ifPresent { listOfListOfCategories -> | ||
// Iterate over the list of list of categories | ||
listOfListOfCategories.forEach { list -> | ||
// Convert each list of categories to a WritableMap | ||
val map: WritableMap = categoryListToWritableMap(list) | ||
// Push the WritableMap to the blendshapesArray | ||
blendshapesArray.pushMap(map) | ||
} | ||
} | ||
|
||
result.facialTransformationMatrixes().ifPresent { listOfMatrices -> | ||
listOfMatrices.forEach { matrix -> | ||
matricesArray.pushMap(transformMatrixToWritableMap(matrix)) | ||
|
||
} | ||
} | ||
|
||
resultMap.putArray("faceLandmarks", landmarksArray) | ||
resultMap.putArray("faceBlendshapes", blendshapesArray) | ||
resultMap.putArray("facialTransformationMatrixes", matricesArray) | ||
|
||
return resultMap | ||
} | ||
|
||
fun orientationToDegrees(orientation: Orientation): Int = | ||
when (orientation) { | ||
Orientation.PORTRAIT -> 0 | ||
Orientation.LANDSCAPE_LEFT -> 90 | ||
Orientation.PORTRAIT_UPSIDE_DOWN -> 180 | ||
Orientation.LANDSCAPE_RIGHT -> -90 | ||
} | ||
|
||
|
||
fun connectionSetToWritableArray(connections: Set<Connection>): WritableArray { | ||
val result = WritableNativeArray() | ||
connections.forEach { | ||
val map = Arguments.createMap() | ||
map.putInt("start", it.start()) | ||
map.putInt("end", it.end()) | ||
result.pushMap(map) | ||
} | ||
return result | ||
} |
Oops, something went wrong.