Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG 🐛] Detected face wrong orientation on Samsung A14 #69

Closed
edritech93 opened this issue Jun 10, 2024 · 14 comments
Closed

[BUG 🐛] Detected face wrong orientation on Samsung A14 #69

edritech93 opened this issue Jun 10, 2024 · 14 comments
Labels
bug Something isn't working

Comments

@edritech93
Copy link

wrong orientation when detected face

Device:

  • Device: Samsumg A14
  • OS: Android

package.json file:

{
...
   "dependencies": {
     "react-native-vision-camera": "4.1.0",
     "react-native-vision-camera-face-detector": "^1.6.3",
     "react-native-worklets-core": "^1.3.3"
  }
...
}
@edritech93 edritech93 added the bug Something isn't working label Jun 10, 2024
@tienbuiba
Copy link

tienbuiba commented Jun 10, 2024

I am facing this issue too, in android Samsung S22, Xiaomi Mi9T, Realme 5Pro... . I can't fix this error. I need you help me !!!!

On iphone everything is ok, however on Android I have to rotate the phone 90 degrees or any other angle to be able to detect successfully. when Android in portrait mode, the detect result will always return []

@Aycom366
Copy link

@luicfrr
I'm sorry to tag you, but is there a quick fix we can add to the native code to make the face work in portrait mode?

@luicfrr
Copy link
Owner

luicfrr commented Jun 17, 2024

@Aycom366 I'm really busy on another project these month, I didn't have time to even check new vision-camera releases.

If you need an urgent patch maybe you should considerate on paying me for that then I'll work on it on my free/rest time.
If you don't want to pay me for this then you can work on a fix yourself or you'll need to wait for a fix (yes, I'll keep this package updated).

@luicfrr
Copy link
Owner

luicfrr commented Jul 3, 2024

@edritech93 I just released 1.7.0 version.
Can you please check if it fix this issue?

@frodriguez-hu
Copy link

frodriguez-hu commented Jul 4, 2024

Hey! Is the version 1.7.0 working on vision camera 3.9.2? @luicfrr

@luicfrr
Copy link
Owner

luicfrr commented Jul 4, 2024

@frodriguez-hu no, for 3.9.2 you should use (I don't remember but I think)1.3.5 version

@luicfrr
Copy link
Owner

luicfrr commented Jul 4, 2024

Closing this issue for now.
If the error persists maybe we can reopen it.

@luicfrr luicfrr closed this as completed Jul 4, 2024
@frodriguez-hu
Copy link

@luicfrr Question, have you tried this to get the orientation? Suggested by Google

private val ORIENTATIONS = SparseIntArray()

init {
    ORIENTATIONS.append(Surface.ROTATION_0, 0)
    ORIENTATIONS.append(Surface.ROTATION_90, 90)
    ORIENTATIONS.append(Surface.ROTATION_180, 180)
    ORIENTATIONS.append(Surface.ROTATION_270, 270)
}

/**
 * Get the angle by which an image must be rotated given the device's current
 * orientation.
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Throws(CameraAccessException::class)
private fun getRotationCompensation(cameraId: String, activity: Activity, isFrontFacing: Boolean): Int {
    // Get the device's current rotation relative to its "native" orientation.
    // Then, from the ORIENTATIONS table, look up the angle the image must be
    // rotated to compensate for the device's rotation.
    val deviceRotation = activity.windowManager.defaultDisplay.rotation
    var rotationCompensation = ORIENTATIONS.get(deviceRotation)

    // Get the device's sensor orientation.
    val cameraManager = activity.getSystemService(CAMERA_SERVICE) as CameraManager
    val sensorOrientation = cameraManager
            .getCameraCharacteristics(cameraId)
            .get(CameraCharacteristics.SENSOR_ORIENTATION)!!

    if (isFrontFacing) {
        rotationCompensation = (sensorOrientation + rotationCompensation) % 360
    } else { // back-facing
        rotationCompensation = (sensorOrientation - rotationCompensation + 360) % 360
    }
    return rotationCompensation
}

Cause for last vision camera version on my last test and with the last version of this library, it wasn't working properly either

@luicfrr
Copy link
Owner

luicfrr commented Jul 4, 2024

@frodriguez-hu I didn't tested it this way on kotlin.
I saw some code using activity.windowManager when I was using java some time ago but I couldn't have access to current activity neither windowManager.

Anyway, I'll test this now on kotlin and give you credits if it works.

If you already have this working on your device and want to create a PR I'll apretiate a lot.

@frodriguez-hu
Copy link

@luicfrr I do not have it working cause I wasn't able to implement it correctly, I can't mount the android project on android studio and when I want to start it with the changes I am not able to do it.
I send the cameraId from device.id from the javascript side and then sending it to the plugin config. Then I had errors trying to get the activity from the ReactPackage, but I think that is cause I wasn't able to set up Kotlin properly so Android Studio is not showing me the errors on the code.

I am not completely sure, I tried it again on a new project and it worked fine, but it is not working on my main project, I don't know it it could have conflicts with another dependency line reanimated maybe? I don't know, but is quite weird

@frodriguez-hu
Copy link

@luicfrr If I hardcode the rotation to 270 degrees it work properly, but it stop working on landscape and other orientations.

And setting this condition to be always true

if (rotation == 270 || rotation == 90) {

What would happen on other devices? All android devices start with an orientation of 90 degrees?

@luicfrr
Copy link
Owner

luicfrr commented Jul 4, 2024

@frodriguez-hu where are you hardcoding this if(rotation ....)?
In my latest version there's no ifs in rotation.

And yes, in every device (android and ios), camera orientation is always -90deg rotated

@frodriguez-hu
Copy link

frodriguez-hu commented Jul 5, 2024

@luicfrr Sorry! I am using 1.4.0 version (We have an older react native version (0.71.12) and we are limited to 3.x.x on VC). But on a test i did on the last version it wasn't catching any face either.
Let me know if you implement the other suggestion, or I will try to implement it too, how do you prepare the project on Android Studio? I'd like to help maintaining this since we are probably using it on a production app

And the equivalent to the if a I mentioned is to hardcode to 270 degrees on processBoundingBox on the latest version.

@luicfrr
Copy link
Owner

luicfrr commented Jul 5, 2024

@frodriguez-hu let's keep this conversation going on this discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants