a7medev / react-native-ml-kit

React Native On-Device Machine Learning w/ Google ML Kit
MIT License
340 stars 53 forks source link

face detection returns [] #44

Open vidurajith-darshana opened 8 months ago

vidurajith-darshana commented 8 months ago

Hello, I'm facing an issue with my IOS device. When I send an image URL captured through a react-native-vision-camera it returns an empty array. Do you know how I can solve this?

const photo = await camera.current.takePhoto({ enableShutterSound: false, });

try { const faceResults = await FaceDetection.detect('file://' + photo.path, { contourMode: 'all', }); console.log(faceResults); } catch (e) { console.log(e); }

EX: I didn't use any firebase package.

a7medev commented 8 months ago

Hi @vidurajith-darshana! Thanks for reporting this issue. I'll check it and get back to you once I have something to share 🙏🏼.

vidurajith-darshana commented 8 months ago

@a7medev thanks for the reply. Hope some quick solution as soon as possible. we are stuck with this issue. Please note I've never used firebase in my app and if there are any additional installation guides will be really helpful 🙏🏼.

zheoreh commented 8 months ago

Hi everyone! I have same issue but only with ios devices and selfie photos made by them. If I download selfie photo from internet it works). I have same issue in react-native-face-detection module too. I use react-native-image-picker module and its methods: launchImageLibrary and launchCamera to get a selfie. If I share problem selfie somewhere and then download it then this selfie works) magic! It looks like ios protects reading images made by its device.

Update: Same issue is reproduced in your example too

iOS 16.5.1 (20F75) iPad (5th generation) (Model A1822)

flexbox commented 8 months ago

@vidurajith-darshana

I've never used firebase in my app and if there are any additional installation guides will be really helpful 🙏🏼.

you can setup firebase with https://rnfirebase.io/ if you are using expo here is how https://docs.expo.dev/guides/using-firebase/#using-react-native-firebase Do not use the Firebase JS SDK

senturatechnologies commented 8 months ago

@flexbox Actually he asked does he needs to setup Firebase for react-native-ml-kit ? he asked if there were any other installation instructions related to react-native-ml-kit based on Firebase, it's helpful. not about the Firebase setup

nth-zik commented 8 months ago

Hi everyone! I have same issue but only with ios devices and selfie photos made by them. If I download selfie photo from internet it works). I have same issue in react-native-face-detection module too. I use react-native-image-picker module and its methods: launchImageLibrary and launchCamera to get a selfie. If I share problem selfie somewhere and then download it then this selfie works) magic! It looks like ios protects reading images made by its device.

Update: Same issue is reproduced in your example too

iOS 16.5.1 (20F75) iPad (5th generation) (Model A1822)

Same on me

vidurajith-darshana commented 8 months ago

@a7medev is there any update, please? we have been stuck with this issue since last week.

zheoreh commented 7 months ago

@vidurajith-darshana have you found some solution?

vidurajith-darshana commented 7 months ago

no luck, still the same

codemem commented 7 months ago

after debugging, i think the problem is with the temp file path from vision-camera output. As the photo file is stored in a temporary location, that is not accessible directly by file path. It cannot work with that file path atm.

codemem commented 7 months ago

it's throwing error like “ABA4B2D6-A241-4DF6-A1BA-FD6F984A2EE3-1864-0000024DF9AE4C71.jpg” couldn’t be opened because there is no such file."

vidurajith-darshana commented 7 months ago

seems we don't have an answer here. I've been struggling for weeks here using this library. any PR is welcome for the issues. This is going to be an inactive, not-maintained repo.

codemem commented 7 months ago

I will try to see if i can open pr. Take a rest :)

vidurajith-darshana commented 7 months ago

great! but did it give your results as you expected? when I try to get the face detection results, it always returns []. did you have your results correctly?

codemem commented 7 months ago

hmm sorry, i messed up the lib. i supposed to comment on other issue from vision-camera-face-detection not here. No it's still not working

codemem commented 6 months ago

it does not work with vision-camera. I think there is smt with temp file. It works fine with local photo from library but not with temp file name file:///private/blah when working with local file it returns correct result. file path from photo library file:///var/mobile

[{"frame": {"height": 1206, "left": 530, "top": 968, "width": 1206}, "rotationX": -5.255302906036377, "rotationY": -3.0993707180023193, "rotationZ": -1.612923502922058}] faces

p/s: on IOS

write2sv commented 3 weeks ago

I had similar issue with another library https://github.com/teslamotors/react-native-camera-kit/issues/568

For me, its not to do with file location as suggested but to do with image orientation. Here is how I patched mine so that I can make this work for the react-native-camera-kit library I am using. I could be wrong but I don't think this has to do with the mlkit itself.

  1. Create a patch file (lookup react native patch if you are not familiar with this) patches/@react-native-ml-kit+face-detection+1.3.1.patch

  2. Paste these file contents

    
    index 87fd4ff..f237b71 100644
    --- a/node_modules/@react-native-ml-kit/face-detection/ios/FaceDetection.m
    +++ b/node_modules/@react-native-ml-kit/face-detection/ios/FaceDetection.m
    @@ -234,6 +234,15 @@ - (NSDictionary*)faceToDict: (MLKFace*)face
     return dict;
    }

+- (UIImage)fixImageOrientation: (UIImage)image